session_edit.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Sessions edition script
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. // setting the section (for the tabs)
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. $formSent = 0;
  12. // Crop picture plugin for session images
  13. $htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
  14. $htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
  15. // Database Table Definitions
  16. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  17. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  18. $id = intval($_GET['id']);
  19. SessionManager::protectSession($id);
  20. $sessionInfo = SessionManager::fetch($id);
  21. // Sets to local time to show it correctly when you edit a session
  22. if (!empty($sessionInfo['display_start_date'])) {
  23. $sessionInfo['display_start_date'] = api_get_local_time($sessionInfo['display_start_date']);
  24. }
  25. if (!empty($sessionInfo['display_end_date'])) {
  26. $sessionInfo['display_end_date'] = api_get_local_time($sessionInfo['display_end_date']);
  27. }
  28. if (!empty($sessionInfo['access_start_date'])) {
  29. $sessionInfo['access_start_date'] = api_get_local_time($sessionInfo['access_start_date']);
  30. }
  31. if (!empty($sessionInfo['access_end_date'])) {
  32. $sessionInfo['access_end_date'] = api_get_local_time($sessionInfo['access_end_date']);
  33. }
  34. if (!empty($sessionInfo['coach_access_start_date'])) {
  35. $sessionInfo['coach_access_start_date'] = api_get_local_time($sessionInfo['coach_access_start_date']);
  36. }
  37. if (!empty($sessionInfo['coach_access_end_date'])) {
  38. $sessionInfo['coach_access_end_date'] = api_get_local_time($sessionInfo['coach_access_end_date']);
  39. }
  40. $id_coach = $sessionInfo['id_coach'];
  41. $tool_name = get_lang('EditSession');
  42. //$interbreadcrumb[] = array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  43. $interbreadcrumb[] = array('url' => "session_list.php", "name" => get_lang('SessionList'));
  44. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id, "name" => get_lang('SessionOverview'));
  45. if (isset($_POST['formSent']) && $_POST['formSent']) {
  46. $formSent = 1;
  47. }
  48. $order_clause = 'ORDER BY ';
  49. $order_clause .= api_sort_by_first_name() ? 'firstname, lastname, username' : 'lastname, firstname, username';
  50. $sql = "SELECT user_id,lastname,firstname,username
  51. FROM $tbl_user
  52. WHERE status='1'".$order_clause;
  53. if (api_is_multiple_url_enabled()) {
  54. $table_access_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  55. $access_url_id = api_get_current_access_url_id();
  56. if ($access_url_id != -1) {
  57. $sql = "SELECT DISTINCT u.user_id,lastname,firstname,username
  58. FROM $tbl_user u
  59. INNER JOIN $table_access_url_rel_user url_rel_user
  60. ON (url_rel_user.user_id = u.user_id)
  61. WHERE status='1' AND access_url_id = '$access_url_id' $order_clause";
  62. }
  63. }
  64. $result = Database::query($sql);
  65. $coaches = Database::store_result($result);
  66. $thisYear = date('Y');
  67. $coachesOption = array(
  68. '' => '----- '.get_lang('None').' -----'
  69. );
  70. foreach ($coaches as $coach) {
  71. $personName = api_get_person_name($coach['firstname'], $coach['lastname']);
  72. $coachesOption[$coach['user_id']] = "$personName ({$coach['username']})";
  73. }
  74. $categoriesList = SessionManager::get_all_session_category();
  75. $categoriesOption = array(
  76. '0' => get_lang('None')
  77. );
  78. if ($categoriesList != false) {
  79. foreach ($categoriesList as $categoryItem) {
  80. $categoriesOption[$categoryItem['id']] = $categoryItem['name'];
  81. }
  82. }
  83. $formAction = api_get_self().'?';
  84. $formAction .= http_build_query(array(
  85. 'page' => Security::remove_XSS($_GET['page']),
  86. 'id' => $id
  87. ));
  88. $form = new FormValidator('edit_session', 'post', $formAction);
  89. $form->addElement('header', $tool_name);
  90. $result = SessionManager::setForm($form, $sessionInfo);
  91. $htmlHeadXtra[] = '
  92. <script>
  93. $(function() {
  94. '.$result['js'].'
  95. });
  96. </script>';
  97. $form->addButtonUpdate(get_lang('ModifyThisSession'));
  98. $formDefaults = $sessionInfo;
  99. $formDefaults['coach_username'] = $sessionInfo['id_coach'];
  100. $formDefaults['session_category'] = $sessionInfo['session_category_id'];
  101. $formDefaults['session_visibility'] = $sessionInfo['visibility'];
  102. if ($formSent) {
  103. $formDefaults['name'] = api_htmlentities($name, ENT_QUOTES, $charset);
  104. } else {
  105. $formDefaults['name'] = Security::remove_XSS($sessionInfo['name']);
  106. }
  107. $form->setDefaults($formDefaults);
  108. if ($form->validate()) {
  109. $params = $form->getSubmitValues();
  110. $name = $params['name'];
  111. $startDate = $params['access_start_date'];
  112. $endDate = $params['access_end_date'];
  113. $displayStartDate = $params['display_start_date'];
  114. $displayEndDate = $params['display_end_date'];
  115. $coachStartDate = $params['coach_access_start_date'];
  116. $coachEndDate = $params['coach_access_end_date'];
  117. $coach_username = intval($params['coach_username']);
  118. $id_session_category = $params['session_category'];
  119. $id_visibility = $params['session_visibility'];
  120. $duration = isset($params['duration']) ? $params['duration'] : null;
  121. if ($params['access'] == 1) {
  122. $duration = null;
  123. }
  124. $description = $params['description'];
  125. $showDescription = isset($params['show_description']) ? 1 : 0;
  126. $sendSubscriptionNotification = isset($params['send_subscription_notification']);
  127. $isThisImageCropped = isset($params['picture_crop_result']);
  128. $extraFields = [];
  129. foreach ($params as $key => $value) {
  130. if (strpos($key, 'extra_') === 0) {
  131. $extraFields[$key] = $value;
  132. }
  133. }
  134. if (isset($extraFields['extra_image']) && $isThisImageCropped) {
  135. $extraFields['extra_image']['crop_parameters'] = $params['picture_crop_result'];
  136. }
  137. $return = SessionManager::edit_session(
  138. $id,
  139. $name,
  140. $startDate,
  141. $endDate,
  142. $displayStartDate,
  143. $displayEndDate,
  144. $coachStartDate,
  145. $coachEndDate,
  146. $coach_username,
  147. $id_session_category,
  148. $id_visibility,
  149. $description,
  150. $showDescription,
  151. $duration,
  152. $extraFields,
  153. null,
  154. $sendSubscriptionNotification
  155. );
  156. if ($return) {
  157. Display::addFlash(Display::return_message(get_lang('Updated')));
  158. header('Location: resume_session.php?id_session='.$return);
  159. exit();
  160. }
  161. }
  162. // display the header
  163. Display::display_header($tool_name);
  164. $form->display();
  165. ?>
  166. <script>
  167. $(document).ready( function() {
  168. <?php
  169. if (!empty($sessionInfo['duration'])) {
  170. echo 'accessSwitcher(0);';
  171. } else {
  172. echo 'accessSwitcher(1);';
  173. }
  174. ?>
  175. });
  176. function accessSwitcher(accessFromReady) {
  177. var access = $('#access option:selected').val();
  178. if (accessFromReady >= 0) {
  179. access = accessFromReady;
  180. $('[name=access]').val(access);
  181. }
  182. if (access == 1) {
  183. $('#duration').hide();
  184. $('#date_fields').show();
  185. } else {
  186. $('#duration').show();
  187. $('#date_fields').hide();
  188. }
  189. emptyDuration();
  190. }
  191. function emptyDuration() {
  192. if ($('#duration').val()) {
  193. $('#duration').val('');
  194. }
  195. }
  196. $(document).on('ready', function (){
  197. $('#show-options').on('click', function (e) {
  198. e.preventDefault();
  199. var display = $('#options').css('display');
  200. display === 'block' ? $('#options').slideUp() : $('#options').slideDown() ;
  201. });
  202. });
  203. </script>
  204. <?php
  205. Display::display_footer();