enroll /xy.php

Language PHP Lines 446
MD5 Hash aecd2c35338d4a9fbf1955c6a8aadb48
Repository https://github.com/xmarcosx/enroll.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<!DOCTYPE html>
<?php
  session_start();
  //Credentials aren't legit or user isn't an admin, kick back to login screen
  if (!isset($_SESSION['username'])){
    $loggedin=false;
    $username=NULL;
  }
  else{
    $loggedin=true;
    $master_username=$_SESSION['username'];
    $ghostuser=$_SESSION['ghostuser'];
    if(!is_null($ghostuser))
      $username=$_SESSION['ghostuser'];
    else
      $username=$_SESSION['username'];
  }
  include_once 'admin/settings.php';
  //Connects to MySQL and Selects Database
  $con = mysql_connect($host,$db_username,$db_password);
  if (!$con)
    die('Could not connect: ' . mysql_error());
  //Select DB
  mysql_select_db($db, $con);
  //Get class levels
  $get_settings_result=mysql_query(
    "SELECT freshman,sophomore,junior,senior,
            xy_num_days_open,xy_time_open,xy_num_days_close,xy_time_close
     FROM settings
     LIMIT 1") or die(mysql_error());
  $get_settings_array=mysql_fetch_array($get_settings_result);
  $freshman=$get_settings_array['freshman'];
  $sophomore=$get_settings_array['sophomore'];
  $junior=$get_settings_array['junior'];
  $senior=$get_settings_array['senior'];
  //Get user's class level
  $class_level=null;
  $get_graduation_year_result=mysql_query(
      "SELECT graduation_year FROM users WHERE username='$username' LIMIT 1") or die(mysql_error());
  if (mysql_num_rows($get_graduation_year_result) > 0){
    $get_graduation_year_array=mysql_fetch_array($get_graduation_year_result);
    $graduation_year=$get_graduation_year_array['graduation_year'];
    if($graduation_year==$freshman)
      $class_level="freshman";
    elseif($graduation_year==$sophomore)
      $class_level="sophomore";
    elseif($graduation_year==$junior)
      $class_level="junior";
    elseif($graduation_year==$senior)
      $class_level="senior";
  }
  //Get next date for XY Courses
  $next_xy_result=mysql_query("SELECT id,date
                               FROM course_schedule
                               WHERE date >= " .  date('Y-m-d') . " AND (x=1 OR y=1)
                               ORDER BY date LIMIT 1") or die(mysql_error());
  if (mysql_num_rows($next_xy_result)==1){
    $next_xy_row=mysql_fetch_array($next_xy_result);
    $next_xy=$next_xy_row['date'];
    $next_xy_id=$next_xy_row['id'];
    //Grab all of the teacher's xy options for that date
    $result = mysql_query("SELECT users.lastname, users.firstname, assignments.id AS xyassnid,
                     courses.name, courses.description, courses.image, assignments.xy_block AS block, assignments.class_size,
                     courses.freshmen,courses.sophomores,courses.juniors,courses.seniors
              FROM `users`
              INNER JOIN `courses` on courses.teacher_id = users.id
              INNER JOIN `assignments` on assignments.course_id = courses.id
              WHERE assignments.final=1 AND assignments.xy_date_id=$next_xy_id AND courses.type='xy' ") or die(mysql_error());
    $chosen_xy_name=NULL;
    $chosen_xy_image=NULL;
    $chosen_xy_id=NULL;
    $chosen_xy_room=NULL;
    $chosen_x_name=NULL;
    $chosen_x_image=NULL;
    $chosen_x_id=NULL;
    $chosen_x_room=NULL;
    $chosen_y_name=NULL;
    $chosen_y_image=NULL;
    $chosen_y_id=NULL;
    $chosen_y_room=NULL;
    //If user is logged in
    if(isset($_SESSION['username'])){
      $chosen_xy_result=mysql_query("SELECT users.username, courses.name, courses.image, assignments.xy_block AS block, assignments.id, assignments.room
                                     FROM `users`
                                     INNER JOIN `enrollments` on enrollments.users_id=users.id
                                     INNER JOIN `assignments` on assignments.id=enrollments.assignments_id
                                     INNER JOIN `courses` on assignments.course_id = courses.id
                                     WHERE users.username='$username' AND assignments.xy_date_id=$next_xy_id ") or die(mysql_error());
      while($chosen_xy_row=mysql_fetch_array($chosen_xy_result)){
        if(strcmp($chosen_xy_row['block'],"xy") == 0){
          $chosen_xy_name=$chosen_xy_row['name'];
          $chosen_xy_image=$chosen_xy_row['image'];
          $chosen_xy_id=$chosen_xy_row['id'];
          $chosen_xy_room=$chosen_xy_row['room'];
        }
        elseif(strcmp($chosen_xy_row['block'],"x") == 0){
          $chosen_x_name=$chosen_xy_row['name'];
          $chosen_x_image=$chosen_xy_row['image'];
          $chosen_x_id=$chosen_xy_row['id'];
          $chosen_x_room=$chosen_xy_row['room'];
        }
        else{
          $chosen_y_name=$chosen_xy_row['name'];
          $chosen_y_image=$chosen_xy_row['image'];
          $chosen_y_id=$chosen_xy_row['id'];
          $chosen_y_room=$chosen_xy_row['room'];
        }
      }
    }
  }
  $xy_registration_open=false;
  if(isset($next_xy)){
    $xy_open=strtotime($next_xy) - ($get_settings_array['xy_num_days_open'] * 86400 + strtotime( $get_settings_array['xy_time_open']));
    $xy_close=strtotime(date("Y-m-d", strtotime($next_xy) - $get_settings_array['xy_num_days_close'] * 86400) + $get_settings_array['xy_time_close'] );
    if(time() >= $xy_open && time() < $xy_close)
      $xy_registration_open=true;
  }
  $status=$_GET['status'];
?>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Enroll: <?php echo $school_name; ?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Flexible Scheduling for Today's Classroom">
    <meta name="author" content="Marcos Alcozer">
    <meta name="keywords" content="Education, Scheduling">

    <!-- Le styles -->
    <style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    <link href="css/wookmark.css" rel="stylesheet">
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
    <link href="css/admin.css" rel="stylesheet">


    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="../js/html5shiv.js"></script>
    <![endif]-->
  </head>
  <body>
    <?php include_once("admin/analyticstracking.php") ?>
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="brand appname" href="#">Enroll<img src='img/beta-icon.png' style="vertical-align:text-top;"/></a>
          <div class="nav-collapse collapse">
            <ul class="nav">
              <li class="active"><a href="xy.php">XY</a></li>
              <li><a href="colloquium.php">Colloquium</a></li>
            </ul>
            <ul class="nav pull-right">
              <?php if(!is_null($ghostuser)){ ?>
                <li><a href="javascript:void(0)" onclick='ghost_user("<?php echo $master_username; ?>","admin");'><?php echo $master_username; ?></a></li>
              <?php
                }
                if(!$loggedin)
                  echo "<li class='login-button'><a href='login.html' style='color:#FFFFFF'>Login</a></li>";
                else
                  echo "<li class='login-button'><a href='logout.php' style='color:#FFFFFF'>Logout</a></li>";
              ?>
            </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
      <?php if(!$status && !is_null($status)) { ?>
      <div id="failed" class="alert alert-error text-center">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        Something went terribly wrong, please try again.
      </div>
      <?php }else if($status==1 && !is_null($status)) { ?>
      <div id="success" class="alert alert-success text-center">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        You got it! Congrats!
      </div>
      <?php }else if($status==3 && !is_null($status)) { ?>
      <div id="success" class="alert alert-info text-center">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        Oh no, so sorry, but that one has just filled up. Please select another.
      </div>
      <?php } ?>
    </div>
    <div class="container">
      <?php
        if(isset($next_xy)){
          echo "<h1>XY for " . date('l F jS, Y', strtotime($next_xy)) . "</h1>";
        }
        else{
          echo "<h1>No XY dates are currently set.</h1>";
        }
      ?>
      <hr />
      <!-- SHOW AGENDA IS USER IS LOGGED IN AND HAS ALREADY CHOSEN A X OR Y COURSE -->
      <?php if(isset($_SESSION['username']) &&
              (!is_null($chosen_xy_name) ||
               !is_null($chosen_x_name) ||
               !is_null($chosen_y_name)))
            { ?>
                <div class="row" style="min-height: 450px;">
                <h2>Agenda</h2>
                <ul id="tiles">
                  <!-- IF USER HAS ALREADY CHOSEN AN XY -->
                  <?php
                    if(isset($chosen_xy_name))
                    { ?>
                      <div id="tile<?php echo $chosen_xy_id; ?>">
                        <form id='remove<?php echo $chosen_xy_id; ?>' >
                          <input name='type' type='hidden' value='xy' />
                          <input name='courseid' type='hidden' value='<?php echo $chosen_xy_id; ?>' />
                          <input name='username' type='hidden' value='<?php echo $username; ?>' />
                        </form>
                        <li>
                          <?php if(isset($username) && $xy_registration_open){ ?>
                            <i id="<?php echo $chosen_xy_id; ?>" class="icon-remove-sign remove_assignment"></i>
                          <?php } ?>
                          <img class="img-rounded" src="img/courses/<?php echo $chosen_xy_image; ?>" width="200"  />
                          <p><?php echo $chosen_xy_name; ?></p>
                          <p>Room <?php echo $chosen_xy_room; ?></p>
                          <p>Spans both X and Y blocks.</p>
                        </li>
                      </div>
              <?php }
                    //IF USER HAS ALREADY CHOSEN AN X
                    if(isset($chosen_x_name))
                    { ?>
                      <div id="tile<?php echo $chosen_x_id; ?>">
                        <form id='remove<?php echo $chosen_x_id; ?>' >
                          <input name='type' type='hidden' value='xy' />
                          <input name='courseid' type='hidden' value='<?php echo $chosen_x_id; ?>' />
                          <input name='username' type='hidden' value='<?php echo $username; ?>' />
                        </form>
                        <li>
                          <?php if(isset($username) && $xy_registration_open){ ?>
                            <i id="<?php echo $chosen_x_id; ?>" class="icon-remove-sign remove_assignment"></i>
                          <?php } ?>
                          <img class="img-rounded" src="img/courses/<?php echo $chosen_x_image; ?>" width="200"  />
                          <p><?php echo $chosen_x_name; ?></p>
                          <p>Room <?php echo $chosen_x_room; ?></p>
                          <p>X Block</p>
                        </li>
                      </div>
              <?php }
                    //IF USER HAS ALREADY CHOSEN AN X
                    if(isset($chosen_y_name))
                    { ?>
                      <div id="tile<?php echo $chosen_y_id; ?>">
                        <form id='remove<?php echo $chosen_y_id; ?>' >
                          <input name='type' type='hidden' value='xy' />
                          <input name='courseid' type='hidden' value='<?php echo $chosen_y_id; ?>' />
                          <input name='username' type='hidden' value='<?php echo $username; ?>' />
                        </form>
                        <li>
                          <?php if(isset($username) && $xy_registration_open){ ?>
                            <i id="<?php echo $chosen_y_id; ?>" class="icon-remove-sign remove_assignment"></i>
                          <?php } ?>
                          <img class="img-rounded" src="img/courses/<?php echo $chosen_y_image; ?>" width="200"  />
                          <p><?php echo $chosen_y_name; ?></p>
                          <p>Room <?php echo $chosen_y_room; ?></p>
                          <p>Y Block</p>
                        </li>
                      </div>
              <?php } ?>
                </ul>
            </div>
      <?php } ?>
    <!-- XY CHOICES -->
    <div id='choices' class='row'>
    <?php
      if((is_null($chosen_xy_name) && is_null($chosen_x_name) && is_null($chosen_y_name)) ||
         (is_null($chosen_xy_name) && is_null($chosen_y_name)) ||
         (is_null($chosen_xy_name) && is_null($chosen_x_name)))
      {
    ?>
          <!-- FILTER BETWEEN X AND Y COURSES-->
          <?php if(is_null($chosen_x_name) &&
                   is_null($chosen_y_name))
                { ?>
                  <ul id="filters" >
                      <div><li data-filter="x"><h2>X Period</h2></li></div>
                      <div><li data-filter="y"><h2>Y Period</h2></li></div>
                  </ul>
          <?php } ?>
          <ul id="tiles">
            <?php
              while($row = mysql_fetch_array($result)){
                if(($row['freshmen'] && strcmp($class_level,'freshman')==0) ||
                   ($row['sophomore'] && strcmp($class_level,'sophomore')==0) ||
                   ($row['junior'] && strcmp($class_level,'junior')==0) ||
                   ($row['senior'] && strcmp($class_level,'senior')==0 ||
                    !$loggedin))
                {
                  $xyassnid = $row['xyassnid'];
                  $image = $row['image'];
                  $name = $row['name'];
                  $description = $row['description'];
                  $lastname = $row['lastname'];
                  $firstname = $row['firstname'];
                  $block = $row['block'];
                  $class_size = $row['class_size'];
                  if(isset($_SESSION['username'])) {
                    $spots_left_result=mysql_query("SELECT COUNT(*) AS count FROM `enrollments` WHERE assignments_id=$xyassnid") or die(mysql_error());
                    $spots_left=0;
                    if (mysql_num_rows($spots_left_result) > 0){
                      $spots_left_array=mysql_fetch_array($spots_left_result);
                      $spots_left=$class_size - $spots_left_array['count'];
                    }
                  }
                  if(($spots_left > 0 || is_null($spots_left)) &&
                    ((is_null($chosen_x_name) && strcmp($block, "x") == 0 && is_null($chosen_xy_name)) ||
                     (is_null($chosen_y_name) && strcmp($block, "y") == 0 && is_null($chosen_xy_name)) ||
                     (is_null($chosen_y_name) && is_null($chosen_x_name) && strcmp($block, "xy") == 0)) )
                  {
              ?>
                    <li class="<?php if(strcmp($block, 'xy')==0){echo 'x y';}else{echo $block;} ?> card" value="<?php echo $xyassnid; ?>"  >
                      <form action='enroll.php' method='post' >
                        <input name='type' type='hidden' value='xy' />
                        <input name='courseid' type='hidden' value='<?php echo $xyassnid; ?>' />
                        <input name='username' type='hidden' value='<?php echo $username; ?>' />
                        <input name='class_size' type='hidden' value='<?php echo $class_size; ?>' />
                      <img class="img-rounded card-image" src="img/courses/<?php echo $image; ?>" width="200" id='<?php echo $cassnid; ?>' />
                      <p><?php echo $name; ?></p>
                      <p><?php echo $firstname . " " . $lastname; ?></p>
                      <?php
                        if(strcmp($block, 'xy')==0){
                          echo "<p>Spans both X and  Y blocks.</p>";
                        }
                        else{
                          echo "<p>" . strtoupper($block) . " Block</p>";
                        }
                      ?>
                      <?php
                        if(isset($_SESSION['username'])) {
                          echo "<p>$spots_left Spots Left</p>";
                        } ?>
                      <p class="desc" id='<?php echo $xyassnid; ?>'>
                        <?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>
                      </p>
                      <div id='status<?php echo $xyassnid; ?>'></div>
                      <?php
                        if(isset($username) && $xy_registration_open)
                          echo "<p><button class='btn btn-primary' type='submit' >Enroll</button></p>";
                      ?>
                      </form>
                    </li>
            <?php
                  }
                }
              }
              mysql_close();
            ?>
          </ul>
<?php } ?>
  </div>
</div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    <!-- <script src="js/bootstrap.min.js"></script> -->
    <script src="js/jquery.wookmark.min.js"></script>
    <script src="js/student.js"></script>
    <!-- Once the images are loaded, initalize the Wookmark plug-in. -->
    <script type="text/javascript">
        $(document).ready(new function() {
          // This filter is later used as the selector for which grid items to show.
          var filter = '', handler;
          // Prepare layout options.
          var options = {
            align: 'left',
            autoResize: true, // This will auto-update the layout when the browser window is resized.
            container: $('#choices'), // Optional, used for some extra CSS styling
            offset: 15, // Optional, the distance between grid items
            itemWidth: 210 // Optional, the width of a grid item
          };
          // This function filters the grid when a change is made.
          var refresh = function() {
            // This hides all grid items ("inactive" is a CSS class that sets opacity to 0).
            $('#tiles li').addClass('inactive');
            // Create a new layout selector with our filter.
            handler = $(filter);
            // This shows the items we want visible.
            handler.removeClass("inactive");
            // This updates the layout.
            handler.wookmark(options);
          }
          /**
           * This function checks all filter options to see which ones are active.
           * If they have changed, it also calls a refresh (see above).
           */
          var updateFilters = function() {
            var oldFilter = filter,
                filters = [];
            // Collect filter list.
            var items = $('#filters li'),
                i = 0, length = items.length, item;
            for(; i < length; i++) {
              item = items.eq(i);
              if(item.hasClass('active')) {
                filters.push('#tiles li.' + item.attr('data-filter'));
              }
            }
            // If no filters active, set default to show all.
            if (filters.length == 0) {
              filters.push('#tiles li');
            }
            // Finalize our filter selector for jQuery.
            filter = filters.join(', ');
            // If the filter has changed, update the layout.
            if(oldFilter != filter) {
              refresh();
            }
          };
          /**
           * When a filter is clicked, toggle it's active state and refresh.
           */
          var onClickFilter = function(event) {
            $('#filters li').removeClass('active');
            $(event.currentTarget).toggleClass('active');
            updateFilters();
          }
          // Capture filter click events.
          $('#filters li').click(onClickFilter);
          // Do initial update (shows all items).
          updateFilters();

          $(".desc").click(function(event){
            $("#ellipses" + event.target.id).toggle();
            $("#description" + event.target.id).toggle();
            refresh();
          });

          $(".card-image").click(function(event){
            $("#ellipses" + event.target.id).toggle();
            $("#description" + event.target.id).toggle();
            refresh();
          });
      </script>
  </body>
</html>
Back to Top