<?php
/**
* AkoComment - A User Comments Component
* @version 2.0
* @package AkoComment
* @copyright (C) 2004 by Arthur Konze - All rights reserved!
* @license http://www.konze.de/content/view/8/26/ Copyrighted Commercial Software
**/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
# Get the right language if it exists
  if (file_exists($mosConfig_absolute_path.'/components/com_akocomment/languages/'.$mosConfig_lang.'.php')) {
    include($mosConfig_absolute_path.'/components/com_akocomment/languages/'.$mosConfig_lang.'.php');
  } else {
    include($mosConfig_absolute_path.'/components/com_akocomment/languages/english.php');
  }
  
class HTML_comment {

  function showAbout() {
  ?>
      <table cellpadding="4" cellspacing="0" border="0" width="100%">
      <tr>
        <td width="100%">
          <img src="components/com_akocomment/images/logo.png">
        </td>
      </tr>
      <tr>
        <td>
          <?php echo _A_AKOCOM_ABOUT ;?>
        </td>
      </tr>
      </table>
  <?php
    }

############################################################################

  function showComments( $option, &$rows, &$search, &$pageNav ) {
    $commentlenght = "40";

    # Table header
    ?>
    <form action="index2.php" method="post" name="adminForm">
    <table cellpadding="4" cellspacing="0" border="0" width="100%">
    <tr>
      <td width="100%">
        <img src="components/com_akocomment/images/logo.png">
      </td>
      <td nowrap="nowrap"><?php echo _A_AKOCOM_DISPLAY ; ?> #</td>
      <td>
        <?php echo $pageNav->writeLimitBox(); ?>
      </td>
      <td><?php echo _A_AKOCOM_SEARCH ; ?>:</td>
      <td>
        <input type="text" name="search" value="<?php echo $search;?>" class="inputbox" onChange="document.adminForm.submit();" />
      </td>
    </tr>
    </table>
    <table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
      <tr>
        <th width="2%" class="title"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $rows ); ?>);" /></th>
        <th class="title"><div align="center"><?php echo _A_AKOCOM_AUTHOR ; ?></div></th>
        <th class="title"><div align="left"><?php echo _A_AKOCOM_COMMENT ; ?></div></th>
        <th class="title"><div align="center"><?php echo _A_AKOCOM_DATE ; ?></div></th>
        <th class="title"><div align="center"><?php echo _A_AKOCOM_CONTENT_ITEM ; ?></div></th>
        <th class="title"><div align="center"><?php echo _A_AKOCOM_PUBLISHED ; ?></div></th>
      </tr>
      <?php
    $k = 0;
    for ($i=0, $n=count( $rows ); $i < $n; $i++) {
      $row = &$rows[$i];
      echo "<tr class='row$k'>";
      echo "<td width='5%'><input type='checkbox' id='cb$i' name='cid[]' value='$row->id' onclick='isChecked(this.checked);' /></td>";
      echo "<td align='center'><a href=\"index2.php?option=".$option."&task=edit&cid[]=".$row->id."\">$row->name</a></td>";
      if(strlen($row->comment) > $commentlenght) {
        $row->comment  = substr($row->comment,0,$entrylenght-3);
        $row->comment .= "...";
      }
      echo "<td align='left'>$row->comment</td>";
      echo "<td align='center'>$row->date</td>";
      echo "<td align='center'>$row->contentid</td>";
      if(strlen($row->gbcomment) > $commentlenght) {
        $row->gbcomment  = substr($row->gbcomment,0,$commentlenght-3);
        $row->gbcomment .= "...";
      }

      $task = $row->published ? 'unpublish' : 'publish';
      $img = $row->published ? 'publish_g.png' : 'publish_x.png';
      ?>
        <td width="10%" align="center"><a href="javascript: void(0);" onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $task;?>')"><img src="images/<?php echo $img;?>" width="12" height="12" border="0" alt="" /></a></td>
    </tr>
    <?php    $k = 1 - $k; } ?>
    <tr>
      <th align="center" colspan="7">
        <?php echo $pageNav->writePagesLinks(); ?></th>
    </tr>
    <tr>
      <td align="center" colspan="7">
        <?php echo $pageNav->writePagesCounter(); ?></td>
    </tr>
  </table>
  <input type="hidden" name="option" value="<?php echo $option;?>" />
  <input type="hidden" name="task" value="" />
  <input type="hidden" name="boxchecked" value="0" />
  </form>
  <?php
  }

############################################################################

  function editComment( $option, &$row, &$clist, &$olist, &$puplist ) {
    mosMakeHtmlSafe( $row, ENT_QUOTES, 'comment' );
    ?>
    <script language="javascript" type="text/javascript">
    function submitbutton(pressbutton) {
      var form = document.adminForm;
      if (pressbutton == 'cancel') {
        submitform( pressbutton );
        return;
      }

      // do field validation
      if (form.comment.value == ""){
        alert( "<?php echo _A_AKOCOM_MSG_WRITE_TXT ; ?>" );
      } else if (form.contentid.value == "0"){
        alert( "<?php echo _A_AKOCOM_MSG_SEL_CORRESP_ITEM ; ?>" );
      } else if (form.name.value == ""){
        alert( "<?php echo _A_AKOCOM_MSG_ENTER_AUTORS ; ?>" );
      } else {
        submitform( pressbutton );
      }
    }
    </script>
    <table cellpadding="4" cellspacing="0" border="0" width="100%">
    <tr>
      <td width="100%"><span class="sectionname"><?php echo $row->id ? _A_AKOCOM_EDIT : _A_AKOCOM_ADD;?> Comment</span></td>
    </tr>
  </table>
    <table cellpadding="4" cellspacing="1" border="0" width="100%" class="adminform">
    <form action="index2.php" method="post" name="adminForm" id="adminForm">
      <tr>
        <td width="20%" align="right"><?php echo _A_AKOCOM_NAME ; ?>:</td>
        <td width="80%">
          <input class="inputbox" type="text" name="name" size="50" maxlength="30" value="<?php echo $row->name;?>" />
        </td>
      </tr>

      <tr>
        <td valign="top" align="right"><?php echo _A_AKOCOM_CONTENT_ITEM ; ?>:</td>
        <td>
          <?php echo $clist; ?>
        </td>
      </tr>

      <tr>
        <td valign="top" align="right"><?php echo _A_AKOCOM_TITLE ; ?>:</td>
        <td>
          <input class="inputbox" type="text" name="title" value="<?php echo $row->title; ?>" size="50" maxlength="50" />
        </td>
      </tr>

      <tr>
        <td valign="top" align="right"><?php echo _A_AKOCOM_COMMENT ; ?>:</td>
        <td>
          <textarea class="inputbox" cols="50" rows="5" name="comment"><?php echo $row->comment;?></textarea>
        </td>
      </tr>

      <tr>
        <td valign="top" align="right"><?php echo _A_AKOCOM_ORDERING ; ?>:</td>
        <td>
          <?php echo $olist; ?>
        </td>
      </tr>


      <tr>
        <td valign="top" align="right"><?php echo _A_AKOCOM_PUBLISHED ; ?>:</td>
        <td>
          <?php echo $puplist; ?>
        </td>
      </tr>

    </table>

    <input type="hidden" name="id" value="<?php echo $row->id; ?>" />
    <input type="hidden" name="option" value="<?php echo $option;?>" />
    <input type="hidden" name="task" value="" />
    </form>
  <?php
  }

############################################################################

  function showFile($file, $option) {
    $file = stripslashes($file);
    $f=fopen($file,"r");
    $content = fread($f, filesize($file));
    $content = htmlspecialchars($content);
    ?>
    <form action="index2.php?" method="post" name="adminForm" class="adminForm" id="adminForm">
    <table cellpadding="4" cellspacing="0" border="0" width="100%">
      <tr>
        <td width="100%">
          <img src="components/com_akocomment/images/logo.png">
        </td>
      </tr>
    </table>
    <table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminform">
       <tr>
         <th colspan="4"><?php echo _A_AKOCOM_PATH ; ?>: <?php echo $file; ?></td> </tr>
       <tr>
         <td> <textarea cols="80" rows="20" name="filecontent" id="filecontent"><?php echo $content; ?></textarea>
         </td>
       </tr>
       <tr>
         <td class="error"><?php echo _A_AKOCOM_NOTE ; ?></td>
       </tr>
    </table>
    <input type="hidden" name="file" value="<?php echo $file; ?>" />
    <input type="hidden" name="option" value="<?php echo $option; ?>">
    <input type="hidden" name="task" value="">
    <input type="hidden" name="boxchecked" value="0">
    </form>
    <?php
  }

}
?>