Browse Source

News now supports categories

tags/rls1
kenn408k 6 years ago
parent
commit
983f7b3db9
4 changed files with 35 additions and 7 deletions
  1. 7
    5
      classes/alter.class.php
  2. 11
    1
      content/addnews.php
  3. 15
    1
      content/editnews.php
  4. 2
    0
      content/newsadmin.php

+ 7
- 5
classes/alter.class.php View File

10
         
10
         
11
     }
11
     }
12
 
12
 
13
-    public static function addNews($author, $title, $content, $image) {
13
+    public static function addNews($author, $title, $content, $image, $type) {
14
         $db = new DBClass();
14
         $db = new DBClass();
15
         $time = new DateTime();
15
         $time = new DateTime();
16
-        $sql = "INSERT INTO `news` (`id`, `author`, `time`, `title`, `type`, `content`, `img`) VALUES (NULL, '$author', '" . $time->getTimestamp() . "', '$title', '1', '$content', '$image');";
16
+        $type = filter_var(trim($type), FILTER_SANITIZE_NUMBER_INT);
17
+        $sql = "INSERT INTO `news` (`id`, `author`, `time`, `title`, `type`, `content`, `img`) VALUES (NULL, '$author', '" . $time->getTimestamp() . "', '$title', '$type', '$content', '$image');";
17
         $db->query($sql);
18
         $db->query($sql);
18
         header('Location: ' . Config::$sys_url . '?page=newsadmin');
19
         header('Location: ' . Config::$sys_url . '?page=newsadmin');
19
         die("Error, please enable browser-redirects.");
20
         die("Error, please enable browser-redirects.");
20
     }
21
     }
21
 
22
 
22
-    public static function editNews($id, $title, $content, $image) {
23
+    public static function editNews($id, $title, $content, $image, $type) {
23
         $db = new DBClass();
24
         $db = new DBClass();
25
+        $type = filter_var(trim($type), FILTER_SANITIZE_NUMBER_INT);
24
         if ($image != false) {
26
         if ($image != false) {
25
-            $sql = "UPDATE `news` SET `title` = '$title', `img` = '$image', `content` = '$content' WHERE `news`.`id` = $id;";
27
+            $sql = "UPDATE `news` SET `title` = '$title', `img` = '$image', `content` = '$content', `type` = '$type' WHERE `news`.`id` = $id;";
26
         } else {
28
         } else {
27
-            $sql = "UPDATE `news` SET `title` = '$title', `content` = '$content' WHERE `news`.`id` = $id;";
29
+            $sql = "UPDATE `news` SET `title` = '$title', `content` = '$content', `type` = '$type' WHERE `news`.`id` = $id;";
28
         }
30
         }
29
         $db->query($sql);
31
         $db->query($sql);
30
         header('Location: ' . Config::$sys_url . '?page=newsadmin');
32
         header('Location: ' . Config::$sys_url . '?page=newsadmin');

+ 11
- 1
content/addnews.php View File

14
          // Fail!
14
          // Fail!
15
          }
15
          }
16
     }
16
     }
17
-    Alter::addNews($_SESSION['user'], $_POST['title'], $_POST['textinput'], $uploaded);
17
+    Alter::addNews($_SESSION['user'], $_POST['title'], $_POST['textinput'], $uploaded, $_POST['type']);
18
 }
18
 }
19
 ?>
19
 ?>
20
 
20
 
29
             <p>Thumbnail</p>
29
             <p>Thumbnail</p>
30
             <input type="file" class='editformtitle' required name="thumbnail" />
30
             <input type="file" class='editformtitle' required name="thumbnail" />
31
             <br /><br />
31
             <br /><br />
32
+            <select class='editformtitle' name="type">
33
+                <?php
34
+                $i = 0;
35
+                foreach (Config::$newscat as $key) {
36
+                    echo '<option value="'.$i.'">'.$key.'</option>';
37
+                    $i++;
38
+                }
39
+                ?>
40
+            </select>
41
+            <br /><br />
32
             <textarea name='textinput' class='editor'></textarea>
42
             <textarea name='textinput' class='editor'></textarea>
33
             <br />
43
             <br />
34
             <input type="submit" class='button btn btn-success pull_right' value="Tilføj" />
44
             <input type="submit" class='button btn btn-success pull_right' value="Tilføj" />

+ 15
- 1
content/editnews.php View File

29
          }
29
          }
30
     }
30
     }
31
     
31
     
32
-    Alter::editNews($_GET['id'], $_POST['title'], $_POST['textinput'], $uploaded);
32
+    Alter::editNews($_GET['id'], $_POST['title'], $_POST['textinput'], $uploaded, $_POST['type']);
33
 }
33
 }
34
 ?>
34
 ?>
35
 
35
 
44
             <p>Thumbnail</p>
44
             <p>Thumbnail</p>
45
             <input type="file" class='editformtitle' name="thumbnail" />
45
             <input type="file" class='editformtitle' name="thumbnail" />
46
             <br /><br />
46
             <br /><br />
47
+            <select class='editformtitle' name="type">
48
+                <?php
49
+                $i = 0;
50
+                foreach (Config::$newscat as $key) {
51
+                    if ($i == $result['type']) {
52
+                        echo '<option selected value="'.$i.'">'.$key.'</option>';
53
+                    } else {
54
+                    echo '<option value="'.$i.'">'.$key.'</option>';
55
+                    }
56
+                    $i++;
57
+                }
58
+                ?>
59
+            </select>
60
+            <br /><br />
47
             <textarea name='textinput' class='editor'><?php echo strip_tags($result['content'], '<br><p><b><i><u><img><a><strong><pre><em><span><div><h1><h2><h3><h4><h5><h6><h7><sub><sup><blockquote><code>'); ?></textarea>
61
             <textarea name='textinput' class='editor'><?php echo strip_tags($result['content'], '<br><p><b><i><u><img><a><strong><pre><em><span><div><h1><h2><h3><h4><h5><h6><h7><sub><sup><blockquote><code>'); ?></textarea>
48
             <br />
62
             <br />
49
             <input type="submit" class='button btn btn-success pull_right' value="Rediger" />
63
             <input type="submit" class='button btn btn-success pull_right' value="Rediger" />

+ 2
- 0
content/newsadmin.php View File

27
             <tr>
27
             <tr>
28
                 <th>ID</th>
28
                 <th>ID</th>
29
                 <th>Titel</th>
29
                 <th>Titel</th>
30
+                <th>Type</th>
30
                 <th>Dato</th>
31
                 <th>Dato</th>
31
                 <th>Indstillinger</th>
32
                 <th>Indstillinger</th>
32
             </tr>
33
             </tr>
36
                 <tr>
37
                 <tr>
37
                     <td><?php echo $row['id']; ?></td>
38
                     <td><?php echo $row['id']; ?></td>
38
                     <td><?php echo $row['title']; ?></td>
39
                     <td><?php echo $row['title']; ?></td>
40
+                    <td><?php echo Config::$newscat[$row['type']]; ?></td>
39
                     <td><?php echo date('H:i d/m-Y', $row['time']); ?></td>
41
                     <td><?php echo date('H:i d/m-Y', $row['time']); ?></td>
40
                     <td>
42
                     <td>
41
                         <a href="?page=editnews&id=<?php echo $row['id']; ?>"><button type="button" class="btn btn-primary"><i class="fa fa-pencil" title="Rediger artikel"></i></button></a>
43
                         <a href="?page=editnews&id=<?php echo $row['id']; ?>"><button type="button" class="btn btn-primary"><i class="fa fa-pencil" title="Rediger artikel"></i></button></a>

Loading…
Cancel
Save