瀏覽代碼

Update to orderpage, now allows people to attend events.

tags/rls1
kenn408k 6 年之前
父節點
當前提交
51b3676abb
共有 4 個文件被更改,包括 101 次插入0 次删除
  1. 33
    0
      classes/alter.class.php
  2. 24
    0
      classes/get.class.php
  3. 2
    0
      content/eventadmin.php
  4. 42
    0
      content/order.php

+ 33
- 0
classes/alter.class.php 查看文件

@@ -69,6 +69,39 @@ class Alter {
69 69
         die("Error, please enable browser redirects.");
70 70
     }
71 71
 
72
+    /* Attendee functions */
73
+
74
+    public static function attentAdd($user, $event) {
75
+        // Add user to an event. And sanitize as we only want numbers.
76
+
77
+
78
+        $event = filter_var(trim($event), FILTER_SANITIZE_NUMBER_INT);
79
+        if (Get::attentDouble($user, $event) != true) {
80
+            $db = new DBClass();
81
+            $time = new DateTime();
82
+            $sql = "INSERT INTO `attendees` (`id`, `eventid`, `userid`, `time`) VALUES (NULL, '$event', '$user', '" . $time->getTimestamp() . "');";
83
+            return $db->query($sql);
84
+        }
85
+        header('Location: ' . Config::$sys_url . '?page=order&error=1');
86
+        die("Error, please enable browser redirects.");
87
+    }
88
+    
89
+    public static function attentDel($user, $event) {
90
+        // Add user to an event. And sanitize as we only want numbers.
91
+
92
+
93
+        $event = filter_var(trim($event), FILTER_SANITIZE_NUMBER_INT);
94
+        if (Get::attentDouble($user, $event) != false) {
95
+            $db = new DBClass();
96
+            $sql = "DELETE FROM `attendees` WHERE `attendees`.`userid` = $user AND `eventid` = $event";
97
+            return $db->query($sql);
98
+        }
99
+        header('Location: ' . Config::$sys_url . '?page=order&error=2');
100
+        die("Error, please enable browser redirects.");
101
+    }
102
+
103
+    /* User functions */
104
+
72 105
     public static function addUser($username, $password, $realname, $mail, $level) {
73 106
         if (Get::checkExists($username)) { // check if user exists
74 107
             // ERROR USER EXISTS

+ 24
- 0
classes/get.class.php 查看文件

@@ -91,6 +91,30 @@ class Get {
91 91
         return $db->fetchAll($db->query($sql));
92 92
     }
93 93
     
94
+    /* Attend functions */
95
+
96
+    public static function attentEventList() {
97
+        // Get list of events that havent already started
98
+        $db = new DBClass();
99
+        $time = new DateTime();
100
+        $sql = "SELECT * FROM `events` WHERE `time` > ".$time->getTimestamp()." AND `type` = 1 ORDER BY `time` ASC";
101
+        return $db->fetchAll($db->query($sql));
102
+    }
103
+    
104
+    public static function attentDouble($user,$event) {
105
+        // Checks if username already is in db, if not return false, if it exists return true
106
+        $db = new DBClass();
107
+        $sql = "SELECT * FROM `attendees` WHERE `userid` = $user AND `eventid` = $event";
108
+        if ($db->numRows($db->query($sql)) != 1) { return false; } else { return true; }
109
+    }
110
+    
111
+    public static function attendees($event) {
112
+        // Checks if username already is in db, if not return false, if it exists return true
113
+        $db = new DBClass();
114
+        $sql = "SELECT * FROM `attendees` WHERE `eventid` = $event";
115
+        return $db->numRows($db->query($sql));
116
+    }
117
+    
94 118
     /* Login and user functions */
95 119
 
96 120
     public static function checkExists($name) {

+ 2
- 0
content/eventadmin.php 查看文件

@@ -27,6 +27,7 @@ Design::header($setup, 100);
27 27
                 <th>ID</th>
28 28
                 <th>Type</th>
29 29
                 <th>Titel</th>
30
+                <th>Tilmeldte</th>
30 31
                 <th>Tidspunkt</th>
31 32
                 <th>Indstillinger</th>
32 33
             </tr>
@@ -37,6 +38,7 @@ Design::header($setup, 100);
37 38
                     <td><?php echo $row['id']; ?></td>
38 39
                     <td><?php if ($row['type'] == 1) {echo "Event";}else{echo "Aktivitet";} ?></td>
39 40
                     <td><?php echo $row['title']; ?></td>
41
+                    <td><?php echo Get::attendees($row['id']); ?></td>
40 42
                     <td><?php echo date('H:i d/m-Y', $row['time']); ?></td>
41 43
                     <td>
42 44
                         <a href="?page=editevent&id=<?php echo $row['id']; ?>"><button type="button" class="btn btn-primary"><i class="fa fa-pencil" title="Rediger artikel"></i></button></a>

+ 42
- 0
content/order.php 查看文件

@@ -5,6 +5,20 @@ $setup['headline'] = "Odense Track - Bestil";
5 5
 $setup['keywords'] = "bestil,bestilnu,betal,order";
6 6
 $setup['description'] = "Odense Track Bestillingsside";
7 7
 
8
+if (isset($_GET['rem'])) {
9
+    Alter::attentDel($_SESSION['user'],$_GET['rem']);
10
+    header('Location: '.Config::$sys_url.'?page=order&rel=success');
11
+    die();
12
+}
13
+
14
+if (isset($_GET['att'])) {
15
+    
16
+    Alter::attentAdd($_SESSION['user'],$_GET['att']);
17
+    
18
+    header('Location: '.Config::$sys_url.'?page=order&rel=success');
19
+    die();
20
+}
21
+
8 22
 Design::header($setup, 25);
9 23
 ?>
10 24
 
@@ -13,6 +27,34 @@ Design::header($setup, 25);
13 27
     <div class="border"></div>
14 28
     <br />
15 29
     <p>Bestil en billet til event.</p>
30
+    <?php
31
+    foreach (Get::attentEventList() as $row) {
32
+        ?>
33
+    
34
+        <div class="eventslice">
35
+        <div class="eventslice-top"><img src="<?php echo $row['img']; ?>" alt="" /></div>
36
+        <div class="eventslice-middle"><?php echo $row['title']; ?></div>
37
+        
38
+        <?php
39
+        if (Get::attentDouble($_SESSION['user'],$row['id']) == true){
40
+        ?>
41
+        <div class="eventslice-bottom"><a href="?page=order&rem=<?php echo $row['id']; ?>"><button>Afmeld</button></a></div>
42
+        <?php
43
+        } else {
44
+        ?>
45
+        <div class="eventslice-bottom"><a href="?page=order&att=<?php echo $row['id']; ?>"><button>Tilmeld</button></a></div>
46
+        <?php
47
+        }
48
+        ?>
49
+        
50
+        </div>
51
+        
52
+        
53
+        <?php
54
+    }
55
+    ?>
56
+    <div class="clear"></div>
57
+
16 58
 </div>
17 59
 
18 60
 <?php

Loading…
取消
儲存