function checkDebug($req = false) { $req = $req === false ? $_REQUEST : $req; if (isset($req['_debug']) && $this->authUser && (method_exists($this->authUser, 'canDebug') && $this->authUser->canDebug() || method_exists($this->authUser, 'groups') && is_a($this->authUser, 'Pman_Core_DataObjects_Person') && in_array('Administrators', $this->authUser->groups('name')))) { DB_DAtaObject::debuglevel((int) $req['_debug']); } }
function get($table) { $d = DB_DAtaObject::Factory($table); if (method_exists($d, 'availableColumns')) { $cols = $d->availableColumns(); } else { $re = $d->autoJoin(); //echo '<PRE>';print_r($re); $cols = $re['cols']; $types = array(); $tables = array(); $schemas = array($table => $d->table()); foreach ($cols as $name => $table_col) { list($tbl, $col) = explode('.', $table_col); if (!isset($schemas[$tbl])) { $schemas[$tbl] = DB_DataObject::Factory($tbl)->table(); } $types[$name] = $schemas[$tbl][$col]; $tables[$name] = $tbl; } foreach ($re['join_names'] as $c => $f) { $cols[$c] = $f; } } foreach ($cols as $c => $f) { $ret[] = array('name' => $c, 'val' => $f, 'type' => isset($types[$c]) ? $this->typeToName($types[$c]) : -1, 'table' => isset($tables[$c]) ? $tables[$c] : ""); } $this->jdata($ret); }
function get($id) { $ev = DB_DataObject::Factory('Events'); if (!$ev->get((int) $id)) { $this->jerr("invalid id"); } // verify if not admin, then they should $g = DB_DataObject::Factory('core_group_member'); if (is_a($g, 'DB_DataObject')) { $grps = $g->listGroupMembership($this->authUser); //var_dump($grps); $isAdmin = $g->inAdmin; if (!$isAdmin && $ev->person_id != $this->authUser->id) { $this->jerrAuth(); } } echo '<PRE>' . htmlspecialchars(print_r($ev->toArray(), true)) . "</PRE>"; // we have 2 bits of data available at present: // core_event_audit // the event file.. $d = DB_DataObject::factory('core_event_audit'); if (is_a($d, 'DB_DataObject')) { echo "<H2>Changed Data:</H2>"; $d->event_id = $ev->id; foreach ($d->fetchAll() as $d) { echo "{$d->name} SET TO: " . htmlspecialchars($d->newvalue) . "<br/>\n"; } } echo "<HR><H2>Posted Data:</H2>"; $logdir = DB_DAtaObject::Factory('Events')->logDir(); if (!$logdir) { echo "not available (Pman[storedir] not configured)"; exit; } $file = $logdir . date('/Y/m/d/', strtotime($ev->event_when)) . $ev->id . ".php"; if (file_exists($file)) { echo '<PRE>' . htmlspecialchars(file_get_contents($file)) . '</PRE>'; } $file = $logdir . date('/Y/m/d/', strtotime($ev->event_when)) . $ev->id . ".json"; if (!file_exists($file)) { echo "not available (missing file) {$file}"; exit; } echo '<PRE>' . htmlspecialchars(print_r(json_decode(file_get_contents($file)), true)) . '</PRE>'; echo '<BR/><PRE>' . htmlspecialchars($ev->remarks) . '</PRE>'; $json = json_decode($ev->remarks, JSON_PRETTY_PRINT); if (json_last_error() == JSON_ERROR_NONE) { echo "<HR><H2>JSON DECODE Data:</H2>"; echo '<PRE>' . print_r($json, true) . '</PRE>'; } $filesJ = json_decode(file_get_contents($file)); echo '<br /><PRE>Download files</PRE>'; foreach ($filesJ->FILES as $k => $f) { $ip = $ff->baseURL . "/Images/events/" . $ev->id . '/' . $f->tmp_name; echo '<a href="' . $ip . '/download">' . htmlspecialchars($k . ' - ' . $f->name) . '</a><br/>'; } exit; }
function beforeDelete($dependants_array, $roo) { if (count($dependants_array) != 1) { //$roo->jerr("more than one dependant type...."); return true; // standard error message. } $p = DB_DAtaObject::Factory('core_person'); if (!is_a($dependants_array[0], get_class($p))) { $roo->jerr("dep is not a person.."); return true; } $p->office_id = $this->id; if ($p->count() > 1) { return true; // default err.. } $p->find(true); $pp = clone $p; $p->office_id = 0; $p->update($pp); return true; }
function outputBody() { if ($this->timer) { $this->timer->setMarker(__CLASS__ . '::outputBody - start'); } $ff = HTML_FlexyFramework::get(); $proj = $ff->project; // DB_DataObject::debugLevel(1); $m = DB_DAtaObject::factory('Builder_modules'); $m->get('name', $proj); //var_dump($m->path);exit; // needs to modify the template directory?? // use the builder_module == app name // look for part with same name. if (empty($ff->Pman_Builder['from_filesystem'])) { $template_engine = new HTML_Template_Flexy(array('templateDir' => $m->path)); } else { $template_engine = new HTML_Template_Flexy(); } $template_engine->debug = 1; //print_R($template_engine); $template_engine->compile($this->template); if ($this->elements) { /* BC crap! */ $this->elements = HTML_Template_Flexy_Factory::setErrors($this->elements, $this->errors); } $template_engine->elements = $this->elements; if ($this->timer) { $this->timer->setMarker(__CLASS__ . '::outputBody - render template'); } //DB_DataObject::debugLevel(1); $template_engine->outputObject($this, $this->elements); if ($this->timer) { $this->timer->setMarker(__CLASS__ . '::outputBody - end'); } }
function downloadEvent($bits) { $popts = PEAR::getStaticProperty('Pman', 'options'); $ev = DB_DAtaObject::Factory('events'); if (!$ev->get($bits[1])) { die("could not find event id"); } // technically same user only.. -- normally www-data.. if (function_exists('posix_getpwuid')) { $uinfo = posix_getpwuid(posix_getuid()); $user = $uinfo['name']; } else { $user = getenv('USERNAME'); // windows. } $ff = HTML_FlexyFramework::get(); $file = $ff->Pman['event_log_dir'] . '/' . $user . date('/Y/m/d/', strtotime($ev->event_when)) . $ev->id . ".json"; $filesJ = json_decode(file_get_contents($file)); //print_r($filesJ); foreach ($filesJ->FILES as $k => $f) { if ($f->tmp_name != $bits[2]) { continue; } $src = $ff->Pman['event_log_dir'] . '/' . $user . date('/Y/m/d/', strtotime($ev->event_when)) . $f->tmp_name; if (!file_exists($src)) { die("file was not saved"); } header('Content-Type: ' . $f->type); header("Content-Disposition: attachment; filename=\"" . basename($f->name) . "\";"); @ob_clean(); flush(); readfile($src); exit; } }
/** * convert email with contents into a core mailer object. - ready to send.. * @param Object|Array $obj Object (or array) to send @see Pman_Core_Mailer * + subject * + rcpts || person << if person is set - then it goes to them... * + rcpts_group (string) << name of group - normally to send admin emails.. (if set, then bcc_group is ignored.) * + replace_links * + template * + mailer_opts * + person << who it actually goes to.. * * @param bool $force - force re-creation of cached version of email. * * @returns Pman_Core_Mailer||PEAR_Error */ function toMailer($obj, $force = false) { $p = new PEAR(); $contents = (array) $obj; if (empty($this->id) && !empty($contents['template'])) { $this->get('name', $contents['template']); } if (empty($this->active)) { return $p->raiseError("template [{$contents['template']}] is Disabled"); } if (empty($this->id)) { return $p->raiseError("template [{$contents['template']}] has not been set"); } // fill in BCC if (!empty($this->bcc_group) && empty($contents['rcpts_group'])) { $admin = DB_DAtaObject::Factory('core_group')->lookupMembersByGroupId($this->bcc_group, 'email'); if (empty($admin)) { return $p->raiseError("template [{$contents['template']}] - bcc group is empty"); } $contents['bcc'] = $admin; } if (!empty($contents['rcpts_group'])) { $admin = DB_DAtaObject::Factory('core_group')->lookupMembers($contents['rcpts_group'], 'email'); if (empty($admin)) { return $p->raiseError("Trying to send to {$contents['rcpts_group']} - group is empty"); } $contents['rcpts'] = $admin; } if (empty($contents['subject'])) { $contents['subject'] = $this->subject; } if (!empty($contents['rcpts']) && is_array($contents['rcpts'])) { $contents['rcpts'] = implode(',', $contents['rcpts']); } $ui = posix_getpwuid(posix_geteuid()); $cachePath = session_save_path() . '/email-cache-' . $ui['name'] . '/mail/' . $this->tableName() . '-' . $this->id . '.txt'; if ($force || !$this->isGenerated($cachePath)) { $this->cachedMailWithOutImages($force, empty($contents['replace_links']) ? false : $contents['replace_links']); } require_once 'Pman/Core/Mailer.php'; $templateDir = session_save_path() . '/email-cache-' . $ui['name']; //print_r($this); $cfg = array('template' => $this->tableName() . '-' . $this->id, 'templateDir' => $templateDir, 'page' => $this, 'contents' => $contents, 'css_embed' => true); if (isset($contents['rcpts'])) { $cfg['rcpts'] = $contents['rcpts']; } if (isset($contents['mailer_opts']) && is_array($contents['mailer_opts'])) { $cfg = array_merge($contents['mailer_opts'], $cfg); } $r = new Pman_Core_Mailer($cfg); $imageCache = session_save_path() . '/email-cache-' . $ui['name'] . '/mail/' . $this->tableName() . '-' . $this->id . '-images.txt'; if (file_exists($imageCache) && filesize($imageCache)) { $images = json_decode(file_get_contents($imageCache), true); $r->images = $images; } return $r; }
function passwordRequest($n) { $u = DB_DataObject::factory('core_person'); //$u->company_id = $this->company->id; $u->whereAdd('LENGTH(passwd) > 1'); $u->email = $n; $u->active = 1; if ($u->count() > 1 || !$u->find(true)) { $this->jerr('invalid User (1)'); } // got a avlid user.. if (!strlen($u->passwd)) { $this->jerr('invalid User (2)'); } // check to see if we have sent a request before.. if ($u->no_reset_sent > 3) { $this->jerr('We have issued to many resets - please contact the Administrator'); } // sort out sender. $cm = DB_DataObject::factory('core_email'); if (!$cm->get('name', 'ADMIN_PASSWORD_RESET')) { $this->jerr("no template ADMIN_PASSWORD_RESET exists - please run importer "); } /* $g = DB_DAtaObject::factory('Groups'); if (!$g->get('name', 'system-email-from')) { $this->jerr("no group 'system-email-from' exists in the system"); } $from_ar = $g->members(); if (count($from_ar) != 1) { $this->jerr(count($from_ar) ? "To many members in the 'system-email-from' group " : "'system-email-from' group does not have any members"); } */ // bcc.. $g = DB_DAtaObject::factory('core_group'); if (!$g->get('name', 'bcc-email')) { $this->jerr("no group 'bcc-email' exists in the system"); } $bcc = $g->members('email'); if (!count($bcc)) { $this->jerr("'bcc-email' group does not have any members"); } $this->authFrom = time(); $this->authKey = $u->genPassKey($this->authFrom); //$this->authKey = md5($u->email . $this->authFrom . $u->passwd); $this->person = $u; $this->bcc = $bcc; $this->rcpts = $u->getEmailFrom(); $ret = $cm->send($this); //$this->jerr(print_r($r->toData(),true)); if (is_object($ret)) { $this->addEvent('SYSERR', false, $ret->getMessage()); $this->jerr($ret->getMessage()); } $this->addEvent('PASSREQ', $u, $u->email); $uu = clone $u; $uu->no_reset_sent++; $uu->update($u); $this->jok("done"); }
/** * DO NOT USE THIS -- see core_curr_rates dataobject. * */ function loadRates() { static $rates = array(); if (!empty($rates)) { $this->rates = $rates; return; } $this->rates = $rates = DB_DAtaObject::Factory('core_curr_rate')->currentRates(); }
function currentRates() { $this->loadRates(); // DB_DataObject::debugLevel(1); $c = DB_DAtaObject::factory('core_curr_rate'); $c->whereAdd('from_dt < NOW() AND to_dt > NOW()'); $c->find(); $ret = array(); while ($c->fetch()) { $ret[$c->curr] = $c->rate; } return $ret; }
function loginPublic() { $this->isAuth(); // force session start.. $db = $this->getDatabaseConnection(); $ff = HTML_FlexyFramework::get(); if (empty($ff->Pman) || empty($ff->Pman['login_public'])) { return false; } $sesPrefix = $ff->Pman['login_public'] . '-' . get_class($this) . '-' . $db->dsn['database']; $p = DB_DAtaObject::Factory($this->tableName()); $p->get($this->pid()); $_SESSION[get_class($this)][$sesPrefix . '-auth'] = serialize((object) $p->toArray()); return true; }
function initEnums($data, $base = array()) { // base only contains etype... //print_r($data); $seq_id = 0; if (!empty($base['etype'])) { $seq_id = 1; $t = DB_DAtaObject::Factory('core_enum'); $t->etype = $base['etype']; $t->selectAdD(); $t->selectAdD('max(seqid) as seqid'); if ($t->find(true)) { $seq_id = $t->seqid + 1; } } foreach ($data as $row) { $t = DB_DAtaObject::Factory('core_enum'); $t->etype = isset($row['etype']) ? $row['etype'] : ''; $t->etype = isset($base['etype']) ? $base['etype'] : $t->etype; $t->name = isset($row['name']) ? $row['name'] : ''; if (empty($t->name)) { print_R($data); die("ERROR: invalid name used for core_enum\n\n"); } if (!$t->count()) { // base already gave it the etype.. $t->setFrom($row); //$t->is_system_enum = 1; // this should be on the caller.. if (!empty($row['seqid']) && !is_numeric($row['seqid'])) { $t->seqid = $seq_id; $seq_id++; } $t->insert(); } else { $t->find(true); // fetch it.. $o = clone $t; if (isset($row['is_system_enum'])) { $t->is_system_enum = isset($row['is_system_enum']) ? $row['is_system_enum'] : $t->is_system_enum; } $t->display_name = isset($row['display_name']) ? $row['display_name'] : $t->display_name; $t->seqid = isset($row['seqid']) ? $row['seqid'] : $t->seqid; $t->update($o); } if (!empty($row['cn'])) { $this->initEnums($row['cn'], array('etype' => $t->name)); } } }
function listTriggerFunctions($table, $type) { static $cache = array(); if (!isset($cache[$table])) { $cache[$table] = array(); $q = DB_DAtaObject::factory('core_enum'); $q->query("SELECT\n SPECIFIC_NAME\n FROM\n information_schema.ROUTINES\n WHERE\n ROUTINE_SCHEMA = '{$q->escape($q->database())}'\n AND\n ROUTINE_NAME LIKE '" . $q->escape("{$table}_trigger_") . "%'\n AND\n ROUTINE_TYPE = 'PROCEDURE'\n \n "); while ($q->fetch()) { $cache[$table][] = $q->SPECIFIC_NAME; } } // now see which of the procedures match the specification.. $ret = array(); foreach ($cache[$table] as $cname) { $bits = explode("_before_{$type}_", $cname); if (count($bits) < 2) { continue; } $ret[$cname] = $bits[1]; } return $ret; }
function person() { $p = DB_DAtaObject::factory('core_person'); $p->get($this->person_id); return $p; }