Converted to ezSQL

git-svn-id: http://svn.automattic.com/wordpress/trunk@254 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
mikelittle 2003-07-19 20:45:27 +00:00
parent 5e5d3abaf2
commit edcb80a4c1
2 changed files with 46 additions and 44 deletions

View File

@ -63,8 +63,7 @@ switch ($action) {
$auto_toggle = 'N'; $auto_toggle = 'N';
} }
$query="INSERT INTO $tablelinkcategories (cat_id,cat_name, auto_toggle) VALUES ('0', '$cat_name', '$auto_toggle')"; $wpdb->query("INSERT INTO $tablelinkcategories (cat_id,cat_name, auto_toggle) VALUES ('0', '$cat_name', '$auto_toggle')");
$result=mysql_query($query) or die("Couldn't add category <b>$cat_name</b>".mysql_error());
header("Location: linkcategories.php"); header("Location: linkcategories.php");
break; break;
@ -84,11 +83,8 @@ switch ($action) {
if ($user_level < $minadminlevel) if ($user_level < $minadminlevel)
die ("Cheatin' uh ?"); die ("Cheatin' uh ?");
$query="DELETE FROM $tablelinkcategories WHERE cat_id=\"$cat_id\""; $wpdb->query("DELETE FROM $tablelinkcategories WHERE cat_id='$cat_id'");
$result=mysql_query($query) or die("Couldn't delete link category <b>$cat_name</b>".mysql_error()); $wpdb->query("UPDATE $tablelinks SET link_category=1 WHERE link_category='$cat_id'");
$query="UPDATE $tablelinks SET link_category=1 WHERE link_category='$cat_id'";
$result=mysql_query($query) or die("Couldn't reset category on links where category was <b>$cat_name</b>");
header("Location: linkcategories.php"); header("Location: linkcategories.php");
break; break;
@ -129,9 +125,8 @@ switch ($action) {
$cat_id=$HTTP_POST_VARS["cat_id"]; $cat_id=$HTTP_POST_VARS["cat_id"];
$auto_toggle=$HTTP_POST_VARS["auto_toggle"]; $auto_toggle=$HTTP_POST_VARS["auto_toggle"];
$query="UPDATE $tablelinkcategories SET cat_name='$cat_name', auto_toggle='$auto_toggle' WHERE cat_id=$cat_id"; $wpdb->query("UPDATE $tablelinkcategories SET cat_name='$cat_name', auto_toggle='$auto_toggle' WHERE cat_id=$cat_id");
$result=mysql_query($query) or die("Couldn't edit link category <b>$cat_name</b>: ".$query.mysql_error());
header("Location: linkcategories.php"); header("Location: linkcategories.php");
break; break;
} // end edit } // end edit
@ -151,10 +146,9 @@ switch ($action) {
<form name="cats" method="post"> <form name="cats" method="post">
<b>Edit</b> a link category:<br /> <b>Edit</b> a link category:<br />
<?php <?php
$query = "SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id"; $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id");
$result = mysql_query($query) or die("Couldn't execute query. ".mysql_error());
echo " <select name=\"cat_id\">\n"; echo " <select name=\"cat_id\">\n";
while($row = mysql_fetch_object($result)) { foreach ($results as $row) {
echo " <option value=\"".$row->cat_id."\""; echo " <option value=\"".$row->cat_id."\"";
if ($row->cat_id == $cat_id) if ($row->cat_id == $cat_id)
echo ' selected'; echo ' selected';

View File

@ -26,9 +26,9 @@
// //
// Mike Little (mike@zed1.com) // Mike Little (mike@zed1.com)
// ***************************************************************** // *****************************************************************
include_once('../wp-config.php'); require_once('../wp-config.php');
include_once('../wp-links/links.config.php'); require_once('../wp-links/links.config.php');
include_once("../wp-links/links.php"); require_once("../wp-links/links.php");
$title = 'Manage Links'; $title = 'Manage Links';
@ -68,6 +68,7 @@ for ($i=0; $i<count($b2varstoreset); $i += 1) {
} }
$links_show_cat_id = $HTTP_COOKIE_VARS["links_show_cat_id"]; $links_show_cat_id = $HTTP_COOKIE_VARS["links_show_cat_id"];
$links_show_order = $HTTP_COOKIE_VARS["links_show_order"];
// error_log("start, links_show_cat_id=$links_show_cat_id"); // error_log("start, links_show_cat_id=$links_show_cat_id");
@ -94,17 +95,14 @@ switch ($action) {
// if we are in an auto toggle category and this one is visible then we // if we are in an auto toggle category and this one is visible then we
// need to make the others invisible before we add this new one. // need to make the others invisible before we add this new one.
if (($auto_toggle == 'Y') && ($link_visible == 'Y')) { if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
$sql = "UPDATE $tablelinks set link_visible = 'N' WHERE link_category = $link_category"; $wpdb->query("UPDATE $tablelinks set link_visible = 'N' WHERE link_category = $link_category");
$sql_result = mysql_query($sql) or die("Couldn't execute query."."sql=[$sql]". mysql_error());
} }
$sql = "INSERT INTO $tablelinks (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel) " . $wpdb->query("INSERT INTO $tablelinks (link_url, link_name, link_image, link_target, link_category, link_description, link_visible, link_owner, link_rating, link_rel) " .
" VALUES('" . addslashes($link_url) . "','" " VALUES('" . addslashes($link_url) . "','"
. addslashes($link_name) . "', '" . addslashes($link_name) . "', '"
. addslashes($link_image) . "', '$link_target', $link_category, '" . addslashes($link_image) . "', '$link_target', $link_category, '"
. addslashes($link_description) . "', '$link_visible', $user_ID, $link_rating, '" . addslashes($link_rel) ."')"; . addslashes($link_description) . "', '$link_visible', $user_ID, $link_rating, '" . addslashes($link_rel) ."')");
$sql_result = mysql_query($sql) or die("Couldn't execute query."."sql=[$sql]". mysql_error());
header('Location: linkmanager.php'); header('Location: linkmanager.php');
break; break;
@ -144,20 +142,17 @@ switch ($action) {
// if we are in an auto toggle category and this one is visible then we // if we are in an auto toggle category and this one is visible then we
// need to make the others invisible before we update this one. // need to make the others invisible before we update this one.
if (($auto_toggle == 'Y') && ($link_visible == 'Y')) { if (($auto_toggle == 'Y') && ($link_visible == 'Y')) {
$sql = "UPDATE $tablelinks set link_visible = 'N' WHERE link_category = $link_category"; $wpdb->query("UPDATE $tablelinks set link_visible = 'N' WHERE link_category = $link_category");
$sql_result = mysql_query($sql) or die("Couldn't execute query."."sql=[$sql]". mysql_error());
} }
$sql = "UPDATE $tablelinks SET link_url='" . addslashes($link_url) . "',\n " . $wpdb->query("UPDATE $tablelinks SET link_url='" . addslashes($link_url) . "',\n " .
" link_name='" . addslashes($link_name) . "',\n link_image='" . addslashes($link_image) . "',\n " . " link_name='" . addslashes($link_name) . "',\n link_image='" . addslashes($link_image) . "',\n " .
" link_target='$link_target',\n link_category=$link_category,\n " . " link_target='$link_target',\n link_category=$link_category,\n " .
" link_visible='$link_visible',\n link_description='" . addslashes($link_description) . "',\n " . " link_visible='$link_visible',\n link_description='" . addslashes($link_description) . "',\n " .
" link_rating=$link_rating,\n" . " link_rating=$link_rating,\n" .
" link_rel='" . addslashes($link_rel) . "'\n" . " link_rel='" . addslashes($link_rel) . "'\n" .
" WHERE link_id=$link_id"; " WHERE link_id=$link_id");
//error_log($sql); //error_log($sql);
$sql_result = mysql_query($sql) or die("Couldn't execute query."."sql=[$sql]". mysql_error());
} // end if save } // end if save
setcookie('links_show_cat_id', $links_show_cat_id, time()+600); setcookie('links_show_cat_id', $links_show_cat_id, time()+600);
header("Location: linkmanager.php"); header("Location: linkmanager.php");
@ -174,8 +169,7 @@ switch ($action) {
if ($user_level < $minadminlevel) if ($user_level < $minadminlevel)
die ("Cheatin' uh ?"); die ("Cheatin' uh ?");
$sql = "DELETE FROM $tablelinks WHERE link_id = '$link_id'"; $wpdb->query("DELETE FROM $tablelinks WHERE link_id = '$link_id'");
$sql_result = mysql_query($sql) or die("Couldn't execute query.".mysql_error());
if (isset($links_show_cat_id) && ($links_show_cat_id != '')) if (isset($links_show_cat_id) && ($links_show_cat_id != ''))
$cat_id = $links_show_cat_id; $cat_id = $links_show_cat_id;
@ -198,12 +192,11 @@ switch ($action) {
die("You have no right to edit the links for this blog.<br />Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a>. :)"); die("You have no right to edit the links for this blog.<br />Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a>. :)");
} }
$sql = "SELECT link_url, link_name, link_image, link_target, link_description, link_visible, link_category AS cat_id, link_rating, link_rel " . $row = $wpdb->get_row("SELECT link_url, link_name, link_image, link_target, link_description, link_visible, link_category AS cat_id, link_rating, link_rel " .
" FROM $tablelinks " . " FROM $tablelinks " .
" WHERE link_id = $link_id"; " WHERE link_id = $link_id");
$result = mysql_query($sql) or die("Couldn't execute query.".mysql_error()); if ($row) {
if ($row = mysql_fetch_object($result)) {
$link_url = $row->link_url; $link_url = $row->link_url;
$link_name = stripslashes($row->link_name); $link_name = stripslashes($row->link_name);
$link_image = $row->link_image; $link_image = $row->link_image;
@ -286,10 +279,9 @@ switch ($action) {
<td height="20" align="right">Category:</td> <td height="20" align="right">Category:</td>
<td> <td>
<?php <?php
$query = "SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id"; $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id");
$result = mysql_query($query) or die("Couldn't execute query. ".mysql_error());
echo " <select name=\"category\" size=\"1\">\n"; echo " <select name=\"category\" size=\"1\">\n";
while($row = mysql_fetch_object($result)) { foreach($results as $row) {
echo " <option value=\"".$row->cat_id."\""; echo " <option value=\"".$row->cat_id."\"";
if ($row->cat_id == $link_category) if ($row->cat_id == $link_category)
echo " selected"; echo " selected";
@ -320,6 +312,11 @@ switch ($action) {
$cat_id = 'All'; $cat_id = 'All';
} }
$links_show_cat_id = $cat_id; $links_show_cat_id = $cat_id;
if (!isset($order_by) || ($order_by == '')) {
if (!isset($links_show_order) || ($links_show_order == ''))
$order_by = 'order_name';
}
$links_show_order = $order_by;
//break; fall through //break; fall through
} // end Show } // end Show
case "popup": case "popup":
@ -338,9 +335,15 @@ switch ($action) {
$cat_id = 'All'; $cat_id = 'All';
} }
$links_show_cat_id = $cat_id; $links_show_cat_id = $cat_id;
if (isset($links_show_order) && ($links_show_order != ''))
$order_by = $links_show_order;
if (!isset($order_by) || ($order_by == '')) if (!isset($order_by) || ($order_by == ''))
$order_by = 'order_name'; $order_by = 'order_name';
$links_show_order = $order_by;
setcookie('links_show_cat_id', $links_show_cat_id, time()+600); setcookie('links_show_cat_id', $links_show_cat_id, time()+600);
setcookie('links_show_order', $links_show_order, time()+600);
$standalone=0; $standalone=0;
include_once ("./b2header.php"); include_once ("./b2header.php");
if ($user_level < $minadminlevel) { if ($user_level < $minadminlevel) {
@ -376,14 +379,13 @@ switch ($action) {
<tr> <tr>
<td> <td>
<?php <?php
$query = "SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id"; $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id");
$result = mysql_query($query) or die("Couldn't execute query. ".mysql_error());
echo " <select name=\"cat_id\">\n"; echo " <select name=\"cat_id\">\n";
echo " <option value=\"All\""; echo " <option value=\"All\"";
if ($cat_id == 'All') if ($cat_id == 'All')
echo " selected"; echo " selected";
echo "> All</option>\n"; echo "> All</option>\n";
while($row = mysql_fetch_object($result)) { foreach ($results as $row) {
echo " <option value=\"".$row->cat_id."\""; echo " <option value=\"".$row->cat_id."\"";
if ($row->cat_id == $cat_id) if ($row->cat_id == $cat_id)
echo " selected"; echo " selected";
@ -433,11 +435,18 @@ switch ($action) {
<th>&nbsp;</th> <th>&nbsp;</th>
</tr> </tr>
<?php <?php
$sql = "SELECT link_url, link_name, link_image, link_description, link_visible, link_category AS cat_id, cat_name AS category, $tableusers.user_login, link_id, link_rating, link_rel FROM $tablelinks LEFT JOIN $tablelinkcategories ON $tablelinks.link_category = $tablelinkcategories.cat_id LEFT JOIN $tableusers on $tableusers.ID = $tablelinks.link_owner "; $sql = "SELECT link_url, link_name, link_image, link_description, link_visible,
link_category AS cat_id, cat_name AS category, $tableusers.user_login, link_id,
link_rating, link_rel
FROM $tablelinks
LEFT JOIN $tablelinkcategories ON $tablelinks.link_category = $tablelinkcategories.cat_id
LEFT JOIN $tableusers on $tableusers.ID = $tablelinks.link_owner ";
// have we got a where clause? // have we got a where clause?
if (($use_adminlevels) || (isset($cat_id) && ($cat_id != 'All')) ) { if (($use_adminlevels) || (isset($cat_id) && ($cat_id != 'All')) ) {
$sql .= " WHERE "; $sql .= " WHERE ";
} }
// FIX ME This make higher level links invisible rather than just uneditable
if ($use_adminlevels) { if ($use_adminlevels) {
$sql .= " ($tableusers.user_level <= $user_level" $sql .= " ($tableusers.user_level <= $user_level"
. " OR $tableusers.ID = $user_ID)"; . " OR $tableusers.ID = $user_ID)";
@ -549,10 +558,9 @@ LINKS;
<td height="20" align="right">Category:</td> <td height="20" align="right">Category:</td>
<td> <td>
<?php <?php
$query = "SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id"; $results = $wpdb->get_results("SELECT cat_id, cat_name, auto_toggle FROM $tablelinkcategories ORDER BY cat_id");
$result = mysql_query($query) or die("Couldn't execute query. ".mysql_error());
echo " <select name=\"category\" size=\"1\">\n"; echo " <select name=\"category\" size=\"1\">\n";
while($row = mysql_fetch_object($result)) { foreach ($results as $row) {
echo " <option value=\"".$row->cat_id."\""; echo " <option value=\"".$row->cat_id."\"";
if ($row->cat_id == $cat_id) if ($row->cat_id == $cat_id)
echo " selected"; echo " selected";