public function load()
 {
     parent::load();
     $model = new SupportCenters();
     $scs = $model->getindex();
     $this->view->scs = array();
     foreach ($this->sc_ids as $sc_id) {
         $this->view->scs[$sc_id] = $scs[$sc_id][0];
     }
     if (isset($_REQUEST["summary_attrs_showcontact"])) {
         $this->view->contacts = array();
         $cmodel = new SupportCenterContact();
         $contacts = $cmodel->getindex();
         //group by contact_type_id
         foreach ($this->sc_ids as $sc_id) {
             $types = array();
             if (isset($contacts[$sc_id])) {
                 foreach ($contacts[$sc_id] as $contact) {
                     if (!isset($types[$contact->contact_type])) {
                         $types[$contact->contact_type] = array();
                     }
                     $types[$contact->contact_type][] = $contact;
                 }
                 $this->view->contacts[$sc_id] = $types;
             }
         }
     }
     if (isset($_REQUEST["summary_attrs_showsites"])) {
         $model = new Site();
         $this->view->sites = $model->getgroupby("sc_id");
     }
 }
 public function dosearch($type, $max, $q, $basic)
 {
     //search in oim
     $model = new OIMSearch();
     $recs = array();
     if ($type == "all" || $type == "resource") {
         foreach ($model->search_resource($q) as $rec) {
             $rec->type = "resource";
             if (!$basic) {
                 //pull resource for each resource (and group by contact type)
                 $rcmodel = new ResourceContact();
                 $contacts = $rcmodel->get(array("resource_id" => $rec->id));
                 $rec->contacts = array();
                 foreach ($contacts as $contact) {
                     if (!isset($rec->contacts[$contact->contact_type])) {
                         $rec->contacts[$contact->contact_type] = array();
                     }
                     $rec->contacts[$contact->contact_type][] = $contact;
                 }
             }
             $recs[] = $rec;
         }
     }
     if (count($recs) > $max) {
         return $recs;
     }
     if ($type == "all" || $type == "resource_group") {
         foreach ($model->search_resourcegroup($q) as $rec) {
             $rec->type = "resource_group";
             $recs[] = $rec;
         }
     }
     if (count($recs) > $max) {
         return $recs;
     }
     if ($type == "all" || $type == "site") {
         foreach ($model->search_site($q) as $rec) {
             $rec->type = "site";
             $recs[] = $rec;
         }
     }
     if (count($recs) > $max) {
         return $recs;
     }
     if ($type == "all" || $type == "facility") {
         foreach ($model->search_facility($q) as $rec) {
             $rec->type = "facility";
             $recs[] = $rec;
         }
     }
     if (count($recs) > $max) {
         return $recs;
     }
     if ($type == "all" || $type == "vo") {
         foreach ($model->search_vo($q) as $rec) {
             $rec->type = "vo";
             if (!$basic) {
                 $vomodel = new VOContact();
                 $contacts = $vomodel->get(array("vo_id" => $rec->id));
                 $rec->contacts = array();
                 foreach ($contacts as $contact) {
                     if (!isset($rec->contacts[$contact->contact_type])) {
                         $rec->contacts[$contact->contact_type] = array();
                     }
                     $rec->contacts[$contact->contact_type][] = $contact;
                 }
             }
             $recs[] = $rec;
         }
     }
     if (count($recs) > $max) {
         return $recs;
     }
     if ($type == "all" || $type == "sc") {
         foreach ($model->search_sc($q) as $rec) {
             $rec->type = "sc";
             if (!$basic) {
                 $scmodel = new SupportCenterContact();
                 $contacts = $scmodel->get(array("sc_id" => $rec->id));
                 $rec->contacts = array();
                 foreach ($contacts as $contact) {
                     if (!isset($rec->contacts[$contact->contact_type])) {
                         $rec->contacts[$contact->contact_type] = array();
                     }
                     $rec->contacts[$contact->contact_type][] = $contact;
                 }
             }
             $recs[] = $rec;
         }
     }
     if (count($recs) > $max) {
         return $recs;
     }
     if ($type == "all" || $type == "project") {
         foreach ($model->search_project($q) as $rec) {
             $rec->type = "project";
             $recs[] = $rec;
         }
     }
     if (count($recs) > $max) {
         return $recs;
     }
     //contact information is only for non-guest
     if (!user()->isGuest()) {
         if ($type == "all" || $type == "contact") {
             foreach ($model->search_contact($q) as $rec) {
                 $rec->type = "contact";
                 $recs[] = $rec;
             }
         }
     }
     //search goc ticket
     if (!$basic) {
         if ($type == "all" || $type == "gocticket") {
             $xml = new SimpleXMLElement(file_get_contents(config()->gocticket_url . "/rest/search?q=" . urlencode($q)));
             $sorted = array();
             foreach ($xml->Tickets->Ticket as $ticket) {
                 $ticket->type = "gocticket";
                 $ticket_id = (int) $ticket->ID;
                 $sorted[$ticket_id] = $ticket;
             }
             krsort($sorted);
             foreach ($sorted as $ticket) {
                 $recs[] = $ticket;
             }
         }
     }
     return $recs;
 }