<?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)
***************************************************************************/
/*$Id: class.categories.php,v 1.4 2003/12/09 07:43:02 rthomp Exp $*/
class category
{
/*!
@function categorize()
@author Ryan Thompson
@abstract Categorizes and item
@version 0.1
@params $item_id - ID returned from database for item
@params $service - Service that item belongs to
@params $category_id - ID of category
@return TRUE/FALSE
@since 07-12-2003
@access PUBLIC
*/
function categorize($item_id, $service, $category_id)
{
GLOBAL $db;
if(!empty($_POST['category']))
{
$sql = "INSERT INTO o_categorize (id, service, category) VALUES ('$item_id', '$service', '$category_id')";
$db->query($sql);
}
return;
}
/*!
@function delete()
@author Ryan Thompson
@abstract Removes and item from categorize table
@version 0.1
@params $item_id - ID returned from database for item
@params $service - Service that item belongs to
@since 07-12-2003
@access PUBLIC
*/
function delete($item_id, $service)
{
GLOBAL $db;
$sql = "DELETE FROM o_categorize WHERE id='$item_id' AND service='$service'";
$db->query($sql);
return;
}
/*!
@function get_category_select()
@author Ryan Thompson
@abstract Retrieves a category select box
@version 0.1
@params $user_id
@params $service
@params $page
@return $select_box. $link
@since 07-12-2003
@access PUBLIC
*/
function get_category_select($user_id, $service, $page, $selected, $filter = NULL)
{
GLOBAL $O, $html, $db, $lang;
if($filter)
{
$categories['*'] = $lang->get_msg('all', 'gl');
}
$sql = "SELECT * FROM o_categories WHERE user_id='{$user_id}' AND service='$service' OR user_id='{$user_id}' AND service='gl'";
$db->query($sql);
while($db->fetch_results())
{
$categories[$db->record['category_id']] = $db->record['category'];
}
$link = $O->create_link("/users/categories.php?rt=$service&pg=$page", $lang->get_msg('add_category', 'gl'), 'small_link');
return $html->select_box('category', 'array', $categories, $selected) . $link;
}
/*!
@function get_category_filter()
@author Ryan Thompson
@abstract Return SQL statement for filtering
@version 0.1
@params $category
@return $select_box. $link
@since 07-12-2003
@access PUBLIC
*/
function get_category_filter($category, $table, $fields, $where)
{
//Can't use until I figure out how.
}
/*!
@function add_default_categories()
@author Ryan Thompson
@abstract Adds some default categories for users
@version 0.1
@params $user_id
@return TRUE
@since 08-12-2003
@access PUBLIC
*/
function add_default_categories($user_id)
{
GLOBAL $db;
$sql = "SELECT * FROM o_categories WHERE user_id='1'";
$db->query($sql);
$i = 0;
while($db->fetch_results())
{
$categories[$i]['service'] = $db->record['service'];
$categories[$i]['cat'] = $db->record['category'];
$i++;
}
foreach($categories AS $value)
{
$sql = "INSERT INTO o_categories (user_id, category, service) VALUES ('$user_id','{$value['cat']}','{$value['service']}')";
$db->query($sql);
}
}
/*!
@function edit_category()
@author Ryan Thompson
@abstract Updates the category for given $item in $service
@version 0.1
@params $item_id
@params $service
@params $category
@return TRUE
@since 08-12-2003
@access PUBLIC
*/
function edit_category($item_id, $service, $category)
{
GLOBAL $db;
$sql = "UPDATE o_categorize SET category='$category' WHERE id='$item_id' AND service='$service'";
$db->query($sql);
return;
}
}