From be4f83cd2a17a0ec05f5bce50c91befaafaa6e0c Mon Sep 17 00:00:00 2001 From: jhunkeler Date: Sun, 20 Dec 2009 18:38:08 +0000 Subject: Test. git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@376 c5b2fb0a-d05d-0410-98c8-828840a80ff6 --- admin/pages/functions.php | 387 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 admin/pages/functions.php (limited to 'admin/pages/functions.php') diff --git a/admin/pages/functions.php b/admin/pages/functions.php new file mode 100644 index 0000000..5dd1d91 --- /dev/null +++ b/admin/pages/functions.php @@ -0,0 +1,387 @@ +. + */ + +/** + * Note to anyone feeling the need to edit this file... + * You MUST declare $db as global inside your functions in order access MySQL from here. + */ + +function ListArticles($pageid){ + + global $db; + $result = $db->Query("SELECT article_id,title FROM bayonet_articles WHERE `page_id` = $pageid ORDER BY `weight`"); + while(($row = $db->Fetch($result))!=false) + { + $articles[] = $row; + } + + echo ""; + + ?> + + + + +
+  Add New Article','?op=pages&edit='.$pageid.'&newarticle=true'); ?> +
No Articles Found.
"; + return; + } + foreach($articles as $article) + { + if($_GET['aid'] == $article['article_id']) + echo ''; + else + echo ''; + ?> + + ^ + + + + v + + + "; + + + +} + +function NewArticle($page_id) +{ + global $db; + if(isset($_POST['newarticleprocessed'])) + { + //Secure our data to prevent injection attacks. + $title = addslashes($_POST['title']); + $text = addslashes($_POST['text']); + if(empty($title) || empty($text)) + { + echo "You must fill everything out before proceeding."; + return; + } + $weight = 0; + $result = $db->Query("SELECT * FROM `bayonet_articles` WHERE `page_id` = $page_id ORDER BY `weight` DESC LIMIT 1"); + while(($row = $db->Fetch($result))!=false) + { + $weight = $row['weight']; + } + $weight++; + + //Update the database with the new data. + $db->Query("INSERT INTO `bayonet_articles` (`article_id` ,`page_id` ,`title` ,`text`, `weight`)VALUES (NULL , $page_id, '$title', '$text', '$weight')"); + echo "New article, '$title', has been added.\n"; + //die, because we have completed what we wanted to do. + return; + } + + ?> +

Add New Article

+
+ + + + +
Title:
+
+ Query("UPDATE bayonet_articles SET title = '$title', text = '$text' WHERE article_id = '$article_id'"); + echo "Article, '$title', has been edited.\n

Please wait while you are redirected.

+ Click here if you don't feel like waiting."; + + // 3 second redirect to go back to the edit page + //echo ""; + PageRedirect(3,"?op=pages&edit={$_GET['edit']}&aid={$article_id}"); + + //die, because we have completed what we wanted to do. + return; + } + + + //Grab the page from the database according to the $article_id passed to the function. + $result = $db->Query("SELECT title,text FROM bayonet_articles WHERE article_id = '$article_id'"); + while(($row = $db->Fetch($result))!=false) + { + //We only want one row, so we don't have to $article[]... No foreach necessary. + $article = $row; + } + + + ?> +
+ + + +
+ + + Delete This Article +
+
+ Query("SELECT title FROM bayonet_articles WHERE article_id = '$article_id'"); + $article = $db->Fetch($result); + + if(isset($_POST['proceed'])) + { + echo "Article '{$article['title']}', was deleted."; + $db->Query("DELETE FROM bayonet_articles WHERE article_id = '$article_id' LIMIT 1"); + return; + } + if(isset($_POST['cancel'])) + { + echo "User cancelled deletion of article: '{$article['title']}'"; + return; + } + ?> +
+ + + +
Are you SURE you want to delete the article titled: ''?
   
+
+ Query("SELECT page_id,title FROM bayonet_pages"); + while(($row = $db->Fetch($result))!=false) + { + $pages[] = $row; + } + + echo ""; + + ?> + + + + +
+  Create New Page','?op=pages&create=true'); ?> +
No Pages Found.
"; + return; + } + + foreach($pages as $page) + { + if($pid == $page['page_id']) + echo ''; + else + echo ''; + ?> + + + + + + + + + + + + +  View this Page','../index.php?load=page&id='.$pid); ?> + + + + +  Delete this Page','?op=pages&delete='.$pid); ?> + + + "; + +} + +function NewPage() +{ + global $db; + if(isset($_POST['newpageprocessed'])) + { + //Secure our data to prevent injection attacks. + $title = addslashes($_POST['title']); + if(empty($title)) + { + echo "You must fill everything out before proceeding."; + return; + } + + //Update the database with the new data. + $db->Query("INSERT INTO `bayonet_pages` (`page_id` ,`author_id` ,`page_created` ,`title` ,`text`)VALUES (NULL , '0',CURRENT_TIMESTAMP , '$title', '$text')"); + + echo "New page, '$title', has been added.\n"; + //die, because we have completed what we wanted to do. + return; + } + + ?> +

Add New Page

+
+ + + +
Title
+
+ Query("UPDATE bayonet_pages SET title = '$title' WHERE page_id = '$page_id'"); + echo "Page, '$title', has been edited.\n"; + //die, because we have completed what we wanted to do. + return; + } + +?> + + + + + + + + +
+ + + + + 0){ + EditArticle($aid); + } + ?> +
+ Query("SELECT title FROM bayonet_pages WHERE page_id = '$page_id'"); + $page = $db->Fetch($result); + + if(isset($_POST['proceed'])) + { + echo "Page '{$page['title']}', was deleted."; + $db->Query("DELETE FROM bayonet_pages WHERE page_id = '$page_id' LIMIT 1"); + return; + } + if(isset($_POST['cancel'])) + { + echo "User cancelled deletion of page: '{$page['title']}'"; + return; + } + if($page_id == 1){ + echo "You can not delete the home page."; + return; + } + + ?> + +
+ + + +
Are you SURE you want to delete the page titled: ''?
All articles attached to this page will be deleted as well.
   
+
+ \ No newline at end of file -- cgit