session_edit.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // name of the language file that needs to be included
  4. $language_file ='admin';
  5. $cidReset = true;
  6. require_once '../inc/global.inc.php';
  7. // setting the section (for the tabs)
  8. $this_section=SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script(true);
  10. $id = intval($_GET['id']);
  11. $formSent=0;
  12. // Database Table Definitions
  13. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  14. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  15. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  16. $sql = "SELECT name,date_start,date_end,id_coach, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility FROM $tbl_session WHERE id = $id";
  17. $result = Database::query($sql);
  18. if (!$infos = Database::fetch_array($result)) {
  19. header('Location: session_list.php');
  20. exit();
  21. }
  22. $id_coach = $infos['id_coach'];
  23. if (!api_is_platform_admin() && $infos['session_admin_id'] != api_get_user_id()) {
  24. api_not_allowed(true);
  25. }
  26. $tool_name = get_lang('EditSession');
  27. $interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  28. $interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang('SessionList'));
  29. $interbreadcrumb[]=array('url' => "resume_session.php?id_session=".$id,"name" => get_lang('SessionOverview'));
  30. list($year_start,$month_start,$day_start) = explode('-',$infos['date_start']);
  31. list($year_end,$month_end,$day_end) = explode('-',$infos['date_end']);
  32. $end_year_disabled = $end_month_disabled = $end_day_disabled = '';
  33. if ($_POST['formSent']) {
  34. $formSent = 1;
  35. $name = $_POST['name'];
  36. $year_start = $_POST['year_start'];
  37. $month_start = $_POST['month_start'];
  38. $day_start = $_POST['day_start'];
  39. $year_end = $_POST['year_end'];
  40. $month_end = $_POST['month_end'];
  41. $day_end = $_POST['day_end'];
  42. $nb_days_acess_before = $_POST['nb_days_access_before'];
  43. $nb_days_acess_after = $_POST['nb_days_access_after'];
  44. //$nolimit = $_POST['nolimit'];
  45. $id_coach = $_POST['id_coach'];
  46. $id_session_category = $_POST['session_category'];
  47. $id_visibility = $_POST['session_visibility'];
  48. $end_limit = $_POST['end_limit'];
  49. $start_limit = $_POST['start_limit'];
  50. if (empty($end_limit) && empty($start_limit)) {
  51. $nolimit = 1;
  52. } else {
  53. $nolimit = null;
  54. }
  55. $return = SessionManager::edit_session($id,$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_session_category,$id_visibility,$start_limit,$end_limit);
  56. if ($return == strval(intval($return))) {
  57. header('Location: resume_session.php?id_session='.$return);
  58. exit();
  59. }
  60. }
  61. $order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
  62. $sql="SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE status='1'".$order_clause;
  63. if ($_configuration['multiple_access_urls']) {
  64. $table_access_url_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  65. $access_url_id = api_get_current_access_url_id();
  66. if ($access_url_id != -1) {
  67. $sql="SELECT DISTINCT u.user_id,lastname,firstname,username FROM $tbl_user u INNER JOIN $table_access_url_rel_user url_rel_user ON (url_rel_user.user_id = u.user_id)
  68. WHERE status='1' AND access_url_id = '$access_url_id' $order_clause";
  69. }
  70. }
  71. $result = Database::query($sql);
  72. $Coaches = Database::store_result($result);
  73. $thisYear = date('Y');
  74. // display the header
  75. Display::display_header($tool_name);
  76. // display the tool title
  77. // api_display_tool_title($tool_name);
  78. if (!empty($return)) {
  79. Display::display_error_message($return,false);
  80. }
  81. ?>
  82. <form method="post" name="form" action="<?php echo api_get_self(); ?>?page=<?php echo Security::remove_XSS($_GET['page']) ?>&id=<?php echo $id; ?>" style="margin:0px;">
  83. <input type="hidden" name="formSent" value="1">
  84. <div class="row"><div class="form_header"><?php echo $tool_name; ?></div></div>
  85. <table border="0" cellpadding="5" cellspacing="0" width="650">
  86. <tr>
  87. <td width="30%"><?php echo get_lang('SessionName') ?>&nbsp;&nbsp;</td>
  88. <td width="70%"><input type="text" name="name" size="50" maxlength="50" value="<?php if($formSent) echo api_htmlentities($name,ENT_QUOTES,$charset); else echo api_htmlentities($infos['name'],ENT_QUOTES,$charset); ?>"></td>
  89. </tr>
  90. <tr>
  91. <td width="30%"><?php echo get_lang('CoachName') ?>&nbsp;&nbsp;</td>
  92. <td width="70%">
  93. <select class="chzn-select" name="id_coach" style="width:380px;" title="<?php echo get_lang('Choose'); ?>" >
  94. <option value="">----- <?php echo get_lang('None') ?> -----</option>
  95. <?php foreach($Coaches as $enreg) { ?>
  96. <option value="<?php echo $enreg['user_id']; ?>" <?php if(($enreg['user_id'] == $infos['id_coach']) || ($enreg['user_id'] == $id_coach)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
  97. <?php
  98. }
  99. unset($Coaches);
  100. $Categories = SessionManager::get_all_session_category();
  101. ?>
  102. </select>
  103. </td>
  104. </tr>
  105. <tr>
  106. <td width="30%"><?php echo get_lang('SessionCategory') ?></td>
  107. <td width="70%">
  108. <select class="chzn-select" id="session_category" name="session_category" style="width:380px;" title="<?php echo get_lang('Select'); ?>">
  109. <option value="0"><?php get_lang('None'); ?></option>
  110. <?php
  111. if (!empty($Categories)) {
  112. foreach($Categories as $Rows) { ?>
  113. <option value="<?php echo $Rows['id']; ?>" <?php if($Rows['id'] == $infos['session_category_id']) echo 'selected="selected"'; ?>><?php echo $Rows['name']; ?></option>
  114. <?php }
  115. }
  116. ?>
  117. </select>
  118. </td>
  119. </tr>
  120. <tr>
  121. <td>
  122. &nbsp;
  123. </td>
  124. <td>
  125. <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>
  126. <div style="display:
  127. <?php
  128. if($formSent){
  129. if($nb_days_access_before!=0 || $nb_days_access_after!=0)
  130. echo 'block';
  131. else echo 'none';
  132. }
  133. else{
  134. if($infos['nb_days_access_before_beginning']!=0 || $infos['nb_days_access_after_end']!=0)
  135. echo 'block';
  136. else
  137. echo 'none';
  138. }
  139. ?>
  140. ;" id="options">
  141. <br>
  142. <input type="text" name="nb_days_access_before" value="<?php if($formSent) echo api_htmlentities($nb_days_access_before,ENT_QUOTES,$charset); else echo api_htmlentities($infos['nb_days_access_before_beginning'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysBefore') ?><br /><br />
  143. <input type="text" name="nb_days_access_after" value="<?php if($formSent) echo api_htmlentities($nb_days_access_after,ENT_QUOTES,$charset); else echo api_htmlentities($infos['nb_days_access_after_end'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysAfter') ?>
  144. <br>
  145. </div>
  146. </td>
  147. </tr>
  148. <tr>
  149. <td width="30%"></td>
  150. <td width="70%">
  151. <input id="start_limit" type="checkbox" name="start_limit" onchange="disable_starttime(this)" <?php if ($year_start!="0000") echo "checked"; ?>/>
  152. <label for="start_limit">
  153. <?php echo get_lang('DateStartSession');?>
  154. </label>
  155. <div id="start_date" style="<?php echo ($year_start=="0000") ? "display:none" : "display:block" ; ?>">
  156. <br />
  157. <select name="day_start">
  158. <option value="1">01</option>
  159. <option value="2" <?php if($day_start == 2) echo 'selected="selected"'; ?> >02</option>
  160. <option value="3" <?php if($day_start == 3) echo 'selected="selected"'; ?> >03</option>
  161. <option value="4" <?php if($day_start == 4) echo 'selected="selected"'; ?> >04</option>
  162. <option value="5" <?php if($day_start == 5) echo 'selected="selected"'; ?> >05</option>
  163. <option value="6" <?php if($day_start == 6) echo 'selected="selected"'; ?> >06</option>
  164. <option value="7" <?php if($day_start == 7) echo 'selected="selected"'; ?> >07</option>
  165. <option value="8" <?php if($day_start == 8) echo 'selected="selected"'; ?> >08</option>
  166. <option value="9" <?php if($day_start == 9) echo 'selected="selected"'; ?> >09</option>
  167. <option value="10" <?php if($day_start == 10) echo 'selected="selected"'; ?> >10</option>
  168. <option value="11" <?php if($day_start == 11) echo 'selected="selected"'; ?> >11</option>
  169. <option value="12" <?php if($day_start == 12) echo 'selected="selected"'; ?> >12</option>
  170. <option value="13" <?php if($day_start == 13) echo 'selected="selected"'; ?> >13</option>
  171. <option value="14" <?php if($day_start == 14) echo 'selected="selected"'; ?> >14</option>
  172. <option value="15" <?php if($day_start == 15) echo 'selected="selected"'; ?> >15</option>
  173. <option value="16" <?php if($day_start == 16) echo 'selected="selected"'; ?> >16</option>
  174. <option value="17" <?php if($day_start == 17) echo 'selected="selected"'; ?> >17</option>
  175. <option value="18" <?php if($day_start == 18) echo 'selected="selected"'; ?> >18</option>
  176. <option value="19" <?php if($day_start == 19) echo 'selected="selected"'; ?> >19</option>
  177. <option value="20" <?php if($day_start == 20) echo 'selected="selected"'; ?> >20</option>
  178. <option value="21" <?php if($day_start == 21) echo 'selected="selected"'; ?> >21</option>
  179. <option value="22" <?php if($day_start == 22) echo 'selected="selected"'; ?> >22</option>
  180. <option value="23" <?php if($day_start == 23) echo 'selected="selected"'; ?> >23</option>
  181. <option value="24" <?php if($day_start == 24) echo 'selected="selected"'; ?> >24</option>
  182. <option value="25" <?php if($day_start == 25) echo 'selected="selected"'; ?> >25</option>
  183. <option value="26" <?php if($day_start == 26) echo 'selected="selected"'; ?> >26</option>
  184. <option value="27" <?php if($day_start == 27) echo 'selected="selected"'; ?> >27</option>
  185. <option value="28" <?php if($day_start == 28) echo 'selected="selected"'; ?> >28</option>
  186. <option value="29" <?php if($day_start == 29) echo 'selected="selected"'; ?> >29</option>
  187. <option value="30" <?php if($day_start == 30) echo 'selected="selected"'; ?> >30</option>
  188. <option value="31" <?php if($day_start == 31) echo 'selected="selected"'; ?> >31</option>
  189. </select>
  190. /
  191. <select name="month_start">
  192. <option value="1">01</option>
  193. <option value="2" <?php if($month_start == 2) echo 'selected="selected"'; ?> >02</option>
  194. <option value="3" <?php if($month_start == 3) echo 'selected="selected"'; ?> >03</option>
  195. <option value="4" <?php if($month_start == 4) echo 'selected="selected"'; ?> >04</option>
  196. <option value="5" <?php if($month_start == 5) echo 'selected="selected"'; ?> >05</option>
  197. <option value="6" <?php if($month_start == 6) echo 'selected="selected"'; ?> >06</option>
  198. <option value="7" <?php if($month_start == 7) echo 'selected="selected"'; ?> >07</option>
  199. <option value="8" <?php if($month_start == 8) echo 'selected="selected"'; ?> >08</option>
  200. <option value="9" <?php if($month_start == 9) echo 'selected="selected"'; ?> >09</option>
  201. <option value="10" <?php if($month_start == 10) echo 'selected="selected"'; ?> >10</option>
  202. <option value="11" <?php if($month_start == 11) echo 'selected="selected"'; ?> >11</option>
  203. <option value="12" <?php if($month_start == 12) echo 'selected="selected"'; ?> >12</option>
  204. </select>
  205. /
  206. <select name="year_start">
  207. <?php
  208. for($i=$thisYear-5;$i <= ($thisYear+5);$i++) { ?>
  209. <option value="<?php echo $i; ?>" <?php if($year_start == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
  210. <?php
  211. }
  212. ?>
  213. </select>
  214. </div>
  215. </td>
  216. </tr>
  217. <tr>
  218. <td width="30%"></td>
  219. <td width="70%">
  220. <input id="end_limit" type="checkbox" name="end_limit" onchange="disable_endtime(this)" <?php if ($year_end!="0000") echo "checked"; ?>/>
  221. <label for="end_limit">
  222. <?php echo get_lang('DateEndSession') ?>
  223. </label>
  224. <div id="end_date" style="<?php echo ($year_end=="0000") ? "display:none" : "display:block" ; ?>">
  225. <br />
  226. <select name="day_end" <?php echo $end_day_disabled; ?> >
  227. <option value="1">01</option>
  228. <option value="2" <?php if($day_end == 2) echo 'selected="selected"'; ?> >02</option>
  229. <option value="3" <?php if($day_end == 3) echo 'selected="selected"'; ?> >03</option>
  230. <option value="4" <?php if($day_end == 4) echo 'selected="selected"'; ?> >04</option>
  231. <option value="5" <?php if($day_end == 5) echo 'selected="selected"'; ?> >05</option>
  232. <option value="6" <?php if($day_end == 6) echo 'selected="selected"'; ?> >06</option>
  233. <option value="7" <?php if($day_end == 7) echo 'selected="selected"'; ?> >07</option>
  234. <option value="8" <?php if($day_end == 8) echo 'selected="selected"'; ?> >08</option>
  235. <option value="9" <?php if($day_end == 9) echo 'selected="selected"'; ?> >09</option>
  236. <option value="10" <?php if($day_end == 10) echo 'selected="selected"'; ?> >10</option>
  237. <option value="11" <?php if($day_end == 11) echo 'selected="selected"'; ?> >11</option>
  238. <option value="12" <?php if($day_end == 12) echo 'selected="selected"'; ?> >12</option>
  239. <option value="13" <?php if($day_end == 13) echo 'selected="selected"'; ?> >13</option>
  240. <option value="14" <?php if($day_end == 14) echo 'selected="selected"'; ?> >14</option>
  241. <option value="15" <?php if($day_end == 15) echo 'selected="selected"'; ?> >15</option>
  242. <option value="16" <?php if($day_end == 16) echo 'selected="selected"'; ?> >16</option>
  243. <option value="17" <?php if($day_end == 17) echo 'selected="selected"'; ?> >17</option>
  244. <option value="18" <?php if($day_end == 18) echo 'selected="selected"'; ?> >18</option>
  245. <option value="19" <?php if($day_end == 19) echo 'selected="selected"'; ?> >19</option>
  246. <option value="20" <?php if($day_end == 20) echo 'selected="selected"'; ?> >20</option>
  247. <option value="21" <?php if($day_end == 21) echo 'selected="selected"'; ?> >21</option>
  248. <option value="22" <?php if($day_end == 22) echo 'selected="selected"'; ?> >22</option>
  249. <option value="23" <?php if($day_end == 23) echo 'selected="selected"'; ?> >23</option>
  250. <option value="24" <?php if($day_end == 24) echo 'selected="selected"'; ?> >24</option>
  251. <option value="25" <?php if($day_end == 25) echo 'selected="selected"'; ?> >25</option>
  252. <option value="26" <?php if($day_end == 26) echo 'selected="selected"'; ?> >26</option>
  253. <option value="27" <?php if($day_end == 27) echo 'selected="selected"'; ?> >27</option>
  254. <option value="28" <?php if($day_end == 28) echo 'selected="selected"'; ?> >28</option>
  255. <option value="29" <?php if($day_end == 29) echo 'selected="selected"'; ?> >29</option>
  256. <option value="30" <?php if($day_end == 30) echo 'selected="selected"'; ?> >30</option>
  257. <option value="31" <?php if($day_end == 31) echo 'selected="selected"'; ?> >31</option>
  258. </select>
  259. /
  260. <select name="month_end" <?php echo $end_month_disabled; ?> >
  261. <option value="1">01</option>
  262. <option value="2" <?php if($month_end == 2) echo 'selected="selected"'; ?> >02</option>
  263. <option value="3" <?php if($month_end == 3) echo 'selected="selected"'; ?> >03</option>
  264. <option value="4" <?php if($month_end == 4) echo 'selected="selected"'; ?> >04</option>
  265. <option value="5" <?php if($month_end == 5) echo 'selected="selected"'; ?> >05</option>
  266. <option value="6" <?php if($month_end == 6) echo 'selected="selected"'; ?> >06</option>
  267. <option value="7" <?php if($month_end == 7) echo 'selected="selected"'; ?> >07</option>
  268. <option value="8" <?php if($month_end == 8) echo 'selected="selected"'; ?> >08</option>
  269. <option value="9" <?php if($month_end == 9) echo 'selected="selected"'; ?> >09</option>
  270. <option value="10" <?php if($month_end == 10) echo 'selected="selected"'; ?> >10</option>
  271. <option value="11" <?php if($month_end == 11) echo 'selected="selected"'; ?> >11</option>
  272. <option value="12" <?php if($month_end == 12) echo 'selected="selected"'; ?> >12</option>
  273. </select>
  274. /
  275. <select name="year_end" <?php echo $end_year_disabled; ?>>
  276. <?php
  277. for($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
  278. ?>
  279. <option value="<?php echo $i; ?>" <?php if($year_end == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
  280. <?php
  281. }
  282. ?>
  283. </select>
  284. <br /> <br />
  285. <?php echo get_lang('SessionVisibility') ?>
  286. <select name="session_visibility" style="width:250px;">
  287. <?php
  288. $visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('SessionReadOnly'), SESSION_VISIBLE=>get_lang('SessionAccessible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('SessionNotAccessible')));
  289. foreach($visibility_list as $key=>$item): ?>
  290. <option value="<?php echo $key; ?>" <?php if($key == $infos['visibility']) echo 'selected="selected"'; ?>><?php echo $item; ?></option>
  291. <?php endforeach; ?>
  292. </select>
  293. </div>
  294. </td>
  295. </tr>
  296. <tr>
  297. <td>&nbsp;</td>
  298. <td>
  299. <button class="save" type="submit" value="<?php echo get_lang('ModifyThisSession') ?>"><?php echo get_lang('ModifyThisSession') ?></button>
  300. </td>
  301. </tr>
  302. </table>
  303. </form>
  304. <script type="text/javascript">
  305. <?php if($year_start=="0000") echo "setDisable(document.form.nolimit);\r\n"; ?>
  306. function setDisable(select){
  307. document.form.day_start.disabled = (select.checked) ? true : false;
  308. document.form.month_start.disabled = (select.checked) ? true : false;
  309. document.form.year_start.disabled = (select.checked) ? true : false;
  310. document.form.day_end.disabled = (select.checked) ? true : false;
  311. document.form.month_end.disabled = (select.checked) ? true : false;
  312. document.form.year_end.disabled = (select.checked) ? true : false;
  313. document.form.session_visibility.disabled = (select.checked) ? true : false;
  314. document.form.session_visibility.selectedIndex = 0;
  315. document.form.start_limit.disabled = (select.checked) ? true : false;
  316. document.form.start_limit.checked = false;
  317. document.form.end_limit.disabled = (select.checked) ? true : false;
  318. document.form.end_limit.checked = false;
  319. var end_div = document.getElementById('end_date');
  320. end_div.style.display = 'none';
  321. var start_div = document.getElementById('start_date');
  322. start_div.style.display = 'none';
  323. }
  324. function disable_endtime(select) {
  325. var end_div = document.getElementById('end_date');
  326. if (end_div.style.display == 'none')
  327. end_div.style.display = 'block';
  328. else
  329. end_div.style.display = 'none';
  330. }
  331. function disable_starttime(select) {
  332. var start_div = document.getElementById('start_date');
  333. if (start_div.style.display == 'none')
  334. start_div.style.display = 'block';
  335. else
  336. start_div.style.display = 'none';
  337. }
  338. </script>
  339. <?php
  340. Display::display_footer();