user_edit.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once '../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script(true);
  10. $user_id = isset($_GET['user_id']) ? intval($_GET['user_id']) : intval($_POST['user_id']);
  11. api_protect_super_admin($user_id, null, true);
  12. $is_platform_admin = api_is_platform_admin() ? 1 : 0;
  13. $userInfo = api_get_user_info($user_id);
  14. $htmlHeadXtra[] = '
  15. <script>
  16. var is_platform_id = "'.$is_platform_admin.'";
  17. function enable_expiration_date() {
  18. document.user_edit.radio_expiration_date[0].checked=false;
  19. document.user_edit.radio_expiration_date[1].checked=true;
  20. }
  21. function password_switch_radio_button(){
  22. var input_elements = document.getElementsByTagName("input");
  23. for (var i = 0; i < input_elements.length; i++) {
  24. if(input_elements.item(i).name == "reset_password" && input_elements.item(i).value == "2") {
  25. input_elements.item(i).checked = true;
  26. }
  27. }
  28. }
  29. function display_drh_list(){
  30. var $radios = $("input:radio[name=platform_admin]");
  31. if (document.getElementById("status_select").value=='.COURSEMANAGER.') {
  32. if (is_platform_id == 1)
  33. document.getElementById("id_platform_admin").style.display="block";
  34. } else if (document.getElementById("status_select").value=='.STUDENT.') {
  35. if (is_platform_id == 1)
  36. document.getElementById("id_platform_admin").style.display="none";
  37. $radios.filter("[value=0]").attr("checked", true);
  38. } else {
  39. if (is_platform_id == 1)
  40. document.getElementById("id_platform_admin").style.display="none";
  41. $radios.filter("[value=0]").attr("checked", true);
  42. }
  43. }
  44. function show_image(image,width,height) {
  45. width = parseInt(width) + 20;
  46. height = parseInt(height) + 20;
  47. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \' , resizable=0\');
  48. }
  49. function confirmation(name) {
  50. if (confirm("'.get_lang('AreYouSureToDeleteJS', '').' " + name + " ?")) {
  51. document.forms["profile"].submit();
  52. } else {
  53. return false;
  54. }
  55. }
  56. </script>';
  57. $userGeolocalization = api_get_setting('enable_profile_user_address_geolocalization') == 'true';
  58. $htmlHeadXtra[] = '<link href="'. api_get_path(WEB_PATH) .'web/assets/cropper/dist/cropper.min.css" rel="stylesheet">';
  59. $htmlHeadXtra[] = '<script src="'. api_get_path(WEB_PATH) .'web/assets/cropper/dist/cropper.min.js"></script>';
  60. $htmlHeadXtra[] = '<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=true" ></script>';
  61. $htmlHeadXtra[] = '<script>
  62. $(document).ready(function() {
  63. var $image = $("#previewImage");
  64. var $input = $("[name=\'cropResult\']");
  65. var $cropButton = $("#cropButton");
  66. $("input:file").change(function() {
  67. var oFReader = new FileReader();
  68. oFReader.readAsDataURL(document.getElementById("picture").files[0]);
  69. oFReader.onload = function (oFREvent) {
  70. $image.attr("src", this.result);
  71. $("#labelCropImage").html("'.get_lang('Preview').'");
  72. $("#cropImage").addClass("thumbnail");
  73. $cropButton.removeClass("hidden");
  74. // Destroy cropper
  75. $image.cropper("destroy");
  76. $image.cropper({
  77. aspectRatio: 1 / 1,
  78. responsive : true,
  79. center : false,
  80. guides : false,
  81. movable: false,
  82. zoomable: false,
  83. rotatable: false,
  84. scalable: false,
  85. crop: function(e) {
  86. // Output the result data for cropping image.
  87. $input.val(e.x+","+e.y+","+e.width+","+e.height);
  88. }
  89. });
  90. };
  91. });
  92. $("#cropButton").on("click", function() {
  93. var canvas = $image.cropper("getCroppedCanvas");
  94. var dataUrl = canvas.toDataURL();
  95. $image.attr("src", dataUrl);
  96. $image.cropper("destroy");
  97. $cropButton.addClass("hidden");
  98. return false;
  99. });
  100. });
  101. </script>';
  102. $libpath = api_get_path(LIBRARY_PATH);
  103. $noPHP_SELF = true;
  104. $tool_name = get_lang('ModifyUserInfo');
  105. $interbreadcrumb[] = array('url' => 'index.php', "name" => get_lang('PlatformAdmin'));
  106. $interbreadcrumb[] = array('url' => "user_list.php", "name" => get_lang('UserList'));
  107. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  108. $table_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
  109. $sql = "SELECT u.*, a.user_id AS is_admin FROM $table_user u
  110. LEFT JOIN $table_admin a ON a.user_id = u.id
  111. WHERE u.id = '".$user_id."'";
  112. $res = Database::query($sql);
  113. if (Database::num_rows($res) != 1) {
  114. header('Location: user_list.php');
  115. exit;
  116. }
  117. $user_data = Database::fetch_array($res, 'ASSOC');
  118. $user_data['platform_admin'] = is_null($user_data['is_admin']) ? 0 : 1;
  119. $user_data['send_mail'] = 0;
  120. $user_data['old_password'] = $user_data['password'];
  121. //Convert the registration date of the user
  122. $user_data['registration_date'] = api_get_local_time($user_data['registration_date']);
  123. unset($user_data['password']);
  124. if ($userGeolocalization) {
  125. $htmlHeadXtra[] = '<script>
  126. $(document).ready(function() {
  127. var address = "' . $user_data['address'] . '";
  128. initializeGeo(address, false);
  129. $("#geolocalization").on("click", function() {
  130. var address = $("#address").val();
  131. initializeGeo(address, false);
  132. return false;
  133. });
  134. $("#myLocation").on("click", function() {
  135. myLocation();
  136. return false;
  137. });
  138. $("#address").keypress(function (event) {
  139. if (event.which == 13) {
  140. $("#geolocalization").click();
  141. return false;
  142. }
  143. });
  144. });
  145. function myLocation() {
  146. if (navigator.geolocation) {
  147. var geoPosition = function(position) {
  148. var lat = position.coords.latitude;
  149. var lng = position.coords.longitude;
  150. var latLng = new google.maps.LatLng(lat, lng);
  151. initializeGeo(false, latLng)
  152. };
  153. var geoError = function(error) {
  154. alert("Geocode ' . get_lang('Error') . ': " + error);
  155. };
  156. var geoOptions = {
  157. enableHighAccuracy: true
  158. };
  159. navigator.geolocation.getCurrentPosition(geoPosition, geoError, geoOptions);
  160. }
  161. }
  162. function initializeGeo(address, latLng) {
  163. var geocoder = new google.maps.Geocoder();
  164. var latlng = new google.maps.LatLng(-34.397, 150.644);
  165. var myOptions = {
  166. zoom: 15,
  167. center: latlng,
  168. mapTypeControl: true,
  169. mapTypeControlOptions: {
  170. style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
  171. },
  172. navigationControl: true,
  173. mapTypeId: google.maps.MapTypeId.ROADMAP
  174. };
  175. map = new google.maps.Map(document.getElementById("map"), myOptions);
  176. var parameter = address ? { "address": address } : latLng ? { "latLng": latLng } : false;
  177. if (geocoder && parameter) {
  178. geocoder.geocode(parameter, function(results, status) {
  179. if (status == google.maps.GeocoderStatus.OK) {
  180. if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
  181. map.setCenter(results[0].geometry.location);
  182. if (!address) {
  183. $("#address").val(results[0].formatted_address);
  184. }
  185. var infowindow = new google.maps.InfoWindow({
  186. content: "<b>" + $("#address").val() + "</b>",
  187. size: new google.maps.Size(150, 50)
  188. });
  189. var marker = new google.maps.Marker({
  190. position: results[0].geometry.location,
  191. map: map,
  192. title: $("#address").val()
  193. });
  194. google.maps.event.addListener(marker, "click", function() {
  195. infowindow.open(map, marker);
  196. });
  197. } else {
  198. alert("' . get_lang("NotFound") . '");
  199. }
  200. } else {
  201. alert("Geocode ' . get_lang('Error') . ': " + status);
  202. }
  203. });
  204. }
  205. }
  206. </script>';
  207. }
  208. // Create the form
  209. $form = new FormValidator(
  210. 'user_edit',
  211. 'post',
  212. api_get_self().'?user_id='.$user_id,
  213. ''
  214. );
  215. $form->addElement('header', $tool_name);
  216. $form->addElement('hidden', 'user_id', $user_id);
  217. if (api_is_western_name_order()) {
  218. // Firstname
  219. $form->addElement('text', 'firstname', get_lang('FirstName'));
  220. $form->applyFilter('firstname', 'html_filter');
  221. $form->applyFilter('firstname', 'trim');
  222. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  223. // Lastname
  224. $form->addElement('text', 'lastname', get_lang('LastName'));
  225. $form->applyFilter('lastname', 'html_filter');
  226. $form->applyFilter('lastname', 'trim');
  227. $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
  228. } else {
  229. // Lastname
  230. $form->addElement('text', 'lastname', get_lang('LastName'));
  231. $form->applyFilter('lastname', 'html_filter');
  232. $form->applyFilter('lastname', 'trim');
  233. $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
  234. // Firstname
  235. $form->addElement('text', 'firstname', get_lang('FirstName'));
  236. $form->applyFilter('firstname', 'html_filter');
  237. $form->applyFilter('firstname', 'trim');
  238. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  239. }
  240. // Official code
  241. $form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => '40'));
  242. $form->applyFilter('official_code', 'html_filter');
  243. $form->applyFilter('official_code', 'trim');
  244. // Email
  245. $form->addElement('text', 'email', get_lang('Email'));
  246. $form->addRule('email', get_lang('EmailWrong'), 'email');
  247. if (api_get_setting('registration', 'email') == 'true') {
  248. $form->addRule('email', get_lang('EmailWrong'), 'required');
  249. }
  250. if (api_get_setting('login_is_email') == 'true') {
  251. $form->addRule('email', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  252. $form->addRule('email', get_lang('UserTaken'), 'username_available', $user_data['username']);
  253. }
  254. // OpenID
  255. if (api_get_setting('openid_authentication') == 'true') {
  256. $form->addElement('text', 'openid', get_lang('OpenIDURL'));
  257. }
  258. // Phone
  259. $form->addElement('text', 'phone', get_lang('PhoneNumber'));
  260. if ($userGeolocalization) {
  261. // Geolocation
  262. $form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
  263. $form->addHtml('
  264. <div class="form-group">
  265. <label for="geolocalization" class="col-sm-2 control-label"></label>
  266. <div class="col-sm-8">
  267. <button class="null btn btn-default " id="geolocalization" name="geolocalization" type="submit"><em class="fa fa-map-marker"></em> '.get_lang('Geolocalization').'</button>
  268. <button class="null btn btn-default " id="myLocation" name="myLocation" type="submit"><em class="fa fa-crosshairs"></em> '.get_lang('MyLocation').'</button>
  269. </div>
  270. </div>
  271. ');
  272. $form->addHtml('
  273. <div class="form-group">
  274. <label for="map" class="col-sm-2 control-label">
  275. '.get_lang('Map').'
  276. </label>
  277. <div class="col-sm-8">
  278. <div name="map" id="map" style="width:100%; height:300px;">
  279. </div>
  280. </div>
  281. </div>
  282. ');
  283. }
  284. // Picture
  285. $form->addElement('file', 'picture', get_lang('AddPicture'), array('id' => 'picture', 'class' => 'picture-form'));
  286. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  287. $form->addHtml('<div class="form-group">
  288. <label for="cropImage" id="labelCropImage" class="col-sm-2 control-label"></label>
  289. <div class="col-sm-8">
  290. <div id="cropImage" class="cropCanvas">
  291. <img id="previewImage" >
  292. </div>
  293. <div>
  294. <button class="btn btn-primary hidden" name="cropButton" id="cropButton">
  295. <em class="fa fa-crop"></em> '.get_lang('CropYourPicture').'</button>
  296. </div>
  297. </div>
  298. </div>');
  299. $form->addHidden('cropResult', '');
  300. $form->addRule(
  301. 'picture',
  302. get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
  303. 'filetype',
  304. $allowed_picture_types
  305. );
  306. if (strlen($user_data['picture_uri']) > 0) {
  307. $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
  308. }
  309. // Username
  310. if (api_get_setting('login_is_email') != 'true') {
  311. $form->addElement('text', 'username', get_lang('LoginName'), array('maxlength' => USERNAME_MAX_LENGTH));
  312. $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
  313. $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
  314. $form->addRule('username', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
  315. $form->addRule('username', get_lang('UserTaken'), 'username_available', $user_data['username']);
  316. }
  317. if (isset($extAuthSource) && !empty($extAuthSource) && count($extAuthSource) > 0) {
  318. $form->addLabel(
  319. get_lang('ExternalAuthentication'),
  320. $userInfo['auth_source']
  321. );
  322. }
  323. // Password
  324. $form->addElement('radio', 'reset_password', get_lang('Password'), get_lang('DontResetPassword'), 0);
  325. $nb_ext_auth_source_added = 0;
  326. if (isset($extAuthSource) && !empty($extAuthSource) && count($extAuthSource) > 0) {
  327. $auth_sources = array();
  328. foreach ($extAuthSource as $key => $info) {
  329. // @todo : make uniform external authentication configuration (ex : cas and external_login ldap)
  330. // Special case for CAS. CAS is activated from Chamilo > Administration > Configuration > CAS
  331. // extAuthSource always on for CAS even if not activated
  332. // same action for file user_add.php
  333. if (($key == CAS_AUTH_SOURCE && api_get_setting('cas_activate') === 'true') || ($key != CAS_AUTH_SOURCE)) {
  334. $auth_sources[$key] = $key;
  335. $nb_ext_auth_source_added++;
  336. }
  337. }
  338. if ($nb_ext_auth_source_added > 0) {
  339. // @todo check the radio button for external authentification and select the external authentication in the menu
  340. $group[] = $form->createElement('radio', 'reset_password', null, get_lang('ExternalAuthentication').' ', 3);
  341. $group[] = $form->createElement('select', 'auth_source', null, $auth_sources);
  342. $group[] = $form->createElement('static', '', '', '<br />');
  343. $form->addGroup($group, 'password', null, '', false);
  344. }
  345. }
  346. $form->addElement('radio', 'reset_password', null, get_lang('AutoGeneratePassword'), 1);
  347. $group = array();
  348. $group[] =$form->createElement('radio', 'reset_password', null, get_lang('EnterPassword'), 2);
  349. $group[] = $form->createElement(
  350. 'password',
  351. 'password',
  352. null,
  353. array('onkeydown' => 'javascript: password_switch_radio_button();')
  354. );
  355. $form->addGroup($group, 'password', null, '', false);
  356. // Status
  357. $status = array();
  358. $status[COURSEMANAGER] = get_lang('Teacher');
  359. $status[STUDENT] = get_lang('Learner');
  360. $status[DRH] = get_lang('Drh');
  361. $status[SESSIONADMIN] = get_lang('SessionsAdmin');
  362. $status[STUDENT_BOSS] = get_lang('RoleStudentBoss');
  363. $status[INVITEE] = get_lang('Invitee');
  364. $form->addElement(
  365. 'select',
  366. 'status',
  367. get_lang('Profile'),
  368. $status,
  369. array(
  370. 'id' => 'status_select',
  371. 'onchange' => 'javascript: display_drh_list();'
  372. )
  373. );
  374. $display = isset($user_data['status']) && ($user_data['status'] == STUDENT || (isset($_POST['status']) && $_POST['status'] == STUDENT)) ? 'block' : 'none';
  375. // Platform admin
  376. if (api_is_platform_admin()) {
  377. $group = array();
  378. $group[] =$form->createElement('radio', 'platform_admin', null, get_lang('Yes'), 1);
  379. $group[] =$form->createElement('radio', 'platform_admin', null, get_lang('No'), 0);
  380. $user_data['status'] == 1 ? $display = 'block':$display = 'none';
  381. $form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.'">');
  382. $form->addGroup($group, 'admin', get_lang('PlatformAdmin'), null, false);
  383. $form->addElement('html', '</div>');
  384. }
  385. //Language
  386. $form->addElement('select_language', 'language', get_lang('Language'));
  387. // Send email
  388. $group = array();
  389. $group[] = $form->createElement('radio', 'send_mail', null, get_lang('Yes'), 1);
  390. $group[] = $form->createElement('radio', 'send_mail', null, get_lang('No'), 0);
  391. $form->addGroup($group, 'mail', get_lang('SendMailToNewUser'), '&nbsp;', false);
  392. // Registration User and Date
  393. $creatorInfo = api_get_user_info($user_data['creator_id']);
  394. $date = sprintf(get_lang('CreatedByXYOnZ'), 'user_information.php?user_id='.$user_data['creator_id'], $creatorInfo['username'], $user_data['registration_date']);
  395. $form->addElement('label', get_lang('RegistrationDate'), $date);
  396. if (!$user_data['platform_admin']) {
  397. // Expiration Date
  398. $form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
  399. $group = array ();
  400. $group[] = $form->createElement('radio', 'radio_expiration_date', null, get_lang('Enabled'), 1);
  401. $group[] = $form->createElement('DateTimePicker', 'expiration_date', null, array('onchange' => 'javascript: enable_expiration_date();'));
  402. $form->addGroup($group, 'max_member_group', null, '', false);
  403. // Active account or inactive account
  404. $form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
  405. $form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
  406. }
  407. $studentBossList = UserManager::getStudentBossList($user_data['user_id']);
  408. $conditions = ['status' => STUDENT_BOSS];
  409. $studentBoss = UserManager::get_user_list($conditions);
  410. $studentBossToSelect = [];
  411. if ($studentBoss) {
  412. foreach ($studentBoss as $bossId => $userData) {
  413. $bossInfo = api_get_user_info($userData['user_id']);
  414. $studentBossToSelect[$bossInfo['user_id']] = $bossInfo['complete_name_with_username'];
  415. }
  416. }
  417. if ($studentBossList) {
  418. $studentBossList = array_column($studentBossList, 'boss_id');
  419. }
  420. $user_data['student_boss'] = array_values($studentBossList);
  421. $form->addElement('advmultiselect', 'student_boss', get_lang('StudentBoss'), $studentBossToSelect);
  422. // EXTRA FIELDS
  423. $extraField = new ExtraField('user');
  424. $returnParams = $extraField->addElements($form, $user_data['user_id']);
  425. $jquery_ready_content = $returnParams['jquery_ready_content'];
  426. // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
  427. $htmlHeadXtra[] ='<script>
  428. $(document).ready(function(){
  429. '.$jquery_ready_content.'
  430. });
  431. </script>';
  432. // Submit button
  433. $form->addButtonSave(get_lang('Save'));
  434. // Set default values
  435. $user_data['reset_password'] = 0;
  436. $expiration_date = $user_data['expiration_date'];
  437. if (empty($expiration_date)) {
  438. $user_data['radio_expiration_date'] = 0;
  439. $user_data['expiration_date'] = api_get_local_time();
  440. } else {
  441. $user_data['radio_expiration_date'] = 1;
  442. $user_data['expiration_date'] = api_get_local_time($expiration_date);
  443. }
  444. $form->setDefaults($user_data);
  445. $error_drh = false;
  446. // Validate form
  447. if ($form->validate()) {
  448. $user = $form->getSubmitValues(1);
  449. $reset_password = intval($user['reset_password']);
  450. if ($reset_password == 2 && empty($user['password'])) {
  451. Display::addFlash(Display::return_message(get_lang('PasswordIsTooShort')));
  452. header('Location: '.api_get_self().'?user_id='.$user_id);
  453. exit();
  454. }
  455. $is_user_subscribed_in_course = CourseManager::is_user_subscribed_in_course($user['user_id']);
  456. if ($user['status'] == DRH && $is_user_subscribed_in_course) {
  457. $error_drh = true;
  458. } else {
  459. $picture_element = $form->getElement('picture');
  460. $picture = $picture_element->getValue();
  461. $picture_uri = $user_data['picture_uri'];
  462. if (isset($user['delete_picture']) && $user['delete_picture']) {
  463. $picture_uri = UserManager::delete_user_picture($user_id);
  464. } elseif (!empty($picture['name'])) {
  465. $picture_uri = UserManager::update_user_picture(
  466. $user_id,
  467. $_FILES['picture']['name'],
  468. $_FILES['picture']['tmp_name'],
  469. $user['cropResult']
  470. );
  471. }
  472. $lastname = $user['lastname'];
  473. $firstname = $user['firstname'];
  474. $password = $user['password'];
  475. $auth_source = isset($user['auth_source']) ? $user['auth_source'] : $userInfo['auth_source'];
  476. $official_code = $user['official_code'];
  477. $email = $user['email'];
  478. $phone = $user['phone'];
  479. $username = isset($user['username']) ? $user['username'] : $userInfo['username'];
  480. $status = intval($user['status']);
  481. $platform_admin = intval($user['platform_admin']);
  482. $send_mail = intval($user['send_mail']);
  483. $reset_password = intval($user['reset_password']);
  484. $hr_dept_id = isset($user['hr_dept_id']) ? intval($user['hr_dept_id']) : null;
  485. $language = $user['language'];
  486. if ($user['radio_expiration_date'] == '1' && !$user_data['platform_admin']) {
  487. $expiration_date = $user['expiration_date'];
  488. } else {
  489. $expiration_date = null;
  490. }
  491. $active = $user_data['platform_admin'] ? 1 : intval($user['active']);
  492. //If the user is set to admin the status will be overwrite by COURSEMANAGER = 1
  493. if ($platform_admin == 1) {
  494. $status = COURSEMANAGER;
  495. }
  496. if (api_get_setting('login_is_email') == 'true') {
  497. $username = $email;
  498. }
  499. UserManager::update_user(
  500. $user_id,
  501. $firstname,
  502. $lastname,
  503. $username,
  504. $password,
  505. $auth_source,
  506. $email,
  507. $status,
  508. $official_code,
  509. $phone,
  510. $picture_uri,
  511. $expiration_date,
  512. $active,
  513. null,
  514. $hr_dept_id,
  515. null,
  516. $language,
  517. null,
  518. $send_mail,
  519. $reset_password,
  520. $user['address']
  521. );
  522. if (isset($user['student_boss'])) {
  523. UserManager::subscribeUserToBossList($user_id, $user['student_boss']);
  524. }
  525. if (api_get_setting('openid_authentication') == 'true' && !empty($user['openid'])) {
  526. $up = UserManager::update_openid($user_id, $user['openid']);
  527. }
  528. $currentUserId = api_get_user_id();
  529. $userObj = api_get_user_entity($user_id);
  530. UserManager::add_user_as_admin($userObj);
  531. if ($user_id != $currentUserId) {
  532. if ($platform_admin == 1) {
  533. $userObj = api_get_user_entity($user_id);
  534. UserManager::add_user_as_admin($userObj);
  535. } else {
  536. UserManager::remove_user_admin($user_id);
  537. }
  538. }
  539. $extraFieldValue = new ExtraFieldValue('user');
  540. $extraFieldValue->saveFieldValues($user);
  541. $tok = Security::get_token();
  542. header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserUpdated')).'&sec_token='.$tok);
  543. exit();
  544. }
  545. }
  546. $message = null;
  547. if ($error_drh) {
  548. $err_msg = get_lang('StatusCanNotBeChangedToHumanResourcesManager');
  549. $message = Display::return_message($err_msg, 'error');
  550. }
  551. $content = null;
  552. $bigImage = UserManager::getUserPicture($user_id, USER_IMAGE_SIZE_BIG);
  553. $normalImage = UserManager::getUserPicture($user_id, USER_IMAGE_SIZE_ORIGINAL);
  554. $content .= '<div class="row">';
  555. $content .= '<div class="col-md-10">';
  556. // Display form
  557. $content .= $form->returnForm();
  558. $content .= '</div>';
  559. $content .= '<div class="col-md-2">';
  560. $content .= '<a class="thumbnail expand-image" href="'.$bigImage.'" /><img src="'.$normalImage.'"></a>';
  561. $content .= '</div>';
  562. $tpl = new Template($tool_name);
  563. $tpl->assign('message', $message);
  564. $tpl->assign('content', $content);
  565. $tpl->display_one_col_template();