public function assignEvaluationAction()
 {
     $id = $this->getSanParam('id');
     $this->view->assign('id', $id);
     $evaluation = new Evaluation();
     $rows = $evaluation->find($id);
     $row = $rows->current();
     $this->view->assign('evaluation', $row);
     // restricted access?? only show trainings we have the ACL to view
     require_once 'views/helpers/TrainingViewHelper.php';
     $orgWhere = '';
     $org_allowed_ids = allowed_organizer_access($this);
     if ($org_allowed_ids) {
         // doesnt have acl 'training_organizer_option_all'
         $org_allowed_ids = implode(',', $org_allowed_ids);
         $orgWhere = " training_organizer_option_id in ({$org_allowed_ids}) ";
     }
     // restricted access?? only show organizers that belong to this site if its a multi org site
     $site_orgs = allowed_organizer_in_this_site($this);
     // for sites to host multiple training organizers on one domain
     $allowedWhereClause .= $site_orgs ? " AND training_organizer_option_id in ({$site_orgs}) " : "";
     require_once 'models/table/Training.php';
     $tableObj = new Training();
     $trainings = $tableObj->getTrainings($orgWhere);
     $assigned = $evaluation->fetchAssignments($id);
     foreach ($trainings as $k => $r) {
         $trainings[$k]['input_checkbox'] = '<input type="checkbox" name="training_ids[]" value="' . $r['training_id'] . '" ' . (array_search($r['training_id'], $assigned) !== false ? ' checked="checked" ' : '') . ' >';
     }
     $this->view->assign('trainings', $trainings);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $status = ValidationContainer::instance();
         $training_ids = $this->getSanParam('training_ids');
         $adjusted = array();
         foreach ($training_ids as $tr) {
             $adjusted[$tr] = $tr;
         }
         require_once 'models/table/MultiOptionList.php';
         MultiOptionList::updateOptions('evaluation_to_training', 'training', 'evaluation_id', $id, 'training_id', $adjusted);
         $_SESSION['status'] = t('The') . ' ' . t('Trainings') . ' ' . t('have been assigned.');
         $status->setStatusMessage(t('The') . ' ' . t('Trainings') . ' ' . t('have been assigned.'));
         $status->setRedirect('/evaluation/browse');
         $this->sendData($status);
     }
 }
function allowed_org_access_full_list(&$itechthis)
{
    $orgs = allowed_organizer_access($itechthis);
    return $orgs ? implode(',', $orgs) : false;
}
    public function evaluationsReportAction()
    {
        require_once 'models/table/Trainer.php';
        require_once 'models/table/TrainingLocation.php';
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        //criteria
        $criteria['showTrainer'] = $this->getSanParam('showTrainer');
        $criteria['showCategory'] = $this->getSanParam('showCategory');
        $criteria['showTitle'] = $this->getSanParam('showTitle');
        $criteria['showLocation'] = $this->getSanParam('showLocation');
        $criteria['showOrganizer'] = $this->getSanParam('showOrganizer');
        $criteria['showMechanism'] = $this->getSanParam('showMechanism');
        $criteria['showTopic'] = $this->getSanParam('showTopic');
        $criteria['showLevel'] = $this->getSanParam('showLevel');
        $criteria['showPepfar'] = $this->getSanParam('showPepfar');
        $criteria['showMethod'] = $this->getSanParam('showMethod');
        $criteria['showFunding'] = $this->getSanParam('showFunding');
        $criteria['showTOT'] = $this->getSanParam('showTOT');
        $criteria['showRefresher'] = $this->getSanParam('showRefresher');
        $criteria['showGotCurric'] = $this->getSanParam('showGotCurric');
        $criteria['showGotComment'] = $this->getSanParam('showGotComment');
        $criteria['showLang1'] = $this->getSanParam('showLang1');
        $criteria['showLang2'] = $this->getSanParam('showLang2');
        $criteria['showCustom1'] = $this->getSanParam('showCustom1');
        $criteria['showCustom2'] = $this->getSanParam('showCustom2');
        $criteria['showCustom3'] = $this->getSanParam('showCustom3');
        $criteria['showCustom4'] = $this->getSanParam('showCustom4');
        $criteria['showCustom5'] = $this->getSanParam('showCustom5');
        $criteria['showProvince'] = $this->getSanParam('showProvince');
        $criteria['showDistrict'] = $this->getSanParam('showDistrict');
        $criteria['showRegionC'] = $this->getSanParam('showRegionC');
        $criteria['showRegionD'] = $this->getSanParam('showRegionD');
        $criteria['showRegionE'] = $this->getSanParam('showRegionE');
        $criteria['showRegionF'] = $this->getSanParam('showRegionF');
        $criteria['showRegionG'] = $this->getSanParam('showRegionG');
        $criteria['showRegionH'] = $this->getSanParam('showRegionH');
        $criteria['showRegionI'] = $this->getSanParam('showRegionI');
        $criteria['evaluation_id'] = $this->getSanParam('evaluation_id');
        $criteria['trainer_id'] = $this->getSanParam('trainer_id');
        $criteria['training_category_id'] = $this->getSanParam('training_category_id');
        $criteria['training_title_id'] = $this->getSanParam('training_title_id');
        $criteria['training_location_id'] = $this->getSanParam('training_location_id');
        $criteria['training_organizer_id'] = $this->getSanParam('training_organizer_id');
        $criteria['training_mechanism_id'] = $this->getSanParam('training_mechanism_id');
        $criteria['training_topic_id'] = $this->getSanParam('training_topic_id');
        $criteria['training_level_id'] = $this->getSanParam('training_level_id');
        $criteria['training_pepfar_id'] = $this->getSanParam('training_pepfar_id');
        $criteria['training_method_id'] = $this->getSanParam('training_method_id');
        $criteria['training_funding_id'] = $this->getSanParam('training_funding_id');
        $criteria['training_tot_id'] = $this->getSanParam('training_tot_id');
        $criteria['training_refresher_id'] = $this->getSanParam('training_refresher_id');
        $criteria['training_got_id'] = $this->getSanParam('training_got_id');
        $criteria['training_gotcomment_id'] = $this->getSanParam('training_gotcomment_id');
        $criteria['training_lang1_id'] = $this->getSanParam('training_lang1_id');
        $criteria['training_lang2_id'] = $this->getSanParam('training_lang2_id');
        $criteria['training_custom1_id'] = $this->getSanParam('training_custom1_id');
        $criteria['training_custom2_id'] = $this->getSanParam('training_custom2_id');
        $criteria['training_custom3_id'] = $this->getSanParam('training_custom3_id');
        $criteria['training_custom4_id'] = $this->getSanParam('training_custom4_id');
        $criteria['province_id'] = $this->getSanParam('province_id');
        $criteria['district_id'] = $this->getSanParam('district_id');
        $criteria['region_c_id'] = $this->getSanParam('region_c_id');
        $criteria['region_d_id'] = $this->getSanParam('region_d_id');
        $criteria['region_e_id'] = $this->getSanParam('region_e_id');
        $criteria['region_f_id'] = $this->getSanParam('region_f_id');
        $criteria['region_g_id'] = $this->getSanParam('region_g_id');
        $criteria['region_h_id'] = $this->getSanParam('region_h_id');
        $criteria['region_i_id'] = $this->getSanParam('region_i_id');
        $criteria['startdate'] = $this->getSanParam('startdate');
        $criteria['enddate'] = $this->getSanParam('enddate');
        $criteria['has_response'] = $this->getSanParam('has_response');
        $criteria['limit'] = $this->getSanParam('limit');
        $criteria['go'] = $this->getSanParam('go');
        if ($criteria['go']) {
            // fields
            $sql = 'SELECT pt.id as "id", ptc.pcnt, pt.training_start_date, pt.training_end_date, pt.has_known_participants  ';
            // training fields
            $sql .= ',title, trainer_person_id, first_name, last_name, question_text, question_type, weight, value_text, value_int';
            // evaluation fields
            if ($criteria['showRegionI']) {
                $sql .= ', pt.region_i_name ';
            }
            if ($criteria['showRegionH']) {
                $sql .= ', pt.region_h_name ';
            }
            if ($criteria['showRegionG']) {
                $sql .= ', pt.region_g_name ';
            }
            if ($criteria['showRegionF']) {
                $sql .= ', pt.region_f_name ';
            }
            if ($criteria['showRegionE']) {
                $sql .= ', pt.region_e_name ';
            }
            if ($criteria['showRegionD']) {
                $sql .= ', pt.region_d_name ';
            }
            if ($criteria['showRegionC']) {
                $sql .= ', pt.region_c_name ';
            }
            if ($criteria['showDistrict']) {
                $sql .= ', pt.district_name ';
            }
            if ($criteria['showProvince']) {
                $sql .= ', pt.province_name ';
            }
            if ($criteria['showLocation']) {
                $sql .= ', pt.training_location_name ';
            }
            if ($criteria['showOrganizer']) {
                $sql .= ', torg.training_organizer_phrase as training_organizer_phrase ';
            }
            if ($criteria['showMechanism'] && $this->setting('display_training_partner')) {
                $sql .= ', organizer_partners.mechanism_id ';
            }
            if ($criteria['showLevel']) {
                $sql .= ', tlev.training_level_phrase ';
            }
            if ($criteria['showCategory']) {
                $sql .= ', tcat.training_category_phrase ';
            }
            if ($criteria['showTitle']) {
                $sql .= ', training_title ';
            }
            if ($criteria['showPepfar'] || $criteria['training_pepfar_id'] || $criteria['training_pepfar_id'] === '0') {
                $sql .= ', GROUP_CONCAT(DISTINCT tpep.pepfar_category_phrase) as "pepfar_category_phrase" ';
            }
            if ($criteria['showMethod']) {
                $sql .= ', tmeth.training_method_phrase ';
            }
            if ($criteria['showTopic']) {
                $sql .= ', GROUP_CONCAT(DISTINCT ttopic.training_topic_phrase ORDER BY training_topic_phrase) AS "training_topic_phrase" ';
            }
            if ($criteria['showTOT']) {
                $sql .= ", IF(is_tot,'" . t('Yes') . "','" . t('No') . "') AS is_tot";
            }
            if ($criteria['showRefresher']) {
                $sql .= ", IF(is_refresher,'" . t('Yes') . "','" . t('No') . "') AS is_refresher";
            }
            if ($criteria['showLang2']) {
                $sql .= ', tlos.language_phrase as "secondary_language_phrase" ';
            }
            if ($criteria['showLang1']) {
                $sql .= ', tlop.language_phrase as "primary_language_phrase" ';
            }
            if ($criteria['showGotComment']) {
                $sql .= ", pt.got_comments";
            }
            if ($criteria['showGotCurric']) {
                $sql .= ', tgotc.training_got_curriculum_phrase ';
            }
            if ($criteria['showFunding']) {
                $sql .= ', GROUP_CONCAT(DISTINCT tfund.funding_phrase ORDER BY funding_phrase) as "funding_phrase" ';
            }
            if ($criteria['showCustom1']) {
                $sql .= ', tqc.custom1_phrase ';
            }
            if ($criteria['showCustom2']) {
                $sql .= ', tqc.custom2_phrase ';
            }
            if ($criteria['showCustom3']) {
                $sql .= ', pt.custom_3';
            }
            if ($criteria['showCustom4']) {
                $sql .= ', pt.custom_4';
            }
            if ($criteria['showCustom5']) {
                $sql .= ', pt.custom_5';
            }
            list($dontcare, $location_tier, $location_id) = $this->getLocationCriteriaValues($criteria);
            $num_location_tiers = $this->setting('num_location_tiers');
            list($field_name, $location_sub_query) = Location::subquery($num_location_tiers, $location_tier, $location_id, true);
            $sql .= ' FROM (SELECT training.*, tto.training_title_phrase AS training_title,training_location.training_location_name, ' . implode(',', $field_name) . '       FROM training  ' . '         LEFT JOIN training_title_option tto ON (`training`.training_title_option_id = tto.id) ' . '         LEFT JOIN training_location ON training.training_location_id = training_location.id ' . '         LEFT JOIN (' . $location_sub_query . ') as l ON training_location.location_id = l.id ' . '  WHERE training.is_deleted=0) as pt ';
            $sql .= ' LEFT JOIN (SELECT COUNT(id) as "pcnt",training_id FROM person_to_training GROUP BY training_id) as ptc ON ptc.training_id = pt.id ';
            // joins
            if ($criteria['trainer_id']) {
                $sql .= ' LEFT JOIN training_to_trainer as t2t ON (t2t.training_id = pt.id AND t2t.trainer_id = ' . $criteria['trainer_id'] . ')';
            }
            if ($criteria['showOrganizer'] or $criteria['training_organizer_id'] || $criteria['showMechanism'] || $criteria['training_mechanism_id']) {
                $sql .= ' JOIN training_organizer_option as torg ON torg.id = pt.training_organizer_option_id ';
            }
            if ($criteria['showMechanism'] || $criteria['training_mechanism_id'] && @$this->setting('display_training_partner')) {
                $sql .= ' LEFT JOIN organizer_partners ON organizer_partners.organizer_id = torg.id';
            }
            if ($criteria['showLevel'] || $criteria['training_level_id']) {
                $sql .= ' JOIN training_level_option as tlev ON tlev.id = pt.training_level_option_id ';
            }
            if ($criteria['showMethod'] || $criteria['training_method_id']) {
                $sql .= ' JOIN training_method_option as tmeth ON tmeth.id = pt.training_method_option_id ';
            }
            if ($criteria['showPepfar'] || $criteria['training_pepfar_id'] || $criteria['training_pepfar_id'] === '0') {
                $sql .= '	LEFT JOIN (SELECT training_id, ttpco.training_pepfar_categories_option_id, pepfar_category_phrase FROM training_to_training_pepfar_categories_option as ttpco JOIN training_pepfar_categories_option as tpco ON ttpco.training_pepfar_categories_option_id = tpco.id) as tpep ON tpep.training_id = pt.id ';
            }
            if ($criteria['showTopic'] || $criteria['training_topic_id']) {
                $sql .= ' LEFT JOIN (SELECT training_id, ttto.training_topic_option_id, training_topic_phrase FROM training_to_training_topic_option as ttto JOIN training_topic_option as tto ON ttto.training_topic_option_id = tto.id) as ttopic ON ttopic.training_id = pt.id ';
            }
            if ($criteria['showLang1'] || $criteria['training_lang1_id']) {
                $sql .= ' LEFT JOIN trainer_language_option as tlop ON tlop.id = pt.training_primary_language_option_id ';
            }
            if ($criteria['showLang2'] || $criteria['training_lang2_id']) {
                $sql .= ' LEFT JOIN trainer_language_option as tlos ON tlos.id = pt.training_secondary_language_option_id ';
            }
            if ($criteria['showFunding'] || (intval($criteria['funding_min']) or intval($criteria['funding_max']))) {
                $sql .= ' LEFT JOIN (SELECT training_id, ttfo.training_funding_option_id, funding_phrase, ttfo.funding_amount FROM training_to_training_funding_option as ttfo JOIN training_funding_option as tfo ON ttfo.training_funding_option_id = tfo.id) as tfund ON tfund.training_id = pt.id ';
            }
            if ($criteria['showGotCurric'] || $criteria['training_got_id']) {
                $sql .= ' LEFT JOIN training_got_curriculum_option as tgotc ON tgotc.id = pt.training_got_curriculum_option_id';
            }
            if ($criteria['showCategory'] or !empty($criteria['training_category_id'])) {
                $sql .= 'LEFT JOIN training_category_option_to_training_title_option tcotto ON (tcotto.training_title_option_id = pt.training_title_option_id)
					 LEFT JOIN training_category_option tcat ON (tcotto.training_category_option_id = tcat.id)';
            }
            if ($criteria['showCustom1'] || $criteria['training_custom1_id']) {
                $sql .= ' LEFT JOIN training_custom_1_option as tqc ON pt.training_custom_1_option_id = tqc.id  ';
            }
            if ($criteria['showCustom2'] || $criteria['training_custom2_id']) {
                $sql .= ' LEFT JOIN training_custom_2_option as tqc2 ON pt.training_custom_2_option_id = tqc2.id  ';
            }
            #if ( $criteria['showCustom3'] || $criteria ['custom_3_id'] )
            #todo$sql .= ' LEFT JOIN training_custom_3_option as custom_3 ON pt.training_custom_3_option_id = tqc3.id  ';
            #if ( $criteria['showCustom4'] || $criteria ['custom_4_id'] )
            #todo$sql .= ' LEFT JOIN training_custom_4_option as custom_4 ON pt.training_custom_4_option_id = tqc4.id  ';
            $sql .= ' RIGHT JOIN evaluation_to_training ON pt.id = evaluation_to_training.training_id
					  RIGHT JOIN evaluation 	        ON evaluation_id = evaluation.id
					  RIGHT JOIN evaluation_response    ON evaluation_to_training.id = evaluation_response.evaluation_to_training_id
					  RIGHT JOIN evaluation_question    ON evaluation.id = evaluation_question.evaluation_id
					  RIGHT JOIN evaluation_question_response ON evaluation_response.id = evaluation_question_response.evaluation_response_id AND evaluation_question.id = evaluation_question_response.evaluation_question_id
					  LEFT JOIN person ON trainer_person_id = person.id ';
            // where
            $where = array(' pt.is_deleted=0 ');
            // restricted access?? only show trainings we have the ACL to view
            require_once 'views/helpers/TrainingViewHelper.php';
            $org_allowed_ids = allowed_organizer_access($this);
            if ($org_allowed_ids) {
                // doesnt have acl 'training_organizer_option_all'
                $org_allowed_ids = implode(',', $org_allowed_ids);
                $where[] = " pt.training_organizer_option_id in ({$org_allowed_ids}) ";
            }
            // restricted access?? only show organizers that belong to this site if its a multi org site
            $site_orgs = allowed_organizer_in_this_site($this);
            // for sites to host multiple training organizers on one domain
            if ($site_orgs) {
                $where[] = " training_organizer_option_id in ({$site_orgs}) ";
            }
            if ($criteria['training_participants_type']) {
                if ($criteria['training_participants_type'] == 'has_known_participants') {
                    $where[] = ' pt.has_known_participants = 1 ';
                }
                if ($criteria['training_participants_type'] == 'has_unknown_participants') {
                    $where[] = ' pt.has_known_participants = 0 ';
                }
            }
            if ($criteria['evaluation_id']) {
                $where[] = ' evaluation.id = ' . $criteria['evaluation_id'];
            }
            if ($criteria['trainer_id']) {
                $where[] = ' trainer_person_id = ' . $criteria['trainer_id'];
            }
            if ($criteria['training_location_id']) {
                $where[] = ' pt.training_location_id = \'' . $criteria['training_location_id'] . '\'';
            }
            if ($criteria['training_title_id'] or $criteria['training_title_id'] === '0') {
                $where[] = ' pt.training_title_option_id = ' . $criteria['training_title_id'];
            }
            if ($criteria['training_organizer_id'] or $criteria['training_organizer_id'] === '0') {
                $where[] = ' pt.training_organizer_option_id = \'' . $criteria['training_organizer_id'] . '\'';
            }
            if ($criteria['training_mechanism_id'] or $criteria['training_mechanism_id'] === '0' && $this->setting('display_training_partner')) {
                $where[] = ' organizer_partners.mechanism_id = \'' . $criteria['training_mechanism_id'] . '\'';
            }
            if ($criteria['training_topic_id'] or $criteria['training_topic_id'] === '0') {
                $where[] = ' ttopic.training_topic_option_id = \'' . $criteria['training_topic_id'] . '\'';
            }
            if ($criteria['training_level_id']) {
                $where[] = ' pt.training_level_option_id = \'' . $criteria['training_level_id'] . '\'';
            }
            if ($criteria['training_pepfar_id'] or $criteria['training_pepfar_id'] === '0') {
                $where[] = ' tpep.training_pepfar_categories_option_id = \'' . $criteria['training_pepfar_id'] . '\'';
            }
            if ($criteria['training_method_id'] or $criteria['training_method_id'] === '0') {
                $where[] = ' tmeth.id = \'' . $criteria['training_method_id'] . '\'';
            }
            if ($criteria['training_lang1_id'] or $criteria['training_lang1_id'] === '0') {
                $where[] = ' pt.training_primary_language_option_id = \'' . $criteria['training_lang1_id'] . '\'';
            }
            if ($criteria['training_lang2_id'] or $criteria['training_lang2_id'] === '0') {
                $where[] = ' pt.training_secondary_language_option_id = \'' . $criteria['training_lang2_id'] . '\'';
            }
            if ($criteria['startdate']) {
                $parts = explode('/', $criteria['startdate']);
                $reformattedDate = implode('/', array(@$parts[1], @$parts[0], @$parts[2]));
                // swap month and date (reverse them)
                $startDate = @date('Y-m-d', @strtotime($reformattedDate));
                $parts2 = explode('/', $criteria['enddate']);
                $reformattedDate = implode('/', array(@$parts2[1], @$parts2[0], @$parts2[2]));
                // swap month and date (reverse them)
                $endDate = @date('Y-m-d', @strtotime($reformattedDate));
                if (!empty($startDate) && !empty($endDate)) {
                    $where[] = ' training_start_date >= \'' . $startDate . '\'  AND training_start_date <= \'' . $endDate . '\'  ';
                }
            }
            if (intval($criteria['is_tot'])) {
                $where[] = ' is_tot = ' . $criteria['is_tot'];
            }
            // not used
            if ($criteria['training_funding_id'] or $criteria['training_funding_id'] === '0') {
                $where[] = ' tfund.training_funding_option_id = \'' . $criteria['training_funding_id'] . '\'';
            }
            if ($criteria['training_category_id'] or $criteria['training_category_id'] === '0') {
                $where[] = ' tcat.id = \'' . $criteria['training_category_id'] . '\'';
            }
            if ($criteria['training_got_id'] or $criteria['training_got_id'] === '0') {
                $where[] = ' tgotc.id = \'' . $criteria['training_got_id'] . '\'';
            }
            if ($criteria['training_custom1_id'] or $criteria['training_custom1_id'] === '0') {
                $where[] = ' pt.training_custom_1_option_id = \'' . $criteria['training_custom1_id'] . '\'';
            }
            if ($criteria['training_custom2_id'] or $criteria['training_custom2_id'] === '0') {
                $where[] = ' pt.training_custom_2_option_id = \'' . $criteria['training_custom2_id'] . '\'';
            }
            if ($criteria['training_custom3_id'] or $criteria['training_custom3_id'] === '0') {
                $where[] = ' pt.custom_3 = \'' . $criteria['training_custom3_id'] . '\'';
            }
            if ($criteria['training_custom4_id'] or $criteria['training_custom4_id'] === '0') {
                $where[] = ' pt.custom_4 = \'' . $criteria['training_custom4_id'] . '\'';
            }
            $where[] = ' evaluation.is_deleted = 0';
            $where[] = ' evaluation_response.is_deleted = 0';
            $where[] = ' evaluation_question.is_deleted = 0';
            $where[] = ' evaluation_question_response.is_deleted = 0';
            if ($criteria['has_response']) {
                $where[] = ' evaluation_response.evaluation_to_training_id IS NOT NULL ';
            }
            // finish
            if ($where) {
                $sql .= ' WHERE ' . implode(' AND ', $where);
            }
            $sql .= ' GROUP BY evaluation_question_response.id';
            $rowArray = $db->fetchAll($sql);
            // end training lookup
            // output csv if necessary
            if ($this->_getParam('outputType')) {
                $this->sendData($this->reportHeaders(false, $rowArray));
            }
            //done
        }
        // values for the view
        $this->viewAssignEscaped('results', $rowArray);
        $this->view->assign('count', count($rowArray));
        $this->view->assign('criteria', $criteria);
        //evaluations drop down
        $evaluationsArray = OptionList::suggestionList('evaluation', 'title', false, false, false);
        $this->viewAssignEscaped('evaluations', $evaluationsArray);
        //trainers
        $trainersArray = $db->fetchAll('select p.id,p.first_name,p.middle_name,p.last_name from trainer left join person p on p.id = person_id order by p.first_name asc');
        foreach ($trainersArray as $i => $row) {
            $trainersArray[$i]['fullname'] = $this->setting('display_middle_name_last') ? $row['first_name'] . ' ' . $row['last_name'] . ' ' . $row['middle_name'] : $row['first_name'] . ' ' . $row['middle_name'] . ' ' . $row['last_name'];
        }
        $this->viewAssignEscaped('trainers', $trainersArray);
        //locations
        $locations = Location::getAll();
        $this->viewAssignEscaped('locations', $locations);
        //course
        $courseArray = TrainingTitleOption::suggestionList(false, 10000);
        $this->viewAssignEscaped('courses', $courseArray);
        //location drop-down
        $tlocations = TrainingLocation::selectAllLocations($this->setting('num_location_tiers'));
        $this->viewAssignEscaped('tlocations', $tlocations);
        //organizers
        $organizersArray = OptionList::suggestionList('training_organizer_option', 'training_organizer_phrase', false, false, false);
        $this->viewAssignEscaped('organizers', $organizersArray);
        //topics
        $topicsArray = OptionList::suggestionList('training_topic_option', 'training_topic_phrase', false, false, false);
        $this->viewAssignEscaped('topics', $topicsArray);
        //levels
        $levelArray = OptionList::suggestionList('training_level_option', 'training_level_phrase', false, false);
        $this->viewAssignEscaped('levels', $levelArray);
        //pepfar
        $organizersArray = OptionList::suggestionList('training_pepfar_categories_option', 'pepfar_category_phrase', false, false, false);
        $this->viewAssignEscaped('pepfars', $organizersArray);
        //refresher
        if ($this->setting('multi_opt_refresher_course')) {
            $refresherArray = OptionList::suggestionList('training_refresher_option', 'refresher_phrase_option', false, false, false);
            $this->viewAssignEscaped('refresher', $refresherArray);
        }
        //funding
        $fundingArray = OptionList::suggestionList('training_funding_option', 'funding_phrase', false, false, false);
        $this->viewAssignEscaped('funding', $fundingArray);
        //category
        $categoryArray = OptionList::suggestionList('training_category_option', 'training_category_phrase', false, false, false);
        $this->viewAssignEscaped('category', $categoryArray);
        //primary language
        $langArray = OptionList::suggestionList('trainer_language_option', 'language_phrase', false, false, false);
        $this->viewAssignEscaped('language', $langArray);
        //category+titles
        $categoryTitle = MultiAssignList::getOptions('training_title_option', 'training_title_phrase', 'training_category_option_to_training_title_option', 'training_category_option');
        $this->view->assign('categoryTitle', $categoryTitle);
        //training methods
        $methodTitle = OptionList::suggestionList('training_method_option', 'training_method_phrase', false, false, false);
        $this->view->assign('methods', $methodTitle);
        //got curric
        $gotCuriccArray = OptionList::suggestionList('training_got_curriculum_option', 'training_got_curriculum_phrase', false, false, false);
        $this->viewAssignEscaped('gotcurric', $gotCuriccArray);
        //mechanism (organizer_partners table)
        $mechanismArray = array();
        if ($this->setting('display_training_partner')) {
            $mechanismArray = OptionList::suggestionList('organizer_partners', 'mechanism_id', false, false, false, "mechanism_id != ''");
        }
        $this->viewAssignEscaped('mechanisms', $mechanismArray);
        //customfields
        $customArray = OptionList::suggestionList('training_custom_1_option', 'custom1_phrase', false, false, false);
        $this->viewAssignEscaped('custom1', $customArray);
        $customArray2 = OptionList::suggestionList('training_custom_2_option', 'custom2_phrase', false, false, false);
        $this->viewAssignEscaped('custom2', $customArray2);
        $customArray3 = OptionList::suggestionList('training', 'custom_3', false, false, false, "custom_3 != ''");
        $this->viewAssignEscaped('custom3', $customArray3);
        $customArray4 = OptionList::suggestionList('training', 'custom_4', false, false, false, "custom_4 != ''");
        $this->viewAssignEscaped('custom4', $customArray4);
        $customArray5 = OptionList::suggestionList('training', 'custom_5', false, false, false, "custom_5 != ''");
        $this->viewAssignEscaped('custom5', $customArray5);
        #$createdByArray = $db->fetchAll("select id,CONCAT(first_name, CONCAT(' ', last_name)) as name from user where is_blocked = 0");
        #$this->viewAssignEscaped ( 'createdBy', $createdByArray );
        #// find category based on title
        #$catId = NULL;
        #if ($criteria ['training_category_id']) {
        #	foreach ( $categoryTitle as $r ) {
        #		if ($r ['id'] == $criteria ['training_category_id']) {
        #			$catId = $r ['training_category_option_id'];
        #			break;
        #		}
        #	}
        #}
        #$this->view->assign ( 'catId', $catId );
        //done
    }