session_edit.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2009 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  14. ==============================================================================
  15. */
  16. // name of the language file that needs to be included
  17. $language_file ='admin';
  18. $cidReset=true;
  19. include('../inc/global.inc.php');
  20. require_once (api_get_path(LIBRARY_PATH).'sessionmanager.lib.php');
  21. // setting the section (for the tabs)
  22. $this_section=SECTION_PLATFORM_ADMIN;
  23. api_protect_admin_script(true);
  24. $id=intval($_GET['id']);
  25. $formSent=0;
  26. $errorMsg='';
  27. // Database Table Definitions
  28. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  29. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  30. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  31. $tool_name = get_lang('EditSession');
  32. $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  33. $interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang('SessionList'));
  34. $result=api_sql_query("SELECT name,date_start,date_end,id_coach, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end FROM $tbl_session WHERE id='$id'",__FILE__,__LINE__);
  35. if (!$infos=mysql_fetch_array($result)) {
  36. header('Location: session_list.php');
  37. exit();
  38. }
  39. list($year_start,$month_start,$day_start)=explode('-',$infos['date_start']);
  40. list($year_end,$month_end,$day_end)=explode('-',$infos['date_end']);
  41. if (!api_is_platform_admin() && $infos['session_admin_id']!=$_user['user_id']) {
  42. api_not_allowed(true);
  43. }
  44. if ($_POST['formSent']) {
  45. $formSent=1;
  46. $name=trim(stripslashes($_POST['name']));
  47. $year_start=intval($_POST['year_start']);
  48. $month_start=intval($_POST['month_start']);
  49. $day_start=intval($_POST['day_start']);
  50. $year_end=intval($_POST['year_end']);
  51. $month_end=intval($_POST['month_end']);
  52. $day_end=intval($_POST['day_end']);
  53. $id_coach=intval($_POST['id_coach']);
  54. $nb_days_acess_before = intval($_POST['nb_days_access_before']);
  55. $nb_days_acess_after = intval($_POST['nb_days_access_after']);
  56. SessionManager::EditSession($name,$year_start,$month_start,$day_start,$year_end,$month_end,$day_end,$nb_days_acess_before,$nb_days_acess_after,$nolimit,$id_coach,$id);
  57. header('Location: resume_session.php?id_session='.$id);
  58. exit();
  59. }
  60. $sql="SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE status='1' ORDER BY lastname,firstname,username";
  61. if ($_configuration['multiple_access_urls']==true){
  62. $table_access_url_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  63. $access_url_id = api_get_current_access_url_id();
  64. if ($access_url_id != -1) {
  65. $sql="SELECT DISTINCT u.user_id,lastname,firstname,username FROM $tbl_user u INNER JOIN $table_access_url_rel_user url_rel_user
  66. ON (url_rel_user.user_id = u.user_id)
  67. WHERE status='1' AND access_url_id = $access_url_id
  68. ORDER BY lastname,firstname,username";
  69. }
  70. }
  71. $result=api_sql_query($sql,__FILE__,__LINE__);
  72. $Coaches=api_store_result($result);
  73. $thisYear=date('Y');
  74. Display::display_header($tool_name);
  75. api_display_tool_title($tool_name);
  76. ?>
  77. <form method="post" name="form" action="<?php echo api_get_self(); ?>?page=<?php echo $_GET['page'] ?>&id=<?php echo $id; ?>" style="margin:0px;">
  78. <input type="hidden" name="formSent" value="1">
  79. <table border="0" cellpadding="5" cellspacing="0" width="550">
  80. <tr>
  81. <td width="30%"><?php echo get_lang('SessionName') ?>&nbsp;&nbsp;</td>
  82. <td width="70%"><input type="text" name="name" size="50" maxlength="50" value="<?php if($formSent) echo htmlentities($name,ENT_QUOTES,$charset); else echo htmlentities($infos['name'],ENT_QUOTES,$charset); ?>"></td>
  83. </tr>
  84. <tr>
  85. <td width="30%"><?php echo get_lang('CoachName') ?>&nbsp;&nbsp;</td>
  86. <td width="70%"><select name="id_coach" style="width:250px;">
  87. <option value="0">----- <?php echo get_lang('Choose') ?> -----</option>
  88. <?php
  89. foreach($Coaches as $enreg) {
  90. ?>
  91. <option value="<?php echo $enreg['user_id']; ?>" <?php if((!$sent && $enreg['user_id'] == $infos['id_coach']) || ($sent && $enreg['user_id'] == $id_coach)) echo 'selected="selected"'; ?>><?php echo $enreg['lastname'].' '.$enreg['firstname'].' ('.$enreg['username'].')'; ?></option>
  92. <?php
  93. }
  94. unset($Coaches);
  95. ?>
  96. </select></td>
  97. </tr>
  98. <tr>
  99. <td width="30%"><?php echo get_lang('NoTimeLimits') ?></td>
  100. <td width="70%">
  101. <input type="checkbox" name="nolimit" onChange="setDisable(this)" <?php if($year_start=="0000") echo "checked"; ?>/>
  102. </td>
  103. <tr>
  104. <tr>
  105. <td width="30%"><?php echo get_lang('DateStartSession') ?>&nbsp;&nbsp;</td>
  106. <td width="70%">
  107. <select name="day_start">
  108. <option value="1">01</option>
  109. <option value="2" <?php if($day_start == 2) echo 'selected="selected"'; ?> >02</option>
  110. <option value="3" <?php if($day_start == 3) echo 'selected="selected"'; ?> >03</option>
  111. <option value="4" <?php if($day_start == 4) echo 'selected="selected"'; ?> >04</option>
  112. <option value="5" <?php if($day_start == 5) echo 'selected="selected"'; ?> >05</option>
  113. <option value="6" <?php if($day_start == 6) echo 'selected="selected"'; ?> >06</option>
  114. <option value="7" <?php if($day_start == 7) echo 'selected="selected"'; ?> >07</option>
  115. <option value="8" <?php if($day_start == 8) echo 'selected="selected"'; ?> >08</option>
  116. <option value="9" <?php if($day_start == 9) echo 'selected="selected"'; ?> >09</option>
  117. <option value="10" <?php if($day_start == 10) echo 'selected="selected"'; ?> >10</option>
  118. <option value="11" <?php if($day_start == 11) echo 'selected="selected"'; ?> >11</option>
  119. <option value="12" <?php if($day_start == 12) echo 'selected="selected"'; ?> >12</option>
  120. <option value="13" <?php if($day_start == 13) echo 'selected="selected"'; ?> >13</option>
  121. <option value="14" <?php if($day_start == 14) echo 'selected="selected"'; ?> >14</option>
  122. <option value="15" <?php if($day_start == 15) echo 'selected="selected"'; ?> >15</option>
  123. <option value="16" <?php if($day_start == 16) echo 'selected="selected"'; ?> >16</option>
  124. <option value="17" <?php if($day_start == 17) echo 'selected="selected"'; ?> >17</option>
  125. <option value="18" <?php if($day_start == 18) echo 'selected="selected"'; ?> >18</option>
  126. <option value="19" <?php if($day_start == 19) echo 'selected="selected"'; ?> >19</option>
  127. <option value="20" <?php if($day_start == 20) echo 'selected="selected"'; ?> >20</option>
  128. <option value="21" <?php if($day_start == 21) echo 'selected="selected"'; ?> >21</option>
  129. <option value="22" <?php if($day_start == 22) echo 'selected="selected"'; ?> >22</option>
  130. <option value="23" <?php if($day_start == 23) echo 'selected="selected"'; ?> >23</option>
  131. <option value="24" <?php if($day_start == 24) echo 'selected="selected"'; ?> >24</option>
  132. <option value="25" <?php if($day_start == 25) echo 'selected="selected"'; ?> >25</option>
  133. <option value="26" <?php if($day_start == 26) echo 'selected="selected"'; ?> >26</option>
  134. <option value="27" <?php if($day_start == 27) echo 'selected="selected"'; ?> >27</option>
  135. <option value="28" <?php if($day_start == 28) echo 'selected="selected"'; ?> >28</option>
  136. <option value="29" <?php if($day_start == 29) echo 'selected="selected"'; ?> >29</option>
  137. <option value="30" <?php if($day_start == 30) echo 'selected="selected"'; ?> >30</option>
  138. <option value="31" <?php if($day_start == 31) echo 'selected="selected"'; ?> >31</option>
  139. </select>
  140. /
  141. <select name="month_start">
  142. <option value="1">01</option>
  143. <option value="2" <?php if($month_start == 2) echo 'selected="selected"'; ?> >02</option>
  144. <option value="3" <?php if($month_start == 3) echo 'selected="selected"'; ?> >03</option>
  145. <option value="4" <?php if($month_start == 4) echo 'selected="selected"'; ?> >04</option>
  146. <option value="5" <?php if($month_start == 5) echo 'selected="selected"'; ?> >05</option>
  147. <option value="6" <?php if($month_start == 6) echo 'selected="selected"'; ?> >06</option>
  148. <option value="7" <?php if($month_start == 7) echo 'selected="selected"'; ?> >07</option>
  149. <option value="8" <?php if($month_start == 8) echo 'selected="selected"'; ?> >08</option>
  150. <option value="9" <?php if($month_start == 9) echo 'selected="selected"'; ?> >09</option>
  151. <option value="10" <?php if($month_start == 10) echo 'selected="selected"'; ?> >10</option>
  152. <option value="11" <?php if($month_start == 11) echo 'selected="selected"'; ?> >11</option>
  153. <option value="12" <?php if($month_start == 12) echo 'selected="selected"'; ?> >12</option>
  154. </select>
  155. /
  156. <select name="year_start">
  157. <?php
  158. for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
  159. {
  160. ?>
  161. <option value="<?php echo $i; ?>" <?php if($year_start == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
  162. <?php
  163. }
  164. ?>
  165. </select>
  166. </td>
  167. </tr>
  168. <tr>
  169. <td width="30%"><?php echo get_lang('DateEndSession') ?>&nbsp;&nbsp;</td>
  170. <td width="70%">
  171. <select name="day_end">
  172. <option value="1">01</option>
  173. <option value="2" <?php if($day_end == 2) echo 'selected="selected"'; ?> >02</option>
  174. <option value="3" <?php if($day_end == 3) echo 'selected="selected"'; ?> >03</option>
  175. <option value="4" <?php if($day_end == 4) echo 'selected="selected"'; ?> >04</option>
  176. <option value="5" <?php if($day_end == 5) echo 'selected="selected"'; ?> >05</option>
  177. <option value="6" <?php if($day_end == 6) echo 'selected="selected"'; ?> >06</option>
  178. <option value="7" <?php if($day_end == 7) echo 'selected="selected"'; ?> >07</option>
  179. <option value="8" <?php if($day_end == 8) echo 'selected="selected"'; ?> >08</option>
  180. <option value="9" <?php if($day_end == 9) echo 'selected="selected"'; ?> >09</option>
  181. <option value="10" <?php if($day_end == 10) echo 'selected="selected"'; ?> >10</option>
  182. <option value="11" <?php if($day_end == 11) echo 'selected="selected"'; ?> >11</option>
  183. <option value="12" <?php if($day_end == 12) echo 'selected="selected"'; ?> >12</option>
  184. <option value="13" <?php if($day_end == 13) echo 'selected="selected"'; ?> >13</option>
  185. <option value="14" <?php if($day_end == 14) echo 'selected="selected"'; ?> >14</option>
  186. <option value="15" <?php if($day_end == 15) echo 'selected="selected"'; ?> >15</option>
  187. <option value="16" <?php if($day_end == 16) echo 'selected="selected"'; ?> >16</option>
  188. <option value="17" <?php if($day_end == 17) echo 'selected="selected"'; ?> >17</option>
  189. <option value="18" <?php if($day_end == 18) echo 'selected="selected"'; ?> >18</option>
  190. <option value="19" <?php if($day_end == 19) echo 'selected="selected"'; ?> >19</option>
  191. <option value="20" <?php if($day_end == 20) echo 'selected="selected"'; ?> >20</option>
  192. <option value="21" <?php if($day_end == 21) echo 'selected="selected"'; ?> >21</option>
  193. <option value="22" <?php if($day_end == 22) echo 'selected="selected"'; ?> >22</option>
  194. <option value="23" <?php if($day_end == 23) echo 'selected="selected"'; ?> >23</option>
  195. <option value="24" <?php if($day_end == 24) echo 'selected="selected"'; ?> >24</option>
  196. <option value="25" <?php if($day_end == 25) echo 'selected="selected"'; ?> >25</option>
  197. <option value="26" <?php if($day_end == 26) echo 'selected="selected"'; ?> >26</option>
  198. <option value="27" <?php if($day_end == 27) echo 'selected="selected"'; ?> >27</option>
  199. <option value="28" <?php if($day_end == 28) echo 'selected="selected"'; ?> >28</option>
  200. <option value="29" <?php if($day_end == 29) echo 'selected="selected"'; ?> >29</option>
  201. <option value="30" <?php if($day_end == 30) echo 'selected="selected"'; ?> >30</option>
  202. <option value="31" <?php if($day_end == 31) echo 'selected="selected"'; ?> >31</option>
  203. </select>
  204. /
  205. <select name="month_end">
  206. <option value="1">01</option>
  207. <option value="2" <?php if($month_end == 2) echo 'selected="selected"'; ?> >02</option>
  208. <option value="3" <?php if($month_end == 3) echo 'selected="selected"'; ?> >03</option>
  209. <option value="4" <?php if($month_end == 4) echo 'selected="selected"'; ?> >04</option>
  210. <option value="5" <?php if($month_end == 5) echo 'selected="selected"'; ?> >05</option>
  211. <option value="6" <?php if($month_end == 6) echo 'selected="selected"'; ?> >06</option>
  212. <option value="7" <?php if($month_end == 7) echo 'selected="selected"'; ?> >07</option>
  213. <option value="8" <?php if($month_end == 8) echo 'selected="selected"'; ?> >08</option>
  214. <option value="9" <?php if($month_end == 9) echo 'selected="selected"'; ?> >09</option>
  215. <option value="10" <?php if($month_end == 10) echo 'selected="selected"'; ?> >10</option>
  216. <option value="11" <?php if($month_end == 11) echo 'selected="selected"'; ?> >11</option>
  217. <option value="12" <?php if($month_end == 12) echo 'selected="selected"'; ?> >12</option>
  218. </select>
  219. /
  220. <select name="year_end">
  221. <?php
  222. for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
  223. {
  224. ?>
  225. <option value="<?php echo $i; ?>" <?php if($year_end == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
  226. <?php
  227. }
  228. ?>
  229. </select>
  230. </td>
  231. </tr>
  232. <tr>
  233. <td>
  234. &nbsp;
  235. </td>
  236. <td>
  237. <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('DefineSessionOptions') ?></a>
  238. <div style="display:
  239. <?php
  240. if($formSent){
  241. if($nb_days_access_before!=0 || $nb_days_access_after!=0)
  242. echo 'block';
  243. else echo 'none';
  244. }
  245. else{
  246. if($infos['nb_days_access_before_beginning']!=0 || $infos['nb_days_access_after_end']!=0)
  247. echo 'block';
  248. else
  249. echo 'none';
  250. }
  251. ?>
  252. ;" id="options">
  253. <br>
  254. <input type="text" name="nb_days_access_before" value="<?php if($formSent) echo htmlentities($nb_days_access_before,ENT_QUOTES,$charset); else echo htmlentities($infos['nb_days_access_before_beginning'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysBefore') ?><br>
  255. <input type="text" name="nb_days_access_after" value="<?php if($formSent) echo htmlentities($nb_days_access_after,ENT_QUOTES,$charset); else echo htmlentities($infos['nb_days_access_after_end'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysAfter') ?>
  256. <br>
  257. </div>
  258. </td>
  259. </tr>
  260. <tr>
  261. <td>&nbsp;</td>
  262. <td><input type="submit" value="<?php echo get_lang('Ok'); ?>"></td>
  263. </tr>
  264. </table>
  265. </form>
  266. <script type="text/javascript">
  267. <?php if($year_start=="0000") echo "setDisable(document.form.nolimit);\r\n"; ?>
  268. function setDisable(select){
  269. document.form.day_start.disabled = (select.checked) ? true : false;
  270. document.form.month_start.disabled = (select.checked) ? true : false;
  271. document.form.year_start.disabled = (select.checked) ? true : false;
  272. document.form.day_end.disabled = (select.checked) ? true : false;
  273. document.form.month_end.disabled = (select.checked) ? true : false;
  274. document.form.year_end.disabled = (select.checked) ? true : false;
  275. }
  276. </script>
  277. <?php
  278. Display::display_footer();
  279. ?>