inital git commit
[phpns.git] / manage.php
blobb0596912c56261a4d4011506d788730a5208971f
1 <?php
3 /* Copyright (c) 2007-08 Alec Henriksen
4 * phpns is free software; you can redistribute it and/or modify it under the
5 * terms of the GNU General Public Licence (GPL) as published by the Free
6 * Software Foundation; either version 2 of the Licence, or (at your option) any
7 * later version.
8 * Please see the GPL at http://www.gnu.org/copyleft/gpl.html for a complete
9 * understanding of what this license means and how to abide by it.
11 include("inc/init.php");
13 $globalvars['page_name'] = 'article management';
15 include("inc/header.php");
16 $do = $_GET['do'];
18 //determine pagintation variables and sorting
19 //init page
20 if (!@$_GET['page']) { $_GET['page'] = FALSE; }
21 $page = $_GET['page'];
22 if (!$page) {
23 $page = 1;
25 $items_per_page = 20;
26 $page_start = ($page*$items_per_page) - $items_per_page;
27 $next_page = $page + 1;
28 $prev_page = $page - 1;
29 //get sorting info and view
30 //init sort
31 if (!@$_GET['sort']) { $_GET['sort'] = FALSE; }
32 $sort = $_GET['sort'];
33 $v = $_GET['v'];
34 //END OF PAGINATION/SORTING
36 //we start the actual page generation. If there is no specific action being done ($do == ""), generate default view
37 if (!$do) {
39 //generate query, and execute function
40 $item_list = load_items('articles',$page_start,$items_per_page,$sort,$v);
42 if (mysql_num_rows($item_list) == NULL) { //if no results
43 $table_rows = '<td class="noresults" colspan="7"><strong>No returned results...</strong></td>';
46 while ($item_row = mysql_fetch_array($item_list)) { //for each item in db
47 //convert timestamp to readable/human date
48 $item_row['timestamp'] = date($globalvars['time_format'],$item_row['timestamp']);
49 $item_row['article_cat_name'] = gen_cat_name($item_row['article_cat']); //switch cat_id to readable name
50 $row_bg = ($row_bg == $globalvars['altcolor'][2]) ? $globalvars['altcolor'][1] : $globalvars['altcolor'][2]; //current row bg
52 //switch active column to yes, draft, or unapproved.
53 if ($item_row['active'] == 1) { $item_row['active'] = '<span class="positive">Yes</span>'; } elseif ($item_row['active'] == 0) { $item_row['active'] = '<span class="negative">Draft</span>'; }
54 if ($item_row['approved'] == 0) { $item_row['active'] = '<span class="negative">Unapproved</span>'; }
56 $item_row['comments'] = mysql_num_rows(general_query('SELECT * FROM '.$databaseinfo['prefix'].'comments WHERE article_id="'.$item_row['id'].'"'));
58 if (strlen($item_row['article_title']) > 30) {
59 $item_row['article_title'] = wordwrap($item_row['article_title'], 30, "<br />");
62 //generate the actual html rows
63 $table_rows = $table_rows.'<tr bgcolor="'.$row_bg.'">
64 <td>
65 <a href="article.php?id='.$item_row['id'].'&do=edit"><img src="images/icons/edit.png" class="row_icon" alt="edit icon" title="edit &quot;'.$item_row['article_title'].'&quot;" /></a>
66 <a href="article.php?id='.$item_row['id'].'&do=edit" title="edit &quot;'.$item_row['article_title'].'&quot;"><strong>'.$item_row['article_title'].'</strong></a>
67 </td>
68 <td><a href="manage.php?v='.$item_row['article_cat'].'">'.$item_row['article_cat_name'].'</a></td>
69 <td>'.$item_row['timestamp'].'</td>
70 <td><a href="manage.php?v='.$item_row['article_author'].'">'.$item_row['article_author'].'</a></td>
71 <td align="center"><a href="article.php?do=comments&id='.$item_row['id'].'">'.$item_row['comments'].'</a></td>
72 <td align="center">'.$item_row['active'].'</td>
73 <td class="checkbox"><input type="checkbox" value="'.$item_row['id'].'" name="'.$item_row['id'].'"></td></tr>';
74 } //end of each item in db generation
76 $content = manage_form(); //generate form
78 } elseif ($do == "deleteitems") { //if we're deleting items
80 //quick permission check (redir to error)
81 if ($globalvars['rank'][16] == 0) {
82 header("Location: index.php?do=permissiondenied");
83 die();
85 $items = $_POST; //get vars
86 if (!$items) { //if no items, avoid mysql error by just redirecting
87 header("Location: manage.php");
89 //we're going to create list of ids to be deleted from database.
90 foreach($items as $key=>$value) {
91 $items_f = $items_f."'$key',";
93 //remove last comma in list for SQL
94 $items_f = substr_replace($items_f,"",-1);
95 //delete the items in 'articles'
96 delete('articles',$items_f);
98 //log this action
99 log_this('delete_items','User <i>'.$_SESSION['username'].'</i> has <strong>deleted</strong> the following articles: "'.$items_f.'"');
101 //redirect back to manage.php
102 header("Location: manage.php?delete_success=1");
104 } elseif ($do == "search") { //search
105 $globalvars['page_name'] = 'search'; //set page name
107 //get query and category from POST or from GET
108 $search['query'] = $_POST['query'];
109 if ($search['query'] == "") { $search['query'] = $_GET['q']; }
110 $search['category'] = $_POST['category'];
111 if (!$search['category']) { $search['category'] = $_GET['c']; }
113 if ($search['query'] == "click here to start the search..." || $search['query'] == "") {
114 header("Location: manage.php");
117 $searchres = search($search); //form and execute search query/cat
118 //if no results
119 if (mysql_num_rows($searchres) == 0) { $table_rows = '<td class="noresults" colspan="7"><strong>No returned results...</strong></td>'; }
121 //for each item, generate html table row
122 while ($item_row = mysql_fetch_assoc($searchres)) {
123 //convert timestamp to readable/human date
124 $item_row['timestamp'] = date($globalvars['time_format'],$item_row['timestamp']);
125 $item_row['article_cat_name'] = gen_cat_name($item_row['article_cat']); //switch cat_id to readable name
126 $row_bg = ($row_bg == $globalvars['altcolor'][2]) ? $globalvars['altcolor'][1] : $globalvars['altcolor'][2]; //current row bg
128 //switch active column to yes, draft, or unapproved.
129 if ($item_row['active'] == 1) { $item_row['active'] = '<span class="positive">Yes</span>'; } elseif ($item_row['active'] == 0) { $item_row['active'] = '<span class="negative">Draft</span>'; }
130 if ($item_row['approved'] == 0) { $item_row['active'] = '<span class="negative">Unapproved</span>'; }
132 $item_row['comments'] = mysql_num_rows(general_query('SELECT * FROM '.$databaseinfo['prefix'].'comments WHERE article_id="'.$item_row['id'].'"'));
134 //generate the actual html rows
135 $table_rows = $table_rows.'<tr bgcolor="'.$row_bg.'">
136 <td>
137 <a href="article.php?id='.$item_row['id'].'&do=edit"><img src="images/icons/edit.png" class="row_icon" alt="edit icon" title="edit &quot;'.$item_row['article_title'].'&quot;" /></a>
138 <a href="article.php?id='.$item_row['id'].'&do=edit" title="edit &quot;'.$item_row['article_title'].'&quot;"><strong>'.$item_row['article_title'].'</strong></a>
139 </td>
140 <td><a href="manage.php?v='.$item_row['article_cat'].'">'.$item_row['article_cat_name'].'</a></td>
141 <td>'.$item_row['timestamp'].'</td>
142 <td><a href="manage.php?v='.$item_row['article_author'].'">'.$item_row['article_author'].'</a></td>
143 <td align="center"><a href="article.php?do=comments&id='.$item_row['id'].'">'.$item_row['comments'].'</a></td>
144 <td align="center">'.$item_row['active'].'</td>
145 <td class="checkbox"><input type="checkbox" value="'.$item_row['id'].'" name="'.$item_row['id'].'"></td></tr>';
146 } //end of table row creation
148 $content = manage_form();
149 } //end if main do (search elseif)
151 include("inc/themecontrol.php"); //include theme script