aboutsummaryrefslogtreecommitdiff
path: root/admin
diff options
context:
space:
mode:
authorjhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6>2009-12-27 10:44:57 -0500
committerjhunkeler <jhunkeler@c5b2fb0a-d05d-0410-98c8-828840a80ff6>2009-12-27 10:44:57 -0500
commitd526decc4884710ae7fafe7aa5171e7f59b24292 (patch)
tree12c07f3ef6ab9bf5a4f278a7b00720996c41667d /admin
parent07253dc75c69cf585ad39a218f3f2cf97b773987 (diff)
downloadbayonetcms-d526decc4884710ae7fafe7aa5171e7f59b24292.tar.gz
MySQL -> MySQLi
Fixed memory leaks after Fetching arrays Removed all while loops that interfaced with $db->Fetch() Rewrote RSS module Fixed syntax error in donations module Fixed link structure for news module Reverting to old page display method git-svn-id: http://svn.3rd-infantry-division.org/testing/branches/Bayonet CMS v2@402 c5b2fb0a-d05d-0410-98c8-828840a80ff6
Diffstat (limited to 'admin')
-rw-r--r--admin/admins/functions.php5
-rw-r--r--admin/announcements/functions.php8
-rw-r--r--admin/blocks/functions.php12
-rw-r--r--admin/calendar/functions.php25
-rw-r--r--admin/functions.php7
-rw-r--r--admin/index.php2
-rw-r--r--admin/modules/functions.php11
-rw-r--r--admin/navigation/functions.php5
-rw-r--r--admin/news/functions.php39
-rw-r--r--admin/newsreel/functions.php47
-rw-r--r--admin/newsreel/updateDB.php3
-rw-r--r--admin/pages/functions.php116
12 files changed, 133 insertions, 147 deletions
diff --git a/admin/admins/functions.php b/admin/admins/functions.php
index 8987322..563b507 100644
--- a/admin/admins/functions.php
+++ b/admin/admins/functions.php
@@ -44,10 +44,7 @@
{
global $db;
$result = $db->Query("SELECT `user_id`, `username`, `level` FROM `bayonet_users` ORDER BY `level` DESC, `username` ASC");
- while(($rows = $db->fetch($result))!=false)
- {
- $admins[] = $rows;
- }
+ $admins = $db->fetch($result);
$num = 1;
OpenTable("300px");
diff --git a/admin/announcements/functions.php b/admin/announcements/functions.php
index 2e55125..917e342 100644
--- a/admin/announcements/functions.php
+++ b/admin/announcements/functions.php
@@ -52,11 +52,9 @@ function EditAnnouncements()
//Grab the page from the database according to the $article_id passed to the function.
$result = $db->Query("SELECT title,text FROM bayonet_announcements WHERE announcement_id = 0");
- while(($row = $db->Fetch($result))!=false)
- {
- //We only want one row, so we don't have to $article[]... No foreach necessary.
- $announcement = $row;
- }
+ /** FIXME - this probably broke. */
+ $announcement = $db->Fetch($result);
+
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table>
diff --git a/admin/blocks/functions.php b/admin/blocks/functions.php
index ad7daa0..aaa7f36 100644
--- a/admin/blocks/functions.php
+++ b/admin/blocks/functions.php
@@ -21,10 +21,8 @@ function ListBlocks()
{
global $db;
$result = $db->Query("SELECT * FROM `bayonet_blocks` ORDER BY `active` DESC, `weight` ASC, `position`");
- while(($rows = $db->fetch($result))!=false)
- {
- $blocks[] = $rows;
- }
+ $blocks = $db->Fetch($result);
+
echo "<table align=\"center\"><tr><th colspan=\"3\">Existing Blocks</th></tr>";
foreach($blocks as $block)
@@ -121,11 +119,7 @@ function EditBlock($block_id)
//Grab the page from the database according to the $page_id passed to the function.
$result = $db->Query("SELECT weight,dir_name,position,active,title FROM bayonet_blocks WHERE block_id = '$block_id'");
- while(($row = $db->Fetch($result))!=false)
- {
- //We only want one row, so we don't have to $block[]... No foreach necessary.
- $block = $row;
- }
+ $block = $db->FetchRow($result);
?>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
diff --git a/admin/calendar/functions.php b/admin/calendar/functions.php
index 8d1d6a1..9983870 100644
--- a/admin/calendar/functions.php
+++ b/admin/calendar/functions.php
@@ -90,25 +90,26 @@
echo "<table width=\"100%\">";
$result = $db->Query("SELECT * FROM bayonet_events WHERE `date` = '$date' ORDER BY `time`");
- while(($row = $db->Fetch($result))!=false)
+ $row = $db->Fetch($result);
+ foreach($row as $event)
{
$tmp = true;
- $datetime = date_create($date.' '.$row['time']);
- $time = date_format($datetime, 'g:ia'); //gets time in hour:minutes am|pm
+ $datetime = date_create($date.' '.$event['time']);
+ $time = date_format($datetime, 'g:ia'); //gets time in hour:minutes am|pm
?>
<tr>
- <td><strong><?php echo $time." - ".$row['title']; ?></strong></td>
- <td><span style="border:1px solid black;background-color:<?php echo $row['color'];?>;">&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
+ <td><strong><?php echo $time." - ".$event['title']; ?></strong></td>
+ <td><span style="border:1px solid black;background-color:<?php echo $event['color'];?>;">&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
<td>
- <a href="?op=calendar&month=<?php echo $_GET['month']; ?>&year=<?php echo $_GET['year']; ?>&edit=<?php echo $row['event_id'];?>">Edit</a>
+ <a href="?op=calendar&month=<?php echo $_GET['month']; ?>&year=<?php echo $_GET['year']; ?>&edit=<?php echo $event['event_id'];?>">Edit</a>
&nbsp;|&nbsp;
- <a href="?op=calendar&delete=<?php echo $row['event_id']; ?>">Delete</a>
+ <a href="?op=calendar&delete=<?php echo $event['event_id']; ?>">Delete</a>
</td>
</tr>
<tr>
- <td><?php echo BBCode($row['text']); ?><br /><br /></td>
+ <td><?php echo BBCode($event['text']); ?><br /><br /></td>
</tr>
<tr>
@@ -116,7 +117,6 @@
</tr>
<?php
}
-
if(!isset($tmp))
echo "<tr><td>There are no events posted for this day.</td></tr>";
@@ -391,10 +391,9 @@ $db->Query("UPDATE `bayonet_events` SET `title` = '$title', `text` = '$text', `c
} */
global $db;
$result = $db->Query("SELECT title,color FROM bayonet_events WHERE `date` = '$sqlDate' LIMIT 1");
- while(($row = $db->Fetch($result))!=false)
- {
- $isEvent = true;
- }
+ $events = $db->Fetch($result);
+ $isEvent = empty($events) ? false : true;
+
if($useCurDate)
echo "<a href=\"?op=calendar&list={$year}-{$monthNum}-{$day_num}\">";
else
diff --git a/admin/functions.php b/admin/functions.php
index 07bc20b..9b950c4 100644
--- a/admin/functions.php
+++ b/admin/functions.php
@@ -526,12 +526,7 @@ function GetBlocks($position = BLOCK_LEFT)
$db->Select_db($config['sql']['database']);
$result = $db->Query("SELECT * FROM `bayonet_blocks` ORDER BY weight, position");
- //$result = mysql_query("SELECT * FROM bayonet_blocks ORDER BY weight, position");
- while(($row = $db->Fetch($result))!==false)
- {
- $blocks[] = $row;
- }
- $db->Free($result);
+ $blocks = $db->Fetch($result);
foreach($blocks as $block)
{
diff --git a/admin/index.php b/admin/index.php
index fea8112..754ef89 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -22,7 +22,7 @@ session_start();
include '../includes/debug.php';
include '../includes/config.php';
include '../includes/sql.class.php';
-include 'functions.php';
+include '../includes/functions.php';
$db = new Bayonet_SQL();
$db->Connect(
diff --git a/admin/modules/functions.php b/admin/modules/functions.php
index 619efc7..3c44b5a 100644
--- a/admin/modules/functions.php
+++ b/admin/modules/functions.php
@@ -21,10 +21,7 @@ function ListModules()
{
global $db;
$result = $db->Query("SELECT * FROM `bayonet_blocks` ORDER BY `active` DESC, `weight` ASC, `position`");
- while(($rows = $db->fetch($result))!=false)
- {
- $blocks[] = $rows;
- }
+ $blocks = $db->fetch($result);
echo "<table align=\"center\"><tr><th colspan=\"3\">Existing Blocks</th></tr>";
foreach($blocks as $block)
@@ -121,11 +118,7 @@ function EditModule($module_id)
//Grab the page from the database according to the $page_id passed to the function.
$result = $db->Query("SELECT weight,dir_name,position,active,title FROM bayonet_blocks WHERE block_id = '$block_id'");
- while(($row = $db->Fetch($result))!=false)
- {
- //We only want one row, so we don't have to $block[]... No foreach necessary.
- $block = $row;
- }
+ $block = $db->Fetch($result)
?>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
diff --git a/admin/navigation/functions.php b/admin/navigation/functions.php
index 29aa10f..2287944 100644
--- a/admin/navigation/functions.php
+++ b/admin/navigation/functions.php
@@ -26,10 +26,7 @@ function ListNavigation(){
global $db;
$result = $db->Query("SELECT `nav_id`, `title`, `weight` FROM `bayonet_navigation` ORDER BY `weight`");
- while(($row = $db->Fetch($result))!=false)
- {
- $data[] = $row;
- }
+ $data = $db->Fetch($result);
echo "|0|Home|0|<br />";
diff --git a/admin/news/functions.php b/admin/news/functions.php
index 1f9e34a..75b52e3 100644
--- a/admin/news/functions.php
+++ b/admin/news/functions.php
@@ -25,19 +25,22 @@ function ListNews(){
"FROM `bayonet_news` AS n ".
"INNER JOIN `bayonet_news_categories` AS c ON c.category_id = n.category_id ".
"LEFT OUTER JOIN `mybb_users` AS u ON u.uid = n.author_id ORDER BY `date` DESC");
- while($row = $db->Fetch($result)){
- $newsBody = $row['message'];
- echo "<a href=\"?op=news&edit={$row['news_id']}\">";
- echo "<span class=\"bold\">{$row['title']}</span>&nbsp;|&nbsp;<span class=\"blue\">{$row['catname']}</span>&nbsp;&nbsp;<img src=\"images/page.png\" /></a><br />";
- if(($len = strlen($newsBody))>150)
- echo substr($newsBody, 0, 150)."...";
- else
- echo $newsBody;
- echo '<br />';
- echo "Posted By: {$row['author']} on ".date('D M j, Y g:i a T', strtotime($row['date']));
- echo '<br /><br />';
+ $row = $db->Fetch($result);
+ foreach($row as $news)
+ {
+ $newsBody = $news['message'];
+ echo "<a href=\"?op=news&edit={$row['news_id']}\">";
+ echo "<span class=\"bold\">{$row['title']}</span>&nbsp;|&nbsp;<span class=\"blue\">{$row['catname']}</span>&nbsp;&nbsp;<img src=\"images/page.png\" /></a><br />";
+ if(($len = strlen($newsBody))>150)
+ echo substr($newsBody, 0, 150)."...";
+ else
+ echo $newsBody;
+ echo '<br />';
+ echo "Posted By: {$row['author']} on ".date('D M j, Y g:i a T', strtotime($news['date']));
+ echo '<br /><br />';
}
+
}
function EditNews($news_id){
@@ -51,7 +54,7 @@ function EditNews($news_id){
}
$result = $db->Query("SELECT `author_id`, `title`, `message`, `date`, `category_id` FROM `bayonet_news` WHERE `news_id` = '$news_id' LIMIT 1");
- $row = $db->Fetch($result);
+ $row = $db->FetchRow($result);
?>
<h3>Edit News</h3>
@@ -118,12 +121,22 @@ function EditNews($news_id){
echo "<select name=\"author\">";
$result = $db->Query("SELECT `user_id`, `lastname` FROM `bayonet_users` ORDER BY `username` ASC");
- while(($row = $db->Fetch($result))!= false){
+ $row = $db->Fetch($result);
+ foreach($row as $author)
+ {
+ if($author_id == $author['user_id'])
+ echo "<option value=\"{$author['user_id']}\" selected>{$author['lastname']}</option>";
+ else
+ echo "<option value=\"{$author['user_id']}\">{$author['lastname']}</option>";
+ }
+ /** FIXME
+ while(($row = $db->Fetch($result))!= false){
if($author_id == $row['user_id'])
echo "<option value=\"{$row['user_id']}\" selected>{$row['lastname']}</option>";
else
echo "<option value=\"{$row['user_id']}\">{$row['lastname']}</option>";
}
+ */
echo "</select>";
}
diff --git a/admin/newsreel/functions.php b/admin/newsreel/functions.php
index 8423b9b..9dece93 100644
--- a/admin/newsreel/functions.php
+++ b/admin/newsreel/functions.php
@@ -58,22 +58,24 @@ $(document).ready(function(){
function EditOrder(){
global $db;
-
- echo "<div id=\"contentLeft\">
+ ?>
+ <div id="contentLeft">
<table>
<tr>
<th>News Reel Order</th>
- <td id=\"updateStatus\"></td>
+ <td id="updateStatus"></td>
</tr>
</table>
- <ul>";
-
+ <ul>
+ <?php
$result = $db->Query("SELECT `title`, `slide_id`, `src` FROM `bayonet_newsreel` WHERE `visible` = 1 ORDER BY `weight` ASC");
- while(($row = $db->fetch($result))!= false){
- echo "<li id=\"recordsArray_{$row['slide_id']}\">";
- PrintSlide($row);
- echo "<br /><a href=\"?op=newsreel&disable={$row['slide_id']}\"><input type=\"button\" value=\"Disable\" /></a></li>";
- }
+ $row = $db->Fetch($result);
+
+ foreach($row as $slide){
+ echo "<li id=\"recordsArray_{$slide['slide_id']}\">";
+ PrintSlide($slide);
+ echo "<br /><a href=\"?op=newsreel&disable={$slide['slide_id']}\"><input type=\"button\" value=\"Disable\" /></a></li>";
+ }
?>
</ul>
Click and drag on a slide to change the order. Wait for confirmation indicating the changes have been saved.
@@ -99,6 +101,11 @@ $(document).ready(function(){
global $db;
echo "Disable: ".$slide_id;
+ $result = $db->Query("SELECT `weight` FROM `bayonet_newsreel` WHERE `slide_id` = '$slide_id' LIMIT 1");
+ $row = $db->Fetch($result);
+ foreach($row as $slide){
+ $oldWeight = $slide['weight'];
+ }
$db->Query("UPDATE `bayonet_newsreel` SET `visible` = 0, `weight` = 0 WHERE `slide_id` = '$slide_id' LIMIT 1");
PageRedirect(0,"?op=newsreel");
}
@@ -107,12 +114,13 @@ $(document).ready(function(){
global $db;
echo "<h3>Disabled Slides</h3>";
- $result = $db->query("SELECT `slide_id`, `title`, `src` FROM `bayonet_newsreel` WHERE `visible` = 0 ORDER BY `slide_id` DESC");
- while(($row = $db->fetch($result))!= false){
-
- echo PrintSlide($row);
- echo "<br /><a href=\"?op=newsreel&enable={$row['slide_id']}\"><input type=\"button\" value=\"Enable\" /></a><br /><br />";
- }
+ $result = $db->Query("SELECT `slide_id`, `title`, `src` FROM `bayonet_newsreel` WHERE `visible` = 0 ORDER BY `slide_id` DESC");
+ $row = $db->Fetch($result);
+
+ foreach($row as $slide){
+ echo PrintSlide($slide);
+ echo "<br /><a href=\"?op=newsreel&enable={$slide['slide_id']}\"><input type=\"button\" value=\"Enable\" /></a><br /><br />";
+ }
}
function PrintSlide($slide){
@@ -125,9 +133,12 @@ $(document).ready(function(){
function GetLastPosition(){
global $db;
- $result = $db->query("SELECT `weight` FROM `bayonet_newsreel` ORDER BY `weight` DESC LIMIT 1");
+ $result = $db->Query("SELECT `weight` FROM `bayonet_newsreel` WHERE `visible` = 1 ORDER BY `weight` DESC LIMIT 1");
$row = $db->Fetch($result);
- return $row['weight'];
+ foreach($row as $slide){
+ $weight = $slide['weight'];
+ }
+ return $weight;
}
diff --git a/admin/newsreel/updateDB.php b/admin/newsreel/updateDB.php
index 904e578..f4031a2 100644
--- a/admin/newsreel/updateDB.php
+++ b/admin/newsreel/updateDB.php
@@ -3,7 +3,7 @@
include '../../includes/debug.php';
include '../../includes/config.php';
include '../../includes/sql.class.php';
-include '../functions.php';
+include '../../includes/functions.php';
$action = $_POST['action'];
$updateRecordsArray = $_POST['recordsArray'];
@@ -22,7 +22,6 @@ if ($action == "updateReelOrder"){
foreach ($updateRecordsArray as $recordIDValue) {
$db->Query("UPDATE `bayonet_newsreel` SET `weight` = '$listingCounter' WHERE `slide_id` = '$recordIDValue'");
- //mysql_query($query) or die('Error, insert query failed');
$listingCounter = $listingCounter + 1;
}
echo "<img src=\"images/accepted.png\" />";
diff --git a/admin/pages/functions.php b/admin/pages/functions.php
index 15b1f0c..7152546 100644
--- a/admin/pages/functions.php
+++ b/admin/pages/functions.php
@@ -22,52 +22,48 @@
* 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 "<table class=\"panelitems\" width=\"100%\" cellspacing=\"0\">";
-
- ?>
+function ListArticles($pageid)
+{
+ global $db;
+ $result = $db->Query("SELECT article_id,title FROM bayonet_articles WHERE `page_id` = $pageid ORDER BY `weight`");
+ $articles = $row = $db->Fetch($result);
+
+ echo "<table class=\"panelitems\" width=\"100%\" cellspacing=\"0\">";
+
+ ?>
<tr>
- <td colspan="3" style="text-align:center; text-overflow:ellipsis; overflow:hidden; background-color:#dfe4df; border-bottom: 1px solid #848484;">
+ <td colspan="3" style="text-align:center; text-overflow:ellipsis; overflow:hidden; background-color:#dfe4df; border-bottom: 1px solid #848484;">
<?php echo LinkInternal('<img src="images/add.png" />&nbsp;Add New Article','?op=pages&edit='.$pageid.'&newarticle=true'); ?>
- </td>
+ </td>
</tr>
-
- <?php
+
+ <?php
- if(count($articles)==0){
- echo "<tr><td>No Articles Found.<br /></td></tr></table>";
- return;
- }
- foreach($articles as $article)
- {
- if($_GET['aid'] == $article['article_id'])
- echo '<tr class="highlight">';
- else
- echo '<tr>';
- ?>
-
- <td>^</td>
- <td style="text-align:center; text-overflow:ellipsis; overflow:hidden;">
+ if(count($articles)==0)
+ {
+ echo "<tr><td>No Articles Found.<br /></td></tr></table>";
+ return;
+ }
+
+ foreach($articles as $article)
+ {
+ if($_GET['aid'] == $article['article_id'])
+ echo '<tr class="highlight">';
+ else
+ echo '<tr>';
+ ?>
+
+ <td>^</td>
+ <td style="text-align:center; text-overflow:ellipsis; overflow:hidden;">
<a href="?op=pages&edit=<?php echo $pageid; ?>&aid=<?php echo $article['article_id']?>"><?php echo $article['title']; ?></a>
- </td>
- <td>v</td>
- </tr>
+ </td>
+ <td>v</td>
+ </tr>
- <?php
- }
+ <?php
+ }
echo "</table>";
-
-
-
}
function NewArticle($page_id)
@@ -83,13 +79,13 @@ function NewArticle($page_id)
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++;
+
+ $weight = 0;
+ $result = $db->Query("SELECT * FROM `bayonet_articles` WHERE `page_id` = $page_id ORDER BY `weight` DESC LIMIT 1");
+ $row = $db->Fetch($result);
+
+ $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')");
@@ -146,12 +142,8 @@ function EditArticle($article_id){
//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;
- }
-
+ $article = $db->Fetch($result);
+ $article = $row;
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
@@ -201,23 +193,21 @@ function ListPages($pid = NULL)
{
global $db;
$result = $db->Query("SELECT page_id,title FROM bayonet_pages");
- while(($row = $db->Fetch($result))!=false)
- {
- $pages[] = $row;
- }
+ $pages = $db->Fetch($result);
- echo "<table class=\"panelitems\" width=\"100%\" cellspacing=\"0\">";
+ echo "<table class=\"panelitems\" width=\"100%\" cellspacing=\"0\">";
- ?>
- <tr>
- <td style="text-align:center; text-overflow:ellipsis; overflow:hidden; background-color:#dfe4df; border-bottom: 1px solid #848484;">
+ ?>
+ <tr>
+ <td style="text-align:center; text-overflow:ellipsis; overflow:hidden; background-color:#dfe4df; border-bottom: 1px solid #848484;">
<?php echo LinkInternal('<img src="images/add.png" />&nbsp;Create New Page','?op=pages&create=true'); ?>
- </td>
- </tr>
+ </td>
+ </tr>
- <?php
+ <?php
- if(count($pages)==0){
+ if(count($pages)==0)
+ {
echo "<tr><td>No Pages Found.<br /></td></tr></table>";
return;
}