session_import.php 35 KB

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