Annotation of /com_supacart/trunk/admin_files/classes/ps_module.php
Parent Directory
|
Revision Log
Revision 4 - (view) (download)
| 1 : | andphe | 4 | <?php |
| 2 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 3 : | /** | ||
| 4 : | * | ||
| 5 : | * @version $Id: ps_module.php 617 2007-01-04 19:43:08Z soeren_nb $ | ||
| 6 : | * @package SupaCart | ||
| 7 : | * @subpackage classes | ||
| 8 : | * See COPYRIGHT.php for copyright notices and details. | ||
| 9 : | * @license GNU/GPL Version 2, see LICENSE.php | ||
| 10 : | * SupaCart is free software, originally derived from Virtuemart. This version may have been modified pursuant | ||
| 11 : | * to the GNU General Public License, and as distributed it includes or | ||
| 12 : | * is derivative of works licensed under the GNU General Public License or | ||
| 13 : | * other free or open source software licenses. | ||
| 14 : | * See /administrator/components/com_supacart/COPYRIGHT.php for copyright notices and details. | ||
| 15 : | * | ||
| 16 : | * http://www.supacart.com | ||
| 17 : | */ | ||
| 18 : | |||
| 19 : | class ps_module { | ||
| 20 : | var $classname = "ps_module"; | ||
| 21 : | var $error; | ||
| 22 : | |||
| 23 : | |||
| 24 : | /************************************************************************** | ||
| 25 : | * name: validate_add() | ||
| 26 : | * created by: pablo | ||
| 27 : | * description: validate the given data before adding a function record | ||
| 28 : | * parameters: | ||
| 29 : | * returns: | ||
| 30 : | **************************************************************************/ | ||
| 31 : | |||
| 32 : | function validate_add(&$d) { | ||
| 33 : | global $db; | ||
| 34 : | |||
| 35 : | if (!$d[ 'module_name' ]) { | ||
| 36 : | $this->error = "ERROR: You must enter a name for the module."; | ||
| 37 : | return False; | ||
| 38 : | } | ||
| 39 : | if ($d[ 'module_name' ]) { | ||
| 40 : | $q = "SELECT count(*) as rowcnt from #__{sc}_module where module_name='" . $d[ 'module_name' ] . "'"; | ||
| 41 : | $db->setQuery($q); | ||
| 42 : | $db->next_record(); | ||
| 43 : | if ($db->f("rowcnt") > 0) { | ||
| 44 : | $this->error = "The given module name already exists."; | ||
| 45 : | return False; | ||
| 46 : | } | ||
| 47 : | } | ||
| 48 : | |||
| 49 : | if (!$d[ 'module_perms' ]) { | ||
| 50 : | $this->error = "ERROR: You must enter permissions for the module."; | ||
| 51 : | return false; | ||
| 52 : | } | ||
| 53 : | if (!$d[ 'list_order' ]) { | ||
| 54 : | $d[ 'list_order' ] = "99"; | ||
| 55 : | } | ||
| 56 : | return True; | ||
| 57 : | } | ||
| 58 : | |||
| 59 : | /************************************************************************** | ||
| 60 : | * name: validate_delete() | ||
| 61 : | * created by: pablo | ||
| 62 : | * description: validate the given data before deleting a function record | ||
| 63 : | * parameters: | ||
| 64 : | * returns: | ||
| 65 : | **************************************************************************/ | ||
| 66 : | |||
| 67 : | function validate_delete($module_id) { | ||
| 68 : | global $db; | ||
| 69 : | |||
| 70 : | if (empty($module_id)) { | ||
| 71 : | $this->error = "ERROR: Please select a module to delete."; | ||
| 72 : | return False; | ||
| 73 : | } | ||
| 74 : | |||
| 75 : | $db->query( "SELECT module_name FROM #__{sc}_module WHERE module_id='$module_id'" ); | ||
| 76 : | $db->next_record(); | ||
| 77 : | $name = $db->f("module_name"); | ||
| 78 : | if( $name == "shop" || $name == "vendor" || $name == "product" || $name == "store" || $name == "order" || $name == "admin" | ||
| 79 : | || $name == "checkout" || $name == "account" ) { | ||
| 80 : | $this->error = "Error: The module $name is a core module. It cannot be deleted."; | ||
| 81 : | return false; | ||
| 82 : | } | ||
| 83 : | return True; | ||
| 84 : | |||
| 85 : | } | ||
| 86 : | |||
| 87 : | |||
| 88 : | /************************************************************************** | ||
| 89 : | * name: validate_update() | ||
| 90 : | * created by: pablo | ||
| 91 : | * description: validate the given data before updating a function record | ||
| 92 : | * parameters: | ||
| 93 : | * returns: | ||
| 94 : | **************************************************************************/ | ||
| 95 : | |||
| 96 : | function validate_update(&$d) { | ||
| 97 : | |||
| 98 : | if (!$d[ 'module_name' ]) { | ||
| 99 : | $this->error = "ERROR: You must enter a name for the module."; | ||
| 100 : | return False; | ||
| 101 : | } | ||
| 102 : | if (!$d[ 'module_perms' ]) { | ||
| 103 : | $this->error = "ERROR: You must enter permissions for the module."; | ||
| 104 : | return False; | ||
| 105 : | } | ||
| 106 : | if (!$d[ 'list_order' ]) { | ||
| 107 : | $d[ 'list_order' ] = "99"; | ||
| 108 : | } | ||
| 109 : | return True; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | |||
| 113 : | /************************************************************************** | ||
| 114 : | * name: add() | ||
| 115 : | * created by: pablo | ||
| 116 : | * description: creates a new function record | ||
| 117 : | * parameters: | ||
| 118 : | * returns: | ||
| 119 : | **************************************************************************/ | ||
| 120 : | function add(&$d) { | ||
| 121 : | global $db; | ||
| 122 : | |||
| 123 : | $hash_secret="PHPShopIsCool"; | ||
| 124 : | |||
| 125 : | $timestamp = time(); | ||
| 126 : | |||
| 127 : | if (!$this->validate_add($d)) { | ||
| 128 : | $d[ 'error' ] = $this->error; | ||
| 129 : | return False; | ||
| 130 : | } | ||
| 131 : | |||
| 132 : | foreach ($d as $key => $value) | ||
| 133 : | $d[$key] = addslashes($value); | ||
| 134 : | |||
| 135 : | $q = "INSERT INTO #__{sc}_module (module_name, module_description, "; | ||
| 136 : | $q .= "module_perms, "; | ||
| 137 : | $q .= "module_publish, list_order) "; | ||
| 138 : | $q .= " VALUES ('"; | ||
| 139 : | $q .= $d[ 'module_name' ] . "','"; | ||
| 140 : | $q .= $d[ 'module_description' ] . "','"; | ||
| 141 : | $q .= $d[ 'module_perms' ] . "','"; | ||
| 142 : | $q .= $d[ 'module_publish' ] . "','"; | ||
| 143 : | $q .= $d[ 'list_order' ] . "' )"; | ||
| 144 : | |||
| 145 : | $db->setQuery($q); | ||
| 146 : | $db->query(); | ||
| 147 : | return True; | ||
| 148 : | |||
| 149 : | } | ||
| 150 : | |||
| 151 : | /************************************************************************** | ||
| 152 : | * name: update() | ||
| 153 : | * created by: pablo | ||
| 154 : | * description: updates function information | ||
| 155 : | * parameters: | ||
| 156 : | * returns: | ||
| 157 : | **************************************************************************/ | ||
| 158 : | function update(&$d) { | ||
| 159 : | global $db; | ||
| 160 : | |||
| 161 : | $timestamp = time(); | ||
| 162 : | |||
| 163 : | if (!$this->validate_update($d)) { | ||
| 164 : | $d[ 'error' ] = $this->error; | ||
| 165 : | return False; | ||
| 166 : | } | ||
| 167 : | |||
| 168 : | foreach ($d as $key => $value) { | ||
| 169 : | if (!is_array($value)) | ||
| 170 : | $d[$key] = addslashes($value); | ||
| 171 : | } | ||
| 172 : | |||
| 173 : | $q = "UPDATE #__{sc}_module SET "; | ||
| 174 : | $q .= "module_name='" . $d[ 'module_name' ]; | ||
| 175 : | $q .= "',module_perms='" . $d[ 'module_perms' ]; | ||
| 176 : | $q .= "',module_description='" . $d[ 'module_description' ]; | ||
| 177 : | $q .= "',module_publish='" . $d[ 'module_publish' ]; | ||
| 178 : | $q .= "',list_order='" . $d[ 'list_order' ]; | ||
| 179 : | $q .= "' WHERE module_id='" . $d[ 'module_id' ] . "'"; | ||
| 180 : | |||
| 181 : | $db->setQuery($q); | ||
| 182 : | |||
| 183 : | $db->query(); | ||
| 184 : | |||
| 185 : | return true; | ||
| 186 : | } | ||
| 187 : | |||
| 188 : | /** | ||
| 189 : | * Controller for Deleting Records. | ||
| 190 : | */ | ||
| 191 : | function delete(&$d) { | ||
| 192 : | |||
| 193 : | $record_id = $d["module_id"]; | ||
| 194 : | |||
| 195 : | if( is_array( $record_id)) { | ||
| 196 : | foreach( $record_id as $record) { | ||
| 197 : | if( !$this->delete_record( $record, $d )) | ||
| 198 : | return false; | ||
| 199 : | } | ||
| 200 : | return true; | ||
| 201 : | } | ||
| 202 : | else { | ||
| 203 : | return $this->delete_record( $record_id, $d ); | ||
| 204 : | } | ||
| 205 : | } | ||
| 206 : | /** | ||
| 207 : | * Deletes one Record. | ||
| 208 : | */ | ||
| 209 : | function delete_record( $record_id, &$d ) { | ||
| 210 : | |||
| 211 : | global $db; | ||
| 212 : | |||
| 213 : | if (!$this->validate_delete($record_id)) { | ||
| 214 : | $d[ 'error' ]=$this->error; | ||
| 215 : | return False; | ||
| 216 : | } | ||
| 217 : | |||
| 218 : | $q = "DELETE from #__{sc}_function WHERE module_id='$record_id'"; | ||
| 219 : | $db->query($q); | ||
| 220 : | |||
| 221 : | $q = "DELETE FROM #__{sc}_module where module_id='$record_id'"; | ||
| 222 : | $db->query($q); | ||
| 223 : | return true; | ||
| 224 : | |||
| 225 : | } | ||
| 226 : | |||
| 227 : | /************************************************************************** | ||
| 228 : | * name: get_dir() | ||
| 229 : | * created by: pablo | ||
| 230 : | * description: | ||
| 231 : | * parameters: | ||
| 232 : | * returns: | ||
| 233 : | **************************************************************************/ | ||
| 234 : | function get_dir($basename) { | ||
| 235 : | $datab = new ps_DB; | ||
| 236 : | |||
| 237 : | $results = array(); | ||
| 238 : | |||
| 239 : | $q = "SELECT module_perms FROM #__{sc}_module where module_name='".$basename."'"; | ||
| 240 : | $datab->query($q); | ||
| 241 : | |||
| 242 : | if ($datab->next_record()) { | ||
| 243 : | $results[ 'perms' ] = $datab->f("module_perms"); | ||
| 244 : | return $results; | ||
| 245 : | } | ||
| 246 : | else { | ||
| 247 : | return false; | ||
| 248 : | } | ||
| 249 : | } | ||
| 250 : | |||
| 251 : | function checkModulePermissions( $calledPage ) { | ||
| 252 : | |||
| 253 : | global $page, $VM_LANG, $error_type, $vmLogger, $perm; | ||
| 254 : | |||
| 255 : | // "shop.browse" => module: shop, page: browse | ||
| 256 : | $my_page= explode ( '.', $page ); | ||
| 257 : | if( empty( $my_page[1] )) { | ||
| 258 : | return false; | ||
| 259 : | } | ||
| 260 : | $modulename = $my_page[0]; | ||
| 261 : | $pagename = $my_page[1]; | ||
| 262 : | |||
| 263 : | |||
| 264 : | $dir_list = $this->get_dir($modulename); | ||
| 265 : | |||
| 266 : | if ($dir_list) { | ||
| 267 : | |||
| 268 : | // Load MODULE-specific CLASS-FILES | ||
| 269 : | include_class( $modulename ); | ||
| 270 : | |||
| 271 : | if ($perm->check( $dir_list[ 'perms' ]) ) { | ||
| 272 : | |||
| 273 : | if ( !file_exists(PAGEPATH.$modulename.".".$pagename.".php") ) { | ||
| 274 : | define( '_VM_PAGE_NOT_FOUND', 1 ); | ||
| 275 : | $error = $VM_LANG->_PHPSHOP_PAGE_404_1; | ||
| 276 : | $error .= ' '.$VM_LANG->_PHPSHOP_PAGE_404_2 ; | ||
| 277 : | $error .= ' "'.$modulename.".".$pagename.'.php"'; | ||
| 278 : | $vmLogger->err( $error ); | ||
| 279 : | return false; | ||
| 280 : | } | ||
| 281 : | return true; | ||
| 282 : | } | ||
| 283 : | else { | ||
| 284 : | define( '_VM_PAGE_NOT_AUTH', 1 ); | ||
| 285 : | $vmLogger->err( $VM_LANG->_PHPSHOP_MOD_NO_AUTH ); | ||
| 286 : | return false; | ||
| 287 : | } | ||
| 288 : | } | ||
| 289 : | else { | ||
| 290 : | $error = $VM_LANG->_PHPSHOP_MOD_NOT_REG; | ||
| 291 : | $error .= '"'.$modulename .'" '. $VM_LANG->_PHPSHOP_MOD_ISNO_REG; | ||
| 292 : | $vmLogger->err( $error ); | ||
| 293 : | return false; | ||
| 294 : | } | ||
| 295 : | |||
| 296 : | } | ||
| 297 : | |||
| 298 : | } | ||
| 299 : | |||
| 300 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

