Преглед изворни кода

News now supports categories

tags/rls1
kenn408k пре 6 година
родитељ
комит
983f7b3db9
4 измењених фајлова са 35 додато и 7 уклоњено
  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 Прегледај датотеку

@@ -10,21 +10,23 @@ class Alter {
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 14
         $db = new DBClass();
15 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 18
         $db->query($sql);
18 19
         header('Location: ' . Config::$sys_url . '?page=newsadmin');
19 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 24
         $db = new DBClass();
25
+        $type = filter_var(trim($type), FILTER_SANITIZE_NUMBER_INT);
24 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 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 31
         $db->query($sql);
30 32
         header('Location: ' . Config::$sys_url . '?page=newsadmin');

+ 11
- 1
content/addnews.php Прегледај датотеку

@@ -14,7 +14,7 @@ if (isset($_POST['title'])) {
14 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,6 +29,16 @@ if (isset($_POST['title'])) {
29 29
             <p>Thumbnail</p>
30 30
             <input type="file" class='editformtitle' required name="thumbnail" />
31 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 42
             <textarea name='textinput' class='editor'></textarea>
33 43
             <br />
34 44
             <input type="submit" class='button btn btn-success pull_right' value="Tilføj" />

+ 15
- 1
content/editnews.php Прегледај датотеку

@@ -29,7 +29,7 @@ if (isset($_POST['title'])) {
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,6 +44,20 @@ if (isset($_POST['title'])) {
44 44
             <p>Thumbnail</p>
45 45
             <input type="file" class='editformtitle' name="thumbnail" />
46 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 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 62
             <br />
49 63
             <input type="submit" class='button btn btn-success pull_right' value="Rediger" />

+ 2
- 0
content/newsadmin.php Прегледај датотеку

@@ -27,6 +27,7 @@ Design::header($setup, 100);
27 27
             <tr>
28 28
                 <th>ID</th>
29 29
                 <th>Titel</th>
30
+                <th>Type</th>
30 31
                 <th>Dato</th>
31 32
                 <th>Indstillinger</th>
32 33
             </tr>
@@ -36,6 +37,7 @@ Design::header($setup, 100);
36 37
                 <tr>
37 38
                     <td><?php echo $row['id']; ?></td>
38 39
                     <td><?php echo $row['title']; ?></td>
40
+                    <td><?php echo Config::$newscat[$row['type']]; ?></td>
39 41
                     <td><?php echo date('H:i d/m-Y', $row['time']); ?></td>
40 42
                     <td>
41 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…
Откажи
Сачувај