[ Index ]

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

title

Body

[close]

/include/inc_module/mod_shop/inc/ -> processing.categories.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  
  31  if($action == 'edit') {
  32  
  33  
  34      $plugin['data']['cat_id']    = intval($_GET['edit']);
  35  
  36      if( isset($_POST['cat_id']) ) {
  37      
  38          // check if form should be closed only -> and back to listing mode
  39          if( isset($_POST['close']) ) {
  40              headerRedirect( shop_url('controller=cat', '') );
  41          }
  42      
  43          $plugin['data']['cat_changedate']    = time();
  44          $plugin['data']['cat_name']            = clean_slweg($_POST['cat_name']);
  45          $plugin['data']['cat_info']            = clean_slweg($_POST['cat_info']);
  46          $plugin['data']['cat_status']        = empty($_POST['cat_status']) ? 0 : 1;
  47          $plugin['data']['cat_pid']            = intval($_POST['cat_pid']);
  48          
  49          if(!$plugin['data']['cat_name']) {
  50              $plugin['error']['cat_name'] = 'No name';
  51          } else {    
  52              $sql  = 'SELECT COUNT(cat_id) FROM '.DB_PREPEND.'phpwcms_categories WHERE ';
  53              $sql .= "cat_type='module_shop' AND cat_name LIKE '". aporeplace($plugin['data']['cat_name']) ."'";
  54              $sql .= $plugin['data']['cat_id'] ? ' AND cat_id != ' . $plugin['data']['cat_id'] : '';
  55              if( _dbQuery($sql, 'COUNT') ) {
  56                  $plugin['error']['cat_name'] = 'Duplicate category name';
  57              }
  58          }        
  59          
  60          if( empty($plugin['error'] )) {
  61          
  62              // Update
  63              if( $plugin['data']['cat_id'] ) {
  64              
  65                  $sql  = 'UPDATE '.DB_PREPEND.'phpwcms_categories SET ';
  66                  $sql .= "cat_changedate = '".aporeplace( date('Y-m-d H:i:s', $plugin['data']['cat_changedate']) )."', ";
  67                  $sql .= "cat_pid = ".$plugin['data']['cat_pid'].", ";
  68                  $sql .= "cat_status = ".$plugin['data']['cat_status'].", ";
  69                  $sql .= "cat_name = '".aporeplace($plugin['data']['cat_name'])."', ";
  70                  $sql .= "cat_info = '".aporeplace($plugin['data']['cat_info'])."' ";
  71                  $sql .= "WHERE cat_type='module_shop' AND cat_id = " . $plugin['data']['cat_id'];
  72                  
  73                  _dbQuery($sql, 'UPDATE');
  74              
  75              // INSERT
  76              } else {
  77  
  78                  $sql  = 'INSERT INTO '.DB_PREPEND.'phpwcms_categories (';
  79                  $sql .= 'cat_type, cat_pid, cat_createdate, cat_changedate, cat_status, cat_name, cat_info';
  80                  $sql .= ') VALUES (';
  81                  $sql .= "'module_shop', ";
  82                  $sql .= $plugin['data']['cat_pid'].', ';
  83                  $sql .= "'".aporeplace( date('Y-m-d H:i:s', $plugin['data']['cat_changedate']) )."', ";            
  84                  $sql .= "'".aporeplace( date('Y-m-d H:i:s', $plugin['data']['cat_changedate']) )."', ";
  85                  $sql .= $plugin['data']['cat_status'].", ";
  86                  $sql .= "'".aporeplace($plugin['data']['cat_name'])."', ";
  87                  $sql .= "'".aporeplace($plugin['data']['cat_info'])."'";
  88                  $sql .= ')';
  89              
  90                  $result = _dbQuery($sql, 'INSERT');
  91                  
  92                  if( !empty($result['INSERT_ID']) ) {
  93                      $plugin['data']['cat_id']    = $result['INSERT_ID'];
  94                  }
  95              
  96              }
  97          
  98              // save and back to listing mode
  99              if( isset($_POST['save']) ) {
 100                  headerRedirect( shop_url('controller=cat', '') );
 101              } else {
 102                  headerRedirect( shop_url( array('controller=cat', 'edit='.$plugin['data']['cat_id']), '') );
 103              }
 104              
 105          }
 106  
 107  
 108      } elseif( $plugin['data']['cat_id'] == 0 ) {
 109      
 110          $plugin['data']['cat_id']            = 0;
 111          $plugin['data']['cat_pid']            = 0;    
 112          $plugin['data']['cat_changedate']    = time();
 113          $plugin['data']['cat_name']            = '';
 114          $plugin['data']['cat_info']            = '';
 115          $plugin['data']['cat_status']        = 1;    
 116      
 117      } else {
 118  
 119          $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_categories WHERE ';
 120          $sql .= "cat_type='module_shop' AND cat_id = " . $plugin['data']['cat_id'] . ' LIMIT 1';
 121  
 122          $plugin['data'] = _dbQuery($sql);
 123          
 124          if( isset($plugin['data'][0]) ) {
 125              $plugin['data'] = $plugin['data'][0];
 126  
 127              $plugin['data']['cat_changedate'] = strtotime($plugin['data']['cat_changedate']);
 128              
 129          } else {
 130              headerRedirect( shop_url('controller=cat', '') );
 131          }
 132  
 133      }
 134  
 135  } elseif($action == 'status') {
 136  
 137      list($plugin['data']['cat_id'], $plugin['data']['cat_status']) = explode( '-', $_GET['status'] );
 138      
 139      $plugin['data']['cat_id']        = intval($plugin['data']['cat_id']);
 140      $plugin['data']['cat_status']    = empty($plugin['data']['cat_status']) ? 1 : 0;
 141  
 142      $sql  = 'UPDATE '.DB_PREPEND.'phpwcms_categories SET ';
 143      $sql .= "cat_status = ".$plugin['data']['cat_status']." ";
 144      $sql .= "WHERE cat_type='module_shop' AND cat_id = " . $plugin['data']['cat_id'];
 145      
 146      _dbQuery($sql, 'UPDATE');
 147  
 148      headerRedirect( shop_url('controller=cat', '') );
 149  
 150  } elseif($action == 'delete') {
 151  
 152      $plugin['data']['cat_id']        = intval($_GET['delete']);
 153  
 154      $sql  = 'UPDATE '.DB_PREPEND.'phpwcms_categories SET ';
 155      $sql .= "cat_status = 9 ";
 156      $sql .= "WHERE cat_type='module_shop' AND ";
 157      $sql .= "(cat_id = " . $plugin['data']['cat_id'] . " OR cat_pid = " . $plugin['data']['cat_id'] . ")";
 158      
 159      _dbQuery($sql, 'UPDATE');
 160  
 161      headerRedirect( shop_url('controller=cat', '') );
 162  
 163  }
 164  
 165  
 166  ?>


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