Location: PHPKode > projects > PHPKode - PHPGuestbook > kode_core.php
<?php
  /*
   * PHPKode PHP Guestbook v0.3
   *
   * Copyright (c) 2010 PHPKode.com <hide@address.com>
   * All rights reserved.
   *
   * See COPYING file for license information.
   *
   * Download the latest version from
   * http://www.phpguestbook.org
   * http://www.phpkode.com/projects/item/phpkode-phpguestbook/
   */

  if (!file_exists('./data/kode_install.lock')) {
      die("You need to install the script first. Click <a href='./installer/'>here</a> to continue.");
  }
  session_start();
  error_reporting(0);
  
// include files
  include "./data/kode_config.php";
  include "kode_class_db.php";
  include "kode_connect_db.php";
  include "kode_functions.php";
  include "kode_author.php";

  $DB_PREFIX = MYSQL_TABLE_PREFIX;

  $connDb = conn_Db();

//get config

  $sql = "SELECT * FROM {$DB_PREFIX}config LIMIT 0,1";
  $result = $connDb->query($sql);
  $CONFIG = $connDb->fetchAssoc($result);

//get avatar list

  $AVATARS = array();
  $sql = "SELECT * FROM {$DB_PREFIX}avatar WHERE category_id=1";
  $result = $connDb->query($sql);
  while ($row = $connDb->fetchAssoc($result)) {
      $AVATARS[$row['id']] = $row['file_name'];
  };
  $rand_avatar = array_rand($AVATARS);

  $visitor_key = get_visitor_key();

  $logged = Logged();
?>
<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title><?php echo($CONFIG['page_title']); ?></title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <link rel="stylesheet" href="kode_style.css" type="text/css" media="screen" />
            <link rel="stylesheet" href="kode_theme_default.css" type="text/css" media="screen" />
            <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
            <script type="text/javascript" src="js/jquery.form.js"></script>

        </head>
        <body>-->

<div id="kode_wrapper">
      <div id="kode_nav">
          <div class="kode_buttons">
              <div class="kode_button" id="kode_btn_sign"  onClick="kode_openForm($('#kode_signform'))"><span class="kode_plus"></span></div>
            <?php
              if ($logged) {
            ?>
                  <div id="kode_dropdown_container">
                      <div class="kode_button" onclick="kode_openForm($('#kode_dropdown'));"> <span class="kode_button_list"></span> <span class="kode_down-arrow"></span> </div>
                      <ul id="kode_dropdown" >
                          <li>
                              <label onClick="kode_openForm($('#kode_adminConfig'))">Configure</label>
                          </li>
                          <li>
                              <label onClick="kode_adminLogout()">Sign out</label>
                          </li>
                      </ul>
                  </div>
            <?php
              }
              else {
            ?>
                  <div class="kode_button" id="kode_btn_login" onClick="kode_openForm($('#kode_adminlogin'))"><span class="kode_login"></span></div>
            <?php
              }
            ?>
          </div>
          <div class="kode_location"> <span>Location: <a href="<?php echo($CONFIG['home_page']); ?>">Home</a> &gt; <?php echo($CONFIG['page_title']); ?></span> </div>
      </div>
      <div class="kode_box kode_box-error" id="kode_result">Error</div>
      <div id="kode_signform">
          <div class="kode_btn_close"> <a href="javascript:void(0);" onclick="kode_closeForm($('#kode_signform'))"><img src="images/close.png" id="kode_signClose" alt="Close" width="14" height="14" border="0" /></a></div>
          <fieldset>
              <legend>Sign Guestbook</legend>
              <form action="kode_operations.php" method="post" enctype="application/x-www-form-urlencoded" id="kode_frmSign">
                  <p>
                      <label for="kode_visitor_name">Your Name (<span class="kode_red_font">*</span>):</label>
                      <br />
                      <input name="visitor_name" type="text" class="half" id="kode_visitor_name" value="" size="20" />
                      <span id="kode_avatar" onclick="kode_openForm($('#kode_avatar_selector'))"><span ><img src="images/avatar/s_<?php echo($AVATARS[$rand_avatar]); ?>" id="kode_rand_avatar" alt="avatar" width="24" height="24" align="absmiddle" /></span>
                          <span id="kode_avatar_all"></span>
                          <span id="kode_avatar_selector">
                            <?php
                              foreach ($AVATARS as $k => $v) {
                            ?>
                                  <img src="images/avatar/s_<?php echo($v); ?>" onclick="kode_selectAvatar(<?php echo($k) ?>,'<?php echo($v); ?>')" alt="avatar" width="24" height="24" />
                            <?php
                              }
                            ?>
                          </span>
                      </span>
                  </p>
                  <p>
                      <label for="kode_email">E-mail:</label>
                      <br />
                      <input name="email" type="text" class="half" id="kode_email" value="" size="40" />
                  </p>
                  <p>
                      <label for="kode_webiste">Website / Blog:</label>
                      <br />
                      <input name="webiste" type="text" class="half" id="kode_webiste" value="http://" size="40" />
                  </p>
                  <p>
                      <label for="kode_subject">Subject (<span class="kode_red_font">*</span>):</label>
                      <br />
                      <input name="subject" type="text" class="half" id="kode_subject" value="" size="40" />
                  </p>
                  <p>
                      <label for="kode_comment">Comment (<span class="kode_red_font">*</span>):</label>
                      <br />
                      <textarea name="comment" cols="60" rows="3" id="kode_comment" class="medium"></textarea>
                  </p>
                  <p>
                      <label>Validate Code (<span class="kode_red_font">*</span>):</label>
                      <input name="validate_code" type="text" value="" size="10" />
                      <img src="./images/kode_validate.gif" class="kode_validate_img" id="kode_img_sign" alt="code" width="80" height="25" align="absmiddle" /></p>
                  <p class="kode_height20"></p>
                  <p>
                      <input name="submit" type="submit" class="kode_submit" id="kode_submitmsg" value="Submit comment" />
                      <input name="avatar_id" id="kode_avatar_id" type="hidden" value="<?php echo($rand_avatar); ?>" />
                      <input name="action" type="hidden" id="kode_action" value="signMsg" />
                  </p>
              </form>
          </fieldset>
      </div>
    <?php
                              if ($logged) {
    ?>
                                  <div id="kode_adminConfig">
                                      <div class="kode_btn_close"><a href="javascript:void(0);" onclick="kode_closeForm($('#kode_adminConfig'))"><img src="images/close.png" alt="Close" width="14" height="14" border="0" /></a> </div>
                                      <fieldset>
                                          <legend>Change Admin Information</legend>
                                          <form action="kode_operations.php" method="post" enctype="application/x-www-form-urlencoded" id="kode_frmConfig">
                                              <p>
                                                  <label for="kode_admin_name">Admin name:</label>
                                                  <br />
                                                  <input type="text" id="kode_admin_name" class="half" value="<?php echo $_SESSION["adminuser"] ?>" name="admin_name" />
                                              </p>
                                              <p>
                                                  <label for="kode_new_pass">New Password:</label>
                                                  <br />
                                                  <input type="password" id="kode_new_pass" class="half" value="" name="new_pass" />
                                              </p>
                                              <p>
                                                  <label for="kode_confirm_pass">Confirm Password:</label>
                                                  <br />
                                                  <input type="password" id="kode_confirm_pass" class="half" value="" name="confirm_pass" />
                                              </p>
                                              <p>
                                                  <label for="kode_home_page">Homepage URL:</label>
                                                  <br />
                                                  <input type="text" id="kode_home_page" class="half" value="<?php echo($CONFIG['home_page']); ?>" name="home_page" />
                                              </p>
                                              <p>
                                                  <label for="kode_page_title">Page Title:</label>
                                                  <br />
                                                  <input type="text" id="kode_page_title" class="half" value="<?php echo($CONFIG['page_title']); ?>" name="page_title" />
                                              </p>
                                              <p>
                                                  <label for="kode_copyright">Copyright Information:</label>
                                                  <br />
                                                  <textarea name="copyright" cols="60" rows="3" id="kode_copyright" class="medium"><?php echo($CONFIG['copyright']); ?></textarea>
                                              </p>
                                              <p class="kode_height20"></p>
                                              <p>
                                                  <input name="Submit" type="submit" class="kode_submit" value="Save Settings"  />
                                                  <input name="action" type="hidden" id="kode_action" value="adminConfig" />
                                              </p>
                                          </form>
                                      </fieldset>
                                  </div>
    <?php
                              }
                              else {
    ?>
                                  <div id="kode_adminlogin">
                                      <div class="kode_btn_close"><a href="javascript:void(0);" onclick="kode_closeForm($('#kode_adminlogin'))"><img src="images/close.png" alt="Close" width="14" height="14" border="0" /></a> </div>
                                      <fieldset>
                                          <legend>Admin Login</legend>
                                          <form action="kode_operations.php" method="post" enctype="application/x-www-form-urlencoded" id="kode_frmLogin">
                                              <p>
                                                  <label for="kode_admin_name">Username  (<span class="kode_red_font">*</span>):</label>
                                                  <br />
                                                  <input type="text" id="kode_admin_name" class="half" value="" name="admin_name" />
                                              </p>
                                              <p>
                                                  <label for="kode_admin_pass">Password  (<span class="kode_red_font">*</span>):</label>
                                                  <br />
                                                  <input type="password" id="kode_admin_pass" class="half" value="" name="admin_pass" />
                                              </p>
                                              <p>
                                                  <label>Validate Code (<span class="kode_red_font">*</span>):</label>
                                                  <input name="validate_code" type="text" value="" size="10" />
                                                  <img src="./images/kode_validate.gif" class="kode_validate_img" id="kode_img_login" alt="code" width="80" height="25" align="absmiddle" />
                                              </p>
                                              <p class="kode_height20"><span class="kode_red_font">Notice</span>: administrator username / password: admin</p>
                                              <p>
                                                  <input name="Submit" type="submit" class="kode_submit" value="Login" />
                                                  <input name="action" type="hidden" id="kode_action" value="adminLogin" />
                                              </p>
                                          </form>
                                      </fieldset>
                                  </div>

    <?php
                              }
                              $page = isset($_GET['page']) ? $_GET['page'] : 1;
                              $sql = "SELECT COUNT(id) as total FROM {$DB_PREFIX}message ORDER BY id DESC";

                              $result = $connDb->query($sql);
                              $row = $connDb->fetchAssoc($result);
                              $total = $row['total'];


                              if ($total > 0) {
                                  $sql = "SELECT message.id as id, message.visitor_name as visitor_name, message.avatar as avatar, message.website as website, message.subject as subject, message.comment as comment, message.date_added as date_added, message.visitor_key as visitor_key, reply.comment as rcomment, reply.date_added as rdate ";
                                  $sql .= " FROM {$DB_PREFIX}message AS message LEFT JOIN {$DB_PREFIX}reply as reply ON (message.id = reply.message_id) ";
                                  $sql .= " ORDER BY message.id DESC";

                                  $results = $connDb->query($sql);
                                  while ($rows = $connDb->fetchAssoc($results)) {
//                                      print_r($rows);
                                      if (is_url($rows['website'])) {
                                          $visitor_name = "<a href='" . $rows['website'] . "'>" . $rows['visitor_name'] . "</a>";
                                      }
                                      else {
                                          $visitor_name = $rows['visitor_name'];
                                      }
    ?>
                                      <div class="kode_post_list" id="kode_post_<?php echo $rows['id'] ?>">
                                          <div class="kode_subject"><?php echo $rows['subject'] ?></div>
                                          <div class="kode_clear"></div>
                                          <div class="kode_post">
                                              <div class="kode_avatar"><img src="images/avatar/<?php echo($AVATARS[$rows['avatar']]); ?>" alt="" width="100" height="100" /></div>
                                              <div class="kode_comment"><?php echo nl2br($rows['comment']) ?></div>
                                          </div>
                                          <div class="kode_clear"></div>
                                          <div class="kode_pmeta">
                                              <div class="kode_buttons">
                <?php
                                      if ($logged || $visitor_key == $rows['visitor_key']) {
                ?>
                                          <div class="kode_btn_del"><a href="javascript:void(0)" onclick="kode_openForm($('#kode_del_confirm_<?php echo $rows['id'] ?>'));">Delete</a></div>
                <?
                                      }
                                      if ($logged) {
                ?>
                                          <div class="kode_btn_reply"><a href="javascript:void(0)" onclick="kode_openForm($('#kode_reply_<?php echo $rows['id'] ?>'))">Reply</a></div>
                <?php
                                      }
                ?>
                                  </div>
                                  <div>Post on <?php echo $rows['date_added'] ?> by <?php echo $visitor_name; ?></div>
                              </div>
                              <div class="kode_del_confirm" id="kode_del_confirm_<?php echo $rows['id'] ?>">
                                  <div><a href="javascript:void(0);" onclick="kode_closeForm($('#kode_del_confirm_<?php echo $rows['id'] ?>'))">CANCEL</a> or <a href="javascript:void(0);" onclick="kode_delMsg(<?php echo $rows['id'] ?>);">DEL</a></div>
                              </div>
                              <div class="kode_clear"></div>
                              <div class="kode_box kode_box-error kode_hidden" id="kode_notify_<?php echo $rows['id'] ?>">Error</div>
                              <div id="kode_reply_<?php echo $rows['id'] ?>" class="kode_replyform">
                                  <div class="kode_btn_close"> <a href="javascript:void(0)" onclick="kode_closeForm($('#kode_reply_<?php echo $rows['id'] ?>'))"><img src="images/close.png" alt="Close" width="14" height="14" border="0"  /></a> </div>
                                  <p>
                                      <textarea id="kode_replymsg_<?php echo $rows['id'] ?>" name="replymsg_<?php echo $rows['id'] ?>" cols="60" rows="3" class="kode_replymsg"><?php echo $rows["rcomment"] ?></textarea>
                                  </p>
                                  <p> <span>
                                          <input name="btn_reply_<?php echo $rows['id'] ?>" type="button" class="kode_button" id="kode_btn_reply_<?php echo $rows['id'] ?>" value="Submit Reply" onclick="kode_replyMsg(<?php echo $rows['id'] ?>);" />
                                      </span> </p>
                              </div>
                              <div class="kode_clear"></div>
        <?php
                                      if (!empty($rows["rcomment"])) {
        ?>
                                          <div class="kode_post_reply" id="kode_post_reply_<?php echo $rows['id'] ?>">
                                              <div class="kode_rmeta">Reply on <?php echo $rows['rdate'] ?></div>
                                              <div class="kode_reply_content" id="kode_reply_content_<?php echo $rows['id'] ?>"><?php echo nl2br($rows["rcomment"]) ?></div>
                                          </div>
        <?php
                                      }
        ?>
                                  </div>
    <?php
                                      $total--;
                                  }
                              }
                              else {
    ?>
                                  <div class="kode_box kode_box-info">There was not any message.</div>
    <?php
                              }
                              $connDb->close();
    ?>
                              <div class="kode_clear"></div>
                              <div id="kode_page_copyright"><?php echo($CONFIG['copyright']); ?></div>
</div>
<script type="text/javascript" src="js/kode_functions.js"></script>
<!--    </body>
</html>-->
Return current item: PHPKode - PHPGuestbook