session_import.php 34 KB

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