Beispiel #1
0
 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);
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 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;
     }
 }
Beispiel #5
0
 /**
  * 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;
 }
Beispiel #6
0
 /**
  * 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();
 }
Beispiel #7
0
 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;
 }
Beispiel #8
0
 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));
         }
     }
 }