Exemple #1
0
function dbos_delete($table, $id, $db, $indexField = false)
{
    $dbo = new DBOS($table, $id, $db, $indexField);
    $dbo->delete();
    show_success("Deleted record {$id} from table {$table}");
}
    public function adminPage($action = false)
    {
        if (!$action) {
            $action = $_REQUEST['action'];
        }
        if (!$table) {
            $table = $_REQUEST['table'];
        }
        // Only supports simple index fields.
        if (!is_array($this->_idField)) {
            if (!$id) {
                $id = $_REQUEST[$this->_idField];
            }
        } else {
            foreach ($this->_idField as $field) {
                $id[$field] = $_REQUEST[$field];
            }
        }
        $this->adminPageTop();
        switch ($action) {
            case "delete":
                $obj = DBOS::factory($this->_table, $id);
                $obj->delete();
                show_success("The record was delete from " . $this->_table);
                $this->showTable();
                break;
            case "summary":
            case $this->_table . "_summary":
                $obj = DBOS::factory($this->_table, $id);
                // Should be toAdminHTML.
                if (is_numeric($obj->id)) {
                    ?>
| <a class="editMe" href="<?php 
                    echo $_SERVER[PHP_SELF];
                    ?>
?action=edit&table=<?php 
                    echo $obj->_table;
                    ?>
&<?php 
                    echo $this->_idField;
                    ?>
=<?php 
                    echo $obj->id;
                    ?>
">Edit this <?php 
                    echo $obj->_table;
                    ?>
</a><?php 
                }
                $obj->toHTML();
                break;
            case "edit_" . $this->_table:
            case "edit":
                $obj = DBOS::factory($this->_table, $id);
                $obj->showForm();
                break;
            case "db_edit_" . $this->_table:
                $obj = DBOS::factory($this->_table, $id);
                $obj->saveForm();
                $this->showTable();
                break;
            case "list":
            case "":
                $this->showTable();
                break;
            default:
                ?>
The action <?php 
                echo $action;
                ?>
 is not defined for this the <?php 
                echo $this->_table;
                ?>
 class.  Use Object->adminPage to set.<?php 
        }
    }
    function dumpRecords($opts = false)
    {
        if (is_array($opts)) {
            extract($opts);
        }
        if ($header) {
            ?>
<textarea cols="160" rows="200"><?php 
        }
        // dump the master record.
        foreach ($this->tbl as $f) {
            $sets[] = " {$f['field']} = '" . mes($this->{$f}[field]) . "'";
        }
        $out = " INSERT INTO {$this->_table} SET " . implode(",", $sets);
        echo $out;
        // dump dependent records
        echo "\r\r\r\r";
        $this->getRelated();
        $tables_used = array($this->_table);
        foreach ($this->_related as $rel) {
            // get relations
            if ($rel['table'] != $this->_table) {
                $sql = "SELECT * FROM " . $rel['table'] . " WHERE {$this->indexField} = {$this->id} ";
                $result = acquery($sql, $rel['db']);
                while ($row = mysql_fetch_array($result)) {
                    extract($row);
                    $link = new DBOS($rel['table'], $row[0], $rel['db']);
                    $link->dumpRecords();
                    $tables_used[] = $rel['table'];
                }
            }
        }
        if ($header) {
            ?>
</textarea><?php 
        }
    }