Quick Search:

View

Revision:

Diff

Diff from 1085 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
1085
64       $Qcheck = $osC_Database->query('select id from :table_administrators where user_name = :user_name');
hpdl
1016
65       if (isset($_GET['aID']) && is_numeric($_GET['aID'])) {
hpdl
1085
66         $Qcheck->appendQuery('and id != :id limit 1');
67         $Qcheck->bindInt(':id', $_GET['aID']);
hpdl
1016
68       }
hpdl
1085
69       $Qcheck->bindTable(':table_administrators', TABLE_ADMINISTRATORS);
70       $Qcheck->bindValue(':user_name', $_POST['user_name']);
71       $Qcheck->execute();
hpdl
1016
72
hpdl
1085
73       if ($Qcheck->numberOfRows() < 1) {
74         $osC_Database->startTransaction();
hpdl
1016
75
hpdl
1085
76         if (isset($_GET['aID']) && is_numeric($_GET['aID'])) {
77           $Qadmin = $osC_Database->query('update :table_administrators set user_name = :user_name where id = :id');
78           $Qadmin->bindInt(':id', $_GET['aID']);
79         } else {
80           $Qadmin = $osC_Database->query('insert into :table_administrators (user_name) values (:user_name)');
81         }
82         $Qadmin->bindTable(':table_administrators', TABLE_ADMINISTRATORS);
83         $Qadmin->bindValue(':user_name', $_POST['user_name']);
84         $Qadmin->execute();
hpdl
1070
85
hpdl
1085
86         if ( !$osC_Database->isError() ) {
87           $id = (isset($_GET['aID']) && is_numeric($_GET['aID']) ? $_GET['aID'] : $osC_Database->nextID());
88
89           if ( !empty($_POST['user_password']) ) {
90             $Qadmin = $osC_Database->query('update :table_administrators set user_password = :user_password where id = :id');
91             $Qadmin->bindTable(':table_administrators', TABLE_ADMINISTRATORS);
92             $Qadmin->bindValue(':user_password', osc_encrypt_string(trim($_POST['user_password'])));
93             $Qadmin->bindInt(':id', $id);
94             $Qadmin->execute();
95
96             if ( $osC_Database->isError() ) {
97               $error = true;
98             }
hpdl
1070
99           }
hpdl
1085
100         } else {
101           $error = true;
hpdl
1070
102         }
hpdl
1016
103
hpdl
1085
104         if ( $error === false ) {
105           $modules_array = array();
hpdl
1070
106
hpdl
1085
107           if ( isset($_POST['modules']) ) {
108             if ( in_array( '*', $_POST['modules'] ) ) {
109               $_POST['modules'] = array('*');
110             }
hpdl
1070
111
hpdl
1085
112             foreach ($_POST['modules'] as $module) {
113               $modules_array[] = '\'' . $module . '\'';
hpdl
1070
114
hpdl
1085
115               $Qcheck = $osC_Database->query('select administrators_id from :table_administrators_access where administrators_id = :administrators_id and module = :module limit 1');
116               $Qcheck->bindTable(':table_administrators_access', TABLE_ADMINISTRATORS_ACCESS);
117               $Qcheck->bindInt(':administrators_id', $id);
118               $Qcheck->bindValue(':module', $module);
119               $Qcheck->execute();
hpdl
1070
120
hpdl
1085
121               if ( $Qcheck->numberOfRows() < 1 ) {
122                 $Qinsert = $osC_Database->query('insert into :table_administrators_access (administrators_id, module) values (:administrators_id, :module)');
123                 $Qinsert->bindTable(':table_administrators_access', TABLE_ADMINISTRATORS_ACCESS);
124                 $Qinsert->bindInt(':administrators_id', $id);
125                 $Qinsert->bindValue(':module', $module);
126                 $Qinsert->execute();
hpdl
1070
127
hpdl
1085
128                 if ( $osC_Database->isError() ) {
129                   $error = true;
130                   break;
131                 }
hpdl
1070
132               }
133             }
134           }
135         }
136
hpdl
1085
137         if ( $error === false ) {
138           $Qdel = $osC_Database->query('delete from :table_administrators_access where administrators_id = :administrators_id');
hpdl
1070
139
hpdl
1085
140           if ( !empty($modules_array) ) {
141             $Qdel->appendQuery('and module not in (:module)');
142             $Qdel->bindRaw(':module', implode(',', $modules_array));
143           }
144
145           $Qdel->bindTable(':table_administrators_access', TABLE_ADMINISTRATORS_ACCESS);
146           $Qdel->bindInt(':administrators_id', $id);
147           $Qdel->execute();
148
149           if ( $osC_Database->isError() ) {
150             $error = true;
151           } else {
152             if ($id == $_SESSION['admin']['id']) {
153               $_SESSION['admin']['access'] = osC_Access::getUserLevels($id);
154             }
155           }
hpdl
1070
156         }
157
hpdl
1085
158         if ( $error === false ) {
159           $osC_Database->commitTransaction();
hpdl
1070
160
hpdl
1085
161           $osC_MessageStack->add_session($this->_module, SUCCESS_DB_ROWS_UPDATED, 'success');
hpdl
1074
162         } else {
hpdl
1085
163           $osC_Database->rollbackTransaction();
164
165           $osC_MessageStack->add_session($this->_module, ERROR_DB_ROWS_NOT_UPDATED, 'error');
hpdl
1070
166         }
167
hpdl
1085
168         osc_redirect(osc_href_link_admin(FILENAME_DEFAULT, $this->_module . '&page=' . $_GET['page'] . (isset($id) ? '&aID=' . $id : '')));
hpdl
1016
169       } else {
hpdl
1085
170         $osC_MessageStack->add($this->_module, ERROR_ADMINISTRATORS_USERNAME_EXISTS, 'error');
hpdl
1070
171
hpdl
1085
172         if (isset($_GET['aID']) && is_numeric($_GET['aID'])) {
173           $_GET['action'] = 'aEdit';
174         } else {
175           $_GET['action'] = 'aNew';
176         }
hpdl
1016
177       }
178     }
179
180     function _delete() {
181       global $osC_Database, $osC_MessageStack;
182
183       if (isset($_GET['aID']) && is_numeric($_GET['aID'])) {
hpdl
1070
184         $osC_Database->startTransaction();
185
186         $Qdel = $osC_Database->query('delete from :table_administrators_access where administrators_id = :administrators_id');
187         $Qdel->bindTable(':table_administrators_access', TABLE_ADMINISTRATORS_ACCESS);
188         $Qdel->bindInt(':administrators_id', $_GET['aID']);
189         $Qdel->execute();
190
hpdl
1016
191         $Qdel = $osC_Database->query('delete from :table_administrators where id = :id');
192         $Qdel->bindTable(':table_administrators', TABLE_ADMINISTRATORS);
193         $Qdel->bindInt(':id', $_GET['aID']);
194         $Qdel->execute();
195
hpdl
1070
196         $osC_Database->commitTransaction();
197
hpdl
1016
198         $osC_MessageStack->add_session($this->_module, SUCCESS_DB_ROWS_UPDATED, 'success');
199       }
200
201       osc_redirect(osc_href_link_admin(FILENAME_DEFAULT, $this->_module . '&page=' . $_GET['page']));
202     }
203   }
204 ?>