include_once "config.php"; // Forces user to be logged-in in order to view this page if (!$loggedIn) { include "login.php"; return; } // This sets the table that needs to be accessed. The reason for this is // that the link the user just clicked was for an article in an archive if (!empty($_POST['y'])) $db_year = $_POST['y']; else if (isset($_GET['y'])) $db_year = $_GET['y']; // If the year hasn't been set somewhere ($_POST, $_SESSION) then set to the current week's database if (!isset($db_year)) $dbName = 'mediawatch_articles'; // Otherwise, use the table name that has been posted to this page else $dbName = $db_year; $db['articles'] = new mysqlDatabase(DB_NAME, $dbName, DB_USER, DB_PASS, DATABASE_SERVER); $db['articles']->connect(); $db['logos']->connect(); $db['sources']->connect(); if (isset($_GET['article_id']) || $_POST['formName'] == 'createArticle') { include "../includes/post_parser.php"; $parser = new post_parser; } // Edit an article // Opens up the article from the database if (isset($_GET['article_id'])) { $db['articles']->buildSelectQuery('*', 'article_id='.$_GET['article_id']); $db['articles']->query(); $data = $db['articles']->getRow(); $data['body'] = $parser->unconvert(stripslashes($data['body'])); } // If the user created an article else if ($_POST['formName'] == 'createArticle') { $data['name'] = $_POST['name']; $data['ref'] = $_POST['ref']; $data['source_id'] = $_POST['source_id']; $data['body'] = $_POST['body']; $data['html'] = $_POST['html']; $data['date'] = $_POST['date']; // The article contains HTML? if ($data['html'] != 'yes') $data['html'] = 'no'; // build the date that the article is to be created on $data['date'] = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; if ($_POST['submit'] == 'Create') { // If there are no errors, then insert the article in the database if (empty($data['name'])) $errorMsg = "A name must be specified!"; else { $temp_source_id = $data['source_id']; $temp_date = $data['date']; $data['ref'] = addslashes($data['ref']); $data['name'] = addslashes($data['name']); $data['body'] = addslashes($parser->convert($data['body'])); $db['articles']->buildInsertQuery(array_keys($data), array_values($data)); $db['articles']->query(); unset($data); $data['source_id'] = $temp_source_id; $data['date'] = $temp_date; } } // If the user is modifying an existing article then update the article else if ($_POST['submit'] == 'Update') { $data['body'] = addslashes($parser->convert($data['body'])); $db['articles']->buildUpdateQuery(array_keys($data), array_values($data), 'article_id='.$_POST['article_id']); $db['articles']->query(); unset($data); } // Otherwise, the user must be deleting an existing article // So display the delete confirmation screen. else {?>