session_edit.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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 '../inc/global.inc.php';
  9. // setting the section (for the tabs)
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. $formSent = 0;
  12. // Database Table Definitions
  13. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  14. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  15. $id = intval($_GET['id']);
  16. SessionManager::protect_session_edit($id);
  17. $infos = SessionManager::fetch($id);
  18. $id_coach = $infos['id_coach'];
  19. $tool_name = get_lang('EditSession');
  20. $interbreadcrumb[] = array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  21. $interbreadcrumb[] = array('url' => "session_list.php","name" => get_lang('SessionList'));
  22. $interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id,"name" => get_lang('SessionOverview'));
  23. list($year_start, $month_start, $day_start) = explode('-', $infos['date_start']);
  24. list($year_end, $month_end, $day_end) = explode('-', $infos['date_end']);
  25. $end_year_disabled = $end_month_disabled = $end_day_disabled = '';
  26. if (isset($_POST['formSent']) && $_POST['formSent']) {
  27. $formSent = 1;
  28. }
  29. $order_clause = 'ORDER BY ';
  30. $order_clause .= api_sort_by_first_name() ? 'firstname, lastname, username' : 'lastname, firstname, username';
  31. $sql="SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE status='1'".$order_clause;
  32. if (api_is_multiple_url_enabled()) {
  33. $table_access_url_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  34. $access_url_id = api_get_current_access_url_id();
  35. if ($access_url_id != -1) {
  36. $sql = "SELECT DISTINCT u.user_id,lastname,firstname,username
  37. FROM $tbl_user u
  38. INNER JOIN $table_access_url_rel_user url_rel_user ON (url_rel_user.user_id = u.user_id)
  39. WHERE status='1' AND access_url_id = '$access_url_id' $order_clause";
  40. }
  41. }
  42. $result = Database::query($sql);
  43. $coaches = Database::store_result($result);
  44. $thisYear = date('Y');
  45. $daysOption = array();
  46. for ($i = 1; $i <= 31; $i++) {
  47. $day = sprintf("%02d", $i);
  48. $daysOption[$day] = $day;
  49. }
  50. $monthsOption = array();
  51. for ($i = 1; $i <= 12; $i++) {
  52. $month = sprintf("%02d", $i);
  53. $monthsOption[$month] = $month;
  54. }
  55. $yearsOption = array();
  56. for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
  57. $yearsOption[$i] = $i;
  58. }
  59. $coachesOption = array(
  60. '' => '----- ' . get_lang('None') . ' -----'
  61. );
  62. foreach ($coaches as $coach) {
  63. $personName = api_get_person_name($coach['firstname'], $coach['lastname']);
  64. $coachesOption[$coach['user_id']] = "$personName ({$coach['username']})";
  65. }
  66. $categoriesList = SessionManager::get_all_session_category();
  67. $categoriesOption = array(
  68. '0' => get_lang('None')
  69. );
  70. if ($categoriesList != false) {
  71. foreach ($categoriesList as $categoryItem) {
  72. $categoriesOption[$categoryItem['id']] = $categoryItem['name'];
  73. }
  74. }
  75. $formAction = api_get_self() . '?';
  76. $formAction .= http_build_query(array(
  77. 'page' => Security::remove_XSS($_GET['page']),
  78. 'id' => $id
  79. ));
  80. $form = new FormValidator('edit_session', 'post', $formAction);
  81. $form->addElement('header', $tool_name);
  82. $form->addElement('text', 'name', get_lang('SessionName'), array(
  83. 'class' => 'span4',
  84. 'maxlength' => 50,
  85. 'value' => $formSent ? api_htmlentities($name,ENT_QUOTES,$charset) : ''
  86. ));
  87. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  88. $form->addRule('name', get_lang('SessionNameAlreadyExists'), 'callback', 'check_session_name');
  89. $form->addElement('select', 'id_coach', get_lang('CoachName'), $coachesOption, array(
  90. 'id' => 'coach_username',
  91. 'class' => 'chzn-select',
  92. 'style' => 'width:370px;',
  93. 'title' => get_lang('Choose')
  94. ));
  95. $form->addRule('id_coach', get_lang('ThisFieldIsRequired'), 'required');
  96. $form->addButtonAdvancedSettings('advanced_params');
  97. $form->addElement('html','<div id="advanced_params_options" style="display:none">');
  98. $form->addSelect('session_category', get_lang('SessionCategory'), $categoriesOption, array(
  99. 'id' => 'session_category',
  100. 'class' => 'chzn-select',
  101. 'style' => 'width:370px;'
  102. ));
  103. $form->addHtmlEditor(
  104. 'description',
  105. get_lang('Description'),
  106. false,
  107. false,
  108. array(
  109. 'ToolbarSet' => 'Minimal'
  110. )
  111. );
  112. $chkDescriptionAttributes = array();
  113. if (!empty($infos['show_description'])) {
  114. $chkDescriptionAttributes['checked'] = '';
  115. }
  116. $form->addElement('checkbox', 'show_description', null, get_lang('ShowDescription'), $chkDescriptionAttributes);
  117. $form->addElement('text', 'nb_days_access_before', array('', '', get_lang('DaysBefore')), array(
  118. 'input-size' => '2',
  119. ));
  120. $form->addElement('text', 'nb_days_access_after', array('', '', get_lang('DaysAfter')), array(
  121. 'input-size' => '2',
  122. ));
  123. if ($year_start!="0000") {
  124. $form->addElement('checkbox', 'start_limit', '', get_lang('DateStartSession'), array(
  125. 'onchange' => 'disable_starttime(this)',
  126. 'id' => 'start_limit',
  127. 'checked' => ''
  128. ));
  129. $form->addElement('html','<div id="start_date" style="display:block">');
  130. } else {
  131. $form->addElement('checkbox', 'start_limit', '', get_lang('DateStartSession'), array(
  132. 'onchange' => 'disable_starttime(this)',
  133. 'id' => 'start_limit'
  134. ));
  135. $form->addElement('html','<div id="start_date" style="display:none">');
  136. }
  137. $form->addElement('date_picker', 'date_start');
  138. $form->addElement('html','</div>');
  139. if ($year_end != "0000") {
  140. $form->addElement('checkbox', 'end_limit', '', get_lang('DateEndSession'), array(
  141. 'onchange' => 'disable_endtime(this)',
  142. 'id' => 'end_limit',
  143. 'checked' => ''
  144. ));
  145. $form->addElement('html','<div id="end_date" style="display:block">');
  146. } else {
  147. $form->addElement('checkbox', 'end_limit', '', get_lang('DateEndSession'), array(
  148. 'onchange' => 'disable_endtime(this)',
  149. 'id' => 'end_limit'
  150. ));
  151. $form->addElement('html','<div id="end_date" style="display:none">');
  152. }
  153. $form->addElement('date_picker', 'date_end');
  154. $visibilityGroup = array();
  155. $visibilityGroup[] = $form->createElement('select', 'session_visibility', null, array(
  156. SESSION_VISIBLE_READ_ONLY => get_lang('SessionReadOnly'),
  157. SESSION_VISIBLE => get_lang('SessionAccessible'),
  158. SESSION_INVISIBLE => api_ucfirst(get_lang('SessionNotAccessible'))
  159. ), array(
  160. 'style' => 'width:250px;'
  161. ));
  162. $form->addGroup($visibilityGroup, 'visibility_group', get_lang('SessionVisibility'), null, false);
  163. $form->addElement('html','</div>');
  164. $duration = empty($infos['duration']) ? null : $infos['duration'];
  165. $form->addElement(
  166. 'text',
  167. 'duration',
  168. array(
  169. get_lang('SessionDurationTitle'),
  170. get_lang('SessionDurationDescription')
  171. ),
  172. array(
  173. 'maxlength' => 50
  174. )
  175. );
  176. //Extra fields
  177. $extra_field = new ExtraField('session');
  178. $extra = $extra_field->addElements($form, $id);
  179. $form->addElement('html','</div>');
  180. $htmlHeadXtra[] ='
  181. <script>
  182. $(function() {
  183. '.$extra['jquery_ready_content'].'
  184. });
  185. </script>';
  186. $form->addButtonUpdate(get_lang('ModifyThisSession'));
  187. $formDefaults = array(
  188. 'id_coach' => $infos['id_coach'],
  189. 'session_category' => $infos['session_category_id'],
  190. 'date_start' => $infos['date_start'],
  191. 'date_end' => $infos['date_end'],
  192. 'session_visibility' => $infos['visibility'],
  193. 'description' => $infos['description']
  194. );
  195. if ($formSent) {
  196. $formDefaults['name'] = api_htmlentities($name,ENT_QUOTES,$charset);
  197. $formDefaults['nb_days_access_before'] = api_htmlentities($nb_days_access_before,ENT_QUOTES,$charset);
  198. $formDefaults['nb_days_access_after'] = api_htmlentities($nb_days_access_after,ENT_QUOTES,$charset);
  199. $formDefaults['duration'] = Security::remove_XSS($duration);
  200. } else {
  201. $formDefaults['name'] = Security::remove_XSS($infos['name']);
  202. $formDefaults['nb_days_access_before'] = api_htmlentities($infos['nb_days_access_before_beginning'],ENT_QUOTES,$charset);
  203. $formDefaults['nb_days_access_after'] = api_htmlentities($infos['nb_days_access_after_end'],ENT_QUOTES,$charset);
  204. $formDefaults['duration'] = $duration;
  205. }
  206. $form->setDefaults($formDefaults);
  207. if ($form->validate()) {
  208. $params = $form->getSubmitValues();
  209. $name = $params['name'];
  210. $startDate = $params['date_start'];
  211. $endDate = $params['date_end'];
  212. $nb_days_acess_before = $params['nb_days_access_before'];
  213. $nb_days_acess_after = $params['nb_days_access_after'];
  214. $id_coach = $params['id_coach'];
  215. $id_session_category = $params['session_category'];
  216. $id_visibility = $params['session_visibility'];
  217. $duration = isset($params['duration']) ? $params['duration'] : null;
  218. $description = $params['description'];
  219. $showDescription = isset($params['show_description']) ? 1: 0;
  220. $end_limit = isset($params['end_limit']);
  221. $start_limit = isset($params['start_limit']);
  222. if (!$end_limit && !$start_limit) {
  223. $nolimit = 1;
  224. } else {
  225. $nolimit = null;
  226. }
  227. $extraFields = array();
  228. foreach ($params as $key => $value) {
  229. if (strpos($key, 'extra_') === 0) {
  230. $extraFields[$key] = $value;
  231. }
  232. }
  233. $return = SessionManager::edit_session(
  234. $id,
  235. $name,
  236. $startDate,
  237. $endDate,
  238. $nb_days_acess_before,
  239. $nb_days_acess_after,
  240. $nolimit,
  241. $id_coach,
  242. $id_session_category,
  243. $id_visibility,
  244. $start_limit,
  245. $end_limit,
  246. $description,
  247. $showDescription,
  248. $duration,
  249. $extraFields
  250. );
  251. if ($return == strval(intval($return))) {
  252. header('Location: resume_session.php?id_session=' . $return);
  253. exit();
  254. }
  255. }
  256. // display the header
  257. Display::display_header($tool_name);
  258. if (!empty($return)) {
  259. Display::display_error_message($return,false);
  260. }
  261. $form->display();
  262. ?>
  263. <script type="text/javascript">
  264. function setDisable(select) {
  265. document.forms['edit_session'].elements['session_visibility'].disabled = (select.checked) ? true : false;
  266. document.forms['edit_session'].elements['session_visibility'].selectedIndex = 0;
  267. document.forms['edit_session'].elements['start_limit'].disabled = (select.checked) ? true : false;
  268. document.forms['edit_session'].elements['start_limit'].checked = false;
  269. document.forms['edit_session'].elements['end_limit'].disabled = (select.checked) ? true : false;
  270. document.forms['edit_session'].elements['end_limit'].checked = false;
  271. var end_div = document.getElementById('end_date');
  272. end_div.style.display = 'none';
  273. var start_div = document.getElementById('start_date');
  274. start_div.style.display = 'none';
  275. }
  276. function disable_endtime(select) {
  277. var end_div = document.getElementById('end_date');
  278. if (end_div.style.display == 'none')
  279. end_div.style.display = 'block';
  280. else
  281. end_div.style.display = 'none';
  282. emptyDuration();
  283. }
  284. function disable_starttime(select) {
  285. var start_div = document.getElementById('start_date');
  286. if (start_div.style.display == 'none')
  287. start_div.style.display = 'block';
  288. else
  289. start_div.style.display = 'none';
  290. emptyDuration();
  291. }
  292. function emptyDuration() {
  293. if ($('#duration').val()) {
  294. $('#duration').val('');
  295. }
  296. }
  297. $(document).on('ready', function (){
  298. $('#show-options').on('click', function (e) {
  299. e.preventDefault();
  300. var display = $('#options').css('display');
  301. display === 'block' ? $('#options').slideUp() : $('#options').slideDown() ;
  302. });
  303. });
  304. </script>
  305. <?php
  306. Display::display_footer();