![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: admin.class.php 168 2008-05-20 11:22:15Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/admin/admin.class.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 // user types 7 $utypes = w2PgetSysVal('UserType'); 8 9 /** 10 * User Class 11 */ 12 class CUser extends CW2pObject { 13 var $user_id = null; 14 var $user_username = null; 15 var $user_password = null; 16 var $user_parent = null; 17 var $user_type = null; 18 var $user_contact = null; 19 var $user_signature = null; 20 21 function CUser() { 22 $this->CW2pObject('users', 'user_id'); 23 } 24 25 function check() { 26 if ($this->user_id === null) { 27 return 'user id is NULL'; 28 } 29 if ($this->user_password !== null) { 30 $this->user_password = db_escape(trim($this->user_password)); 31 } 32 // TODO MORE 33 return null; // object is ok 34 } 35 36 function store() { 37 $msg = $this->check(); 38 if ($msg) { 39 return get_class($this) . '::store-check failed'; 40 } 41 $q = new DBQuery; 42 if ($this->user_id) { 43 // save the old password 44 $perm_func = 'updateLogin'; 45 $q->addTable('users'); 46 $q->addQuery('user_password'); 47 $q->addWhere('user_id = ' . $this->user_id); 48 $pwd = $q->loadResult(); 49 if (!$this->user_password) { 50 //if the user didn't provide a password keep the old one 51 $this->user_password = $pwd; 52 } elseif ($pwd != $this->user_password) { 53 $this->user_password = md5($this->user_password); 54 } else { 55 //if something is not right keep the old one 56 $this->user_password = $pwd; 57 } 58 $q->clear(); 59 60 $ret = $q->updateObject('users', $this, 'user_id', false); 61 $q->clear(); 62 } else { 63 $perm_func = 'addLogin'; 64 $this->user_password = md5($this->user_password); 65 $ret = $q->insertObject('users', $this, 'user_id'); 66 $q->clear(); 67 } 68 if (!$ret) { 69 return get_class($this) . '::store failed' . db_error(); 70 } else { 71 $acl = &$GLOBALS['AppUI']->acl(); 72 $acl->$perm_func($this->user_id, $this->user_username); 73 //Insert Default Preferences 74 //Lets check if the user has allready default users preferences set, if not insert the default ones 75 $q->addTable('user_preferences', 'upr'); 76 $q->addWhere('upr.pref_user = ' . $this->user_id); 77 $uprefs = $q->loadList(); 78 $q->clear(); 79 if (!count($uprefs) && $this->user_id > 0) { 80 //Lets get the default users preferences 81 $q->addTable('user_preferences', 'dup'); 82 $q->addWhere('dup.pref_user = 0'); 83 $w2prefs = $q->loadList(); 84 $q->clear(); 85 86 foreach ($w2prefs as $w2prefskey => $w2prefsvalue) { 87 $q->addTable('user_preferences', 'up'); 88 $q->addInsert('pref_user', $this->user_id); 89 $q->addInsert('pref_name', $w2prefsvalue['pref_name']); 90 $q->addInsert('pref_value', $w2prefsvalue['pref_value']); 91 $q->exec(); 92 $q->clear(); 93 } 94 } 95 return null; 96 } 97 } 98 99 function delete($oid = null) { 100 global $AppUI; 101 $id = (int)$this->user_id; 102 //check if the user is related to anything and disallow deletion if he is. 103 //companies: is he a owner of any company? 104 $q = new DBQuery; 105 $q->addQuery('count(company_id)'); 106 $q->addTable('companies'); 107 $q->addWhere('company_owner = ' . $id); 108 $result = $q->loadResult(); 109 $q->clear(); 110 if ($result) { 111 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Companies') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Owner') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 112 } 113 //departments: is he a owner of any department? 114 $q = new DBQuery; 115 $q->addQuery('count(dept_id)'); 116 $q->addTable('departments'); 117 $q->addWhere('dept_owner = ' . $id); 118 $result = $q->loadResult(); 119 $q->clear(); 120 if ($result) { 121 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Departments') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Owner') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 122 } 123 //events: is he a owner of any event? 124 $q = new DBQuery; 125 $q->addQuery('count(event_id)'); 126 $q->addTable('events'); 127 $q->addWhere('event_owner = ' . $id); 128 $result = $q->loadResult(); 129 $q->clear(); 130 if ($result) { 131 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Events') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Owner') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 132 } 133 //files: is he a owner of any file? 134 $q = new DBQuery; 135 $q->addQuery('count(file_id)'); 136 $q->addTable('files'); 137 $q->addWhere('file_owner = ' . $id); 138 $result = $q->loadResult(); 139 $q->clear(); 140 if ($result) { 141 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Files') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Owner') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 142 } 143 //forums: is he a owner of any forum? 144 $q = new DBQuery; 145 $q->addQuery('count(forum_id)'); 146 $q->addTable('forums'); 147 $q->addWhere('forum_owner = ' . $id); 148 $result = $q->loadResult(); 149 $q->clear(); 150 if ($result) { 151 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Forums') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Owner') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 152 } 153 //forums: is he a moderator of any forum? 154 $q = new DBQuery; 155 $q->addQuery('count(forum_id)'); 156 $q->addTable('forums'); 157 $q->addWhere('forum_moderated = ' . $id); 158 $result = $q->loadResult(); 159 $q->clear(); 160 if ($result) { 161 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Forums') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Forum Moderator') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 162 } 163 //forums: is he a message creator on any forum? 164 $q = new DBQuery; 165 $q->addQuery('count(message_id)'); 166 $q->addTable('forum_messages'); 167 $q->addWhere('message_author = ' . $id); 168 $result = $q->loadResult(); 169 $q->clear(); 170 if ($result) { 171 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Forum Messages') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Author') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 172 } 173 //forums: is he a message creator on any forum? 174 $q = new DBQuery; 175 $q->addQuery('count(message_id)'); 176 $q->addTable('forum_messages'); 177 $q->addWhere('message_editor = ' . $id); 178 $result = $q->loadResult(); 179 $q->clear(); 180 if ($result) { 181 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Forum Messages') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Editor') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 182 } 183 //links: is he a owner of any link? 184 $q = new DBQuery; 185 $q->addQuery('count(link_id)'); 186 $q->addTable('links'); 187 $q->addWhere('link_owner = ' . $id); 188 $result = $q->loadResult(); 189 $q->clear(); 190 if ($result) { 191 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Links') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Owner') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 192 } 193 //projects: is he related to any project? 194 $q = new DBQuery; 195 $q->addQuery('count(project_id)'); 196 $q->addTable('projects'); 197 $q->addWhere('(project_owner = ' . $id . ' OR project_creator = ' . $id . ' OR project_updator = ' . $id . ')'); 198 $result = $q->loadResult(); 199 $q->clear(); 200 if ($result) { 201 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Projects') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Owner, Creator or Updator') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 202 } 203 //tasks: is he related to any task? 204 $q = new DBQuery; 205 $q->addQuery('count(task_id)'); 206 $q->addTable('tasks'); 207 $q->addWhere('(task_owner = ' . $id . ' OR task_creator = ' . $id . ' OR task_updator = ' . $id . ')'); 208 $result = $q->loadResult(); 209 $q->clear(); 210 if ($result) { 211 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Tasks') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Owner, Creator or Updator') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 212 } 213 //events: is he related to any event? 214 $q = new DBQuery; 215 $q->addQuery('count(event_id)'); 216 $q->addTable('user_events'); 217 $q->addWhere('user_id = ' . $id); 218 $result = $q->loadResult(); 219 $q->clear(); 220 if ($result) { 221 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Events') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Attendee') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 222 } 223 //tasks: is he related to any event? 224 $q = new DBQuery; 225 $q->addQuery('count(task_id)'); 226 $q->addTable('user_tasks'); 227 $q->addWhere('user_id = ' . $id); 228 $result = $q->loadResult(); 229 $q->clear(); 230 if ($result) { 231 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Tasks') . ' ' . $AppUI->_('where he is') . ' ' .$AppUI->_('Assignee') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 232 } 233 //tasks: is he related to any pins? 234 $q = new DBQuery; 235 $q->addQuery('count(task_id)'); 236 $q->addTable('user_task_pin'); 237 $q->addWhere('user_id = ' . $id); 238 $result = $q->loadResult(); 239 $q->clear(); 240 if ($result) { 241 return $AppUI->_('Can not Delete Because This User has') . ' ' . $result . ' ' . $AppUI->_('Tasks') . ' ' . $AppUI->_('pinned') . '. ' . $AppUI->_('If you just want this user not to log in consider removing all his Roles. That would make the user Inactive.'); 242 } 243 244 $result = parent::delete($oid); 245 if (!$result) { 246 $acl = &$GLOBALS['AppUI']->acl(); 247 $acl->deleteLogin($id); 248 $q = new DBQuery; 249 $q->setDelete('user_preferences'); 250 $q->addWhere('pref_user = ' . $id); 251 $q->exec(); 252 $q->clear(); 253 } 254 return $result; 255 } 256 257 function getAllowedRecords($uid, $fields = '*', $orderby = '', $index = null, $extra = null) { 258 return w2PgetUsers(); 259 } 260 } 261 262 function notifyNewUser($address, $username) { 263 global $AppUI; 264 $mail = new Mail; 265 if ($mail->ValidEmail($address)) { 266 if ($mail->ValidEmail($AppUI->user_email)) { 267 $email = $AppUI->user_email; 268 } else { 269 return false; 270 } 271 272 $mail->To($address); 273 $mail->Subject('New Account Created'); 274 $mail->Body("Dear $username,\n\n" . "Congratulations! Your account has been activated by the administrator.\n" . "Please use the login information provided earlier.\n\n" . "You may login at the following URL: " . W2P_BASE_URL . "\n\n" . "If you have any difficulties or questions, please ask the administrator for help.\n" . "Assuring you the best of our attention at all time.\n\n" . "Our Warmest Regards,\n\n" . "The Support Staff.\n\n" . "****PLEASE KEEP THIS EMAIL FOR YOUR RECORDS****"); 275 $mail->Send(); 276 } 277 } 278 279 function notifyNewUserCredentials($address, $username, $logname, $logpwd) { 280 global $AppUI, $w2Pconfig; 281 $mail = new Mail; 282 if ($mail->ValidEmail($address)) { 283 if ($mail->ValidEmail($AppUI->user_email)) { 284 $email = $AppUI->user_email; 285 } else { 286 $email = "web2project@" . $AppUI->cfg['site_domain']; 287 } 288 289 $mail->To($address); 290 $mail->Subject('New Account Created - web2Project Project Management System'); 291 $mail->Body($username . ",\n\n" . "An access account has been created for you in our web2Project project management system.\n\n" . "You can access it here at " . w2PgetConfig('base_url') . "\n\n" . "Your username is: " . $logname . "\n" . "Your password is: " . $logpwd . "\n\n" . 292 "This account will allow you to see and interact with projects. If you have any questions please contact us."); 293 $mail->Send(); 294 } 295 } 296 ?>
title
Description
Body
title
Description
Body
title
Description