Browse Source

Update to eventsystem to allow upload and display of thumbnails.

tags/rls1
kenn408k 6 years ago
parent
commit
f23541554a
7 changed files with 38 additions and 13 deletions
  1. 10
    6
      classes/alter.class.php
  2. 11
    2
      content/addevent.php
  3. 13
    2
      content/editevent.php
  4. 1
    1
      content/events.php
  5. 0
    1
      content/eventview.php
  6. 1
    0
      css/style.css
  7. 2
    1
      handleUpload.php

+ 10
- 6
classes/alter.class.php View File

37
 
37
 
38
     /* Event functions */
38
     /* Event functions */
39
 
39
 
40
-    public static function addEvent($title, $content, $type, $eventdate) {
40
+    public static function addEvent($title, $content, $type, $eventdate, $image) {
41
         $db = new DBClass();
41
         $db = new DBClass();
42
-        $sql = "INSERT INTO `events` (`id`, `title`, `img`, `type`, `description`, `time`) VALUES (NULL, '$title', 'image', '$type', '$content', '" . strtotime($eventdate) . "');";
42
+        $sql = "INSERT INTO `events` (`id`, `title`, `img`, `type`, `description`, `time`) VALUES (NULL, '$title', '$image', '$type', '$content', '" . strtotime($eventdate) . "');";
43
         $db->query($sql);
43
         $db->query($sql);
44
         header('Location: ' . Config::$sys_url . '?page=eventadmin');
44
         header('Location: ' . Config::$sys_url . '?page=eventadmin');
45
         die("Error, please enable browser-redirects.");
45
         die("Error, please enable browser-redirects.");
46
     }
46
     }
47
 
47
 
48
-    public static function editEvent($id, $title, $content, $type, $eventdate) {
48
+    public static function editEvent($id, $title, $content, $type, $eventdate, $image) {
49
         $db = new DBClass();
49
         $db = new DBClass();
50
-        $sql = "UPDATE `events` SET `title` = '$title', `img` = 'images', `type` = '$type', `time` = '" . strtotime($eventdate) . "', `description` = '$content' WHERE `events`.`id` = $id;";
50
+        if ($image != false) {
51
+            $sql = "UPDATE `events` SET `title` = '$title', `img` = '$image', `type` = '$type', `time` = '" . strtotime($eventdate) . "', `description` = '$content' WHERE `events`.`id` = $id;";
52
+        } else {
53
+            $sql = "UPDATE `events` SET `title` = '$title', `type` = '$type', `time` = '" . strtotime($eventdate) . "', `description` = '$content' WHERE `events`.`id` = $id;";
54
+        }
51
         $db->query($sql);
55
         $db->query($sql);
52
         header('Location: ' . Config::$sys_url . '?page=eventadmin');
56
         header('Location: ' . Config::$sys_url . '?page=eventadmin');
53
         die("Error, please enable browser redirects.");
57
         die("Error, please enable browser redirects.");
87
             return $db->query($sql);
91
             return $db->query($sql);
88
         }
92
         }
89
     }
93
     }
90
-    
91
-    public static function insertImage($filename,$mime) {
94
+
95
+    public static function insertImage($filename, $mime) {
92
         $db = new DBClass();
96
         $db = new DBClass();
93
         $time = new DateTime();
97
         $time = new DateTime();
94
         $sql = "INSERT INTO `uploads` (`id`, `filename`, `date`, `user`, `mime`) VALUES (NULL, '$filename', '" . $time->getTimestamp() . "', '" . $_SESSION['user'] . "', '" . $mime . "');";
98
         $sql = "INSERT INTO `uploads` (`id`, `filename`, `date`, `user`, `mime`) VALUES (NULL, '$filename', '" . $time->getTimestamp() . "', '" . $_SESSION['user'] . "', '" . $mime . "');";

+ 11
- 2
content/addevent.php View File

8
 Design::header($setup, 100);
8
 Design::header($setup, 100);
9
 
9
 
10
 if (isset($_POST['title'])) {
10
 if (isset($_POST['title'])) {
11
-    Alter::addEvent($_POST['title'], $_POST['textinput'], $_POST['type'], $_POST['eventdate']);
11
+    if (isset($_FILES['thumbnail'])) {
12
+        $uploaded = Upload::handleUpload($_FILES['thumbnail']);
13
+         if ($uploaded == false) {
14
+         // Fail!
15
+         }
16
+    }
17
+    Alter::addEvent($_POST['title'], $_POST['textinput'], $_POST['type'], $_POST['eventdate'], $uploaded);
12
 }
18
 }
13
 ?>
19
 ?>
14
 
20
 
17
     <div class="border"></div>
23
     <div class="border"></div>
18
     <br />
24
     <br />
19
     <div class='editorform'>
25
     <div class='editorform'>
20
-        <form method="POST" action="">
26
+        <form method="POST" action="" enctype="multipart/form-data">
21
             <input type="text" class='editformtitle' required placeholder='Nyhedstitel' name="title" />
27
             <input type="text" class='editformtitle' required placeholder='Nyhedstitel' name="title" />
22
             <br /><br />
28
             <br /><br />
29
+            <p>Thumbnail</p>
30
+            <input type="file" class='editformtitle' required name="thumbnail" />
31
+            <br /><br />
23
             <select class='editformtitle' name="type">
32
             <select class='editformtitle' name="type">
24
                 <option value="1">Event</option>
33
                 <option value="1">Event</option>
25
                 <option value="2">Baneaktivitet</option>
34
                 <option value="2">Baneaktivitet</option>

+ 13
- 2
content/editevent.php View File

19
 $result = Get::ViewEvent($_GET['id']);
19
 $result = Get::ViewEvent($_GET['id']);
20
 
20
 
21
 if (isset($_POST['title'])) {
21
 if (isset($_POST['title'])) {
22
-    Alter::editEvent($_GET['id'], $_POST['title'], $_POST['textinput'], $_POST['type'], $_POST['eventdate']);
22
+    if (isset($_FILES['thumbnail'])) {
23
+        $uploaded = Upload::handleUpload($_FILES['thumbnail']);
24
+         if ($uploaded == false) {
25
+         // Fail!
26
+         }
27
+    }
28
+    
29
+    
30
+    Alter::editEvent($_GET['id'], $_POST['title'], $_POST['textinput'], $_POST['type'], $_POST['eventdate'], $uploaded);
23
 }
31
 }
24
 ?>
32
 ?>
25
 
33
 
28
     <div class="border"></div>
36
     <div class="border"></div>
29
     <br />
37
     <br />
30
     <div class='editorform'>
38
     <div class='editorform'>
31
-        <form method="POST" action="">
39
+        <form method="POST" action="" enctype="multipart/form-data">
32
             <input type="text" class='editformtitle' required placeholder='Nyhedstitel' value="<?php echo $result['title']; ?>" name="title" />
40
             <input type="text" class='editformtitle' required placeholder='Nyhedstitel' value="<?php echo $result['title']; ?>" name="title" />
33
             <br /><br />
41
             <br /><br />
42
+            <p>Thumbnail (Intet valgt billede beholder nuværende)</p>
43
+            <input type="file" class='editformtitle' name="thumbnail" />
44
+            <br /><br />
34
             <select class='editformtitle' name="type">
45
             <select class='editformtitle' name="type">
35
                 <option <?php if ($result['type'] == 1) {
46
                 <option <?php if ($result['type'] == 1) {
36
     echo "selected";
47
     echo "selected";

+ 1
- 1
content/events.php View File

18
     foreach (Get::publicEventList() as $row) {
18
     foreach (Get::publicEventList() as $row) {
19
         ?>
19
         ?>
20
     <div class="eventslice">
20
     <div class="eventslice">
21
-        <div class="eventslice-top"><img src="img/ev/f1.jpg" alt="" /></div>
21
+        <div class="eventslice-top"><img src="<?php echo $row['img']; ?>" alt="" /></div>
22
         <div class="eventslice-middle"><?php echo $row['title']; ?></div>
22
         <div class="eventslice-middle"><?php echo $row['title']; ?></div>
23
         <div class="eventslice-bottom"><a href="?page=eventview&e=<?php echo $row['id']; ?>"><button>Læs Mere</button></a></div>
23
         <div class="eventslice-bottom"><a href="?page=eventview&e=<?php echo $row['id']; ?>"><button>Læs Mere</button></a></div>
24
     </div>
24
     </div>

+ 0
- 1
content/eventview.php View File

20
     <div class="border"></div>
20
     <div class="border"></div>
21
 
21
 
22
     <div class="newsbody">
22
     <div class="newsbody">
23
-        <img src="http://www.greetsparis.com/img/cms/GREETS-F1-header2.jpg" />
24
         <?php echo strip_tags($result['description'], '<br><p><b><i><u><img><a><strong><pre><em><span><div><h1><h2><h3><h4><h5><h6><h7><sub><sup><blockquote><code>'); ?>
23
         <?php echo strip_tags($result['description'], '<br><p><b><i><u><img><a><strong><pre><em><span><div><h1><h2><h3><h4><h5><h6><h7><sub><sup><blockquote><code>'); ?>
25
     </div>
24
     </div>
26
 </div>
25
 </div>

+ 1
- 0
css/style.css View File

399
 .eventslice-top img {
399
 .eventslice-top img {
400
     padding-left:5px;
400
     padding-left:5px;
401
     padding-right:5px;
401
     padding-right:5px;
402
+    width:320px;
402
     max-width:320px;
403
     max-width:320px;
403
 }
404
 }
404
 
405
 

+ 2
- 1
handleUpload.php View File

48
     $filetowrite = $imageFolder . $randomname .'.'. $extension;
48
     $filetowrite = $imageFolder . $randomname .'.'. $extension;
49
     move_uploaded_file($temp['tmp_name'], $filetowrite);
49
     move_uploaded_file($temp['tmp_name'], $filetowrite);
50
 
50
 
51
-    // Respond to the successful upload with JSON.
51
+    // Respond to the successful upload with JSON. - And add image to database.
52
+    Alter::insertImage($randomname . '.' . $extension, $temp['type']);
52
     echo json_encode(array('location' => Config::$sys_url . Config::$file_path . $randomname .'.'. $extension));
53
     echo json_encode(array('location' => Config::$sys_url . Config::$file_path . $randomname .'.'. $extension));
53
 } else {
54
 } else {
54
     // Notify editor that the upload failed
55
     // Notify editor that the upload failed

Loading…
Cancel
Save