session_add.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. require_once ('../inc/lib/xajax/xajax.inc.php');
  7. $xajax = new xajax();
  8. //$xajax->debugOn();
  9. $xajax -> registerFunction ('search_coachs');
  10. // setting the section (for the tabs)
  11. $this_section=SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. $formSent=0;
  14. $errorMsg='';
  15. // Database Table Definitions
  16. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  17. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  18. function search_coachs($needle)
  19. {
  20. global $tbl_user;
  21. $xajax_response = new XajaxResponse();
  22. $return = '';
  23. if(!empty($needle))
  24. {
  25. // search users where username or firstname or lastname begins likes $needle
  26. $sql = 'SELECT username, lastname, firstname FROM '.$tbl_user.' user
  27. WHERE (username LIKE "'.$needle.'%"
  28. OR firstname LIKE "'.$needle.'%"
  29. OR lastname LIKE "'.$needle.'%")
  30. AND status=1
  31. ORDER BY lastname, firstname, username
  32. LIMIT 10';
  33. $rs = api_sql_query($sql, __FILE__, __LINE__);
  34. while($user = Database :: fetch_array($rs))
  35. {
  36. $return .= '<a href="#" onclick="fill_coach_field(\''.$user['username'].'\')">'.$user['firstname'].' '.$user['lastname'].' ('.$user['username'].')</a><br />';
  37. }
  38. }
  39. $xajax_response -> addAssign('ajax_list_coachs','innerHTML',utf8_encode($return));
  40. return $xajax_response;
  41. }
  42. $xajax -> processRequests();
  43. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  44. $htmlHeadXtra[] = '
  45. <script type="text/javascript">
  46. function fill_coach_field (username) {
  47. document.getElementById("coach_username").value = username;
  48. document.getElementById("ajax_list_coachs").innerHTML = "";
  49. }
  50. </script>';
  51. $tool_name = get_lang('AddSession');
  52. $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  53. $interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang('SessionList'));
  54. if($_POST['formSent'])
  55. {
  56. $formSent=1;
  57. $name=trim(stripslashes($_POST['name']));
  58. $year_start=intval($_POST['year_start']);
  59. $month_start=intval($_POST['month_start']);
  60. $day_start=intval($_POST['day_start']);
  61. $year_end=intval($_POST['year_end']);
  62. $month_end=intval($_POST['month_end']);
  63. $day_end=intval($_POST['day_end']);
  64. $sql = 'SELECT user_id FROM '.$tbl_user.' WHERE username="'.Database::escape_string($_POST['coach_username']).'"';
  65. $rs = api_sql_query($sql, __FILE__, __LINE__);
  66. $id_coach = mysql_result($rs,0,'user_id');
  67. if(empty($_POST['nolimit'])){
  68. $date_start="$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
  69. $date_end="$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
  70. }
  71. else {
  72. $date_start="000-00-00";
  73. $date_end="000-00-00";
  74. }
  75. if(empty($name)) $errorMsg=get_lang('SessionNameIsRequired');
  76. elseif(empty($_POST['nolimit']) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start,$day_start,$year_start))) $errorMsg=get_lang('InvalidStartDate');
  77. elseif(empty($_POST['nolimit']) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end))) $errorMsg=get_lang('InvalidEndDate');
  78. elseif(empty($_POST['nolimit']) && $date_start >= $date_end) $errorMsg=get_lang('StartDateShouldBeBeforeEndDate');
  79. else
  80. {
  81. $rs = api_sql_query("SELECT 1 FROM $tbl_session WHERE name='".addslashes($name)."'");
  82. if(mysql_num_rows($rs)){
  83. $errorMsg = get_lang('SessionNameSoonExists');
  84. }
  85. else {
  86. 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__);
  87. $id_session=mysql_insert_id();
  88. header('Location: add_courses_to_session.php?id_session='.$id_session.'&add=true');
  89. exit();
  90. }
  91. }
  92. }
  93. $thisYear=date('Y');
  94. $thisMonth=date('m');
  95. $thisDay=date('d');
  96. Display::display_header($tool_name);
  97. api_display_tool_title($tool_name);
  98. ?>
  99. <form method="post" name="form" action="<?php echo api_get_self(); ?>" style="margin:0px;">
  100. <input type="hidden" name="formSent" value="1">
  101. <table border="0" cellpadding="5" cellspacing="0" width="550">
  102. <?php
  103. if(!empty($errorMsg))
  104. {
  105. ?>
  106. <tr>
  107. <td colspan="2">
  108. <?php
  109. Display::display_normal_message($errorMsg);
  110. ?>
  111. </td>
  112. </tr>
  113. <?php
  114. }
  115. ?>
  116. <tr>
  117. <td width="30%"><?php echo get_lang('SessionName') ?>&nbsp;&nbsp;</td>
  118. <td width="70%"><input type="text" name="name" size="50" maxlength="50" value="<?php if($formSent) echo htmlentities($name,ENT_QUOTES,$charset); ?>"></td>
  119. </tr>
  120. <tr>
  121. <td width="30%"><?php echo get_lang('CoachName') ?>&nbsp;&nbsp;</td>
  122. <td width="70%">
  123. <?php
  124. $sql = 'SELECT COUNT(1) FROM '.$tbl_user.' WHERE status=1';
  125. $rs = api_sql_query($sql, __FILE__, __LINE__);
  126. $count_users = mysql_result($rs, 0, 0);
  127. if(intval($count_users)<50)
  128. {
  129. $sql="SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE status='1' ORDER BY lastname,firstname,username";
  130. $result=api_sql_query($sql,__FILE__,__LINE__);
  131. $Coaches=api_store_result($result);
  132. ?>
  133. <select name="coach_username" value="true" style="width:250px;">
  134. <option value="0"><?php get_lang('None'); ?></option>
  135. <?php foreach($Coaches as $enreg): ?>
  136. <option value="<?php echo $enreg['username']; ?>" <?php if($sent && $enreg['user_id'] == $id_coach) echo 'selected="selected"'; ?>><?php echo $enreg['firstname'].' '.$enreg['lastname'].' ('.$enreg['username'].')'; ?></option>
  137. <?php endforeach; ?>
  138. </select>
  139. <?php
  140. }
  141. else
  142. {
  143. ?>
  144. <input type="text" name="coach_username" id="coach_username" onkeyup="xajax_search_coachs(document.getElementById('coach_username').value)" /><div id="ajax_list_coachs"></div>
  145. <?php
  146. }
  147. ?>
  148. </td>
  149. </tr>
  150. <tr>
  151. <td width="30%"><?php echo get_lang('NoTimeLimits') ?></td>
  152. <td width="70%">
  153. <input type="checkbox" name="nolimit" onChange="setDisable(this)" />
  154. </td>
  155. <tr>
  156. <td width="30%"><?php echo get_lang('DateStart') ?>&nbsp;&nbsp;</td>
  157. <td width="70%">
  158. <select name="day_start">
  159. <option value="1">01</option>
  160. <option value="2" <?php if((!$formSent && $thisDay == 2) || ($formSent && $day_start == 2)) echo 'selected="selected"'; ?> >02</option>
  161. <option value="3" <?php if((!$formSent && $thisDay == 3) || ($formSent && $day_start == 3)) echo 'selected="selected"'; ?> >03</option>
  162. <option value="4" <?php if((!$formSent && $thisDay == 4) || ($formSent && $day_start == 4)) echo 'selected="selected"'; ?> >04</option>
  163. <option value="5" <?php if((!$formSent && $thisDay == 5) || ($formSent && $day_start == 5)) echo 'selected="selected"'; ?> >05</option>
  164. <option value="6" <?php if((!$formSent && $thisDay == 6) || ($formSent && $day_start == 6)) echo 'selected="selected"'; ?> >06</option>
  165. <option value="7" <?php if((!$formSent && $thisDay == 7) || ($formSent && $day_start == 7)) echo 'selected="selected"'; ?> >07</option>
  166. <option value="8" <?php if((!$formSent && $thisDay == 8) || ($formSent && $day_start == 8)) echo 'selected="selected"'; ?> >08</option>
  167. <option value="9" <?php if((!$formSent && $thisDay == 9) || ($formSent && $day_start == 9)) echo 'selected="selected"'; ?> >09</option>
  168. <option value="10" <?php if((!$formSent && $thisDay == 10) || ($formSent && $day_start == 10)) echo 'selected="selected"'; ?> >10</option>
  169. <option value="11" <?php if((!$formSent && $thisDay == 11) || ($formSent && $day_start == 11)) echo 'selected="selected"'; ?> >11</option>
  170. <option value="12" <?php if((!$formSent && $thisDay == 12) || ($formSent && $day_start == 12)) echo 'selected="selected"'; ?> >12</option>
  171. <option value="13" <?php if((!$formSent && $thisDay == 13) || ($formSent && $day_start == 13)) echo 'selected="selected"'; ?> >13</option>
  172. <option value="14" <?php if((!$formSent && $thisDay == 14) || ($formSent && $day_start == 14)) echo 'selected="selected"'; ?> >14</option>
  173. <option value="15" <?php if((!$formSent && $thisDay == 15) || ($formSent && $day_start == 15)) echo 'selected="selected"'; ?> >15</option>
  174. <option value="16" <?php if((!$formSent && $thisDay == 16) || ($formSent && $day_start == 16)) echo 'selected="selected"'; ?> >16</option>
  175. <option value="17" <?php if((!$formSent && $thisDay == 17) || ($formSent && $day_start == 17)) echo 'selected="selected"'; ?> >17</option>
  176. <option value="18" <?php if((!$formSent && $thisDay == 18) || ($formSent && $day_start == 18)) echo 'selected="selected"'; ?> >18</option>
  177. <option value="19" <?php if((!$formSent && $thisDay == 19) || ($formSent && $day_start == 19)) echo 'selected="selected"'; ?> >19</option>
  178. <option value="20" <?php if((!$formSent && $thisDay == 20) || ($formSent && $day_start == 20)) echo 'selected="selected"'; ?> >20</option>
  179. <option value="21" <?php if((!$formSent && $thisDay == 21) || ($formSent && $day_start == 21)) echo 'selected="selected"'; ?> >21</option>
  180. <option value="22" <?php if((!$formSent && $thisDay == 22) || ($formSent && $day_start == 22)) echo 'selected="selected"'; ?> >22</option>
  181. <option value="23" <?php if((!$formSent && $thisDay == 23) || ($formSent && $day_start == 23)) echo 'selected="selected"'; ?> >23</option>
  182. <option value="24" <?php if((!$formSent && $thisDay == 24) || ($formSent && $day_start == 24)) echo 'selected="selected"'; ?> >24</option>
  183. <option value="25" <?php if((!$formSent && $thisDay == 25) || ($formSent && $day_start == 25)) echo 'selected="selected"'; ?> >25</option>
  184. <option value="26" <?php if((!$formSent && $thisDay == 26) || ($formSent && $day_start == 26)) echo 'selected="selected"'; ?> >26</option>
  185. <option value="27" <?php if((!$formSent && $thisDay == 27) || ($formSent && $day_start == 27)) echo 'selected="selected"'; ?> >27</option>
  186. <option value="28" <?php if((!$formSent && $thisDay == 28) || ($formSent && $day_start == 28)) echo 'selected="selected"'; ?> >28</option>
  187. <option value="29" <?php if((!$formSent && $thisDay == 29) || ($formSent && $day_start == 29)) echo 'selected="selected"'; ?> >29</option>
  188. <option value="30" <?php if((!$formSent && $thisDay == 30) || ($formSent && $day_start == 30)) echo 'selected="selected"'; ?> >30</option>
  189. <option value="31" <?php if((!$formSent && $thisDay == 31) || ($formSent && $day_start == 31)) echo 'selected="selected"'; ?> >31</option>
  190. </select>
  191. /
  192. <select name="month_start">
  193. <option value="1">01</option>
  194. <option value="2" <?php if((!$formSent && $thisMonth == 2) || ($formSent && $month_start == 2)) echo 'selected="selected"'; ?> >02</option>
  195. <option value="3" <?php if((!$formSent && $thisMonth == 3) || ($formSent && $month_start == 3)) echo 'selected="selected"'; ?> >03</option>
  196. <option value="4" <?php if((!$formSent && $thisMonth == 4) || ($formSent && $month_start == 4)) echo 'selected="selected"'; ?> >04</option>
  197. <option value="5" <?php if((!$formSent && $thisMonth == 5) || ($formSent && $month_start == 5)) echo 'selected="selected"'; ?> >05</option>
  198. <option value="6" <?php if((!$formSent && $thisMonth == 6) || ($formSent && $month_start == 6)) echo 'selected="selected"'; ?> >06</option>
  199. <option value="7" <?php if((!$formSent && $thisMonth == 7) || ($formSent && $month_start == 7)) echo 'selected="selected"'; ?> >07</option>
  200. <option value="8" <?php if((!$formSent && $thisMonth == 8) || ($formSent && $month_start == 8)) echo 'selected="selected"'; ?> >08</option>
  201. <option value="9" <?php if((!$formSent && $thisMonth == 9) || ($formSent && $month_start == 9)) echo 'selected="selected"'; ?> >09</option>
  202. <option value="10" <?php if((!$formSent && $thisMonth == 10) || ($formSent && $month_start == 10)) echo 'selected="selected"'; ?> >10</option>
  203. <option value="11" <?php if((!$formSent && $thisMonth == 11) || ($formSent && $month_start == 11)) echo 'selected="selected"'; ?> >11</option>
  204. <option value="12" <?php if((!$formSent && $thisMonth == 12) || ($formSent && $month_start == 12)) echo 'selected="selected"'; ?> >12</option>
  205. </select>
  206. /
  207. <select name="year_start">
  208. <?php
  209. for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
  210. {
  211. ?>
  212. <option value="<?php echo $i; ?>" <?php if((!$formSent && $thisYear == $i) || ($formSent && $year_start == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
  213. <?php
  214. }
  215. ?>
  216. </select>
  217. </td>
  218. </tr>
  219. <tr>
  220. <td width="30%"><?php echo get_lang('DateEnd') ?>&nbsp;&nbsp;</td>
  221. <td width="70%">
  222. <select name="day_end">
  223. <option value="1">01</option>
  224. <option value="2" <?php if((!$formSent && $thisDay == 2) || ($formSent && $day_end == 2)) echo 'selected="selected"'; ?> >02</option>
  225. <option value="3" <?php if((!$formSent && $thisDay == 3) || ($formSent && $day_end == 3)) echo 'selected="selected"'; ?> >03</option>
  226. <option value="4" <?php if((!$formSent && $thisDay == 4) || ($formSent && $day_end == 4)) echo 'selected="selected"'; ?> >04</option>
  227. <option value="5" <?php if((!$formSent && $thisDay == 5) || ($formSent && $day_end == 5)) echo 'selected="selected"'; ?> >05</option>
  228. <option value="6" <?php if((!$formSent && $thisDay == 6) || ($formSent && $day_end == 6)) echo 'selected="selected"'; ?> >06</option>
  229. <option value="7" <?php if((!$formSent && $thisDay == 7) || ($formSent && $day_end == 7)) echo 'selected="selected"'; ?> >07</option>
  230. <option value="8" <?php if((!$formSent && $thisDay == 8) || ($formSent && $day_end == 8)) echo 'selected="selected"'; ?> >08</option>
  231. <option value="9" <?php if((!$formSent && $thisDay == 9) || ($formSent && $day_end == 9)) echo 'selected="selected"'; ?> >09</option>
  232. <option value="10" <?php if((!$formSent && $thisDay == 10) || ($formSent && $day_end == 10)) echo 'selected="selected"'; ?> >10</option>
  233. <option value="11" <?php if((!$formSent && $thisDay == 11) || ($formSent && $day_end == 11)) echo 'selected="selected"'; ?> >11</option>
  234. <option value="12" <?php if((!$formSent && $thisDay == 12) || ($formSent && $day_end == 12)) echo 'selected="selected"'; ?> >12</option>
  235. <option value="13" <?php if((!$formSent && $thisDay == 13) || ($formSent && $day_end == 13)) echo 'selected="selected"'; ?> >13</option>
  236. <option value="14" <?php if((!$formSent && $thisDay == 14) || ($formSent && $day_end == 14)) echo 'selected="selected"'; ?> >14</option>
  237. <option value="15" <?php if((!$formSent && $thisDay == 15) || ($formSent && $day_end == 15)) echo 'selected="selected"'; ?> >15</option>
  238. <option value="16" <?php if((!$formSent && $thisDay == 16) || ($formSent && $day_end == 16)) echo 'selected="selected"'; ?> >16</option>
  239. <option value="17" <?php if((!$formSent && $thisDay == 17) || ($formSent && $day_end == 17)) echo 'selected="selected"'; ?> >17</option>
  240. <option value="18" <?php if((!$formSent && $thisDay == 18) || ($formSent && $day_end == 18)) echo 'selected="selected"'; ?> >18</option>
  241. <option value="19" <?php if((!$formSent && $thisDay == 19) || ($formSent && $day_end == 19)) echo 'selected="selected"'; ?> >19</option>
  242. <option value="20" <?php if((!$formSent && $thisDay == 20) || ($formSent && $day_end == 20)) echo 'selected="selected"'; ?> >20</option>
  243. <option value="21" <?php if((!$formSent && $thisDay == 21) || ($formSent && $day_end == 21)) echo 'selected="selected"'; ?> >21</option>
  244. <option value="22" <?php if((!$formSent && $thisDay == 22) || ($formSent && $day_end == 22)) echo 'selected="selected"'; ?> >22</option>
  245. <option value="23" <?php if((!$formSent && $thisDay == 23) || ($formSent && $day_end == 23)) echo 'selected="selected"'; ?> >23</option>
  246. <option value="24" <?php if((!$formSent && $thisDay == 24) || ($formSent && $day_end == 24)) echo 'selected="selected"'; ?> >24</option>
  247. <option value="25" <?php if((!$formSent && $thisDay == 25) || ($formSent && $day_end == 25)) echo 'selected="selected"'; ?> >25</option>
  248. <option value="26" <?php if((!$formSent && $thisDay == 26) || ($formSent && $day_end == 26)) echo 'selected="selected"'; ?> >26</option>
  249. <option value="27" <?php if((!$formSent && $thisDay == 27) || ($formSent && $day_end == 27)) echo 'selected="selected"'; ?> >27</option>
  250. <option value="28" <?php if((!$formSent && $thisDay == 28) || ($formSent && $day_end == 28)) echo 'selected="selected"'; ?> >28</option>
  251. <option value="29" <?php if((!$formSent && $thisDay == 29) || ($formSent && $day_end == 29)) echo 'selected="selected"'; ?> >29</option>
  252. <option value="30" <?php if((!$formSent && $thisDay == 30) || ($formSent && $day_end == 30)) echo 'selected="selected"'; ?> >30</option>
  253. <option value="31" <?php if((!$formSent && $thisDay == 31) || ($formSent && $day_end == 31)) echo 'selected="selected"'; ?> >31</option>
  254. </select>
  255. /
  256. <select name="month_end">
  257. <option value="1">01</option>
  258. <option value="2" <?php if((!$formSent && $thisMonth == 2) || ($formSent && $month_end == 2)) echo 'selected="selected"'; ?> >02</option>
  259. <option value="3" <?php if((!$formSent && $thisMonth == 3) || ($formSent && $month_end == 3)) echo 'selected="selected"'; ?> >03</option>
  260. <option value="4" <?php if((!$formSent && $thisMonth == 4) || ($formSent && $month_end == 4)) echo 'selected="selected"'; ?> >04</option>
  261. <option value="5" <?php if((!$formSent && $thisMonth == 5) || ($formSent && $month_end == 5)) echo 'selected="selected"'; ?> >05</option>
  262. <option value="6" <?php if((!$formSent && $thisMonth == 6) || ($formSent && $month_end == 6)) echo 'selected="selected"'; ?> >06</option>
  263. <option value="7" <?php if((!$formSent && $thisMonth == 7) || ($formSent && $month_end == 7)) echo 'selected="selected"'; ?> >07</option>
  264. <option value="8" <?php if((!$formSent && $thisMonth == 8) || ($formSent && $month_end == 8)) echo 'selected="selected"'; ?> >08</option>
  265. <option value="9" <?php if((!$formSent && $thisMonth == 9) || ($formSent && $month_end == 9)) echo 'selected="selected"'; ?> >09</option>
  266. <option value="10" <?php if((!$formSent && $thisMonth == 10) || ($formSent && $month_end == 10)) echo 'selected="selected"'; ?> >10</option>
  267. <option value="11" <?php if((!$formSent && $thisMonth == 11) || ($formSent && $month_end == 11)) echo 'selected="selected"'; ?> >11</option>
  268. <option value="12" <?php if((!$formSent && $thisMonth == 12) || ($formSent && $month_end == 12)) echo 'selected="selected"'; ?> >12</option>
  269. </select>
  270. /
  271. <select name="year_end">
  272. <?php
  273. for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
  274. {
  275. ?>
  276. <option value="<?php echo $i; ?>" <?php if((!$formSent && ($thisYear+1) == $i) || ($formSent && $year_end == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
  277. <?php
  278. }
  279. ?>
  280. </select>
  281. </td>
  282. </tr>
  283. <tr>
  284. <td>&nbsp;</td>
  285. <td><input type="submit" value="<?php echo get_lang('NextStep') ?>"></td>
  286. </tr>
  287. </table>
  288. </form>
  289. <script type="text/javascript">
  290. function setDisable(select){
  291. document.form.day_start.disabled = (select.checked) ? true : false;
  292. document.form.month_start.disabled = (select.checked) ? true : false;
  293. document.form.year_start.disabled = (select.checked) ? true : false;
  294. document.form.day_end.disabled = (select.checked) ? true : false;
  295. document.form.month_end.disabled = (select.checked) ? true : false;
  296. document.form.year_end.disabled = (select.checked) ? true : false;
  297. }
  298. </script>
  299. <?php
  300. Display::display_footer();
  301. ?>