Location: PHPKode > scripts > Command Class > command-class/command_class.php
<?php

/*
File Name:      command_class.php
Orig Author:    James Dziak
Purpose:        This class takes a set of input commands and creates
                a load command for loading needed data files.
Input:          DOMAIN = Realm/database to use
                CMD = Main command sequencer
                SCMD = Sub-Command
                MODE = Normal or SECURE
Output:         None
Return:         None
Requirement:    main.php (MAIN), security_class.php (SECURITY_CLASS)
Notes:          None
*/

/*
Revision History

04-08-2002      First release submitted to phpclasses.org -JWD
10-09-2003      History added -JWD (NOTE: This has gone through a number
                of revisions since the First public release most of the
                assumptions made in the first release have been changed)
10-09-2003      clean up and recomment -JWD
10-09-2003      Updated Error codes to new design -JWD
10-09-2003      Added requirement for Security class -JWD
10-09-2003      Updated to use query_class -JWD
10-09-2003      Added full set of Get and Set methods for Domain
                Command and Sub Command -JWD
10-09-2003      Updated internal updates to use method calls rather
                than direct updates -JWD
*/

if (!defined("MAIN")) {
        die ("FATAL ERROR: required file not loaded: main.php (12)");
}
if (!defined("SECURITY_CLASS")) {
        global $tools;
        $tools->fatal_error(16);
}

if (!defined("COMMAND_CLASS")) {
        define("COMMAND_CLASS",1);
} else {
        global $tools;
        $tools->fatal_error(8);
}

Class Command_CLASS {

// Properties
        var $domain;
        var $command;
        var $sub_command;
        var $mode;
        var $file;
        var $sec;
        var $title;

/*
Function:       Command_CLASS
Purpose:        This is the constructor for the Command Class.
Input:          POST variables (DOMAIN, CMD, and SCMD)
Output:         None
Return:         None
Notes:          None
*/
function Command_CLASS ($DOMAIN = "", $CMD = "", $SCMD = "") {
        $this->set_domain($DOMAIN);
        $this->set_command($CMD);
        $this->set_sub_command($SCMD);
        //Check the database and load the other properties
        $this->load();
//END Command_CLASS
}

/*
Function:       load
Purpose:        Take the Command set and check the database and load
                remaining data such as the data path and page title.
Input:          None
Output:         None
Return:         None
Notes:          If the DOMAIN is IMAGE there is only one record to
                be loaded while the Image class uses the command
                and sub_command in other ways so they can not be
                changed this is why we don't just over ride as we
                do for the default.
*/
function load () {
        global $database;
        global $tools;
        global $query;
        $d = $this->get_domain();
        $c = $this->get_command();
        $s = $this->get_sub_command();
        if (empty($d)) {
                $this->set_domain("DEFAULT");
        }
        if (empty($c)) {
                $this->set_command("DEFAULT");
        }
        if (empty($s)) {
                $this->set_sub_command("DEFAULT");
        }
        if ($this->get_domain() =="IMAGE") {
                $q = $query->get_command("IMAGE","DEFAULT","DEFAULT");
        } else {
                $q = $query->get_command($this->domain,$this->command,
                        $this->sub_command);
        }
        $n = $database->num_rows($q);
        if ($n > 1) {
                $tools->fatal_error(71);
        } else if ($n == 0) {
                $tools->fatal_error(72);
        }
        $data = $database->get_row($q);
        $this->file = $data->File;
        $this->sec = $data->Security;
        $this->title = $data->Title;
}

/*
Function:       load_command
Purpose:        Load the file set from the database based on the
                command submitted.
Input:          None
Output:         None
Return:         None
Notes:          None
*/
function load_command() {
        global $tools;
        global $database;
        global $query;
        $uname = $tools->clean_text($_SERVER['PHP_AUTH_USER']);
        if (!empty($uname) && ($this->sub_command != "VERIFY_LOCK")) {
                $q = $query->user_lookup($uname);
                $row = $database->get_row($q);
                if (!empty($row->Lock_Key)) {
                        $this->set_domain("DEFAULT");
                        $this->set_command("LOGIN");
                        $this->set_sub_command("LOCK_RELEASE");
                        $this->load();
                }
        }
        if ($this->sec == "Secure") {
                global $security;
                $security->authenticate();
        }
        require_once $this->file;
}

/*
Function:       get/set_*
Purpose:        To get or set the property (Public Methods)
Input:          value for sets None for Gets
Output:         None
Return:         None
Notes:          These are all single line methods that can be use
                by other classes to affect command_class properties
                While PHP does not currently support public/private
                data this is still the correct way to do this.  All
                other properties are private and thus don't need a
                set or get since we can directly access them in this
                class without breaking any rules.
*/

function get_title() {
        return $this->title;
}

function get_domain() {
        return $this->domain;
}

function get_command() {
        return $this->command;
}

function get_sub_command() {
        return $this->sub_command;
}

function set_domain($d="") {
        $this->domain = $d;
}

function set_command($c="") {
        $this->command = $c;
}

function set_sub_command($s="") {
        $this->sub_command = $s;
}
// END get/set*

// End Command Class
}
// END command_class.php
?>
Return current item: Command Class