Location: PHPKode > projects > Slacker > slacker/slacker.inc/slacker/slacker_functions.inc.php
<?php
/*
                ------======--------
                 Slacker 	v0.1
                 ------------------
                 
                 Developed and Coded by
                 Dave Bullock - hide@address.com 2002
                 _BSD Lic._

*/

include ("slacker/user_functions.inc.php");

# --- Functions ---

    
/* 
    --------------------------------------
    FUNCTION: add_user()
    --------------------------------------
*/                
function add_user($username,$firstname,$lastname, $address="", $city, $state, $zip, $country, $phone, $fax="", $domain, $company="", $password, $status="1", $admin="0", $homedir)
{
    dbconnect();
    safe_db_create($username);
    $now = time();
    safe_query ("INSERT INTO clients 
        VALUES ( '', '$username', '$firstname', 
        '$lastname', '$address', '$city', 
        '$state', '$zip', '$country', '$phone', '$fax', '$domain', '$company', PASSWORD('$password'),
        '$status', '$now', '$admin', '$homedir', '$email')"
    );
    mysql_select_db("mysql");
  
    
    $http_path = $homedir . "/website/";
    $inc_path = $homedir . "/inc";
    $htaccess = $http_path . ".htaccess";
    
    safe_query("INSERT INTO user VALUES ( 'localhost', '$username', PASSWORD('$password'), 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N',
     		'N', 'N', 'N', 'N')");
    safe_query("INSERT INTO db VALUES ( 'localhost', '$username', '$username', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y')");


    $filename = "/slacker/slacker.inc/slacker/header.inc.php.skel";
    $fp = fopen("$filename","r");
    $header = fread ($fp, filesize($filename));
    fclose ($fp);
 
    $fp = fopen("/slacker/slacker.inc/slacker/footer.inc.php.skel","r");
    $footer = fread ($fp, filesize("/slacker/slacker.inc/slacker/footer.inc.php"));
    fclose ($fp);

    $fp = fopen("/slacker/slacker.inc/slacker/dbconnect_shell.inc.php","r");
    $dbconnect  = fread ($fp, filesize("/slacker/slacker.inc/slacker/dbconnect_shell.inc.php"));
    fclose ($fp);

    $fp = fopen("/slacker/slacker.inc/slacker/user_functions.inc.php","r");
    $functions = fread ($fp, filesize("/slacker/slacker.inc/slacker/user_functions.inc.php"));
    fclose ($fp);

    $fp = fopen("/slacker/slacker.inc/conf/global.conf.php","r");
    $global_conf = fread ($fp, filesize("/slacker/slacker.inc/conf/global.conf.php"));
    fclose ($fp);

    $fp = fopen("/slacker/slacker.inc/inc/db.inc.php","r");
    $db_conf = fread ($fp, filesize("/slacker/slacker.inc/inc/db.inc.php"));
    fclose ($fp);

    $fp = fopen("/slacker/install/.htaccess","r");
    $htaccess = fread ($fp, filesize("/slacker/install/.htaccess"));
    fclose ($fp);

    #customize header file
    $header = str_replace("1myname1","$company","$header");
 
    #customize db.inc.php    
    $db_conf = str_replace("1reactororg1","$username","$db_conf");
    $db_conf = str_replace("2reactororg2","$password","$db_conf");
    
    #customize .htaccess
    $htaccess = str_replace("/var/tron","$inc_path","$htaccess");
    
    #customize functions    
    $functions = str_replace("/Library/Webserver/Documents/","$http_path","$functions");

    
   
    #customize global.inc.php    
    $global_conf = str_replace("1/home/reactororg/phpreactor1","$inc_path","$global_conf");
    $global_conf = str_replace("1http://phpreactor.org1","$domain","$global_conf");
    $global_conf = str_replace("1php(Reactor)1","$company","$global_conf");
    $global_conf = str_replace("hide@address.com","$email","$global_conf");

    #customize dbconnect    
    $dbconnect = str_replace("1username1","$username","$dbconnect");
    $dbconnect = str_replace("1password1","$password","$dbconnect");
    $newdb = $user . "_dbconnect";
 
    # Create header php file
    $filename = $homedir . "/inc/header.inc.php";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp,($header));
    fclose ($fp);

    # Create htaccess php file
    $filename = $homedir . "/website/.htaccess";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp,($htaccess));
    fclose ($fp);
    
    # Create footer php file
    $filename = $homedir . "/inc/footer.inc.php";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp,($footer));
    fclose ($fp);

    # Create functions php file
    $filename = $homedir . "/inc/functions.inc.php";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp,($functions));
    fclose ($fp);    
    
    # Create dbconnect file
    $filename =  $homedir . "/inc/dbconnect.inc.php";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp,($dbconnect));
    fclose ($fp);
    
    # Create global.inc file
    $filename =  $homedir . "/inc/conf/global.conf.php";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp,($global_conf));
    fclose ($fp);
    
    # Create db.inc file
    $filename =  $homedir . "/inc/inc/db.inc.php";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp,($db_conf));
    fclose ($fp);
    
	    
    safe_query("FLUSH PRIVILEGES");
    
    $output = $username . " added! click here to <a href=/slacker/index.html>add more users or pages</a>";
    return $output;    
    
}   

/* 
    FUNCTION: safe_db_create()
    string safe_db_create (string name)
*/  
function safe_db_create($name)
{
    $name = sanitize($name);
    safe_query("CREATE DATABASE $name");                 
    mysql_select_db("$name");

safe_query("

CREATE TABLE users (
  username varchar(20) NOT NULL default '',
  password tinyblob NOT NULL,
  email varchar(80) NOT NULL default '',
  opt_in tinyint(4) default '1',
  profile varchar(255) default NULL,
  posts int(11) NOT NULL default '0',
  admin tinyint(4) NOT NULL default '0',
  status tinyint(4) default '0',
  modified timestamp(14) NOT NULL,
  created timestamp(14) NOT NULL,
  address varchar(80) default NULL,
  city varchar(60) default NULL,
  state varchar(20) default NULL,
  zip varchar(20) default NULL,
  country varchar(40) default NULL,
  rider tinyint(4) default '0',
  flameboy tinyint(4) default '0',
  wetwilly tinyint(4) default '0',
  devilman tinyint(4) default '0',
  winner tinyint(4) default '0',
  spam tinyint(4) default NULL,
  over_13 tinyint(4) default '0',
  name varchar(100) NOT NULL default '',
  age tinyint(4) NOT NULL default '0',
  online tinyint(4) default '0',
  sent varchar(50) default NULL,
  sms varchar(99) default NULL,
  sms_provider varchar(20) default NULL,
  PRIMARY KEY  (username),
  UNIQUE KEY username (username),
  KEY status (status),
  KEY admin (admin),
  KEY over_13 (over_13),
  KEY email (email),
  KEY opt_in (opt_in),
  KEY profile (profile),
  KEY posts (posts),
  KEY name (name),
  KEY modified (modified),
  KEY online (online),
  KEY sent (sent),
  KEY sms (sms)
) TYPE=MyISAM
");
safe_query("


CREATE TABLE online (
  username varchar(64) NOT NULL ,
  modified int(64) NOT NULL ,
  online tinyint(4) NOT NULL,
  PRIMARY KEY  (username)
) TYPE=MyISAM
");

safe_query("
CREATE TABLE `order_items` (
  `id` tinyint(255) NOT NULL auto_increment,
  `order` tinyint(255) NOT NULL default '0',
  `item` tinyint(255) NOT NULL default '0',
  `active` tinyint(4) default '1',
  `name` varchar(90) default NULL,
  `price` varchar(50) default NULL,
  `quantity` tinyint(255) default NULL,
  `username` varchar(50) default NULL,
  `shipping` tinyint(4) default NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM   


");

safe_query("

CREATE TABLE `orders` (
  `id` tinyint(255) NOT NULL auto_increment,
  `username` varchar(50) NOT NULL default '',
  `paid` tinyint(4) default '0',
  `shipped` tinyint(4) default '0',
  `active` tinyint(4) NOT NULL default '1',
  `total` varchar(50) default NULL,
  `tax` varchar(50) default NULL,
  `shipping` varchar(50) default NULL,
  `notes` text,
  `checkout` tinyint(4) default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM;



");
safe_query("

CREATE TABLE `cart` (
  `id` tinyint(255) NOT NULL auto_increment,
  `username` varchar(50) NOT NULL default '',
  `item` tinyint(255) NOT NULL default '0',
  `active` tinyint(4) NOT NULL default '0',
  `quantity` tinyint(255) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM

");

safe_query("

CREATE TABLE `items` (
  `id` tinyint(255) NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  `description` text,
  `active` tinyint(4) default '1',
  `quantity` tinyint(255) default '0',
  `price` varchar(20) default NULL,
  `group` tinyint(255) default '1',
  `priority` tinyint(4) NOT NULL default '0',
  `shipping` tinyint(255) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `active` (`active`),
  KEY `group` (`group`),
  KEY `priority` (`priority`)
) TYPE=MyISAM;

    



");

safe_query("
CREATE TABLE lurkers (
  username varchar(64) NOT NULL ,
  modified int(64) NOT NULL ,
  online tinyint(4) NOT NULL,
  PRIMARY KEY  (username)
) TYPE=MyISAM

");

safe_query("


CREATE TABLE sms_sent (
  id smallint(32) NOT NULL auto_increment,
  sender varchar(99) default NULL,
  subject text,
  message text,
  ip varchar(255) default NULL,
  modified timestamp(14) NOT NULL,
  username varchar(32) default NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM
");
safe_query("
CREATE TABLE `Images` (
  `Id` int(11) NOT NULL auto_increment,
  `Views` int(11) NOT NULL default '0',
  `Caption` varchar(127) default NULL,
  `Comment` varchar(255) default NULL,
  `Format` varchar(32) NOT NULL default '',
  `Width` int(11) NOT NULL default '0',
  `Height` int(11) NOT NULL default '0',
  `Bytes` int(11) NOT NULL default '0',
  `PublishedAt` timestamp(14) NOT NULL,
  `ShotAt` date default NULL,
  `username` varchar(255) default 'unkn0wn',
  PRIMARY KEY  (`Id`),
  KEY `Comment` (`Comment`),
  KEY `Caption` (`Caption`),
  KEY `Views` (`Views`),
  KEY `Width` (`Width`),
  KEY `username` (`username`)
) TYPE=MyISAM;
");
safe_query("
CREATE TABLE `ImageGroups` (
  `GroupId` int(11) NOT NULL default '0',
  `ImageId` int(11) NOT NULL default '0',
  `username` varchar(255) default 'unkn0wn',
  PRIMARY KEY  (`GroupId`,`ImageId`),
  UNIQUE KEY `ImageGroupsInidex` (`GroupId`,`ImageId`),
  KEY `username` (`username`)
) TYPE=MyISAM;

");
safe_query("
CREATE TABLE `Groups` (
  `Id` int(11) NOT NULL auto_increment,
  `Name` varchar(127) default NULL,
  `Comment` varchar(255) default NULL,
  `username` varchar(255) NOT NULL default 'unkn0wn',
  PRIMARY KEY  (`Id`),
  KEY `Name` (`Name`),
  KEY `Comment` (`Comment`),
  KEY `username` (`username`)
) TYPE=MyISAM;

    

    


");
safe_query("
CREATE TABLE `artists` (
  `id` mediumint(32) NOT NULL auto_increment,
  `name` varchar(99) NOT NULL default '',
  `url` text NOT NULL,
  `active` tinyint(4) default '1',
  `username` varchar(99) default NULL,
  `linkgroup` tinyint(4) default NULL,
  `description` text,
  PRIMARY KEY  (`id`),
  KEY `username` (`username`),
  KEY `linkgroup` (`linkgroup`),
  KEY `name` (`name`),
  KEY `active` (`active`)
) TYPE=MyISAM;

    

");
safe_query("
CREATE TABLE `artistsgroup` (
  `id` mediumint(32) NOT NULL auto_increment,
  `name` varchar(99) NOT NULL default '',
  `description` text NOT NULL,
  `active` tinyint(4) NOT NULL default '0',
  `username` varchar(99) NOT NULL default '',
  PRIMARY KEY  (`id`),
  KEY `active` (`active`),
  KEY `name` (`name`)
) TYPE=MyISAM;

    


");
safe_query("
CREATE TABLE `links` (
  `id` mediumint(32) NOT NULL auto_increment,
  `name` varchar(99) NOT NULL default '',
  `url` text NOT NULL,
  `active` tinyint(4) default '1',
  `username` varchar(99) default NULL,
  `linkgroup` tinyint(4) default NULL,
  `description` text,
  PRIMARY KEY  (`id`),
  KEY `username` (`username`),
  KEY `linkgroup` (`linkgroup`),
  KEY `name` (`name`),
  KEY `active` (`active`)
) TYPE=MyISAM;

    


");
safe_query("
CREATE TABLE `linkgroup` (
  `id` mediumint(32) NOT NULL auto_increment,
  `name` varchar(99) NOT NULL default '',
  `description` text NOT NULL,
  `active` tinyint(4) NOT NULL default '0',
  `username` varchar(99) NOT NULL default '',
  PRIMARY KEY  (`id`),
  KEY `active` (`active`),
  KEY `name` (`name`)
) TYPE=MyISAM;

    


");
safe_query("
CREATE TABLE `mixes` (
  `id` mediumint(32) NOT NULL auto_increment,
  `name` varchar(99) NOT NULL default '',
  `url` text NOT NULL,
  `active` tinyint(4) default '1',
  `username` varchar(99) default NULL,
  `linkgroup` tinyint(4) default NULL,
  `description` text,
  PRIMARY KEY  (`id`),
  KEY `username` (`username`),
  KEY `linkgroup` (`linkgroup`),
  KEY `name` (`name`),
  KEY `active` (`active`)
) TYPE=MyISAM;

    

");
safe_query("
CREATE TABLE `mixesgroup` (
  `id` mediumint(32) NOT NULL auto_increment,
  `name` varchar(99) NOT NULL default '',
  `description` text NOT NULL,
  `active` tinyint(4) NOT NULL default '0',
  `username` varchar(99) NOT NULL default '',
  PRIMARY KEY  (`id`),
  KEY `active` (`active`),
  KEY `name` (`name`)
) TYPE=MyISAM;

    

");
safe_query("
CREATE TABLE `tracks` (
  `id` mediumint(32) NOT NULL auto_increment,
  `name` varchar(99) NOT NULL default '',
  `url` text NOT NULL,
  `active` tinyint(4) default '1',
  `username` varchar(99) default NULL,
  `linkgroup` tinyint(4) default NULL,
  `description` text,
  PRIMARY KEY  (`id`),
  KEY `username` (`username`),
  KEY `linkgroup` (`linkgroup`),
  KEY `name` (`name`),
  KEY `active` (`active`)
) TYPE=MyISAM;

    

");
safe_query("
CREATE TABLE `tracksgroup` (
  `id` mediumint(32) NOT NULL auto_increment,
  `name` varchar(99) NOT NULL default '',
  `description` text NOT NULL,
  `active` tinyint(4) NOT NULL default '0',
  `username` varchar(99) NOT NULL default '',
  PRIMARY KEY  (`id`),
  KEY `active` (`active`),
  KEY `name` (`name`)
) TYPE=MyISAM;

    

");


safe_query("
CREATE TABLE calendar (
  id mediumint(255) NOT NULL auto_increment,
  name varchar(200) NOT NULL default '',
  description blob,
  month varchar(10) default NULL,
  date tinyint(20) NOT NULL default '0',
  year varchar(25) NOT NULL default '0',
  starttime varchar(20) default NULL,
  endtime varchar(20) default NULL,
  country varchar(99) default NULL,
  venue varchar(99) default NULL,
  address varchar(250) default NULL,
  city varchar(200) default NULL,
  state varchar(20) default NULL,
  zip varchar(20) default NULL,
  url varchar(250) default NULL,
  user varchar(99) default NULL,
  info1 varchar(20) default NULL,
  info2 varchar(20) default NULL,
  info3 varchar(20) default NULL,
  active tinyint(4) default '1',
  recurring varchar(20) default NULL,
  PRIMARY KEY  (id),
  KEY date (month),
  KEY month (month),
  KEY year (year),
  KEY active (active),
  KEY recurring (recurring)
) TYPE=MyISAM
");
safe_query("
CREATE TABLE sms (
  id tinyint(4) NOT NULL auto_increment,
  name varchar(99) NOT NULL default '',
  host varchar(99) NOT NULL default '',
  active tinyint(4) NOT NULL default '0',
  PRIMARY KEY  (id),
  KEY name (name),
  KEY active (active)
) TYPE=MyISAM
");
safe_query("INSERT INTO sms VALUES ( '1', 'AT&T', 'mobile.att.net', '1')
");
safe_query("
INSERT INTO sms VALUES ( '2', 'Sprint PCS', 'messaging.sprintpcs.com', '1')
");
safe_query("
INSERT INTO sms VALUES ( '3', 'Cingular', 'mobile.mycingular.com', '1')
");
safe_query("
INSERT INTO sms VALUES ( '4', 'Verizon', 'msg.myvzw.com', '1')
");
safe_query("
INSERT INTO sms VALUES ( '5', 'Voicestream', 'voicestream.net', '1')
");
safe_query("
INSERT INTO sms VALUES ( '6', 'Nextel', 'messaging.nextel.com', '1')
");
safe_query("
INSERT INTO sms VALUES ( '7', 'Metrocall', 'page.metrocall.com', '1')
");
safe_query("
INSERT INTO sms VALUES ( '8', 'Cingular Pacbell Alternate', 'pacbellpcs.net', '1')
");
safe_query("
CREATE TABLE content (
  mailname varchar(20) NOT NULL default '',
  modified date default NULL,
  message text,
  sentto text,
  emailfrom varchar(80) default NULL,
  replyto varchar(80) default NULL,
  subject varchar(150) default NULL,
  PRIMARY KEY  (mailname)
) TYPE=MyISAM
");
safe_query("

CREATE TABLE giveaway (
  id smallint(6) NOT NULL auto_increment,
  name varchar(90) NOT NULL default '0',
  month varchar(15) NOT NULL default '',
  city varchar(50) NOT NULL default '0',
  status smallint(6) NOT NULL default '1',
  created datetime NOT NULL default '0000-00-00 00:00:00',
  modified datetime NOT NULL default '0000-00-00 00:00:00',
  country varchar(90) default NULL,
  state varchar(20) NOT NULL default '',
  username varchar(220) default NULL,
  PRIMARY KEY  (id),
  KEY user (name),
  KEY status (status)
) TYPE=MyISAM
");

safe_query("

CREATE TABLE wish (
  id smallint(6) NOT NULL auto_increment,
  name varchar(80) default NULL,
  item smallint(6) default NULL,
  modified timestamp(14) NOT NULL,
  created timestamp(14) NOT NULL,
  visible tinyint(4) default '1',
  user varchar(70) default NULL,
  PRIMARY KEY  (id),
  KEY visible (visible),
  KEY user (user),
  KEY name (name),
  KEY item (item)
) TYPE=MyISAM
");

safe_query("


CREATE TABLE dealer (
  id mediumint(255) NOT NULL auto_increment,
  name varchar(100) default NULL,
  address varchar(200) default NULL,
  city varchar(250) default NULL,
  state varchar(250) default NULL,
  zip varchar(200) default NULL,
  country varchar(150) default NULL,
  phone varchar(200) default NULL,
  visible tinyint(2) NOT NULL default '1',
  snow tinyint(2) NOT NULL default '0',
  skate tinyint(2) NOT NULL default '1',
  PRIMARY KEY  (id),
  KEY city (city),
  KEY zip (zip),
  KEY country (country),
  KEY state (state),
  KEY visible (visible),
  KEY snow (snow),
  KEY skate (skate)
) TYPE=MyISAM
");

safe_query("


CREATE TABLE news (
  id smallint(6) NOT NULL auto_increment,
  name varchar(80) default NULL,
#  news.group smallint(6) default NULL,
  description blob,
  blurb mediumblob,
  team tinyint(4) NOT NULL default '0',
  modified timestamp(14) NOT NULL,
  created timestamp(14) NOT NULL,
  priority tinyint(4) default NULL,
  visible tinyint(4) default '1',
  user tinyint(4) default NULL,
  views mediumint(9) default '0',
  PRIMARY KEY  (id),
#  KEY group (group),
  KEY visible (visible),
  KEY priority (priority),
  KEY name (name)
) TYPE=MyISAM
");

safe_query("

CREATE TABLE jsm (
  id smallint(255) NOT NULL auto_increment,
  username varchar(32) default NULL,
  sender varchar(32) default NULL,
  message text,
  created timestamp(14) NOT NULL,
  active tinyint(4) default '1',
  deleted tinyint(4) default '0',
  PRIMARY KEY  (id),
  KEY username (username),
  KEY sender (sender),
  KEY active (active)
) TYPE=MyISAM
");

safe_query("
CREATE TABLE team (
  id smallint(6) NOT NULL auto_increment,
  name varchar(80) NOT NULL default '',
  age smallint(6) NOT NULL default '0',
  bio blob NOT NULL,
  interview blob NOT NULL,
  pro tinyint(4) NOT NULL default '0',
  am tinyint(4) NOT NULL default '0',
  skate tinyint(4) NOT NULL default '0',
  snow tinyint(4) NOT NULL default '0',
  flow tinyint(4) NOT NULL default '0',
  international tinyint(4) NOT NULL default '0',
  wcs blob,
  priority smallint(6) default '0',
  visible smallint(6) default '1',
  created datetime default NULL,
  modified datetime default NULL,
  news blob,
  tid varchar(64) default NULL,
  PRIMARY KEY  (id),
  KEY international (international),
  KEY name (name),
  KEY am (am),
  KEY snow (snow),
  KEY skate (skate),
  KEY flow (flow),
  KEY priority (priority),
  KEY visible (visible),
  KEY pro (pro)
) TYPE=MyISAM
");

safe_query("
CREATE TABLE item (
  id smallint(6) NOT NULL auto_increment,
  name varchar(80) default NULL,
#  item.group smallint(6) default NULL,
  description blob,
  item_number varchar(60) default NULL,
  retired tinyint(4) default '0',
  team tinyint(4) NOT NULL default '0',
  modified timestamp(14) NOT NULL,
  created timestamp(14) NOT NULL,
  priority tinyint(4) default NULL,
  visible tinyint(4) default '1',
  user tinyint(4) default NULL,
  views mediumint(9) default '0',
  tid varchar(32) default NULL,
  new tinyint(4) default '0',
  PRIMARY KEY (id),
  KEY views (views),
#  KEY group (group),
  KEY name (name),
  KEY team (team),
  KEY priority (priority),
  KEY visible (visible),
  KEY retired (retired),
  KEY new (new)
) TYPE=MyISAM

");
    safe_query("
CREATE TABLE category (
  id tinyint(4) NOT NULL auto_increment,
  name varchar(80) NOT NULL default '',
  parent smallint(6) NOT NULL default '0',
  description blob,
  image mediumblob,
  blurb blob,
  image2 mediumblob,
  blurb2 varchar(200) default NULL,
  title varchar(200) default NULL,
  visible tinyint(4) NOT NULL default '1',
  priority tinyint(4) default NULL,
  PRIMARY KEY  (id),
  KEY parent (parent),
  KEY visible (visible),
  KEY priority (priority),
  KEY name (name),
  KEY title (title)
) TYPE=MyISAM
");
mysql_select_db("slacker");
}                 

     
/* 

    FUNCTION: safe_table_create()
*/                
function safe_table_create($user,$t_name,$homedir)
{
dbconnect();
mysql_select_db("$user");
safe_query("CREATE TABLE $t_name (
    id tinyint(255) NOT NULL auto_increment,
    title varchar(255) NOT NULL,
    blurb text,
    description text,
    image text,
    parent tinyint(8) NOT NULL default '0',
    active tinyint(4) default '1',
    priority tinyint(4) default '5',
    link varchar(255) default NULL,
    link_only tinyint(4) default '0',
    PRIMARY KEY (id),
    KEY title(title),
    KEY parent(parent),
    KEY active(active),
    KEY priority(priority)
    ) 
");
$tt_name=$t_name . "_category";
safe_query("CREATE TABLE $tt_name (
    id tinyint(255) NOT NULL auto_increment,
    name varchar(150) NOT NULL,
    description text,
    image varchar(50) default NULL,
    priority tinyint(4) NOT NULL default '5',
    visible tinyint(4) NOT NULL default '1',
    parent tinyint(8) NOT NULL default '0',
    created timestamp(14) NOT NULL,
    PRIMARY KEY (id),
    KEY name(name),
    KEY parent(parent),
    KEY priority(priority),
    KEY visible(visible)
    )
");
}

/* 
    --------------------------------------
    FUNCTION: create_admin_pages()
    string create_admin_pages (string t_name)
    --------------------------------------
*/                
function create_admin_pages($user,$t_name,$user_dir)
{
    if (empty($t_name)) { return FLASE; }     
    
    if ($other)
    {
        $other_m = "<br>" . $other . ":" . text_field("$other"); 
    }
    
    if ($other2)
    {
        $other2_m = "<br>" . $other2 . ":" . text_field("$other2"); 
    }  
    
    if ($other3)    
    {
        $other3_m = "<br>" . $other3 . ":" . text_field("$other3"); 
    }
    

          
    safe_table_create($user,$t_name,$other,$other2,other3);
    $page_name = "admin page for: " . $t_name . " section:";

    $list_link = $t_name . ".php?list=1&t_name=" . $t_name;
    $list_link2 = $t_name . ".php?list=2&t_name=" . $t_name;
   
    $admin_page = '<?php include ("header.inc.php");' 
        . "\n \$m_name = $t_name . \"_category\";\n" 
        . 'dbconnect();      
    $selector =  "<br><br>parent:<br>" . db_select_field("parent","$m_name","id","name");
    if($edit_item)
        {
            $output = edit_item($t_name,$id);
            $body_output = $output;           
        } 
        
        elseif($update_item)
        {
            $output = update_item($t_name,$id,$name,$blurb,$description,$priority,$active,$image, $link,$link_only,$parent);
            $body_output = $output;
        }
        
        elseif($list==1)
        {
        
            $output = list_item($t_name);
            $body_output = $output;
        }

        elseif($list==2)
        {
            $output = list_item($t_name);
            $body_output = $output;

        }
       
        elseif($add_item)
        {
            $output = add_item($t_name,$id,$name,$blurb,$description,$priority,$active,$image,$link,$link_only,$parent);
            $body_output = $output;
            
        }
        
        elseif($edit_category)
        {
            $output = edit_category($t_name,$id);   
            $body_output = $output;        
        }  
        
        elseif($update_category)
        {
            $output = update_category($t_name,$id,$name,$blurb,$description,$priority,$active,$image,$parent);
            $body_output = $output;
        }
        
        elseif($add_category)
        {
            $output = add_category($t_name,$id,$name,$blurb,$description,$priority,$active,$image,$parent);
            $body_output = $output;
        }
        else 
        {
        ' 
        . "\n\$body_output = <<<EOQ\n" 
        . subtitle($page_name) 
	        . start_form("$t_name.php") 
	. "<b>add items:</b><hr>name:<br>" . text_field("name","\$name")
        . "\n<br>blurb:<br>" . textarea_field("blurb","\$blurb")
        . "\n<br>description:<br>" . textarea_field("description","\$description")
        . "\n<br>priority:<br>" . text_field("priority","\$priority","2")
        . "\n<br>link:<br>" . text_field("link","\$link")
        . "\n<br>" . checkbox_field("link_only","1","link only","2")
        . "\n<br>" . checkbox_field("active","1","active","1") . '$selector'
        . $other_m . $other2_m . $other3_m
        . hidden_field("id","\$name")
        . hidden_field("add_item","1")
        . hidden_field("t_name","$t_name")
        . "\n<br>image:<br>" . file_field("image") . "<br><br>\n" . submit_field() . end_form()
        . anchor_tag("$list_link2","list all items")



	. "<b>add categories:</b>" . start_form("$t_name.php") . "<hr>name:<br>" . text_field("name","\$name")   
        . "\n<br>description:<br>" . textarea_field("description","\$description")    
        . "\n<br>priority:<br>" . text_field("priority","\$priority","2")    
        . "\n<br>" . checkbox_field("active","1","active","1") . '$selector'
        . hidden_field("add_category","1") . hidden_field("id","\$name") 
        . hidden_field("t_name","$t_name") 
        . "\n<br>image:<br>" . file_field("image") . "<br>" . submit_field() . end_form() 
        . anchor_tag("$list_link","list all categories")
        . "\nEOQ;\n
        
        
        
        \n          \n}"
                . "\n echo  \$menu_output . \$title_output . \$body_output ; 
include(\"footer.inc.php\");
                
      \n?>";
    
$user_page = '<?php 

include("header.inc.php");
if ($view_item)
{
    $body_output = view_item("$t_name","$id");
}
elseif ($view_category)
{
    $body_output = view_category("$t_name","$id");
}

else
{
    $body_output = category("' . $t_name . '");
}
?>
<?
echo $body_output;
include("footer.inc.php");
?>';        
    
    # Create user php file
    $filename = "$user_dir" . "/website/" . $t_name . ".php";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp, ($user_page));
    fclose ($fp);
    
    # Create admin php file
    $filename = "$user_dir" . "/website/admin/" . $t_name . ".php";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp, ($admin_page));
    fclose ($fp);

    # open admin menu
    $filename = $user_dir . "/website/admin/index.php";
    $fp = fopen("$filename","r");
    $admin_menu = fread ($fp, filesize("$filename"));
    fclose ($fp);    
    # customize
    $admin_add = "<a href=/admin/". $t_name . ".php>" . $t_name . "</a><br>\n<?php #menu ?>";	
    $admin_menu = str_replace("<?php #menu ?>","$admin_add","$admin_menu");

    # update admin index file
    $filename = "$user_dir" . "/website/admin/index.php";
    $fp = fopen ("$filename", "w+");
    fwrite ($fp, ($admin_menu));
    fclose ($fp);
    
    # open admin menu
    $filename = $user_dir . "/inc/header.inc.php";
    $fp = fopen("$filename","r");
    $admin_menu = fread ($fp, filesize("$filename"));
    fclose ($fp);
    # customize
    $admin_add = "<a href=/". $t_name . ".php>" . $t_name . "</a><br>\n<?php #menu ?>";
    $admin_menu = str_replace("<?php #menu ?>","$admin_add","$admin_menu");

    # update admin index file
    $fp = fopen ("$filename", "w+");
    fwrite ($fp, ($admin_menu));
    fclose ($fp);
	

    $result = "success!";
    
    return $result;
} 
Return current item: Slacker