PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/Quản lý website thi trắc nghiệm qua mạng PHP/tracnghiem/inc/pages/manageusers-3.inc.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 190 lines | 186 code | 4 blank | 0 comment | 83 complexity | 443657375e1f42397557afb93bb8afed MD5 | raw file
  1. <?php
  2. $f_userid = (int)readGetVar('userid');
  3. $bIsNewUser = ($f_userid <= 0);
  4. if(!$bIsNewUser) {
  5. $arrValuesToUpdate = array();
  6. $arrValuesToUpdate['userid'] = $f_userid;
  7. }
  8. if(isset($_POST['user_enabled']))
  9. $arrValuesToUpdate['user_enabled'] = (int)(boolean)readPostVar('user_enabled');
  10. if(isset($_POST['user_expiredate'])) {
  11. $f_user_expiredate = readPostVar('user_expiredate');
  12. if(empty($f_user_expiredate))
  13. $f_user_expiredate = 0;
  14. else $f_user_expiredate = (int)strtotime($f_user_expiredate);
  15. $arrValuesToUpdate['user_expiredate'] = $f_user_expiredate;
  16. }
  17. if(isset($_POST['user_name']))
  18. $arrValuesToUpdate['user_name'] = readPostVar('user_name');
  19. if(isset($_POST['user_password']) && (strlen($_POST['user_password']) > 0)) {
  20. $f_user_password = readPostVar('user_password');
  21. $f_user_password_confirm = readPostVar('user_password_confirm');
  22. if($f_user_password == $f_user_password_confirm) {
  23. if(get_magic_quotes_gpc())
  24. $f_user_password = stripslashes($f_user_password);
  25. $i_pass_hash = md5($f_user_password);
  26. $arrValuesToUpdate['user_passhash'] = $i_pass_hash;
  27. } else {
  28. $g_vars['page']['errors'] .= $lngstr['page_register']['no_password'];
  29. }
  30. }
  31. if(isset($_POST['user_email']))
  32. $arrValuesToUpdate['user_email'] = readPostVar('user_email');
  33. if(isset($_POST['user_firstname']))
  34. $arrValuesToUpdate['user_firstname'] = readPostVar('user_firstname');
  35. if(isset($_POST['user_lastname']))
  36. $arrValuesToUpdate['user_lastname'] = readPostVar('user_lastname');
  37. if(isset($_POST['user_middlename']))
  38. $arrValuesToUpdate['user_middlename'] = readPostVar('user_middlename');
  39. if(isset($_POST['user_address']))
  40. $arrValuesToUpdate['user_address'] = readPostVar('user_address');
  41. if(isset($_POST['user_city']))
  42. $arrValuesToUpdate['user_city'] = readPostVar('user_city');
  43. if(isset($_POST['user_state']))
  44. $arrValuesToUpdate['user_state'] = readPostVar('user_state');
  45. if(isset($_POST['user_zip']))
  46. $arrValuesToUpdate['user_zip'] = readPostVar('user_zip');
  47. if(isset($_POST['user_country']))
  48. $arrValuesToUpdate['user_country'] = readPostVar('user_country');
  49. if(isset($_POST['user_phone']))
  50. $arrValuesToUpdate['user_phone'] = readPostVar('user_phone');
  51. if(isset($_POST['user_fax']))
  52. $arrValuesToUpdate['user_fax'] = readPostVar('user_fax');
  53. if(isset($_POST['user_mobile']))
  54. $arrValuesToUpdate['user_mobile'] = readPostVar('user_mobile');
  55. if(isset($_POST['user_pager']))
  56. $arrValuesToUpdate['user_pager'] = readPostVar('user_pager');
  57. if(isset($_POST['user_ipphone']))
  58. $arrValuesToUpdate['user_ipphone'] = readPostVar('user_ipphone');
  59. if(isset($_POST['user_webpage']))
  60. $arrValuesToUpdate['user_webpage'] = readPostVar('user_webpage');
  61. if(isset($_POST['user_icq']))
  62. $arrValuesToUpdate['user_icq'] = readPostVar('user_icq');
  63. if(isset($_POST['user_msn']))
  64. $arrValuesToUpdate['user_msn'] = readPostVar('user_msn');
  65. if(isset($_POST['user_aol']))
  66. $arrValuesToUpdate['user_aol'] = readPostVar('user_aol');
  67. if(isset($_POST['user_gender']))
  68. $arrValuesToUpdate['user_gender'] = readPostVar('user_gender');
  69. if(isset($_POST['user_husbandwife']))
  70. $arrValuesToUpdate['user_husbandwife'] = readPostVar('user_husbandwife');
  71. if(isset($_POST['user_children']))
  72. $arrValuesToUpdate['user_children'] = readPostVar('user_children');
  73. if(isset($_POST['user_trainer']))
  74. $arrValuesToUpdate['user_trainer'] = readPostVar('user_trainer');
  75. if(isset($_POST['user_photo']))
  76. $arrValuesToUpdate['user_photo'] = readPostVar('user_photo');
  77. if(isset($_POST['user_company']))
  78. $arrValuesToUpdate['user_company'] = readPostVar('user_company');
  79. if(isset($_POST['user_cposition']))
  80. $arrValuesToUpdate['user_cposition'] = readPostVar('user_cposition');
  81. if(isset($_POST['user_department']))
  82. $arrValuesToUpdate['user_department'] = readPostVar('user_department');
  83. if(isset($_POST['user_coffice']))
  84. $arrValuesToUpdate['user_coffice'] = readPostVar('user_coffice');
  85. if(isset($_POST['user_caddress']))
  86. $arrValuesToUpdate['user_caddress'] = readPostVar('user_caddress');
  87. if(isset($_POST['user_ccity']))
  88. $arrValuesToUpdate['user_ccity'] = readPostVar('user_ccity');
  89. if(isset($_POST['user_cstate']))
  90. $arrValuesToUpdate['user_cstate'] = readPostVar('user_cstate');
  91. if(isset($_POST['user_czip']))
  92. $arrValuesToUpdate['user_czip'] = readPostVar('user_czip');
  93. if(isset($_POST['user_ccountry']))
  94. $arrValuesToUpdate['user_ccountry'] = readPostVar('user_ccountry');
  95. if(isset($_POST['user_cphone']))
  96. $arrValuesToUpdate['user_cphone'] = readPostVar('user_cphone');
  97. if(isset($_POST['user_cfax']))
  98. $arrValuesToUpdate['user_cfax'] = readPostVar('user_cfax');
  99. if(isset($_POST['user_cmobile']))
  100. $arrValuesToUpdate['user_cmobile'] = readPostVar('user_cmobile');
  101. if(isset($_POST['user_cpager']))
  102. $arrValuesToUpdate['user_cpager'] = readPostVar('user_cpager');
  103. if(isset($_POST['user_cipphone']))
  104. $arrValuesToUpdate['user_cipphone'] = readPostVar('user_cipphone');
  105. if(isset($_POST['user_cwebpage']))
  106. $arrValuesToUpdate['user_cwebpage'] = readPostVar('user_cwebpage');
  107. if(isset($_POST['user_cphoto']))
  108. $arrValuesToUpdate['user_cphoto'] = readPostVar('user_cphoto');
  109. if(getConfigItem(CONFIG_reg_userfield1) > CONFIG_CONST_donotshow) {
  110. if(isset($_POST['user_ufield1']))
  111. $arrValuesToUpdate['user_ufield1'] = readPostVar('user_ufield1');
  112. }
  113. if(getConfigItem(CONFIG_reg_userfield2) > CONFIG_CONST_donotshow) {
  114. if(isset($_POST['user_ufield2']))
  115. $arrValuesToUpdate['user_ufield2'] = readPostVar('user_ufield2');
  116. }
  117. if(getConfigItem(CONFIG_reg_userfield3) > CONFIG_CONST_donotshow) {
  118. if(isset($_POST['user_ufield3']))
  119. $arrValuesToUpdate['user_ufield3'] = readPostVar('user_ufield3');
  120. }
  121. if(getConfigItem(CONFIG_reg_userfield4) > CONFIG_CONST_donotshow) {
  122. if(isset($_POST['user_ufield4']))
  123. $arrValuesToUpdate['user_ufield4'] = readPostVar('user_ufield4');
  124. }
  125. if(getConfigItem(CONFIG_reg_userfield5) > CONFIG_CONST_donotshow) {
  126. if(isset($_POST['user_ufield5']))
  127. $arrValuesToUpdate['user_ufield5'] = readPostVar('user_ufield5');
  128. }
  129. if(getConfigItem(CONFIG_reg_userfield6) > CONFIG_CONST_donotshow) {
  130. if(isset($_POST['user_ufield6']))
  131. $arrValuesToUpdate['user_ufield6'] = readPostVar('user_ufield6');
  132. }
  133. if(getConfigItem(CONFIG_reg_userfield7) > CONFIG_CONST_donotshow) {
  134. if(isset($_POST['user_ufield7']))
  135. $arrValuesToUpdate['user_ufield7'] = readPostVar('user_ufield7');
  136. }
  137. if(getConfigItem(CONFIG_reg_userfield8) > CONFIG_CONST_donotshow) {
  138. if(isset($_POST['user_ufield8']))
  139. $arrValuesToUpdate['user_ufield8'] = readPostVar('user_ufield8');
  140. }
  141. if(getConfigItem(CONFIG_reg_userfield9) > CONFIG_CONST_donotshow) {
  142. if(isset($_POST['user_ufield9']))
  143. $arrValuesToUpdate['user_ufield9'] = readPostVar('user_ufield9');
  144. }
  145. if(getConfigItem(CONFIG_reg_userfield10) > CONFIG_CONST_donotshow) {
  146. if(isset($_POST['user_ufield10']))
  147. $arrValuesToUpdate['user_ufield10'] = readPostVar('user_ufield10');
  148. }
  149. if(isset($_POST['user_notes']))
  150. $arrValuesToUpdate['user_notes'] = readPostVar('user_notes');
  151. $bIsUserNameDuplicated = getRecordCount($srv_settings['table_prefix'].'users', 'user_name='.$arrValuesToUpdate['user_name'].(!$bIsNewUser ? ' AND userid<>'.$arrValuesToUpdate['userid'] : '')) > 0;
  152. if($bIsUserNameDuplicated)
  153. $g_vars['page']['errors'] .= $lngstr['err_username_duplicate'];
  154. if($g_vars['page']['errors']) {
  155. include_once($DOCUMENT_PAGES."manageusers-2.inc.php");
  156. } else {
  157. if($bIsNewUser) {
  158. $f_userid = addNewUser($arrValuesToUpdate, array(), true);
  159. } else {
  160. updateUser($arrValuesToUpdate);
  161. }
  162. if(isset($_POST['group']) && !empty($_POST['group'][0])) {
  163. $arrGroupIDsNew = readPostVar('group');
  164. unset($arrGroupIDsNew[0]);
  165. $arrGroupIDsToAdd = array();
  166. $arrGroupIDsToDelete = array();
  167. $i_rSet1 = $g_db->Execute("SELECT ".$srv_settings['table_prefix']."groups_users.groupid FROM ".$srv_settings['table_prefix']."groups_users WHERE userid=".$f_userid);
  168. if(!$i_rSet1) {
  169. showDBError(__FILE__, 1);
  170. } else {
  171. while(!$i_rSet1->EOF) {
  172. if(!empty($arrGroupIDsNew[$i_rSet1->fields['groupid']]))
  173. unset($arrGroupIDsNew[$i_rSet1->fields['groupid']]);
  174. else array_push($arrGroupIDsToDelete, $i_rSet1->fields['groupid']);
  175. $i_rSet1->MoveNext();
  176. }
  177. $i_rSet1->Close();
  178. }
  179. foreach($arrGroupIDsNew as $key=>$val)
  180. array_push($arrGroupIDsToAdd, $key);
  181. manageUserGroups(array($f_userid), $arrGroupIDsToAdd, true);
  182. manageUserGroups(array($f_userid), $arrGroupIDsToDelete, false);
  183. }
  184. gotoLocation('users.php');
  185. }
  186. ?>