[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/include/inc_lib/ -> lib.keywords.inc.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // ----------------------------------------------------------------
  24  // obligate check for phpwcms constants
  25  if (!defined('PHPWCMS_ROOT')) {
  26     die("You Cannot Access This Script Directly, Have a Nice Day.");
  27  }
  28  // ----------------------------------------------------------------
  29  
  30  // keyword specific functions
  31  
  32  $BE['HEADER'][]  = getJavaScriptSourceLink('include/inc_js/lib.keyword.js');
  33  
  34  function backend_list_keywords() {
  35  
  36      $list         = '<form name="keywordListing" action="'.html_specialchars(BE_CURRENT_URL).'" method="post">' . LF;
  37      $list        .= LF . '<table cellspacing="0" cellpadding="0" border="0" class="listingTable">' . LF;
  38      $list        .= '    <tr>' . LF;
  39      $list        .= '        <th class="checkbox">All</th>' . LF;
  40      $list        .= '        <th class="entry">Keyword Name</th>' . LF;
  41      $list        .= '        <th class="actions">&nbsp;</th>' . LF;
  42      $list        .= '    </tr>' . LF;
  43      
  44      $sql         = "SELECT * FROM ".DB_PREPEND."phpwcms_keyword WHERE keyword_trash=0 ORDER BY keyword_name";
  45      $keywords     = _dbQuery($sql);
  46      
  47      $c             = 0;
  48  
  49      foreach($keywords as $value) {
  50      
  51          // set alternating class name
  52          $aclass  = ($c % 2) ? ' class="alternating"' : '';
  53      
  54          $list    .= '    <tr'.$aclass.'>' . LF;
  55          $list    .= '        <td class="checkbox"><input type="checkbox" value="1" name="check['.$value['keyword_id'].']" id="check_'.$value['keyword_id'].'" /></td>' . LF;
  56          $list    .= '        <td class="entry">' . html_specialchars($value['keyword_name']) . '</td>' . LF;
  57          $list    .= '        <td class="actions"><button type="button" onclick="keyword_submit_edit(this, '.$value['keyword_id'].');">Edit</button></td>' .LF;
  58          $list    .= '    </tr>' . LF;
  59          
  60          $c++;
  61  
  62      }
  63      
  64      $list        .= '</table>' . LF;
  65      $list        .= '<input type="hidden" name="keyword_selected_id" value="0" />';
  66      $list         .= '<input type="hidden" name="keyword_action" value="" />';
  67      $list        .= LF . '</form>' . LF;
  68  
  69      return $list;
  70  
  71  }
  72  
  73  function backend_edit_keywords() {
  74  
  75      $list         = '';
  76      $keyword_id     = empty($_POST['keyword_selected_id']) ? 0 : intval($_POST['keyword_selected_id']);
  77          
  78      // UPDATE keyword
  79      if(isset($_POST['send_update'])) {
  80          
  81          $update = backend_getKeywordPostValues();
  82          
  83          if(empty($update['keyword_name'])) {
  84              // False, empty Keyword Name
  85              $list .= '<p>Proof your input. Keyword name had no value. Value was reset.</p>';
  86          } else {
  87              
  88              $sql      = "UPDATE ".DB_PREPEND."phpwcms_keyword SET ";
  89              $sql    .= "keyword_name='" . aporeplace($update['keyword_name']) ."' ";
  90              $sql    .= "WHERE keyword_id=".$keyword_id." ";
  91              $sql    .= "AND keyword_name!='" . aporeplace($update['keyword_name']) ."' LIMIT 1";
  92              
  93              $update['result'] = _dbQuery($sql, 'UPDATE');
  94              
  95          }
  96      
  97      // INSERT keyword
  98      } elseif(isset($_POST['send_insert'])) {
  99      
 100          $insert = backend_getKeywordPostValues();
 101          
 102          if(empty($insert['keyword_name'])) {
 103              // False, empty Keyword Name
 104              $list .= '<p>Proof your input. Keyword name had no value. Value was reset.</p>';
 105          } else {
 106  
 107              // 1st check if keyword does not exist
 108              $sql       = "SELECT * FROM ".DB_PREPEND."phpwcms_keyword ";
 109              $sql    .= "WHERE keyword_trash=0 AND keyword_name='" . aporeplace($insert['keyword_name']) ."'";
 110              $check     = _dbQuery($sql);
 111              
 112              if(empty($check[0])) {
 113              
 114                  $sql  = "INSERT INTO ".DB_PREPEND."phpwcms_keyword SET ";
 115                  $sql .= "keyword_name='" . aporeplace($insert['keyword_name']) ."'";
 116                  
 117                  $insert['result'] = _dbQuery($sql, 'INSERT');
 118                  $keyword_id          = $insert['result']['INSERT_ID'];
 119                  
 120              } else {
 121  
 122                  $list .= '<p>No new keyword created. Keyword name must be unique.</p>';
 123  
 124              }
 125          }
 126      
 127      }
 128      
 129      $sql         = "SELECT * FROM ".DB_PREPEND."phpwcms_keyword WHERE keyword_trash=0 AND keyword_id=" . $keyword_id." LIMIT 1";
 130      $keyword     = _dbQuery($sql);
 131      
 132      if(!$keyword) return '<p>No keyword could be found for the given ID</p>';
 133      
 134      $list        .= '<form name="keywordEditing" action="'.html_specialchars(BE_CURRENT_URL).'" method="post">' . LF;
 135      
 136      // edit values
 137      $list        .= '<div class="inputText">';
 138      $list        .= '<label for="keyword_name">Keyword name:</label>';
 139      $list        .= '<input type="text" name="keyword_name" id="keyword_name" value="'.html_specialchars($keyword[0]['keyword_name']).'" />';
 140      $list        .= '</div>' . LF;
 141  
 142      $list        .= '<div class="inputButton">';
 143      $list        .= '<button type="submit" name="send_update">Update</button>';
 144      $list        .= '<button type="submit" name="send_insert">New</button>';    
 145      $list        .= '</div>' . LF;
 146  
 147      // hidden values
 148      $list        .= '<input type="hidden" name="keyword_selected_id" value="'.$keyword_id.'" />';
 149      $list         .= '<input type="hidden" name="keyword_action" value="edit" />';
 150      $list        .= LF . '</form>' . LF;
 151  
 152      return $list;
 153      
 154  }
 155  
 156  function backend_getKeywordPostValues() {
 157  
 158      $value = array();
 159      $value['keyword_name']    = isset($_POST['keyword_name']) ? clean_slweg($_POST['keyword_name']) : '';
 160      return $value;
 161  
 162  }
 163  
 164  ?>


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7