user_import.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * This tool allows platform admins to add users by uploading a CSV or XML file.
  6. *
  7. * @package chamilo.admin
  8. */
  9. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. // Set this option to true to enforce strict purification for usenames.
  12. $purification_option_for_usernames = false;
  13. $userId = api_get_user_id();
  14. /**
  15. * @param array $users
  16. * @param bool $checkUniqueEmail
  17. *
  18. * @return array
  19. */
  20. function validate_data($users, $checkUniqueEmail = false)
  21. {
  22. global $defined_auth_sources;
  23. $usernames = [];
  24. // 1. Check if mandatory fields are set.
  25. $mandatory_fields = ['LastName', 'FirstName'];
  26. if (api_get_setting('registration', 'email') == 'true' || $checkUniqueEmail) {
  27. $mandatory_fields[] = 'Email';
  28. }
  29. $classExistList = [];
  30. $usergroup = new UserGroup();
  31. foreach ($users as &$user) {
  32. $user['has_error'] = false;
  33. $user['message'] = '';
  34. foreach ($mandatory_fields as $field) {
  35. if (empty($user[$field])) {
  36. $user['message'] .= Display::return_message(get_lang($field.'Mandatory'), 'warning');
  37. $user['has_error'] = true;
  38. }
  39. }
  40. $username = isset($user['UserName']) ? $user['UserName'] : '';
  41. // 2. Check username, first, check whether it is empty.
  42. if (!UserManager::is_username_empty($username)) {
  43. // 2.1. Check whether username is too long.
  44. if (UserManager::is_username_too_long($username)) {
  45. $user['message'] .= Display::return_message(get_lang('UserNameTooLong'), 'warning');
  46. $user['has_error'] = true;
  47. }
  48. // 2.1.1
  49. $hasDash = strpos($username, '-');
  50. if ($hasDash !== false) {
  51. $user['message'] .= Display::return_message(get_lang('UserNameHasDash'), 'warning');
  52. $user['has_error'] = true;
  53. }
  54. // 2.2. Check whether the username was used twice in import file.
  55. if (isset($usernames[$username])) {
  56. $user['message'] .= Display::return_message(get_lang('UserNameUsedTwice'), 'warning');
  57. $user['has_error'] = true;
  58. }
  59. $usernames[$username] = 1;
  60. // 2.3. Check whether username is already occupied.
  61. if (!UserManager::is_username_available($username)) {
  62. $user['message'] .= Display::return_message(get_lang('UserNameNotAvailable'), 'warning');
  63. $user['has_error'] = true;
  64. }
  65. }
  66. if (isset($user['Email'])) {
  67. $result = api_valid_email($user['Email']);
  68. if ($result === false) {
  69. $user['message'] .= Display::return_message(get_lang('PleaseEnterValidEmail'), 'warning');
  70. $user['has_error'] = true;
  71. }
  72. }
  73. if ($checkUniqueEmail) {
  74. if (isset($user['Email'])) {
  75. $userFromEmail = api_get_user_info_from_email($user['Email']);
  76. if (!empty($userFromEmail)) {
  77. $user['message'] .= Display::return_message(get_lang('EmailUsedTwice'), 'warning');
  78. $user['has_error'] = true;
  79. }
  80. }
  81. }
  82. // 3. Check status.
  83. if (isset($user['Status']) && !api_status_exists($user['Status'])) {
  84. $user['message'] .= Display::return_message(get_lang('WrongStatus'), 'warning');
  85. $user['has_error'] = true;
  86. }
  87. // 4. Check ClassId
  88. if (!empty($user['ClassId'])) {
  89. $classId = explode('|', trim($user['ClassId']));
  90. foreach ($classId as $id) {
  91. if (in_array($id, $classExistList)) {
  92. continue;
  93. }
  94. $info = $usergroup->get($id);
  95. if (empty($info)) {
  96. $user['message'] .= Display::return_message(
  97. sprintf(get_lang('ClassIdDoesntExists'), $id),
  98. 'warning'
  99. );
  100. $user['has_error'] = true;
  101. } else {
  102. $classExistList[] = $info['id'];
  103. }
  104. }
  105. }
  106. // 5. Check authentication source
  107. if (!empty($user['AuthSource'])) {
  108. if (!in_array($user['AuthSource'], $defined_auth_sources)) {
  109. $user['message'] .= Display::return_message(get_lang('AuthSourceNotAvailable'), 'warning');
  110. $user['has_error'] = true;
  111. }
  112. }
  113. }
  114. return $users;
  115. }
  116. /**
  117. * Add missing user-information (which isn't required, like password, username etc).
  118. *
  119. * @param array $user
  120. */
  121. function complete_missing_data($user)
  122. {
  123. global $purification_option_for_usernames;
  124. $username = isset($user['UserName']) ? $user['UserName'] : '';
  125. // 1. Create a username if necessary.
  126. if (UserManager::is_username_empty($username)) {
  127. $user['UserName'] = UserManager::create_unique_username(
  128. $user['FirstName'],
  129. $user['LastName']
  130. );
  131. } else {
  132. $user['UserName'] = UserManager::purify_username(
  133. $user['UserName'],
  134. $purification_option_for_usernames
  135. );
  136. }
  137. // 2. Generate a password if necessary.
  138. if (empty($user['Password'])) {
  139. $user['Password'] = api_generate_password();
  140. }
  141. // 3. Set status if not allready set.
  142. if (empty($user['Status'])) {
  143. $user['Status'] = 'user';
  144. }
  145. // 4. Set authsource if not allready set.
  146. if (empty($user['AuthSource'])) {
  147. $user['AuthSource'] = PLATFORM_AUTH_SOURCE;
  148. }
  149. if (empty($user['ExpiryDate'])) {
  150. $user['ExpiryDate'] = '';
  151. }
  152. if (!isset($user['OfficialCode'])) {
  153. $user['OfficialCode'] = '';
  154. }
  155. if (!isset($user['language'])) {
  156. $user['language'] = '';
  157. }
  158. if (!isset($user['PhoneNumber'])) {
  159. $user['PhoneNumber'] = '';
  160. }
  161. if (!isset($user['OfficialCode'])) {
  162. $user['OfficialCode'] = '';
  163. }
  164. return $user;
  165. }
  166. /**
  167. * Save the imported data.
  168. *
  169. * @param array $users List of users
  170. * @param bool $sendMail
  171. *
  172. * @uses \global variable $inserted_in_course, which returns the list of
  173. * courses the user was inserted in
  174. */
  175. function save_data($users, $sendMail = false)
  176. {
  177. global $inserted_in_course;
  178. // Not all scripts declare the $inserted_in_course array (although they should).
  179. if (!isset($inserted_in_course)) {
  180. $inserted_in_course = [];
  181. }
  182. $usergroup = new UserGroup();
  183. if (is_array($users)) {
  184. foreach ($users as &$user) {
  185. if ($user['has_error']) {
  186. continue;
  187. }
  188. $user = complete_missing_data($user);
  189. $user['Status'] = api_status_key($user['Status']);
  190. $user_id = UserManager::create_user(
  191. $user['FirstName'],
  192. $user['LastName'],
  193. $user['Status'],
  194. $user['Email'],
  195. $user['UserName'],
  196. $user['Password'],
  197. $user['OfficialCode'],
  198. $user['language'],
  199. $user['PhoneNumber'],
  200. '',
  201. $user['AuthSource'],
  202. $user['ExpiryDate'],
  203. 1,
  204. 0,
  205. null,
  206. null,
  207. $sendMail
  208. );
  209. if ($user_id) {
  210. $returnMessage = Display::return_message(get_lang('UserAdded'), 'success');
  211. if (isset($user['Courses']) && is_array($user['Courses'])) {
  212. foreach ($user['Courses'] as $course) {
  213. if (CourseManager::course_exists($course)) {
  214. $result = CourseManager::subscribeUser($user_id, $course, $user['Status']);
  215. if ($result) {
  216. $course_info = api_get_course_info($course);
  217. $inserted_in_course[$course] = $course_info['title'];
  218. }
  219. }
  220. }
  221. }
  222. if (isset($user['Sessions']) && is_array($user['Sessions'])) {
  223. foreach ($user['Sessions'] as $sessionId) {
  224. $sessionInfo = api_get_session_info($sessionId);
  225. if (!empty($sessionInfo)) {
  226. SessionManager::subscribeUsersToSession(
  227. $sessionId,
  228. [$user_id],
  229. SESSION_VISIBLE_READ_ONLY,
  230. false
  231. );
  232. }
  233. }
  234. }
  235. if (!empty($user['ClassId'])) {
  236. $classId = explode('|', trim($user['ClassId']));
  237. foreach ($classId as $id) {
  238. $usergroup->subscribe_users_to_usergroup($id, [$user_id], false);
  239. }
  240. }
  241. // Saving extra fields.
  242. global $extra_fields;
  243. // We are sure that the extra field exists.
  244. foreach ($extra_fields as $extras) {
  245. if (isset($user[$extras[1]])) {
  246. $key = $extras[1];
  247. $value = $user[$extras[1]];
  248. UserManager::update_extra_field_value($user_id, $key, $value);
  249. }
  250. }
  251. } else {
  252. $returnMessage = Display::return_message(get_lang('Error'), 'warning');
  253. }
  254. $user['message'] = $returnMessage;
  255. }
  256. }
  257. return $users;
  258. }
  259. /**
  260. * @param array $users
  261. * @param string $fileName
  262. * @param int $sendEmail
  263. * @param bool $checkUniqueEmail
  264. * @param bool $resumeImport
  265. *
  266. * @return array
  267. */
  268. function parse_csv_data($users, $fileName, $sendEmail = 0, $checkUniqueEmail = true, $resumeImport = false)
  269. {
  270. $usersFromOrigin = $users;
  271. $allowRandom = api_get_configuration_value('generate_random_login');
  272. if ($allowRandom) {
  273. $factory = new RandomLib\Factory();
  274. $generator = $factory->getLowStrengthGenerator();
  275. $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  276. }
  277. $readMax = 50;
  278. $userId = api_get_user_id();
  279. $logMessages = '';
  280. $importData = Session::read('user_import_data_'.$userId);
  281. if (!empty($importData)) {
  282. $counter = $importData['counter'];
  283. $users = $importData['complete_list'];
  284. $users = array_splice($users, $counter, $readMax);
  285. $logMessages = $importData['log_messages'];
  286. } else {
  287. $users = array_splice($users, 0, $readMax);
  288. }
  289. if ($resumeImport === false) {
  290. $users = $usersFromOrigin;
  291. }
  292. $counter = 0;
  293. foreach ($users as $index => $user) {
  294. if ($resumeImport) {
  295. if ($counter >= $readMax) {
  296. $users = array_splice($users, $counter, $readMax);
  297. break;
  298. }
  299. }
  300. $counter++;
  301. if (empty($user['UserName'])) {
  302. if ($allowRandom) {
  303. $username = $generator->generateString(10, $chars);
  304. $user['UserName'] = $username;
  305. }
  306. }
  307. if (isset($user['Courses'])) {
  308. $user['Courses'] = explode('|', trim($user['Courses']));
  309. }
  310. if (isset($user['Sessions'])) {
  311. $user['Sessions'] = explode('|', trim($user['Sessions']));
  312. }
  313. // Lastname is needed.
  314. if (!isset($user['LastName']) || (isset($user['LastName']) && empty($user['LastName']))) {
  315. unset($users[$index]);
  316. continue;
  317. }
  318. // FirstName is needed.
  319. if (!isset($user['FirstName']) || (isset($user['FirstName']) && empty($user['FirstName']))) {
  320. unset($users[$index]);
  321. continue;
  322. }
  323. $users[$index] = $user;
  324. }
  325. $globalCounter = $counter;
  326. if (!empty($importData)) {
  327. $globalCounter = $importData['counter'] + $counter;
  328. }
  329. $importData = [
  330. 'complete_list' => $usersFromOrigin,
  331. 'filename' => $fileName,
  332. 'counter' => $globalCounter,
  333. 'check_unique_email' => $checkUniqueEmail,
  334. 'send_email' => $sendEmail,
  335. 'date' => api_get_utc_datetime(),
  336. 'log_messages' => $logMessages,
  337. 'resume' => $resumeImport,
  338. ];
  339. Session::write('user_import_data_'.$userId, $importData);
  340. return $users;
  341. }
  342. /**
  343. * Read the XML-file.
  344. *
  345. * @param string $file Path to the XML-file
  346. *
  347. * @return array All user information read from the file
  348. */
  349. function parse_xml_data($file)
  350. {
  351. $crawler = new \Symfony\Component\DomCrawler\Crawler();
  352. $crawler->addXmlContent(file_get_contents($file));
  353. $crawler = $crawler->filter('Contacts > Contact ');
  354. $array = [];
  355. foreach ($crawler as $domElement) {
  356. $row = [];
  357. foreach ($domElement->childNodes as $node) {
  358. if ($node->nodeName != '#text') {
  359. $row[$node->nodeName] = $node->nodeValue;
  360. }
  361. }
  362. if (!empty($row)) {
  363. $array[] = $row;
  364. }
  365. }
  366. return $array;
  367. }
  368. /**
  369. * @param array $users
  370. * @param bool $sendMail
  371. */
  372. function processUsers(&$users, $sendMail)
  373. {
  374. $users = save_data($users, $sendMail);
  375. $warningMessage = '';
  376. if (!empty($users)) {
  377. $table = new HTML_Table(['class' => 'table table-responsive']);
  378. $headers = [
  379. get_lang('User'),
  380. get_lang('Status'),
  381. ];
  382. $row = 0;
  383. $column = 0;
  384. foreach ($headers as $header) {
  385. $table->setHeaderContents($row, $column, $header);
  386. $column++;
  387. }
  388. $row++;
  389. foreach ($users as $user) {
  390. $column = 0;
  391. $email = isset($user['Email']) ? ' - '.$user['Email'] : null;
  392. $userData =
  393. '<strong>'.$user['UserName'].'</strong> - '.
  394. api_get_person_name(
  395. $user['FirstName'],
  396. $user['LastName']
  397. ).' '.$email;
  398. $table->setCellContents($row, $column, $userData);
  399. $table->setCellContents($row, ++$column, $user['message']);
  400. $row++;
  401. }
  402. $warningMessage = $table->toHtml();
  403. }
  404. // if the warning message is too long then we display the warning message trough a session
  405. Display::addFlash(Display::return_message(get_lang('FileImported'), 'confirmation', false));
  406. $importData = Session::read('user_import_data_'.api_get_user_id());
  407. if (!empty($importData)) {
  408. if (isset($importData['log_messages'])) {
  409. $importData['log_messages'] .= $warningMessage;
  410. } else {
  411. $importData['log_messages'] = $warningMessage;
  412. }
  413. Session::write('user_import_data_'.api_get_user_id(), $importData);
  414. }
  415. }
  416. $this_section = SECTION_PLATFORM_ADMIN;
  417. api_protect_admin_script(true, null);
  418. api_protect_limit_for_session_admin();
  419. set_time_limit(0);
  420. $defined_auth_sources[] = PLATFORM_AUTH_SOURCE;
  421. if (isset($extAuthSource) && is_array($extAuthSource)) {
  422. $defined_auth_sources = array_merge($defined_auth_sources, array_keys($extAuthSource));
  423. }
  424. $tool_name = get_lang('ImportUserListXMLCSV');
  425. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  426. $reloadImport = (isset($_REQUEST['reload_import']) && (int) $_REQUEST['reload_import'] === 1);
  427. $extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', true);
  428. if (isset($_POST['formSent']) && $_POST['formSent'] && $_FILES['import_file']['size'] !== 0) {
  429. $file_type = $_POST['file_type'];
  430. Security::clear_token();
  431. $tok = Security::get_token();
  432. $allowed_file_mimetype = ['csv', 'xml'];
  433. $error_kind_file = true;
  434. $checkUniqueEmail = isset($_POST['check_unique_email']) ? $_POST['check_unique_email'] : null;
  435. $sendMail = $_POST['sendMail'] ? true : false;
  436. $resume = isset($_POST['resume_import']) ? true : false;
  437. $uploadInfo = pathinfo($_FILES['import_file']['name']);
  438. $ext_import_file = $uploadInfo['extension'];
  439. $users = [];
  440. if (in_array($ext_import_file, $allowed_file_mimetype)) {
  441. if (strcmp($file_type, 'csv') === 0 &&
  442. $ext_import_file == $allowed_file_mimetype[0]
  443. ) {
  444. Session::erase('user_import_data_'.$userId);
  445. $users = Import::csvToArray($_FILES['import_file']['tmp_name']);
  446. $users = parse_csv_data(
  447. $users,
  448. $_FILES['import_file']['name'],
  449. $sendMail,
  450. $checkUniqueEmail,
  451. $resume
  452. );
  453. $users = validate_data($users, $checkUniqueEmail);
  454. $error_kind_file = false;
  455. } elseif (strcmp($file_type, 'xml') === 0 && $ext_import_file == $allowed_file_mimetype[1]) {
  456. $users = parse_xml_data($_FILES['import_file']['tmp_name']);
  457. $users = validate_data($users, $checkUniqueEmail);
  458. $error_kind_file = false;
  459. }
  460. processUsers($users, $sendMail);
  461. if ($error_kind_file) {
  462. Display::addFlash(
  463. Display::return_message(
  464. get_lang('YouMustImportAFileAccordingToSelectedOption'),
  465. 'error',
  466. false
  467. )
  468. );
  469. } else {
  470. $reload = '';
  471. if ($resume) {
  472. $reload = '?reload_import=1';
  473. }
  474. header('Location: '.api_get_self().$reload);
  475. exit;
  476. }
  477. } else {
  478. Display::addFlash(
  479. Display::return_message(
  480. get_lang('YouMustImportAFileAccordingToSelectedOption'),
  481. 'error',
  482. false
  483. )
  484. );
  485. //header('Location: '.api_get_path(WEB_CODE_PATH).'admin/user_list.php?sec_token='.$tok);
  486. header('Location: '.api_get_self());
  487. exit;
  488. }
  489. }
  490. $importData = Session::read('user_import_data_'.$userId);
  491. $formContinue = false;
  492. $resumeStop = true;
  493. if (!empty($importData)) {
  494. $isResume = $importData['resume'];
  495. $formContinue = new FormValidator('user_import_continue', 'post', api_get_self());
  496. $label = get_lang('Results');
  497. if ($isResume) {
  498. $label = get_lang('ContinueLastImport');
  499. }
  500. $formContinue->addHeader($label);
  501. $formContinue->addLabel(get_lang('File'), $importData['filename']);
  502. $resumeStop = true;
  503. if ($isResume) {
  504. $totalUsers = isset($importData['complete_list']) ? count($importData['complete_list']) : 0;
  505. $counter = isset($importData['counter']) ? $importData['counter'] : 0;
  506. $bar = '';
  507. if (!empty($totalUsers)) {
  508. $bar = Display::bar_progress($counter / $totalUsers * 100);
  509. }
  510. $formContinue->addLabel(get_lang('Status'), $bar);
  511. $formContinue->addLabel(
  512. get_lang('UsersAdded'),
  513. $importData['counter'].' / '.count($importData['complete_list'])
  514. );
  515. } else {
  516. $formContinue->addLabel(
  517. get_lang('Users'),
  518. count($importData['complete_list'])
  519. );
  520. }
  521. $formContinue->addLabel(
  522. get_lang('CheckUniqueEmail'),
  523. $importData['check_unique_email'] ? get_lang('Yes') : get_lang('No')
  524. );
  525. $formContinue->addLabel(get_lang('SendMailToUsers'), $importData['send_email'] ? get_lang('Yes') : get_lang('No'));
  526. $formContinue->addLabel(get_lang('Date'), Display::dateToStringAgoAndLongDate($importData['date']));
  527. if ($isResume) {
  528. $resumeStop = $importData['counter'] >= count($importData['complete_list']);
  529. if ($resumeStop == false) {
  530. $formContinue->addButtonImport(get_lang('ContinueImport'), 'import_continue');
  531. }
  532. }
  533. $formContinue->addHtml(get_lang('Results').'<br />'.$importData['log_messages']);
  534. if ($formContinue->validate()) {
  535. $users = parse_csv_data(
  536. $importData['complete_list'],
  537. $importData['filename'],
  538. $importData['send_email'],
  539. $importData['check_unique_email'],
  540. true
  541. );
  542. $users = validate_data($users, $importData['check_unique_email']);
  543. processUsers($users, $importData['send_email']);
  544. $reload = '';
  545. if ($isResume && $resumeStop === false) {
  546. $reload = '?reload_import=1';
  547. }
  548. header('Location: '.api_get_self().$reload);
  549. exit;
  550. }
  551. }
  552. Display::display_header($tool_name);
  553. $form = new FormValidator('user_import', 'post', api_get_self());
  554. $form->addHeader($tool_name);
  555. $form->addElement('hidden', 'formSent');
  556. $form->addElement('file', 'import_file', get_lang('ImportFileLocation'));
  557. $group = [
  558. $form->createElement(
  559. 'radio',
  560. 'file_type',
  561. '',
  562. 'CSV (<a href="example.csv" target="_blank" download>'.get_lang('ExampleCSVFile').'</a>)',
  563. 'csv'
  564. ),
  565. $form->createElement(
  566. 'radio',
  567. 'file_type',
  568. null,
  569. 'XML (<a href="example.xml" target="_blank" download>'.get_lang('ExampleXMLFile').'</a>)',
  570. 'xml'
  571. ),
  572. ];
  573. $form->addGroup($group, '', get_lang('FileType'));
  574. $group = [
  575. $form->createElement('radio', 'sendMail', '', get_lang('Yes'), 1),
  576. $form->createElement('radio', 'sendMail', null, get_lang('No'), 0),
  577. ];
  578. $form->addGroup($group, '', get_lang('SendMailToUsers'));
  579. $form->addElement(
  580. 'checkbox',
  581. 'check_unique_email',
  582. '',
  583. get_lang('CheckUniqueEmail')
  584. );
  585. $form->addElement(
  586. 'checkbox',
  587. 'resume_import',
  588. '',
  589. get_lang('ResumeImport')
  590. );
  591. $form->addButtonImport(get_lang('Import'));
  592. $defaults['formSent'] = 1;
  593. $defaults['sendMail'] = 0;
  594. $defaults['file_type'] = 'csv';
  595. $extraSettings = api_get_configuration_value('user_import_settings');
  596. if (!empty($extraSettings) && isset($extraSettings['options']) &&
  597. isset($extraSettings['options']['send_mail_default_option'])
  598. ) {
  599. $defaults['sendMail'] = $extraSettings['options']['send_mail_default_option'];
  600. }
  601. $form->setDefaults($defaults);
  602. $form->display();
  603. if ($formContinue) {
  604. $formContinue->display();
  605. }
  606. if ($reloadImport) {
  607. echo '<script>
  608. $(function() {
  609. function reload() {
  610. $("#user_import_continue").submit();
  611. }
  612. setTimeout(reload, 3000);
  613. });
  614. </script>';
  615. }
  616. $list = [];
  617. $list_reponse = [];
  618. $result_xml = '';
  619. $i = 0;
  620. $count_fields = count($extra_fields);
  621. if ($count_fields > 0) {
  622. foreach ($extra_fields as $extra) {
  623. $list[] = $extra[1];
  624. $list_reponse[] = 'xxx';
  625. $spaces = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  626. $result_xml .= $spaces.'&lt;'.$extra[1].'&gt;xxx&lt;/'.$extra[1].'&gt;';
  627. if ($i != $count_fields - 1) {
  628. $result_xml .= '<br/>';
  629. }
  630. $i++;
  631. }
  632. }
  633. ?>
  634. <p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
  635. <blockquote>
  636. <pre>
  637. <b>LastName</b>;<b>FirstName</b>;<b>Email</b>;UserName;Password;AuthSource;OfficialCode;PhoneNumber;Status;ExpiryDate;<span style="color:red;"><?php if (count($list) > 0) {
  638. echo implode(';', $list).';';
  639. } ?></span>Courses;Sessions;ClassId;
  640. <b>xxx</b>;<b>xxx</b>;<b>xxx</b>;xxx;xxx;<?php echo implode('/', $defined_auth_sources); ?>;xxx;xxx;user/teacher/drh;0000-00-00 00:00:00;<span style="color:red;"><?php if (count($list_reponse) > 0) {
  641. echo implode(';', $list_reponse).';';
  642. } ?></span>xxx1|xxx2|xxx3;sessionId|sessionId|sessionId;1;<br />
  643. </pre>
  644. </blockquote>
  645. <p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
  646. <blockquote>
  647. <pre>
  648. &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  649. &lt;Contacts&gt;
  650. &lt;Contact&gt;
  651. <b>&lt;LastName&gt;xxx&lt;/LastName&gt;</b>
  652. <b>&lt;FirstName&gt;xxx&lt;/FirstName&gt;</b>
  653. &lt;UserName&gt;xxx&lt;/UserName&gt;
  654. &lt;Password&gt;xxx&lt;/Password&gt;
  655. &lt;AuthSource&gt;<?php echo implode('/', $defined_auth_sources); ?>&lt;/AuthSource&gt;
  656. <b>&lt;Email&gt;xxx&lt;/Email&gt;</b>
  657. &lt;OfficialCode&gt;xxx&lt;/OfficialCode&gt;
  658. &lt;PhoneNumber&gt;xxx&lt;/PhoneNumber&gt;
  659. &lt;Status&gt;user/teacher/drh<?php if ($result_xml != '') {
  660. echo '<br /><span style="color:red;">', $result_xml;
  661. echo '</span>';
  662. } ?>&lt;/Status&gt;
  663. &lt;Courses&gt;xxx1|xxx2|xxx3&lt;/Courses&gt;
  664. &lt;Sessions&gt;sessionId|sessionId|sessionId&lt;/Sessions&gt;
  665. &lt;ClassId&gt;1&lt;/ClassId&gt;
  666. &lt;/Contact&gt;
  667. &lt;/Contacts&gt;
  668. </pre>
  669. </blockquote>
  670. <?php
  671. Display :: display_footer();