<?php
include_once("core/main.php");
if( !check_user_class($config["admmenu"]["links_cat"]["class"]) ) exit;

$index_page = false;
$page_name = $lang["LINKS_CAT_EDIT_TITLE"];

draw_header();

require_once("phpdbform/phpdbform_{$config["dbtype"]}.php");
require_once("phpdbform/phpdbform_db.php");

$db = new phpdbform_db( $config["database"], $config["host"], $config["user"], $config["password"] );
$db->connect();

$parents[] = array( 0, "none");
$ret = $db->query( "select cod, name from {$config["prefix"]}_linkscat order by name", "listing links categories for parent_id" );
while( $row = $db->fetch_row($ret) ) $parents[] = array( $row[0], $row[0]." | ".$row[1] );
$db->free_result($ret);

$formdb = new phpdbform( $db, "{$config["prefix"]}_linkscat", "cod", "cod,name", "name" );

$formdb->add_textbox( "name", "Category", 60 );
$formdb->add_textarea( "descr", "Description", 60, 10 );
$formdb->add_static_listbox( "parent_id", "Parent", $parents );

function proclinkscat( &$form )
{
    if( $form->keyvalue[0] == $form->fields["parent_id"]->value )
	{
		print "Parent can't be the same as the category";
		return false;
	}
    return true;
}

$formdb->onupdate = "proclinkscat";

theme_draw_centerbox_open($page_name);
$formdb->process();
$formdb->draw();
theme_draw_centerbox_close();
draw_footer();
?>
