PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/user_profile_edit.php

https://github.com/nicdev007/sitracker
PHP | 436 lines | 387 code | 21 blank | 28 comment | 39 complexity | b24611f07aa3fe1a1538ea2e5f6ff067 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0, BSD-3-Clause
  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>".array_drop_down($availabletimezones, 'utcoffset', $user->utc_offset, '', TRUE)."</td></tr>\n";
  221. echo "<tr><th>{$strInterfaceStyle}</th><td>".interfacestyle_drop_down('style', $user->style)."</td></tr>\n";
  222. echo "<tr><th>{$strIncidentRefresh}</th>";
  223. echo "<td><input maxlength='10' name='incidentrefresh' size='3' type='text' value=\"{$user->incident_refresh}\" /> {$strSeconds}</td></tr>\n";
  224. echo "<tr><th>{$strIncidentLogOrder}</th><td>";
  225. echo "<select name='updateorder'>";
  226. echo "<option ";
  227. if ($user->update_order == "desc")
  228. {
  229. echo "selected='selected'";
  230. }
  231. echo " value='desc'>{$strNewestAtTop}</option>\n";
  232. echo "<option ";
  233. if ($user->update_order == "asc")
  234. {
  235. echo "selected='selected'";
  236. }
  237. echo " value='asc'>{$strNewestAtBottom}</option>\n";
  238. echo "</select>";
  239. echo "</td></tr>\n";
  240. echo "<tr><th>{$strIncidentUpdatesPerPage}</th>";
  241. echo "<td><input maxlength='5' name='updatesperpage' size='3' type='text' ";
  242. echo "value=\"".$user->num_updates_view."\" /> ({$str0MeansUnlimited})</td></tr>\n";
  243. echo "<tr><th>{$strShowEmoticons}</th>";
  244. echo "<td><input type='checkbox' name='emoticons' id='emoticons' value='true' ";
  245. if ($user->emoticons == 'true') echo "checked='checked' ";
  246. echo "/></td></tr>\n";
  247. echo "<tr><th colspan='2'>{$strNotifications}</th></tr>\n";
  248. echo "<tr><th></th><td>";
  249. echo "{$strNotificationsMovedToTriggersPage} - <a href='triggers.php'>{$strTriggers}</a></td></tr>\n";
  250. plugin_do('edit_profile_form');
  251. // Do not allow password change if using LDAP
  252. if ($_SESSION['user_source'] != 'sit')
  253. {
  254. if ($CONFIG['trusted_server'] == FALSE AND $edituserid == $sit[2])
  255. {
  256. echo "<tr class='password'><th colspan='2'>{$strChangePassword}</th></tr>";
  257. echo "<tr class='password'><th>&nbsp;</th><td>{$strToChangePassword}</td></tr>";
  258. echo "<tr class='password'><th>{$strOldPassword}</th><td><input maxlength='50' name='oldpassword' size='30' type='password' /></td></tr>";
  259. echo "<tr class='password'><th>{$strNewPassword}</th><td><input maxlength='50' name='newpassword1' size='30' type='password' /></td></tr>";
  260. echo "<tr class='password'><th>{$strConfirmNewPassword}</th><td><input maxlength='50' name='newpassword2' size='30' type='password' /></td></tr>";
  261. }
  262. }
  263. echo "</table>\n";
  264. echo "<input type='hidden' name='userid' value='{$edituserid}' />";
  265. echo "<input type='hidden' name='mode' value='save' />";
  266. echo "<p><input name='reset' type='reset' value='{$strReset}' /> <input name='submit' type='submit' value='{$strSave}' /></p>";
  267. echo "</form>\n";
  268. include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
  269. }
  270. elseif ($mode == 'save')
  271. {
  272. // External variables
  273. $user = new User();
  274. $user->id = cleanvar($_POST['userid']);
  275. $edituserid = cleanvar($_POST['userid']); // remove when tested
  276. $user->message = cleanvar($_POST['message']);
  277. $user->realname = cleanvar($_POST['realname']);
  278. $user->qualifications = cleanvar($_POST['qualifications']);
  279. $user->email = cleanvar($_POST['email']);
  280. $user->jobtitle = cleanvar($_POST['jobtitle']);
  281. $user->phone = cleanvar($_POST['phone']);
  282. $user->mobile = cleanvar($_POST['mobile']);
  283. $user->aim = cleanvar($_POST['aim']);
  284. $user->icq = cleanvar($_POST['icq']);
  285. $user->msn = cleanvar($_POST['msn']);
  286. $user->fax = cleanvar($_POST['fax']);
  287. $user->incident_refresh = cleanvar($_POST['incidentrefresh']);
  288. $user->update_order = cleanvar($_POST['updateorder']);
  289. $user->num_updates_view = cleanvar($_POST['updatesperpage']);
  290. $user->signature = cleanvar($_POST['signature']);
  291. $user->status = cleanvar($_POST['status']);
  292. $user->style = cleanvar($_POST['style']);
  293. $user->i18n = cleanvar($_POST['vari18n']);
  294. $user->utc_offset = cleanvar($_POST['utcoffset']);
  295. $user->emoticons = cleanvar($_POST['emoticons']);
  296. if (cleanvar($_POST['accepting']) == 'Yes') $user->accepting = true;
  297. else $user->accepting = false;
  298. $user->roleid = cleanvar($_POST['roleid']);
  299. $user->holiday_entitlement = cleanvar($_POST['holiday_entitlement']);
  300. if (!empty($_POST['startdate']))
  301. {
  302. $user->startdate = date('Y-m-d',strtotime($_POST['startdate']));
  303. }
  304. else
  305. {
  306. $user->startdate = date('Y-m-d',0);
  307. }
  308. $password = cleanvar($_POST['oldpassword']);
  309. $newpassword1 = cleanvar($_POST['newpassword1']);
  310. $newpassword2 = cleanvar($_POST['newpassword2']);
  311. if (empty($user->emoticons)) $user->emoticons = 'false';
  312. // Some extra checking here so that users can't edit other peoples profiles
  313. $edituserpermission = user_permission($sit[2],23); // edit user
  314. if ($edituserid != $sit[2] AND $edituserpermission == FALSE)
  315. {
  316. trigger_error('Error: No permission to edit this users profile', E_USER_ERROR);
  317. exit;
  318. }
  319. // If users status is set to 0 (disabled) force 'accepting' to no
  320. if ($user->status==0) $user->accepting='No';
  321. // Update user profile
  322. $errors = 0;
  323. // check for change of password
  324. if ($password != '' && $newpassword1 != '' && $newpassword2 != '')
  325. {
  326. // verify password fields
  327. $passwordMD5 = md5($password);
  328. if ($newpassword1 == $newpassword2 AND strcasecmp($passwordMD5, user_password($edituserid)) == 0)
  329. {
  330. $user->password = $password;
  331. }
  332. else
  333. {
  334. $errors++;
  335. $error_string .= "<h5 class='error'>{$strPasswordsDoNotMatch}</h5>";
  336. }
  337. }
  338. // update database if no errors
  339. if ($errors == 0)
  340. {
  341. $result = $user->edit();
  342. // If this is the current user, update the profile in the users session
  343. if ($edituserid == $_SESSION['userid'])
  344. {
  345. $_SESSION['style'] = $user->style;
  346. $_SESSION['realname'] = $user->realname;
  347. $_SESSION['email'] = $user->email;
  348. $_SESSION['incident_refresh'] = $user->incident_refresh;
  349. $_SESSION['update_order'] = $user->update_order;
  350. $_SESSION['num_update_view'] = $user->num_updates_view;
  351. $_SESSION['lang'] = $user->i18n;
  352. $_SESSION['utcoffset'] = $user->utc_offset;
  353. }
  354. if ($result === FALSE)
  355. {
  356. include (APPLICATION_INCPATH . 'htmlheader.inc.php');
  357. trigger_error("!Error while updating users table", E_USER_WARNING);
  358. include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
  359. exit;
  360. }
  361. elseif ($result === TRUE)
  362. {
  363. if ($edituserid==$sit[2]) $redirecturl='index.php';
  364. else $redirecturl='manage_users.php';
  365. plugin_do('save_profile_form');
  366. // password was not changed
  367. if (isset($confirm_message)) html_redirect($redirecturl, TRUE, $confirm_message);
  368. else html_redirect($redirecturl);
  369. exit;
  370. }
  371. else
  372. {
  373. $errors++;
  374. $error_string .= $result;
  375. }
  376. }
  377. if ($errors > 0)
  378. {
  379. html_redirect($redirecturl, FALSE, $error_string);
  380. }
  381. }
  382. elseif ($mode == 'savesessionlang')
  383. {
  384. $sql = "UPDATE `{$dbUsers}` SET var_i18n = '{$_SESSION['lang']}' WHERE id = {$sit[2]}";
  385. mysql_query($sql);
  386. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  387. // FIXME 3.35 use revoke instead
  388. $sql = "DELETE FROM `{$dbNotices}` WHERE type='".USER_LANG_DIFFERS_TYPE."' AND userid={$sit[2]}";
  389. mysql_query($sql);
  390. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  391. html_redirect("main.php");
  392. }
  393. ?>