Article Management'; require('../data/config.php'); require('includes/functions.php'); require('includes/header.php'); ?>

'; echo 'Click here to refresh the article list and close this window.'; tableClose(); } elseif ($_GET['action'] == 'edit' && hasAccess('articles', 'edit')) { $article_id = $_GET['id']; echo '
'; tableHeader('Edit Article'); $result = dbQuery("SELECT * FROM articles WHERE id=$article_id"); while ($row = mysql_fetch_object($result)) { echo '
Title
Short description
Article body
Toggle WYSIWYG editor
Category
Status
'; } tableClose(); echo '
'; echo '
'; } elseif ($_GET['action'] == 'preview' && hasAccess('articles', 'view')) { $id = $_GET['id']; $result = dbQuery("SELECT admins.username AS publisher, a.id, a.title, a.body, a.view_count, a.print_count, a.email_count, a.ratings_1, a.ratings_2, a.ratings_3, a.ratings_4, a.ratings_5, UNIX_TIMESTAMP(a.created) AS created, UNIX_TIMESTAMP(a.last_updated) AS last_updated, c.id AS cat_id, c.title AS category FROM admins, articles AS a, categories AS c WHERE a.id=$id AND a.cat_id=c.id AND a.admin_id=admins.id"); while ($row = mysql_fetch_object($result)) { $rating = getRating($row->ratings_1, $row->ratings_2, $row->ratings_3, $row->ratings_4, $row->ratings_5, 'Not yet rated'); tableHeader($row->title); echo nl2br($row->body); tableClose(); echo '
'; tableHeader('Document Information'); echo ' Published by: '.$row->publisher.'
Found in: '.$row->category.'
Created: '.date($cfg['date_format'], $row->created).'
Last updated: '.date($cfg['date_format'], $row->last_updated); tableClose(); echo '
'; tableHeader('Document Statistics'); echo ' Rating: '.$rating['standard'].'
Views: '.$row->view_count.'
Print count: '.$row->print_count.'
E-mail count: '.$row->email_count; tableClose(); echo '
'; } } elseif ($_GET['action'] == 'reset' && hasAccess('articles', 'edit') && notDemoAccess(true)) { $id = $_GET['id']; $type = $_GET['type']; if ($type == 'rating') { dbQuery("UPDATE articles SET ratings_1=0, ratings_2=0, ratings_3=0, ratings_4=0, ratings_5=0 WHERE id=$id"); dbQuery("DELETE FROM glossary WHERE article_id=$id"); } else { dbQuery("UPDATE articles SET $type=0 WHERE id=$id"); } tableHeader('Operation Successful'); echo 'The specified article statistic has been reset to 0 successfully!

'; echo 'Click here to refresh the article list and close this window.'; tableClose(); } if ($_POST['action'] == 'create' && hasAccess('categories', 'create') && notDemoAccess()) { $userid = $_SESSION['kbase_userid']; $title = mysql_escape_string($_POST['title']); $short_desc = mysql_escape_string($_POST['short_desc']); $body = mysql_escape_string($_POST['body']); $cat_id = $_POST['cat_id']; $status = $_POST['status']; $errmsg = ''; if (strlen($title) == 0) $errmsg = 'You did not enter a category name.'; elseif (strlen($body) == 0) $errmsg = 'You did not enter anything for the article body.'; if ($errmsg != '') { tableHeader('Oops!'); echo 'The new article could not be created for the following reason:

'; echo ''.$errmsg.'

'; echo 'Click here to return.'; tableClose(); } else { dbQuery("INSERT INTO articles(cat_id, admin_id, status, created, last_updated, title, short_desc, body) VALUES('$cat_id', '$userid', $status, NOW(), NOW(), '$title', '$short_desc', '$body')"); changeArticleCount($cat_id, 1); tableHeader('Operation Successful'); echo 'The new article has been created successfully!

'; echo 'Click here to continue.'; tableClose(); } } elseif ($_GET['action'] == 'new' && hasAccess('articles', 'create')) { $cat_id = ($_GET['cat_id'] != '') ? $_GET['cat_id'] : 0; $result = dbQuery('SELECT id FROM categories'); if (mysql_num_rows($result) == 0) { tableHeader('Oops!'); echo 'You have not created any categories yet. You cannot create an article until you have created at lease one category.

Click here if you would like to create one now.'; tableClose(); } else { echo '
'; tableHeader('Create New Article'); echo '
Publisher '.$_SESSION['kbase_username'].'
Title
Short description
Article body

Toggle WYSIWYG editor
Category
Status
'; tableClose(); echo '
'; echo '
'; } } elseif ($_GET['action'] == 'manage' && hasAccess('articles', 'view')) { $order = getOrderDetails('last_updated', 'DESC'); $nav = getNavInfo("SELECT id FROM articles WHERE status=1"); tableHeader('Manage Articles'); $result = dbQuery("SELECT (articles.ratings_1 + 2*articles.ratings_2 + 3*articles.ratings_3 + 4*articles.ratings_4 + 5*articles.ratings_5) / (articles.ratings_1 + articles.ratings_2 + articles.ratings_3 + articles.ratings_4 + articles.ratings_5) AS rating, articles.*, UNIX_TIMESTAMP(articles.last_updated) AS last_updated, admins.username AS publisher, categories.id AS cat_id, categories.title AS category FROM articles, admins, categories WHERE articles.admin_id=admins.id AND articles.cat_id=categories.id ORDER BY ".$order['by'].' '.$order['asc_desc']." LIMIT ".$nav['start'].", ".$cfg['per_page']); if ($nav['total'] > 0) { $page_nav = getPageNav($nav, 'articles', 'manage'); echo '
'.$nav['total'].' '.isPlural($nav['total'], 'articles', 'articles').' found. Displaying page '.$nav['page'].' of '.$nav['pages'].'
'.createGetFields(array('orderby', 'order')).' Sort results by in order:
'; $ctr = 0; while ($row = mysql_fetch_object($result)) { $rating = $row->rating; $rating = number_format($rating, 2); if ($rating == 0.00) { $rating = 'Not rated'; } echo ' '; } echo '
Article Title Category Publisher Rating Views Status Last Updated Options
'.$row->title.' '.$row->category.' '.$row->publisher.' '.$rating.' '.$row->view_count.' '.str_replace(array(0, 1), array('Hidden', 'Visible'), $row->status).' '.date($cfg['date_format'], $row->last_updated).'

With selected articles:
'; } else { echo 'No articles have been created yet.

Click here if you would like to create one now.'; } tableClose(); } elseif ($_POST['action'] == 'bulk_action' && notDemoAccess()) { $return_action = $_POST['return_action']; $bulk_action = $_POST['bulk_action']; $errmsg = ''; if (!$_POST['mark']) { tableHeader('Oops!'); echo 'Your action could not be performed for the following reason:

'; echo 'You did not select any articles. You must select at least one article.

'; echo 'Click here to return.'; tableClose(); } else { $id_list = implode(",", $_POST['mark']); if ($bulk_action == 'show' && hasAccess('articles', 'edit')) dbQuery("UPDATE articles SET status=1, last_updated=NOW() WHERE id IN ($id_list)"); elseif ($bulk_action == 'hide' && hasAccess('articles', 'edit')) dbQuery("UPDATE articles SET status=0, last_updated=NOW() WHERE id IN ($id_list)"); elseif ($bulk_action == 'delete' && hasAccess('articles', 'delete')) { foreach($_POST['mark'] as $article_id) { dbQuery("DELETE FROM comments WHERE article_id=$article_id"); dbQuery("DELETE FROM glossary WHERE article_id=$article_id"); $result = dbQuery("SELECT cat_id FROM articles WHERE id=$article_id"); while ($row = mysql_fetch_object($result)) { $cat_id = $row->cat_id; changeArticleCount($cat_id, -1); } } dbQuery("DELETE FROM articles WHERE id IN ($id_list)"); } tableHeader('Operation Successful'); echo 'Your action has been performed successfully!

'; echo 'Please click here to continue.'; tableClose(); } } ?>