session_import.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $language_file = array('admin', 'registration');
  7. $cidReset = true;
  8. require_once '../inc/global.inc.php';
  9. $this_section = SECTION_PLATFORM_ADMIN;
  10. api_protect_admin_script(true);
  11. require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
  12. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  13. $form_sent = 0;
  14. $error_message = ''; // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php.
  15. if (isset($_GET['action']) && $_GET['action'] == 'show_message') {
  16. $error_message = Security::remove_XSS($_GET['message']);
  17. }
  18. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  19. $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
  20. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  21. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  22. $tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  23. $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  24. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  25. $tool_name = get_lang('ImportSessionListXMLCSV');
  26. $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  27. $interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
  28. set_time_limit(0);
  29. // Set this option to true to enforce strict purification for usenames.
  30. $purification_option_for_usernames = false;
  31. $inserted_in_course = array();
  32. global $_configuration;
  33. $warn = null;
  34. if (isset($_POST['formSent']) && $_POST['formSent']) {
  35. if (isset($_FILES['import_file']['tmp_name']) &&
  36. !empty($_FILES['import_file']['tmp_name'])
  37. ) {
  38. $form_sent = $_POST['formSent'];
  39. $file_type = isset($_POST['file_type']) ? $_POST['file_type'] : null;
  40. $send_mail = isset($_POST['sendMail']) && $_POST['sendMail'] ? 1 : 0;
  41. $isOverwrite = isset($_POST['overwrite']) && $_POST['overwrite'] ? true: false;
  42. $deleteUsersNotInList = isset($_POST['delete_users_not_in_list']) ? true : false;
  43. $sessions = array();
  44. $session_counter = 0;
  45. if ($file_type == 'xml') {
  46. // XML
  47. // SimpleXML for PHP5 deals with various encodings, but how many they are, what are version issues, do we need to waste time with configuration options?
  48. // For avoiding complications we go some sort of "PHP4 way" - we convert the input xml-file into UTF-8 before passing it to the parser.
  49. // Instead of:
  50. // $root = @simplexml_load_file($_FILES['import_file']['tmp_name']);
  51. // we may use the following construct:
  52. // $root = @simplexml_load_string(api_utf8_encode_xml(file_get_contents($_FILES['import_file']['tmp_name'])));
  53. // To ease debugging let us use:
  54. $content = file_get_contents($_FILES['import_file']['tmp_name']);
  55. $content = api_utf8_encode_xml($content);
  56. $root = @simplexml_load_string($content);
  57. unset($content);
  58. if (is_object($root)) {
  59. if (count($root->Users->User) > 0) {
  60. // Creating/updating users from <Sessions> <Users> base node.
  61. foreach ($root->Users->User as $node_user) {
  62. $username = $username_old = trim(api_utf8_decode($node_user->Username));
  63. if (UserManager::is_username_available($username)) {
  64. $password = api_utf8_decode($node_user->Password);
  65. if (empty($password)) {
  66. $password = api_generate_password();
  67. }
  68. switch ($node_user->Status) {
  69. case 'student' :
  70. $status = 5;
  71. break;
  72. case 'teacher' :
  73. $status = 1;
  74. break;
  75. default :
  76. $status = 5;
  77. $error_message .= get_lang('StudentStatusWasGivenTo').' : '.$username.'<br />';
  78. }
  79. $result = UserManager::create_user(
  80. api_utf8_decode($node_user->Firstname),
  81. api_utf8_decode($node_user->Lastname),
  82. $status,
  83. api_utf8_decode($node_user->Email),
  84. $username,
  85. $password,
  86. api_utf8_decode($node_user->OfficialCode),
  87. null,
  88. api_utf8_decode($node_user->Phone),
  89. null,
  90. PLATFORM_AUTH_SOURCE,
  91. null,
  92. 1,
  93. 0,
  94. null,
  95. null,
  96. $send_mail
  97. );
  98. } else {
  99. $lastname = trim(api_utf8_decode($node_user->Lastname));
  100. $firstname = trim(api_utf8_decode($node_user->Firstname));
  101. $password = api_utf8_decode($node_user->Password);
  102. $email = trim(api_utf8_decode($node_user->Email));
  103. $official_code = trim(api_utf8_decode($node_user->OfficialCode));
  104. $phone = trim(api_utf8_decode($node_user->Phone));
  105. $status = trim(api_utf8_decode($node_user->Status));
  106. switch ($status) {
  107. case 'student' : $status = 5; break;
  108. case 'teacher' : $status = 1; break;
  109. default : $status = 5; $error_message .= get_lang('StudentStatusWasGivenTo').' : '.$username.'<br />';
  110. }
  111. $sql = "UPDATE $tbl_user SET
  112. lastname = '".Database::escape_string($lastname)."',
  113. firstname = '".Database::escape_string($firstname)."',
  114. ".(empty($password) ? "" : "password = '".(api_get_encrypted_password($password))."',")."
  115. email = '".Database::escape_string($email)."',
  116. official_code = '".Database::escape_string($official_code)."',
  117. phone = '".Database::escape_string($phone)."',
  118. status = '".intval($status)."'
  119. WHERE username = '".Database::escape_string($username)."'";
  120. Database::query($sql);
  121. }
  122. }
  123. }
  124. // Creating courses from <Sessions> <Courses> base node.
  125. if (count($root->Courses->Course) > 0) {
  126. foreach ($root->Courses->Course as $courseNode) {
  127. $params = array();
  128. if (empty($courseNode->CourseTitle)) {
  129. $params['title'] = api_utf8_decode($courseNode->CourseCode);
  130. } else {
  131. $params['title'] = api_utf8_decode($courseNode->CourseTitle);
  132. }
  133. $params['wanted_code'] = api_utf8_decode($courseNode->CourseCode);
  134. $params['tutor_name'] = null;
  135. $params['course_category'] = null;
  136. $params['course_language'] = api_get_valid_language(api_utf8_decode($courseNode->CourseLanguage));
  137. $params['user_id'] = api_get_user_id();
  138. // Looking up for the teacher.
  139. $username = trim(api_utf8_decode($courseNode->CourseTeacher));
  140. $sql = "SELECT user_id, lastname, firstname FROM $tbl_user WHERE username='$username'";
  141. $rs = Database::query($sql);
  142. list($user_id, $lastname, $firstname) = Database::fetch_array($rs);
  143. $params['teachers'] = $user_id;
  144. CourseManager::create_course($params);
  145. }
  146. }
  147. // Creating sessions from <Sessions> base node.
  148. if (count($root->Session) > 0) {
  149. foreach ($root->Session as $node_session) {
  150. $course_counter = 0;
  151. $user_counter = 0;
  152. $session_name = trim(api_utf8_decode($node_session->SessionName));
  153. $coach = UserManager::purify_username(
  154. api_utf8_decode($node_session->Coach),
  155. $purification_option_for_usernames
  156. );
  157. if (!empty($coach)) {
  158. $coach_id = UserManager::get_user_id_from_username($coach);
  159. if ($coach_id === false) {
  160. $error_message .= get_lang('UserDoesNotExist').' : '.$coach.'<br />';
  161. // Forcing the coach id if user does not exist.
  162. $coach_id = api_get_user_id();
  163. }
  164. } else {
  165. // Forcing the coach id.
  166. $coach_id = api_get_user_id();
  167. }
  168. // Just in case - encoding conversion.
  169. $date_start = trim(api_utf8_decode($node_session->DateStart));
  170. if (!empty($date_start)) {
  171. list($year_start, $month_start, $day_start) = explode('/', $date_start);
  172. if (empty($year_start) || empty($month_start) || empty($day_start)) {
  173. $error_message .= get_lang('WrongDate').' : '.$date_start.'<br />';
  174. break;
  175. } else {
  176. $time_start = mktime(0, 0, 0, $month_start, $day_start, $year_start);
  177. }
  178. $date_end = trim(api_utf8_decode($node_session->DateEnd));
  179. if (!empty($date_start)) {
  180. list($year_end, $month_end, $day_end) = explode('/', $date_end);
  181. if (empty($year_end) || empty($month_end) || empty($day_end)) {
  182. $error_message .= get_lang('Error').' : '.$date_end.'<br />';
  183. break;
  184. } else {
  185. $time_end = mktime(0, 0, 0, $month_end, $day_end, $year_end);
  186. }
  187. }
  188. if ($time_end - $time_start < 0) {
  189. $error_message .= get_lang('StartDateShouldBeBeforeEndDate').' : '.$date_end.'<br />';
  190. }
  191. }
  192. $visibility = trim(api_utf8_decode($node_session->Visibility));
  193. $session_category_id = trim(api_utf8_decode($node_session->SessionCategory));
  194. if (!$updatesession) {
  195. // Always create a session.
  196. $unique_name = false; // This MUST be initializead.
  197. $i = 0;
  198. // Change session name, verify that session doesn't exist.
  199. while (!$unique_name) {
  200. if ($i > 1) {
  201. $suffix = ' - '.$i;
  202. }
  203. $sql = 'SELECT 1 FROM '.$tbl_session.'
  204. WHERE name="'.Database::escape_string($session_name.$suffix).'"';
  205. $rs = Database::query($sql);
  206. if (Database::result($rs, 0, 0)) {
  207. $i++;
  208. } else {
  209. $unique_name = true;
  210. $session_name .= $suffix;
  211. }
  212. }
  213. // Creating the session.
  214. $sql_session = "INSERT IGNORE INTO $tbl_session SET
  215. name = '".Database::escape_string($session_name)."',
  216. id_coach = '$coach_id',
  217. date_start = '$date_start',
  218. date_end = '$date_end',
  219. visibility = '$visibility',
  220. session_category_id = '$session_category_id',
  221. session_admin_id=".intval($_user['user_id']);
  222. $rs_session = Database::query($sql_session);
  223. $session_id = Database::insert_id();
  224. $session_counter++;
  225. } else {
  226. // Update the session if it is needed.
  227. $my_session_result = SessionManager::get_session_by_name($session_name);
  228. if ($my_session_result === false) {
  229. // Creating the session.
  230. $sql_session = "INSERT IGNORE INTO $tbl_session SET
  231. name = '".Database::escape_string($session_name)."',
  232. id_coach = '$coach_id',
  233. date_start = '$date_start',
  234. date_end = '$date_end',
  235. visibility = '$visibility',
  236. session_category_id = '$session_category_id',
  237. session_admin_id=".intval($_user['user_id']);
  238. $rs_session = Database::query($sql_session);
  239. $session_id = Database::insert_id();
  240. $session_counter++;
  241. } else {
  242. // if the session already exists - update it.
  243. $sql_session = "UPDATE $tbl_session SET
  244. id_coach = '$coach_id',
  245. date_start = '$date_start',
  246. date_end = '$date_end',
  247. visibility = '$visibility',
  248. session_category_id = '$session_category_id'
  249. WHERE name = '$session_name'";
  250. $rs_session = Database::query($sql_session);
  251. $session_id = Database::query("SELECT id FROM $tbl_session WHERE name='$session_name'");
  252. list($session_id) = Database::fetch_array($session_id);
  253. Database::query("DELETE FROM $tbl_session_user WHERE id_session='$session_id'");
  254. Database::query("DELETE FROM $tbl_session_course WHERE id_session='$session_id'");
  255. Database::query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id'");
  256. }
  257. }
  258. // Associate the session with access_url.
  259. global $_configuration;
  260. if ($_configuration['multiple_access_urls']) {
  261. $access_url_id = api_get_current_access_url_id();
  262. UrlManager::add_session_to_url($session_id, $access_url_id);
  263. } else {
  264. // We fill by default the access_url_rel_session table.
  265. UrlManager::add_session_to_url($session_id, 1);
  266. }
  267. // Adding users to the new session.
  268. foreach ($node_session->User as $node_user) {
  269. $username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames);
  270. $user_id = UserManager::get_user_id_from_username($username);
  271. if ($user_id !== false) {
  272. $sql = "INSERT IGNORE INTO $tbl_session_user SET
  273. id_user='$user_id',
  274. id_session = '$session_id'";
  275. $rs_user = Database::query($sql);
  276. $user_counter++;
  277. }
  278. }
  279. // Adding courses to a session.
  280. foreach ($node_session->Course as $node_course) {
  281. $course_code = Database::escape_string(trim(api_utf8_decode($node_course->CourseCode)));
  282. // Verify that the course pointed by the course code node exists.
  283. if (CourseManager::course_exists($course_code)) {
  284. // If the course exists we continue.
  285. $course_info = CourseManager::get_course_information($course_code);
  286. $session_course_relation = SessionManager::relation_session_course_exist($session_id, $course_code);
  287. if (!$session_course_relation) {
  288. $sql_course = "INSERT INTO $tbl_session_course SET
  289. course_code = '$course_code',
  290. id_session='$session_id'";
  291. $rs_course = Database::query($sql_course);
  292. $course_info = api_get_course_info($course['code']);
  293. SessionManager::installCourse($id_session, $course_info['real_id']);
  294. }
  295. $course_coaches = explode(',', $node_course->Coach);
  296. // Adding coachs to session course user
  297. foreach ($course_coaches as $course_coach) {
  298. $coach_id = UserManager::purify_username(api_utf8_decode($course_coach), $purification_option_for_usernames);
  299. $coach_id = UserManager::get_user_id_from_username($course_coach);
  300. if ($coach_id !== false) {
  301. $sql = "INSERT IGNORE INTO $tbl_session_course_user SET
  302. id_user='$coach_id',
  303. course_code='$course_code',
  304. id_session = '$session_id',
  305. status = 2 ";
  306. $rs_coachs = Database::query($sql);
  307. } else {
  308. $error_message .= get_lang('UserDoesNotExist').' : '.$user.'<br />';
  309. }
  310. }
  311. // Adding users.
  312. $course_counter++;
  313. $users_in_course_counter = 0;
  314. foreach ($node_course->User as $node_user) {
  315. $username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames);
  316. $user_id = UserManager::get_user_id_from_username($username);
  317. if ($user_id !== false) {
  318. // Adding to session_rel_user table.
  319. $sql = "INSERT IGNORE INTO $tbl_session_user SET
  320. id_user='$user_id',
  321. id_session = '$session_id'";
  322. $rs_user = Database::query($sql);
  323. $user_counter++;
  324. // Adding to session_rel_user_rel_course table.
  325. $sql = "INSERT IGNORE INTO $tbl_session_course_user SET
  326. id_user='$user_id',
  327. course_code='$course_code',
  328. id_session = '$session_id'";
  329. $rs_users = Database::query($sql);
  330. $users_in_course_counter++;
  331. } else {
  332. $error_message .= get_lang('UserDoesNotExist').' : '.$username.'<br />';
  333. }
  334. }
  335. $update_session_course = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE course_code='$course_code'";
  336. Database::query($update_session_course);
  337. $inserted_in_course[$course_code] = $course_info['title'];
  338. }
  339. if (CourseManager::course_exists($course_code, true)) {
  340. // If the course exists we continue.
  341. // Also subscribe to virtual courses through check on visual code.
  342. $list = CourseManager :: get_courses_info_from_visual_code($course_code);
  343. foreach ($list as $vcourse) {
  344. if ($vcourse['code'] == $course_code) {
  345. // Ignore, this has already been inserted.
  346. } else {
  347. $sql_course = "INSERT INTO $tbl_session_course SET
  348. course_code = '".$vcourse['code']."',
  349. id_session='$session_id'";
  350. $rs_course = Database::query($sql_course);
  351. $course_info = api_get_course_info($course['code']);
  352. SessionManager::installCourse($id_session, $course_info['real_id']);
  353. $course_coaches = explode(",",$node_course->Coach);
  354. // adding coachs to session course user
  355. foreach ($course_coaches as $course_coach) {
  356. $coach_id = UserManager::purify_username(api_utf8_decode($course_coach), $purification_option_for_usernames);
  357. $coach_id = UserManager::get_user_id_from_username($course_coach);
  358. if ($coach_id !== false) {
  359. $sql = "INSERT IGNORE INTO $tbl_session_course_user SET
  360. id_user='$coach_id',
  361. course_code='{$vcourse['code']}',
  362. id_session = '$session_id',
  363. status = 2 ";
  364. $rs_coachs = Database::query($sql);
  365. } else {
  366. $error_message .= get_lang('UserDoesNotExist').' : '.$user.'<br />';
  367. }
  368. }
  369. // adding users
  370. $course_counter++;
  371. $users_in_course_counter = 0;
  372. foreach ($node_course->User as $node_user) {
  373. $username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames);
  374. $user_id = UserManager::get_user_id_from_username($username);
  375. if ($user_id !== false) {
  376. // Adding to session_rel_user table.
  377. $sql = "INSERT IGNORE INTO $tbl_session_user SET
  378. id_user='$user_id',
  379. id_session = '$session_id'";
  380. $rs_user = Database::query($sql);
  381. $user_counter++;
  382. // Adding to session_rel_user_rel_course table.
  383. $sql = "INSERT IGNORE INTO $tbl_session_course_user SET
  384. id_user='$user_id',
  385. course_code='{$vcourse['code']}',
  386. id_session = '$session_id'";
  387. $rs_users = Database::query($sql);
  388. $users_in_course_counter++;
  389. } else {
  390. $error_message .= get_lang('UserDoesNotExist').' : '.$username.'<br />';
  391. }
  392. }
  393. $update_session_course = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE course_code='$course_code'";
  394. Database::query($update_session_course);
  395. $inserted_in_course[$course_code] = $course_info['title'];
  396. }
  397. $inserted_in_course[$vcourse['code']] = $vcourse['title'];
  398. }
  399. } else {
  400. // The course does not exist.
  401. $error_message .= get_lang('CourseDoesNotExist').' : '.$course_code.'<br />';
  402. }
  403. }
  404. Database::query("UPDATE $tbl_session SET nbr_users='$user_counter', nbr_courses='$course_counter' WHERE id='$session_id'");
  405. }
  406. }
  407. if (empty($root->Users->User) && empty($root->Courses->Course) && empty($root->Session)) {
  408. $error_message = get_lang('NoNeededData');
  409. }
  410. } else {
  411. $error_message .= get_lang('XMLNotValid');
  412. }
  413. } else {
  414. // CSV
  415. $updateCourseCoaches = isset($_POST['update_course_coaches']) ? true : false;
  416. $addOriginalCourseTeachersAsCourseSessionCoaches = isset($_POST['add_me_as_coach']) ? true : false;
  417. $result = SessionManager::importCSV(
  418. $_FILES['import_file']['tmp_name'],
  419. $isOverwrite,
  420. api_get_user_id(),
  421. null,
  422. array(),
  423. null,
  424. null,
  425. null,
  426. 1,
  427. array(),
  428. $deleteUsersNotInList,
  429. $updateCourseCoaches,
  430. false,
  431. $addOriginalCourseTeachersAsCourseSessionCoaches,
  432. false
  433. );
  434. $sessionList = $result['session_list'];
  435. $error_message = $result['error_message'];
  436. $session_counter = $result['session_counter'];
  437. }
  438. if (!empty($error_message)) {
  439. $error_message = get_lang('ButProblemsOccured').' :<br />'.$error_message;
  440. }
  441. if (count($inserted_in_course) > 1) {
  442. $warn = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': ';
  443. foreach ($inserted_in_course as $code => $title) {
  444. $warn .= ' '.$title.' ('.$code.'),';
  445. }
  446. $warn = substr($warn, 0, -1);
  447. }
  448. if ($session_counter == 1) {
  449. if ($file_type == 'csv') {
  450. $session_id = current($sessionList);
  451. }
  452. header('Location: resume_session.php?id_session='.$session_id.'&warn='.urlencode($warn));
  453. exit;
  454. } else {
  455. header('Location: session_list.php?action=show_message&message='.urlencode(get_lang('FileImported').' '.$error_message).'&warn='.urlencode($warn));
  456. exit;
  457. }
  458. } else {
  459. $error_message = get_lang('NoInputFile');
  460. }
  461. }
  462. // Display the header.
  463. Display::display_header($tool_name);
  464. if (count($inserted_in_course) > 1) {
  465. $msg = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': ';
  466. foreach ($inserted_in_course as $code => $title) {
  467. $msg .= ' '.$title.' ('.$title.'),';
  468. }
  469. $msg = substr($msg, 0, -1);
  470. Display::display_warning_message($msg);
  471. }
  472. echo '<div class="actions">';
  473. echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'',ICON_SIZE_MEDIUM).'</a>';
  474. echo '</div>';
  475. if (!empty($error_message)) {
  476. Display::display_normal_message($error_message, false);
  477. }
  478. $form = new FormValidator('import_sessions', 'post', api_get_self(), null, array('enctype' => 'multipart/form-data'));
  479. $form->addElement('hidden', 'formSent', 1);
  480. $form->addElement('file', 'import_file', get_lang('ImportFileLocation'));
  481. $form->addElement('radio', 'file_type', array(get_lang('FileType'), '<a href="example_session.csv" target="_blank">'.get_lang('ExampleCSVFile').'</a>'), 'CSV', 'csv');
  482. $form->addElement('radio', 'file_type', array(null, '<a href="example_session.xml" target="_blank">'.get_lang('ExampleXMLFile').'</a>'), 'XML', 'xml');
  483. $form->addElement('checkbox', 'overwrite', null, get_lang('IfSessionExistsUpdate'));
  484. $form->addElement('checkbox', 'delete_users_not_in_list', null, get_lang('DeleteUsersNotInList'));
  485. $form->addElement('checkbox', 'update_course_coaches', null, get_lang('CleanAndUpdateCourseCoaches'));
  486. $form->addElement('checkbox', 'add_me_as_coach', null, get_lang('AddMeAsCoach'));
  487. $form->addElement('checkbox', 'sendMail', null, get_lang('SendMailToUsers'));
  488. $form->addElement('button', 'submit', get_lang('ImportSession'));
  489. $defaults = array('sendMail' => 'true','file_type' => 'csv');
  490. $form->setDefaults($defaults);
  491. Display::display_normal_message(get_lang('TheXMLImportLetYouAddMoreInfoAndCreateResources'));
  492. $form->display();
  493. ?>
  494. <p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
  495. <blockquote>
  496. <pre>
  497. <strong>SessionName</strong>;Coach;<strong>DateStart</strong>;<strong>DateEnd</strong>;Users;Courses;VisibilityAfterExpiration
  498. <strong>Example 1</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...];read_only
  499. <strong>Example 2</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...];accessible
  500. <strong>Example 3</strong>;username;<strong>yyyy/mm/dd;yyyy/mm/dd</strong>;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...];not_accessible
  501. </pre>
  502. </blockquote>
  503. <p><?php echo get_lang('XMLMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>
  504. <blockquote>
  505. <pre>
  506. &lt;?xml version=&quot;1.0&quot; encoding=&quot;<?php echo api_refine_encoding_id(api_get_system_encoding()); ?>&quot;?&gt;
  507. &lt;Sessions&gt;
  508. &lt;Users&gt;
  509. &lt;User&gt;
  510. &lt;Username&gt;<strong>username1</strong>&lt;/Username&gt;
  511. &lt;Lastname&gt;xxx&lt;/Lastname&gt;
  512. &lt;Firstname&gt;xxx&lt;/Firstname&gt;
  513. &lt;Password&gt;xxx&lt;/Password&gt;
  514. &lt;Email&gt;xxx@xx.xx&lt;/Email&gt;
  515. &lt;OfficialCode&gt;xxx&lt;/OfficialCode&gt;
  516. &lt;Phone&gt;xxx&lt;/Phone&gt;
  517. &lt;Status&gt;student|teacher&lt;/Status&gt;
  518. &lt;/User&gt;
  519. &lt;/Users&gt;
  520. &lt;Courses&gt;
  521. &lt;Course&gt;
  522. &lt;CourseCode&gt;<strong>xxx</strong>&lt;/CourseCode&gt;
  523. &lt;CourseTeacher&gt;<strong>teacher_username</strong>&lt;/CourseTeacher&gt;
  524. &lt;CourseLanguage&gt;xxx&lt;/CourseLanguage&gt;
  525. &lt;CourseTitle&gt;xxx&lt;/CourseTitle&gt;
  526. &lt;CourseDescription&gt;xxx&lt;/CourseDescription&gt;
  527. &lt;/Course&gt;
  528. &lt;/Courses&gt;
  529. &lt;Session&gt;
  530. <strong>&lt;SessionName&gt;xxx&lt;/SessionName&gt;</strong>
  531. &lt;Coach&gt;xxx&lt;/Coach&gt;
  532. <strong>&lt;DateStart&gt;yyyy/mm/dd&lt;/DateStart&gt;</strong>
  533. <strong>&lt;DateEnd&gt;yyyy/mm/dd&lt;/DateEnd&gt;</strong>
  534. &lt;User&gt;xxx&lt;/User&gt;
  535. &lt;User&gt;xxx&lt;/User&gt;
  536. &lt;Course&gt;
  537. &lt;CourseCode&gt;coursecode1&lt;/CourseCode&gt;
  538. &lt;Coach&gt;coach1&lt;/Coach&gt;
  539. &lt;User&gt;username1&lt;/User&gt;
  540. &lt;User&gt;username2&lt;/User&gt;
  541. &lt;/Course&gt;
  542. &lt;/Session&gt;
  543. &lt;Session&gt;
  544. <strong>&lt;SessionName&gt;xxx&lt;/SessionName&gt;</strong>
  545. &lt;Coach&gt;xxx&lt;/Coach&gt;
  546. <strong>&lt;DateStart&gt;xxx&lt;/DateStart&gt;</strong>
  547. <strong>&lt;DateEnd&gt;xxx&lt;/DateEnd&gt;</strong>
  548. &lt;User&gt;xxx&lt;/User&gt;
  549. &lt;User&gt;xxx&lt;/User&gt;
  550. &lt;Course&gt;
  551. &lt;CourseCode&gt;coursecode1&lt;/CourseCode&gt;
  552. &lt;Coach&gt;coach1&lt;/Coach&gt;
  553. &lt;User&gt;username1&lt;/User&gt;
  554. &lt;User&gt;username2&lt;/User&gt;
  555. &lt;/Course&gt;
  556. &lt;/Session&gt;
  557. &lt;/Sessions&gt;
  558. </pre>
  559. </blockquote>
  560. <?php
  561. Display::display_footer();