PageRenderTime 32ms CodeModel.GetById 69ms RepoModel.GetById 1ms app.codeStats 0ms

/conference/admin/add_session.php

https://github.com/azeckoski/az-php-sandbox
PHP | 330 lines | 258 code | 39 blank | 33 comment | 37 complexity | c3024ecc5c0c984f29045f802162d4a9 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /* add_session.php
  3. * Created on May 10, 2006 by @author az - Aaron Zeckoski
  4. * Aaron Zeckoski (aaronz@vt.edu) - Virginia Tech (http://www.vt.edu/)
  5. * copyright 2006 Virginia Tech
  6. */
  7. ?>
  8. <?php
  9. require_once '../include/tool_vars.php';
  10. $PAGE_NAME = "Add Session";
  11. $Message = "";
  12. // connect to database
  13. require $ACCOUNTS_PATH.'sql/mysqlconnect.php';
  14. // check authentication
  15. require $ACCOUNTS_PATH.'include/check_authentic.php';
  16. // login if not autheticated
  17. require $ACCOUNTS_PATH.'include/auth_login_redirect.php';
  18. // Make sure user is authorized
  19. $allowed = 0; // assume user is NOT allowed unless otherwise shown
  20. if (!$User->checkPerm("admin_conference")) {
  21. $allowed = 0;
  22. $Message = "Only admins with <b>admin_conference</b> may view this page.<br/>" .
  23. "Try out this one instead: <a href='$TOOL_URL/'>$TOOL_NAME</a>";
  24. } else {
  25. $allowed = 1;
  26. }
  27. $roomPk = 0;
  28. $timeslotPk = 0;
  29. $conf_room = array();
  30. $conf_timeslot = array();
  31. $mins_used = 0;
  32. $mins_left = 0;
  33. if (!$_REQUEST['room'] || !$_REQUEST['time']) {
  34. $allowed = false;
  35. $Message = "Error: room and time must be set.<br/><a href='schedule.php'>Go Back</a>";
  36. } else {
  37. $roomPk = $_REQUEST['room'];
  38. $timeslotPk = $_REQUEST['time'];
  39. // fetch the room and time for the PKs
  40. $sql = "select * from conf_rooms where pk = '$roomPk'";
  41. $result = mysql_query($sql) or die("Room query failed ($sql): " . mysql_error());
  42. $conf_room = mysql_fetch_assoc($result);
  43. $sql = "select * from conf_timeslots where pk = '$timeslotPk'";
  44. $result = mysql_query($sql) or die("Timeslot query failed ($sql): " . mysql_error());
  45. $conf_timeslot = mysql_fetch_assoc($result);
  46. // find remaining time in this slot and room
  47. $sql = "select sum(CP.length) as mins_used from conf_proposals CP " .
  48. "join conf_sessions CS on CS.proposals_pk = CP.pk and " .
  49. "CS.rooms_pk='$roomPk' and CS.timeslots_pk='$timeslotPk'" .
  50. "where CP.confID = '$CONF_ID'";
  51. $result = mysql_query($sql) or die("Sessions fetch query failed ($sql): " . mysql_error());
  52. $conf_sessions = array();
  53. $row=mysql_fetch_assoc($result);
  54. $mins_used = $row['mins_used'];
  55. $mins_left = $conf_timeslot['length_mins'] - $mins_used;
  56. }
  57. // adding
  58. if ($_REQUEST['add'] && $allowed) {
  59. // write the new value to the sessions table
  60. if ($_REQUEST['proposals_pk']) {
  61. $proposalPk = $_REQUEST['proposals_pk'];
  62. $sql = "select * from conf_proposals where pk = '$proposalPk'";
  63. $result = mysql_query($sql) or die("Proposals fetch query failed ($sql): " . mysql_error());
  64. $proposal = mysql_fetch_assoc($result);
  65. // check for existing sessions in this timeslot
  66. // and check for this proposal in another slot already
  67. $sql = "select CS.*, CP.length from conf_sessions CS " .
  68. "join conf_proposals CP on CP.pk = CS.proposals_pk and CP.pk = '$proposalPk' " .
  69. "where CS.timeslots_pk = '$timeslotPk'";
  70. $result = mysql_query($sql) or die("Sessions fetch query failed ($sql): " . mysql_error());
  71. $conf_sessions = array();
  72. while($row=mysql_fetch_assoc($result)) { $conf_sessions[$row['pk']] = $row; }
  73. //echo "<pre>",print_r($conf_sessions),"</pre>";
  74. $new = true;
  75. $order = 0; // TODO - figure out ordering
  76. $error = false;
  77. if (count($conf_sessions) > 0) {
  78. $found_session = 0;
  79. $time_used = 0;
  80. foreach ($conf_sessions as $key=>$conf_session) {
  81. // check for this proposal in another timeslot
  82. if ($conf_session['proposals_pk'] == $proposalPk) {
  83. if ($conf_session['timeslots_pk'] == $timeslotPk) {
  84. // this session already exists in this timeslot
  85. $error = true;
  86. $Message = "Warning: This session already exists in this timeslot.";
  87. break;
  88. } else {
  89. // this session exists in another timeslot
  90. $found_session = $conf_session['pk']; // store the session pk
  91. continue;
  92. }
  93. }
  94. // count up the total time used in this slot
  95. $time_used += $conf_session['length'];
  96. }
  97. // do the length check
  98. echo "time_used: $time_used >= length:".$conf_timeslot['length_mins']."<br/>";
  99. if ($time_used >= $conf_timeslot['length_mins']) {
  100. $error = true;
  101. $Message = "Error: No more time remaining in this timeslot. You have to remove current proposals from this slot before you can add more.";
  102. }
  103. // do the session removal from the other timeslot
  104. if ($found_session > 0) {
  105. // remove this session so we can put this proposal somewhere else
  106. $sql = "DELETE from conf_sessions where pk = '$found_session'";
  107. $result = mysql_query($sql) or die("Sessions remove failed ($sql): " . mysql_error());
  108. $Message = "Moved proposal to new timeslot/room";
  109. }
  110. }
  111. if (!$error) {
  112. // update sql
  113. $sql = "UPDATE conf_sessions SET rooms_pk=$roomPk, timeslots_pk=$timeslotPk, " .
  114. "proposals_pk=$proposalPk, ordering=$order, title='' " .
  115. "WHERE pk = '$sessionPk'";
  116. if ($new) {
  117. // insert sql
  118. $sql = "INSERT INTO conf_sessions" .
  119. "(date_created, confID, rooms_pk, timeslots_pk, proposals_pk, ordering, title) " .
  120. "VALUES(NOW(), '$CONF_ID', '$roomPk', '$timeslotPk', '$proposalPk', $order, '')";
  121. }
  122. $result = mysql_query($sql) or die("Sessions query failed ($sql): " . mysql_error());
  123. if (mysql_affected_rows() > 0) {
  124. $Message = "Created new session for proposal";
  125. if ($Message) {
  126. $msg = "?msg=".$Message;
  127. }
  128. // redirect to the schedule page
  129. header('location:schedule.php'.$msg);
  130. exit;
  131. } else {
  132. $Message = "Error: Could not insert sessions record!";
  133. }
  134. }
  135. }
  136. }
  137. // fetch the proposals
  138. $sql = "select CP.*, CS.pk as sessions_pk, CT.start_time from conf_proposals CP " .
  139. "left join conf_sessions CS on CS.proposals_pk = CP.pk " .
  140. "left join conf_timeslots CT on CT.pk = CS.timeslots_pk " .
  141. "where CP.confID = '$CONF_ID' and CP.approved='Y' and CP.type != 'demo' and CP.type != 'poster' " .
  142. "order by track asc, order_num, length, title";
  143. $result = mysql_query($sql) or die("Fetch query failed ($sql): " . mysql_error());
  144. $conf_proposals = array();
  145. while($row=mysql_fetch_assoc($result)) { $conf_proposals[$row['pk']] = $row; }
  146. //echo "<pre>",print_r($conf_proposals),"</pre>";
  147. // custom CSS file
  148. $CSS_FILE = $ACCOUNTS_URL."/include/accounts.css";
  149. $CSS_FILE2 = $TOOL_URL."/include/schedule.css";
  150. $DATE_FORMAT = "M d, Y h:i A";
  151. // set header links
  152. $EXTRA_LINKS =
  153. "<br/><span style='font-size:9pt;'>" .
  154. "<a href='index.php'>Admin:</a> " .
  155. "<a href='attendees.php'>Attendees</a> - " .
  156. "<a href='proposals.php'>Proposals</a> - " .
  157. "<a href='check_in.php'>Check In</a> - " .
  158. "<a href='schedule.php'><strong>Schedule</strong></a> " .
  159. "</span>";
  160. ?>
  161. <?php include $ACCOUNTS_PATH.'include/top_header.php'; ?>
  162. <script type="text/javascript">
  163. <!--
  164. function orderBy(newOrder) {
  165. if (document.adminform.sortorder.value == newOrder) {
  166. document.adminform.sortorder.value = newOrder + " desc";
  167. } else {
  168. document.adminform.sortorder.value = newOrder;
  169. }
  170. document.adminform.submit();
  171. return false;
  172. }
  173. function setConfProposal(pk) {
  174. document.adminform.proposals_pk.value = pk;
  175. }
  176. // -->
  177. </script>
  178. <?php include $TOOL_PATH.'include/admin_header.php'; ?>
  179. <?= $Message ?>
  180. <?php
  181. // Put in footer and stop the rest of the page from loading if not allowed -AZ
  182. if (!$allowed) {
  183. include $TOOL_PATH.'include/admin_footer.php';
  184. exit;
  185. }
  186. ?>
  187. <form name="adminform" method="post" action="<?=$_SERVER['PHP_SELF']; ?>" style="margin:0px;">
  188. <input type="hidden" name="sortorder" value="<?= $sortorder ?>"/>
  189. <input type="hidden" name="room" value="<?= $roomPk ?>"/>
  190. <input type="hidden" name="time" value="<?= $timeslotPk ?>"/>
  191. <input type="hidden" name="proposals_pk" value=""/>
  192. <div class="filterarea">
  193. <table border=0 cellspacing=0 cellpadding=0 width="100%">
  194. <tr>
  195. <td nowrap="y"><b style="font-size:1.1em;">Info:</b></td>
  196. <td nowrap="y">
  197. <div style="float:left;">
  198. <strong><?= $CONF_NAME ?></strong>
  199. (<?= date($SHORT_DATE_FORMAT,strtotime($CONF_START_DATE)) ?> - <?= date($SHORT_DATE_FORMAT,strtotime($CONF_END_DATE)) ?>)
  200. </div>
  201. <div style="float:right; padding-right: 30px;">
  202. </td>
  203. <td nowrap="y">
  204. <strong>Room:</strong> <?= $conf_room['title'] ?>
  205. </td>
  206. <td nowrap="y">
  207. <strong>Timeslot:</strong> <?= date('D, M d, g:i a',strtotime($conf_timeslot['start_time'])) ?>
  208. </td>
  209. <td nowrap="y">
  210. <strong>Remaining:</strong> <?= $mins_left ?>
  211. </td>
  212. </tr>
  213. </table>
  214. </div>
  215. <table border="0" cellspacing="0" width="100%">
  216. <?php
  217. $line = 0;
  218. $last = 0;
  219. foreach ($conf_proposals as $proposal_pk=>$conf_proposal) {
  220. $line++;
  221. $linestyle = "oddrow";
  222. if (($line % 2) == 0) { $linestyle = "evenrow"; } else { $linestyle = "oddrow"; }
  223. $disabled = "";
  224. if ($conf_proposal['sessions_pk']) {
  225. $disabled = "disabled='Y'";
  226. $linestyle = "session_exists";
  227. }
  228. if ($conf_proposal['length'] > $mins_left) {
  229. $disabled = "disabled='Y'";
  230. }
  231. $current = $conf_proposal['track'];
  232. if ($line == 1 || $current != $last) {
  233. // next track, print the header again
  234. ?>
  235. <tr>
  236. <td class='time_header'><?= $current ?></td>
  237. <td class='schedule_header'>#</td>
  238. <td class='schedule_header'>Title</td>
  239. <td class='schedule_header'>Track</td>
  240. <td class='schedule_header'>Length</td>
  241. <td class='schedule_header'></td>
  242. </tr>
  243. <?php
  244. }
  245. $last = $current;
  246. ?>
  247. <tr class="<?= $linestyle ?>">
  248. <td class="grid">
  249. <input type="submit" <?= $disabled ?> name="add" value="add" onClick="setConfProposal('<?= $conf_proposal['pk'] ?>');" />
  250. </td><td><?=$conf_proposal['order_num']?></td>
  251. <td class="proposal_title">
  252. <label title="<?= str_replace("\"","'",htmlspecialchars($proposal['abstract'])) ?>">
  253. <?= $conf_proposal['title'] ?>
  254. </label>
  255. </td>
  256. <td class="session_date">
  257. <?= $conf_proposal['track'] ?>
  258. </td>
  259. <td class="grid">
  260. <?= $conf_proposal['length'] ?>
  261. </td>
  262. <td class="session_date">
  263. <?php
  264. if ($conf_proposal['start_time']) {
  265. echo date('D, M d, g:i a',strtotime($conf_proposal['start_time']));
  266. } else {
  267. echo "--";
  268. }
  269. ?>
  270. </td>
  271. </tr>
  272. <?php
  273. } // end foreach
  274. ?>
  275. </table>
  276. </form>
  277. <br/>
  278. <div class="right">
  279. <div class="rightheader">How to use the add session page</div>
  280. <div style="padding:3px;">
  281. <li>This page contains a full listing of all approved proposals</li>
  282. <li>Click the add button to create a session in the Room and Timeslot indicated at the top of the page</li>
  283. <li>Note that the time remaining in this timeslot is indicated in the upper right</li>
  284. <li>If a proposal is longer than the time remaining in this timeslot then the add button will be disabled</li>
  285. <li>If a proposal has already been added to a timeslot then the add button will be disabled and
  286. the <span class="session_exists">style will be different</span></li>
  287. </div>
  288. </div>
  289. <?php include $TOOL_PATH.'include/admin_footer.php'; ?>