PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/user_profile_edit.php

https://github.com/paulheaney/sitracker
PHP | 442 lines | 393 code | 21 blank | 28 comment | 39 complexity | 6e59290b38b8c0c2a49c72107f09430d MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0, BSD-3-Clause, GPL-2.0
  1. <?php
  2. // edit_profile.php
  3. //
  4. // SiT (Support Incident Tracker) - Support call tracking system
  5. // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
  6. //
  7. // This software may be used and distributed according to the terms
  8. // of the GNU General Public License, incorporated herein by reference.
  9. //
  10. // This Page Is Valid XHTML 1.0 Transitional! 1Nov05
  11. $permission = 4; // Edit your profile
  12. require ('core.php');
  13. require (APPLICATION_LIBPATH . 'functions.inc.php');
  14. // This page requires authentication
  15. require (APPLICATION_LIBPATH . 'auth.inc.php');
  16. // External variables
  17. $mode = $_REQUEST['mode'];
  18. $edituserpermission = user_permission($sit[2],23); // edit user
  19. if (empty($_REQUEST['userid']) OR $_REQUEST['userid'] == 'current' OR $edituserpermission == FALSE)
  20. {
  21. $edituserid = mysql_real_escape_string($sit[2]);
  22. }
  23. else
  24. {
  25. if (!empty($_REQUEST['userid']))
  26. {
  27. $edituserid = cleanvar($_REQUEST['userid']);
  28. }
  29. }
  30. if (empty($mode))
  31. {
  32. $title = $strEditProfile;
  33. include (APPLICATION_INCPATH . 'htmlheader.inc.php');
  34. /*
  35. $sql = "SELECT u.*, r.rolename FROM `{$dbUsers}` AS u, `{$dbRoles}` AS r ";
  36. $sql .= "WHERE u.id='{$edituserid}' AND u.roleid = r.id LIMIT 1";
  37. $result = mysql_query($sql);
  38. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
  39. if (mysql_num_rows($result) < 1) trigger_error("$sql No such user ".strip_tags($edituserid),E_USER_WARNING);
  40. $user = mysql_fetch_object($result);
  41. */
  42. $user = new User($edituserid);
  43. echo "<h2>".icon('user', 32)." ";
  44. echo sprintf($strEditProfileFor, $user->realname).' '.gravatar($user->email)."</h2>";
  45. echo "<form id='edituser' action='{$_SERVER['PHP_SELF']}' method='post'>";
  46. echo "<table align='center' class='vertical'>";
  47. echo "<col width='250'></col><col width='*'></col>";
  48. echo "<tr><th colspan='2'>";
  49. if ($edituserid == $sit[2])
  50. {
  51. echo sprintf($strAboutPerson, $strYou);
  52. }
  53. else
  54. {
  55. echo sprintf($strAboutPerson, $user->realname);
  56. }
  57. echo "</th></tr>\n";
  58. echo "<tr><th>{$strUsername}</th><td>{$user->username}</td></tr>";
  59. echo "<tr><th>{$strRole}</th>";
  60. if ($edituserid == $sit[2] OR $edituserid == 1)
  61. {
  62. echo "<td>{$user->rolename}</td>";
  63. }
  64. else
  65. {
  66. echo "<td>".role_drop_down('roleid', $user->roleid)."</td>";
  67. }
  68. echo "</tr>";
  69. echo "<tr><th>{$strRealName}</th><td>";
  70. if ($_SESSION['user_source'] != 'sit' AND !empty($CONFIG['ldap_realname']))
  71. {
  72. echo "<input name='realname' type='hidden' value=\"{$user->realname}\" '/>{$user->realname}";
  73. }
  74. else
  75. {
  76. echo "<input class='required' maxlength='50' name='realname' size='30'";
  77. echo " type='text' value=\"{$user->realname}\" />";
  78. echo " <span class='required'>{$strRequired}</span>";
  79. }
  80. echo "</td></tr>\n";
  81. echo "<tr><th>{$strSource}</th><td>{$user->source}</td></th>";
  82. echo "<tr><th>{$strJobTitle}</th>";
  83. echo "<td>";
  84. if ($_SESSION['user_source'] != 'sit' AND !empty($CONFIG['ldap_jobtitle']))
  85. {
  86. echo $user->jobtitle;
  87. }
  88. else
  89. {
  90. echo "<input maxlength='50' name='jobtitle' size='30' type='text' ";
  91. echo "value=\"{$user->jobtitle}\" />";
  92. }
  93. echo "</td></tr>\n";
  94. echo "<tr><th>{$strQualifications} ".help_link('QualificationsTip')."</th>";
  95. echo "<td><input maxlength='100' size='100' name='qualifications' value='{$user->qualifications}' /></td></tr>\n";
  96. echo "<tr><th>{$strEmailSignature} ".help_link('EmailSignatureTip')."</th>";
  97. echo "<td><textarea name='signature' rows='4' cols='40'>".strip_tags($user->signature)."</textarea></td></tr>\n";
  98. $entitlement = user_holiday_entitlement($edituserid);
  99. if ($edituserpermission && $edituserid != $sit[2])
  100. {
  101. echo "<tr><th>{$strHolidayEntitlement}</th><td>";
  102. echo "<input type='text' name='holiday_entitlement' value='{$entitlement}' size='2' /> {$strDays}";
  103. echo "</td></tr>\n";
  104. echo "<tr><th>{$strStartDate} ".help_link('UserStartdate')."</th>";
  105. echo "<td><input type='text' name='startdate' id='startdate' size='10' ";
  106. echo "value='{$user->user_startdate}'";
  107. echo "/> ";
  108. echo date_picker('edituser.startdate');
  109. echo "</td></tr>\n";
  110. }
  111. elseif ($entitlement > 0)
  112. {
  113. $holiday_resetdate = user_holiday_resetdate($edituserid);
  114. $holidaystaken = user_count_holidays($edituserid, HOL_HOLIDAY, $holiday_resetdate);
  115. echo "<tr><th>{$strHolidayEntitlement}</th><td>";
  116. echo "{$entitlement} {$strDays}, ";
  117. echo "{$holidaystaken} {$strtaken}, ";
  118. echo sprintf($strRemaining, $entitlement-$holidaystaken);
  119. echo "</td></tr>\n";
  120. echo "<tr><th>{$strOtherLeave}</th><td>";
  121. echo user_count_holidays($edituserid, HOL_SICKNESS)." {$strdayssick}, ";
  122. echo user_count_holidays($edituserid, HOL_WORKING_AWAY)." {$strdaysworkingaway}, ";
  123. echo user_count_holidays($edituserid, HOL_TRAINING)." {$strdaystraining}";
  124. echo "<br />";
  125. echo user_count_holidays($edituserid, HOL_FREE)." {$strdaysother}";
  126. echo "</td></tr>";
  127. }
  128. echo "<tr><th>{$strGroupMembership}</th><td valign='top'>";
  129. echo $user->group->name;
  130. echo "</td></tr>";
  131. echo "<tr><th colspan='2'>{$strWorkStatus}</th></tr>";
  132. if ($edituserpermission AND $edituserid != $sit[2] AND $user->user_source == 'sit')
  133. {
  134. $userdisable = TRUE;
  135. }
  136. else
  137. {
  138. $userdisable = FALSE;
  139. }
  140. echo "<tr><th>{$strStatus}</th><td>";
  141. echo userstatus_drop_down("status", $user->status, $userdisable);
  142. echo "</td></tr>\n";
  143. echo "<tr><th>{$strAccepting} {$strIncidents}</th><td>";
  144. echo accepting_drop_down("accepting", $edituserid);
  145. echo "</td></tr>\n";
  146. echo "<tr><th>{$strMessage} ".help_link('MessageTip')."</th>";
  147. echo "<td><textarea name='message' rows='4' cols='40'>".strip_tags($user->message)."</textarea></td></tr>\n";
  148. echo "<tr><th colspan='2'>{$strContactDetails}</th></tr>";
  149. echo "<tr id='email'><th>{$strEmail}</th>";
  150. echo "<td>";
  151. if ($_SESSION['user_source'] != 'sit' AND !empty($CONFIG['ldap_email']))
  152. {
  153. echo "<input name='email' type='hidden'value='".strip_tags($user->email)."' />{$user->email}";
  154. }
  155. else
  156. {
  157. echo "<input class='required' maxlength='50' name='email' size='30' ";
  158. echo "type='text' value='".strip_tags($user->email)."' />";
  159. echo " <span class='required'>{$strRequired}</span>";
  160. }
  161. echo "</td></tr>";
  162. echo "<tr id='phone'><th>{$strTelephone}</th><td>";
  163. if ($_SESSION['user_source'] != 'sit' AND !empty($CONFIG['ldap_telephone']))
  164. {
  165. echo $user->phone;
  166. }
  167. else
  168. {
  169. echo "<input maxlength='50' name='phone' size='30' type='text' value='".strip_tags($user->phone)."' />";
  170. }
  171. echo "</td></tr>";
  172. echo "<tr><th>{$strFax}</th><td>";
  173. if ($_SESSION['user_source'] != 'sit' AND !empty($CONFIG['ldap_fax']))
  174. {
  175. echo $user->fax;
  176. }
  177. else
  178. {
  179. echo "<input maxlength='50' name='fax' size='30' type='text' value='".strip_tags($user->fax)."' />";
  180. }
  181. echo "</td></tr>";
  182. echo "<tr><th>{$strMobile}</th><td>";
  183. if ($_SESSION['user_source'] != 'sit' AND !empty($CONFIG['ldap_mobile']))
  184. {
  185. echo $user->mobile;
  186. }
  187. else
  188. {
  189. echo "<input maxlength='50' name='mobile' size='30' type='text' value='{$user->mobile}' />";
  190. }
  191. echo "</td></tr>";
  192. echo "<tr><th>AIM ".icon('aim', 16, 'AIM')."</th>";
  193. echo "<td><input maxlength=\"50\" name=\"aim\" size=\"30\" type=\"text\" value=\"".strip_tags($user->aim)."\" /></td></tr>";
  194. echo "<tr><th>ICQ ".icon('icq', 16, 'ICQ')."</th>";
  195. echo "<td><input maxlength=\"50\" name=\"icq\" size=\"30\" type=\"text\" value=\"".strip_tags($user->icq)."\" /></td></tr>";
  196. echo "<tr><th>MSN ".icon('msn', 16, 'MSN')."</th>";
  197. echo "<td><input maxlength=\"50\" name=\"msn\" size=\"30\" type=\"text\" value=\"".strip_tags($user->msn)."\" /></td></tr>";
  198. echo "<tr><th colspan='2'>{$strDisplayPreferences}</th></tr>\n";
  199. echo "<tr><th>{$strLanguage}</th><td>";
  200. if (!empty($CONFIG['available_i18n']))
  201. {
  202. $available_languages = i18n_code_to_name($CONFIG['available_i18n']);
  203. }
  204. else
  205. {
  206. $available_languages = available_languages();
  207. }
  208. $available_languages = array_merge(array(''=>$strDefault),$available_languages);
  209. if (!empty($user->i18n))
  210. {
  211. $selectedlang = $user->i18n;
  212. }
  213. else
  214. {
  215. $selectedlang = $_SESSION['lang'];
  216. }
  217. echo array_drop_down($available_languages, 'vari18n',$selectedlang, '', TRUE);
  218. echo "</td></tr>\n";
  219. if ($user->utc_offset == '') $user->utc_offset = 0;
  220. echo "<tr><th>{$strUTCOffset}</th><td>";
  221. foreach ($availabletimezones AS $offset=>$tz)
  222. {
  223. $tz = $tz . ' ('.ldate('H:i',utc_time($now) + ($offset*60)).')';
  224. $availtz[$offset] = $tz;
  225. }
  226. echo array_drop_down($availtz, 'utcoffset', $user->utc_offset, '', TRUE)."</td></tr>\n";
  227. echo "<tr><th>{$strInterfaceStyle}</th><td>".interfacestyle_drop_down('style', $user->style)."</td></tr>\n";
  228. echo "<tr><th>{$strIncidentRefresh}</th>";
  229. echo "<td><input maxlength='10' name='incidentrefresh' size='3' type='text' value=\"{$user->incident_refresh}\" /> {$strSeconds}</td></tr>\n";
  230. echo "<tr><th>{$strIncidentLogOrder}</th><td>";
  231. echo "<select name='updateorder'>";
  232. echo "<option ";
  233. if ($user->update_order == "desc")
  234. {
  235. echo "selected='selected'";
  236. }
  237. echo " value='desc'>{$strNewestAtTop}</option>\n";
  238. echo "<option ";
  239. if ($user->update_order == "asc")
  240. {
  241. echo "selected='selected'";
  242. }
  243. echo " value='asc'>{$strNewestAtBottom}</option>\n";
  244. echo "</select>";
  245. echo "</td></tr>\n";
  246. echo "<tr><th>{$strIncidentUpdatesPerPage}</th>";
  247. echo "<td><input maxlength='5' name='updatesperpage' size='3' type='text' ";
  248. echo "value=\"".$user->num_updates_view."\" /> ({$str0MeansUnlimited})</td></tr>\n";
  249. echo "<tr><th>{$strShowEmoticons}</th>";
  250. echo "<td><input type='checkbox' name='emoticons' id='emoticons' value='true' ";
  251. if ($user->emoticons == 'true') echo "checked='checked' ";
  252. echo "/></td></tr>\n";
  253. echo "<tr><th colspan='2'>{$strNotifications}</th></tr>\n";
  254. echo "<tr><th></th><td>";
  255. echo "{$strNotificationsMovedToTriggersPage} - <a href='triggers.php'>{$strTriggers}</a></td></tr>\n";
  256. plugin_do('edit_profile_form');
  257. // Do not allow password change if using LDAP
  258. if ($_SESSION['user_source'] != 'sit')
  259. {
  260. if ($CONFIG['trusted_server'] == FALSE AND $edituserid == $sit[2])
  261. {
  262. echo "<tr class='password'><th colspan='2'>{$strChangePassword}</th></tr>";
  263. echo "<tr class='password'><th>&nbsp;</th><td>{$strToChangePassword}</td></tr>";
  264. echo "<tr class='password'><th>{$strOldPassword}</th><td><input maxlength='50' name='oldpassword' size='30' type='password' /></td></tr>";
  265. echo "<tr class='password'><th>{$strNewPassword}</th><td><input maxlength='50' name='newpassword1' size='30' type='password' /></td></tr>";
  266. echo "<tr class='password'><th>{$strConfirmNewPassword}</th><td><input maxlength='50' name='newpassword2' size='30' type='password' /></td></tr>";
  267. }
  268. }
  269. echo "</table>\n";
  270. echo "<input type='hidden' name='userid' value='{$edituserid}' />";
  271. echo "<input type='hidden' name='mode' value='save' />";
  272. echo "<p><input name='reset' type='reset' value='{$strReset}' /> <input name='submit' type='submit' value='{$strSave}' /></p>";
  273. echo "</form>\n";
  274. include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
  275. }
  276. elseif ($mode == 'save')
  277. {
  278. // External variables
  279. $user = new User();
  280. $user->id = cleanvar($_POST['userid']);
  281. $edituserid = cleanvar($_POST['userid']); // remove when tested
  282. $user->message = cleanvar($_POST['message']);
  283. $user->realname = cleanvar($_POST['realname']);
  284. $user->qualifications = cleanvar($_POST['qualifications']);
  285. $user->email = cleanvar($_POST['email']);
  286. $user->jobtitle = cleanvar($_POST['jobtitle']);
  287. $user->phone = cleanvar($_POST['phone']);
  288. $user->mobile = cleanvar($_POST['mobile']);
  289. $user->aim = cleanvar($_POST['aim']);
  290. $user->icq = cleanvar($_POST['icq']);
  291. $user->msn = cleanvar($_POST['msn']);
  292. $user->fax = cleanvar($_POST['fax']);
  293. $user->incident_refresh = cleanvar($_POST['incidentrefresh']);
  294. $user->update_order = cleanvar($_POST['updateorder']);
  295. $user->num_updates_view = cleanvar($_POST['updatesperpage']);
  296. $user->signature = cleanvar($_POST['signature']);
  297. $user->status = cleanvar($_POST['status']);
  298. $user->style = cleanvar($_POST['style']);
  299. $user->i18n = cleanvar($_POST['vari18n']);
  300. $user->utc_offset = cleanvar($_POST['utcoffset']);
  301. $user->emoticons = cleanvar($_POST['emoticons']);
  302. if (cleanvar($_POST['accepting']) == 'Yes') $user->accepting = true;
  303. else $user->accepting = false;
  304. $user->roleid = cleanvar($_POST['roleid']);
  305. $user->holiday_entitlement = cleanvar($_POST['holiday_entitlement']);
  306. if (!empty($_POST['startdate']))
  307. {
  308. $user->startdate = date('Y-m-d',strtotime($_POST['startdate']));
  309. }
  310. else
  311. {
  312. $user->startdate = date('Y-m-d',0);
  313. }
  314. $password = cleanvar($_POST['oldpassword']);
  315. $newpassword1 = cleanvar($_POST['newpassword1']);
  316. $newpassword2 = cleanvar($_POST['newpassword2']);
  317. if (empty($user->emoticons)) $user->emoticons = 'false';
  318. // Some extra checking here so that users can't edit other peoples profiles
  319. $edituserpermission = user_permission($sit[2],23); // edit user
  320. if ($edituserid != $sit[2] AND $edituserpermission == FALSE)
  321. {
  322. trigger_error('Error: No permission to edit this users profile', E_USER_ERROR);
  323. exit;
  324. }
  325. // If users status is set to 0 (disabled) force 'accepting' to no
  326. if ($user->status==0) $user->accepting='No';
  327. // Update user profile
  328. $errors = 0;
  329. // check for change of password
  330. if ($password != '' && $newpassword1 != '' && $newpassword2 != '')
  331. {
  332. // verify password fields
  333. $passwordMD5 = md5($password);
  334. if ($newpassword1 == $newpassword2 AND strcasecmp($passwordMD5, user_password($edituserid)) == 0)
  335. {
  336. $user->password = $password;
  337. }
  338. else
  339. {
  340. $errors++;
  341. $error_string .= "<h5 class='error'>{$strPasswordsDoNotMatch}</h5>";
  342. }
  343. }
  344. // update database if no errors
  345. if ($errors == 0)
  346. {
  347. $result = $user->edit();
  348. // If this is the current user, update the profile in the users session
  349. if ($edituserid == $_SESSION['userid'])
  350. {
  351. $_SESSION['style'] = $user->style;
  352. $_SESSION['realname'] = $user->realname;
  353. $_SESSION['email'] = $user->email;
  354. $_SESSION['incident_refresh'] = $user->incident_refresh;
  355. $_SESSION['update_order'] = $user->update_order;
  356. $_SESSION['num_update_view'] = $user->num_updates_view;
  357. $_SESSION['lang'] = $user->i18n;
  358. $_SESSION['utcoffset'] = $user->utc_offset;
  359. }
  360. if ($result === FALSE)
  361. {
  362. include (APPLICATION_INCPATH . 'htmlheader.inc.php');
  363. trigger_error("!Error while updating users table", E_USER_WARNING);
  364. include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
  365. exit;
  366. }
  367. elseif ($result === TRUE)
  368. {
  369. if ($edituserid==$sit[2]) $redirecturl='index.php';
  370. else $redirecturl='manage_users.php';
  371. plugin_do('save_profile_form');
  372. // password was not changed
  373. if (isset($confirm_message)) html_redirect($redirecturl, TRUE, $confirm_message);
  374. else html_redirect($redirecturl);
  375. exit;
  376. }
  377. else
  378. {
  379. $errors++;
  380. $error_string .= $result;
  381. }
  382. }
  383. if ($errors > 0)
  384. {
  385. html_redirect($redirecturl, FALSE, $error_string);
  386. }
  387. }
  388. elseif ($mode == 'savesessionlang')
  389. {
  390. $sql = "UPDATE `{$dbUsers}` SET var_i18n = '{$_SESSION['lang']}' WHERE id = {$sit[2]}";
  391. mysql_query($sql);
  392. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  393. // FIXME 3.35 use revoke instead
  394. $sql = "DELETE FROM `{$dbNotices}` WHERE type='".USER_LANG_DIFFERS_TYPE."' AND userid={$sit[2]}";
  395. mysql_query($sql);
  396. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  397. html_redirect("main.php");
  398. }
  399. ?>