<?/*
Copyright (C) 2003 Media Net Link, Inc. Danville, CA 94526 USA

This file is part of AthenaRMS.

AthenaRMS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

AthenaRMS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/?>
<?php
/*
   # declared above this
   $ticket_p = new Ticket ();
   $person_p = new Person ();
   $comment = new Comment ();
   $crm = new CRM ();
   $attv = new Attribute_Value ();

   $ticket - object has current ticket
   $dd - drop-down object
   $dec_params - url parameters so you don't need a form
 */
?>
        <table border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
          <td align="left">
            <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr>
              <td width="38"><?php
echo $display->Value ('<a href="escalated_reply'.$dec_params.'"><img alt="" src="../../img/but-esc.gif" width="38" height="26" border="0" /></a>', '&nbsp;');
?></td>
              <td align="center">
                <table border="0" cellspacing="0" cellpadding="0">
                <tbody>
                <tr>
                  <td align="left" class="textsm" nowrap="nowrap"><b>Opened:</b> <?php echo $ticket->Get ('created_date'); ?></td>
                </tr>
                <tr>
                  <td align="left" class="textsm" nowrap="nowrap"><b>Last Update:</b> <?php echo $ticket->Get ('updated_date'); ?></td>
                </tr>
                <tr>
                  <td align="left" class="textsm" nowrap="nowrap"><b>Closed Date:</b> <?php echo $ticket->Get ('close_date'); ?></td>
                </tr>
                </tbody>
                </table>
              </td>
              <td width="38"><?php
  echo $display->Value ('<a href="add_user_reply'.$dec_params.'"><img alt="" src="../../img/but-add.gif" width="38" height="26" border="0" /></a>', '&nbsp;');
?></td>
            </tr>
            </table>
          </td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td class="rnavside-btm" background="../../img/gradient-rnav-left.gif" valign='top'><img alt="" src="../../img/elipse-rnav-top-corn-left.gif" width="6" height="5" /></td>
          <td>




<!-- Start Compose Email Table -->
<table width='100%' cellpadding="0" border="0" cellspacing="0">
<tr><td class="composebox" valign="middle" align="center" nowrap="nowrap">
<?php
  echo $display->Value ('<b class="commentsatextmedgrn">Send:</b></font>
    <input ONCLICK="if (this.checked) { document.mainform.send_user_b.checked=true;} else { document.mainform.send_user_b.checked=false;}" checked="checked" type="checkbox" name="send_user_a" class="commentscheckbox" value="user"><font class="commentstxt">customer</font></input>
    <input ONCLICK="if (this.checked) { document.mainform.send_support_b.checked=true;} else { document.mainform.send_support_b.checked=false;}" checked="checked" type="checkbox" name="send_support_a" class="commentscheckbox" value="support"><font class="commentstxt">owner</font></input>
    <input ONCLICK="if (this.checked) { document.mainform.send_internal_b.checked=true;} else { document.mainform.send_internal_b.checked=false;}" type="checkbox" name="send_internal_a" class="commentscheckbox" value="internal"><font class="commentstxt">escalated</font></input>
    <input ONCLICK="if (this.checked) { document.mainform.send_other_b.checked=true;} else { document.mainform.send_other_b.checked=false;}" type="checkbox" name="send_other_a" class="commentscheckbox" value="other"><font class="commentstxt">other rms</font></input>

&nbsp;<input type="submit" value="Compose" name="submit_button" class="btn-on" />', '&nbsp;');?>

</td>

</table>
<!-- End Compose Email Table -->




          </td>
          <td class="rnavside-btm" background="../../img/gradient-rnav-right.gif" valign='top'><img alt="" src="../../img/elipse-rnav-top-corn-right.gif" width="6" height="5" /></td>
        </tr>
        <tr>
          <td class="rnavside-lf" rowspan="2"><img alt="" src="../../img/cldot.gif" width="1" height="1" /></td>
          <td width="100%"><br />


<!-- Start Email Comments Table -->

<?php
  if (is_null($comment_id_list = 
    $comment->List_By_Ticket_CRM ($ticket_id, null, '%b %d %Y %l:%i%p'))) 
      die("edit_ticket_rnav.php: " . $comment->error);

  $user_pid = $ticket->Get ('user_person_id');
  $support_pid = $ticket->Get ('support_person_id');
  $escalate_pid = $ticket->Get ('escalated_to_person_id');

  require_once 'icon_map.php';
  require_once 'server_functions.php';

  foreach ($comment_id_list as $r) {

    $attachments = $comment->Attachments ($r['comment_id']);

    if ($r['internal'] == 'Y') {
      $bgcolor = $ESCALATED_COMMENT;
      $bgcolor2 = 'com-escalated2';
      $bgcolorcom = 'commes-escalated';
      $com_img = '../../img/comments-escalated.gif';
    } elseif ($r['person_id'] == $user_pid) {
      $bgcolor = $USER_COMMENT;
      $bgcolor2 = 'com-customer2';
      $bgcolorcom = 'commes-customer';
      $com_img = '../../img/comments-customer.gif';
    } elseif (!$r['is_in_crm']) {
      $bgcolor = $OTHER_CRM_COMMENT;
      $bgcolor2 = 'com-other2';
      $bgcolorcom = 'commes-other';
      $com_img = '../../img/comments-other.gif';
    } else {
      $bgcolor = $SUPPORT_COMMENT;
      $bgcolor2 = 'com-owner2';
      $bgcolorcom = 'commes-owner';
      $com_img = '../../img/comments-owner.gif';
    }

    $comm_text = $comment->to_HTML( $r['comments'] );

    $show_edit_button  = <<<EOF
              <td align="right" width="1" class="$bgcolor2"><img src="../../img/cldot.gif" width="1" height="1" /></td>
EOF;

    $show_edit_button = $display->Value ($show_edit_button, '');

    #echo("<tr><td><pre>" . htmlentities(print_r($r, true)) 
    #  . "</pre></td></tr\n");

    print <<<EOF
            <table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="left" width="19" class="textsm"><img align="absmiddle" hspace="0" vspace="0" border="0" alt="" src="$com_img" width="19" height="19" />
</td>
              <td valign='middle' align="left" width="100%" class="$bgcolor"><img alt="" src="../../img/cldot.gif" width="3" height="1" /><b class="textsm">$r[first_name]
                $r[last_name]:</b> <font class="textsm">$r[created_date]</font></td>
$show_edit_button
            </tr><tr><td class="$bgcolorcom" colspan='3'>

           <table cellpadding="0" border="0" cellspacing="2" width="100%">
EOF;

    foreach ($attachments as $a) {
      $aname = htmlentities ($a['attachment_name']);
      $aname_link = rawurlencode ($a['attachment_name']);
      $atype = $a['attachment_type'];

      if ($atype) {
        $aimg = array_key_exists($atype, $ICONS)
	      ? $ICONS[$atype]
              : $ICONS['default'];

        $desc = getimagesize ("../../img/icons/$aimg");

        $img = "<img src=\"../../img/icons/$aimg\" $desc[3] align=\"ABSMIDDLE\" hspace=\"1\" vspace=\"1\" border=\"0\" alt=\"$aimg\" />";
      }

      print <<<EOF
            <tr>
              <td align="left" class="textsm"><a href="../email/viewattachment/$aname_link?attach_id=$a[attachment_id]" target="_blank">$img $aname - $atype</a></td>
            </tr>
EOF;
    }

print <<<EOF


              <tr><td align="left" class="atextmed">$comm_text<a href="edit_comment$dec_params&amp;comment_id=$r[comment_id]"><img align="right" class="comeditbtn" vspace="0" border="0" alt="" src="../../img/comment-edit.gif" width="34" height="16" /></a></td>
            </tr></table></td></tr><tr><td colspan='3'><img alt="" src="../../img/cldot.gif" width="1" height="7" /></td></tr></table>
EOF;
  }

  $show_submit_button = <<<EOF

<table cellspacing="0" cellpadding="1" border="0" bgcolor="#de0000">
<tr>
<td><input type="submit" value="SAVE" name="submit_button" class="textsm" /></td>
</tr>
</table>

EOF;

  $show_submit_button = $display->Value ($show_submit_button, '');
?>

          </td>
          <td class="rnavside-rt" rowspan="2"><img alt="" src="../../img/cldot.gif" width="1" height="1" /></td>
        </tr>
        <tr>
          <td width="100%" class="textsm"><b>Internal Support Notes:</b><br />
<?php
  $tmp = htmlentities($ticket->Get ('additional_info'));
  echo $display->Value ('<textarea name="additional_info" rows="3" cols="55" wrap="soft" class="textsm">'.$tmp.'</textarea>', $tmp);
?>
<br /><br />
          </td>
        </tr>
        <tr>
          <td class="rnavside-top" background="../../img/gradient-rnav-left.gif" valign='bottom'><img alt="" src="../../img/elipse-rnav-btm-corn-left.gif" width="6" height="5" /></td>
          <td>

<!-- Start Compose Email Table -->

<table width='100%' cellpadding="0" border="0" cellspacing="0">
<tr><td class="composebox" valign="middle" align="center" nowrap="nowrap">
<?php
  echo $display->Value ('<b class="commentsatextmedgrn">Send:</b></font>
    <input ONCLICK="if (this.checked) { document.mainform.send_user_a.checked=true;} else { document.mainform.send_user_a.checked=false;}" checked="checked" type="checkbox" name="send_user_b" class="commentscheckbox" value="user"><font class="commentstxt">customer</font></input>
    <input ONCLICK="if (this.checked) { document.mainform.send_support_a.checked=true;} else { document.mainform.send_support_a.checked=false;}" checked="checked" type="checkbox" name="send_support_b" class="commentscheckbox" value="support"><font class="commentstxt">owner</font></input>
    <input ONCLICK="if (this.checked) { document.mainform.send_internal_a.checked=true;} else { document.mainform.send_internal_a.checked=false;}" type="checkbox" name="send_internal_b" class="commentscheckbox" value="internal"><font class="commentstxt">escalated</font></input>
    <input ONCLICK="if (this.checked) { document.mainform.send_other_a.checked=true;} else { document.mainform.send_other_a.checked=false;}" type="checkbox" name="send_other_b" class="commentscheckbox" value="other"><font class="commentstxt">other rms</font></input>

&nbsp;<input type="submit" value="Compose" name="submit_button" class="btn-on" />', '&nbsp;');?>

</td>

</table>
<!-- End Compose Email Table -->

          </td>
          <td class="rnavside-top" background="../../img/gradient-rnav-right.gif" valign='bottom'><img src="../../img/elipse-rnav-btm-corn-right.gif" width="6" height="5" /></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td align="center" valign="middle" height="25">
<?php echo $show_submit_button; ?>
          <td>&nbsp;</td>
        </tr>
        </table>
