Exemplo n.º 1
0
function core_getClass($class, $id, $continueOnError = False)
{
    /* this version works only for the "standard" classes with args (id,db,mode) */
    $class = ereg_replace('formform', 'form', $class);
    $cache = new cache('core_getClass');
    if ($cache->wasSet($class, $id)) {
        return $cache->get();
    }
    if ($_GET["mode"] != 'RW') {
        $_GET["mode"] = 'RO';
    }
    if ((int) $id) {
        if (!get_class($GLOBALS["appsDB"])) {
            core_internalError("core_getClass: DB not initialized");
        }
        $svdebug = $GLOBALS["appsDB"]->debug;
        $GLOBALS["appsDB"]->debug = 0;
        if (!($identity = $GLOBALS["identities"][$class])) {
            core_internalError("no identities for {$class}");
        }
        $q = $GLOBALS["appsDB"]->query("SELECT " . $identity["i"] . " AS id FROM " . $identity["t"] . " WHERE " . $identity["i"] . " = {$id}");
        $GLOBALS["appsDB"]->debug = $svdebug;
        if ($GLOBALS["appsDB"]->num_rows($q)) {
            return $cache->set(new $class($id, $GLOBALS["appsDB"], $_GET["mode"]));
        }
        $error = "does not exist in the database";
    } else {
        return new $class($id, $GLOBALS["appsDB"], $_GET["mode"]);
    }
    if (!$continueOnError) {
        core_dbg(redText('core_getClass'), redText("{$class}({$id})"), redText($error), core_getOption('YBhere'));
        core_backtrace();
    }
}
Exemplo n.º 2
0
 function dbg($f, $value)
 {
     if ($this->debug) {
         list($name, $id, $key) = $this->fromStack();
         if ($id == "anyID") {
             $id = "";
         }
         if ($key == "anyKEY") {
             $key = "";
         }
         if ($key) {
             $id .= "," . $key;
         }
         if ($id) {
             $id = "(" . $id . ")";
         }
         if (is_object($value)) {
             $value = $value->name();
         }
         core_dbg(redText($this->ID . "-" . strtoupper($f), $this->c), redText($name . $id, $this->c), redText($value, $this->c), $this->debug);
     }
 }