/**
  * handles the adding of a channel to a layout
  *
  * @param $channel \b id of channel to add
  * @param $target \b id of tab to add channel to
  */
 public function add($channel, $target = null)
 {
     $default_layout = false;
     ignore_user_abort();
     if ($_SESSION['generic_user_type'] == 'portalord') {
         $default_layout = true;
     }
     MyPortal::force_clone($this->portal);
     $channel_id = str_replace('channel-', '', $channel);
     $target = str_replace('tab-', '', $target);
     //
     // if portal was just cloned, channel ids must be updated.
     // they referred to the default layout in the ui, but we will actually update
     // the custom user layout.
     //
     // @todo account for admins updating the default layout (GET param?)
     //
     //if we just cloned the layout, set the target as the child tab
     if ($this->portal->cloned) {
         $target = MyUserTab::get_child_id($this->portal->person, $target);
     }
     if (!$this->portal->tabs($target)) {
         $default_portal = new MyPortal(0);
         $default_tab_slug = $default_portal->tabs($target)->slug;
         $target = $this->portal->tabs($default_tab_slug)->id;
         $default_channel = $default_portal->tabs($default_tab_slug)->channels($channel_id);
         $sql = "SELECT id FROM userchannels WHERE channel_id = ? AND usertab_id = ? AND col_num = ? AND sort_order = ?";
         $channel_id = PSU::db('portal')->GetOne($sql, array($channel_id, $this->portal->tabs($default_tab_slug)->id, $default_channel->col_num, $default_channel->sort_order));
     }
     //end if
     //if we're spoofing the portalord role, edit the default layout rather than the cloned one
     if ($default_layout) {
         if (!$default_portal) {
             $default_portal = new MyPortal(0);
         }
         $target = $default_portal->tabs($target)->base->id;
     }
     $sql = "SELECT MAX(sort_order) FROM userchannels WHERE usertab_id = ? AND col_num = 2";
     $sort_order = psu::db('portal')->GetOne($sql, $target);
     $channel = new MyUserChannel(array('channel_id' => $channel_id));
     $channel->col_num = 2;
     $channel->sort_order = $sort_order + 1;
     $channel->usertab_id = $target ? $target : 1;
     $channel->save();
     echo $this->portal->is_default_layout() ? 'default' : 'user';
 }
 /**
  * executes student query and returns a result set for looping
  */
 public static function query($args = array(), $return_results = true, $debug = false)
 {
     if (!is_array($args)) {
         $args = array('term_code' => $args);
     }
     //end if
     $valid_args = array('term_code', 'last_name', 'first_name', 'gender', 'veteran', 'advisor_first_name', 'advisor_last_name', 'continuing_ed', 'class1', 'class2', 'class3', 'class4', 'confirmed_status', 'pt_ft', 'age_low', 'age_high', 'gpa_low', 'gpa_high', 'credit_low', 'credit_high', 'state_code', 'degree', 'department', 'major', 'option', 'minor', 'degs', 'sport', 'teacher_cert', 'c_age', 'c_commute', 'c_sex', 'c_dean', 'c_styp', 'c_advr', 'c_conf', 'c_ma', 'c_pt_cred', 'c_t_cred', 'c_birth', 'c_cred', 'c_majr', 'c_pt_gpa', 'c_t_gpa', 'c_ca', 'c_gpa', 'c_min', 'c_sport', 'c_vet', 'c_ca_ph', 'c_degr', 'c_opt', 'c_sport_comments', 'c_webreg', 'c_citz', 'c_dept', 'c_pa', 'c_sport_eligibility', 'c_class', 'c_email', 'c_load', 'c_stat', 'c_degs', 'c_cat');
     $validated_args = array();
     foreach ($args as $key => $value) {
         if (in_array($key, $valid_args)) {
             $validated_args['ps_' . $key] = $value;
         }
         //end if
     }
     //end foreach
     if (!$validated_args['ps_term_code']) {
         $validated_args['ps_term_code'] = self::getCurrentTerm('UG');
     }
     //end if
     $sql = "BEGIN pkg_student_utility.p_query(pb_load_address => TRUE";
     foreach ($validated_args as $key => $value) {
         $sql .= ", " . $key . " => :" . $key;
     }
     //end foreach
     $sql .= "); END;";
     $stmt = \PSU::db('banner')->PrepareSP($sql);
     foreach ($validated_args as $key => $value) {
         \PSU::db('banner')->InParameter($stmt, $value, $key);
     }
     //end foreach
     \PSU::db('banner')->Execute($stmt);
     if ($debug) {
         psu::dbug(psu::db('banner')->GetOne("SELECT pkg_student_utility.f_get_unexclude() FROM dual"));
     }
     //end if
     $sql = "SELECT * FROM gt_student_query WHERE exclude IS NULL";
     if ($return_results) {
         return \PSU::db('banner')->Execute($sql);
     } else {
         return $sql;
     }
     //end if
 }
 /**
  * loads former last names
  */
 protected function _load_former_last_names()
 {
     $sql = "SELECT DISTINCT spriden_last_name FROM spriden WHERE spriden_pidm = :pidm AND spriden_last_name <> :last_name";
     $this->person->former_last_names = psu::db('banner')->GetCol($sql, array('pidm' => $this->person->pidm, 'last_name' => $this->person->last_name));
 }
 protected function _get_calls($type = 'open', $page = 1, $start = 0)
 {
     $sql = "SELECT c.call_id,\n\t\t\t\t\t\t\t\t\t h.id history_id,\n\t\t\t\t\t\t\t\t\t h.call_status status,\n\t\t\t\t\t\t\t\t\t h.tlc_assigned_to,\n\t\t\t\t\t\t\t\t\t h.updated_by,\n\t\t\t\t\t\t\t\t\t h.comments,\n\t\t\t\t\t\t\t\t\t CONCAT(c.call_date, ' ', c.call_time) call_date,\n\t\t\t\t\t\t\t\t\t CONCAT(h.date_assigned, ' ', h.time_assigned) update_date,\n\t\t\t\t\t\t\t\t\t h2.updated_by original_submitter,\n\t\t\t\t\t\t\t\t\t h2.tlc_assigned_to first_assigned_to,\n\t\t\t\t\t\t\t\t\t h2.comments original_comment\n\t\t\t\t\t\t\tFROM call_log c\n\t\t\t\t\t\t\t\t\t INNER JOIN call_history h\n\t\t\t\t\t\t\t\t\t\tON h.call_id = c.call_id\n\t\t\t\t\t\t\t\t\t\tAND h.current = 1\n\t\t\t\t\t\t\t\t\t\tAND h.call_status = ?\n\t\t\t\t\t\t\t\t\t INNER JOIN call_history h2\n\t\t\t\t\t\t\t\t\t\tON h2.call_id = c.call_id\n\t\t\t\t\t\t WHERE (c.caller_username = ? OR c.wp_id = ?)\n\t\t\t\t\t\t\t AND h2.id = (\n\t\t\t\t\t\t\t\t\t\tSELECT min(h3.id)\n\t\t\t\t\t\t\t\t\t\t\tFROM call_history h3\n\t\t\t\t\t\t\t\t\t\t WHERE h3.call_id = h2.call_id\n\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t ORDER BY h.date_assigned DESC,\n\t\t\t\t\t\t \t\t\t h.time_assigned DESC\n\t\t\t\t\t\t\t\t\t {$limit}";
     $args = array('status' => $type, 'username' => $this->myuser->username, 'wp_id' => $this->myuser->wp_id);
     $results = psu::db('calllog')->PageExecute($sql, 10, $page, $args);
     $data = array();
     foreach ($results as $row) {
         $data[] = $row;
     }
     //end foreach
     return psu::paginationResults(psu::paginationInfo($_GET, $results), $data);
 }
 /**
  * generatePopulations
  *
  * creates populations that the account process references for accounts
  *   during execution
  *
  * @since		version 1.0.0
  * @return		boolean
  */
 function generatePopulations()
 {
     echo $this->line . ":: Retrieving Employees and Non Employees from Banner" . $this->line;
     //grab employees
     $sql = "SELECT distinct pidm\n\t\t          FROM psu_identity.person_attribute\n\t\t         WHERE attribute in('staff', 'faculty', 'lecturer')\n\t\t           AND type_id = 2\n\t\t           AND not exists(SELECT 1 FROM spbpers WHERE spbpers_pidm = pidm AND spbpers_dead_ind = 'Y')";
     $this->emps = $this->idm->db->GetAll($sql);
     //grab non employees
     $this->non_emps = $this->idm->db->GetAll("SELECT * FROM v_psu_friend");
     $this->emeritus = psu::db('banner')->GetAll("SELECT distinct pidm FROM v_alumni_emeritus UNION SELECT distinct pidm FROM v_alumni_campus");
     //check counts
     if ($this->verifyCounts()) {
         //all good...continue
         return true;
     } else {
         //oh noes!  death to us
         return false;
     }
     //end else
 }