Author Topic: new template -> latest comments but paging doesn´t work  (Read 4190 times)

0 Members and 1 Guest are viewing this topic.

Offline Art1977

  • Newbie
  • *
  • Posts: 37
    • View Profile
    • http://www.d-mack.de
new template -> latest comments but paging doesn´t work
« on: May 26, 2003, 06:47:56 PM »
I created a new template with the name latest comments .....

but the paging function doesn´t work ....
the latest comments are appearing but i could only change the value in the details... not in my new template ,also the paging funtions ( how many comments ....... ) is not shown .......

my code in the php file :
<?php
$templates_used = 'whos_online,comment_short_bit,last_comments,commentsperpage_dropdown_form';
$main_template = 'last_comments';

define('GET_CACHES', 1);
define('ROOT_PATH', './');
define('GET_USER_ONLINE', 1);
include(ROOT_PATH.'global.php');
require(ROOT_PATH.'includes/sessions.php');
$user_access = get_permission();
if (isset($HTTP_GET_VARS['template']) || isset($HTTP_POST_VARS['template'])) {
  $template = (isset($HTTP_GET_VARS['template'])) ? stripslashes(trim($HTTP_GET_VARS['template'])) : stripslashes(trim($HTTP_POST_VARS['template']));
  if (!file_exists(TEMPLATE_PATH."/".$template.".".$site_template->template_extension)) {
    $template = "";
  }
  else {
    $main_template = $template;
  }
}
else {
  $template = "";
}
include(ROOT_PATH.'includes/page_header.php');


//-----------------------------------------------------
//--- Clickstream -------------------------------------
//-----------------------------------------------------
$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'].get_category_path($cat_id)."</span>";



//-----------------------------------------------------
//--- Letzte Kommentare
//-----------------------------------------------------
 
if (isset($HTTP_POST_VARS['commentsetperpage']) || isset($HTTP_GET_VARS['commentsetperpage'])) {
  $commentsetperpage = (intval($HTTP_POST_VARS['commentsetperpage']) ) ? intval($HTTP_POST_VARS['commentsetperpage']) : intval($HTTP_GET_VARS['commentsetperpage']);
  if ($commentsetperpage) {
    $site_sess->set_session_var("commentperpage", $commentsetperpage);
    $session_info['commentperpage'] = $commentsetperpage;
  }
}

if (isset($session_info['commentperpage'])) {
  $commentperpage = $session_info['commentperpage'];
}
else {
  $commentperpage = 5;
}
$commentsperpage_dropdown = "\n<select name=\"commentsetperpage\" onchange=\"if (this.options[this.selectedIndex].value != 0){ forms['commentsperpage'].submit() }\" class=\"select\">\n";
    for($i = 1; $i <= 15; $i++) {
      $setvalue = 1 * $i;
      $commentsperpage_dropdown .= "<option value=\"".$setvalue."\"";
        if ($setvalue == $commentperpage) {
        $commentsperpage_dropdown .= " selected=\"selected\"";
      }
      $commentsperpage_dropdown .= ">";
      $commentsperpage_dropdown .= $setvalue;
      $commentsperpage_dropdown .= "</option>\n";
    }
    $commentsperpage_dropdown .= "</select>\n";

    $site_template->register_vars("commentsperpage_dropdown", $commentsperpage_dropdown);
    $commentsperpage_dropdown_form = $site_template->parse_template("commentsperpage_dropdown_form");
    $site_template->register_vars("commentsperpage_dropdown_form", $commentsperpage_dropdown_form);
      $sql = "SELECT COUNT(image_id) AS comments
      FROM ".COMMENTS_TABLE."
      WHERE image_id = $image_id";
    $result = $site_db->query_firstrow($sql);
    $site_db->free_result();
    $num_comments = $result['comments'];
    if ($action == "postcomment") {
        $page = ceil($num_comments / $commentperpage);
    }
    $num_rows_all = (isset($num_comments)) ? $num_comments : 0;
    $link_arg = $site_sess->url(ROOT_PATH."details.php?image_id=$image_id");
    include(ROOT_PATH.'includes/paging.php');
    $getpaging = new Paging($page, $commentperpage, $num_rows_all, $link_arg, $lang['comment_stats'], "comments");
    $offset = $getpaging->get_offset();
    $site_template->register_vars(array(
      "paging" => $getpaging->get_paging(),
      "paging_stats" => ($num_comments) ? $getpaging->get_paging_stats() : ""
    ));            

$additional_sql = "";
      $table_fields = $site_db->get_table_fields(USERS_TABLE);
      foreach ($additional_user_fields as $key => $val) {
        if (isset($HTTP_POST_VARS[$key]) && isset($table_fields[$key])) {
          $additional_sql .= ", $key = '".un_htmlspecialchars(trim($HTTP_POST_VARS[$key]))."'";
        }
      }
  $sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS comment_user_name, c.comment_headline, c.comment_text, c.comment_date".get_user_table_field(", u.", "user_level").get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_lastaction").get_user_table_field(", u.", "user_comments").$additional_sql."
          FROM ".COMMENTS_TABLE." c
          LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = c.user_id)
          ORDER BY c.comment_date DESC
          LIMIT $offset, $commentperpage";
  $result = $site_db->query($sql);
  $comment_row = array();
  while ($row = $site_db->fetch_array($result)) {
    $comment_row[] = $row;
  }
  $site_db->free_result($result);
  $num_comments = sizeof($comment_row);
  if (!$num_comments) {
    $comments_short = "<tr><td class=\"commentrow1\" colspan=\"2\">".$lang['no_comments']."</td></tr>";
  }
  else {
    $comments_short = "";
    for ($i = 0; $i < $num_comments; $i++) {
        $image_id = $comment_row[$i]['image_id'];
        $sql = "SELECT i.image_id, i.cat_id, i.image_name, c.cat_name, i.image_media_file, i.image_thumb_file
                FROM ".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
                LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
                WHERE i.image_id = $image_id AND c.cat_id = i.cat_id";
        $image_row = $site_db->query_firstrow($sql);
        $cat_id = (isset($image_row['cat_id'])) ? $image_row['cat_id'] : 0;
      if (check_permission("auth_readcomment", $cat_id)){
        $comment_user_name = htmlspecialchars($comment_row[$i]['comment_user_name']);
        $comment_user_info = $lang['userlevel_guest'];
        $comment_user_id = $comment_row[$i]['user_id'];
        $user_row_comment = get_user_info($comment_user_id);
        $comment_user_profile_link = "";
        $comment_user_info = $lang['userlevel_guest'];
        if (!isset($comment_row[$i][$user_table_fields['user_level']]) || (isset($comment_row[$i][$user_table_fields['user_level']]) && $comment_row[$i][$user_table_fields['user_level']] == USER)) {
          $comment_user_info = $lang['userlevel_user'];
        }
        elseif ($comment_row[$i][$user_table_fields['user_level']] == ADMIN) {
          $comment_user_info = $lang['userlevel_admin'];
        }
        if (isset($comment_row[$i][$user_table_fields['user_name']]) && $comment_user_id != GUEST) {
          $comment_user_name = htmlspecialchars($comment_row[$i][$user_table_fields['user_name']]);
          $comment_user_profile_link = !empty($url_show_profile) ? $site_sess->url(preg_replace("/{user_id}/", $comment_user_id, $url_show_profile)) : $site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$comment_user_id);
        }
          $comment_user_profile_link = ($comment_user_profile_link) ? "<a href=\"".$comment_user_profile_link."\">".$comment_user_name."</a>" : $comment_user_name;
       
      if (!get_file_path($image_row['image_thumb_file'], "thumb", $image_row['cat_id'], 0, 0)) {
        $thumb_file = ICON_PATH."/".get_file_extension($image_row['image_media_file']).".gif";
      }else {
        $thumb_file = get_file_path($image_row['image_thumb_file'], "thumb", $image_row['cat_id'], 0, 1);
      }
      $thumb_info = @getimagesize($thumb_file);
      $width = $thumb_info[0];
      $height = $thumb_info[1];
      $dimension = 80;
      $ratio = $width / $height;
      if ($ratio > 1) {
        $new_width = $dimension;
        $new_height = floor(($dimension/$width) * $height);
      }else {
        $new_width = floor(($dimension/$height) * $width);
        $new_height = $dimension;
      }    
      $site_template->register_vars(array(    
          "comment_image_thumb" => (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id)) ? "<img src=\"".$thumb_file."\"
        width=\"".$new_width."\" height=\"".$new_height."\" onClick=\"alert('".$lang['members_only']."');\" border=\"".$config['image_border']."\">" : "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$comment_row[$i]['image_id'].((!empty($mode)) ? "&amp;mode=".$mode : ""))."\">
        <img src=\"".$thumb_file."\" width=\"".$new_width."\" height=\"".$new_height."\" border=\"".$config['image_border']."\"></a>",
       
          "comment_image_name" => (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id)) ? $image_row['image_name'] : "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$comment_row[$i]['image_id'].((!empty($mode)) ? "&amp;mode=".$mode : ""))."\">".$image_row['image_name']."</a>",
          "comment_cat_name" => (!check_permission("auth_viewcat", $cat_id)) ? $image_row['cat_name'] : "<a href=\"".$site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$cat_id)."\">".$image_row['cat_name']."</a>",
          "comment_user_name" => $comment_user_profile_link,
          "comment_user_info" => $comment_user_info,
          "comment_headline" => format_text($comment_row[$i]['comment_headline'], 0, $config['wordwrap_comments'], 0, 0),
          "comment_text" => format_text($comment_row[$i]['comment_text'], $config['html_comments'], $config['wordwrap_comments'], $config['bb_comments'], $config['bb_img_comments']),
          "comment_date" => format_date($config['date_format']." ".$config['time_format'], $comment_row[$i]['comment_date']),
        ));
      
      
      
        $comments_short .= $site_template->parse_template("comment_short_bit");
      }
    } // end while
  } //end else
  $site_template->register_vars("comments_short", $comments_short);
  unset($comments_short);

//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------
$site_template->register_vars(array(
  "msg" => $msg,
  "clickstream" => $clickstream
));
$site_template->print_template($site_template->parse_template($main_template));
include(ROOT_PATH.'includes/page_footer.php');
?>




THE CODE in my html file :
{header}
<table width="640" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td>
      <table width="640" border="0" cellspacing="0" cellpadding="0" class="tablehead">
        <tr>
      <td colspan="4"><img src="{template_url}/images/header_top.gif" width="640" height="6" alt="" /></td>
        </tr>
        <tr>
        <td width="6"><img src="{template_url}/images/header_left.gif" width="6" height="60" alt="" /></td>
          <td width="405"><img src="{template_url}/images/header_logo.jpg" width="405" height="60" alt="" /> </td>
          <td width="225" align="right">
            <form method="post" action="{url_search}">
              <table border="0" cellspacing="0" cellpadding="1">
                <tr>
                  <td>
                    <input type="text" name="search_keywords" size="15" class="searchinput" />
                  </td>
                  <td>
                    <input type="submit" value="{lang_search}" class="button" name="submit" />
                  </td>
                </tr>
                <tr valign="top">
                  <td colspan="2"><a href="{url_search}" class="smalltext">{lang_advanced_search}</a></td>
                </tr>
              </table>
            </form>
          </td>
          <td align="right" width="6"><img src="{template_url}/images/header_right.gif" width="6" height="60" alt="" /></td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td class="bordercolor">
      <table width="640" border="0" cellspacing="1" cellpadding="0">
        <tr>
          <td class="tablebgcolor">
            <table width="638" border="0" cellspacing="1" cellpadding="0">
              <tr>
                <td class="navbar" height="23">
                  <table width="636" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><img src="{template_url}/images/spacer.gif" width="4" height="4" alt="" />{clickstream}</td>
                      <td align="right">
                  <a href="{url_top_images}"><b>{lang_top_images}</b></a>&nbsp;
                  <a href="{url_new_images}"><b>{lang_new_images}</b></a>&nbsp;
                 </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
            <table width="638" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="150" class="row2" valign="top">
                  <table width="150" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head2" height="20"><img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />{lang_registered_user}</td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                    <tr>
                      <td align="center" class="row1">{user_box}
                 </td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                  </table>
              {if random_image}
                  <table width="150" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head2" height="20"> <img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />{lang_random_image}</td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                    <tr>
                      <td align="center" class="row1">
                   <br />
                        {random_image}
                  <br />
                        <br />
                      </td>
                    </tr>
                    <tr>
                      <td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                    </tr>
                  </table>
              {endif random_image}           
                </td>
                <td width="1" class="bordercolor" valign="top"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td>
                <td width="18" valign="top"><img src="{template_url}/images/spacer.gif" alt="" width="18" height="18" /></td>
                <td width="450" valign="top">
              <br />
                  <span class="title">{site_name}</span>
              <br />
              <hr size="1" />
                  <table width="450" border="0" cellspacing="0" cellpadding="1">            
                <tr><td class="head2" height="20" align="left"><img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />Neueste Kommentare</td></tr>
                <tr><td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td></tr>
                <tr><td align="center" class="row1">{comments_short}
                <tr><td class="tablebgcolor"><img src="{template_url}/images/spacer.gif" alt="" width="1" height="1" /></td></tr>    
      <a name="comments"></a>
        {if paging_stats}
            <table width="100%" border="0" cellspacing="1" cellpadding="0" class="bordercolor">
                <tr>
                    <td>
                        <table width="100%" border="0" cellspacing="0" cellpadding="3">
                            <tr>
                                <td class="row1" valign="middle">
                                    {paging_stats}
                                </td>
                                <td class="row1" valign="top" align="right">
                                    {commentsperpage_dropdown_form}
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>        
        {endif paging_stats}
        {if paging}
            <table width="100%" border="0" cellspacing="1" cellpadding="0" class="bordercolor">
                <tr>
                    <td>
                        <table width="100%" border="0" cellspacing="0" cellpadding="3">
                            <tr>
                                <td class="row1" valign="top">{paging}</td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>        
        {endif paging}
              </table>
                  <br />
                  <br />
                  <br />
                  {if msg}<b>{msg}</b><br /><br />{endif msg}
                 
                  <br />
              {whos_online}
              <br />
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>{category_dropdown_form}</td>        
                    </tr>
                  </table>
                  <p>&nbsp;</p>
                </td>
                <td width="19" valign="top"><img src="{template_url}/images/spacer.gif" alt="" width="19" height="19" /></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td>
      <table width="640" border="0" cellspacing="0" cellpadding="0" class="tablebottom">
        <tr>
          <td width="6"><img src="{template_url}/images/footer_left.gif" width="6" height="19" alt="" /></td>
          <td width="405">&nbsp;</td>
          <td width="225">&nbsp;</td>
          <td width="6"><img src="{template_url}/images/footer_right.gif" width="6" height="19" alt="" /></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
{footer}