Public paste
Undefined
By: Guest | Date: Sep 2 2008 09:58 | Format: PHP | Expires: never | Size: 17.74 KB | Hits: 1495

  1. <?php
  2.  
  3.   /*****************************************************
  4.   ** Title........: Guestbook Script
  5.   ** Filename.....: index.php
  6.   ** Author.......: Ralf Stadtaus
  7.   ** Homepage.....: http://www.stadtaus.com/
  8.   ** Contact......: http://www.stadtaus.com/forum/
  9.   ** Version......: 0.9
  10.   ** Notes........:                  
  11.   ** Last changed.: 2004-04-04
  12.   ** Last change..:
  13.   *****************************************************/
  14.  
  15.   /*****************************************************
  16.   **
  17.   ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY
  18.   ** OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  19.   ** LIMITED   TO  THE WARRANTIES  OF  MERCHANTABILITY,
  20.   ** FITNESS    FOR    A    PARTICULAR    PURPOSE   AND
  21.   ** NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR
  22.   ** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
  23.   ** OR  OTHER  LIABILITY,  WHETHER  IN  AN  ACTION  OF
  24.   ** CONTRACT,  TORT OR OTHERWISE, ARISING FROM, OUT OF
  25.   ** OR  IN  CONNECTION WITH THE SOFTWARE OR THE USE OR
  26.   ** OTHER DEALINGS IN THE SOFTWARE.
  27.   **
  28.   *****************************************************/
  29.  
  30.  
  31.  
  32.  
  33.  
  34.   /*****************************************************
  35.   ** Settings
  36.   *****************************************************/
  37.           $script_root  = './';
  38.           $script_title = '';
  39.           $query_string = '?';
  40.  
  41.  
  42.  
  43.  
  44.   /*****************************************************
  45.   ** Send safety signal to included files
  46.   *****************************************************/
  47.           define('IN_SCRIPT', 'true');
  48.  
  49.  
  50.  
  51.  
  52.   /*****************************************************
  53.   ** Include files
  54.   *****************************************************/
  55.           include($script_root . 'inc/common.inc.php');
  56.           include($script_root . 'inc/table_check.inc.php');
  57.  
  58.  
  59.  
  60.  
  61.   /*****************************************************
  62.   ** Set file name
  63.   *****************************************************/
  64.           $file_name    = basename($_SERVER['PHP_SELF']);
  65.  
  66.  
  67.  
  68.  
  69.  
  70.   /*****************************************************
  71.   ** Initialyze form field class
  72.   *****************************************************/
  73.           $form = new Formfields;
  74.  
  75.  
  76.  
  77.  
  78.   /*****************************************************
  79.   ** Load form field templates into object
  80.   *****************************************************/
  81.           $form->define_form('sign', $new_form_fields);
  82.  
  83.          
  84.  
  85.  
  86.   /*****************************************************
  87.   ** Initialyze template class
  88.   *****************************************************/
  89.           $tpl = new my_template;
  90.  
  91.  
  92.  
  93.  
  94.   /*****************************************************
  95.   ** Prevent appending session id
  96.   *****************************************************/
  97.           $sid_name = session_name();
  98.          
  99.           if ((isset($_GET[$sid_name]) and $trans_sid != 'no') or isset($_COOKIE[$sid_name])) {
  100.               session_start();
  101.           }
  102.          
  103.  
  104.  
  105.  
  106.   /*****************************************************
  107.   ** Load admin html template
  108.   *****************************************************/
  109.           if (isset($_SESSION['login_status']) and $_SESSION['login_status'] == 'IN') {
  110.               $tpl->load_file('admin', $script_root . $path['templates'] . $file['admin_details']);
  111.  
  112.               $admin_template = $tpl->files['admin'];
  113.               $logged_in      = 'true';
  114.           } else {
  115.               $admin_template = '';
  116.           }
  117.  
  118.  
  119.  
  120.  
  121.   /*****************************************************
  122.   ** Validate query string and set offset value.
  123.   *****************************************************/
  124.           if (isset($_GET['offset']) and !empty($_GET['offset']) and preg_match("/^[0-9]*$/", $_GET['offset'])) {
  125.               $currentpage = $_GET['offset'];
  126.           } else {
  127.               $currentpage = 1;
  128.           }
  129.  
  130.  
  131.  
  132.  
  133.   /*****************************************************
  134.   ** Initialyze database class
  135.   *****************************************************/
  136.           $db = new Database;
  137.  
  138.  
  139.  
  140.  
  141.   /*****************************************************
  142.   ** Connect and select database
  143.   *****************************************************/
  144.           if (!isset($message) and $db->db_connect($database)) {
  145.              
  146.               if ($db->db_select($database)) {
  147.  
  148.  
  149.  
  150.  
  151.                   /*****************************************************
  152.                   ** Count results
  153.                   *****************************************************/
  154.                           $sql = "SELECT COUNT(entry_id) FROM " . ENTRY_TABLE;
  155.                
  156.                           if ($result_number = $db->db_count_result($sql)) {
  157.                               $result_true   = 'true';
  158.                               $entries       = $result_number;
  159.                
  160.                
  161.                               if (!isset($results_per_page) or empty($results_per_page)) {
  162.                                   $limit = $result_number;
  163.                               } else {
  164.                                   $limit = $results_per_page;
  165.                               }
  166.                
  167.                               $allpages = ceil($result_number / $limit);
  168.                
  169.                
  170.                               if (isset($currentpage) and !empty($currentpage)) {
  171.                                   $start = $result_number - $currentpage * $limit;
  172.                               } else {
  173.                                   $start = $result_number;
  174.                               }
  175.                
  176.                               if ($start < 0) {
  177.                                   $limit       = $result_number - ($allpages - 1) * $limit;
  178.                                   $start       = 0;
  179.                                   $currentpage = $allpages;
  180.                               }
  181.                
  182.                
  183.                
  184.                
  185.                       /*****************************************************
  186.                       ** Set offset value for template (mainly for delete
  187.                       ** and edit entry link in admin template
  188.                       *****************************************************/
  189.                               $offset = $currentpage;
  190.                
  191.                
  192.                
  193.                
  194.                
  195.                       /*****************************************************
  196.                       ** Browse pages - next - previous link
  197.                       *****************************************************/
  198.                               if ($start < $result_number - $limit) {
  199.                                   $previous_start = $currentpage - 1;
  200.                                   $previous_result_page = 'true ';
  201.                               } else {
  202.                                   $previous_result_page = '';
  203.                               }
  204.                
  205.                
  206.                               if ($start > 0) {
  207.                                   $next_start = $currentpage + 1;
  208.                                   $next_result_page = 'true';
  209.                               } else {
  210.                                   $next_result_page = '';
  211.                               }
  212.                
  213.                
  214.                
  215.                       /*****************************************************
  216.                       ** Pre-select results
  217.                       *****************************************************/
  218.                               $sql = "SELECT entry_id FROM " . ENTRY_TABLE . " LIMIT " . $start . ", " . $limit;
  219.                
  220.                
  221.                               if ($result_range = $db->db_search_entries($sql)) {
  222.                
  223.                                   $between_start = $result_range[0]['entry_id'];
  224.                                   $between_end   = $result_range[count($result_range)-1]['entry_id'];
  225.                
  226.                                   $id_range = " AND t1.entry_id BETWEEN " . $between_start . " AND " . $between_end;
  227.                
  228.                               } else {
  229.                                   $id_range = '';
  230.                               }
  231.                
  232.                
  233.                
  234.                
  235.                       /*****************************************************
  236.                       ** Select content
  237.                       *****************************************************/
  238.                               $sql = "  SELECT      t1.entry_id, t1.full_text,
  239.                                                    t2.data_id, t2.entry_id, t2.data_name, t2.data_content
  240.                              
  241.                                        FROM        " . ENTRY_TABLE . " AS t1,
  242.                                                    " . DATA_TABLE . "  AS t2
  243.                              
  244.                                        WHERE       t2.entry_id = t1.entry_id " . $id_range . "
  245.                                        ORDER BY    t1.entry_id DESC";
  246.                
  247.                               if ($search_result = $db->db_search_entries($sql)) {
  248.                
  249.                                   $new_search_result = data_loop($search_result, 'entry_id', 'true');
  250.                                   $guestbook_entries = array_values($new_search_result);
  251.                
  252.                               }
  253.                
  254.                
  255.                
  256.                
  257.                       /*****************************************************
  258.                       ** Apply row class
  259.                       *****************************************************/
  260.                               while (list($key, $val) = each($guestbook_entries))
  261.                               {
  262.                                   if (!isset($rowclass) or $rowclass == 'lightrow') {
  263.                                       $rowclass = 'darkrow';
  264.                                   } else {
  265.                                       $rowclass = 'lightrow';
  266.                                   }
  267.                
  268.                                   $guestbook_entries[$key]['rowclass'] = $rowclass;
  269.                               }
  270.                
  271.                
  272.                
  273.                
  274.                       /*****************************************************
  275.                       ** Page statistics
  276.                       *****************************************************/
  277.                               // $currentpage = ceil($start / $results_per_page) + 1;
  278.                
  279.                
  280.                
  281.                
  282.                       /*****************************************************
  283.                       ** Generate direct page link menu
  284.                       *****************************************************/
  285.                               $pagelink = 0;
  286.                               $i        = 1;
  287.                
  288.                               if ($allpages > 1) {
  289.                
  290.                                   while ($i <= $allpages) {
  291.                
  292.                                       if ($i == $currentpage) {
  293.                                           $link_class = 'currentpage';
  294.                                       } else {
  295.                                           $link_class = 'allpages';
  296.                                       }
  297.                
  298.                                       $page_direct[] = array('page'       => $i++,
  299.                                                              'link'       => $pagelink,
  300.                                                              'file_name'  => $file_name,
  301.                                                              'link_class' => $link_class);
  302.                
  303.                                       $pagelink += $results_per_page;
  304.                                   }
  305.                               }
  306.                
  307.                               $start_link = 1;
  308.                               $end_link   = $allpages;
  309.                
  310.                
  311.                
  312.                
  313.                       /*****************************************************
  314.                       ** Cut off oversized direct page links
  315.                       *****************************************************/
  316.                               if (isset($direct_page_links) and !empty($direct_page_links) and isset($page_direct) and count($page_direct) > $direct_page_links) {
  317.                
  318.                                   $half_offset = ceil($direct_page_links / 2 );
  319.                                   $offset_end  = $allpages - $direct_page_links;
  320.                
  321.                                   if ($currentpage <= $half_offset) {
  322.                                       $start_element = 0;
  323.                                   }
  324.                
  325.                                   if (!isset($start_element) and $currentpage > $half_offset and ($currentpage - $half_offset) < $offset_end) {
  326.                                       $start_element = $currentpage - $half_offset;
  327.                                       $page_link_start = 'true';
  328.                                   }
  329.                
  330.                                   if (!isset($start_element) and $currentpage >= $offset_end) {
  331.                                       $start_element = $offset_end;
  332.                                       $page_link_start = 'true';
  333.                                   } else {
  334.                                       $page_link_end = 'true';
  335.                                   }
  336.                
  337.                                   if (isset($start_element)) {
  338.                                       $page_direct = array_slice($page_direct, $start_element, $direct_page_links);
  339.                                   }
  340.                               }
  341.                
  342.                
  343.                
  344.                           } else {
  345.                               $result_number = 0;
  346.                           }
  347.  
  348.  
  349.  
  350.  
  351.               /*****************************************************
  352.               ** End database connect select if
  353.               *****************************************************/          
  354.               }
  355.           }
  356.  
  357.  
  358.  
  359.  
  360.   /*****************************************************
  361.   ** Load part html template
  362.   *****************************************************/
  363.           $tpl->load_file('guest', $script_root . $path['templates'] . $file['entries']);
  364.  
  365.           $main_content = $tpl->return_file('guest');
  366.  
  367.  
  368.  
  369.  
  370.   /*****************************************************
  371.   ** Load main layout html template
  372.   *****************************************************/
  373.           $tpl->load_file('main', $script_root . $path['templates'] . $file['main_layout']);
  374.           $tpl->register('main', 'main_content');
  375.           $tpl->parse('main');
  376.          
  377.           $tpl->files['guest'] = $tpl->return_file('main');
  378.  
  379.  
  380.  
  381.  
  382.   /*****************************************************
  383.   ** Load entry detail html template
  384.   *****************************************************/
  385.           $tpl->load_file('detail', $script_root . $path['templates'] . $file['entry_detail']);
  386.           $tpl->parse_loop('detail', 'guestbook_entries');
  387.  
  388.           $entry_detail = $tpl->return_file('detail');
  389.  
  390.           $tpl->register('guest', 'entry_detail');
  391.  
  392.  
  393.  
  394.  
  395.   /*****************************************************
  396.   ** Register language file and additional text array
  397.   *****************************************************/
  398.           if (isset ($include_files) and is_array ($include_files)) {
  399.               reset ($include_files);
  400.               while(list($key, $val) = each($include_files))
  401.               {
  402.                   if ($file_content = include_content($val)) {
  403.                       $$key = $file_content;
  404.                   } else {
  405.                       $$key = '<pre>[' . $txt['txt_file_not_found'] . ': ' . $val . ']</pre>';
  406.                   }
  407.                   $tpl->register('guest', $key);
  408.               }
  409.           }
  410.          
  411.           if (isset ($txt) and is_array ($txt)) {
  412.               reset ($txt);
  413.               while(list($key, $val) = each($txt))
  414.               {
  415.                   $$key = $val;
  416.                   $tpl->register('guest', $key);
  417.               }
  418.           }
  419.  
  420.  
  421.           if (isset($add_text) and is_array($add_text)) {
  422.               reset ($add_text);
  423.               while(list($key, $val) = each($add_text))
  424.               {
  425.                   $$key = $val;
  426.                   $tpl->register('guest', $key);
  427.               }
  428.           }
  429.  
  430.  
  431.  
  432.  
  433.   /*****************************************************
  434.   ** Parse template
  435.   *****************************************************/
  436.           $tpl->register('guest', array('query_string',
  437.                                          'previous_start',
  438.                                          'next_start',
  439.                                          'file_name',
  440.                                          'allpages',
  441.                                          'currentpage',
  442.                                          'start_link',
  443.                                          'end_link',
  444.                                          'offset',
  445.                                          'entries'
  446.                                          ));
  447.  
  448.           $tpl->parse_loop('guest', 'message');
  449.  
  450.           $tpl->parse_if('guest', 'previous_result_page');
  451.           $tpl->parse_if('guest', 'next_result_page');
  452.           $tpl->parse_if('guest', 'page_link_end');
  453.           $tpl->parse_if('guest', 'page_link_start');
  454.           $tpl->parse_if('guest', 'logged_in');
  455.           $tpl->parse_loop('guest', 'page_direct'); @eval($conf_var);
  456.  
  457.           debug_mode(script_runtime($runtime_start), 'Script Runtime');
  458.  
  459.  
  460.  
  461.  
  462. ?>
  463. <html>
  464. <body>
  465. Here's a guestbook.. :>
  466. </body>
  467. </html>