Exemplo n.º 1
0
 public static function getTrainerForBadge($leader, $pokemon_string)
 {
     $trainer = new Trainer();
     $trainer->setName($leader);
     $trainer->setPokemon($trainer->getPokemonForTrainer($pokemon_string, ['id', 'pokemon', 'level'], true));
     return $trainer;
 }
Exemplo n.º 2
0
 public function getTrainers()
 {
     $result = Database::query(SQL::ownersOfPokemon($this->id));
     $trainers = array();
     if (mysqli_num_rows($result) > 0) {
         foreach ($result as $row) {
             $trainer = new Trainer($row);
             array_push($trainers, $trainer->serialize());
         }
     }
     return $trainers;
 }
Exemplo n.º 3
0
 public static function getTrainerForBadge($leader, $pokemon_string)
 {
     $trainer = new Trainer();
     $trainer->setName($leader);
     foreach (explode(',', $pokemon_string) as $pokemon) {
         $ex = explode(':', $pokemon);
         $newPokemon = new Pokemon();
         $newPokemon->name = $ex[0];
         $newPokemon->level = $ex[1];
         $returnPokemon[] = $newPokemon;
     }
     $trainer->pokemon = $returnPokemon;
     return $trainer;
 }
Exemplo n.º 4
0
 public static function getImportantTrainers($where = null, $limit = null, $order = ' i.`order_by`, i.`id` ')
 {
     if (!is_null($where)) {
         $where = 'WHERE ' . $where;
     }
     $getImportantTrainers = TPP::db()->query("SELECT\n\t\t\ti.`id`,\n\t\t\ti.`name`,\n\t\t\ti.`nickname`,\n\t\t\ti.`type`,\n\t\t\ti.`attempts`,\n\t\t\ti.`wins`,\n\t\t\ti.`losses`,\n\t\t\ti.`time`,\n\t\t\ti.`is_rematch`,\n\t\t\ti.`order_by`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\titp.`id`,\n\t\t\t\t\titp.`pokemon`,\n\t\t\t\t\titp.`level`,\n\t\t\t\t\titp.`nickname`,\n\t\t\t\t\tIFNULL(itp.`item`, 1)\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `pokemon`,\n\t\t\tGROUP_CONCAT(\n\t\t\t\tDISTINCT CONCAT_WS('" . self::SEPARATOR_2 . "',\n\t\t\t\t\titpm.important_trainer_pokemon_id,\n\t\t\t\t\titpm.name\n\t\t\t\t) SEPARATOR '" . self::SEPARATOR_1 . "'\n\t\t\t) as `moves`\n\t\t\tFROM `important_trainer` i\n\t\t\tJOIN `important_trainer_pokemon` itp\n\t\t\t\tON itp.`important_trainer_id` = i.`id`\n\t\t  \tLEFT JOIN `important_trainer_pokemon_move` itpm\n\t\t  \t\tON itpm.`important_trainer_pokemon_id` = itp.`id`\n\t\t\t" . $where . "\n\t\t\tGROUP BY i.`id`\n\t\t\tORDER BY " . $order . $limit);
     if (!$getImportantTrainers) {
         return [];
     }
     $return = [];
     while ($importantTrainer = $getImportantTrainers->fetch()) {
         $newIT = new self();
         $newIT->setAttributes(['id' => (int) $importantTrainer['id'], 'name' => $importantTrainer['name'], 'nickname' => $importantTrainer['nickname'], 'type' => $importantTrainer['type'], 'attempts' => (int) $importantTrainer['attempts'], 'wins' => (int) $importantTrainer['wins'], 'losses' => (int) $importantTrainer['losses'], 'time' => $importantTrainer['time'], 'order_by' => (int) $importantTrainer['order_by'], 'is_rematch' => (bool) $importantTrainer['is_rematch'], 'pokemon' => parent::getPokemonForTrainer($importantTrainer['pokemon'], ['id', 'pokemon', 'level', 'nickname', 'item'])]);
         $moves = [];
         foreach (explode(self::SEPARATOR_1, $importantTrainer['moves']) as $move) {
             $ex = explode(self::SEPARATOR_2, $move);
             $moves[$ex[0]][] = $ex[1];
         }
         foreach ($newIT->pokemon as $p) {
             if (isset($moves[$p->id])) {
                 $p->moves = $p->setMoves($moves[$p->id]);
             }
         }
         $return[] = $newIT;
     }
     return ['importanttrainers' => $return];
 }
Exemplo n.º 5
0
 /**
  * The default action - show the home page
  */
 public function indexAction()
 {
     // TODO Auto-generated mapController::indexAction() default action
     $where = array('city !=' => '', 'postCode !=' => '', 'lon !=' => '', 'lat !=' => '', 'phone !=' => '');
     $postcodeList = Trainer::getAllPostcode();
     $trainer = array();
     for ($i = 0; $i < count($postcodeList); $i++) {
         $trainerList[$i] = Trainer::getGMapData($postcodeList[$i]);
         if (is_array($trainerList[$i])) {
             $trainer = array_merge($trainerList[$i], $trainer);
         }
     }
     for ($j = 0; $j < count($trainer); $j++) {
         $dataJson[$j]['name'] = $trainer[$j]['city'];
         $dataJson[$j]['postcode'] = $trainer[$j]['postcode'];
         $dataJson[$j]['total'] = $trainer[$j]['total'];
         $dataJson[$j]['lon'] = $trainer[$j]['lon'];
         $dataJson[$j]['lat'] = $trainer[$j]['lat'];
         //    		$dataJson[$i][$j]['city'] =  $trainerList[$j]['city'];
         //    		$dataJson[$i][$j]['type'] =  $trainerList[$j]['type'];
         //    		$dataJson[$i][$j]['phone'] =  $trainerList[$j]['phone'];
         $dataCity = array('city' => $dataJson);
     }
     $dataCities = array('cities' => $dataCity);
     $data = array('data' => $dataCities);
     $dataJson = json_encode($data);
     $this->view->data = $dataJson;
 }
Exemplo n.º 6
0
 public function indexAction()
 {
     $this->view->Title = "Racehorse Trainers";
     $this->view->headTitle($this->view->Title);
     $condition = array();
     $page = $this->getRequest()->getParam('page');
     list($this->view->Pager, $this->view->trainers) = Trainer::getAll($condition, $page, 50, $order = 'lastName,firstName');
 }
Exemplo n.º 7
0
 /**
  * Delete a Country
  */
 public function deleteAction()
 {
     $trainers = Trainer::getById($this->getRequest()->getParam('id'));
     if ($trainers) {
         if ($this->getRequest()->isPost()) {
             $trainers->delete();
             $this->Member->log('Delete: ' . $trainers->first_name . ' ' . $trainers->last_name . '(' . $this->getRequest()->getParam('id') . ')', 'Trainers');
             My_Plugin_Libs::setSplash('Posts: <b>' . $trainers->first_name . ' ' . $trainers->last_name . '</b> have been delete.');
             $this->_redirect($this->_helper->url('index', 'trainers', 'admin'));
         }
         $this->view->trainers = $trainers;
     }
 }
Exemplo n.º 8
0
function import()
{
    try {
        $page = isset($_GET['page']) ? $_GET['page'] : null;
        if ($page == 0) {
            del_feature();
        }
        $results = get_writing($page);
        $size = sizeof($results);
        foreach ($results as $r) {
            $f = new Feature();
            $w = json_decode($r->writing);
            $char_id = $r->char_id;
            $features = $f->make_feature($w);
            //获取特征
            $dic = new Dictionary();
            $dict_feature = $dic->get_feature($char_id);
            //获取数据库中已存的特征值
            $dict_feature = isset($dict_feature) ? json_decode($dict_feature) : null;
            $t = new Trainer();
            $t->train($features, $dict_feature);
            $c = new Character();
            $first_stroke_type = $c->get_first_stroke_type($w);
            //首笔的笔画类型(横竖撇点折)
            $int_strokes = sizeof($w->s);
            //笔画数
            $dic->update_character($char_id, json_encode($t->train_features), $int_strokes, $first_stroke_type);
        }
        if ($size > 0) {
            echo "<meta HTTP-EQUIV=REFRESH CONTENT='5;URL=import.php?page=" . ($page + 1) . "'>";
        } else {
            echo "导入完成";
        }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
Exemplo n.º 9
0
 public function indexAction()
 {
     $error = array();
     if ($this->getRequest()->isPost()) {
         $request = $this->getRequest()->getParams();
         $error = $this->_checkForm($request);
         if (count($error) == 0) {
             if ($request['textSearch']) {
                 $condition = array();
                 $condition['firstName LIKE ?'] = "%{$request['textSearch']}%";
                 $condition['lastName LIKE ?'] = "%{$request['textSearch']}%";
                 $condition['city LIKE ?'] = "%{$request['textSearch']}%";
                 $session_condition = array();
                 $session_condition['textSearch'] = $request['textSearch'];
                 $_SESSION['Condition'] = $session_condition;
                 $page = $this->getRequest()->getParam('page');
                 list($this->view->Pager, $this->view->Trainer) = Trainer::getAllBySearch($condition, $page, 50, $order = 'lastName,firstName');
                 $this->view->Title = "Search Trainers by keyword: <span style='color:#0073EA'>" . $request['textSearch'] . "</span>";
                 $this->view->headTitle($this->view->Title);
             }
         } else {
             $this->view->error = $error;
         }
     } else {
         if ($_SESSION['Condition'] != "") {
             $condition = array();
             $condition['firstName LIKE ?'] = "%{$_SESSION['Condition']['textSearch']}%";
             $condition['lastName LIKE ?'] = "%{$_SESSION['Condition']['textSearch']}%";
             $condition['city LIKE ?'] = "%{$_SESSION['Condition']['textSearch']}%";
             $page = $this->getRequest()->getParam('page');
             list($this->view->Pager, $this->view->Trainer) = Trainer::getAllBySearch($condition, $page, 50, $order = 'firstName, lastName');
             $this->view->Title = "Search Trainers by keyword: <span style='color:#0073EA'>" . $_SESSION['Condition']['textSearch'] . "</span>";
             $this->view->headTitle($this->view->Title);
         } else {
             $error[] = "Not found data. Please enter a keyword to search!";
             $this->view->error = $error;
         }
     }
 }
Exemplo n.º 10
0
 public function indexAction()
 {
     $stateId = $this->getRequest()->getParam('id');
     $condition = array('stateNo =?' => $stateId);
     $page = $this->getRequest()->getParam('page');
     $request = $this->getRequest()->getParams();
     $this->view->nameplain = $request['name_plain'];
     list($this->view->Pager, $this->view->trainers) = Trainer::getAll($condition, $page, 50, $order = 'lastName,firstName');
     /** Get state name **/
     $state = State::getById($stateId);
     switch ($state->name) {
         case "NSW":
             $this->view->Title = "Racehorse Trainers in New South Wales";
             break;
         case "VIC":
             $this->view->Title = "Racehorse Trainers in Victoria";
             break;
         case "QLD":
             $this->view->Title = "Racehorse Trainers in Queensland";
             break;
         case "TAS":
             $this->view->Title = "Racehorse Trainers in Tasmania";
             break;
         case "SA":
             $this->view->Title = "Racehorse Trainers in South Australia";
             break;
         case "WA":
             $this->view->Title = "Racehorse Trainers in Western Australia";
             break;
         case "NT":
             $this->view->Title = "Racehorse Trainers in Northern Territory";
             break;
         case "ACT":
             $this->view->Title = "Racehorse Trainers in Australian Capital Territory";
             break;
     }
     $this->view->headTitle($this->view->Title);
     $this->view->active = "state";
 }
Exemplo n.º 11
0
function debug_train(&$writing, $ret)
{
    $t = new Trainer();
    //训练(需要大量资源,非常慢)
    $t->train();
}
Exemplo n.º 12
0
function learn(&$ret, &$writing, $char_id, $user_id)
{
    try {
        $c = new Character();
        $w = $c->create_sparse_writing($writing);
        //骨架化笔画
        $f = new Feature();
        $features = $f->make_feature($w);
        //获取特征
        $dic = new Dictionary();
        $dic->add_writing($char_id, $w, $user_id);
        //添加笔迹
        $dict_feature = $dic->get_feature($char_id);
        //获取数据库中已存的特征值
        $dict_feature = isset($dict_feature) ? json_decode($dict_feature) : null;
        $t = new Trainer();
        $t->train($features, $dict_feature);
        $first_stroke_type = $c->get_first_stroke_type($w);
        //首笔的笔画类型(横竖撇点折)
        $int_strokes = sizeof($w->s);
        //笔画数
        $dic->update_character($char_id, json_encode($t->train_features), $int_strokes, $first_stroke_type);
        $ret->msgno = MSG_OK;
        $ret->msg = MSG_OK_LEARN;
    } catch (Exception $e) {
        $ret->msgno = MSG_ERR;
        $ret->msg = $e->getMessage();
    }
}
Exemplo n.º 13
0
    $body = $app->request->getBody();
    $json = json_decode($body);
    $trainer = Trainer::getById($id);
    $result = $trainer->removeBadge($json->badgeId);
    sendResponse($result);
});
$app->get('/trainers/:id', function ($id) use($app) {
    $trainer = Trainer::getById($id);
    sendResponse($trainer->serialize());
});
$app->get('/trainers/:id/pokemon', function ($id) use($app) {
    $trainer = Trainer::getById($id);
    sendResponse($trainer->getPokemon());
});
$app->get('/trainers/:id/badges', function ($id) use($app) {
    $trainer = Trainer::getById($id);
    sendResponse($trainer->getBadges());
});
$app->get('/gyms', function () use($app) {
    sendResponse(Gym::getAll());
});
$app->get('/gyms/:id', function ($id) use($app) {
    $gym = Gym::getById($id);
    sendResponse($gym->serialize());
});
$app->get('/gyms/:id/leader', function ($id) use($app) {
    $gym = Gym::getById($id);
    sendResponse($gym->getLeader()->serialize());
});
$app->get('/types', function () use($app) {
    sendResponse(Type::getAll());
 public function doAddEditView()
 {
     try {
         //validate
         $status = ValidationContainer::instance();
         require_once 'models/table/OptionList.php';
         require_once 'models/table/MultiOptionList.php';
         require_once 'models/table/Location.php';
         $request = $this->getRequest();
         $validateOnly = $request->isXmlHttpRequest();
         $person_id = $this->getSanParam('id');
         $personObj = new Person();
         $personrow = $personObj->findOrCreate($person_id);
         $personArray = $personrow->toArray();
         $helper = new Helper();
         $ssl = $helper->getSkillSmartLookups();
         $this->view->assign('skillsmart', $ssl);
         // nationality dropdown data
         $this->view->assign('lookupnationalities', $helper->getNationalities());
         $train = $helper->getPersonTraining($person_id);
         $this->view->assign('persontraining', $train);
         //locations
         $locations = Location::getAll();
         $this->viewAssignEscaped('locations', $locations);
         if ($validateOnly) {
             $this->setNoRenderer();
         }
         // Figure out reason code "Other" for checking posted data,
         // and for enabling/disabling reason_other field
         $other_reason_option_id = -1;
         $db = Zend_Db_Table_Abstract::getDefaultAdapter();
         $sql = "SELECT * FROM person_attend_reason_option where LCASE(attend_reason_phrase) LIKE '%other%'";
         $rowArray = $db->fetchAll($sql);
         if ($rowArray) {
             $other_reason_option_id = $rowArray[0]['id'];
         }
         $this->viewAssignEscaped('other_reason_option_id', $other_reason_option_id);
         if ($request->isPost()) {
             $errortext = "";
             if ($dupe_id = $this->getSanParam('dupe_id')) {
                 if ($this->getSanParam('maketrainer')) {
                     // require user to add trainer info
                     $status->setRedirect('/person/edit/id/' . $dupe_id . '/trainingredirect/' . $this->getSanParam('trainingredirect') . '/maketrainer/1');
                 } else {
                     if ($this->_getParam('trainingredirect')) {
                         $status->setStatusMessage(t('The person was saved. Refreshing history...'));
                         $_SESSION['status'] = t('The person was saved.');
                         $this->trainingRedirect($dupe_id);
                     } else {
                         $status->setRedirect('/person/edit/id/' . $dupe_id);
                     }
                 }
                 return;
             }
             $status->checkRequired($this, 'first_name', $this->tr('First Name'));
             $status->checkRequired($this, 'last_name', $this->tr('Last Name'));
             $status->checkRequired($this, 'primary_qualification_option_id', t('Professional qualification'));
             if ($this->setting('display_gender') != '0') {
                 $status->checkRequired($this, 'gender', t('Gender'));
             }
             if ($this->setting('display_mod_skillsmart')) {
                 //$status->checkRequired ( $this, 'occupational_category_id', t ( 'Occupational category' ) );
                 if ($this->getSanParam('govemp_option_id')) {
                     //$status->checkRequired ( $this, 'govemp_option_id', t ( 'Government Employee' ) );
                     //$status->checkRequired ( $this, 'occupational_category_id', t ( 'Occupational category' ) );
                     $status->checkRequired($this, 'persal_number', t('Persal Number'));
                 }
             } else {
                 $status->checkRequired($this, 'primary_qualification_option_id', t('Professional qualification'));
             }
             $birthParam = @$this->getSanParam('birth-year') . '-' . @$this->getSanParam('birth-month') . '-' . @$this->getSanParam('birth-day');
             if ($birthParam !== '--' and $birthParam !== '0000-00-00') {
                 $status->isValidDate($this, 'birth-day', t('Birthdate'), $birthParam);
             }
             //trainer only
             if ($this->getSanParam('is_trainer') || $this->getSanParam('active_trainer_option_id') || $this->getSanParam('trainer_type_option_id')) {
                 $status->checkRequired($this, 'trainer_type_option_id', t('Trainer') . ' ' . t('type'));
                 // 10/02/2011 Sean Smith: Removed at client request.
                 //if ($this->setting ( 'display_trainer_affiliations' )) {
                 //	$status->checkRequired ( $this, 'trainer_affiliation_option_id', t ( 'Trainer').' '.t('affiliation' ) );
                 //}
                 //at least one skill
                 $status->checkRequired($this, 'trainer_skill_id', t('Trainer') . ' ' . t('skill'));
             }
             // Check for manual reason for attending entry (if pulldown reason is 'other')
             if ($this->setting('display_attend_reason')) {
                 //if ($status->checkRequired ( $this, 'attend_reason_option_id', t ( 'Reason For Attending' ))) {
                 $reason_id = $this->getSanParam('attend_reason_option_id');
                 $other_reason = $this->getSanParam('attend_reason_other');
                 if (($reason_id || $reason_id == 0) && $other_reason_option_id >= 0) {
                     if ($reason_id == $other_reason_option_id) {
                         if ($other_reason == "") {
                             $status->addError('attend_reason_other', t('Enter a reason, or select a different reason above.'));
                             $errortext .= "Enter a reason, or select a different reason above.<br>";
                             error_log("Enter a reason, or select a different reason above.");
                         }
                     } else {
                         if ($other_reason != "") {
                             $status->addError('attend_reason_other', t('You can not type in a reason with the reason selected above.'));
                             $errortext .= "You can not type in a reason with the reason selected above.<br>";
                             error_log("You can not type in a reason with the reason selected above.");
                         }
                     }
                 }
                 //}
             }
             //check facility
             if ($status->checkRequired($this, 'facilityInput', t('Facility'))) {
                 $facility_id = $this->getSanParam('facilityInput');
                 if (is_array($facility_id)) {
                     $fac_arr = array();
                     foreach ($facility_id as $fac_id) {
                         if ($strrpos = strrpos($fac_id, '_')) {
                             $fac_arr[] = substr($fac_id, $strrpos + 1);
                         }
                     }
                     $personrow->multi_facility_ids = json_encode($fac_arr);
                     $facility_id = current($facility_id);
                 } else {
                     $personrow->multi_facility_ids = '';
                 }
                 if ($strrpos = strrpos($facility_id, '_')) {
                     $facility_id = array_pop(explode('_', $facility_id));
                 }
                 //find by name
                 if ($facility_id) {
                     $facilityByName = new Facility();
                     $row = $facilityByName->fetchRow('id = ' . $facility_id);
                     //$row = $facilityByName->fetchRow($facilityByName->select()->where('facility_name = ?', $this->getSanParam('facilityInput')));
                 }
                 if (@$row->id) {
                     $personrow->facility_id = $row->id;
                 } else {
                     $status->addError('facilityInput', t('That facility name could not be found.'));
                     $errortext .= "That facility name could not be found.<br>";
                     error_log("That facility name could not be found.");
                 }
             }
             //get home city name
             $city_id = false;
             $criteria = $this->_getAllParams();
             require_once 'views/helpers/Location.php';
             $home_city_parent_id = regionFiltersGetLastID('home', $criteria);
             if ($criteria['home_city'] && !$criteria['is_new_home_city']) {
                 $city_id = Location::verifyHierarchy($criteria['home_city'], $home_city_parent_id, $this->setting('num_location_tiers'));
                 if ($city_id === false) {
                     $status->addError('home_city', t("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box."));
                     $errortext .= "That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box.<br>";
                     error_log("That city does not appear to be located in the chosen region. If you want to create a new city, check the new city box.");
                 }
             }
             if ($status->hasError()) {
                 foreach ($status->messages as $k => $v) {
                     $errortext .= $v . "<br>";
                 }
                 $status->setStatusMessage(t('The person could not be saved. <br>' . $errortext));
             } else {
                 $personrow = self::fillFromArray($personrow, $this->_getAllParams());
                 if ($city_id === false && $this->getSanParam('is_new_home_city')) {
                     $city_id = Location::insertIfNotFound($criteria['home_city'], $home_city_parent_id, $this->setting('num_location_tiers'));
                     if ($city_id === false) {
                         $status->addError('home_city', t('Could not save that city.'));
                     }
                 }
                 if ($city_id) {
                     $personrow->home_location_id = $city_id;
                 } else {
                     $home_location_id = Location::verifyHierarchy($criteria['home_city'], $home_city_parent_id, $this->setting('num_location_tiers'));
                     if ($home_location_id) {
                         $personrow->home_location_id = $home_location_id;
                     }
                 }
                 //these are transitionary database fields, will go away soon
                 //  $personrow->home_district_id = null;
                 //  $personrow->home_province_id = null;
                 if (!$personrow->home_city) {
                     $personrow->home_city = '';
                 }
                 // bugfix, field cannot be null.
                 if ($this->getSanParam('active')) {
                     $personrow->active = 'active';
                 } else {
                     $personrow->active = 'inactive';
                 }
                 $personrow->birthdate = @$this->getSanParam('birth-year') . '-' . @$this->getSanParam('birth-month') . '-' . @$this->getSanParam('birth-day');
                 //lookup custom 1 and 2
                 if ($this->getSanParam('custom1Input')) {
                     $id = OptionList::insertIfNotFound('person_custom_1_option', 'custom1_phrase', $this->getSanParam('custom1Input'));
                     $personrow->person_custom_1_option_id = $id;
                 } else {
                     $personrow->person_custom_1_option_id = null;
                 }
                 if ($this->getSanParam('custom2Input')) {
                     $id = OptionList::insertIfNotFound('person_custom_2_option', 'custom2_phrase', $this->getSanParam('custom2Input'));
                     $personrow->person_custom_2_option_id = $id;
                 } else {
                     $personrow->person_custom_2_option_id = null;
                 }
                 if ($this->setting('display_mod_skillsmart')) {
                     $personrow->govemp_option_id = $this->getSanParam('govemp_option_id');
                     $personrow->occupational_category_id = $this->getSanParam('occupational_category_id');
                     $personrow->persal_number = $this->getSanParam('persal_number');
                     $personrow->bodies_id = $this->getSanParam('professionalbodies_id');
                     $personrow->race_option_id = $this->getSanParam('race_option_id');
                     $personrow->disability_option_id = $this->getSanParam('disability_option_id');
                     $personrow->professional_reg_number = $this->getSanParam('professional_reg_number');
                     $personrow->nationality_id = $this->getSanParam('nationality_id');
                     $personrow->nurse_training_id = $this->getSanParam('nurse_training_id');
                     $personrow->care_start_year = $this->getSanParam('care_start_year');
                     $personrow->timespent_rank_pregnant = $this->getSanParam('timespent_rank_pregnant');
                     $personrow->timespent_rank_adults = $this->getSanParam('timespent_rank_adults');
                     $personrow->timespent_rank_children = $this->getSanParam('timespent_rank_children');
                     $personrow->timespent_rank_pregnant_pct = $this->getSanParam('timespent_rank_pregnant_pct');
                     $personrow->timespent_rank_adults_pct = $this->getSanParam('timespent_rank_adults_pct');
                     $personrow->timespent_rank_children_pct = $this->getSanParam('timespent_rank_children_pct');
                     $personrow->supervised_id = $this->getSanParam('supervised_id');
                     $personrow->supervision_frequency_id = $this->getSanParam('supervision_frequency_id');
                     $personrow->supervisors_profession = $this->getSanParam('supervisors_profession');
                     $personrow->facilitydepartment_id = $this->getSanParam('facilitydepartment_id');
                     $training_recieved_arr = array();
                     $training_recieved_data = '';
                     $training_recieved_results = array();
                     foreach ($ssl['training'] as $trainingnode) {
                         $training_recieved_arr[$trainingnode['id']] = $trainingnode['label'];
                     }
                     // build and insert training recieved vars in json
                     foreach ($_POST as $postvar => $postval) {
                         if (strstr($postvar, 'trainingrecieved_') && (isset($_POST[$postvar]) && $_POST[$postvar] != '')) {
                             $recv_str = '';
                             $recv_num = explode('_', $postvar);
                             if (isset($training_recieved_arr[intval($recv_num[1])])) {
                                 $recv_str = $training_recieved_arr[intval($recv_num[1])];
                                 $training_recieved_results[$recv_str][$recv_num[2]] = $postval;
                             }
                         }
                     }
                     if (!empty($training_recieved_results)) {
                         $training_recieved_data = json_encode($training_recieved_results);
                     }
                     $personrow->training_recieved_data = $training_recieved_data;
                     //$personrow->comments_skillsmart = $this->getSanParam('govemp_option_id');//0
                     /*
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('custom1Input');//1
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('race_option_id');//2
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('disability_option_id');//3
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('disability');//4
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('custom2Input');//5
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('rank1_option_id');//6
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('rank2_option_id');//7
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('rank3_option_id');//8
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('percent1');//9
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('percent2');//10
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('percent3');//11
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('supervised_option_id');//12
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('sfreq_option_id');//13
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('specifyfreqinput');//14
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('svoccu');//15
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother');//16
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother');//17
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother');//18
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother');//19
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('specifyoccupationinput');//20
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('trainer_type_option_id1');//21
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother0');//22
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother0');//23
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother0');//24
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother0');//25
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother1');//26
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother1');//27
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother1');//28
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother1');//29
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother2');//30
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother2');//31
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother2');//32
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother2');//33
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother3');//34
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother3');//35
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother3');//36
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother3');//37
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother4');//38
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother4');//39
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother4');//40
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother4');//41
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother5');//42
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother5');//43
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother5');//44
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother5');//45
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother6');//46
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother6');//47
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother6');//48
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother6');//49
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother7');//50
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother7');//51
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother7');//52
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother7');//53
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainother8');//54
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('checktrainother8');//55
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('selecttrainother8');//56
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('texttrainotherother8');//57
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('bodies_id');//58
                     $personrow->comments_skillsmart = $personrow->comments_skillsmart."§".$this->getSanParam('nationality_id');//59
                     */
                     if ($person_id) {
                         $trainsaved = array();
                         $train = $this->getSanParam('train');
                         foreach ($train as $key => $t) {
                             if (isset($t['check'])) {
                                 if ($t['originalid'] != 0) {
                                     // UPDATING EXISTING // moving this - cant really use $person_id before $personrow->save on adding a new user... probably should happen later or only on edits... im not sure
                                     $trainid = $t['originalid'];
                                     $query = "UPDATE link_person_training SET\n\t\t\t\t\t\t\t\t\tpersonid = '" . $person_id . "',\n\t\t\t\t\t\t\t\t\tyear = '" . addslashes($t['year']) . "',\n\t\t\t\t\t\t\t\t\tinstitution = '" . addslashes($t['text']) . "',\n\t\t\t\t\t\t\t\t\tothername = '' WHERE id = " . $trainid;
                                     error_log($query);
                                     $db->query($query);
                                 } else {
                                     // ADDING NEW
                                     $query = "INSERT INTO link_person_training SET\n\t\t\t\t\t\t\t\t\t\t\tpersonid = '" . $person_id . "',\n\t\t\t\t\t\t\t\t\t\t\ttrainingid = '" . addslashes($key) . "',\n\t\t\t\t\t\t\t\t\t\t\tyear = '" . addslashes($t['year']) . "',\n\t\t\t\t\t\t\t\t\t\t\tinstitution = '" . addslashes($t['text']) . "',\n\t\t\t\t\t\t\t\t\t\t\tothername = ''";
                                     error_log($query);
                                     $db->query($query);
                                     $trainid = $db->lastInsertId();
                                 }
                                 $trainsaved[] = $trainid;
                             }
                         }
                         if (count($trainsaved) > 0) {
                             // REMOVE ALL NON-SAVED TRAINING IDS FOR PERSON
                             $query = "DELETE FROM link_person_training WHERE personid = " . $person_id . " AND id NOT IN (" . implode(",", $trainsaved) . ")";
                             error_log($query);
                             $db->query($query);
                         } else {
                             // REMOVE ALL TRAINING IDS FOR PERSON
                             $query = "DELETE FROM link_person_training WHERE personid = " . $person_id;
                             error_log($query);
                             $db->query($query);
                         }
                     }
                 }
                 if ($personrow->save()) {
                     $status->setStatusMessage(t('The person was saved. Refreshing change history...'));
                     $_SESSION['status'] = t('The person was saved.');
                     $person_id = $personrow->id;
                     if ($this->setting('display_mod_skillsmart')) {
                         if (strlen($this->getSanParam('Facilities')) > 0) {
                             $db->query('UPDATE `facs` SET `Active`=\'N\' WHERE `person`=' . $person_id . ' AND `Active`=\'Y\';');
                             $Facs = split('\\$', $this->getSanParam('Facilities'));
                             foreach ($Facs as $kys => $vls) {
                                 $Locs = split("~", $vls);
                                 $Fac = $Locs[0];
                                 if ($strrpos = strrpos($Fac, '_')) {
                                     $Fac = substr($Fac, $strrpos + 1);
                                 }
                                 $db->query('INSERT INTO `facs` ( `person`, `facility`, `facstring`, `active`) VALUES (' . $person_id . ', ' . $Fac . ', \'' . $vls . '\', \'Y\');');
                             }
                         }
                         $co = 0;
                         for ($co = 1; $co <= 20; $co++) {
                             $db->query('UPDATE `trans` SET `Active`=\'N\' WHERE `person`=' . $person_id . ' AND `id`=' . $co . ' AND `Active`=\'Y\';');
                             if ($this->getSanParam('checktrain' . $co) == 'on') {
                                 $db->query('INSERT INTO `trans` ( `person`, `id`, `chk`, `yr`, `transstring`, `active`) VALUES (' . $person_id . ', ' . $co . ', \'' . $this->getSanParam('checktrain' . $co) . '\', \'' . $this->getSanParam('selecttrain' . $co) . '\', \'' . $this->getSanParam('texttrain' . $co) . '\', \'Y\');');
                             }
                         }
                     }
                     //get trainer information
                     $trainerTable = new Trainer();
                     $trainerRow = $trainerTable->fetchRow('person_id = ' . $person_id);
                     if (!$trainerRow and ($this->getSanParam('active_trainer_option_id') or $this->getSanParam('trainer_type_option_id'))) {
                         // add trainer
                         $trainerRow = $trainerTable->createRow();
                         $trainerRow->person_id = $personrow->id;
                     }
                     if ($trainerRow) {
                         //trainer info
                         $trainerRow->is_active = 1;
                         //deprecated //($this->getSanParam ( 'is_trainer' ) ? 1 : 0);
                         $trainerRow->active_trainer_option_id = $this->getSanParam('active_trainer_option_id');
                         $trainerRow->type_option_id = $this->getSanParam('trainer_type_option_id');
                         $trainerRow->affiliation_option_id = $this->setting('display_trainer_affiliations') ? $this->getSanParam('trainer_affiliation_option_id') ? $this->getSanParam('trainer_affiliation_option_id') : 0 : 0;
                         if (!$trainerRow->save()) {
                             $status->setStatusMessage(t('The') . ' ' . t('trainer') . ' ' . t('information could not be saved.'));
                         } else {
                             MultiOptionList::updateOptions('trainer_to_trainer_skill_option', 'trainer_skill_option', 'trainer_id', $person_id, 'trainer_skill_option_id', $this->getSanParam('trainer_skill_id'));
                             $language_ids = $this->getSanParam('trainer_language_id');
                             $planguage_id = $this->getSanParam('primary_language_id');
                             $primary_settings = array();
                             $found = false;
                             if ($language_ids) {
                                 foreach ($language_ids as $lid) {
                                     if ($lid == $planguage_id) {
                                         $primary_settings[] = 1;
                                         $found = true;
                                     } else {
                                         $primary_settings[] = 0;
                                     }
                                 }
                             }
                             if (!$found) {
                                 $primary_settings[] = 1;
                                 $language_ids[] = $planguage_id;
                             }
                             MultiOptionList::updateOptions('trainer_to_trainer_language_option', 'trainer_language_option', 'trainer_id', $person_id, 'trainer_language_option_id', $language_ids, 'is_primary', $primary_settings);
                         }
                     }
                     TrainingRecommend::saveRecommendedforPerson($person_id, $this->getSanParam('training_recommend'));
                     if ($this->_getParam('redirectUrl')) {
                         $status->redirect = $this->_getParam('redirectUrl');
                     } else {
                         if ($this->_getParam('trainingredirect')) {
                             // redirect back to training session
                             $this->trainingRedirect($person_id);
                         } else {
                             //if it's an add then redirect to the view page
                             if ($this->setting('display_mod_skillsmart')) {
                                 //$status->setRedirect ( '/person/view/id/' . $person_id );
                                 $qs = OptionList::suggestionListHierarchical('person_qualification_option', 'qualification_phrase', false, false, array('0 AS is_default', 'child.is_default'));
                                 $parent_id = $this->getSanParam('primary_qualification_option_id');
                                 foreach ($qs as $k => $v) {
                                     if ($v['id'] == $parent_id) {
                                         $parent_id = $v['parent_id'];
                                         break;
                                     }
                                 }
                                 $comps = $helper->getPersonCompetenciesDetailed($person_id);
                                 // Disabled redirect to competency page as per Robert's request, 11/19/2012, CDL
                                 //							if (count($comps) > 0){
                                 //								$status->setRedirect ( '/person/editcompetency/id/' . $person_id );
                                 //							} else {
                                 $status->setRedirect('/person/edit/id/' . $person_id);
                                 //							}
                                 /*
                                 							if($parent_id=="6")
                                 							{
                                 								$status->setRedirect ( '/person/addcomc/id/' . $person_id );
                                 							}
                                 							if($parent_id=="7")
                                 							{
                                 								$status->setRedirect ( '/person/addcomd/id/' . $person_id );
                                 							}
                                 							if($parent_id=="8")
                                 							{
                                 								$status->setRedirect ( '/person/addcomn/id/' . $person_id );
                                 							}
                                 							if($parent_id=="9")
                                 							{
                                 								$status->setRedirect ( '/person/addcomp/id/' . $person_id );
                                 							}
                                 */
                             } else {
                                 $status->setRedirect('/person/edit/id/' . $person_id);
                             }
                         }
                     }
                 } else {
                     $status->setStatusMessage(t('ERROR: The person could not be saved. ' . __LINE__));
                 }
             }
             if ($validateOnly) {
                 $this->sendData($status);
             } else {
                 $this->view->assign('status', $status);
             }
         }
         if ($this->setting('display_mod_skillsmart')) {
             if ($person_id) {
                 $rows = $db->fetchAll('SELECT `facstring` FROM `facs` INNER JOIN `facility` ON `facs`.`facility` = `facility`.`id` WHERE `facility`.`is_deleted`=0 AND `facs`.`person`=' . $person_id . ' AND `facs`.`Active`=\'Y\' ORDER BY `facs`.`sno` ASC;');
                 $Fcs = "";
                 foreach ($rows as $rw) {
                     $Fcs = $Fcs . $rw['facstring'] . '$';
                 }
                 $Fcs = trim($Fcs, '$');
                 $this->view->assign('Fcs', $Fcs);
                 $rows = $db->fetchAll('SELECT `id`, `chk`, `yr`, `transstring` FROM `trans` WHERE `person`=' . $person_id . ' AND `Active`=\'Y\' ORDER BY sno ASC;');
                 $Trs = array();
                 $c*k = 0;
                 for ($c*k = 1; $c*k <= 20; $c*k++) {
                     $Trs[$c*k] = NULL;
                 }
                 foreach ($rows as $rw) {
                     $Trs[$rw['id']] = $rw;
                 }
                 $this->view->assign('Trs', $Trs);
             }
         }
         //view it
         $facilityObj = new Facility();
         $facilityrow = $facilityObj->findOrCreate($personrow->facility_id);
         $personArray['facility'] = $facilityrow->toArray();
         //facility location
         $region_ids = Location::getCityInfo($facilityrow->location_id, $this->setting('num_location_tiers'));
         $region_ids = Location::regionsToHash($region_ids, 'person_facility');
         $personArray = array_merge($personArray, $region_ids);
         //audit history
         $creatorObj = new User();
         $updaterObj = new User();
         $creatorrow = $creatorObj->findOrCreate($personrow->created_by);
         $personArray['creator'] = addslashes($creatorrow->first_name . ' ' . $creatorrow->last_name);
         $updaterrow = $updaterObj->findOrCreate($personrow->modified_by);
         $personArray['updater'] = addslashes($updaterrow->first_name . ' ' . $updaterrow->last_name);
         $personArray['birthdate-year'] = '';
         $personArray['birthdate-month'] = '';
         $personArray['birthdate-day'] = '';
         //split birthdate fields
         if ($person_id and $personrow->birthdate) {
             $parts = explode(' ', $personrow->birthdate);
             $parts = explode('-', $parts[0]);
             $personArray['birthdate-year'] = $parts[0];
             $personArray['birthdate-month'] = $parts[1];
             $personArray['birthdate-day'] = $parts[2];
         }
         //custom fields
         if ($person_id) {
             $personArray['custom1'] = ITechTable::getCustomValue('person_custom_1_option', 'custom1_phrase', $personArray['person_custom_1_option_id']);
             $personArray['custom2'] = ITechTable::getCustomValue('person_custom_2_option', 'custom2_phrase', $personArray['person_custom_2_option_id']);
         }
         //qualifications
         $qualificationsArray = OptionList::suggestionListHierarchical('person_qualification_option', 'qualification_phrase', false, false, array('0 AS is_default', 'child.is_default'));
         $personQualificationId = $personArray['primary_qualification_option_id'];
         // get parent qualification id, if user has sub qualification selected
         $personArray['primary_qualification_option_id_parent'] = $personQualificationId;
         foreach ($qualificationsArray as $k => $qualArray) {
             if ($qualArray['parent_phrase'] == 'unknown') {
                 unset($qualificationsArray[$k]);
                 //remove unknown as an option
             }
             if ($qualArray['id'] == $personQualificationId) {
                 $personArray['primary_qualification_option_id_parent'] = $qualArray['parent_id'];
             }
         }
         $this->viewAssignEscaped('qualifications', $qualificationsArray);
         // occupational categories
         $occupationalsArray = OptionList::suggestionListHierarchical('occupational_categories', 'category_phrase', false, false, array('0 AS is_default', 'child.is_default'));
         $personQualificationId = $personArray['primary_qualification_option_id'];
         // get parent occupational category id, if user has sub qualification selected
         $personArray['occupational_category_id_parent'] = $personQualificationId;
         foreach ($occupationalsArray as $k => $catArray) {
             if ($catArray['category_phrase'] == 'unknown') {
                 unset($qualificationsArray[$k]);
                 //remove unknown as an option
             }
             if ($catArray['id'] == $personQualificationId) {
                 $personArray['occupational_category_id'] = $catArray['parent_id'];
             }
         }
         $this->viewAssignEscaped('occupationalcats', $occupationalsArray);
         // get recommended trainings class topics
         $training_recommend = TrainingRecommend::getRecommendedTrainingTopics($personArray['primary_qualification_option_id_parent']);
         $this->viewAssignEscaped('training_recommend', $training_recommend);
         // get saved recommended trainings class titles
         $training_recommend_saved = TrainingRecommend::getRecommendedforPerson($person_id);
         $this->viewAssignEscaped('training_recommend_saved', $training_recommend_saved);
         //$classes = TrainingRecommend::getRecommendedClassesforPerson ( $person_id );
         //responsibilities
         if ($this->setting('display_mod_skillsmart')) {
             $responsibilitiesArray = OptionList::suggestionList('person_responsibility_option', 'responsibility_phrase', false, false);
             $this->viewAssignEscaped('responsibilities', $responsibilitiesArray);
         }
         $primaryResponsibilitiesArray = OptionList::suggestionList('person_primary_responsibility_option', 'responsibility_phrase', false, false);
         $this->viewAssignEscaped('primaryResponsibilities', $primaryResponsibilitiesArray);
         $secondaryResponsibilitiesArray = OptionList::suggestionList('person_secondary_responsibility_option', 'responsibility_phrase', false, false);
         $this->viewAssignEscaped('secondaryResponsibilities', $secondaryResponsibilitiesArray);
         $educationlevelsArray = OptionList::suggestionList('person_education_level_option', 'education_level_phrase', false, false);
         $this->viewAssignEscaped('educationlevels', $educationlevelsArray);
         $attendreasonsArray = OptionList::suggestionList('person_attend_reason_option', 'attend_reason_phrase', false, false);
         $this->viewAssignEscaped('attendreasons', $attendreasonsArray);
         $activeTrainerArray = OptionList::suggestionList('person_active_trainer_option', 'active_trainer_phrase', false, false);
         $this->viewAssignEscaped('active_trainer', $activeTrainerArray);
         $titlesArray = OptionList::suggestionList('person_title_option', 'title_phrase', false, false);
         $this->viewAssignEscaped('titles', $titlesArray);
         $suffixesArray = OptionList::suggestionList('person_suffix_option', 'suffix_phrase', false, false);
         $this->viewAssignEscaped('suffixes', $suffixesArray);
         //training types
         //attach Trainer attributes
         $trainerTable = new Trainer();
         $trainerrow = $trainerTable->findOrCreate($person_id);
         $personArray['trainer_is_active'] = $this->getSanParam('maketrainer') ? 1 : $trainerrow->is_active;
         $personArray['active_trainer_option_id'] = $trainerrow->active_trainer_option_id;
         $personArray['trainer_type_option_id'] = $trainerrow->type_option_id;
         $personArray['trainer_affiliation_option_id'] = $trainerrow->affiliation_option_id;
         $titlesArray = OptionList::suggestionList('person_title_option', 'title_phrase', false, false);
         $this->viewAssignEscaped('titles', $titlesArray);
         $trainerTypesArray = OptionList::suggestionList('trainer_type_option', 'trainer_type_phrase', false, false);
         $this->viewAssignEscaped('trainer_types', $trainerTypesArray);
         $trainerAffiliationArray = OptionList::suggestionList('trainer_affiliation_option', 'trainer_affiliation_phrase', false, false);
         $this->viewAssignEscaped('trainer_affiliations', $trainerAffiliationArray);
         $trainerSkillsArray = MultiOptionList::choicesList('trainer_to_trainer_skill_option', 'trainer_id', $person_id, 'trainer_skill_option', 'trainer_skill_phrase');
         $this->viewAssignEscaped('trainer_skills', $trainerSkillsArray);
         $trainerLanguagesArray = MultiOptionList::choicesList('trainer_to_trainer_language_option', 'trainer_id', $person_id, 'trainer_language_option', 'language_phrase', 'is_primary');
         $this->viewAssignEscaped('trainer_languages', $trainerLanguagesArray);
         foreach ($trainerLanguagesArray as $lang) {
             if ($lang['is_primary']) {
                 $personArray['primary_language_id'] = $lang['id'];
             }
         }
         //has training history
         $hasTrainerHistory = false;
         if ($trainerrow->person_id) {
             $hasTrainerHistory = true;
             //we could also look up any history now, but we'll be lazy
         }
         $this->view->assign('hasTrainerHistory', $hasTrainerHistory);
         //facility types
         $typesArray = OptionList::suggestionList('facility_type_option', 'facility_type_phrase', false, false);
         $this->viewAssignEscaped('facility_types', $typesArray);
         //get home city name
         if ($personrow->home_location_id) {
             $region_ids = Location::getCityInfo($personrow->home_location_id, $this->setting('num_location_tiers'));
             $personArray['home_city'] = $region_ids[0];
             $region_ids = Location::regionsToHash($region_ids, 'home');
             $personArray = array_merge($personArray, $region_ids);
         }
         //sponsor types
         $sponsorsArray = OptionList::suggestionList('facility_sponsor_option', 'facility_sponsor_phrase', false, false);
         $this->viewAssignEscaped('facility_sponsors', $sponsorsArray);
         $this->viewAssignEscaped('person', $personArray);
         //facilities list
         //$rowArray = OptionList::suggestionList('facility',array('facility_name','id'),false,9999);
         $rowArray = Facility::selectAllFacilities($this->setting('num_location_tiers'));
         $this->viewAssignEscaped('facilities', $rowArray);
         if ($this->hasACL('edit_facility')) {
             $this->view->assign('insertFacilityLink', '<a href="#" id="show">' . str_replace(' ', '&nbsp;', t('Insert new facility')) . '</a>');
         }
         //see if it is referenced anywhere
         $this->view->assign('okToDelete', !$person_id or !Person::isReferenced($person_id));
         // create reference for GET paramaters
         if ($this->_getParam('trainingredirect')) {
             $this->view->assign('trainingredirect', $this->_getParam('trainingredirect'));
         }
         if ($this->_getParam('maketrainer')) {
             $this->view->assign('maketrainer', $this->_getParam('maketrainer'));
         }
         if ($this->_getParam('days')) {
             $this->view->assign('days', $this->_getParam('days'));
         }
     } catch (Exception $e) {
         print $e->getMessage();
     }
 }
Exemplo n.º 15
0
    function edit($create = null)
    {
        $translator = new Translator();
        if ($create) {
            $func = 'add';
        } else {
            $func = 'save';
            $trainer = new Trainer();
            $data = $trainer->get(array('id' => array_shift($this->param)));
            foreach ($data as $key => $val) {
                $data[$key] = htmlspecialchars($val, ENT_QUOTES);
            }
        }
        echo <<<EOF
<div class="container">
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
    <form role="form" action="/admin_trainer/{$func}/{$data[id]}" method="post">
\t<h2>{$translator->edit}</h2>
\t    <div class="form-group">
\t\t<input type="text" name="name" id="name" class="form-control input-lg" 
\t\tplaceholder="{$translator->Name}" tabindex="3" required value="{$data[name]}">
\t    </div>
\t    <div class="form-group">
\t\t<input type="email" name="email" id="email" class="form-control input-lg" 
\t\tplaceholder="{$translator->Email}" tabindex="3" required value="{$data[email]}">
\t    </div>
\t    <div class="form-group">
\t\t<label for="data">{$translator->Data}:</label> {$translator->Data_Desc}
\t\t<textarea  name="data" id="data" class="form-control" rows="5">{$data[data]}</textarea>
\t    </div>
\t    <div class="row">
\t\t<div class="col-xs-12 col-md-6"><input type="submit" value="{$translator->Save}" class="btn btn-primary" tabindex="13"></div>
\t    </div>
    </form>
</div>
</div> <!-- /container -->

EOF;
    }
Exemplo n.º 16
0
    function edit($create = null)
    {
        $translator = new Translator();
        $category = new Category();
        $course = new Course();
        $trainer = new Trainer();
        if ($create) {
            $func = 'add';
        } else {
            $func = 'save';
            $plan = new Plan();
            $this->id = array_shift($this->param);
            $data = $plan->get(array('id' => $this->id));
            foreach ($data as $key => $val) {
                $data[$key] = htmlspecialchars($val, ENT_QUOTES);
            }
        }
        try {
            $c_data = $course->get(array('id' => $data['course_id']));
            $category_id = $c_data['category_id'];
            $enum = $course->enumerate(array('category_id' => intval($category_id)));
            foreach ($enum as $val) {
                $courses .= "<option value=\"{$val[id]}\"" . ($val['id'] == $data['course_id'] ? ' selected' : '') . ">" . htmlspecialchars($val['name'], ENT_QUOTES) . "</option>" . NL;
            }
        } catch (Exception $e) {
        }
        $categories = Course::getCategoriesForSelect($category_id);
        $enum = $trainer->enumerate();
        foreach ($enum as $val) {
            $trainers .= "<option value=\"{$val[id]}\"" . ($val['id'] == $data['trainer_id'] ? ' selected' : '') . ">" . htmlspecialchars($val['name'], ENT_QUOTES) . "</option>" . NL;
        }
        if ($data['active'] == 't') {
            $active = 'checked';
        }
        echo <<<EOF
<div class="container">
<div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
    <form role="form" action="/admin_training/{$func}/{$data[id]}" method="post">
\t<h2>{$translator->Plan_edit}</h2>
\t    <div class="form-group">
                <label for="category_id">{$translator->Category}:</label>
        \t<select class="form-control" id="category_id" name="category_id">
                {$categories}
                </select>
            </div>
\t    <div class="form-group">
                <label for="course_id">{$translator->Course}:</label>
        \t<select class="form-control" id="course_id" name="course_id">
                {$courses}
                </select>
            </div>

\t    <div class="form-group">
\t\t<label for="start">{$translator->Start}:</label> <span class="text-muted">{$translator->Start_Desc}</span>
\t\t<input name="start" id="start" class="form-control datetimepicker" value="{$data[start]}">
\t    </div>
\t    <div class="form-group">
\t\t<label for="finish">{$translator->Finish}:</label> <span class="text-muted">{$translator->Finish_Desc}</span>
\t\t<input name="finish" id="finish" class="form-control datetimepicker" value="{$data[finish]}">
\t    </div>
\t    <div class="form-group">
\t\t<input type="text" name="contact" id="contact" class="form-control input-lg" 
\t\tplaceholder="{$translator->Contact}" tabindex="5" required value="{$data[contact]}">
\t    </div>
\t    <div class="form-group">
\t\t<input type="text" name="place" id="place" class="form-control input-lg" 
\t\tplaceholder="{$translator->Place}" tabindex="6" required value="{$data[place]}">
\t    </div>
\t    <div class="form-group">
                <label for="trainer_id">{$translator->Trainer}:</label>
        \t<select class="form-control" id="trainer_id" name="trainer_id">
                {$trainers}
                </select>
            </div>
\t    <div class="checkbox">
\t\t<label><input type="checkbox" value="true" name="active" id="active" {$active}> {$translator->Active}</label>
\t    </div>

EOF;
        if (!$create) {
            // let add people to plan, because plan_ID is known
            $user = new User();
            $training = new Training();
            $enum = $training->enumerate(array('plan_id' => $data['id']));
            if (is_object($enum)) {
                foreach ($enum as $val) {
                    $u_data = $user->get(array('id' => $val['user_id']));
                    $json = array('id' => $data['id'], 'name' => $data['name'], 'email' => $data['email'], 'company' => $data['company'], 'city' => $data['city']);
                    $users .= "<tr id=\"row{$u_data[id]}\"><td>{$u_data[name]}</td><td>" . "{$u_data[email]}</td><td>{$u_data[company]} / {$u_data[city]}</td><td>" . "<a href=\"#\" onclick=\"return removeuser({$u_data[id]});\">" . '<span class="glyphicon glyphicon-trash"></span></a></td></tr>' . NL;
                }
            }
            echo <<<EOF
<div class="form-group totop-relative">
<small>
<table id="users"  class="table table-striped">
<tbody>
{$users}
</tbody>
</table>
</small>
<div class="list-group totop" id="usermenu" >
</div>
<input type="text" name="searchuser" id="searchuser" class="form-control input-md" placeholder="{$translator->Search_user}">
</div>

EOF;
        }
        echo <<<EOF
\t    <div class="row">
\t\t<div class="col-xs-12 col-md-6"><input type="submit" value="{$translator->Save}" class="btn btn-primary" tabindex="13"></div>
\t    </div>
    </form>
</div>
</div> <!-- /container -->

EOF;
    }
 /**
  * autocomplete ajax (trainer)
  */
 public function trainerFirstListAction()
 {
     require_once 'models/table/Trainer.php';
     $rowArray = Trainer::suggestionListByFirstName($this->_getParam('query'), 100, $this->setting('display_middle_name_last'));
     $rowArray = $this->_attach_locations($rowArray);
     $this->sendData($rowArray);
 }
Exemplo n.º 18
0
 public static function create($name, $rivalId, $pokemon, $badgeIds)
 {
     if ($rivalId == null) {
         $rivalId = "NULL";
     }
     $result = Database::query(SQL::createTrainer($name, $rivalId));
     if ($result) {
         $lastId = mysqli_insert_id(Database::sharedDB());
         $trainer = Trainer::getById($lastId);
         foreach ($pokemon as $p) {
             $trainer->addPokemon($p->pokemonId, $p->pokemonLevel);
         }
         foreach ($badgeIds as $id) {
             $trainer->addBadge($id);
         }
         return Trainer::getById($lastId)->serialize();
     }
     return false;
 }
Exemplo n.º 19
0
 public function getApproveRequest($rid, $tid, $cid)
 {
     $trainer = Trainer::find($tid);
     $client = Client::find($cid);
     $client->trainer()->associate($trainer);
     $client->save();
     DB::table('requests')->where('id', '=', $rid)->delete();
     return Redirect::to('admin/requests');
 }
Exemplo n.º 20
0
    function displayBody()
    {
        parent::displayBody();
        $translator = new Translator();
        $trainer = new Trainer();
        $page = $_GET['page'];
        $offset = intval($page) * ITEMS_IN_PAGE;
        if (isset($_GET['search'])) {
            unset($_GET['search']);
            unset($_GET['page']);
            $search = $_GET;
        } else {
            $search = null;
        }
        $cnt = $trainer->getCount($search);
        if (sizeof($_GET) > 0) {
            foreach ($_GET as $key => $val) {
                $values[$key] = htmlspecialchars($val, ENT_QUOTES);
            }
        }
        if ($cnt > ITEMS_IN_PAGE) {
            $pagination = $this->addPaginator($cnt, $page);
        }
        echo <<<EOF
<h2  class="page-header">{$translator->Trainers_header} <span class="badge">{$cnt}</span></h2>
    <div class="row">
\t<div class="btn-group">
\t<a href="/admin_trainer/new" class="btn btn-sm btn-default">
\t    <span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-user"></span> {$translator->Add}</a>
\t<button class="btn btn-sm btn-default"  data-toggle="collapse" data-target="#filter">
\t    <span class="glyphicon glyphicon-filter"></span> {$translator->Filter}
\t</button>
\t</div>
    </div>
    <div class="row">
        <div class="col-md-5 collapse" id="filter">
\t    <form role="form" class="form-horizontal" action="?" method="get">
\t\t<div class="form-group">
\t\t    <div class="form-group">
\t\t    <label for="name" class="control-label col-sm-3">{$translator->Name}:</label>
\t\t    <div class="col-sm-8">
\t\t    <input type="text" class="form-control" id="name" name="name" value="{$values[name]}">
\t\t    </div>
\t\t    </div>
\t\t    <div class="form-group">
\t\t    <label for="email" class="control-label col-sm-3">{$translator->Email}:</label>
\t\t    <div class="col-sm-8">
\t\t    <input type="text" class="form-control" id="email" name="email" value="{$values[email]}">
\t\t    </div>
\t\t    </div>
\t\t    <div class="form-group">
\t\t    <label for="data" class="control-label col-sm-3">{$translator->Data}:</label>
\t\t    <div class="col-sm-8">
\t\t    <input type="text" class="form-control" id="data" name="data" value="{$values[data]}">
\t\t    </div>
\t\t    </div>
\t\t    <div class="form-group">
\t\t    <div class="col-sm-offset-3 col-md-10">
\t\t    <input class="sr-only" name="search" value="1">
\t\t    <button type="submit" class="btn btn-sm btn-default">{$translator->Apply}</button>
\t\t    </div>
\t\t    </div>
\t\t</div>
\t    </form>
\t</div>
    </div>
{$pagination}
          <div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>#</th>
                  <th>{$translator->Name}</th>
                  <th>{$translator->Email}</th>
                  <th>{$translator->Data}</th>
                </tr>
              </thead>
              <tbody>

EOF;
        $enum = $trainer->enumerate($search, $offset, ITEMS_IN_PAGE);
        if (is_object($enum)) {
            $i = 1 + $offset;
            foreach ($enum as $key => $data) {
                if (strlen($data['data']) > 50) {
                    $data['data'] = '<small>' . $data['data'] . '</small>';
                } else {
                    if (strlen($data['data']) > 200) {
                        $data['data'] = '<small>' . substr($data['data'], 0, 200) . '...</small>';
                    }
                }
                echo "                <tr>\n                  <td>{$i}</td>\n                  <td>{$data[name]}</td>\n                  <td>{$data[email]}</td>\n                  <td>{$data[data]}</td>\n                  <td><a href=\"/admin_trainer/edit/{$data[id]}\" title=\"{$translator->edit}\"><span class=\"glyphicon glyphicon-user\"></span></a></td>\n                  <td><a href=\"/admin_trainer/delete/{$data[id]}\" title=\"{$translator->del}\" onClick=\"return confirm('{$translator->AreYouSure}');\"><span class=\"glyphicon glyphicon-trash\"></span></a></td>\n                </tr>" . NL;
                $i++;
            }
        }
        echo <<<EOF
\t    </table>
\t</div>

EOF;
    }