user_import.php 25 KB

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