mode = $mode;
        $this->titleField = "";
        $this->titleText = "";
        $this->numberedTitles = 0;
    }
    function test($query)
    {
        $hResult  = query_appdb($query);
        $nfields = query_num_fields($hResult);
        $nrows   = query_num_rows($hResult);
        $table   = query_field_table($hResult, 0);
        echo "Table: $table 
 Fields: $nfields 
 Rows: $nrows 
 
\n";
        $i = 0;
        while($i < $nfields)
        {
            $type = query_field_type($hResult, $i);
            $name = query_field_name($hResult, $i);
            $len  = query_field_len($hResult, $i);
            $flags = query_field_flags($hResult, $i);
            echo "$type | $name | $len | $flags 
\n";
            $i++;
        }
    }
    /* this is a bit of a hack,
     * we first create an empty entry, and then simply use the
     * edit() function to do the rest of the work for us.
     */
    function create($query, $table, $idcolumn)
    {
        $hResult = query_appdb($query);
        $id     = query_appdb_insert_id();
	
        $new_query = "SELECT * FROM $table WHERE $idcolumn = $id";
        $this->edit($new_query);
    }
    function view($query)
    {
        //$this->test($query);
        $nrows = 0;
        $hResult  = query_appdb($query);
        $nrows   = query_num_rows($hResult);
        if(debugging())
        {
            echo "Query returns $nrows rows.";
        }
        for($i = 0; $i < $nrows; $i++)
        {
            $this->view_entry($hResult, $i);
            echo "
\n";
        }
    }
    
    function view_entry($hResult, $num)
    {
        $nfields = query_num_fields($hResult);
        $fields = query_fetch_array($hResult, MYSQL_BOTH);
        $titleValue = $fields[$this->titleField];
        $titleText = $this->titleText;
        if($this->numberedTitles)
        {
            // don't want zero-based.
            $num++;
            $titleText .= "  # $num";
        }
        //echo "
| \n"; //echo " | ||||||||
|---|---|---|---|---|---|---|---|---|
| \n";
        
        echo html_frame_start("Viewing $titleValue $titleText","80%","",0);
        echo " 
 
 \n"; if(ereg($r, $name)) { //echo "ID for $name -> $id \n"; return $id; } } return null; } /** * update() expects $_POST as argument * this is where things are getting kinda complex, here we update " * multiple entries with multiple fields in multiple tables (get it?) */ function update($vars) { $tables = array(); $fieldnames = array(); $num_entries = 0; while(list($varname, $arr) = each($vars)) { if(!ereg("^FIELD_([a-zA-Z_]+)___(.+)$", $varname, $regs)) continue; $tables[$regs[1]][] = $regs[2]; $fieldnames[$regs[2]] = $arr; $num_entries = sizeof($arr); } while(list($table, $fields) = each($tables)) { echo " $table (".$this->get_id($table).") "; if($fieldnames[$this->get_id($table)]) echo "OK!"; echo " \n"; for($i = 0; $i < sizeof($fields); $i++) echo "- $fields[$i] \n"; echo " \n"; } for($i = 0; $i < $num_entries; $i++) { reset($tables); while(list($table, $fields) = each($tables)) { $update = "UPDATE $table SET "; $count = sizeof($fields); reset($fields); while(list($idx, $field) = each($fields)) { $count--; if($this->table_ids[$table] == $field) { continue; } $key = "FIELD_".$table."___".$field; $type = $vars["TYPE_$key"][$i]; if($type == "int") $update .= "$field = ".$vars[$key][$i]; else $update .= "$field = '".addslashes($vars[$key][$i])."'"; if($count) $update .= ", "; } $value = $fieldnames[$this->get_id($table)][$i]; $update .= " WHERE ".$this->get_id($table)." = $value"; if(query_appdb($update)) { addmsg("Database Operation Complete!","green"); } if(ereg("^impl_.+$", $table)) { $value = $fieldnames["apiid"][$i]; query_parameters("UPDATE ? SET lastmodby = '?' WHERE apiid = '?'", $table, $_SESSION['current']->iUserId, $value); } } } } function set_title_field($newTitleField) { $this->titleField = $newTitleField; } function set_title_text($newTitleText) { $this->titleText = $newTitleText; } function set_numbered_titles() { $this->numberedTitles = 1; } }; ?> | ||||||||