1
0

edit_user.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. function exec_ogp_module() {
  25. global $db, $settings;
  26. // Check if the user_id is set in the uri first. Prevents notices if it's been removed.
  27. if(!isset($_REQUEST['user_id']) === true){
  28. print_failure(get_lang('valid_user'));
  29. return;
  30. }
  31. $my_user_id = $_SESSION['user_id']; #who we're logged in as
  32. $user_id = $_REQUEST['user_id'];
  33. $isAdmin = $db->isAdmin($my_user_id);
  34. $mySubUsers = $db->getUsersSubUsersIds($_SESSION['user_id']);
  35. // Check that the user_id parameter corresponds to a valid user.
  36. if(($userInfo = $db->getUserById($user_id)) === null)
  37. {
  38. print_failure(get_lang('valid_user'));
  39. return;
  40. }
  41. // Allow user to modify owned subuser account information
  42. else if ( ! $isAdmin && $my_user_id !== $user_id && @!in_array($user_id, $mySubUsers))
  43. {
  44. print_failure(get_lang('no_rights'));
  45. return;
  46. }
  47. if ( $isAdmin )
  48. {
  49. $users = $db->getUserList();
  50. foreach ( $users as $user )
  51. {
  52. if ( $db->isAdmin($user['user_id']) )
  53. {
  54. $first_admin_id = $user['user_id'];
  55. break;
  56. }
  57. }
  58. if( $db->isAdmin($user_id) and ( $first_admin_id != $my_user_id ) and ( $user_id != $my_user_id ) )
  59. {
  60. print_failure(get_lang('no_rights'));
  61. return;
  62. }
  63. }
  64. echo "<h2>".($my_user_id !== $user_id ? get_lang_f('editing_profile', htmlentities($userInfo['users_login'])) : get_lang('your_profile'))."</h2>";
  65. echo "<div align='center'>";
  66. require_once("includes/form_table_class.php");
  67. if ( ( isset($_POST['new_password']) || isset($_POST['retype_new_password']) ) &&
  68. $_POST['new_password'] !== $_POST['retype_new_password'] )
  69. {
  70. print_failure(get_lang('password_mismatch'));
  71. }
  72. # If we are editing our own profile we need to enter our current password as well
  73. elseif (isset($_POST['edit_user']) &&
  74. ($my_user_id === $user_id) &&
  75. !$db->is_valid_login($my_user_id,$_REQUEST['current_password']))
  76. {
  77. print_failure(get_lang('current_password_mismatch'));
  78. }
  79. else if (isset($_POST['edit_user']))
  80. {
  81. $user_id = sanitizeInputStr($_POST['user_id']);
  82. $newlang = sanitizeInputStr($_POST['newlang']);
  83. $login = sanitizeInputStr($_POST['login']);
  84. $firstname = sanitizeInputStr($_POST['first_name']);
  85. $lastname = sanitizeInputStr($_POST['last_name']);
  86. $email = sanitizeInputStr($_POST['email_address']);
  87. $city = sanitizeInputStr($_POST['city']);
  88. $province = sanitizeInputStr($_POST['province']);
  89. $country = sanitizeInputStr($_POST['country']);
  90. $phone = sanitizeInputStr($_POST['phone_number']);
  91. $phone = preg_replace("/[^0-9]/", "", $phone);
  92. $theme = sanitizeInputStr($_POST['theme']);
  93. $page_limit = sanitizeInputStr($_POST['page_limit']);
  94. // OGP needs to set the new theme and language in the current session, only if I'm modifying my own user profile.
  95. if ( $my_user_id == $user_id )
  96. {
  97. $_SESSION['users_theme'] = $theme;
  98. $_SESSION['users_lang'] = $newlang;
  99. }
  100. $fields['users_lang'] = $newlang;
  101. $fields['users_fname'] = $firstname;
  102. $fields['users_lname'] = $lastname;
  103. $fields['users_phone'] = $phone;
  104. $fields['users_city'] = $city;
  105. $fields['users_province'] = $province;
  106. $fields['users_country'] = $country;
  107. if( isset($settings['editable_email']) )
  108. {
  109. if( $settings['editable_email'] == "1" OR ( $settings['editable_email'] == "0" and $isAdmin ) )
  110. $fields['users_email'] = $email;
  111. }
  112. elseif( !isset( $settings['editable_email'] ) )
  113. {
  114. $fields['users_email'] = $email;
  115. }
  116. if ( $isAdmin )
  117. {
  118. $mins = sanitizeInputStr($_POST['minutes']);
  119. $hours = sanitizeInputStr($_POST['hours']);
  120. $months = sanitizeInputStr($_POST['month']);
  121. $days = sanitizeInputStr($_POST['days']);
  122. $years = sanitizeInputStr($_POST['years']);
  123. if($months == 'X' || $days == 'X' || $years == 'X' || $hours == 'X' || $mins == 'X')
  124. $expire_timestamp = "X";
  125. else
  126. $expire_timestamp = mktime( $hours, $mins, 0, $months, $days, $years, -1);
  127. $fields['users_role'] = sanitizeInputStr($_POST['newrole']);
  128. $fields['users_comment'] = sanitizeInputStr($_POST['comment']);
  129. $fields['user_expires'] = $expire_timestamp;
  130. $fields['users_login'] = $login;
  131. }
  132. if ( empty($theme) )
  133. $fields['users_theme'] = NULL;
  134. else
  135. $fields['users_theme'] = $theme;
  136. if (empty($page_limit) || !is_numeric($page_limit) || $page_limit < 10){
  137. $fields['users_page_limit'] = 25;
  138. }else{
  139. if($page_limit > 9999){
  140. $page_limit = 9999;
  141. }
  142. $fields['users_page_limit'] = $page_limit;
  143. }
  144. if ( isset($_POST['new_password']) && !empty($_POST['new_password']) )
  145. $fields['users_passwd'] = md5($_POST['new_password']);
  146. if ( !$db->editUser($fields,$user_id) )
  147. {
  148. print_failure(get_lang_f('failed_to_update_user_profile_error', $db->getError()));
  149. }
  150. else
  151. {
  152. print_success(get_lang_f('profile_of_user_modified_successfully',$login));
  153. $db->logger(get_lang_f('profile_of_user_modified_successfully',$login));
  154. }
  155. global $view;
  156. if ( $isAdmin )
  157. {
  158. $view->refresh("?m=user_admin");
  159. }
  160. else
  161. {
  162. if(isset($_SESSION['REFER']))
  163. $view->refresh($_SESSION['REFER']);
  164. else
  165. $view->refresh("?m=user_admin&amp;p=edit_user&user_id=".$_SESSION['user_id']);
  166. }
  167. return;
  168. }
  169. $ft = new FormTable();
  170. $ft->start_form('?m=user_admin&amp;p=edit_user');
  171. $ft->add_field_hidden('user_id',$user_id);
  172. $ft->start_table();
  173. $login_option = ( !$isAdmin ) ? 'readonly="readonly"' : "";
  174. $ft->add_field('string','login',$userInfo['users_login'],50,$login_option);
  175. if ( $my_user_id === $user_id )
  176. {
  177. $ft->add_field('password','current_password','');
  178. }
  179. $ft->add_field('password','new_password','');
  180. $ft->add_field('password','retype_new_password','');
  181. $locale_files = makefilelist("lang/", ".|..|.svn", true, "folders");
  182. array_push($locale_files,"-");
  183. sort($locale_files);
  184. $ft->add_custom_field('language',
  185. create_drop_box_from_array($locale_files,"newlang",@$userInfo['users_lang']));
  186. require_once('modules/settings/functions.php');
  187. $theme = "";
  188. $add_empty = FALSE;
  189. if ( isset($userInfo['users_theme']) )
  190. {
  191. $theme = $userInfo['users_theme'];
  192. $add_empty = TRUE;
  193. }
  194. $ft->add_custom_field('theme', get_theme_html_str($theme, $add_empty));
  195. $ft->add_field('string','page_limit',$userInfo['users_page_limit']);
  196. $ft->add_field('string','first_name',$userInfo['users_fname']);
  197. $ft->add_field('string','last_name',$userInfo['users_lname']);
  198. $ft->add_field('string','phone_number',$userInfo['users_phone']);
  199. $email_option = ( !$isAdmin and isset( $settings['editable_email'] ) and $settings['editable_email'] == "0" ) ? 'readonly="readonly"' : "";
  200. $ft->add_field('string','email_address',$userInfo['users_email'],50,$email_option);
  201. $ft->add_field('string','city',$userInfo['users_city']);
  202. $ft->add_field('string','province',$userInfo['users_province']);
  203. $ft->add_field('string','country',$userInfo['users_country']);
  204. if ( $isAdmin && $userInfo['users_role'] != "subuser" ) {
  205. $ft->add_custom_field('user_role',
  206. create_drop_box_from_array(array('user', 'admin'),"newrole", $userInfo['users_role']));
  207. $ft->add_field('text','comment',$userInfo['users_comment']);
  208. ?>
  209. <tr>
  210. <td align='right'><?php print_lang('expires'); ?>:</td>
  211. <?php
  212. $timediff = $userInfo["user_expires"];
  213. //echo "Timediff is $timediff<br>";
  214. if(read_expire($timediff) !== 'X')
  215. {
  216. $exday = date("j", $timediff);
  217. $exyear = date("Y", $timediff);
  218. $exmonth = date("m", $timediff);
  219. $exhour = date("H", $timediff);
  220. $exmin = date("i", $timediff);
  221. }
  222. else
  223. {
  224. $exday = "X";
  225. $exyear = "X";
  226. $exmonth = "X";
  227. $exhour = "X";
  228. $exmin = "X";
  229. }
  230. $minutes = range(0,59);
  231. $pad_length = 2;
  232. foreach ($minutes as &$minute)
  233. {
  234. $minute = str_pad($minute, $pad_length, "0", STR_PAD_LEFT);
  235. }
  236. $months = array('X' => 'X', '1' => 'Jan', '2' => 'Feb', '3' => 'Mar', '4' => 'Apr', '5' => 'May', '6' => 'Jun', '7' => 'July',
  237. '8' => 'Aug', '9' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
  238. #The ugliness below is to populate the expiration fields with what is in the db
  239. #Looks bad, but it works well
  240. echo "<td align='left'>";
  241. $x_array = array('X');
  242. echo create_drop_box_from_array(array_merge($x_array,range(1,31)),"days",$exday,true);
  243. echo create_drop_box_from_array($months,"month",$exmonth,false);
  244. echo create_drop_box_from_array(array_merge($x_array,range(date('Y')-1,date('Y')+10)),
  245. "years",$exyear,true);
  246. echo " - ";
  247. echo create_drop_box_from_array(array_merge($x_array,range(0,23)),"hours",$exhour,true);
  248. echo ":";
  249. echo create_drop_box_from_array(array_merge($x_array,$minutes),"minutes",$exmin,true);
  250. echo "<tr><td colspan='2' class='info'>".get_lang('expires_info')."</td></tr>";
  251. }
  252. $ft->end_table();
  253. $ft->add_button("submit","edit_user",get_lang('save_profile'));
  254. $ft->end_form();
  255. echo "</div>";
  256. }
  257. ?>