<?php
/**************************************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
@Authors: Ryan Thompson(hide@address.com)
***************************************************************************/
include("./data.php");
$service['add_header'] = TRUE;
include("../config.inc.php");
include($here. "/class.preferences.php");
$prefs = new preferences;
if(isset($_POST['add_category']))
{
if(strlen($_POST['category']) == 0)
{
$error->get_message(3000);
echo $error->display();
} else {
$sql = "INSERT INTO o_categories (user_id, service, category) VALUES
('". $user->user_id ."','$_POST[service]','$_POST[category]')";
$db->query($sql);
}
if(isset($_GET['rt']))
{
$db->query("SELECT location FROM o_services WHERE code='{$_GET['rt']}'");
$db->fetch_results();
if(strstr($_GET['pg'], '.php'))
{
$O->redirect("/{$db->record['location']}/{$_GET['pg']}");
} else {
$O->redirect("/{$db->record['location']}/{$_GET['pg']}.php");
}
}
} elseif(isset($_POST['update']))
{
foreach($_POST['categories'] AS $key=>$value)
{
$sql = "UPDATE o_categories SET category='$value' WHERE category_id='$key'";
$db->query($sql);
if(isset($_POST['delete'][$key]))
{
$sql = "DELETE FROM o_categories WHERE category_id='$key'";
$db->query($sql);
}
}
}
echo $layout->page_header;
echo $layout->service_header($text['service_name'], $prefs->nav_buttons(), $text['categories']);
if(isset($_GET['rt']))
{
$redirect = "?rt={$_GET['rt']}&pg={$_GET['pg']}";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'].$redirect?>" method="post">
<table style="width:500px" align="center">
<tr>
<td></td>
<td>
<select name="service">
<option value="gl">Global</option>
<?php
$sql = "SELECT o_user_rights.service, o_services.location FROM o_user_rights LEFT JOIN o_services
ON o_user_rights.service=o_services.code
WHERE o_user_rights.rights > 0 AND o_user_rights.user_id='{$user->user_id}'";
$db->query($sql);
while($db->fetch_results())
{
include($O->dir ."/". $db->record['location'] ."/data.php");
echo "<option value=\"". $db->record['service'] ."\">". $service['name'] ."</option>\n";
}
?>
</select>
</td>
<td>
<input type="text" name="category" value="<?php $_POST['category']?>" size="40">
</td>
<td>
<input type="submit" name="add_category" value="Add Category" class="button1">
</td>
</tr>
<?php
$sql = "SELECT o_categories.category_id, o_categories.category, o_services.location
FROM o_categories LEFT JOIN o_services ON o_categories.service=o_services.code
WHERE user_id='{$user->user_id}' ORDER BY service, category";
$db->query($sql);
while($db->fetch_results())
{
if($class == "list_light")
{
$class = "list_dark";
} else {
$class = "list_light";
}
echo "<tr>\n";
echo "<td><input type=\"checkbox\" name=\"delete[". $db->record['category_id'] ."]\" value=\"1\"></td>";
echo "<td width=\"100\" class=\"$class\">";
include($O->dir ."/". $db->record['location'] ."/data.php");
echo $service['name'];
echo "</td>\n<td width=\"300\" class=\"$class\">";
echo "<input type=\"text\" name=\"categories[". $db->record['category_id'] ."]\" value=\"". $db->record['category'] ."\" class=\"$class\" style=\"border: 1px solid black\">";
echo "</td>\n</tr>\n";
}
?>
</table>
<input type="submit" name="update" value="Update Categories" class="button1">
<?php echo $layout->create_footer();?>