title = $id; $this->menu_div = $menu_div_class; $this->cmd_id = $cmd; $this->table = $table_name; $this->default_id = $default_id; $this->order_by = $order; } // function: execute query $query // returns: result identifier function query($query) { // connect $connection = mysql_connect($this->hostname, $this->user, $this->password) or die ("Cannot connect to database"); // run query mysql_select_db($this->db, $connection); $ret = mysql_query($query, $connection) or die ("Error in query: $query"); // return result identifier return $ret; } // function: set database parameters // returns: none function set_database_parameters($hostname, $user, $password, $db) { $this->hostname = $hostname; $this->user = $user; $this->password = $password; $this->db = $db; } function get_id_by_type($type,$string) { $query = "SELECT id FROM $this->table WHERE $type = '$string'"; $result = $this->query($query); $row = mysql_fetch_row($result); return $row[0]; } function get($type, $id) { $query = "SELECT $type FROM $this->table WHERE id = '$id'"; $result = $this->query($query); $row = mysql_fetch_row($result); return $row[0]; } function rollover($id) { $query = "SELECT rollover FROM rollovers WHERE id = '$id'"; $result = $this->query($query); $row = mysql_fetch_row($result); return $row[0]; } function parse_cmd() { $this->select_id = $this->get_id_by_type("id", $_GET[$this->cmd_id]); if (is_null($this->select_id)) { $this->select(null); return null; } return $this->select_id; } // the $arg input is an id function select($arg) { $this->select_id = $this->get_id_by_type("id", $arg); } function strip_keys($cmds, $keys) { foreach ($cmds as $key => $value) { if (in_array($key, $keys)) { unset($cmds[$key]); } } return $cmds; } function usedefault() { $this->select_id = $this->default_id; } function get_children($id) { $query = "SELECT id FROM $this->table WHERE parent = '$id' ORDER BY $this->order_by"; $result = $this->query($query); $children = array(); while ($row = mysql_fetch_array($result)) { $children[] = $row[0]; } return $children; } function make_url ($args) { $str = ''; foreach ($args as $key => $value) { if ($value) { $str .= (strlen($str) < 1) ? "?" : "&"; $str .= $key . '=' . rawurlencode($value); } } $href = $_SERVER["PHP_SELF"] . $str; return $href; } function make_link($id, $rollover, $divclass, $deactivate=0) { $linktext = $this->get("linktext", $id); $linkarg = $this->get("id", $id); $str = "make_url(array($this->cmd_id => $linkarg)) . "\""; } $str .= ">". $linktext .""; return $str; } function create_menu_item($id, $check_current, $level) { $linktitle = $this->rollover($id); $check_current &= ($id == $this->select_id); $divclass = "l".$level.(($check_current) ? " current" : "") ; echo $this->make_link($id, $linktitle, $divclass)."\n"; } // function: return a list of this node's parents // by travelling upwards all the way to the root of the tree // returns: array function is_ancestor($ancestor, $id) { // get parent of this node $parent = $this->get("parent",$id); if (($parent == $ancestor) or ($ancestor == "0") or ($ancestor == $id)) { return 1; } if (!is_null($parent)) { return $this->is_ancestor($ancestor, $parent); } return 0; } // function: displays the root tree and expanded tree for selected node // returns HMTL function print_children($all, $id, $level = 1) { $this->create_menu_item($id, 1, $level); if ($all || ($this->is_ancestor($id, $this->select_id))) { foreach($this->get_children($id) as $child) { $this->print_children($all, $child, $level + 1); } } } function print_menu($all,$level=0) { // echo "

".$this->title."

\n"; echo "
menu_div."\">\n"; echo "

".$this->title."

\n"; foreach($this->get_children(0) as $child) { $this->print_children($all, $child,$level); } echo "
\n"; } // end } ?>