  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: administrators.php 1850 2009-02-28 03:07:56Z hpdl $ |
| |
| 3 | + | $Id: administrators.php 1851 2009-02-28 03:08:07Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2007 osCommerce |
| |
| 8 | + | Copyright (c) 2009 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | This program is free software; you can redistribute it and/or modify |
| |
11 | 11 | | it under the terms of the GNU General Public License v2 (1991) |
| |
12 | 12 | | as published by the Free Software Foundation. |
| |
13 | 13 | | */ |
| |
14 | 14 | | |
  |
15 | | - | define('OSC_ADMINISTRATORS_ACCESS_MODE_ADD', 'add'); |
| |
16 | | - | define('OSC_ADMINISTRATORS_ACCESS_MODE_SET', 'set'); |
| |
17 | | - | define('OSC_ADMINISTRATORS_ACCESS_MODE_REMOVE', 'remove'); |
| |
18 | | - | |
|
19 | 15 | | class osC_Administrators_Admin { |
  |
20 | | - | function getData($id) { |
| |
| 16 | + | const ACCESS_MODE_ADD = 'add'; |
| |
| 17 | + | const ACCESS_MODE_SET = 'set'; |
| |
| 18 | + | const ACCESS_MODE_REMOVE = 'remove'; |
| |
| 19 | + | |
| |
| 20 | + | public static function get($id) { |
|
21 | 21 | | global $osC_Database; |
| |
22 | 22 | | |
  |
23 | | - | $Qadmin = $osC_Database->query('select id, user_name from :table_administrators where id = :id'); |
| |
| 23 | + | $Qadmin = $osC_Database->query('select * from :table_administrators where id = :id'); |
|
24 | 24 | | $Qadmin->bindTable(':table_administrators', TABLE_ADMINISTRATORS); |
| |
25 | 25 | | $Qadmin->bindInt(':id', $id); |
| |
26 | 26 | | $Qadmin->execute(); |
| |
27 | 27 | | |
  |
28 | | - | $modules = array( 'access_modules' => array() ); |
| |
| 28 | + | $modules = array('access_modules' => array()); |
|
29 | 29 | | |
| |
30 | 30 | | $Qaccess = $osC_Database->query('select module from :table_administrators_access where administrators_id = :administrators_id'); |
| |
31 | 31 | | $Qaccess->bindTable(':table_administrators_access', TABLE_ADMINISTRATORS_ACCESS); |
| |
|
|
 |
… |
|
45 | 45 | | return $data; |
| |
46 | 46 | | } |
| |
47 | 47 | | |
  |
48 | | - | function save($id = null, $data, $modules = null) { |
| |
| 48 | + | public static function getAll($pageset = 1) { |
|
49 | 49 | | global $osC_Database; |
| |
50 | 50 | | |
  |
| 51 | + | if ( !is_numeric($pageset) || (floor($pageset) != $pageset) ) { |
| |
| 52 | + | $pageset = 1; |
| |
| 53 | + | } |
| |
| 54 | + | |
| |
| 55 | + | $result = array('entries' => array()); |
| |
| 56 | + | |
| |
| 57 | + | $Qadmins = $osC_Database->query('select SQL_CALC_FOUND_ROWS * from :table_administrators order by user_name'); |
| |
| 58 | + | $Qadmins->bindTable(':table_administrators', TABLE_ADMINISTRATORS); |
| |
| 59 | + | |
| |
| 60 | + | if ( $pageset !== -1 ) { |
| |
| 61 | + | $Qadmins->setBatchLimit($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS); |
| |
| 62 | + | } |
| |
| 63 | + | |
| |
| 64 | + | $Qadmins->execute(); |
| |
| 65 | + | |
| |
| 66 | + | while ( $Qadmins->next() ) { |
| |
| 67 | + | $result['entries'][] = $Qadmins->toArray(); |
| |
| 68 | + | } |
| |
| 69 | + | |
| |
| 70 | + | $result['total'] = $Qadmins->getBatchSize(); |
| |
| 71 | + | |
| |
| 72 | + | $Qadmins->freeResult(); |
| |
| 73 | + | |
| |
| 74 | + | return $result; |
| |
| 75 | + | } |
| |
| 76 | + | |
| |
| 77 | + | public static function find($search, $pageset = 1) { |
| |
| 78 | + | global $osC_Database; |
| |
| 79 | + | |
| |
| 80 | + | if ( !is_numeric($pageset) || (floor($pageset) != $pageset) ) { |
| |
| 81 | + | $pageset = 1; |
| |
| 82 | + | } |
| |
| 83 | + | |
| |
| 84 | + | $result = array('entries' => array()); |
| |
| 85 | + | |
| |
| 86 | + | $Qadmins = $osC_Database->query('select SQL_CALC_FOUND_ROWS * from :table_administrators where (user_name like :user_name) order by user_name'); |
| |
| 87 | + | $Qadmins->bindTable(':table_administrators', TABLE_ADMINISTRATORS); |
| |
| 88 | + | $Qadmins->bindValue(':user_name', '%' . $search . '%'); |
| |
| 89 | + | |
| |
| 90 | + | if ( $pageset !== -1 ) { |
| |
| 91 | + | $Qadmins->setBatchLimit($pageset, MAX_DISPLAY_SEARCH_RESULTS); |
| |
| 92 | + | } |
| |
| 93 | + | |
| |
| 94 | + | $Qadmins->execute(); |
| |
| 95 | + | |
| |
| 96 | + | while ( $Qadmins->next() ) { |
| |
| 97 | + | $result['entries'][] = $Qadmins->toArray(); |
| |
| 98 | + | } |
| |
| 99 | + | |
| |
| 100 | + | $result['total'] = $Qadmins->getBatchSize(); |
| |
| 101 | + | |
| |
| 102 | + | $Qadmins->freeResult(); |
| |
| 103 | + | |
| |
| 104 | + | return $result; |
| |
| 105 | + | } |
| |
| 106 | + | |
| |
| 107 | + | public static function save($id = null, $data, $modules = null) { |
| |
| 108 | + | global $osC_Database; |
| |
| 109 | + | |
|
51 | 110 | | $error = false; |
| |
52 | 111 | | |
| |
53 | 112 | | $Qcheck = $osC_Database->query('select id from :table_administrators where user_name = :user_name'); |
| |
|
|
 |
… |
|
95 | 154 | | |
| |
96 | 155 | | if ( $error === false ) { |
| |
97 | 156 | | if ( !empty($modules) ) { |
  |
98 | | - | if ( in_array('*', $modules) ) { |
| |
| 157 | + | if ( in_array('0', $modules) ) { |
|
99 | 158 | | $modules = array('*'); |
| |
100 | 159 | | } |
| |
101 | 160 | | |
| |
|
|
 |
… |
|
155 | 214 | | } |
| |
156 | 215 | | } |
| |
157 | 216 | | |
  |
158 | | - | function delete($id) { |
| |
| 217 | + | public static function delete($id) { |
|
159 | 218 | | global $osC_Database; |
| |
160 | 219 | | |
| |
161 | 220 | | $osC_Database->startTransaction(); |
| |
|
|
 |
… |
|
185 | 244 | | return false; |
| |
186 | 245 | | } |
| |
187 | 246 | | |
  |
188 | | - | function setAccessLevels($id, $modules, $mode = OSC_ADMINISTRATORS_ACCESS_MODE_ADD) { |
| |
| 247 | + | public static function setAccessLevels($id, $modules, $mode = self::ACCESS_MODE_ADD) { |
|
189 | 248 | | global $osC_Database; |
| |
190 | 249 | | |
| |
191 | 250 | | $error = false; |
| |
192 | 251 | | |
  |
193 | | - | if ( in_array('*', $modules) ) { |
| |
| 252 | + | if ( in_array('0', $modules) ) { |
|
194 | 253 | | $modules = array('*'); |
| |
195 | 254 | | } |
| |
196 | 255 | | |
| |
197 | 256 | | $osC_Database->startTransaction(); |
| |
198 | 257 | | |
  |
199 | | - | if ( ($mode == OSC_ADMINISTRATORS_ACCESS_MODE_ADD) || ($mode == OSC_ADMINISTRATORS_ACCESS_MODE_SET) ) { |
| |
| 258 | + | if ( ($mode == self::ACCESS_MODE_ADD) || ($mode == self::ACCESS_MODE_SET) ) { |
|
200 | 259 | | foreach ($modules as $module) { |
| |
201 | 260 | | $execute = true; |
| |
202 | 261 | | |
| |
|
|
 |
… |
|
237 | 296 | | } |
| |
238 | 297 | | |
| |
239 | 298 | | if ( $error === false ) { |
  |
240 | | - | if ( ($mode == OSC_ADMINISTRATORS_ACCESS_MODE_REMOVE) || ($mode == OSC_ADMINISTRATORS_ACCESS_MODE_SET) || in_array('*', $modules) ) { |
| |
| 299 | + | if ( ($mode == self::ACCESS_MODE_REMOVE) || ($mode == self::ACCESS_MODE_SET) || in_array('*', $modules) ) { |
|
241 | 300 | | if ( !empty($modules) ) { |
| |
242 | 301 | | $Qdel = $osC_Database->query('delete from :table_administrators_access where administrators_id = :administrators_id'); |
| |
243 | 302 | | |
  |
244 | | - | if ( $mode == OSC_ADMINISTRATORS_ACCESS_MODE_REMOVE ) { |
| |
| 303 | + | if ( $mode == self::ACCESS_MODE_REMOVE ) { |
|
245 | 304 | | if ( !in_array('*', $modules) ) { |
| |
246 | 305 | | $Qdel->appendQuery('and module in (":module")'); |
| |
247 | 306 | | $Qdel->bindRaw(':module', implode('", "', $modules)); |
| |
|
|
 |
… |
|
274 | 333 | | |
| |
275 | 334 | | return false; |
| |
276 | 335 | | } |
  |
| 336 | + | |
| |
| 337 | + | public static function getAccessModules() { |
| |
| 338 | + | global $osC_Language; |
| |
| 339 | + | |
| |
| 340 | + | $osC_DirectoryListing = new osC_DirectoryListing('includes/modules/access'); |
| |
| 341 | + | $osC_DirectoryListing->setIncludeDirectories(false); |
| |
| 342 | + | |
| |
| 343 | + | $modules = array(); |
| |
| 344 | + | |
| |
| 345 | + | foreach ( $osC_DirectoryListing->getFiles() as $file ) { |
| |
| 346 | + | $module = substr($file['name'], 0, strrpos($file['name'], '.')); |
| |
| 347 | + | |
| |
| 348 | + | if ( !class_exists('osC_Access_' . ucfirst($module)) ) { |
| |
| 349 | + | $osC_Language->loadIniFile('modules/access/' . $file['name']); |
| |
| 350 | + | include($osC_DirectoryListing->getDirectory() . '/' . $file['name']); |
| |
| 351 | + | } |
| |
| 352 | + | |
| |
| 353 | + | $module = 'osC_Access_' . ucfirst($module); |
| |
| 354 | + | $module = new $module(); |
| |
| 355 | + | |
| |
| 356 | + | $modules[osC_Access::getGroupTitle( $module->getGroup() )][] = array('id' => $module->getModule(), |
| |
| 357 | + | 'text' => $module->getTitle()); |
| |
| 358 | + | } |
| |
| 359 | + | |
| |
| 360 | + | ksort($modules); |
| |
| 361 | + | |
| |
| 362 | + | return $modules; |
| |
| 363 | + | } |
  |
277 | 364 | | } |
| |
278 | 365 | | ?> |