PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/chronique/UserSettings.php

http://chronique.googlecode.com/
PHP | 219 lines | 162 code | 43 blank | 14 comment | 33 complexity | a238baf0a7c4b1fc9889d5c5a0dcc59f MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /* $Id: UserSettings.php 4752 2011-11-24 09:10:21Z daintree $*/
  3. include('includes/session.inc');
  4. $title = _('User Settings');
  5. include('includes/header.inc');
  6. echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/user.png" title="' .
  7. _('User Settings') . '" alt="" />' . ' ' . _('User Settings') . '</p>';
  8. $PDFLanguages = array(_('Latin Western Languages'),
  9. _('Eastern European Russian Japanese Korean Hebrew Arabic Thai'),
  10. _('Chinese'));
  11. if (isset($_POST['Modify'])) {
  12. // no input errors assumed initially before we test
  13. $InputError = 0;
  14. /* actions to take once the user has clicked the submit button
  15. ie the page has called itself with some user input */
  16. //first off validate inputs sensible
  17. if ($_POST['DisplayRecordsMax'] <= 0){
  18. $InputError = 1;
  19. prnMsg(_('The Maximum Number of Records on Display entered must not be negative') . '. ' . _('0 will default to system setting'),'error');
  20. }
  21. //!!!for the demo only - enable this check so password is not changed
  22. /*
  23. if ($_POST['pass'] != ''){
  24. $InputError = 1;
  25. prnMsg(_('Cannot change password in the demo or others would be locked out!'),'warn');
  26. }
  27. */
  28. $UpdatePassword = 'N';
  29. if ($_POST['PasswordCheck'] != ''){
  30. if (mb_strlen($_POST['Password'])<5){
  31. $InputError = 1;
  32. prnMsg(_('The password entered must be at least 5 characters long'),'error');
  33. } elseif (mb_strstr($_POST['Password'],$_SESSION['UserID'])!= False){
  34. $InputError = 1;
  35. prnMsg(_('The password cannot contain the user id'),'error');
  36. }
  37. if ($_POST['Password'] != $_POST['PasswordCheck']){
  38. $InputError = 1;
  39. prnMsg(_('The password and password confirmation fields entered do not match'),'error');
  40. }else{
  41. $UpdatePassword = 'Y';
  42. }
  43. }
  44. if ($InputError != 1) {
  45. // no errors
  46. if ($UpdatePassword != 'Y'){
  47. $sql = "UPDATE www_users
  48. SET displayrecordsmax='" . $_POST['DisplayRecordsMax'] . "',
  49. theme='" . $_POST['Theme'] . "',
  50. language='" . $_POST['Language'] . "',
  51. email='". $_POST['email'] ."',
  52. pdflanguage='" . $_POST['PDFLanguage'] . "'
  53. WHERE userid = '" . $_SESSION['UserID'] . "'";
  54. $ErrMsg = _('The user alterations could not be processed because');
  55. $DbgMsg = _('The SQL that was used to update the user and failed was');
  56. $result = DB_query($sql,$db, $ErrMsg, $DbgMsg);
  57. prnMsg( _('The user settings have been updated') . '. ' . _('Be sure to remember your password for the next time you login'),'success');
  58. } else {
  59. $sql = "UPDATE www_users
  60. SET displayrecordsmax='" . $_POST['DisplayRecordsMax'] . "',
  61. theme='" . $_POST['Theme'] . "',
  62. language='" . $_POST['Language'] . "',
  63. email='". $_POST['email'] ."',
  64. pdflanguage='" . $_POST['PDFLanguage'] . "',
  65. password='" . CryptPass($_POST['Password']) . "'
  66. WHERE userid = '" . $_SESSION['UserID'] . "'";
  67. $ErrMsg = _('The user alterations could not be processed because');
  68. $DbgMsg = _('The SQL that was used to update the user and failed was');
  69. $result = DB_query($sql,$db, $ErrMsg, $DbgMsg);
  70. prnMsg(_('The user settings have been updated'),'success');
  71. }
  72. // update the session variables to reflect user changes on-the-fly
  73. $_SESSION['DisplayRecordsMax'] = $_POST['DisplayRecordsMax'];
  74. $_SESSION['Theme'] = trim($_POST['Theme']); /*already set by session.inc but for completeness */
  75. $theme = $_SESSION['Theme'];
  76. $_SESSION['Language'] = trim($_POST['Language']);
  77. $_SESSION['PDFLanguage'] = $_POST['PDFLanguage'];
  78. include ('includes/LanguageSetup.php');
  79. }
  80. }
  81. echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF']) . '">';
  82. echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
  83. If (!isset($_POST['DisplayRecordsMax']) OR $_POST['DisplayRecordsMax']=='') {
  84. $_POST['DisplayRecordsMax'] = $_SESSION['DefaultDisplayRecordsMax'];
  85. }
  86. echo '<table class="selection">
  87. <tr>
  88. <td>' . _('User ID') . ':</td>
  89. <td>' . $_SESSION['UserID'] . '</td>
  90. </tr>';
  91. echo '<tr>
  92. <td>' . _('User Name') . ':</td>
  93. <td>' . $_SESSION['UsersRealName'] . '</td>
  94. <input type="hidden" name="RealName" value="'.$_SESSION['UsersRealName'].'" /></tr>';
  95. echo '<tr>
  96. <td>' . _('Maximum Number of Records to Display') . ':</td>
  97. <td><input type="text" class="number" name="DisplayRecordsMax" size="3" maxlength="3" value="' . $_POST['DisplayRecordsMax'] . '" ></td>
  98. </tr>';
  99. echo '<tr>
  100. <td>' . _('Language') . ':</td>
  101. <td><select name="Language">';
  102. if (!isset($_POST['Language'])){
  103. $_POST['Language']=$_SESSION['Language'];
  104. }
  105. foreach ($LanguagesArray as $LanguageEntry => $LanguageName){
  106. if (isset($_POST['Language']) AND $_POST['Language'] == $LanguageEntry){
  107. echo '<option selected value="' . $LanguageEntry . '">' . $LanguageName['LanguageName'] .'</option>';
  108. } elseif (!isset($_POST['Language']) AND $LanguageEntry == $DefaultLanguage) {
  109. echo '<option selected value="' . $LanguageEntry . '">' . $LanguageName['LanguageName'] .'</option>';
  110. } else {
  111. echo '<option value="' . $LanguageEntry . '">' . $LanguageName['LanguageName'] .'</option>';
  112. }
  113. }
  114. echo '</select></td></tr>';
  115. echo '<tr>
  116. <td>' . _('Theme') . ':</td>
  117. <td><select name="Theme">';
  118. $ThemeDirectory = dir('css/');
  119. while (false != ($ThemeName = $ThemeDirectory->read())){
  120. if (is_dir('css/' . $ThemeName) AND $ThemeName != '.' AND $ThemeName != '..' AND $ThemeName != '.svn'){
  121. if ($_SESSION['Theme'] == $ThemeName){
  122. echo '<option selected value="' . $ThemeName . '">' . $ThemeName . '</option>';
  123. } else {
  124. echo '<option value="' . $ThemeName . '">' . $ThemeName . '</option>';
  125. }
  126. }
  127. }
  128. if (!isset($_POST['PasswordCheck'])) {
  129. $_POST['PasswordCheck']='';
  130. }
  131. if (!isset($_POST['Password'])) {
  132. $_POST['Password']='';
  133. }
  134. echo '</select></td></tr>
  135. <tr>
  136. <td>' . _('New Password') . ':</td>
  137. <td><input type="password" name="Password" size="20" value="' . $_POST['Password'] . '" /></td>
  138. </tr>
  139. <tr>
  140. <td>' . _('Confirm Password') . ':</td>
  141. <td><input type="password" name="PasswordCheck" size="20" value="' . $_POST['PasswordCheck'] . '" /></td>
  142. </tr>
  143. <tr>
  144. <td colspan=2 align="center"><i>' . _('If you leave the password boxes empty your password will not change') . '</i></td>
  145. </tr>
  146. <tr>
  147. <td>' . _('Email') . ':</td>';
  148. $sql = "SELECT email from www_users WHERE userid = '" . $_SESSION['UserID'] . "'";
  149. $result = DB_query($sql,$db);
  150. $myrow = DB_fetch_array($result);
  151. if(!isset($_POST['email'])){
  152. $_POST['email'] = $myrow['email'];
  153. }
  154. echo '<td><input type="text" name="email" size=40 value="' . $_POST['email'] . '" /></td>
  155. </tr>';
  156. if (!isset($_POST['PDFLanguage'])){
  157. $_POST['PDFLanguage']=$_SESSION['PDFLanguage'];
  158. }
  159. echo '<tr>
  160. <td>' . _('PDF Language Support') . ': </td>
  161. <td><select name="PDFLanguage">';
  162. for($i=0;$i<count($PDFLanguages);$i++){
  163. if ($_POST['PDFLanguage']==$i){
  164. echo '<option selected value=' . $i .'>' . $PDFLanguages[$i] . '</option>';
  165. } else {
  166. echo '<option value=' . $i .'>' . $PDFLanguages[$i]. '</option>';
  167. }
  168. }
  169. echo '</select></td>
  170. </tr>
  171. </table>
  172. <br />
  173. <div class="centre"><input type="submit" name="Modify" value="' . _('Modify') . '"></div>
  174. </form>';
  175. include('includes/footer.inc');
  176. ?>