PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/xy.php

https://github.com/xmarcosx/enroll
PHP | 446 lines | 414 code | 2 blank | 30 comment | 67 complexity | aecd2c35338d4a9fbf1955c6a8aadb48 MD5 | raw file
  1<!DOCTYPE html>
  2<?php
  3  session_start();
  4  //Credentials aren't legit or user isn't an admin, kick back to login screen
  5  if (!isset($_SESSION['username'])){
  6    $loggedin=false;
  7    $username=NULL;
  8  }
  9  else{
 10    $loggedin=true;
 11    $master_username=$_SESSION['username'];
 12    $ghostuser=$_SESSION['ghostuser'];
 13    if(!is_null($ghostuser))
 14      $username=$_SESSION['ghostuser'];
 15    else
 16      $username=$_SESSION['username'];
 17  }
 18  include_once 'admin/settings.php';
 19  //Connects to MySQL and Selects Database
 20  $con = mysql_connect($host,$db_username,$db_password);
 21  if (!$con)
 22    die('Could not connect: ' . mysql_error());
 23  //Select DB
 24  mysql_select_db($db, $con);
 25  //Get class levels
 26  $get_settings_result=mysql_query(
 27    "SELECT freshman,sophomore,junior,senior,
 28            xy_num_days_open,xy_time_open,xy_num_days_close,xy_time_close
 29     FROM settings
 30     LIMIT 1") or die(mysql_error());
 31  $get_settings_array=mysql_fetch_array($get_settings_result);
 32  $freshman=$get_settings_array['freshman'];
 33  $sophomore=$get_settings_array['sophomore'];
 34  $junior=$get_settings_array['junior'];
 35  $senior=$get_settings_array['senior'];
 36  //Get user's class level
 37  $class_level=null;
 38  $get_graduation_year_result=mysql_query(
 39      "SELECT graduation_year FROM users WHERE username='$username' LIMIT 1") or die(mysql_error());
 40  if (mysql_num_rows($get_graduation_year_result) > 0){
 41    $get_graduation_year_array=mysql_fetch_array($get_graduation_year_result);
 42    $graduation_year=$get_graduation_year_array['graduation_year'];
 43    if($graduation_year==$freshman)
 44      $class_level="freshman";
 45    elseif($graduation_year==$sophomore)
 46      $class_level="sophomore";
 47    elseif($graduation_year==$junior)
 48      $class_level="junior";
 49    elseif($graduation_year==$senior)
 50      $class_level="senior";
 51  }
 52  //Get next date for XY Courses
 53  $next_xy_result=mysql_query("SELECT id,date
 54                               FROM course_schedule
 55                               WHERE date >= " .  date('Y-m-d') . " AND (x=1 OR y=1)
 56                               ORDER BY date LIMIT 1") or die(mysql_error());
 57  if (mysql_num_rows($next_xy_result)==1){
 58    $next_xy_row=mysql_fetch_array($next_xy_result);
 59    $next_xy=$next_xy_row['date'];
 60    $next_xy_id=$next_xy_row['id'];
 61    //Grab all of the teacher's xy options for that date
 62    $result = mysql_query("SELECT users.lastname, users.firstname, assignments.id AS xyassnid,
 63                     courses.name, courses.description, courses.image, assignments.xy_block AS block, assignments.class_size,
 64                     courses.freshmen,courses.sophomores,courses.juniors,courses.seniors
 65              FROM `users`
 66              INNER JOIN `courses` on courses.teacher_id = users.id
 67              INNER JOIN `assignments` on assignments.course_id = courses.id
 68              WHERE assignments.final=1 AND assignments.xy_date_id=$next_xy_id AND courses.type='xy' ") or die(mysql_error());
 69    $chosen_xy_name=NULL;
 70    $chosen_xy_image=NULL;
 71    $chosen_xy_id=NULL;
 72    $chosen_xy_room=NULL;
 73    $chosen_x_name=NULL;
 74    $chosen_x_image=NULL;
 75    $chosen_x_id=NULL;
 76    $chosen_x_room=NULL;
 77    $chosen_y_name=NULL;
 78    $chosen_y_image=NULL;
 79    $chosen_y_id=NULL;
 80    $chosen_y_room=NULL;
 81    //If user is logged in
 82    if(isset($_SESSION['username'])){
 83      $chosen_xy_result=mysql_query("SELECT users.username, courses.name, courses.image, assignments.xy_block AS block, assignments.id, assignments.room
 84                                     FROM `users`
 85                                     INNER JOIN `enrollments` on enrollments.users_id=users.id
 86                                     INNER JOIN `assignments` on assignments.id=enrollments.assignments_id
 87                                     INNER JOIN `courses` on assignments.course_id = courses.id
 88                                     WHERE users.username='$username' AND assignments.xy_date_id=$next_xy_id ") or die(mysql_error());
 89      while($chosen_xy_row=mysql_fetch_array($chosen_xy_result)){
 90        if(strcmp($chosen_xy_row['block'],"xy") == 0){
 91          $chosen_xy_name=$chosen_xy_row['name'];
 92          $chosen_xy_image=$chosen_xy_row['image'];
 93          $chosen_xy_id=$chosen_xy_row['id'];
 94          $chosen_xy_room=$chosen_xy_row['room'];
 95        }
 96        elseif(strcmp($chosen_xy_row['block'],"x") == 0){
 97          $chosen_x_name=$chosen_xy_row['name'];
 98          $chosen_x_image=$chosen_xy_row['image'];
 99          $chosen_x_id=$chosen_xy_row['id'];
100          $chosen_x_room=$chosen_xy_row['room'];
101        }
102        else{
103          $chosen_y_name=$chosen_xy_row['name'];
104          $chosen_y_image=$chosen_xy_row['image'];
105          $chosen_y_id=$chosen_xy_row['id'];
106          $chosen_y_room=$chosen_xy_row['room'];
107        }
108      }
109    }
110  }
111  $xy_registration_open=false;
112  if(isset($next_xy)){
113    $xy_open=strtotime($next_xy) - ($get_settings_array['xy_num_days_open'] * 86400 + strtotime( $get_settings_array['xy_time_open']));
114    $xy_close=strtotime(date("Y-m-d", strtotime($next_xy) - $get_settings_array['xy_num_days_close'] * 86400) + $get_settings_array['xy_time_close'] );
115    if(time() >= $xy_open && time() < $xy_close)
116      $xy_registration_open=true;
117  }
118  $status=$_GET['status'];
119?>
120<html lang="en">
121  <head>
122    <meta charset="utf-8">
123    <title>Enroll: <?php echo $school_name; ?></title>
124    <meta name="viewport" content="width=device-width, initial-scale=1.0">
125    <meta name="description" content="Flexible Scheduling for Today's Classroom">
126    <meta name="author" content="Marcos Alcozer">
127    <meta name="keywords" content="Education, Scheduling">
128
129    <!-- Le styles -->
130    <style>
131      body {
132        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
133      }
134    </style>
135    <link href="css/wookmark.css" rel="stylesheet">
136    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
137    <link href="css/admin.css" rel="stylesheet">
138
139
140    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
141    <!--[if lt IE 9]>
142      <script src="../js/html5shiv.js"></script>
143    <![endif]-->
144  </head>
145  <body>
146    <?php include_once("admin/analyticstracking.php") ?>
147    <div class="navbar navbar-inverse navbar-fixed-top">
148      <div class="navbar-inner">
149        <div class="container">
150          <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
151            <span class="icon-bar"></span>
152            <span class="icon-bar"></span>
153            <span class="icon-bar"></span>
154          </button>
155          <a class="brand appname" href="#">Enroll<img src='img/beta-icon.png' style="vertical-align:text-top;"/></a>
156          <div class="nav-collapse collapse">
157            <ul class="nav">
158              <li class="active"><a href="xy.php">XY</a></li>
159              <li><a href="colloquium.php">Colloquium</a></li>
160            </ul>
161            <ul class="nav pull-right">
162              <?php if(!is_null($ghostuser)){ ?>
163                <li><a href="javascript:void(0)" onclick='ghost_user("<?php echo $master_username; ?>","admin");'><?php echo $master_username; ?></a></li>
164              <?php
165                }
166                if(!$loggedin)
167                  echo "<li class='login-button'><a href='login.html' style='color:#FFFFFF'>Login</a></li>";
168                else
169                  echo "<li class='login-button'><a href='logout.php' style='color:#FFFFFF'>Logout</a></li>";
170              ?>
171            </ul>
172          </div><!--/.nav-collapse -->
173        </div>
174      </div>
175      <?php if(!$status && !is_null($status)) { ?>
176      <div id="failed" class="alert alert-error text-center">
177        <button type="button" class="close" data-dismiss="alert">&times;</button>
178        Something went terribly wrong, please try again.
179      </div>
180      <?php }else if($status==1 && !is_null($status)) { ?>
181      <div id="success" class="alert alert-success text-center">
182        <button type="button" class="close" data-dismiss="alert">&times;</button>
183        You got it! Congrats!
184      </div>
185      <?php }else if($status==3 && !is_null($status)) { ?>
186      <div id="success" class="alert alert-info text-center">
187        <button type="button" class="close" data-dismiss="alert">&times;</button>
188        Oh no, so sorry, but that one has just filled up. Please select another.
189      </div>
190      <?php } ?>
191    </div>
192    <div class="container">
193      <?php
194        if(isset($next_xy)){
195          echo "<h1>XY for " . date('l F jS, Y', strtotime($next_xy)) . "</h1>";
196        }
197        else{
198          echo "<h1>No XY dates are currently set.</h1>";
199        }
200      ?>
201      <hr />
202      <!-- SHOW AGENDA IS USER IS LOGGED IN AND HAS ALREADY CHOSEN A X OR Y COURSE -->
203      <?php if(isset($_SESSION['username']) &&
204              (!is_null($chosen_xy_name) ||
205               !is_null($chosen_x_name) ||
206               !is_null($chosen_y_name)))
207            { ?>
208                <div class="row" style="min-height: 450px;">
209                <h2>Agenda</h2>
210                <ul id="tiles">
211                  <!-- IF USER HAS ALREADY CHOSEN AN XY -->
212                  <?php
213                    if(isset($chosen_xy_name))
214                    { ?>
215                      <div id="tile<?php echo $chosen_xy_id; ?>">
216                        <form id='remove<?php echo $chosen_xy_id; ?>' >
217                          <input name='type' type='hidden' value='xy' />
218                          <input name='courseid' type='hidden' value='<?php echo $chosen_xy_id; ?>' />
219                          <input name='username' type='hidden' value='<?php echo $username; ?>' />
220                        </form>
221                        <li>
222                          <?php if(isset($username) && $xy_registration_open){ ?>
223                            <i id="<?php echo $chosen_xy_id; ?>" class="icon-remove-sign remove_assignment"></i>
224                          <?php } ?>
225                          <img class="img-rounded" src="img/courses/<?php echo $chosen_xy_image; ?>" width="200"  />
226                          <p><?php echo $chosen_xy_name; ?></p>
227                          <p>Room <?php echo $chosen_xy_room; ?></p>
228                          <p>Spans both X and Y blocks.</p>
229                        </li>
230                      </div>
231              <?php }
232                    //IF USER HAS ALREADY CHOSEN AN X
233                    if(isset($chosen_x_name))
234                    { ?>
235                      <div id="tile<?php echo $chosen_x_id; ?>">
236                        <form id='remove<?php echo $chosen_x_id; ?>' >
237                          <input name='type' type='hidden' value='xy' />
238                          <input name='courseid' type='hidden' value='<?php echo $chosen_x_id; ?>' />
239                          <input name='username' type='hidden' value='<?php echo $username; ?>' />
240                        </form>
241                        <li>
242                          <?php if(isset($username) && $xy_registration_open){ ?>
243                            <i id="<?php echo $chosen_x_id; ?>" class="icon-remove-sign remove_assignment"></i>
244                          <?php } ?>
245                          <img class="img-rounded" src="img/courses/<?php echo $chosen_x_image; ?>" width="200"  />
246                          <p><?php echo $chosen_x_name; ?></p>
247                          <p>Room <?php echo $chosen_x_room; ?></p>
248                          <p>X Block</p>
249                        </li>
250                      </div>
251              <?php }
252                    //IF USER HAS ALREADY CHOSEN AN X
253                    if(isset($chosen_y_name))
254                    { ?>
255                      <div id="tile<?php echo $chosen_y_id; ?>">
256                        <form id='remove<?php echo $chosen_y_id; ?>' >
257                          <input name='type' type='hidden' value='xy' />
258                          <input name='courseid' type='hidden' value='<?php echo $chosen_y_id; ?>' />
259                          <input name='username' type='hidden' value='<?php echo $username; ?>' />
260                        </form>
261                        <li>
262                          <?php if(isset($username) && $xy_registration_open){ ?>
263                            <i id="<?php echo $chosen_y_id; ?>" class="icon-remove-sign remove_assignment"></i>
264                          <?php } ?>
265                          <img class="img-rounded" src="img/courses/<?php echo $chosen_y_image; ?>" width="200"  />
266                          <p><?php echo $chosen_y_name; ?></p>
267                          <p>Room <?php echo $chosen_y_room; ?></p>
268                          <p>Y Block</p>
269                        </li>
270                      </div>
271              <?php } ?>
272                </ul>
273            </div>
274      <?php } ?>
275    <!-- XY CHOICES -->
276    <div id='choices' class='row'>
277    <?php
278      if((is_null($chosen_xy_name) && is_null($chosen_x_name) && is_null($chosen_y_name)) ||
279         (is_null($chosen_xy_name) && is_null($chosen_y_name)) ||
280         (is_null($chosen_xy_name) && is_null($chosen_x_name)))
281      {
282    ?>
283          <!-- FILTER BETWEEN X AND Y COURSES-->
284          <?php if(is_null($chosen_x_name) &&
285                   is_null($chosen_y_name))
286                { ?>
287                  <ul id="filters" >
288                      <div><li data-filter="x"><h2>X Period</h2></li></div>
289                      <div><li data-filter="y"><h2>Y Period</h2></li></div>
290                  </ul>
291          <?php } ?>
292          <ul id="tiles">
293            <?php
294              while($row = mysql_fetch_array($result)){
295                if(($row['freshmen'] && strcmp($class_level,'freshman')==0) ||
296                   ($row['sophomore'] && strcmp($class_level,'sophomore')==0) ||
297                   ($row['junior'] && strcmp($class_level,'junior')==0) ||
298                   ($row['senior'] && strcmp($class_level,'senior')==0 ||
299                    !$loggedin))
300                {
301                  $xyassnid = $row['xyassnid'];
302                  $image = $row['image'];
303                  $name = $row['name'];
304                  $description = $row['description'];
305                  $lastname = $row['lastname'];
306                  $firstname = $row['firstname'];
307                  $block = $row['block'];
308                  $class_size = $row['class_size'];
309                  if(isset($_SESSION['username'])) {
310                    $spots_left_result=mysql_query("SELECT COUNT(*) AS count FROM `enrollments` WHERE assignments_id=$xyassnid") or die(mysql_error());
311                    $spots_left=0;
312                    if (mysql_num_rows($spots_left_result) > 0){
313                      $spots_left_array=mysql_fetch_array($spots_left_result);
314                      $spots_left=$class_size - $spots_left_array['count'];
315                    }
316                  }
317                  if(($spots_left > 0 || is_null($spots_left)) &&
318                    ((is_null($chosen_x_name) && strcmp($block, "x") == 0 && is_null($chosen_xy_name)) ||
319                     (is_null($chosen_y_name) && strcmp($block, "y") == 0 && is_null($chosen_xy_name)) ||
320                     (is_null($chosen_y_name) && is_null($chosen_x_name) && strcmp($block, "xy") == 0)) )
321                  {
322              ?>
323                    <li class="<?php if(strcmp($block, 'xy')==0){echo 'x y';}else{echo $block;} ?> card" value="<?php echo $xyassnid; ?>"  >
324                      <form action='enroll.php' method='post' >
325                        <input name='type' type='hidden' value='xy' />
326                        <input name='courseid' type='hidden' value='<?php echo $xyassnid; ?>' />
327                        <input name='username' type='hidden' value='<?php echo $username; ?>' />
328                        <input name='class_size' type='hidden' value='<?php echo $class_size; ?>' />
329                      <img class="img-rounded card-image" src="img/courses/<?php echo $image; ?>" width="200" id='<?php echo $cassnid; ?>' />
330                      <p><?php echo $name; ?></p>
331                      <p><?php echo $firstname . " " . $lastname; ?></p>
332                      <?php
333                        if(strcmp($block, 'xy')==0){
334                          echo "<p>Spans both X and  Y blocks.</p>";
335                        }
336                        else{
337                          echo "<p>" . strtoupper($block) . " Block</p>";
338                        }
339                      ?>
340                      <?php
341                        if(isset($_SESSION['username'])) {
342                          echo "<p>$spots_left Spots Left</p>";
343                        } ?>
344                      <p class="desc" id='<?php echo $xyassnid; ?>'>
345                        <?php echo substr($description, 0, 200); ?><span id="ellipses<?php echo $xyassnid; ?>">...</span><span id="description<?php echo $xyassnid; ?>" style="display: none;"><?php echo substr($description, 200); ?></span>
346                      </p>
347                      <div id='status<?php echo $xyassnid; ?>'></div>
348                      <?php
349                        if(isset($username) && $xy_registration_open)
350                          echo "<p><button class='btn btn-primary' type='submit' >Enroll</button></p>";
351                      ?>
352                      </form>
353                    </li>
354            <?php
355                  }
356                }
357              }
358              mysql_close();
359            ?>
360          </ul>
361<?php } ?>
362  </div>
363</div>
364    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
365    <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
366    <!-- <script src="js/bootstrap.min.js"></script> -->
367    <script src="js/jquery.wookmark.min.js"></script>
368    <script src="js/student.js"></script>
369    <!-- Once the images are loaded, initalize the Wookmark plug-in. -->
370    <script type="text/javascript">
371        $(document).ready(new function() {
372          // This filter is later used as the selector for which grid items to show.
373          var filter = '', handler;
374          // Prepare layout options.
375          var options = {
376            align: 'left',
377            autoResize: true, // This will auto-update the layout when the browser window is resized.
378            container: $('#choices'), // Optional, used for some extra CSS styling
379            offset: 15, // Optional, the distance between grid items
380            itemWidth: 210 // Optional, the width of a grid item
381          };
382          // This function filters the grid when a change is made.
383          var refresh = function() {
384            // This hides all grid items ("inactive" is a CSS class that sets opacity to 0).
385            $('#tiles li').addClass('inactive');
386            // Create a new layout selector with our filter.
387            handler = $(filter);
388            // This shows the items we want visible.
389            handler.removeClass("inactive");
390            // This updates the layout.
391            handler.wookmark(options);
392          }
393          /**
394           * This function checks all filter options to see which ones are active.
395           * If they have changed, it also calls a refresh (see above).
396           */
397          var updateFilters = function() {
398            var oldFilter = filter,
399                filters = [];
400            // Collect filter list.
401            var items = $('#filters li'),
402                i = 0, length = items.length, item;
403            for(; i < length; i++) {
404              item = items.eq(i);
405              if(item.hasClass('active')) {
406                filters.push('#tiles li.' + item.attr('data-filter'));
407              }
408            }
409            // If no filters active, set default to show all.
410            if (filters.length == 0) {
411              filters.push('#tiles li');
412            }
413            // Finalize our filter selector for jQuery.
414            filter = filters.join(', ');
415            // If the filter has changed, update the layout.
416            if(oldFilter != filter) {
417              refresh();
418            }
419          };
420          /**
421           * When a filter is clicked, toggle it's active state and refresh.
422           */
423          var onClickFilter = function(event) {
424            $('#filters li').removeClass('active');
425            $(event.currentTarget).toggleClass('active');
426            updateFilters();
427          }
428          // Capture filter click events.
429          $('#filters li').click(onClickFilter);
430          // Do initial update (shows all items).
431          updateFilters();
432
433          $(".desc").click(function(event){
434            $("#ellipses" + event.target.id).toggle();
435            $("#description" + event.target.id).toggle();
436            refresh();
437          });
438
439          $(".card-image").click(function(event){
440            $("#ellipses" + event.target.id).toggle();
441            $("#description" + event.target.id).toggle();
442            refresh();
443          });
444      </script>
445  </body>
446</html>