session_category_add.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. *
  6. * @todo use formvalidator for the form
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $xajax = new xajax();
  11. $xajax->registerFunction('search_coachs');
  12. // setting the section (for the tabs)
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. api_protect_admin_script(true);
  15. $formSent = 0;
  16. $errorMsg = '';
  17. $interbreadcrumb[] = [
  18. 'url' => 'session_list.php',
  19. 'name' => get_lang('Session list'),
  20. ];
  21. $interbreadcrumb[] = [
  22. 'url' => "session_category_list.php",
  23. "name" => get_lang('Sessions categories list'),
  24. ];
  25. // Database Table Definitions
  26. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  27. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  28. if (isset($_POST['formSent']) && $_POST['formSent']) {
  29. $formSent = 1;
  30. $name = $_POST['name'];
  31. $year_start = $_POST['year_start'];
  32. $month_start = $_POST['month_start'];
  33. $day_start = $_POST['day_start'];
  34. $year_end = $_POST['year_end'];
  35. $month_end = $_POST['month_end'];
  36. $day_end = $_POST['day_end'];
  37. $return = SessionManager::create_category_session(
  38. $name,
  39. $year_start,
  40. $month_start,
  41. $day_start,
  42. $year_end,
  43. $month_end,
  44. $day_end
  45. );
  46. if ($return == strval(intval($return))) {
  47. Display::addFlash(Display::return_message(get_lang('The category has been added')));
  48. header('Location: session_category_list.php');
  49. exit();
  50. }
  51. }
  52. $thisYear = date('Y');
  53. $thisMonth = date('m');
  54. $thisDay = date('d');
  55. $tool_name = get_lang('Add category');
  56. //display the header
  57. Display::display_header($tool_name);
  58. if (!empty($return)) {
  59. echo Display::return_message($return, 'error', false);
  60. }
  61. ?>
  62. <div class="row">
  63. <div class="col-md-12">
  64. <form method="post" name="form" action="<?php echo api_get_self(); ?>" class="form-horizontal">
  65. <input type="hidden" name="formSent" value="1">
  66. <legend><?php echo $tool_name; ?></legend>
  67. <div class="form-group">
  68. <label class="col-sm-3 control-label"><?php echo get_lang('Category name'); ?></label>
  69. <div class="col-sm-6">
  70. <input type="text" class="form-control" name="name" placeholder="<?php echo get_lang('Category'); ?>" size="50" maxlength="50" value="<?php if ($formSent) {
  71. echo api_htmlentities($name, ENT_QUOTES, $charset);
  72. } ?>">
  73. </div>
  74. <div class="col-md-3"></div>
  75. </div>
  76. <div class="form-group">
  77. <div class="col-sm-offset-3 col-sm-6">
  78. <?php echo get_lang('The time limit of a category is referential, will not affect the boundaries of a training session'); ?> <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('Add time limit'); ?></a>
  79. </div>
  80. <div class="col-md-3"></div>
  81. </div>
  82. <div style="display: none" id="options">
  83. <div class="form-group">
  84. <label class="col-sm-3 control-label"><?php echo get_lang('Start date'); ?></label>
  85. <div class="col-sm-6">
  86. <select name="day_start">
  87. <option value="1">01</option>
  88. <option value="2" <?php if ((!$formSent && $thisDay == 2) || ($formSent && $day_start == 2)) {
  89. echo 'selected="selected"';
  90. } ?> >02</option>
  91. <option value="3" <?php if ((!$formSent && $thisDay == 3) || ($formSent && $day_start == 3)) {
  92. echo 'selected="selected"';
  93. } ?> >03</option>
  94. <option value="4" <?php if ((!$formSent && $thisDay == 4) || ($formSent && $day_start == 4)) {
  95. echo 'selected="selected"';
  96. } ?> >04</option>
  97. <option value="5" <?php if ((!$formSent && $thisDay == 5) || ($formSent && $day_start == 5)) {
  98. echo 'selected="selected"';
  99. } ?> >05</option>
  100. <option value="6" <?php if ((!$formSent && $thisDay == 6) || ($formSent && $day_start == 6)) {
  101. echo 'selected="selected"';
  102. } ?> >06</option>
  103. <option value="7" <?php if ((!$formSent && $thisDay == 7) || ($formSent && $day_start == 7)) {
  104. echo 'selected="selected"';
  105. } ?> >07</option>
  106. <option value="8" <?php if ((!$formSent && $thisDay == 8) || ($formSent && $day_start == 8)) {
  107. echo 'selected="selected"';
  108. } ?> >08</option>
  109. <option value="9" <?php if ((!$formSent && $thisDay == 9) || ($formSent && $day_start == 9)) {
  110. echo 'selected="selected"';
  111. } ?> >09</option>
  112. <option value="10" <?php if ((!$formSent && $thisDay == 10) || ($formSent && $day_start == 10)) {
  113. echo 'selected="selected"';
  114. } ?> >10</option>
  115. <option value="11" <?php if ((!$formSent && $thisDay == 11) || ($formSent && $day_start == 11)) {
  116. echo 'selected="selected"';
  117. } ?> >11</option>
  118. <option value="12" <?php if ((!$formSent && $thisDay == 12) || ($formSent && $day_start == 12)) {
  119. echo 'selected="selected"';
  120. } ?> >12</option>
  121. <option value="13" <?php if ((!$formSent && $thisDay == 13) || ($formSent && $day_start == 13)) {
  122. echo 'selected="selected"';
  123. } ?> >13</option>
  124. <option value="14" <?php if ((!$formSent && $thisDay == 14) || ($formSent && $day_start == 14)) {
  125. echo 'selected="selected"';
  126. } ?> >14</option>
  127. <option value="15" <?php if ((!$formSent && $thisDay == 15) || ($formSent && $day_start == 15)) {
  128. echo 'selected="selected"';
  129. } ?> >15</option>
  130. <option value="16" <?php if ((!$formSent && $thisDay == 16) || ($formSent && $day_start == 16)) {
  131. echo 'selected="selected"';
  132. } ?> >16</option>
  133. <option value="17" <?php if ((!$formSent && $thisDay == 17) || ($formSent && $day_start == 17)) {
  134. echo 'selected="selected"';
  135. } ?> >17</option>
  136. <option value="18" <?php if ((!$formSent && $thisDay == 18) || ($formSent && $day_start == 18)) {
  137. echo 'selected="selected"';
  138. } ?> >18</option>
  139. <option value="19" <?php if ((!$formSent && $thisDay == 19) || ($formSent && $day_start == 19)) {
  140. echo 'selected="selected"';
  141. } ?> >19</option>
  142. <option value="20" <?php if ((!$formSent && $thisDay == 20) || ($formSent && $day_start == 20)) {
  143. echo 'selected="selected"';
  144. } ?> >20</option>
  145. <option value="21" <?php if ((!$formSent && $thisDay == 21) || ($formSent && $day_start == 21)) {
  146. echo 'selected="selected"';
  147. } ?> >21</option>
  148. <option value="22" <?php if ((!$formSent && $thisDay == 22) || ($formSent && $day_start == 22)) {
  149. echo 'selected="selected"';
  150. } ?> >22</option>
  151. <option value="23" <?php if ((!$formSent && $thisDay == 23) || ($formSent && $day_start == 23)) {
  152. echo 'selected="selected"';
  153. } ?> >23</option>
  154. <option value="24" <?php if ((!$formSent && $thisDay == 24) || ($formSent && $day_start == 24)) {
  155. echo 'selected="selected"';
  156. } ?> >24</option>
  157. <option value="25" <?php if ((!$formSent && $thisDay == 25) || ($formSent && $day_start == 25)) {
  158. echo 'selected="selected"';
  159. } ?> >25</option>
  160. <option value="26" <?php if ((!$formSent && $thisDay == 26) || ($formSent && $day_start == 26)) {
  161. echo 'selected="selected"';
  162. } ?> >26</option>
  163. <option value="27" <?php if ((!$formSent && $thisDay == 27) || ($formSent && $day_start == 27)) {
  164. echo 'selected="selected"';
  165. } ?> >27</option>
  166. <option value="28" <?php if ((!$formSent && $thisDay == 28) || ($formSent && $day_start == 28)) {
  167. echo 'selected="selected"';
  168. } ?> >28</option>
  169. <option value="29" <?php if ((!$formSent && $thisDay == 29) || ($formSent && $day_start == 29)) {
  170. echo 'selected="selected"';
  171. } ?> >29</option>
  172. <option value="30" <?php if ((!$formSent && $thisDay == 30) || ($formSent && $day_start == 30)) {
  173. echo 'selected="selected"';
  174. } ?> >30</option>
  175. <option value="31" <?php if ((!$formSent && $thisDay == 31) || ($formSent && $day_start == 31)) {
  176. echo 'selected="selected"';
  177. } ?> >31</option>
  178. </select>
  179. /
  180. <select name="month_start">
  181. <option value="1">01</option>
  182. <option value="2" <?php if ((!$formSent && $thisMonth == 2) || ($formSent && $month_start == 2)) {
  183. echo 'selected="selected"';
  184. } ?> >02</option>
  185. <option value="3" <?php if ((!$formSent && $thisMonth == 3) || ($formSent && $month_start == 3)) {
  186. echo 'selected="selected"';
  187. } ?> >03</option>
  188. <option value="4" <?php if ((!$formSent && $thisMonth == 4) || ($formSent && $month_start == 4)) {
  189. echo 'selected="selected"';
  190. } ?> >04</option>
  191. <option value="5" <?php if ((!$formSent && $thisMonth == 5) || ($formSent && $month_start == 5)) {
  192. echo 'selected="selected"';
  193. } ?> >05</option>
  194. <option value="6" <?php if ((!$formSent && $thisMonth == 6) || ($formSent && $month_start == 6)) {
  195. echo 'selected="selected"';
  196. } ?> >06</option>
  197. <option value="7" <?php if ((!$formSent && $thisMonth == 7) || ($formSent && $month_start == 7)) {
  198. echo 'selected="selected"';
  199. } ?> >07</option>
  200. <option value="8" <?php if ((!$formSent && $thisMonth == 8) || ($formSent && $month_start == 8)) {
  201. echo 'selected="selected"';
  202. } ?> >08</option>
  203. <option value="9" <?php if ((!$formSent && $thisMonth == 9) || ($formSent && $month_start == 9)) {
  204. echo 'selected="selected"';
  205. } ?> >09</option>
  206. <option value="10" <?php if ((!$formSent && $thisMonth == 10) || ($formSent && $month_start == 10)) {
  207. echo 'selected="selected"';
  208. } ?> >10</option>
  209. <option value="11" <?php if ((!$formSent && $thisMonth == 11) || ($formSent && $month_start == 11)) {
  210. echo 'selected="selected"';
  211. } ?> >11</option>
  212. <option value="12" <?php if ((!$formSent && $thisMonth == 12) || ($formSent && $month_start == 12)) {
  213. echo 'selected="selected"';
  214. } ?> >12</option>
  215. </select>
  216. /
  217. <select name="year_start">
  218. <?php
  219. for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
  220. ?>
  221. <option value="<?php echo $i; ?>" <?php if ((!$formSent && $thisYear == $i) || ($formSent && $year_start == $i)) {
  222. echo 'selected="selected"';
  223. } ?> ><?php echo $i; ?></option>
  224. <?php
  225. }
  226. ?>
  227. </select>
  228. </div>
  229. <div class="col-md-3"></div>
  230. </div>
  231. <div class="form-group">
  232. <label class="col-sm-3 control-label"><?php echo get_lang('End date'); ?></label>
  233. <div class="col-sm-6">
  234. <select name="day_end">
  235. <option value="0">--</option>
  236. <option value="1">01</option>
  237. <option value="2">02</option>
  238. <option value="3">03</option>
  239. <option value="4">04</option>
  240. <option value="5">05</option>
  241. <option value="6">06</option>
  242. <option value="7">07</option>
  243. <option value="8">08</option>
  244. <option value="9">09</option>
  245. <option value="10">10</option>
  246. <option value="11">11</option>
  247. <option value="12">12</option>
  248. <option value="13">13</option>
  249. <option value="14">14</option>
  250. <option value="15">15</option>
  251. <option value="16">16</option>
  252. <option value="17">17</option>
  253. <option value="18">18</option>
  254. <option value="19">19</option>
  255. <option value="20">20</option>
  256. <option value="21">21</option>
  257. <option value="22">22</option>
  258. <option value="23">23</option>
  259. <option value="24">24</option>
  260. <option value="25">25</option>
  261. <option value="26">26</option>
  262. <option value="27">27</option>
  263. <option value="28">28</option>
  264. <option value="29">29</option>
  265. <option value="30">30</option>
  266. <option value="31">31</option>
  267. </select>
  268. /
  269. <select name="month_end">
  270. <option value="0">--</option>
  271. <option value="1">01</option>
  272. <option value="2">02</option>
  273. <option value="3">03</option>
  274. <option value="4">04</option>
  275. <option value="5">05</option>
  276. <option value="6">06</option>
  277. <option value="7">07</option>
  278. <option value="8">08</option>
  279. <option value="9">09</option>
  280. <option value="10">10</option>
  281. <option value="11">11</option>
  282. <option value="12">12</option>
  283. </select>
  284. /
  285. <select name="year_end">
  286. <option value="0">----</option>
  287. <?php
  288. for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
  289. ?>
  290. <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
  291. <?php
  292. }
  293. ?>
  294. </select>
  295. </div>
  296. <div class="col-md-3">
  297. </div>
  298. </div>
  299. </div>
  300. <div class="form-group">
  301. <div class="col-sm-offset-3 col-sm-6">
  302. <button class="btn btn-success" type="submit" value="<?php echo get_lang('Add category'); ?>"><em class="fa fa-plus"></em> <?php echo get_lang('Add category'); ?></button>
  303. </div>
  304. <div class="col-md-3"></div>
  305. </div>
  306. </form>
  307. </div>
  308. <script>
  309. function setDisable(select) {
  310. document.form.day_start.disabled = (select.checked) ? true : false;
  311. document.form.month_start.disabled = (select.checked) ? true : false;
  312. document.form.year_start.disabled = (select.checked) ? true : false;
  313. document.form.day_end.disabled = (select.checked) ? true : false;
  314. document.form.month_end.disabled = (select.checked) ? true : false;
  315. document.form.year_end.disabled = (select.checked) ? true : false;
  316. }
  317. </script>
  318. <?php
  319. Display::display_footer();