Location: PHPKode > projects > News Publishing Content Management System > news-publishing-content-management-system/jpowered/newscms/admin/newsarticle.php
<?php 
require "./include/include.php";function articleindexpage($message) {$replacearray[0] = "[MESSAGE]";$replacearray[1] = $message;$replacearray[2] = "[ARTICLELIST]";$replacearray[3] = articleList();createPage("article",$replacearray);}function addArticle() {$subaction = "";if (array_key_exists("headline",   $_REQUEST))  {$subaction = "add";}switch ($subaction) {case "add": $article["headline"]   = stripslashes($_REQUEST["headline"]);$article["categoryid"] = $_REQUEST["category"];$article["templateid"] = 0;
$article["status"]     = $_REQUEST["status"];$articleplus["summary"]  = stripslashes($_REQUEST["summary"]);$articleplus["fulltext"] = stripslashes($_REQUEST["fulltext"]);$article["datecreated"]            = gmdate("Y-m-d H:i:s");$article["createdbyuserid"]        = $_SESSION['userid'];$article["lastmodifieddate"]       = gmdate("Y-m-d H:i:s");$article["lastmodifiedbyuserid"]   = $_SESSION['userid'];$article["nviews"]                 = 0;$article["lastresetdate"]          = gmdate("Y-m-d H:i:s");$article["filename"]               = " ";
$article["newsid"] = addRecord("articles",$article);$article["filename"] = "a".$article["newsid"].".jpf";updateRecord("articles",$article);createArticleFile($article["filename"],$articleplus);articleindexpage("News Article was added.");break;default: $replacearray[0] = "[CATEGORYOPTIONS]";$replacearray[1] = categoryOptions(0);$replacearray[2] = "[INSERTFCKEDITOR]";createPage("articleadd",$replacearray);}}function toggleArticleStatus() {$article = getRecordByID("articles",$_REQUEST["articleid"]);if ($article["newsid"]>0) {
if ($article["status"]>0) {$article["status"] = 0;}else {$article["status"] = 1;}updateRecord("articles",$article);}articleindexpage("");}function editArticle() {$subaction = "";if (array_key_exists("headline",   $_REQUEST))  {$subaction = "update";}$article = getRecordByID("articles",$_REQUEST["articleid"]);switch ($subaction) {case "update": $article["headline"]   = stripslashes($_REQUEST["headline"]);$article["categoryid"] = $_REQUEST["category"];$article["templateid"] = 0;$article["status"]     = $_REQUEST["status"];
$articleplus["summary"]  = stripslashes($_REQUEST["summary"]);$articleplus["fulltext"] = stripslashes($_REQUEST["fulltext"]);$article["lastmodifieddate"]       = gmdate("Y-m-d H:i:s");$article["lastmodifiedbyuserid"]   = $_SESSION['userid'];updateRecord("articles",$article);createArticleFile($article["filename"],$articleplus);articleindexpage("News Article was updated.");break;default: if ($article["newsid"]>0) {$articleplus = getArticleFile($article["filename"]);$replacearray[0]  = "[HEADLINE]";
$replacearray[1]  = $article["headline"];$replacearray[2]  = "[CATEGORYOPTIONS]";$replacearray[3]  = categoryOptions($article["categoryid"]);$replacearray[4]  = "[TEMPLATEID]";$replacearray[5]  = 0;$replacearray[6]  = "[STATUSOPTIONS]";$replacearray[7]  = statusOptions($article["status"]);$replacearray[8]  = "[SUMMARY]";$replacearray[9]  = $articleplus["summary"];$replacearray[10] = "[FULLTEXT]";$replacearray[11] = $articleplus["fulltext"];$replacearray[12] = "[ARTICLEID]";$replacearray[13] = $article["newsid"];
$replacearray[14] = "[INSERTFCKEDITOR]";$replacearray[15] = "[INSERTFCKEDITOR]";createPage("articleedit",$replacearray);}else {articleindexpage("Error: Article record could not be found");}}}function deleteArticle() {$subaction = "";if (array_key_exists("confirmdelete",   $_REQUEST))  {$subaction = "delete";}$article = getRecordByID("articles",$_REQUEST["articleid"]);switch ($subaction) {case "delete": deleteRecord("articles",$_REQUEST["articleid"]);deleteArticleFile($article["filename"]);articleindexpage("News Article was deleted.");
break;default: if ($article["newsid"]>0) {$articleplus = getArticleFile($article["filename"]);$replacearray[0]  = "[HEADLINE]";$replacearray[1]  = $article["headline"];$replacearray[2]  = "[SUMMARY]";$replacearray[3]  = $articleplus["summary"];$replacearray[4] = "[FULLTEXT]";$replacearray[5] = $articleplus["fulltext"];$replacearray[6] = "[ARTICLEID]";$replacearray[7] = $article["newsid"];createPage("articledelete",$replacearray);}else {articleindexpage("Error: Article record could not be found");
}}}function articleList() {$content = "";$articles = getAllRecords("articles","datecreated","datedesc");$rowcolor = "row1";for ($i=0;$i<count($articles);$i++) {if ($articles[$i]["newsid"]>0) {$category = getRecordByID("categories",$articles[$i]["categoryid"]);$statusimage = "green.gif";if ($articles[$i]["status"]>0) {$statusimage = "red.gif";}$content .= "<tr class='".$rowcolor."'>\n"."    <td align='left' colspan='5'>\n"."    <div align='left'><b>".$articles[$i]["headline"]."</b></div>\n"."    </td>\n".
"    <td align='right'>".$category["shortname"]."</td>\n"."</tr>\n"."<tr class='".$rowcolor."'>\n"."    <td align='center'> Status: <a href='newsarticle.php?action=status&amp;articleid=".$articles[$i]["newsid"]."'><img src='./images/".$statusimage."' width='15' height='15' border='0' alt='click to change status' align='absbottom'></a></td>\n"."    <td align='center'><a href='../index.php?frame=true&action=fullstory&articleid=".$articles[$i]["newsid"]."' target='_blank'>preview</a></td>\n"."    <td align='center'><a href='newsarticle.php?action=edit&amp;articleid=".$articles[$i]["newsid"]."'>edit</a></td>\n".
"    <td align='center'><a href='newsarticle.php?action=delete&amp;articleid=".$articles[$i]["newsid"]."'>delete</a></td>\n"."    <td align='center'>Views: ".$articles[$i]["nviews"]."</td>\n"."    <td align='right'>Date: ".$articles[$i]["datecreated"]."</td>\n"."</tr>\n";if (strcmp($rowcolor,"row1")==0) {$rowcolor = "row2";}else {$rowcolor = "row1";}}}return $content;}function categoryOptions($selectedid) {$cats = getAllRecords("categories","sortorder","numberasc");$content = 0;for ($i=0;$i<count($cats);$i++) {
if ($thisid != $cats[$i]["categoryid"]) {if ($selectedid == $cats[$i]["categoryid"]) {$content .= "<option value='".$cats[$i]["categoryid"]."' selected>".$cats[$i]["shortname"]."</option>\n";}else {$content .= "<option value='".$cats[$i]["categoryid"]."'>".$cats[$i]["shortname"]."</option>\n";}}}return $content;}function statusOptions($status) {if ($status<1) {$content = "<input type='radio' name='status' value='0' checked>\n"."Active\n"."<input type='radio' name='status' value='1'>\n"."Inactive \n";
}else {$content = "<input type='radio' name='status' value='0'>\n"."Active\n"."<input type='radio' name='status' value='1' checked>\n"."Inactive \n";}return $content;}getSystemParameters();$userid = testSession();if ($userid>0) { $_SESSION['adminmenu']->setSelect(2);$action = "";if (array_key_exists("action",   $_REQUEST))  {$action = $_REQUEST["action"];}switch ($action) {case "edit": editArticle();break;case "status": toggleArticleStatus();break;case "add": addArticle();break;case "delete": deleteArticle();
break;default: articleindexpage("");}}else { $errormessage = "";logonPage($errormessage);}
?>
Return current item: News Publishing Content Management System