session_category_edit.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Edition script for sessions categories.
  5. *
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. // setting the section (for the tabs)
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script(true);
  13. $id = intval($_GET['id']);
  14. $formSent = 0;
  15. $errorMsg = '';
  16. // Database Table Definitions
  17. $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
  18. $tool_name = get_lang('EditSessionCategory');
  19. $interbreadcrumb[] = [
  20. 'url' => 'session_list.php',
  21. "name" => get_lang('SessionList'),
  22. ];
  23. $interbreadcrumb[] = [
  24. 'url' => "session_category_list.php",
  25. "name" => get_lang('ListSessionCategory'),
  26. ];
  27. $sql = "SELECT * FROM $tbl_session_category WHERE id='".$id."' ORDER BY name";
  28. $result = Database::query($sql);
  29. if (!$infos = Database::fetch_array($result)) {
  30. header('Location: session_list.php');
  31. exit();
  32. }
  33. list($year_start, $month_start, $day_start) = explode('-', $infos['date_start']);
  34. list($year_end, $month_end, $day_end) = explode('-', $infos['date_end']);
  35. if (!api_is_platform_admin() && $infos['session_admin_id'] != $_user['user_id'] && !api_is_session_admin()) {
  36. api_not_allowed(true);
  37. }
  38. if (isset($_POST['formSent']) && $_POST['formSent']) {
  39. $formSent = 1;
  40. $name = $_POST['name'];
  41. $year_start = $_POST['year_start'];
  42. $month_start = $_POST['month_start'];
  43. $day_start = $_POST['day_start'];
  44. $year_end = $_POST['year_end'];
  45. $month_end = $_POST['month_end'];
  46. $day_end = $_POST['day_end'];
  47. $return = SessionManager::edit_category_session(
  48. $id,
  49. $name,
  50. $year_start,
  51. $month_start,
  52. $day_start,
  53. $year_end,
  54. $month_end,
  55. $day_end
  56. );
  57. if ($return == strval(intval($return))) {
  58. Display::addFlash(Display::return_message(get_lang('SessionCategoryUpdate')));
  59. header('Location: session_category_list.php');
  60. exit();
  61. }
  62. }
  63. $thisYear = date('Y');
  64. $thisMonth = date('m');
  65. $thisDay = date('d');
  66. // display the header
  67. Display::display_header($tool_name);
  68. if (!empty($return)) {
  69. echo Display::return_message($return, 'error', false);
  70. }
  71. ?>
  72. <div class="row">
  73. <div class="col-md-12">
  74. <form method="post" name="form" action="<?php echo api_get_self(); ?>?id=<?php echo $id; ?>" class="form-horizontal">
  75. <input type="hidden" name="formSent" value="1">
  76. <legend><?php echo $tool_name; ?> </legend>
  77. <div class="form-group">
  78. <label class="col-sm-3 control-label"><?php echo get_lang('Name'); ?></label>
  79. <div class="col-sm-6">
  80. <input class="form-control" type="text" name="name" size="50" maxlength="50" value="<?php if ($formSent) {
  81. echo api_htmlentities($name, ENT_QUOTES, $charset);
  82. } else {
  83. echo api_htmlentities($infos['name'], ENT_QUOTES, $charset);
  84. } ?>">
  85. </div>
  86. <div class="col-sm-3"></div>
  87. </div>
  88. <div class="form-group">
  89. <div class="col-sm-offset-3 col-sm-6">
  90. <?php echo get_lang('TheTimeLimitsAreReferential'); ?>
  91. <a href="javascript://" onclick="if(document.getElementById('options').style.display == 'none'){document.getElementById('options').style.display = 'block';}else{document.getElementById('options').style.display = 'none';}"><?php echo get_lang('EditTimeLimit'); ?></a>
  92. </div>
  93. </div>
  94. <div style="display: <?php echo $formSent ? 'display' : 'none'; ?>;" id="options">
  95. <div class="form-group">
  96. <label class="col-sm-3 control-label"><?php echo get_lang('DateStart'); ?></label>
  97. <div class="col-sm-6">
  98. <select name="day_start">
  99. <option value="1">01</option>
  100. <option value="2" <?php if ($day_start == 2) {
  101. echo 'selected="selected"';
  102. } ?> >02</option>
  103. <option value="3" <?php if ($day_start == 3) {
  104. echo 'selected="selected"';
  105. } ?> >03</option>
  106. <option value="4" <?php if ($day_start == 4) {
  107. echo 'selected="selected"';
  108. } ?> >04</option>
  109. <option value="5" <?php if ($day_start == 5) {
  110. echo 'selected="selected"';
  111. } ?> >05</option>
  112. <option value="6" <?php if ($day_start == 6) {
  113. echo 'selected="selected"';
  114. } ?> >06</option>
  115. <option value="7" <?php if ($day_start == 7) {
  116. echo 'selected="selected"';
  117. } ?> >07</option>
  118. <option value="8" <?php if ($day_start == 8) {
  119. echo 'selected="selected"';
  120. } ?> >08</option>
  121. <option value="9" <?php if ($day_start == 9) {
  122. echo 'selected="selected"';
  123. } ?> >09</option>
  124. <option value="10" <?php if ($day_start == 10) {
  125. echo 'selected="selected"';
  126. } ?> >10</option>
  127. <option value="11" <?php if ($day_start == 11) {
  128. echo 'selected="selected"';
  129. } ?> >11</option>
  130. <option value="12" <?php if ($day_start == 12) {
  131. echo 'selected="selected"';
  132. } ?> >12</option>
  133. <option value="13" <?php if ($day_start == 13) {
  134. echo 'selected="selected"';
  135. } ?> >13</option>
  136. <option value="14" <?php if ($day_start == 14) {
  137. echo 'selected="selected"';
  138. } ?> >14</option>
  139. <option value="15" <?php if ($day_start == 15) {
  140. echo 'selected="selected"';
  141. } ?> >15</option>
  142. <option value="16" <?php if ($day_start == 16) {
  143. echo 'selected="selected"';
  144. } ?> >16</option>
  145. <option value="17" <?php if ($day_start == 17) {
  146. echo 'selected="selected"';
  147. } ?> >17</option>
  148. <option value="18" <?php if ($day_start == 18) {
  149. echo 'selected="selected"';
  150. } ?> >18</option>
  151. <option value="19" <?php if ($day_start == 19) {
  152. echo 'selected="selected"';
  153. } ?> >19</option>
  154. <option value="20" <?php if ($day_start == 20) {
  155. echo 'selected="selected"';
  156. } ?> >20</option>
  157. <option value="21" <?php if ($day_start == 21) {
  158. echo 'selected="selected"';
  159. } ?> >21</option>
  160. <option value="22" <?php if ($day_start == 22) {
  161. echo 'selected="selected"';
  162. } ?> >22</option>
  163. <option value="23" <?php if ($day_start == 23) {
  164. echo 'selected="selected"';
  165. } ?> >23</option>
  166. <option value="24" <?php if ($day_start == 24) {
  167. echo 'selected="selected"';
  168. } ?> >24</option>
  169. <option value="25" <?php if ($day_start == 25) {
  170. echo 'selected="selected"';
  171. } ?> >25</option>
  172. <option value="26" <?php if ($day_start == 26) {
  173. echo 'selected="selected"';
  174. } ?> >26</option>
  175. <option value="27" <?php if ($day_start == 27) {
  176. echo 'selected="selected"';
  177. } ?> >27</option>
  178. <option value="28" <?php if ($day_start == 28) {
  179. echo 'selected="selected"';
  180. } ?> >28</option>
  181. <option value="29" <?php if ($day_start == 29) {
  182. echo 'selected="selected"';
  183. } ?> >29</option>
  184. <option value="30" <?php if ($day_start == 30) {
  185. echo 'selected="selected"';
  186. } ?> >30</option>
  187. <option value="31" <?php if ($day_start == 31) {
  188. echo 'selected="selected"';
  189. } ?> >31</option>
  190. </select>
  191. /
  192. <select name="month_start">
  193. <option value="1">01</option>
  194. <option value="2" <?php if ($month_start == 2) {
  195. echo 'selected="selected"';
  196. } ?> >02</option>
  197. <option value="3" <?php if ($month_start == 3) {
  198. echo 'selected="selected"';
  199. } ?> >03</option>
  200. <option value="4" <?php if ($month_start == 4) {
  201. echo 'selected="selected"';
  202. } ?> >04</option>
  203. <option value="5" <?php if ($month_start == 5) {
  204. echo 'selected="selected"';
  205. } ?> >05</option>
  206. <option value="6" <?php if ($month_start == 6) {
  207. echo 'selected="selected"';
  208. } ?> >06</option>
  209. <option value="7" <?php if ($month_start == 7) {
  210. echo 'selected="selected"';
  211. } ?> >07</option>
  212. <option value="8" <?php if ($month_start == 8) {
  213. echo 'selected="selected"';
  214. } ?> >08</option>
  215. <option value="9" <?php if ($month_start == 9) {
  216. echo 'selected="selected"';
  217. } ?> >09</option>
  218. <option value="10" <?php if ($month_start == 10) {
  219. echo 'selected="selected"';
  220. } ?> >10</option>
  221. <option value="11" <?php if ($month_start == 11) {
  222. echo 'selected="selected"';
  223. } ?> >11</option>
  224. <option value="12" <?php if ($month_start == 12) {
  225. echo 'selected="selected"';
  226. } ?> >12</option>
  227. </select>
  228. /
  229. <select name="year_start">
  230. <?php
  231. for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
  232. ?>
  233. <option value="<?php echo $i; ?>" <?php if ($year_start == $i) {
  234. echo 'selected="selected"';
  235. } ?> ><?php echo $i; ?></option>
  236. <?php
  237. } ?>
  238. </select>
  239. </div>
  240. <div class="col-sm-3"></div>
  241. </div>
  242. <div class="form-group">
  243. <label class="col-sm-3 control-label"><?php echo get_lang('DateEnd'); ?></label>
  244. <div class="col-sm-6">
  245. <select name="day_end">
  246. <option value="0">--</option>
  247. <option value="1" <?php if ($day_end == 1) {
  248. echo 'selected="selected"';
  249. } ?> >01</option>
  250. <option value="2" <?php if ($day_end == 2) {
  251. echo 'selected="selected"';
  252. } ?> >02</option>
  253. <option value="3" <?php if ($day_end == 3) {
  254. echo 'selected="selected"';
  255. } ?> >03</option>
  256. <option value="4" <?php if ($day_end == 4) {
  257. echo 'selected="selected"';
  258. } ?> >04</option>
  259. <option value="5" <?php if ($day_end == 5) {
  260. echo 'selected="selected"';
  261. } ?> >05</option>
  262. <option value="6" <?php if ($day_end == 6) {
  263. echo 'selected="selected"';
  264. } ?> >06</option>
  265. <option value="7" <?php if ($day_end == 7) {
  266. echo 'selected="selected"';
  267. } ?> >07</option>
  268. <option value="8" <?php if ($day_end == 8) {
  269. echo 'selected="selected"';
  270. } ?> >08</option>
  271. <option value="9" <?php if ($day_end == 9) {
  272. echo 'selected="selected"';
  273. } ?> >09</option>
  274. <option value="10" <?php if ($day_end == 10) {
  275. echo 'selected="selected"';
  276. } ?> >10</option>
  277. <option value="11" <?php if ($day_end == 11) {
  278. echo 'selected="selected"';
  279. } ?> >11</option>
  280. <option value="12" <?php if ($day_end == 12) {
  281. echo 'selected="selected"';
  282. } ?> >12</option>
  283. <option value="13" <?php if ($day_end == 13) {
  284. echo 'selected="selected"';
  285. } ?> >13</option>
  286. <option value="14" <?php if ($day_end == 14) {
  287. echo 'selected="selected"';
  288. } ?> >14</option>
  289. <option value="15" <?php if ($day_end == 15) {
  290. echo 'selected="selected"';
  291. } ?> >15</option>
  292. <option value="16" <?php if ($day_end == 16) {
  293. echo 'selected="selected"';
  294. } ?> >16</option>
  295. <option value="17" <?php if ($day_end == 17) {
  296. echo 'selected="selected"';
  297. } ?> >17</option>
  298. <option value="18" <?php if ($day_end == 18) {
  299. echo 'selected="selected"';
  300. } ?> >18</option>
  301. <option value="19" <?php if ($day_end == 19) {
  302. echo 'selected="selected"';
  303. } ?> >19</option>
  304. <option value="20" <?php if ($day_end == 20) {
  305. echo 'selected="selected"';
  306. } ?> >20</option>
  307. <option value="21" <?php if ($day_end == 21) {
  308. echo 'selected="selected"';
  309. } ?> >21</option>
  310. <option value="22" <?php if ($day_end == 22) {
  311. echo 'selected="selected"';
  312. } ?> >22</option>
  313. <option value="23" <?php if ($day_end == 23) {
  314. echo 'selected="selected"';
  315. } ?> >23</option>
  316. <option value="24" <?php if ($day_end == 24) {
  317. echo 'selected="selected"';
  318. } ?> >24</option>
  319. <option value="25" <?php if ($day_end == 25) {
  320. echo 'selected="selected"';
  321. } ?> >25</option>
  322. <option value="26" <?php if ($day_end == 26) {
  323. echo 'selected="selected"';
  324. } ?> >26</option>
  325. <option value="27" <?php if ($day_end == 27) {
  326. echo 'selected="selected"';
  327. } ?> >27</option>
  328. <option value="28" <?php if ($day_end == 28) {
  329. echo 'selected="selected"';
  330. } ?> >28</option>
  331. <option value="29" <?php if ($day_end == 29) {
  332. echo 'selected="selected"';
  333. } ?> >29</option>
  334. <option value="30" <?php if ($day_end == 30) {
  335. echo 'selected="selected"';
  336. } ?> >30</option>
  337. <option value="31" <?php if ($day_end == 31) {
  338. echo 'selected="selected"';
  339. } ?> >31</option>
  340. </select>
  341. /
  342. <select name="month_end">
  343. <option value="0">--</option>
  344. <option value="1" <?php if ($month_end == 1) {
  345. echo 'selected="selected"';
  346. } ?> >01</option>
  347. <option value="2" <?php if ($month_end == 2) {
  348. echo 'selected="selected"';
  349. } ?> >02</option>
  350. <option value="3" <?php if ($month_end == 3) {
  351. echo 'selected="selected"';
  352. } ?> >03</option>
  353. <option value="4" <?php if ($month_end == 4) {
  354. echo 'selected="selected"';
  355. } ?> >04</option>
  356. <option value="5" <?php if ($month_end == 5) {
  357. echo 'selected="selected"';
  358. } ?> >05</option>
  359. <option value="6" <?php if ($month_end == 6) {
  360. echo 'selected="selected"';
  361. } ?> >06</option>
  362. <option value="7" <?php if ($month_end == 7) {
  363. echo 'selected="selected"';
  364. } ?> >07</option>
  365. <option value="8" <?php if ($month_end == 8) {
  366. echo 'selected="selected"';
  367. } ?> >08</option>
  368. <option value="9" <?php if ($month_end == 9) {
  369. echo 'selected="selected"';
  370. } ?> >09</option>
  371. <option value="10" <?php if ($month_end == 10) {
  372. echo 'selected="selected"';
  373. } ?> >10</option>
  374. <option value="11" <?php if ($month_end == 11) {
  375. echo 'selected="selected"';
  376. } ?> >11</option>
  377. <option value="12" <?php if ($month_end == 12) {
  378. echo 'selected="selected"';
  379. } ?> >12</option>
  380. </select>
  381. /
  382. <select name="year_end">
  383. <option value="0">----</option>
  384. <?php
  385. for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
  386. ?>
  387. <option value="<?php echo $i; ?>" <?php if ($year_end == $i) {
  388. echo 'selected="selected"';
  389. } ?> ><?php echo $i; ?></option>
  390. <?php
  391. } ?>
  392. </select>
  393. </div>
  394. <div class="col-sm-3"></div>
  395. </div>
  396. </div>
  397. <div class="form-group">
  398. <div class="col-sm-offset-3 col-sm-6">
  399. <button class="btn btn-success" type="submit" value="<?php echo get_lang('Edit'); ?>">
  400. <?php echo get_lang('Edit'); ?>
  401. </button>
  402. </div>
  403. </div>
  404. </form>
  405. </div>
  406. </div>
  407. <script>
  408. <?php if ($year_start == "0000") {
  409. echo "setDisable(document.form.nolimit);\r\n";
  410. } ?>
  411. function setDisable(select){
  412. document.form.day_start.disabled = (select.checked) ? true : false;
  413. document.form.month_start.disabled = (select.checked) ? true : false;
  414. document.form.year_start.disabled = (select.checked) ? true : false;
  415. document.form.day_end.disabled = (select.checked) ? true : false;
  416. document.form.month_end.disabled = (select.checked) ? true : false;
  417. document.form.year_end.disabled = (select.checked) ? true : false;
  418. }
  419. </script>
  420. <?php
  421. Display::display_footer();