/** * Call util to set remove stale records and set UUID, and then setup any * table-specific data. * * @param Doctrine_Event $event */ function preInsert($event) { trec_make_new($this); // table-specific $this->out_headline = "Outcome Headline - " . $this->out_uuid; $this->out_teaser = "Outcome Teaser - " . $this->out_uuid; $this->out_dtim = air2_date(); parent::preInsert($event); }
/** * Converts dotted quad to long integer for tb_ip. * * @param unknown $event * @return parent preValidate */ public function preValidate($event) { if (!is_numeric($this->tb_ip)) { $this->tb_ip = ip2long($this->tb_ip); } if (!$this->tb_dtim) { $this->tb_dtim = air2_date(); } return parent::preValidate($event); }
/** * * * @return unknown * @param unknown $pinq */ protected function air_delete($pinq) { if (!$pinq->user_may_delete($this->user)) { throw new Rframe_Exception(Rframe::BAD_DATA, "Invalid Query authz"); } $project = $pinq->Project; // log activity $activity = new InquiryActivity(); $activity->ia_inq_id = $this->parent_rec->inq_id; $activity->ia_actm_id = 49; $activity->ia_dtim = air2_date(); $activity->ia_desc = sprintf('project %s removed by {USER}', $project->prj_name); $activity->save(); }
/** * Loads login view and authenticate users * * we do explicit load->view calls here because the login screen is * independent of the rest of the View architecture. */ public function index() { // redirect to original request, or home page $back = $this->input->get_post('back'); if (!isset($back) || !strlen($back)) { $back = site_url(''); } // admin allows overriding PIN SSO $admin = false; if (isset($this->input_all['admin']) && $this->input_all['admin']) { $admin = true; } if (isset($_GET['admin']) && $_GET['admin']) { $admin = true; } // create stash $stash = array('static_url' => site_url(), 'back' => $back, 'c' => $this, 'admin' => $admin); // GET requests show a login form if ($this->method == 'GET') { // special case. // if we are configured to trust the PIN SSO tkt (auth_tkt) // then check for it and use its "sso" data value // as the AIR2 username if (AIR2_PIN_SSO_TRUST && !$admin) { $tkt = $this->input->cookie(AIR2_PIN_SSO_TKT); if (!$tkt) { $tkt = $this->input->get_post(AIR2_PIN_SSO_TKT); } if ($tkt) { $at = new Apache_AuthTkt(array('conf' => AIR2_PIN_SSO_CONFIG, 'encrypt_data' => false)); //Carper::carp("got auth_tkt for trust pin sso"); if ($at->validate_ticket($tkt)) { $tkt_info = $at->parse_ticket($tkt); $tkt_data = json_decode($tkt_info['data'], true); if (isset($tkt_data['sso'])) { $username = $tkt_data['sso']; $user = $this->_fetch_user($username); if ($user) { // trust prior authentication. create the AIR2 tkt. $this->airuser->create_tkt($user, true, true); $user->user_login_dtim = air2_date(); $user->save(); //echo "Location: $back\n"; redirect($back); } else { Carper::carp("Invalid user in tkt"); redirect(AIR2_PIN_SSO_URL . '?back=' . $back); } } else { Carper::carp("Missing sso param in tkt"); redirect(AIR2_PIN_SSO_URL . '?back=' . $back); } } else { Carper::carp("Invalid tkt"); redirect(AIR2_PIN_SSO_URL . '?back=' . $back); } } else { // no PIN tkt; redirect to PIN login Carper::carp("No PIN SSO tkt"); redirect(AIR2_PIN_SSO_URL . '?back=' . $back); } } // print form $this->load->view('login', $stash); } elseif ($this->method == 'POST') { header('Access-Control-Allow-Origin: *'); // allow external $uname = isset($this->input_all['username']) ? $this->input_all['username'] : null; // #9505 - xss-filter messes up passwords, so get raw input $pwd = isset($_POST['password']) ? $_POST['password'] : null; // didn't enter username or password if (!$uname || !$pwd || strlen($uname) < 1 || strlen($pwd) < 1) { if ($this->view == "json") { header('X-AIR2: authentication failed', false, 400); $resp = array('success' => false, 'message' => 'invalid request'); print json_encode($resp); } elseif ($this->view == "xml") { header('X-AIR2: authentication failed', false, 400); // TODO use 'xml' view print "<air2><success>false</success><message>invalid request</message></air2>"; } else { $stash['errormsg'] = 'You must enter both a username and password'; $this->load->view('login', $stash); } return; } // bad username $user = $this->_fetch_user($uname); if (!$user || !$user->exists()) { if ($this->view == "json") { header('X-AIR2: authentication failed', false, 401); $resp = array('success' => false, 'message' => 'authentication failed'); print json_encode($resp); return; } elseif ($this->view == "xml") { header('X-AIR2: authentication failed', false, 401); // TODO use 'xml' view print "<air2><success>false</success><message>authentication failed</message></air2>"; return; } else { $stash['errormsg'] = 'The information you entered does not match an active account'; $this->load->view('login', $stash); return; } } // delegate to PIN SSO? $pw_ok = false; // the !$admin means we avoid infinite loop with the SSO service, // which just points back here. if (AIR2_PIN_SSO_TRUST && !$admin) { $pw_ok = $this->check_pin_sso($uname, $pwd); } else { $pw_ok = $user->check_password($pwd); } // bad password if (!$pw_ok) { if ($this->view == "json") { header('X-AIR2: authentication failed', false, 401); $resp = array('success' => false, 'message' => 'authentication failed'); print json_encode($resp); return; } elseif ($this->view == "xml") { header('X-AIR2: authentication failed', false, 401); // TODO use 'xml' view print "<air2><success>false</success><message>authentication failed</message></air2>"; return; } else { $stash['errormsg'] = 'The information you entered does not match an active account'; $this->load->view('login', $stash); //TODO -- form error msg return; } } // authenticated ok. create the tkt. $tkt = $this->airuser->create_tkt($user, true, true); $user->user_login_dtim = air2_date(); $user->save(); // non-html response does not redirect if ($this->view == "json") { $tkt['success'] = true; print json_encode($tkt); return; } elseif ($this->view == "xml") { header('X-AIR2: authentication failed', false, 401); // TODO use 'xml' view print "<air2><success>true</success><air2_tkt>" . $tkt['air2_tkt'] . "</air2_tkt></air2>"; return; } else { redirect($back); } } }
/** * Create * * @param array $data * @return Doctrine_Record $rec */ protected function air_create($data) { $name = isset($data['tm_name']) ? $data['tm_name'] : null; $tmid = isset($data['tm_id']) ? $data['tm_id'] : null; if (!$name && !$tmid) { throw new Rframe_Exception(Rframe::BAD_DATA, "Required data 'tm_name' or 'tm_id'"); } // create tag $input = $tmid ? $tmid : $name; $use_id = $tmid ? true : false; $rec = TagSource::create_tag('TagResponseSet', $this->parent_rec->srs_id, $input, $use_id); if (!$rec) { throw new Rframe_Exception(Rframe::BAD_DATA, "Invalid tm_id({$tmid})"); } if ($rec->exists()) { $rec->tag_upd_user = $this->user->user_id; $rec->tag_upd_dtim = air2_date(); } return $rec; }
/** * * * @param unknown $data * @return unknown */ protected function air_delete($inq_auth) { $user = $inq_auth->User; // log activity $activity = new InquiryActivity(); $activity->ia_inq_id = $this->parent_rec->inq_id; $activity->ia_actm_id = 49; $activity->ia_dtim = air2_date(); $activity->ia_desc = sprintf('author %s removed by {USER}', $user->user_username); $this->parent_rec->InquiryActivity[] = $activity; }
/** * Log a src_activity to indicate that we merged a source. * * @param array $result_data * @param array $response_data */ protected function log_activity($result_data, $response_data) { $sa = new SrcActivity(); $sa->sact_actm_id = ActivityMaster::SRCINFO_UPDATED; $sa->sact_src_id = $this->prime->src_id; $sa->sact_dtim = air2_date(); $old_usr = $response_data['MergeSource']['src_username']; $sa->sact_desc = "{USER} merged source {SRC} with {$old_usr}"; $sa->sact_notes = null; //TODO: something from result? $sa->save(); }
/** * Create * * @param array $data */ protected function air_create($data) { $rec = new TranslationMap(); $this->require_data($data, array('xm_fact_id', 'xm_xlate_from', 'xm_xlate_to_fv_id')); $rec->xm_fact_id = $data['xm_fact_id']; $rec->xm_xlate_from = $data['xm_xlate_from']; $rec->xm_xlate_to_fv_id = $data['xm_xlate_to_fv_id']; $rec->xm_cre_dtim = air2_date(); // verify uniqueness $this->check_translation($rec); return $rec; }
/** * * * @param unknown $payload (optional) */ public function unsubscribe($payload = null) { $this->load->library('session'); // for flash data on POST redirect $method = $_SERVER['REQUEST_METHOD']; $action = current_url(); if ($method == 'GET') { // payload is (optional) base64-encoded JSON string with email and org $email = null; $org = null; if ($payload) { $buf = base64_decode($payload); if ($buf) { $json = json_decode($buf); if (isset($json->email)) { $email = $json->email; } if (isset($json->org)) { $org = $json->org; } } } $organization = null; if ($org) { $organization = Doctrine::getTable('Organization')->findOneBy('org_name', $org); } $stash = array('static_url' => $this->uri_for(''), 'action' => $action, 'method' => 'GET', 'email' => $email, 'org' => $organization); $this->load->view('email/unsubscribe', $stash); } else { $email = $this->input->post('email'); $org = $this->input->post('org'); // invalid params, re-render form with msg if (!$email) { $stash = array('static_url' => $this->uri_for(''), 'action' => $action, 'method' => 'GET', 'error' => 'Must supply an email address.'); $this->load->view('email/unsubscribe', $stash); return; } // find the source $src_email = Doctrine::getTable('SrcEmail')->findOneBy('sem_email', strtolower($email)); if (!$src_email) { // can't act. return 404 and do not reveal why to protect privacy of email $this->load->view('email/404'); return; } // determine our action. // if this org, and the org != APM, opt out from the org. // if this org == APM, or no org, or all orgs, unsubscribe the email address. $opt_out_from = null; if ($org && $org != 'all') { $organization = Doctrine::getTable('Organization')->findOneBy('org_name', $org); if ($organization) { if ($organization->org_id != Organization::$APMPIN_ORG_ID) { $opt_out_from = $organization; } } } $source = $src_email->Source; $should_save = false; $sact = new SrcActivity(); $sact->sact_dtim = air2_date(); $sact->sact_actm_id = 22; if ($opt_out_from) { // toggle the relevant src_org record foreach ($source->SrcOrg as $so) { if ($so->so_org_id != $opt_out_from->org_id) { continue; } $so->so_status = SrcOrg::$STATUS_OPTED_OUT; $should_save = true; $sact->sact_desc = 'Source unsubscribed via AIR from Org'; $sact->sact_ref_type = SrcActivity::$REF_TYPE_ORG; $sact->sact_xid = $so->so_org_id; } } else { // toggle the relevant src_email record $src_email->sem_status = SrcEmail::$STATUS_UNSUBSCRIBED; $src_email->save(); $should_save = true; $sact->sact_desc = 'Source unsubscribed via AIR'; } if (!$should_save) { // bad org name, most likely $this->load->view('email/404'); return; } $source->SrcActivity[] = $sact; $source->save(); // redirect to avoid double post $this->session->set_flashdata('unsubscribed', $email); redirect($this->uri_for('email/unsubscribe-confirm')); } }
/** * Handle bulk-update operations * * @param Bin $rec * @param array $data */ protected function air_update($rec, $data) { // unset bulk_op vars $this->bulk_op = null; $this->bulk_rs = null; // extract any notes for a bulk_add $addnotes = null; if (array_key_exists('bulk_add_notes', $data)) { $addnotes = $data['bulk_add_notes']; unset($data['bulk_add_notes']); if (strlen($addnotes) < 1 || strlen($addnotes) > 255) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid notes field for add'); } } // look for first BULK_OP $bulk_op = false; foreach ($this->BULK_OPS as $op) { if (isset($data[$op])) { $bulk_op = $op; break; } } // run op if ($bulk_op) { // add-notes only allowed on 'add' operations if ($addnotes && !preg_match('/^bulk_add/', $bulk_op)) { throw new Rframe_Exception(Rframe::BAD_DATA, "Key bulk_add_notes not allowed for operation {$bulk_op}"); } // sanity if (count($data) > 1) { throw new Rframe_Exception(Rframe::BAD_DATA, "Bulk operation " . "{$bulk_op} cannot run with any other updates!"); } $this->run_bulk($rec, $bulk_op, $data[$bulk_op], $addnotes); // touch timestamp, since bulk ops usually don't $rec->bin_upd_user = $this->user->user_id; $rec->bin_upd_dtim = air2_date(); } }
/** * Public utility to log a src_activity without using doctrine. * * @param int $usrid * @param array $srcids * @param string $dtim * @param string $desc * @param string $note */ public static function log_raw($usrid, $srcids, $dtim, $desc, $note) { // collect default values if (!$dtim) { $dtim = air2_date(); } if (!$desc) { $desc = ''; } if (!$note) { $note = ''; } // create generic mapping $mapping = array('src_activity' => array('sact_src_id' => array('map' => 0), 'sact_actm_id' => array('val' => 40), 'sact_dtim' => array('val' => $dtim), 'sact_desc' => array('val' => $desc), 'sact_notes' => array('val' => $note), 'sact_cre_user' => array('val' => $usrid), 'sact_upd_user' => array('val' => $usrid), 'sact_cre_dtim' => array('val' => $dtim), 'sact_upd_dtim' => array('val' => $dtim))); // import data (FAST if there are alot of rows) $rdr = new ArrayReader($srcids); $conn = AIR2_DBManager::get_master_connection(); if (count($srcids) < 10) { $wrt = new SqlWriter($conn, $mapping); $wrt->write_data($rdr); } else { $wrt = new MySqlImporter('/tmp', $mapping, $conn); $wrt->write_data($rdr); $wrt->exec_load_infile(); } // check for errors $errs = $wrt->get_errors(); if (count($errs) > 0) { $str = implode(', ', $errs); throw new Exception("Errors on activity logging: {$str}"); } }
/** * Run this job * * @return unknown */ public function run() { $cmd = $this->jq_job; if (!isset($cmd) || !strlen($cmd)) { throw new Exception("jq_job is empty for jq_id " . $this->jq_id); } if ($this->jq_start_dtim || $this->jq_pid) { throw new Exception('Job already run'); } // write our pid and hostname $this->jq_pid = getmypid(); $this->jq_host = php_uname('n'); $this->jq_start_dtim = air2_date(); $this->save(); // replace vars $php = PHP_BINDIR . '/php'; $perl = '/usr/bin/env perl'; $root = realpath(APPPATH . '../'); // simple interpolation $cmd = preg_replace('/PHP /', "{$php} ", $cmd); $cmd = preg_replace('/PERL /', "{$perl} ", $cmd); $cmd = preg_replace('/AIR2_ROOT/', $root, $cmd); // redirect STDERR to STDOUT (so it's captured correctly) $cmd .= " 2>&1"; // exec the cmd, saving the completion time exec($cmd, $output, $ret); $this->jq_complete_dtim = air2_date(); if ($ret != 0) { // truncate long output $output = implode("\n", $output); if (($len = strlen($output)) > 65535) { $output = substr($output, $len - 65535); } $this->jq_error_msg = $output; } // save and return success $this->save(); return $ret == 0; }
/** * Annotate sources in a bin (must have write-authz on the actual source) * * @param User $u * @param Bin $bin * @param array $note * @return array $counts */ public function annotate_sources($u, $bin, $note) { $stats = self::init_stats($stats = array('total', 'insert', 'duplicate', 'invalid')); // validate note $note = is_string($note) ? trim($note) : $note; if (!$note || !strlen($note)) { throw new Exception("Invalid annotation '{$note}'"); } // calculate total $conn = AIR2_DBManager::get_master_connection(); $q = "select count(*) from bin_source where bsrc_bin_id = ?"; $stats['total'] = $conn->fetchOne($q, array($bin->bin_id), 0); // fast-sql insert $read_org_ids = $u->get_authz_str(ACTION_ORG_SRC_UPDATE, 'soc_org_id'); $cache = "select soc_src_id from src_org_cache where {$read_org_ids}"; $where = "where bsrc_bin_id=? and bsrc_src_id in ({$cache})"; $select = "select bsrc_src_id,?,?,?,?,? from bin_source {$where}"; $flds = 'srcan_src_id,srcan_value,srcan_cre_user,srcan_upd_user,srcan_cre_dtim,srcan_upd_dtim'; $ins = "insert into src_annotation ({$flds}) {$select}"; $params = array($note, $u->user_id, $u->user_id, air2_date(), air2_date(), $bin->bin_id); $stats['insert'] = $conn->exec($ins, $params); // invalid == no write-authz on source $stats['invalid'] = $stats['total'] - $stats['insert'] - $stats['duplicate']; return $stats; }
/** * Add sources to a PINfluence * * @param Outcome $outcome * @param Bin $bin * @param string $type */ public static function add_sources_from_bin($outcome, $bin, $type) { $stats = array('total' => 0, 'insert' => 0, 'duplicate' => 0, 'invalid' => 0); $bin_id = $bin->bin_id; $b_where = "where bsrc_bin_id={$bin_id}"; //hardcode so i don't get mixed up // totals $conn = AIR2_DBManager::get_master_connection(); $stats['total'] = $conn->fetchOne("select count(*) from bin_source {$b_where}", array(), 0); // duplicates $b_s = "select bsrc_src_id from bin_source {$b_where}"; $b_q = "select count(*) from src_outcome where sout_out_id=? and sout_src_id in ({$b_s})"; $stats['duplicate'] += $conn->fetchOne($b_q, array($outcome->out_id), 0); // insert $user_id = $outcome->UpdUser->user_id; $s_where = "where src_id in ({$b_s})"; $s_s = "select ?, src_id, ?, ?, ?, ?, ? from source {$s_where}"; $s_q = "insert ignore into src_outcome (sout_out_id,sout_src_id, sout_type, sout_cre_user, sout_cre_dtim, sout_upd_user, sout_upd_dtim) {$s_s}"; $stats['insert'] += $conn->exec($s_q, array($outcome->out_id, $type, $user_id, air2_date(), $user_id, air2_date())); $stats['invalid'] += $stats['total'] - $stats['insert'] - $stats['duplicate']; return $stats; }
/** * Create or update a SrcOrg record for a Source. * * @param Source $src */ public function process_source(Source $src) { // run raw-sql for efficiency $conn = AIR2_DBManager::get_master_connection(); $src_id = $src->src_id; $org_id = $this->to_org_id; $unset_home_flags = false; // check for existing (and total) $where = "where so_src_id = {$src_id} and so_org_id = {$org_id}"; $status = "(select so_status from src_org {$where}) as status"; $ishome = "(select so_home_flag from src_org {$where}) as ishome"; $select = "select count(*) as total, {$status}, {$ishome}"; $q = "{$select} from src_org where so_src_id = {$src_id}"; $rs = $conn->fetchRow($q); // run operation $op = false; $data = array(); if (is_null($rs['status'])) { // insert $data = array('so_src_id' => $src_id, 'so_org_id' => $org_id, 'so_uuid' => air2_generate_uuid(), 'so_effective_date' => air2_date(), 'so_home_flag' => $this->to_so_home_flag ? 1 : 0, 'so_status' => $this->to_so_status, 'so_cre_user' => $this->Tank->tank_user_id, 'so_upd_user' => $this->Tank->tank_user_id, 'so_cre_dtim' => $this->Tank->tank_cre_dtim, 'so_upd_dtim' => $this->Tank->tank_upd_dtim); // determine home flag if ($rs['total'] == 0) { $data['so_home_flag'] = true; } elseif ($this->to_so_home_flag && $data['total'] > 0) { $unset_home_flags = true; } // insert $flds = implode(',', array_keys($data)); $vals = air2_sql_param_string($data); $q = "insert into src_org ({$flds}) values ({$vals})"; $conn->exec($q, array_values($data)); } else { // update $updates = array(); // change to status if ($rs['status'] != $this->to_so_status) { $updates[] = "so_status='" . $this->to_so_status . "'"; } // change to home flag (only allow setting, not unsetting) if ($this->to_so_home_flag && !$rs['ishome']) { $updates[] = "so_home_flag=1"; //MUST be true if ($rs['total'] > 1) { $unset_home_flags = true; } } // do we need to do anything? if (count($updates)) { $set = implode(', ', $updates); $where = "so_src_id={$src_id} and so_org_id={$org_id}"; $q = "update src_org set {$set} where {$where}"; $conn->exec($q); } } // optionally unset other home flags if ($unset_home_flags) { $set = 'so_home_flag=0'; $where = "so_src_id={$src_id} and so_org_id!={$org_id}"; $conn->exec("update src_org set {$set} where {$where}"); } }
/** * Optionally update the user/time stamps on the parent record * * @param Doctrine_Record $rec */ protected function update_parent(Doctrine_Record $rec) { if ($this->update_parent_stamps && $this->parent_rec) { $user = $this->user->user_id; $dtim = air2_date(); $parentd = $this->parent_rec->toArray(); foreach ($parentd as $col => $val) { if (preg_match('/_upd_user$/', $col)) { $this->parent_rec->{$col} = $user; } if (preg_match('/_upd_dtim$/', $col)) { $this->parent_rec->{$col} = $dtim; } } $this->parent_rec->save(); } }
/** * Get response sets from row object * * @param array $obj row object * @param int $idx row index * @param array $fields field mapping def * @return array data */ protected function get_response_sets($obj, $idx, $fields) { if (!$this->tank_me_inq_id) { return false; } $date = $this->tank_me_validator->extract('date', $obj); $date = air2_date(strtotime($date)); return array("TankResponseSet_{$idx}" => array("TankSource" => "TankSource_{$idx}", "srs_inq_id" => $this->tank_me_inq_id, "srs_type" => SrcResponseSet::$TYPE_MANUAL_ENTRY, "srs_date" => $date)); }
/** * Create JobQueue for send-watcher-email. * * @param TankSource $tsrc */ private function _queue_notification($tsrc) { $tank = $tsrc->Tank; // querymaker imports only if ($tank->tank_type != Tank::$TYPE_QM) { return; } $job = new JobQueue(); $job->jq_job = sprintf("PERL AIR2_ROOT/bin/send-watcher-email --inq_uuid %s --complete 1 --srs_uuid %s", $tank->tank_xuuid, $tsrc->TankResponseSet[0]->srs_uuid); $job->jq_start_after_dtim = air2_date(time() + 5 * 60); // let search index update $this->air_save($job); }
/** * Magic path to mark submissions as unfavorite * * @param string @srs_uuid * @param unknown $srs_uuid */ public function unfavorite($srs_uuid) { $conn = AIR2_DBManager::get_master_connection(); $srsid = $conn->fetchOne('select srs_id from src_response_set where srs_uuid = ?', array($srs_uuid), 0); if (!$srsid) { return; } $now = air2_date(); $flds = "usrs_user_id, usrs_srs_id, usrs_favorite_flag, usrs_cre_dtim, usrs_upd_dtim"; $ondup = "on duplicate key update usrs_favorite_flag=0,usrs_upd_dtim='{$now}'"; $ins = "insert into user_srs ({$flds}) values (?,{$srsid},0,'{$now}','{$now}') {$ondup}"; $n = $conn->exec($ins, array($this->user->user_id)); air2_touch_stale_record('src_response_set', $srsid); }
/** * Returns AIR2_Query object for published Inquiries. * * @param string $class (optional) * @return AIR2_Query $q */ public static function get_base_query_for_published($class = 'Inquiry') { $now = air2_date(); $q = AIR2_Query::create()->from("{$class} i")->whereIn("i.inq_type", array(self::$TYPE_FORMBUILDER, self::$TYPE_QUERYBUILDER, self::$TYPE_TEST, self::$TYPE_NONJOURN))->andWhereIn('i.inq_status', Inquiry::published_status_flags())->andWhere("(i.inq_publish_dtim is null OR i.inq_publish_dtim <= '{$now}')")->andWhere("(i.inq_expire_dtim is null OR i.inq_expire_dtim > '{$now}')")->andWhere("(i.inq_deadline_dtim is null OR i.inq_deadline_dtim > '{$now}')"); return $q; }
/** * Update out_org_id * * @param Doctrine_Record $rec * @param array $data */ protected function air_update($rec, $data) { // check perms if (!$rec->user_may_write($this->user)) { throw new Rframe_Exception(Rframe::BAD_DATA, "You do not have permission to update this PINfluence."); return; } // unset bulk_op vars $this->bulk_op = null; $this->bulk_rs = null; if (isset($data['org_uuid']) && $data['org_uuid']) { $o = AIR2_Record::find('Organization', $data['org_uuid']); if (!$o) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid org_uuid'); } $rec->out_org_id = $o->org_id; $rec->Organization = $o; } $bulk_op = ''; foreach ($this->BULK_OPS as $op) { if (isset($data[$op])) { $bulk_op = $op; break; } } if ($bulk_op) { // sanity if (count($data) > 1) { throw new Rframe_Exception(Rframe::BAD_DATA, "Bulk operation " . "{$bulk_op} cannot run with any other updates!"); } $this->run_bulk($rec, $bulk_op, $data[$bulk_op]); // touch timestamp, since bulk ops usually don't $rec->out_upd_user = $this->user->user_id; $rec->out_upd_dtim = air2_date(); } }
/** * Update - (handle image creation/deletion) * * @param Email $eml * @param array $data */ protected function air_update($eml, $data) { if (array_key_exists('logo', $data)) { if ($data['logo']) { try { if (!$eml->Logo) { $eml->Logo = new ImageEmailLogo(); } $eml->Logo->set_image($data['logo']); } catch (Exception $e) { throw new Rframe_Exception(RFrame::BAD_DATA, $e->getMessage()); } } else { if ($eml->Logo) { $eml->Logo->delete(); $eml->clearRelated('Logo'); } } } // organization change if (isset($data['org_uuid'])) { $org = AIR2_Record::find('Organization', $data['org_uuid']); if (!$org) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid Organization specified!'); } $eml->Organization = $org; } // signature setting/creation if (isset($data['usig_uuid'])) { $usig = AIR2_Record::find('UserSignature', $data['usig_uuid']); if (!$usig) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid Signature specified!'); } $usig->usig_upd_dtim = air2_date(); //touch $eml->UserSignature = $usig; } elseif (isset($data['usig_text'])) { $usig = new UserSignature(); $usig->usig_user_id = $this->user->user_id; $usig->usig_text = $data['usig_text']; $eml->UserSignature = $usig; } }
/** * * * @return unknown * @param unknown $iorg */ protected function air_delete($iorg) { $org = $iorg->Organization; // log activity $activity = new InquiryActivity(); $activity->ia_inq_id = $this->parent_rec->inq_id; $activity->ia_actm_id = 49; $activity->ia_dtim = air2_date(); $activity->ia_desc = sprintf('org %s removed by {USER}', $org->org_name); $activity->save(); }
/** * Tag an object using raw connections. Returns true if the tag was added, * or false if the tag already existed. * * @param int $xid * @param string $type * @param string $tag * @return boolean */ public static function make_tag($xid, $type, $tag) { // sanity! if (!is_numeric($xid) || $xid < 1) { throw new Exception("Bad tag XID({$xid})"); } if (!in_array($type, array('I', 'P', 'S', 'R'))) { throw new Exception("Bad tag TYPE({$type})"); } if (!is_string($tag) || strlen($tag) < 1) { throw new Exception("Bad tag '{$tag}'"); } // fetch/create tag master $tm_id = TagMaster::get_tm_id($tag); // params $usrid = defined('AIR2_REMOTE_USER_ID') ? AIR2_REMOTE_USER_ID : 1; $dtim = air2_date(); $cols = array('tag_tm_id', 'tag_xid', 'tag_ref_type', 'tag_cre_user', 'tag_upd_user', 'tag_cre_dtim', 'tag_upd_dtim'); $vals = array($tm_id, $xid, $type, $usrid, $usrid, $dtim, $dtim); // insert ignore $conn = AIR2_DBManager::get_master_connection(); $colstr = implode(',', $cols); $params = air2_sql_param_string($cols); $n = $conn->exec("insert ignore into tag ({$colstr}) values ({$params})", $vals); // if tag existed, update userstamp $tag_was_new = true; if ($n == 0) { $tag_was_new = false; $set = "tag_upd_user={$usrid}, tag_upd_dtim='{$dtim}'"; $where = "tag_tm_id={$tm_id} and tag_xid={$xid} and tag_ref_type='{$type}'"; $conn->exec("update tag set {$set} where {$where}"); } return $tag_was_new; }
/** * Indicate to the search server that the record for $pk in table $table * needs to be re-indexed. * * @param string $table * @param string $pk * @return unknown */ function air2_touch_stale_record($table, $pk) { if (!is_numeric($pk)) { throw new Exception("pk must be a numeric primary key"); } $stale_types = array('source' => StaleRecord::$TYPE_SOURCE, 'src_response_set' => StaleRecord::$TYPE_RESPONSE, 'public_response' => StaleRecord::$TYPE_PUBLIC_RESPONSE, 'inquiry' => StaleRecord::$TYPE_INQUIRY, 'project' => StaleRecord::$TYPE_PROJECT); if (!array_key_exists($table, $stale_types)) { throw new Exception("Undefined table for stale records: {$table}"); } $stale_record = new StaleRecord(); $stale_record->str_xid = $pk; $stale_record->str_type = $stale_types[$table]; $stale_record->str_upd_dtim = air2_date(); return $stale_record->replace(); }
/** * Custom setter for the image. * * @param array|string $image */ public function set_image($image) { if (is_array($image)) { $name = $image['name']; $path = $image['tmp_name']; } elseif (is_string($image) && is_readable($image)) { $name = basename($image); $path = $image; } else { throw new Exception("Invalid image"); } // validate image if (!is_readable($path)) { throw new Exception("Invalid image path: {$path}"); } $img_info = getimagesize($path); if (!$img_info) { throw new Exception("Invalid image file: {$name}"); } // check/create image directory if (!$this->img_uuid) { $this->img_uuid = air2_generate_uuid(); } $dir = self::get_directory($this->img_ref_type, $this->img_uuid); air2_mkdir($dir); if (!is_writable($dir)) { throw new Exception("Cannot write to: {$dir}"); } // looks okay... raw-set the info $this->_set('img_file_name', air2_fileify($name)); $this->_set('img_file_size', filesize($path)); $this->_set('img_content_type', $img_info['mime']); $this->_set('img_dtim', air2_date()); $this->_set_image = $path; }
/** * Convenience method for adding a SrcOrg record to a new Source. * * @param Source $source * @param string $org_uuid * @return SrcOrg $src_org */ public static function for_new_source($source, $org_uuid) { $org = AIR2_Record::find('Organization', $org_uuid); if (!$org) { throw new Exception("No such Organization for uuid {$org_uuid}"); } $so = new SrcOrg(); $so->so_home_flag = true; $so->so_org_id = $org->org_id; $so->so_effective_date = air2_date(); return $so; }
* @package default */ AIR2_DBManager::init(); echo "Enter the username of an AIR2 User:\n > "; $username = trim(fgets(STDIN)); if (strlen($username) < 1) { echo "Error! No username specified!\n"; exit(0); } $user = Doctrine::getTable('User')->findOneBy('user_username', $username); if (!$user) { $user = new User(); $user->user_username = $username; $user->user_first_name = '[First]'; $user->user_last_name = '[Last]'; $user->user_cre_dtim = air2_date(); $user->user_cre_user = 1; // system user $user->user_uuid = air2_generate_uuid(); $user->user_type = 'A'; // system type $user->user_status = 'A'; // active echo "AIR2 User '{$username}' not found!\n"; echo "Enter new password to create User. (Blank to cancel)\n > "; } else { echo "Enter new password:\n > "; } $userpass = trim(fgets(STDIN)); $pinpass = new PINPassword(array('username' => $username, 'phrase' => $userpass)); if (!$pinpass->validate()) {