session_add.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. // name of the language file that needs to be included
  3. $language_file='admin';
  4. $cidReset=true;
  5. include('../inc/global.inc.php');
  6. api_protect_admin_script();
  7. $formSent=0;
  8. $errorMsg='';
  9. // Database Table Definitions
  10. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  11. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  12. $tool_name = get_lang('AddSession');
  13. $interbreadcrumb[]=array("url" => "index.php","name" => get_lang('AdministrationTools'));
  14. $interbreadcrumb[]=array("url" => "session_list.php","name" => get_lang('SessionList'));
  15. if($_POST['formSent'])
  16. {
  17. $formSent=1;
  18. $name=trim(stripslashes($_POST['name']));
  19. $year_start=intval($_POST['year_start']);
  20. $month_start=intval($_POST['month_start']);
  21. $day_start=intval($_POST['day_start']);
  22. $year_end=intval($_POST['year_end']);
  23. $month_end=intval($_POST['month_end']);
  24. $day_end=intval($_POST['day_end']);
  25. $id_coach=intval($_POST['id_coach']);
  26. if(empty($_POST['nolimit'])){
  27. $date_start="$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
  28. $date_end="$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
  29. }
  30. else {
  31. $date_start="000-00-00";
  32. $date_end="000-00-00";
  33. }
  34. if(empty($name)) $errorMsg=get_lang('SessionNameIsRequired');
  35. elseif(empty($_POST['nolimit']) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start,$day_start,$year_start))) $errorMsg="Veuillez introduire une date de début valide !";
  36. elseif(empty($_POST['nolimit']) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end))) $errorMsg="Veuillez introduire une date de fin valide !";
  37. elseif(empty($_POST['nolimit']) && $date_start >= $date_end) $errorMsg="La date de fin doit être postérieure à la date de début !";
  38. else
  39. {
  40. $rs = api_sql_query("SELECT 1 FROM $tbl_session WHERE name='".addslashes($name)."'");
  41. if(mysql_num_rows($rs)){
  42. $errorMsg = get_lang('SessionNameSoonExists');
  43. }
  44. else {
  45. api_sql_query("INSERT INTO $tbl_session(name,date_start,date_end,id_coach) VALUES('".addslashes($name)."','$date_start','$date_end','$id_coach')",__FILE__,__LINE__);
  46. $id_session=mysql_insert_id();
  47. header('Location: add_courses_to_session.php?id_session='.$id_session.'&add=true');
  48. exit();
  49. }
  50. }
  51. }
  52. $sql="SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE status='1' ORDER BY lastname,firstname,username";
  53. $result=api_sql_query($sql,__FILE__,__LINE__);
  54. $Coaches=api_store_result($result);
  55. $thisYear=date('Y');
  56. $thisMonth=date('m');
  57. $thisDay=date('d');
  58. Display::display_header($tool_name);
  59. api_display_tool_title($tool_name);
  60. ?>
  61. <form method="post" name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" style="margin:0px;">
  62. <input type="hidden" name="formSent" value="1">
  63. <table border="0" cellpadding="5" cellspacing="0" width="550">
  64. <?php
  65. if(!empty($errorMsg))
  66. {
  67. ?>
  68. <tr>
  69. <td colspan="2">
  70. <?php
  71. Display::display_normal_message($errorMsg);
  72. ?>
  73. </td>
  74. </tr>
  75. <?php
  76. }
  77. ?>
  78. <tr>
  79. <td width="30%"><?php echo get_lang('SessionName') ?>&nbsp;&nbsp;</td>
  80. <td width="70%"><input type="text" name="name" size="50" maxlength="50" value="<?php if($formSent) echo htmlentities($name); ?>"></td>
  81. </tr>
  82. <tr>
  83. <td width="30%"><?php echo get_lang('CoachName') ?>&nbsp;&nbsp;</td>
  84. <td width="70%"><select name="id_coach" value="true" style="width:250px;">
  85. <option value="0">Aucun</option>
  86. <?php
  87. foreach($Coaches as $enreg)
  88. {
  89. ?>
  90. <option value="<?php echo $enreg['user_id']; ?>" <?php if($sent && $enreg['user_id'] == $id_coach) echo 'selected="selected"'; ?>><?php echo $enreg['lastname'].' '.$enreg['firstname'].' ('.$enreg['username'].')'; ?></option>
  91. <?php
  92. }
  93. unset($Coaches);
  94. ?>
  95. </select></td>
  96. </tr>
  97. <tr>
  98. <td width="30%"><?php echo get_lang('NoTimeLimits') ?></td>
  99. <td width="70%">
  100. <input type="checkbox" name="nolimit" onChange="setDisable(this)" />
  101. </td>
  102. <tr>
  103. <td width="30%"><?php echo get_lang('DateStart') ?>&nbsp;&nbsp;</td>
  104. <td width="70%">
  105. <select name="day_start">
  106. <option value="1">01</option>
  107. <option value="2" <?php if((!$formSent && $thisDay == 2) || ($formSent && $day_start == 2)) echo 'selected="selected"'; ?> >02</option>
  108. <option value="3" <?php if((!$formSent && $thisDay == 3) || ($formSent && $day_start == 3)) echo 'selected="selected"'; ?> >03</option>
  109. <option value="4" <?php if((!$formSent && $thisDay == 4) || ($formSent && $day_start == 4)) echo 'selected="selected"'; ?> >04</option>
  110. <option value="5" <?php if((!$formSent && $thisDay == 5) || ($formSent && $day_start == 5)) echo 'selected="selected"'; ?> >05</option>
  111. <option value="6" <?php if((!$formSent && $thisDay == 6) || ($formSent && $day_start == 6)) echo 'selected="selected"'; ?> >06</option>
  112. <option value="7" <?php if((!$formSent && $thisDay == 7) || ($formSent && $day_start == 7)) echo 'selected="selected"'; ?> >07</option>
  113. <option value="8" <?php if((!$formSent && $thisDay == 8) || ($formSent && $day_start == 8)) echo 'selected="selected"'; ?> >08</option>
  114. <option value="9" <?php if((!$formSent && $thisDay == 9) || ($formSent && $day_start == 9)) echo 'selected="selected"'; ?> >09</option>
  115. <option value="10" <?php if((!$formSent && $thisDay == 10) || ($formSent && $day_start == 10)) echo 'selected="selected"'; ?> >10</option>
  116. <option value="11" <?php if((!$formSent && $thisDay == 11) || ($formSent && $day_start == 11)) echo 'selected="selected"'; ?> >11</option>
  117. <option value="12" <?php if((!$formSent && $thisDay == 12) || ($formSent && $day_start == 12)) echo 'selected="selected"'; ?> >12</option>
  118. <option value="13" <?php if((!$formSent && $thisDay == 13) || ($formSent && $day_start == 13)) echo 'selected="selected"'; ?> >13</option>
  119. <option value="14" <?php if((!$formSent && $thisDay == 14) || ($formSent && $day_start == 14)) echo 'selected="selected"'; ?> >14</option>
  120. <option value="15" <?php if((!$formSent && $thisDay == 15) || ($formSent && $day_start == 15)) echo 'selected="selected"'; ?> >15</option>
  121. <option value="16" <?php if((!$formSent && $thisDay == 16) || ($formSent && $day_start == 16)) echo 'selected="selected"'; ?> >16</option>
  122. <option value="17" <?php if((!$formSent && $thisDay == 17) || ($formSent && $day_start == 17)) echo 'selected="selected"'; ?> >17</option>
  123. <option value="18" <?php if((!$formSent && $thisDay == 18) || ($formSent && $day_start == 18)) echo 'selected="selected"'; ?> >18</option>
  124. <option value="19" <?php if((!$formSent && $thisDay == 19) || ($formSent && $day_start == 19)) echo 'selected="selected"'; ?> >19</option>
  125. <option value="20" <?php if((!$formSent && $thisDay == 20) || ($formSent && $day_start == 20)) echo 'selected="selected"'; ?> >20</option>
  126. <option value="21" <?php if((!$formSent && $thisDay == 21) || ($formSent && $day_start == 21)) echo 'selected="selected"'; ?> >21</option>
  127. <option value="22" <?php if((!$formSent && $thisDay == 22) || ($formSent && $day_start == 22)) echo 'selected="selected"'; ?> >22</option>
  128. <option value="23" <?php if((!$formSent && $thisDay == 23) || ($formSent && $day_start == 23)) echo 'selected="selected"'; ?> >23</option>
  129. <option value="24" <?php if((!$formSent && $thisDay == 24) || ($formSent && $day_start == 24)) echo 'selected="selected"'; ?> >24</option>
  130. <option value="25" <?php if((!$formSent && $thisDay == 25) || ($formSent && $day_start == 25)) echo 'selected="selected"'; ?> >25</option>
  131. <option value="26" <?php if((!$formSent && $thisDay == 26) || ($formSent && $day_start == 26)) echo 'selected="selected"'; ?> >26</option>
  132. <option value="27" <?php if((!$formSent && $thisDay == 27) || ($formSent && $day_start == 27)) echo 'selected="selected"'; ?> >27</option>
  133. <option value="28" <?php if((!$formSent && $thisDay == 28) || ($formSent && $day_start == 28)) echo 'selected="selected"'; ?> >28</option>
  134. <option value="29" <?php if((!$formSent && $thisDay == 29) || ($formSent && $day_start == 29)) echo 'selected="selected"'; ?> >29</option>
  135. <option value="30" <?php if((!$formSent && $thisDay == 30) || ($formSent && $day_start == 30)) echo 'selected="selected"'; ?> >30</option>
  136. <option value="31" <?php if((!$formSent && $thisDay == 31) || ($formSent && $day_start == 31)) echo 'selected="selected"'; ?> >31</option>
  137. </select>
  138. /
  139. <select name="month_start">
  140. <option value="1">01</option>
  141. <option value="2" <?php if((!$formSent && $thisMonth == 2) || ($formSent && $month_start == 2)) echo 'selected="selected"'; ?> >02</option>
  142. <option value="3" <?php if((!$formSent && $thisMonth == 3) || ($formSent && $month_start == 3)) echo 'selected="selected"'; ?> >03</option>
  143. <option value="4" <?php if((!$formSent && $thisMonth == 4) || ($formSent && $month_start == 4)) echo 'selected="selected"'; ?> >04</option>
  144. <option value="5" <?php if((!$formSent && $thisMonth == 5) || ($formSent && $month_start == 5)) echo 'selected="selected"'; ?> >05</option>
  145. <option value="6" <?php if((!$formSent && $thisMonth == 6) || ($formSent && $month_start == 6)) echo 'selected="selected"'; ?> >06</option>
  146. <option value="7" <?php if((!$formSent && $thisMonth == 7) || ($formSent && $month_start == 7)) echo 'selected="selected"'; ?> >07</option>
  147. <option value="8" <?php if((!$formSent && $thisMonth == 8) || ($formSent && $month_start == 8)) echo 'selected="selected"'; ?> >08</option>
  148. <option value="9" <?php if((!$formSent && $thisMonth == 9) || ($formSent && $month_start == 9)) echo 'selected="selected"'; ?> >09</option>
  149. <option value="10" <?php if((!$formSent && $thisMonth == 10) || ($formSent && $month_start == 10)) echo 'selected="selected"'; ?> >10</option>
  150. <option value="11" <?php if((!$formSent && $thisMonth == 11) || ($formSent && $month_start == 11)) echo 'selected="selected"'; ?> >11</option>
  151. <option value="12" <?php if((!$formSent && $thisMonth == 12) || ($formSent && $month_start == 12)) echo 'selected="selected"'; ?> >12</option>
  152. </select>
  153. /
  154. <select name="year_start">
  155. <?php
  156. for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
  157. {
  158. ?>
  159. <option value="<?php echo $i; ?>" <?php if((!$formSent && $thisYear == $i) || ($formSent && $year_start == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
  160. <?php
  161. }
  162. ?>
  163. </select>
  164. </td>
  165. </tr>
  166. <tr>
  167. <td width="30%"><?php echo get_lang('DateEnd') ?>&nbsp;&nbsp;</td>
  168. <td width="70%">
  169. <select name="day_end">
  170. <option value="1">01</option>
  171. <option value="2" <?php if((!$formSent && $thisDay == 2) || ($formSent && $day_end == 2)) echo 'selected="selected"'; ?> >02</option>
  172. <option value="3" <?php if((!$formSent && $thisDay == 3) || ($formSent && $day_end == 3)) echo 'selected="selected"'; ?> >03</option>
  173. <option value="4" <?php if((!$formSent && $thisDay == 4) || ($formSent && $day_end == 4)) echo 'selected="selected"'; ?> >04</option>
  174. <option value="5" <?php if((!$formSent && $thisDay == 5) || ($formSent && $day_end == 5)) echo 'selected="selected"'; ?> >05</option>
  175. <option value="6" <?php if((!$formSent && $thisDay == 6) || ($formSent && $day_end == 6)) echo 'selected="selected"'; ?> >06</option>
  176. <option value="7" <?php if((!$formSent && $thisDay == 7) || ($formSent && $day_end == 7)) echo 'selected="selected"'; ?> >07</option>
  177. <option value="8" <?php if((!$formSent && $thisDay == 8) || ($formSent && $day_end == 8)) echo 'selected="selected"'; ?> >08</option>
  178. <option value="9" <?php if((!$formSent && $thisDay == 9) || ($formSent && $day_end == 9)) echo 'selected="selected"'; ?> >09</option>
  179. <option value="10" <?php if((!$formSent && $thisDay == 10) || ($formSent && $day_end == 10)) echo 'selected="selected"'; ?> >10</option>
  180. <option value="11" <?php if((!$formSent && $thisDay == 11) || ($formSent && $day_end == 11)) echo 'selected="selected"'; ?> >11</option>
  181. <option value="12" <?php if((!$formSent && $thisDay == 12) || ($formSent && $day_end == 12)) echo 'selected="selected"'; ?> >12</option>
  182. <option value="13" <?php if((!$formSent && $thisDay == 13) || ($formSent && $day_end == 13)) echo 'selected="selected"'; ?> >13</option>
  183. <option value="14" <?php if((!$formSent && $thisDay == 14) || ($formSent && $day_end == 14)) echo 'selected="selected"'; ?> >14</option>
  184. <option value="15" <?php if((!$formSent && $thisDay == 15) || ($formSent && $day_end == 15)) echo 'selected="selected"'; ?> >15</option>
  185. <option value="16" <?php if((!$formSent && $thisDay == 16) || ($formSent && $day_end == 16)) echo 'selected="selected"'; ?> >16</option>
  186. <option value="17" <?php if((!$formSent && $thisDay == 17) || ($formSent && $day_end == 17)) echo 'selected="selected"'; ?> >17</option>
  187. <option value="18" <?php if((!$formSent && $thisDay == 18) || ($formSent && $day_end == 18)) echo 'selected="selected"'; ?> >18</option>
  188. <option value="19" <?php if((!$formSent && $thisDay == 19) || ($formSent && $day_end == 19)) echo 'selected="selected"'; ?> >19</option>
  189. <option value="20" <?php if((!$formSent && $thisDay == 20) || ($formSent && $day_end == 20)) echo 'selected="selected"'; ?> >20</option>
  190. <option value="21" <?php if((!$formSent && $thisDay == 21) || ($formSent && $day_end == 21)) echo 'selected="selected"'; ?> >21</option>
  191. <option value="22" <?php if((!$formSent && $thisDay == 22) || ($formSent && $day_end == 22)) echo 'selected="selected"'; ?> >22</option>
  192. <option value="23" <?php if((!$formSent && $thisDay == 23) || ($formSent && $day_end == 23)) echo 'selected="selected"'; ?> >23</option>
  193. <option value="24" <?php if((!$formSent && $thisDay == 24) || ($formSent && $day_end == 24)) echo 'selected="selected"'; ?> >24</option>
  194. <option value="25" <?php if((!$formSent && $thisDay == 25) || ($formSent && $day_end == 25)) echo 'selected="selected"'; ?> >25</option>
  195. <option value="26" <?php if((!$formSent && $thisDay == 26) || ($formSent && $day_end == 26)) echo 'selected="selected"'; ?> >26</option>
  196. <option value="27" <?php if((!$formSent && $thisDay == 27) || ($formSent && $day_end == 27)) echo 'selected="selected"'; ?> >27</option>
  197. <option value="28" <?php if((!$formSent && $thisDay == 28) || ($formSent && $day_end == 28)) echo 'selected="selected"'; ?> >28</option>
  198. <option value="29" <?php if((!$formSent && $thisDay == 29) || ($formSent && $day_end == 29)) echo 'selected="selected"'; ?> >29</option>
  199. <option value="30" <?php if((!$formSent && $thisDay == 30) || ($formSent && $day_end == 30)) echo 'selected="selected"'; ?> >30</option>
  200. <option value="31" <?php if((!$formSent && $thisDay == 31) || ($formSent && $day_end == 31)) echo 'selected="selected"'; ?> >31</option>
  201. </select>
  202. /
  203. <select name="month_end">
  204. <option value="1">01</option>
  205. <option value="2" <?php if((!$formSent && $thisMonth == 2) || ($formSent && $month_end == 2)) echo 'selected="selected"'; ?> >02</option>
  206. <option value="3" <?php if((!$formSent && $thisMonth == 3) || ($formSent && $month_end == 3)) echo 'selected="selected"'; ?> >03</option>
  207. <option value="4" <?php if((!$formSent && $thisMonth == 4) || ($formSent && $month_end == 4)) echo 'selected="selected"'; ?> >04</option>
  208. <option value="5" <?php if((!$formSent && $thisMonth == 5) || ($formSent && $month_end == 5)) echo 'selected="selected"'; ?> >05</option>
  209. <option value="6" <?php if((!$formSent && $thisMonth == 6) || ($formSent && $month_end == 6)) echo 'selected="selected"'; ?> >06</option>
  210. <option value="7" <?php if((!$formSent && $thisMonth == 7) || ($formSent && $month_end == 7)) echo 'selected="selected"'; ?> >07</option>
  211. <option value="8" <?php if((!$formSent && $thisMonth == 8) || ($formSent && $month_end == 8)) echo 'selected="selected"'; ?> >08</option>
  212. <option value="9" <?php if((!$formSent && $thisMonth == 9) || ($formSent && $month_end == 9)) echo 'selected="selected"'; ?> >09</option>
  213. <option value="10" <?php if((!$formSent && $thisMonth == 10) || ($formSent && $month_end == 10)) echo 'selected="selected"'; ?> >10</option>
  214. <option value="11" <?php if((!$formSent && $thisMonth == 11) || ($formSent && $month_end == 11)) echo 'selected="selected"'; ?> >11</option>
  215. <option value="12" <?php if((!$formSent && $thisMonth == 12) || ($formSent && $month_end == 12)) echo 'selected="selected"'; ?> >12</option>
  216. </select>
  217. /
  218. <select name="year_end">
  219. <?php
  220. for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
  221. {
  222. ?>
  223. <option value="<?php echo $i; ?>" <?php if((!$formSent && ($thisYear+1) == $i) || ($formSent && $year_end == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
  224. <?php
  225. }
  226. ?>
  227. </select>
  228. </td>
  229. </tr>
  230. <tr>
  231. <td>&nbsp;</td>
  232. <td><input type="submit" value="<?php echo get_lang('NextStep') ?>"></td>
  233. </tr>
  234. </table>
  235. </form>
  236. <script type="text/javascript">
  237. function setDisable(select){
  238. document.form.day_start.disabled = (select.checked) ? true : false;
  239. document.form.month_start.disabled = (select.checked) ? true : false;
  240. document.form.year_start.disabled = (select.checked) ? true : false;
  241. document.form.day_end.disabled = (select.checked) ? true : false;
  242. document.form.month_end.disabled = (select.checked) ? true : false;
  243. document.form.year_end.disabled = (select.checked) ? true : false;
  244. }
  245. </script>
  246. <?php
  247. Display::display_footer();
  248. ?>