Quick Search:

View

Revision:

Diff

Diff from 1070 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/admin/includes/applications/administrators/administrators.php

Annotated File View

hpdl
1016
1 <?php
2 /*
3   $Id: $
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2006 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   class osC_Content_Administrators extends osC_Template {
14
15 /* Private variables */
16
17     var $_module = 'administrators',
hpdl
1070
18         $_page_title = HEADING_TITLE,
hpdl
1016
19         $_page_contents = 'administrators.php';
20
21 /* Class constructor */
22
23     function osC_Content_Administrators() {
24       if (!isset($_GET['action'])) {
25         $_GET['action'] = '';
26       }
27
28       if (!isset($_GET['page']) || (isset($_GET['page']) && !is_numeric($_GET['page']))) {
29         $_GET['page'] = 1;
30       }
31
32       if (!empty($_GET['action'])) {
33         switch ($_GET['action']) {
34           case 'save':
35             $this->_save();
36             break;
37
38           case 'deleteconfirm':
39             $this->_delete();
40             break;
41         }
42       }
43     }
44
hpdl
1070
45     function sortAccessList($a, $b) {
46       if ($a['group'] == $b['group']) {
47         if ($a['text'] == $b['text']) {
48           return 0;
49         }
50
51         return ($a['text'] < $b['text']) ? -1 : 1;
52       }
53
54       return ($a['group'] < $b['group']) ? -1 : 1;
55     }
56
hpdl
1016
57 /* Private methods */
58
59     function _save() {
60       global $osC_Database, $osC_MessageStack;
61
hpdl
1070
62       $error = false;
hpdl
1016
63
hpdl
1070
64       $osC_Database->startTransaction();
65
hpdl
1016
66       if (isset($_GET['aID']) && is_numeric($_GET['aID'])) {
67         $Qadmin = $osC_Database->query('update :table_administrators set user_name = :user_name where id = :id');
68         $Qadmin->bindInt(':id', $_GET['aID']);
69       } else {
70         $Qadmin = $osC_Database->query('insert into :table_administrators (user_name) values (:user_name)');
71       }
72       $Qadmin->bindTable(':table_administrators', TABLE_ADMINISTRATORS);
73       $Qadmin->bindValue(':user_name', $_POST['user_name']);
74       $Qadmin->execute();
75
hpdl
1070
76       if ( !$osC_Database->isError() ) {
77         $id = (isset($_GET['aID']) && is_numeric($_GET['aID']) ? $_GET['aID'] : $osC_Database->nextID());
hpdl
1016
78
hpdl
1070
79         if ( !empty($_POST['user_password']) ) {
80           $Qadmin = $osC_Database->query('update :table_administrators set user_password = :user_password where id = :id');
81           $Qadmin->bindTable(':table_administrators', TABLE_ADMINISTRATORS);
82           $Qadmin->bindValue(':user_password', osc_encrypt_string(trim($_POST['user_password'])));
83           $Qadmin->bindInt(':id', $id);
84           $Qadmin->execute();
85
86           if ( $osC_Database->isError() ) {
87             $error = true;
88           }
89         }
90       } else {
91         $error = true;
hpdl
1016
92       }
93
hpdl
1070
94       if ( $error === false ) {
95         $modules_array = array();
96
97         if ( isset($_POST['modules']) ) {
98           if ( in_array( '*', $_POST['modules'] ) ) {
99             $_POST['modules'] = array('*');
100           }
101
102           foreach ($_POST['modules'] as $module) {
103             $modules_array[] = '\'' . $module . '\'';
104
105             $Qcheck = $osC_Database->query('select administrators_id from :table_administrators_access where administrators_id = :administrators_id and module = :module limit 1');
106             $Qcheck->bindTable(':table_administrators_access', TABLE_ADMINISTRATORS_ACCESS);
107             $Qcheck->bindInt(':administrators_id', $id);
108             $Qcheck->bindValue(':module', $module);
109             $Qcheck->execute();
110
111             if ( $Qcheck->numberOfRows() < 1 ) {
112               $Qinsert = $osC_Database->query('insert into :table_administrators_access (administrators_id, module) values (:administrators_id, :module)');
113               $Qinsert->bindTable(':table_administrators_access', TABLE_ADMINISTRATORS_ACCESS);
114               $Qinsert->bindInt(':administrators_id', $id);
115               $Qinsert->bindValue(':module', $module);
116               $Qinsert->execute();
117
118               if ( $osC_Database->isError() ) {
119                 $error = true;
120                 break;
121               }
122             }
123           }
124         }
125       }
126
127       if ( $error === false ) {
128         $Qdel = $osC_Database->query('delete from :table_administrators_access where administrators_id = :administrators_id');
129
130         if ( !empty($modules_array) ) {
131           $Qdel->appendQuery('and module not in (:module)');
132           $Qdel->bindRaw(':module', implode(',', $modules_array));
133         }
134
135         $Qdel->bindTable(':table_administrators_access', TABLE_ADMINISTRATORS_ACCESS);
136         $Qdel->bindInt(':administrators_id', $id);
137         $Qdel->execute();
138
139         if ( $osC_Database->isError() ) {
140           $error = true;
141         }
142       }
143
144       if ( $error === false ) {
145         $osC_Database->commitTransaction();
146
hpdl
1016
147         $osC_MessageStack->add_session($this->_module, SUCCESS_DB_ROWS_UPDATED, 'success');
148       } else {
hpdl
1070
149         $osC_Database->rollbackTransaction();
150
hpdl
1016
151         $osC_MessageStack->add_session($this->_module, ERROR_DB_ROWS_NOT_UPDATED, 'error');
152       }
153
hpdl
1070
154       osc_redirect(osc_href_link_admin(FILENAME_DEFAULT, $this->_module . '&page=' . $_GET['page'] . (isset($id) ? '&aID=' . $id : '')));
hpdl
1016
155     }
156
157     function _delete() {
158       global $osC_Database, $osC_MessageStack;
159
160       if (isset($_GET['aID']) && is_numeric($_GET['aID'])) {
hpdl
1070
161         $osC_Database->startTransaction();
162
163         $Qdel = $osC_Database->query('delete from :table_administrators_access where administrators_id = :administrators_id');
164         $Qdel->bindTable(':table_administrators_access', TABLE_ADMINISTRATORS_ACCESS);
165         $Qdel->bindInt(':administrators_id', $_GET['aID']);
166         $Qdel->execute();
167
hpdl
1016
168         $Qdel = $osC_Database->query('delete from :table_administrators where id = :id');
169         $Qdel->bindTable(':table_administrators', TABLE_ADMINISTRATORS);
170         $Qdel->bindInt(':id', $_GET['aID']);
171         $Qdel->execute();
172
hpdl
1070
173         $osC_Database->commitTransaction();
174
hpdl
1016
175         $osC_MessageStack->add_session($this->_module, SUCCESS_DB_ROWS_UPDATED, 'success');
176       }
177
178       osc_redirect(osc_href_link_admin(FILENAME_DEFAULT, $this->_module . '&page=' . $_GET['page']));
179     }
180   }
181 ?>