session_category_add.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. * @todo use formvalidator for the form
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $xajax = new xajax();
  10. $xajax->registerFunction('search_coachs');
  11. // setting the section (for the tabs)
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script(true);
  14. $formSent = 0;
  15. $errorMsg = '';
  16. //$interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  17. $interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
  18. $interbreadcrumb[] = array('url' => "session_category_list.php", "name" => get_lang('ListSessionCategory'));
  19. // Database Table Definitions
  20. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  21. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  22. if (isset($_POST['formSent']) && $_POST['formSent']) {
  23. $formSent = 1;
  24. $name = $_POST['name'];
  25. $year_start = $_POST['year_start'];
  26. $month_start = $_POST['month_start'];
  27. $day_start = $_POST['day_start'];
  28. $year_end = $_POST['year_end'];
  29. $month_end = $_POST['month_end'];
  30. $day_end = $_POST['day_end'];
  31. $return = SessionManager::create_category_session(
  32. $name,
  33. $year_start,
  34. $month_start,
  35. $day_start,
  36. $year_end,
  37. $month_end,
  38. $day_end
  39. );
  40. if ($return == strval(intval($return))) {
  41. Display::addFlash(Display::return_message(get_lang('SessionCategoryAdded')));
  42. header('Location: session_category_list.php');
  43. exit();
  44. }
  45. }
  46. $thisYear = date('Y');
  47. $thisMonth = date('m');
  48. $thisDay = date('d');
  49. $tool_name = get_lang('AddACategory');
  50. //display the header
  51. Display::display_header($tool_name);
  52. if (!empty($return)) {
  53. echo Display::return_message($return, 'error', false);
  54. }
  55. ?>
  56. <div class="row">
  57. <div class="col-md-12">
  58. <form method="post" name="form" action="<?php echo api_get_self(); ?>" class="form-horizontal">
  59. <input type="hidden" name="formSent" value="1">
  60. <legend><?php echo $tool_name; ?></legend>
  61. <div class="form-group">
  62. <label class="col-sm-3 control-label"><?php echo get_lang('SessionCategoryName') ?></label>
  63. <div class="col-sm-6">
  64. <input type="text" class="form-control" name="name" placeholder="<?php echo get_lang('Category') ?>" size="50" maxlength="50" value="<?php if ($formSent) echo api_htmlentities($name, ENT_QUOTES, $charset); ?>">
  65. </div>
  66. <div class="col-md-3"></div>
  67. </div>
  68. <div class="form-group">
  69. <div class="col-sm-offset-3 col-sm-6">
  70. <?php echo get_lang('TheTimeLimitsAreReferential'); ?> <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('AddTimeLimit') ?></a>
  71. </div>
  72. <div class="col-md-3"></div>
  73. </div>
  74. <div style="display: none" id="options">
  75. <div class="form-group">
  76. <label class="col-sm-3 control-label"><?php echo get_lang('DateStart') ?></label>
  77. <div class="col-sm-6">
  78. <select name="day_start">
  79. <option value="1">01</option>
  80. <option value="2" <?php if ((!$formSent && $thisDay == 2) || ($formSent && $day_start == 2)) echo 'selected="selected"'; ?> >02</option>
  81. <option value="3" <?php if ((!$formSent && $thisDay == 3) || ($formSent && $day_start == 3)) echo 'selected="selected"'; ?> >03</option>
  82. <option value="4" <?php if ((!$formSent && $thisDay == 4) || ($formSent && $day_start == 4)) echo 'selected="selected"'; ?> >04</option>
  83. <option value="5" <?php if ((!$formSent && $thisDay == 5) || ($formSent && $day_start == 5)) echo 'selected="selected"'; ?> >05</option>
  84. <option value="6" <?php if ((!$formSent && $thisDay == 6) || ($formSent && $day_start == 6)) echo 'selected="selected"'; ?> >06</option>
  85. <option value="7" <?php if ((!$formSent && $thisDay == 7) || ($formSent && $day_start == 7)) echo 'selected="selected"'; ?> >07</option>
  86. <option value="8" <?php if ((!$formSent && $thisDay == 8) || ($formSent && $day_start == 8)) echo 'selected="selected"'; ?> >08</option>
  87. <option value="9" <?php if ((!$formSent && $thisDay == 9) || ($formSent && $day_start == 9)) echo 'selected="selected"'; ?> >09</option>
  88. <option value="10" <?php if ((!$formSent && $thisDay == 10) || ($formSent && $day_start == 10)) echo 'selected="selected"'; ?> >10</option>
  89. <option value="11" <?php if ((!$formSent && $thisDay == 11) || ($formSent && $day_start == 11)) echo 'selected="selected"'; ?> >11</option>
  90. <option value="12" <?php if ((!$formSent && $thisDay == 12) || ($formSent && $day_start == 12)) echo 'selected="selected"'; ?> >12</option>
  91. <option value="13" <?php if ((!$formSent && $thisDay == 13) || ($formSent && $day_start == 13)) echo 'selected="selected"'; ?> >13</option>
  92. <option value="14" <?php if ((!$formSent && $thisDay == 14) || ($formSent && $day_start == 14)) echo 'selected="selected"'; ?> >14</option>
  93. <option value="15" <?php if ((!$formSent && $thisDay == 15) || ($formSent && $day_start == 15)) echo 'selected="selected"'; ?> >15</option>
  94. <option value="16" <?php if ((!$formSent && $thisDay == 16) || ($formSent && $day_start == 16)) echo 'selected="selected"'; ?> >16</option>
  95. <option value="17" <?php if ((!$formSent && $thisDay == 17) || ($formSent && $day_start == 17)) echo 'selected="selected"'; ?> >17</option>
  96. <option value="18" <?php if ((!$formSent && $thisDay == 18) || ($formSent && $day_start == 18)) echo 'selected="selected"'; ?> >18</option>
  97. <option value="19" <?php if ((!$formSent && $thisDay == 19) || ($formSent && $day_start == 19)) echo 'selected="selected"'; ?> >19</option>
  98. <option value="20" <?php if ((!$formSent && $thisDay == 20) || ($formSent && $day_start == 20)) echo 'selected="selected"'; ?> >20</option>
  99. <option value="21" <?php if ((!$formSent && $thisDay == 21) || ($formSent && $day_start == 21)) echo 'selected="selected"'; ?> >21</option>
  100. <option value="22" <?php if ((!$formSent && $thisDay == 22) || ($formSent && $day_start == 22)) echo 'selected="selected"'; ?> >22</option>
  101. <option value="23" <?php if ((!$formSent && $thisDay == 23) || ($formSent && $day_start == 23)) echo 'selected="selected"'; ?> >23</option>
  102. <option value="24" <?php if ((!$formSent && $thisDay == 24) || ($formSent && $day_start == 24)) echo 'selected="selected"'; ?> >24</option>
  103. <option value="25" <?php if ((!$formSent && $thisDay == 25) || ($formSent && $day_start == 25)) echo 'selected="selected"'; ?> >25</option>
  104. <option value="26" <?php if ((!$formSent && $thisDay == 26) || ($formSent && $day_start == 26)) echo 'selected="selected"'; ?> >26</option>
  105. <option value="27" <?php if ((!$formSent && $thisDay == 27) || ($formSent && $day_start == 27)) echo 'selected="selected"'; ?> >27</option>
  106. <option value="28" <?php if ((!$formSent && $thisDay == 28) || ($formSent && $day_start == 28)) echo 'selected="selected"'; ?> >28</option>
  107. <option value="29" <?php if ((!$formSent && $thisDay == 29) || ($formSent && $day_start == 29)) echo 'selected="selected"'; ?> >29</option>
  108. <option value="30" <?php if ((!$formSent && $thisDay == 30) || ($formSent && $day_start == 30)) echo 'selected="selected"'; ?> >30</option>
  109. <option value="31" <?php if ((!$formSent && $thisDay == 31) || ($formSent && $day_start == 31)) echo 'selected="selected"'; ?> >31</option>
  110. </select>
  111. /
  112. <select name="month_start">
  113. <option value="1">01</option>
  114. <option value="2" <?php if ((!$formSent && $thisMonth == 2) || ($formSent && $month_start == 2)) echo 'selected="selected"'; ?> >02</option>
  115. <option value="3" <?php if ((!$formSent && $thisMonth == 3) || ($formSent && $month_start == 3)) echo 'selected="selected"'; ?> >03</option>
  116. <option value="4" <?php if ((!$formSent && $thisMonth == 4) || ($formSent && $month_start == 4)) echo 'selected="selected"'; ?> >04</option>
  117. <option value="5" <?php if ((!$formSent && $thisMonth == 5) || ($formSent && $month_start == 5)) echo 'selected="selected"'; ?> >05</option>
  118. <option value="6" <?php if ((!$formSent && $thisMonth == 6) || ($formSent && $month_start == 6)) echo 'selected="selected"'; ?> >06</option>
  119. <option value="7" <?php if ((!$formSent && $thisMonth == 7) || ($formSent && $month_start == 7)) echo 'selected="selected"'; ?> >07</option>
  120. <option value="8" <?php if ((!$formSent && $thisMonth == 8) || ($formSent && $month_start == 8)) echo 'selected="selected"'; ?> >08</option>
  121. <option value="9" <?php if ((!$formSent && $thisMonth == 9) || ($formSent && $month_start == 9)) echo 'selected="selected"'; ?> >09</option>
  122. <option value="10" <?php if ((!$formSent && $thisMonth == 10) || ($formSent && $month_start == 10)) echo 'selected="selected"'; ?> >10</option>
  123. <option value="11" <?php if ((!$formSent && $thisMonth == 11) || ($formSent && $month_start == 11)) echo 'selected="selected"'; ?> >11</option>
  124. <option value="12" <?php if ((!$formSent && $thisMonth == 12) || ($formSent && $month_start == 12)) echo 'selected="selected"'; ?> >12</option>
  125. </select>
  126. /
  127. <select name="year_start">
  128. <?php
  129. for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
  130. ?>
  131. <option value="<?php echo $i; ?>" <?php if ((!$formSent && $thisYear == $i) || ($formSent && $year_start == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
  132. <?php
  133. }
  134. ?>
  135. </select>
  136. </div>
  137. <div class="col-md-3"></div>
  138. </div>
  139. <div class="form-group">
  140. <label class="col-sm-3 control-label"><?php echo get_lang('DateEnd') ?></label>
  141. <div class="col-sm-6">
  142. <select name="day_end">
  143. <option value="0">--</option>
  144. <option value="1">01</option>
  145. <option value="2">02</option>
  146. <option value="3">03</option>
  147. <option value="4">04</option>
  148. <option value="5">05</option>
  149. <option value="6">06</option>
  150. <option value="7">07</option>
  151. <option value="8">08</option>
  152. <option value="9">09</option>
  153. <option value="10">10</option>
  154. <option value="11">11</option>
  155. <option value="12">12</option>
  156. <option value="13">13</option>
  157. <option value="14">14</option>
  158. <option value="15">15</option>
  159. <option value="16">16</option>
  160. <option value="17">17</option>
  161. <option value="18">18</option>
  162. <option value="19">19</option>
  163. <option value="20">20</option>
  164. <option value="21">21</option>
  165. <option value="22">22</option>
  166. <option value="23">23</option>
  167. <option value="24">24</option>
  168. <option value="25">25</option>
  169. <option value="26">26</option>
  170. <option value="27">27</option>
  171. <option value="28">28</option>
  172. <option value="29">29</option>
  173. <option value="30">30</option>
  174. <option value="31">31</option>
  175. </select>
  176. /
  177. <select name="month_end">
  178. <option value="0">--</option>
  179. <option value="1">01</option>
  180. <option value="2">02</option>
  181. <option value="3">03</option>
  182. <option value="4">04</option>
  183. <option value="5">05</option>
  184. <option value="6">06</option>
  185. <option value="7">07</option>
  186. <option value="8">08</option>
  187. <option value="9">09</option>
  188. <option value="10">10</option>
  189. <option value="11">11</option>
  190. <option value="12">12</option>
  191. </select>
  192. /
  193. <select name="year_end">
  194. <option value="0">----</option>
  195. <?php
  196. for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
  197. ?>
  198. <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
  199. <?php
  200. }
  201. ?>
  202. </select>
  203. </div>
  204. <div class="col-md-3">
  205. </div>
  206. </div>
  207. </div>
  208. <div class="form-group">
  209. <div class="col-sm-offset-3 col-sm-6">
  210. <button class="btn btn-success" type="submit" value="<?php echo get_lang('AddACategory') ?>"><em class="fa fa-plus"></em> <?php echo get_lang('AddACategory') ?></button>
  211. </div>
  212. <div class="col-md-3"></div>
  213. </div>
  214. </form>
  215. </div>
  216. <script type="text/javascript">
  217. function setDisable(select) {
  218. document.form.day_start.disabled = (select.checked) ? true : false;
  219. document.form.month_start.disabled = (select.checked) ? true : false;
  220. document.form.year_start.disabled = (select.checked) ? true : false;
  221. document.form.day_end.disabled = (select.checked) ? true : false;
  222. document.form.month_end.disabled = (select.checked) ? true : false;
  223. document.form.year_end.disabled = (select.checked) ? true : false;
  224. }
  225. </script>
  226. <?php
  227. Display::display_footer();