Пример #1
0
function getFormOpendeurToevoegen()
{
    //opendeurdag toevoegen
    global $Grus;
    global $DM;
    $arrCactusclubs = $Grus->getArray_cactusclubs();
    //array
    //dropdown	__construct($name, array $values, $CSSclass=null, $title=null, $selected=null, $firstOption=null, $valueIsLabel=false, $multiple=false){
    $dd_cc = new DropDown("club_id", $arrCactusclubs, null, null, null, null, true, null);
    //value = label
    $cc_dd = $dd_cc->parse();
    $str = "\r\n<!--dialog form-->\r\n\r\n<div id='dialog_frm' title='opendurdag toevoegen' style='display:none'>\r\n  <form class='ui-widget ui-widget-content dialog' id='frm_data' name='frm_data'>\r\n    <fieldset>\r\n      <legend>bij wie en waar?</legend>\r\n\t  <p class='tekst'>Velden met een <span class='verplicht'>!</span> zijn verplicht in te vullen</p>\r\n      <div >\r\n        <label for='wie'>voornaam + naam<span class='verplicht'>!</span></label>\r\n        <input class='lang' type='text' name='wie' id='wie' alt='Bij wie wordt de opendeur gegeven? / wie is de organisator?' title='Bij wie wordt de opendeur gegeven? / wie is de organisator?'  >\r\n      </div>\r\n      <div>\r\n        <label for='adres' >straat huisnr,<br />postnr gemeente<span class='verplicht'>!</span></label>\r\n        <input class='lang' type='text' name='adres' id='adres' alt='volledig adres, vb: cactustraat 111, 8400 Oostende' title='volledig adres, vb: cactustraat 111, 8400 Oostende' />\r\n      </div>\r\n\t   <div>\r\n        <label for='email'>email</label>\r\n        <input class='lang required_group' type='text' name='email' id='email' alt='een emailadres waar inlichtingen kunnen bekomen worden' title='een emailadres waar inlichtingen kunnen bekomen worden' />\r\n      </div>\r\n\t  <div>\r\n        <label for='tel'>telefoon<span class='verplicht'>!</span></label>\r\n        <input class='lang required_group' type='text' name='tel' id='tel' alt='het telefoonnr waar u te bereiken bent' title='het telefoonnr waar u te bereiken bent' />\r\n      </div>\r\n    </fieldset>\r\n\t<fieldset>\r\n      <legend>het evenement</legend>\r\n\t  \r\n\t  <div>\r\n        <label for='type_evenement' class='info'>type evenement</label>\r\n       <select name='type_evenement' id='type_evenement'><option>opendeurdag</option><option>beurs</option></select>\r\n      </div>\r\n\t <div>\r\n        <label for='start_datum'>startdatum<span class='verplicht'>!</span></label>\r\n        <input class='lang datum' type='text' name='start_datum' id='start_datum' alt='de eerste dag' title='de eerste dag' />\r\n      </div>\r\n\t  <div>\r\n        <label for='eind_datum'>einddatum<span class='verplicht'>!</span></label>\r\n        <input class='lang datum' type='text' name='eind_datum' id='eind_datum' alt='de laatste dag (niet invullen indien slechts 1 dag)' title='de laatste dag (niet invullen indien slechts 1 dag)' />\r\n      </div>\r\n\t  <div>\r\n        <label for='uur'>uur<span class='verplicht'>!</span></label>\r\n        <input class='lang' type='text' name='uur' id='uur' alt='het beginuur (9u.) of de duurtijd (9u-17u)' title='het beginuur (9u.) of de duurtijd (9u-17u)' />\r\n      </div>\r\n\t  <div>\r\n        <label for='tekst' class='info'>meer uitleg?<br />(kort!)</label>\r\n        <textarea name='tekst' id='tekst' alt='eventuele begeleidende tekst' title='eventuele begeleidende tekst' rows='4' cols='10'></textarea>\r\n      </div>\r\n\t </fieldset>  \r\n    <fieldset id='fs_as' >\r\n      <legend>anti-spam vraag <span class='verplicht'>!</span></legend>\r\n\t  <p>Deze vraag dient om spammers buiten te houden, dank u voor de moeite. <br />Beantwoorden met &eacute;&eacute;n woord, in kleine letters</p>\r\n      <div id='as'>\r\n        <label for='aw' class='boven as' ></label>\r\n        <input class='lang'  type='text' name='aw' id='aw' alt='bent u een me? dit is een anti-spam vraag' title='bent u een mens? dit is een anti-spam vraag' />\r\n      </div>\r\n    </fieldset>\r\n  </form>\r\n  <!--einde dialog form-->\r\n  ";
    //return statement nodig voor output include in een variabele
    return $str;
}
   public function init(&$controller)
   {
       $this->controller = $controller;
       $this->url = $this->controller->getRequest()->getRequestUri();
       $this->url = str_replace("/outputType/" . $this->controller->getSanParam('outputType'), "", $this->url);
       $this->url = str_replace("/edit/" . $this->controller->getSanParam('edit'), "", $this->url);
       $this->url = str_replace("/delete/" . $this->controller->getSanParam('delete'), "", $this->url);
       $output = '';
       $checked = array();
       // for json table
       if ($this->controller->getSanParam('outputType')) {
           return $this->json();
       }
       // saving
       if ($this->controller->getRequest()->isPost()) {
           // Update db
           MultiAssignList::save($this->table, $this->parent_table, $this->option_table, $this->controller->getSanParam("{$this->parent_table}_id"), $this->controller->getSanParam("{$this->option_table}_id"));
       }
       //
       // deleting
       // editing
       if ($edit_id = $this->controller->getSanParam('edit')) {
           $assignedArray = MultiAssignList::getAssigned($this->table, $this->parent_table, $this->option_table, $edit_id);
           foreach ($assignedArray as $row) {
               $checked[] = $row["{$this->option_table}_id"];
           }
       }
       $output .= '
 	<div id="jsonTableHolder"></div>
 	<script type="text/javascript">
 		var multiColumnDefs = [
 		    {key:"' . key($this->parent_field) . '", label: "' . current($this->parent_field) . '", sortable:true, resizeable:true},
 		    {key:"' . key($this->option_field) . '", label: "' . current($this->option_field) . '", sortable:true, resizeable:true},
 		    {key:"edit", label: "Edit", sortable:true, resizeable:true}
 		];
 		var action = "' . $this->url . '/outputType/json";
 		makeJSONDataTable("jsonTableHolder", null, action, multiColumnDefs);
 	</script>
 	<a name="edit"></a>
 	<div class="hrGrey"></div>        
   ';
       // drop-down
       $attributes['onchange'] = "document.location = '{$this->url}/edit/' + this.value";
       $output .= '<div class="label">' . current($this->parent_field) . '</div>';
       $output .= DropDown::generateHtml($this->parent_table, key($this->parent_field), $this->controller->getSanParam('edit'), false, false, false, false, $attributes);
       $output .= '<br><br>';
       //$options = OptionList::suggestionList($this->option_table, $this->option_field, false, false);
       //print_r($options);
       $output .= Checkboxes::generateHtml($this->option_table, key($this->option_field), $view, $checked);
       return $output;
   }
 public function searchAction()
 {
     if (!$this->hasACL('edit_employee')) {
         $this->doNoAccessError();
     }
     $criteria = $this->getAllParams();
     if ($criteria['go']) {
         // process search
         $where = array();
         list($a, $location_tier, $location_id) = $this->getLocationCriteriaValues($criteria);
         list($locationFlds, $locationsubquery) = Location::subquery($this->setting('num_location_tiers'), $location_tier, $location_id, true);
         $sql = "SELECT DISTINCT\r\n\t\t\t\t\temployee.*, " . implode(',', $locationFlds) . "\r\n\t\t\t\t\t,CONCAT(supervisor.first_name, CONCAT(' ', supervisor.last_name)) as supervisor,\r\n\t\t\t\t\tqual.qualification_phrase as staff_cadre,\r\n\t\t\t\t\tsite.facility_name,\r\n\t\t\t\t\tcategory.category_phrase as staff_category\r\n\t\t\t\t\tFROM employee LEFT JOIN ({$locationsubquery}) as l ON l.id = employee.location_id\r\n\t\t\t\t\tLEFT JOIN employee supervisor ON supervisor.id = employee.supervisor_id\r\n\t\t\t\t\tLEFT JOIN facility site ON site.id = employee.site_id\r\n\t\t\t\t\tLEFT JOIN employee_qualification_option qual ON qual.id = employee.employee_qualification_option_id\r\n\t\t\t\t\tLEFT JOIN employee_category_option category on category.id = employee.employee_category_option_id\r\n\t\t\t\t\tLEFT JOIN partner ON partner.id = employee.partner_id\r\n\t\t\t\t\t";
         #if ($criteria['partner_id']) $sql    .= ' INNER JOIN partner_to_subpartner subp ON partner.id = ' . $criteria['partner_id'];
         // restricted access?? only show partners by organizers that we have the ACL to view
         #$org_allowed_ids = allowed_org_access_full_list($this); // doesnt have acl 'training_organizer_option_all'
         #if($org_allowed_ids)
         #	$where[] = " partner.organizer_option_id in ($org_allowed_ids) ";
         $locationWhere = $this->getLocationCriteriaWhereClause($criteria, '', '');
         if ($locationWhere) {
             $where[] = $locationWhere;
         }
         if ($criteria['first_name']) {
             $where[] = "employee.first_name   = '{$criteria['first_name']}'";
         }
         if ($criteria['last_name']) {
             $where[] = "employee.last_name    = '{$criteria['last_name']}'";
         }
         if ($criteria['partner_id']) {
             $where[] = 'employee.partner_id   = ' . $criteria['partner_id'];
         }
         //todo
         if ($criteria['facilityInput']) {
             $where[] = 'employee.site_id      = ' . $criteria['facilityInput'];
         }
         if ($criteria['employee_qualification_option_id']) {
             $where[] = 'employee.employee_qualification_option_id    = ' . $criteria['employee_qualification_option_id'];
         }
         if ($criteria['category_option_id']) {
             $where[] = 'employee.staff_category_id = ' . $criteria['category_option_id'];
         }
         if (count($where)) {
             $sql .= ' WHERE ' . implode(' AND ', $where);
         }
         $db = $this->dbfunc();
         $rows = $db->fetchAll($sql);
         $this->viewAssignEscaped('results', $rows);
         $this->viewAssignEscaped('count', count($rows));
     }
     // assign form drop downs
     $helper = new Helper();
     $this->view->assign('status', $status);
     $this->viewAssignEscaped('criteria', $criteria);
     $this->viewAssignEscaped('locations', Location::getAll());
     $this->view->assign('partners', DropDown::generateHtml('partner', 'partner', $criteria['partner_id'], false, $this->view->viewonly, false));
     $this->view->assign('subpartners', DropDown::generateHtml('partner', 'partner', $criteria['partner_id'], false, $this->view->viewonly, false, false, array('name' => 'subpartner_id'), true));
     $this->view->assign('cadres', DropDown::generateHtml('employee_qualification_option', 'qualification_phrase', $criteria['employee_qualification_option_id'], false, $this->view->viewonly, false));
     $this->viewAssignEscaped('sites', $helper->getFacilities());
     $this->view->assign('categories', DropDown::generateHtml('employee_category_option', 'category_phrase', $criteria['employee_category_option_id'], false, $this->view->viewonly, false));
 }
 public function editAction()
 {
     if (!$this->hasACL('edit_course')) {
         $this->doNoAccessError();
     }
     $db = Zend_Db_Table_Abstract::getDefaultAdapter();
     $request = $this->getRequest();
     $validateOnly = $request->isXmlHttpRequest();
     $status = ValidationContainer::instance();
     if ($validateOnly) {
         $this->setNoRenderer();
     }
     // populate form
     $allowIds = false;
     // todo test
     if (!$this->hasACL('training_organizer_option_all')) {
         $allowIds = array();
         $user_id = $this->isLoggedIn();
         $training_organizer_array = MultiOptionList::choicesList('user_to_organizer_access', 'user_id', $user_id, 'training_organizer_option', 'training_organizer_phrase', false, false);
         foreach ($training_organizer_array as $orgOption) {
             if ($orgOption['user_id']) {
                 $allowIds[] = $orgOption['id'];
             }
         }
     }
     $id = $this->getSanParam('id');
     if ($id && !empty($id)) {
         $sql = 'select * from organizer_partners where id = ' . $id;
         $partner_row = $db->fetchRow($sql);
         if ($partner_row !== false) {
             $this->view->assign('partner', $partner_row);
         } else {
             $this->view->assign('mode', 'add');
             $status->setStatusMessage(t('That partner could not be found.'));
         }
     } else {
         $this->view->assign('mode', 'add');
     }
     $this->view->assign('dropDownOrg', DropDown::generateHtml('training_organizer_option', 'training_organizer_phrase', isset($partner_row) ? $partner_row['organizer_id'] : '', $this->hasACL('training_organizer_option_all') ? 'training/insert-table' : false, $this->view->viewonly, $this->view->viewonly ? false : $allowIds));
     // form submit?
     if ($request->isPost()) {
         $obj = new TrainingPartner();
         if ($this->view->mode == 'add') {
             $obj_id = $this->validateAndSave($obj->createRow(), false);
         } else {
             $partnerRow = $obj->fetchRow('id = ' . $id);
             $obj_id = $this->validateAndSave($partnerRow, false);
         }
         if ($obj_id) {
             // success
             $status->setObjectId($obj_id);
             $id = $obj_id;
             $status->setStatusMessage(t('The partner was saved.'));
             if ($this->view->mode == 'add') {
                 $status->redirect = Settings::$COUNTRY_BASE_URL . '/training-partner/edit/id/' . $id;
             }
             if (!$validateOnly || $this->view->mode == 'add') {
                 // refreshing also
                 $_SESSION['status'] = t('The partner was saved.');
             }
         }
         if (!$obj_id) {
             // fail
             $status->setStatusMessage(t('ERROR: The partner could not be saved.'));
         }
         if ($validateOnly) {
             $this->sendData($status);
         } else {
             $this->view->assign('status', $status);
             $this->_redirect('training-partner/edit/id/' . $id);
         }
     }
 }
Пример #5
0
 public function after_all($results)
 {
     echo Util::br();
     parent::after_all($results);
 }
 public function searchAction()
 {
     if (!$this->hasACL('edit_employee')) {
         $this->doNoAccessError();
     }
     $criteria = $this->getAllParams();
     if ($criteria['go']) {
         // process search
         $where = array();
         list($a, $location_tier, $location_id) = $this->getLocationCriteriaValues($criteria);
         list($locationFlds, $locationsubquery) = Location::subquery($this->setting('num_location_tiers'), $location_tier, $location_id);
         $sql = "SELECT DISTINCT\r\n\t\t\t\t\tpartner.id,partner.partner,partner.location_id," . implode(',', $locationFlds) . "\r\n\t\t\t\t\t,GROUP_CONCAT(funderopt.funder_phrase) as funder\r\n\t\t\t\t\t,GROUP_CONCAT(funders.funder_end_date) as funding_end_date\r\n\t\t\t\t\t,GROUP_CONCAT(subp.partner) as subpartners\r\n\t\t\t\t\tFROM partner LEFT JOIN ({$locationsubquery}) as l  ON l.id = partner.location_id\r\n\t\t\t\t\tLEFT JOIN partner_to_funder funders         ON partner.id = funders.partner_id\r\n\t\t\t\t\tLEFT JOIN partner_funder_option funderopt   ON funders.partner_funder_option_id = funderopt.id\r\n\t\t\t\t\tLEFT JOIN partner_to_subpartner subpartners ON subpartners.partner_id = partner.id\r\n\t\t\t\t\tLEFT JOIN partner subp                      ON subp.id = subpartners.subpartner_id ";
         // restricted access?? only show partners by organizers that we have the ACL to view
         #$org_allowed_ids = allowed_org_access_full_list($this); // doesnt have acl 'training_organizer_option_all'
         #if($org_allowed_ids)
         #	$where[] = " partner.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[] = " partner.organizer_option_id in ($site_orgs) ";
         $locationWhere = $this->getLocationCriteriaWhereClause($criteria, '', '');
         if ($locationWhere) {
             $where[] = $locationWhere;
         }
         if ($criteria['subpartner_id']) {
             $where[] = 'subpartners.subpartner_id = ' . $criteria['subpartner_id'];
         }
         if ($criteria['partner_id']) {
             $where[] = 'partner.id = ' . $criteria['partner_id'];
         }
         if ($criteria['start_date']) {
             $where[] = 'funder_end_date >= \'' . $this->_date_to_sql($criteria['start_date']) . ' 00:00:00\'';
         }
         if ($criteria['end_date']) {
             $where[] = 'funder_end_date <= \'' . $this->_date_to_sql($criteria['end_date']) . ' 23:59:59\'';
         }
         if (count($where)) {
             $sql .= ' WHERE ' . implode(' AND ', $where);
         }
         $sql .= ' GROUP BY partner.id ';
         $db = $this->dbfunc();
         $rows = $db->fetchAll($sql);
         $this->viewAssignEscaped('results', $rows);
         $this->view->assign('count', count($rows));
     }
     // assign form drop downs
     $this->view->assign('status', $status);
     $this->viewAssignEscaped('criteria', $criteria);
     $this->viewAssignEscaped('locations', Location::getAll());
     $this->view->assign('partners', DropDown::generateHtml('partner', 'partner', $criteria['partner_id'], false, $this->view->viewonly, false));
     $this->view->assign('subpartners', DropDown::generateHtml('partner', 'partner', $criteria['subpartner_id'], false, $this->view->viewonly, false, true, array('name' => 'subpartner_id'), true));
 }
Пример #7
0
<?php

include_once '../common/headers.php';
echo '<a href="createDirection.php">Insert directions for routes</a><br /><br />';
echo '<a href="view.php">View existing routes and directions</a><br />';
exit;
print 'Select route:<br/>';
$route = new Route('12');
$route->long_name = 'Conestoga Mall/Fairview Mall';
$route->short_name = '12';
//$route->WriteToDatabase();
$Routes = Route::GetAllRoutes();
$dd = new DropDown('routeID', $Routes);
$dd->Write();
$ddsp = new DropDown('servicePeriod', ServicePeriod::GetAllServicePeriods());
$ddsp->Write();
echo '<pre>';
print Route::WriteGTFSHeader();
foreach ($Routes as $route) {
    print $route->WriteToGTFS();
}
print '<br/><br/><br/>Query count: ' . $Database->GetQueryCount();
Пример #8
0
 public static function dropdown($name, $source, $default = null, array $attributes = array())
 {
     $control = new DropDown($name, $source, $default, $attributes);
     $control->setEscaper(self::$escaper);
     echo $control->render();
 }
 private function doAddEditView()
 {
     if (!$this->hasACL('edit_course')) {
         $this->view->assign('viewonly', 'disabled="disabled"');
         $this->view->assign('pageTitle', t('View') . ' ' . t('Training'));
     }
     // edittable ajax (remove/update/etc)
     if ($this->_getParam('edittable')) {
         $this->ajaxeditTable();
         return;
     }
     require_once 'models/table/MultiOptionList.php';
     require_once 'models/table/TrainingLocation.php';
     require_once 'models/table/Location.php';
     require_once 'models/table/System.php';
     require_once 'views/helpers/EditTableHelper.php';
     require_once 'views/helpers/DropDown.php';
     require_once 'views/helpers/FileUpload.php';
     // allow multiple pepfars?
     if (!$this->setting('allow_multi_pepfar')) {
         $this->NUM_PEPFAR = 1;
     }
     // get translation labels
     // $this->view->assign('labels', Translation::getAll());
     //validate
     $status = ValidationContainer::instance();
     $request = $this->getRequest();
     $validateOnly = $request->isXmlHttpRequest();
     $training_id = $this->getSanParam('id');
     $is_new = $this->getSanParam('new') || !$training_id;
     // new training -- use defaults
     $this->view->assign('is_new', $is_new);
     $trainingObj = new Training();
     $row = $trainingObj->findOrCreate($training_id);
     $rowRay = @$row->toArray();
     //filter training orgs by user access
     $allowIds = false;
     if (!$this->hasACL('training_organizer_option_all')) {
         $allowIds = array();
         $user_id = $this->isLoggedIn();
         $training_organizer_array = MultiOptionList::choicesList('user_to_organizer_access', 'user_id', $user_id, 'training_organizer_option', 'training_organizer_phrase', false, false);
         foreach ($training_organizer_array as $orgOption) {
             if ($orgOption['user_id']) {
                 $allowIds[] = $orgOption['id'];
             }
         }
     }
     if ($this->_getParam('action') != 'add' and !$this->hasACL('training_organizer_option_all') and (!$allowIds or array_search($rowRay['training_organizer_option_id'], $allowIds) === false)) {
         $this->view->assign('viewonly', 'disabled="disabled"');
         $this->view->assign('pageTitle', t('View') . ' ' . t('Training'));
     }
     if ($row->is_deleted) {
         $this->_redirect('training/deleted');
         return;
     }
     $courseRow = $trainingObj->getCourseInfo($training_id);
     $rowRay['training_title'] = $courseRow ? $courseRow->training_title_phrase : '';
     $rowRay['training_title_option_id'] = $courseRow ? $courseRow->training_title_option_id : 0;
     // does not exist
     if (!$row->id && $this->_getParam('action') != 'add') {
         $this->_redirect('training/index');
     }
     if ($validateOnly) {
         $this->setNoRenderer();
     }
     $age_opts = OptionList::suggestionList('age_range_option', array('id', 'age_range_phrase'), false, 100, false);
     if ($request->isPost() && !$this->getSanParam('edittabledelete')) {
         //$status->checkRequired($this, 'training_title_option_id',t('Training Name'));
         //$status->checkRequired($this, 'training_category_and_title_option_id',t('Training Name'));
         $status->checkRequired($this, 'training_length_value', t('Training') . ' ' . t('Length'));
         $status->checkRequired($this, 'training_length_interval', t('Training') . ' ' . t('Interval'));
         //$status->checkRequired($this, 'training_organizer_option_id',t('Training Organizer'));
         //$status->checkRequired($this, 'training_level_option_id',t('Training Level'));
         //$status->checkRequired($this, 'training_location_id',t('Training Location'));
         //$status->checkRequired($this, 'training_topic_option_id','Training Topic');
         // May be "0" value
         if (!$this->getSanParam('training_length_value')) {
             $status->addError('training_length_value', t('Training length is required.'));
         }
         // validate score averages values
         if ($score = trim($this->getSanParam('pre'))) {
             if (!is_numeric($score)) {
                 $status->addError('pre', $this->view->translation['Pre Test Score'] . ' ' . t('must be numeric.'));
             } elseif ($score < 0 || $score > 100) {
                 $status->addError('pre', $this->view->translation['Pre Test Score'] . ' ' . t('must be between 1-100.'));
             }
         }
         if ($score = trim($this->getSanParam('post'))) {
             if (!is_numeric($score)) {
                 $status->addError('post', $this->view->translation['Post Test Score'] . ' ' . t('must be numeric.'));
             } elseif ($score < 0 || $score > 100) {
                 $status->addError('post', $this->view->translation['Post Test Score'] . ' ' . t('must be between 1-100.'));
             }
         }
         if ($this->getSanParam('start-year') == "" || $this->getSanParam('start-month') == "" || $this->getSanParam('start-day') == "") {
             $status->addError('start-day', t('Start date is required.'));
         }
         $training_start_date = @$this->getSanParam('start-year') . '-' . @$this->getSanParam('start-month') . '-' . @$this->getSanParam('start-day');
         if ($training_start_date !== '--' and $training_start_date !== '0000-00-00') {
             $status->isValidDate($this, 'start-day', t('Training') . ' ' . t('start'), $training_start_date);
         }
         if ($this->setting('display_end_date')) {
             $training_end_date = @$this->getSanParam('end-year') . '-' . @$this->getSanParam('end-month') . '-' . @$this->getSanParam('end-day');
             if ($training_end_date !== '--' and $training_end_date !== '0000-00-00') {
                 $status->isValidDate($this, 'end-day', t('Training') . ' ' . t('end'), $training_end_date);
             }
             if ($training_end_date != '--') {
                 if (strtotime($training_end_date) < strtotime($training_start_date)) {
                     $status->addError('end-day', t('End date must be after start date.'));
                 }
             }
         }
         $pepfarEnabled = @$this->setting('display_training_pepfar');
         if ($training_id) {
             $pepfarCount = 0;
             $pepfar_array = $this->getSanParam('training_pepfar_categories_option_id');
             if ($pepfar_array) {
                 foreach ($pepfar_array as $p) {
                     if ($p) {
                         $pepfarCount++;
                     }
                 }
             }
             //          if (!$pepfarCount) {
             //            $status->addError('training_pepfar_categories_option',t('PEPFAR is required.'));
             //         }
             // pepfar (multiple days)
             if ($this->getSanParam('pepfar_days') && $pepfarEnabled) {
                 $pepfarTotal = 0;
                 foreach ($this->getSanParam('pepfar_days') as $key => $value) {
                     if (!is_numeric($value)) {
                         $value = ereg_replace("/^[.0-9]", "", $value);
                     }
                     //$daysRay [$pepfar_array[$key]] = $value; //set the days key to  the pepfar id
                     $daysRay[$key] = $value;
                     //set the days key to  the pepfar id
                     $pepfarTotal += $value;
                     if ($pepfarCount > 1 && !$value && $pepfarEnabled) {
                         $status->addError('training_pepfar_categories_option', t('Number of days is required.'));
                     }
                     if ($pepfarCount == $key + 1) {
                         break;
                     }
                 }
                 // calculate days
                 switch ($this->getSanParam('training_length_interval')) {
                     case 'week':
                         $days = $this->getSanParam('training_length_value') * 7;
                         break;
                     case 'day':
                         $days = $this->getSanParam('training_length_value');
                         // start day counts as a day?
                         break;
                     default:
                         $days = 0.5;
                         break;
                 }
                 // do days add up to match training length?
                 if ($days != $pepfarTotal && $pepfarCount > 1 && $pepfarEnabled) {
                     $status->addError('training_pepfar_categories_option', sprintf(t("Total") . ' ' . t('Training') . ' ' . t("length is %s, but PEPFAR category total is %d days. "), $days == 1 ? $days . ' ' . t('day') : $days . ' ' . t('days'), $pepfarTotal));
                 }
             }
             // custom fields
             if ($this->getSanParam('custom1_phrase')) {
                 $tableCustom = new ITechTable(array('name' => 'training_custom_1_option'));
                 $row->training_custom_1_option_id = $tableCustom->insertUnique('custom1_phrase', $this->getSanParam('custom1_phrase'), true);
             }
             if ($this->getSanParam('custom2_phrase')) {
                 $tableCustom = new ITechTable(array('name' => 'training_custom_2_option'));
                 $row->training_custom_2_option_id = $tableCustom->insertUnique('custom2_phrase', $this->getSanParam('custom2_phrase'), true);
             }
             $custom3 = $this->getSanParam('custom3_phrase');
             $row->custom_3 = $custom3 ? $custom3 : '';
             $custom4 = $this->getSanParam('custom4_phrase');
             $row->custom_4 = $custom4 ? $custom4 : '';
             // checkbox
             if (!$this->getSanParam('is_tot')) {
                 $row->is_tot = 0;
             }
             if (!$this->getSanParam('is_refresher')) {
                 $row->is_refresher = 0;
             }
             $training_refresher_option_id = $this->getSanParam('training_refresher_option_id');
             if (!empty($training_refresher_option_id)) {
                 $row->is_refresher = 1;
             }
         }
         if ($this->_getParam('action') == 'add' && $this->_countrySettings['module_unknown_participants_enabled'] && !$this->getSanParam('has_known_participants')) {
             $row->has_known_participants = 0;
         } else {
             if ($this->_getParam('action') == 'add') {
                 $row->has_known_participants = 1;
             }
         }
         //approve by default if the approvals modules is not enabled
         if ($this->_getParam('action') == 'add' && $this->_countrySettings['module_approvals_enabled'] && !$this->hasACL('approve_trainings')) {
             $row->is_approved = 0;
         } else {
             if ($this->_getParam('action') == 'add') {
                 $row->is_approved = 1;
             }
         }
         // delete training
         if ($this->getSanParam('specialAction') == 'delete') {
             $partys = PersonToTraining::getParticipants($training_id)->toArray();
             $tranys = TrainingToTrainer::getTrainers($training_id)->toArray();
             if (!$partys && !$tranys) {
                 $row->is_deleted = 1;
                 $trainingObj->delete('id = ' . $row->id);
             } else {
                 $status->setStatusMessage(t('This') . ' ' . t('Training') . ' ' . t('session could not be deleted. Some participants or trainers may still be attached.'));
             }
         }
         if ($status->hasError() && !$row->is_deleted) {
             $status->setStatusMessage(t('This') . ' ' . t('Training') . ' ' . t('session could not be saved.'));
         } else {
             $row = self::fillFromArray($row, $this->_getAllParams());
             // format: categoryid_titleid
             $ct_ids = $this->getSanParam('training_category_and_title_option_id');
             // remove category id and underscore (unless dynamic title insert, which is numeric)
             $training_title_option_id = !is_numeric($ct_ids) ? substr($ct_ids, strpos($ct_ids, '_') + 1) : $ct_ids;
             $row->training_title_option_id = $training_title_option_id;
             $row->training_start_date = @$this->getSanParam('start-year') . '-' . @$this->getSanParam('start-month') . '-' . @$this->getSanParam('start-day');
             if ($this->setting('display_end_date')) {
                 $row->training_end_date = @$this->getSanParam('end-year') . '-' . @$this->getSanParam('end-month') . '-' . @$this->getSanParam('end-day');
             }
             // cannot be null ... set defaults
             if (!$row->comments) {
                 $row->comments = '';
             }
             if (!$row->got_comments) {
                 $row->got_comments = '';
             }
             if (!$row->objectives) {
                 $row->objectives = '';
             }
             if (!$row->is_tot) {
                 $row->is_tot = 0;
             }
             if (!$row->is_refresher) {
                 $row->is_refresher = 0;
             }
             // update related tables
             if ($training_id) {
                 // funding
                 $amount_extra_col = '';
                 $amount_extra_vals = array();
                 $amount_extra_col = 'funding_amount';
                 if ($this->getSanParam('funding_id')) {
                     foreach ($this->getSanParam('funding_id') as $funding_id) {
                         $amount_extra_vals[] = $this->getSanParam('funding_id_amount_' . $funding_id);
                     }
                 }
                 MultiOptionList::updateOptions('training_to_training_funding_option', 'training_funding_option', 'training_id', $training_id, 'training_funding_option_id', $this->getSanParam('funding_id'), $amount_extra_col, $amount_extra_vals);
                 // pepfar
                 if ($pepfarEnabled) {
                     MultiOptionList::updateOptions('training_to_training_pepfar_categories_option', 'training_pepfar_categories_option', 'training_id', $training_id, 'training_pepfar_categories_option_id', $this->getSanParam('training_pepfar_categories_option_id'), 'duration_days', isset($daysRay) ? $daysRay : false);
                 }
                 // method
                 if ($this->setting('display_training_method')) {
                     $row->training_method_option_id = $this->getSanParam('training_method_option_id');
                 }
                 // topics
                 if (!$this->setting('allow_multi_topic')) {
                     // drop-down -- set up faux checkbox array (since table schema uses multiple choices)
                     $_GET['topic_id'][] = $this->getSanParam('training_topic_option_id');
                 }
                 MultiOptionList::updateOptions('training_to_training_topic_option', 'training_topic_option', 'training_id', $training_id, 'training_topic_option_id', $this->getSanParam('topic_id'));
                 // refresher course (if dropdownlist)
                 if ($this->setting('multi_opt_refresher_course')) {
                     MultiOptionList::updateOptions('training_to_training_refresher_option', 'training_refresher_option', 'training_id', $training_id, 'training_refresher_option_id', $this->getSanParam('training_refresher_option_id'));
                 }
                 //Qualifications for unknown participants
                 if (!$row->has_known_participants) {
                     //check for duplicates
                     ///oooh, compound key = qual + age
                     //DELETE EVERYTHING FOR THIS TRAINING
                     //START OVER
                     $quals = $this->getSanParam('person_qualification_option_id');
                     $quantities_na = $this->getSanParam('qualification_quantity_na');
                     $quantities_male = $this->getSanParam('qualification_quantity_male');
                     $quantities_female = $this->getSanParam('qualification_quantity_female');
                     $age_ranges = $this->getSanParam('age_range_option_id');
                     $qualPlusAgeArray = array();
                     //make array of qualifications + age range
                     $qualRows = OptionList::suggestionListHierarchical('person_qualification_option', 'qualification_phrase', false, false);
                     foreach ($qualRows as $qRow) {
                         foreach (array_keys($age_opts) as $age_opt) {
                             $qualPlusAgeArray[$qRow['id']][$age_opt] = array('na' => 0, 'male' => 0, 'female' => 0);
                         }
                     }
                     foreach ($quals as $ix => $item) {
                         if ($item) {
                             $qualPlusAgeArray[$quals[$ix]][$age_ranges[$ix]]['na'] = $qualPlusAgeArray[$quals[$ix]][$age_ranges[$ix]]['na'] + $quantities_na[$ix];
                             $qualPlusAgeArray[$quals[$ix]][$age_ranges[$ix]]['male'] = $qualPlusAgeArray[$quals[$ix]][$age_ranges[$ix]]['male'] + $quantities_male[$ix];
                             $qualPlusAgeArray[$quals[$ix]][$age_ranges[$ix]]['female'] = $qualPlusAgeArray[$quals[$ix]][$age_ranges[$ix]]['female'] + $quantities_female[$ix];
                         }
                     }
                     $deleteTable = new ITechTable(array('name' => 'training_to_person_qualification_option'));
                     $deleteTable->delete('training_id = ' . $training_id, true);
                     foreach ($qualPlusAgeArray as $qkey => $ageRay) {
                         foreach ($ageRay as $akey => $counts) {
                             if ($counts['na'] || $counts['male'] || $counts['female']) {
                                 MultiOptionList::insertOption('training_to_person_qualification_option', 'training_id', $training_id, 'person_qualification_option_id', $qkey, array('age_range_option_id', 'person_count_na', 'person_count_male', 'person_count_female'), array('age_range_option_id' => $akey, 'person_count_na' => $counts['na'], 'person_count_male' => $counts['male'], 'person_count_female' => $counts['female']));
                             }
                         }
                     }
                 }
             }
             //mark approval status
             $do_save_approval_history = false;
             if ($this->setting('module_approvals_enabled')) {
                 if ($this->getSanParam('approval_status') == 'approved') {
                     $row->is_approved = 1;
                     if ($this->setting('allow_multi_approvers') && !$this->hasACL('master_approver')) {
                         $row->is_approved = 2;
                         // approved, but not approved by master approver, only that user can make this a 1 and have it display aproved!
                     }
                     $rowRay['is_approved'] = 1;
                     $do_save_approval_history = true;
                 } else {
                     if ($this->getSanParam('approval_status') == 'rejected') {
                         $row->is_approved = 0;
                         $rowRay['is_approved'] = 0;
                         if ($this->setting('allow_multi_approvers') && !$this->hasACL('master_approver')) {
                             $row->is_approved = 1;
                             // approved, but not approved by master approver, only that user can make this a 1 and have it display aproved!
                             $rowRay['is_approved'] = 1;
                         }
                         $do_save_approval_history = true;
                     }
                 }
                 if ($this->_getParam('action') == 'add' or !$this->hasACL('approve_trainings')) {
                     $do_save_approval_history = true;
                 }
             }
             if ($this->_getParam('action') == 'add') {
                 $do_save_approval_history = true;
             }
             $row->training_refresher_option_id = 0;
             // refresher / bugfix - this col isnt used anymore
             if ($row->save()) {
                 //save approval history
                 if ($this->getSanParam('approval_comments') || $do_save_approval_history) {
                     require_once 'models/table/TrainingApprovalHistory.php';
                     $history_table = new TrainingApprovalHistory();
                     $approval_status = $this->_countrySettings['module_approvals_enabled'] ? $this->getSanParam('approval_status') : 'approved';
                     if (!$this->hasACL('approve_trainings')) {
                         $approval_status = 'resubmitted';
                     }
                     $history_data = array('training_id' => $row->id, 'approval_status' => $approval_status, 'message' => $this->getSanParam('approval_comments'));
                     $history_table->insert($history_data);
                 }
                 // redirects
                 if ($this->_getParam('action') == 'add') {
                     $status->redirect = Settings::$COUNTRY_BASE_URL . '/training/edit/id/' . $row->id . '/new/1';
                 }
                 if ($this->_getParam('redirectUrl')) {
                     $status->redirect = $this->_getParam('redirectUrl');
                 }
                 // duplicate training
                 if ($this->getSanParam('specialAction') == 'duplicate') {
                     if ($this->hasACL('duplicate_training')) {
                         $dupId = $trainingObj->duplicateTraining($row->id);
                         $status->redirect = Settings::$COUNTRY_BASE_URL . '/training/edit/id/' . $dupId . '/msg/duplicate';
                     }
                 }
                 if (!$status->redirect) {
                     $status->setStatusMessage(t('This') . ' ' . t('Training') . ' ' . t('session has been saved.'));
                 }
             } else {
                 error_log("Couldn't save training {$training_id}");
             }
         }
         if ($validateOnly) {
             $this->sendData($status);
         } else {
             $this->view->assign('status', $status);
         }
     }
     //
     // Init view
     //
     $this->view->assign('custom3_phrase', $row->custom_3);
     $this->view->assign('custom4_phrase', $row->custom_4);
     //split start date fields
     if (!$row->training_start_date) {
         $row->training_start_date = '--';
     }
     // empty
     $parts = explode(' ', $row->training_start_date);
     $parts = explode('-', $parts[0]);
     $rowRay['start-year'] = $parts[0];
     $rowRay['start-month'] = $parts[1];
     $rowRay['start-day'] = $parts[2];
     //split end date fields
     if (!$row->training_end_date) {
         $row->training_end_date = '--';
     }
     // empty
     $parts = explode(' ', $row->training_end_date);
     $parts = explode('-', $parts[0]);
     $rowRay['end-year'] = $parts[0];
     $rowRay['end-month'] = $parts[1];
     $rowRay['end-day'] = $parts[2];
     // Drop downs
     //$this->view->assign('dropDownTitle', DropDown::generateHtml('training_title_option','training_title_phrase',$rowRay['training_title_option_id'],($this->hasACL('training_title_option_all')?'training/insert-table':false), $this->view->viewonly,false));
     $this->view->assign('dropDownOrg', DropDown::generateHtml('training_organizer_option', 'training_organizer_phrase', $rowRay['training_organizer_option_id'], $this->hasACL('training_organizer_option_all') ? 'training/insert-table' : false, $this->view->viewonly, $this->view->viewonly ? false : $allowIds));
     $this->view->assign('dropDownLevel', DropDown::generateHtml('training_level_option', 'training_level_phrase', $rowRay['training_level_option_id'], 'training/insert-table', $this->view->viewonly));
     $this->view->assign('dropDownGotCir', DropDown::generateHtml('training_got_curriculum_option', 'training_got_curriculum_phrase', $rowRay['training_got_curriculum_option_id'], 'training/insert-table', $this->view->viewonly));
     $this->view->assign('dropDownMethod', DropDown::generateHtml('training_method_option', 'training_method_phrase', $rowRay['training_method_option_id'], 'training/insert-table', $this->view->viewonly));
     $this->view->assign('dropDownPrimaryLanguage', DropDown::generateHtml('trainer_language_option', 'language_phrase', $rowRay['training_primary_language_option_id'], false, $this->view->viewonly, false, false, array('name' => 'training_primary_language_option_id')));
     $this->view->assign('dropDownSecondaryLanguage', DropDown::generateHtml('trainer_language_option', 'language_phrase', $rowRay['training_secondary_language_option_id'], false, $this->view->viewonly, false, false, array('name' => 'training_secondary_language_option_id')));
     //$catTitleArray = OptionList::suggestionList('location_district',array('district_name','parent_province_id'),false,false);
     $this->view->assign('age_options', $age_opts);
     // training categories & 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);
     // add title link
     if ($this->hasACL('training_title_option_all')) {
         $this->view->assign('titleInsertLink', " <a href=\"#\" onclick=\"addToSelect('" . str_replace("'", "\\" . "'", t('Please enter your new')) . " " . strtolower($this->view->translation['Training'] . t('Name')) . ":', 'select_training_title_option', '" . Settings::$COUNTRY_BASE_URL . "/training/insert-table/table/training_title_option/column/training_title_phrase/outputType/json'); return false;\">" . t('Insert new') . "</a>");
     }
     //get assigned evaluation
     $ev_id = null;
     $ev_to_t_id = null;
     if ($training_id) {
         $evtableObj = new ITechTable(array('name' => 'evaluation_to_training'));
         $evRow = $evtableObj->fetchRow($evtableObj->select(array('id', 'evaluation_id'))->where('training_id = ' . $training_id));
         if ($evRow) {
             $ev_id = $evRow->evaluation_id;
             $ev_to_t_id = $evRow->id;
         }
         $this->view->assign('evaluation_id', $ev_id);
         $this->view->assign('evaluation_to_training_id', $ev_to_t_id);
     }
     //Qualifications for unknown participants
     if (!$row->has_known_participants) {
         //count primary qualifications.
         //add a dropdown for each
         $tableObj = new ITechTable(array('name' => 'person_qualification_option'));
         $qualRows = OptionList::suggestionListHierarchical('person_qualification_option', 'qualification_phrase', false, false);
         //get values for this training
         $selectedObj = new ITechTable(array('name' => 'training_to_person_qualification_option'));
         $selectedRows = null;
         if ($training_id) {
             $selectedRows = $selectedObj->fetchAll($selectedObj->select(array('person_qualification_option_id', 'id', 'person_count_na', 'person_count_male', 'person_count_female', 'age_range_option_id'))->where('training_id = ' . $training_id));
             $unknownQualDropDowns = array();
             $qual_row_count = 0;
             foreach ($selectedRows as $selectedRow) {
                 $selector = array();
                 $selector['select'] = $this->_generate_hierarchical('select_person_qualification_option_' . $qual_row_count, $qualRows, 'qualification_phrase', $selectedRow->person_qualification_option_id);
                 $selector['age_range_option_id'] = $selectedRow->age_range_option_id;
                 $selector['quantity_na'] = $selectedRow->person_count_na;
                 $selector['quantity_male'] = $selectedRow->person_count_male;
                 $selector['quantity_female'] = $selectedRow->person_count_female;
                 $unknownQualDropDowns[] = $selector;
                 $qual_row_count++;
             }
             $max_rows = count($qualRows) * 3;
             //should be about 30
             for ($i = $selectedRows->count(); $i < $max_rows; $i++) {
                 $selector = array();
                 $selector['select'] = $this->_generate_hierarchical('select_person_qualification_option_' . $qual_row_count, $qualRows, 'qualification_phrase', -1);
                 $selector['age_range_option_id'] = 1;
                 $selector['quantity_na'] = 0;
                 $selector['quantity_male'] = 0;
                 $selector['quantity_female'] = 0;
                 $unknownQualDropDowns[] = $selector;
                 $qual_row_count++;
             }
             $this->view->assign('unknownQualDropDowns', $unknownQualDropDowns);
         }
     }
     // find category based on title
     $catId = 0;
     if ($courseRow && $courseRow->training_title_option_id) {
         foreach ($categoryTitle as $r) {
             if ($r['id'] == $courseRow->training_title_option_id && $r['training_category_option_id'] != 0) {
                 $catId = $r['training_category_option_id'];
                 break;
             }
         }
     }
     $this->view->assign('dropDownCategory', DropDown::generateHtml('training_category_option', 'training_category_phrase', $catId, false, $this->view->viewonly, false));
     //echo '<pre>';
     //print_r($catTitleArray); exit;
     //      $this->view->assign('dropDownProvince', DropDown::generateHtml('location_province','province_name',false,false,$this->view->viewonly));
     //      $this->view->assign('dropDownDistrict', DropDown::generateHtml('location_district','district_name',false,false,$this->view->viewonly));
     $this->viewAssignEscaped('locations', Location::getAll());
     // Topic drop-down
     if ($training_id) {
         if (!$this->setting('allow_multi_topic')) {
             $training_topic_id = $trainingObj->getTrainingSingleTopic($training_id);
             if ($is_new) {
                 $training_topic_id = false;
             }
             // use default
             $this->view->assign('dropDownTopic', DropDown::generateHtml('training_topic_option', 'training_topic_phrase', $training_topic_id, 'training/insert-table', $this->view->viewonly));
         } else {
             // topic checkboxes
             $topicArray = MultiOptionList::choicesList('training_to_training_topic_option', 'training_id', $training_id, 'training_topic_option', 'training_topic_phrase');
             $this->view->assign('topicArray', $topicArray);
             $this->view->assign('topicJsonUrl', Settings::$COUNTRY_BASE_URL . '/training/insert-table/table/training_topic_option/column/training_topic_phrase/outputType/json');
         }
     }
     if ($this->hasACL('acl_editor_training_topic')) {
         $this->view->assign("topicInsertLink", ' <a href="#" onclick="addCheckbox(\'' . t('Please enter the name your new topic item') . '\', \'topic_id\', \'topicContainer\', \'' . $this->view->topicJsonUrl . '\'); return false;">' . t('Insert New') . '</a>');
     }
     // get custom phrases (custom1_phrase, custom2_phrase)
     if ($training_id) {
         $rowRay = array_merge($rowRay, $trainingObj->getCustom($training_id)->toArray());
     }
     // location drop-down
     $tlocations = TrainingLocation::selectAllLocations($this->setting('num_location_tiers'));
     $this->viewAssignEscaped('tlocations', $tlocations);
     if ($this->hasACL('edit_facility')) {
         $this->view->assign("insertLocationLink", '<a href="#" onclick="return false;" id="show">' . t(str_replace(' ', '&nbsp;', t('Insert new'))) . '</a>');
     }
     // pepfar durations
     $pepfarEnabled = @$this->setting('display_training_pepfar');
     if ($training_id && $pepfarEnabled) {
         $pepfarArray = MultiOptionList::choicesList('training_to_training_pepfar_categories_option', 'training_id', $training_id, 'training_pepfar_categories_option', 'pepfar_category_phrase', 'duration_days');
         foreach ($pepfarArray as $item) {
             if (isset($item['training_id']) && $item['training_id']) {
                 $pepfars[] = array('id' => $item['id'], 'duration' => $item['duration_days']);
             }
         }
     }
     // pepfar
     $this->view->assign('NUM_PEPFAR', $this->NUM_PEPFAR);
     // number of Pepfar drop-downs to display
     for ($j = 0; $j < $this->NUM_PEPFAR; $j++) {
         $pepfarid = isset($pepfars[$j]['id']) ? $pepfars[$j]['id'] : '';
         if ($is_new) {
             $pepfarid = false;
         }
         // use default
         $pepfarHtml = DropDown::generateHtml('training_pepfar_categories_option', 'pepfar_category_phrase', $pepfarid, false, $this->view->viewonly, false, false, array(), $j == 0);
         $pepfarHtml = str_replace('training_pepfar_categories_option_id', 'training_pepfar_categories_option_id[]', $pepfarHtml);
         // use array
         $dropDownPepfars[] = $pepfarHtml;
         //$pepfarDurations[] = (isset($pepfars[$j]['duration']) && $pepfars[$j]['duration'] ? $pepfars[$j]['duration'] . ' day' . (($pepfars[$j]['duration'] <= 1) ? '' : 's') : '');
         $pepfarDurations[] = isset($pepfars[$j]['duration']) && $pepfars[$j]['duration'] ? $pepfars[$j]['duration'] : '';
     }
     $this->view->assign('dropDownPepfars', $dropDownPepfars);
     $this->view->assign('pepfarDurations', $pepfarDurations);
     // checkboxes
     $fundingArray = MultiOptionList::choicesList('training_to_training_funding_option', 'training_id', $training_id, 'training_funding_option', array('funding_phrase', 'is_default'));
     if ($training_id) {
         //lame to do another query, but it's easy
         $tableObj = new ITechTable(array('name' => 'training_to_training_funding_option'));
         $amountRows = $tableObj->fetchAll($tableObj->select(array('training_funding_option_id', 'id', 'funding_amount'))->where('training_id = ' . $training_id));
         foreach ($amountRows as $amt_row) {
             foreach ($fundingArray as $k => $funding_row) {
                 if ($funding_row['id'] == $amt_row->training_funding_option_id) {
                     $fundingArray[$k]['funding_amount'] = $amt_row->funding_amount;
                 }
             }
         }
     }
     $this->view->assign('fundingArray', $fundingArray);
     if ($this->hasACL('acl_editor_funding')) {
         $this->view->assign('fundingJsonUrl', Settings::$COUNTRY_BASE_URL . '/training/insert-table/table/training_funding_option/column/funding_phrase/outputType/json');
         $this->view->assign("fundingInsertLink", ' <a href="#" onclick="addCheckbox(\'' . t('Please enter the name your new funding item:') . '\', \'funding_id\', \'fundingContainer\', \'' . $this->view->fundingJsonUrl . '\'); return false;">' . t('Insert New') . '</a>');
     }
     // refresher (if multi)
     if ($training_id) {
         if ($this->setting('multi_opt_refresher_course')) {
             $training_refresher_id = $row->training_refresher_option_id;
             if ($is_new) {
                 $training_refresher_id = false;
             }
             // use default
             #$this->view->assign ( 'dropDownRefresher', DropDown::generateHtml ( 'training_refresher_option', 'refresher_phrase_option', $training_refresher_id, 'training/insert-table', $this->view->viewonly ) );
             $this->view->assign('refresherArray', MultiOptionList::choicesList('training_to_training_refresher_option', 'training_id', $training_id, 'training_refresher_option', 'refresher_phrase_option', false, false));
             if ($this->hasACL('acl_editor_refresher_course')) {
                 $this->view->assign('refresherJsonUrl', Settings::$COUNTRY_BASE_URL . '/training/insert-table/table/training_refresher_option/column/refresher_phrase_option/outputType/json');
                 $this->view->assign("refresherInsertLink", ' <a href="#" onclick="addCheckbox(\'' . t('Please enter the name your new refresher item') . '\', \'training_refresher_option_id\', \'refresherContainer\', \'' . $this->view->refresherJsonUrl . '\'); return false;">' . t('Insert New') . '</a>');
             }
         }
     }
     /****************************************************************************************************************
      * Trainers */
     if ($training_id) {
         $trainers = TrainingToTrainer::getTrainers($training_id)->toArray();
     } else {
         $trainers = array();
     }
     if (!$this->setting('display_middle_name')) {
         $trainerFields = array('first_name' => $this->tr('First Name'), 'last_name' => $this->tr('Last Name'));
         $colStatic = array('first_name', 'last_name');
     } else {
         if ($this->setting('display_middle_name_last')) {
             $trainerFields = array('first_name' => $this->tr('First Name'), 'last_name' => $this->tr('Last Name'), 'middle_name' => $this->tr('Middle Name'));
             $colStatic = array('first_name', 'last_name', 'middle_name');
         } else {
             $trainerFields = array('first_name' => $this->tr('First Name'), 'middle_name' => $this->tr('Middle Name'), 'last_name' => $this->tr('Last Name'));
             $colStatic = array('first_name', 'middle_name', 'last_name');
         }
     }
     if ($this->view->viewonly) {
         $editLinkInfo['disabled'] = 1;
         $linkInfo = array();
         $colStatic = array_keys($trainerFields);
     } else {
         $linkInfo = array('linkFields' => $colStatic, 'linkId' => 'trainer_id', 'linkUrl' => Settings::$COUNTRY_BASE_URL . '/person/edit/id/%trainer_id%');
         $linkInfo['linkUrl'] = "javascript:submitThenRedirect('{$linkInfo['linkUrl']}/trainingredirect/{$training_id}');";
         $editLinkInfo = array();
     }
     $html = EditTableHelper::generateHtmlTraining('Trainer', $trainers, $trainerFields, $colStatic, $linkInfo, $editLinkInfo);
     $this->view->assign('tableTrainers', $html);
     /****************************************************************************************************************
      * Participants */
     $locations = Location::getAll();
     $customColDefs = array();
     if ($training_id) {
         $persons = PersonToTraining::getParticipants($training_id)->toArray();
         foreach ($persons as $pid => $p) {
             $region_ids = Location::getCityInfo($p['location_id'], $this->setting('num_location_tiers'));
             // todo expensive call, getcityinfo loads all locations each time??
             $persons[$pid]['province_name'] = $region_ids[1] ? $locations[$region_ids['1']]['name'] : 'unknown';
             if ($region_ids[2]) {
                 $persons[$pid]['district_name'] = $locations[$region_ids[2]]['name'];
             } else {
                 $persons[$pid]['district_name'] = 'unknown';
             }
             if ($region_ids[3]) {
                 $persons[$pid]['region_c_name'] = $locations[$region_ids[3]]['name'];
             } else {
                 $persons[$pid]['region_c_name'] = 'unknown';
             }
             if ($region_ids[4]) {
                 $persons[$pid]['region_d_name'] = $locations[$region_ids[4]]['name'];
             } else {
                 $persons[$pid]['region_d_name'] = 'unknown';
             }
             if ($region_ids[5]) {
                 $persons[$pid]['region_e_name'] = $locations[$region_ids[5]]['name'];
             } else {
                 $persons[$pid]['region_e_name'] = 'unknown';
             }
             if ($region_ids[6]) {
                 $persons[$pid]['region_f_name'] = $locations[$region_ids[6]]['name'];
             } else {
                 $persons[$pid]['region_f_name'] = 'unknown';
             }
             if ($region_ids[7]) {
                 $persons[$pid]['region_g_name'] = $locations[$region_ids[7]]['name'];
             } else {
                 $persons[$pid]['region_g_name'] = 'unknown';
             }
             if ($region_ids[8]) {
                 $persons[$pid]['region_h_name'] = $locations[$region_ids[8]]['name'];
             } else {
                 $persons[$pid]['region_h_name'] = 'unknown';
             }
             if ($region_ids[9]) {
                 $persons[$pid]['region_i_name'] = $locations[$region_ids[9]]['name'];
             } else {
                 $persons[$pid]['region_i_name'] = 'unknown';
             }
         }
     } else {
         $persons = array();
     }
     if (!$this->setting('display_middle_name')) {
         $personsFields = array('first_name' => $this->tr('First Name'), 'last_name' => $this->tr('Last Name'), 'birthdate' => t('Date of Birth'), 'facility_name' => t('Facility'));
     } else {
         if ($this->setting('display_middle_name_last')) {
             $personsFields = array('first_name' => $this->tr('First Name'), 'last_name' => $this->tr('Last Name'), 'middle_name' => "..." . $this->tr('Middle Name'), 'birthdate' => t('Date of Birth'), 'facility_name' => t('Facility'));
         } else {
             $personsFields = array('first_name' => $this->tr('First Name'), 'middle_name' => "..." . $this->tr('Middle Name'), 'last_name' => $this->tr('Last Name'), 'birthdate' => t('Date of Birth'), 'facility_name' => t('Facility'));
         }
     }
     if ($this->setting('module_attendance_enabled')) {
         $personsFields['duration_days'] = $this->tr('Days Attended');
         $personsFields['award_phrase'] = $this->tr('Complete');
         $rowArray = OptionList::suggestionList('person_to_training_award_option', array('id', 'award_phrase'), false, 9999, false, false);
         $elements = array(0 => array('text' => ' ', 'value' => 0));
         foreach ($rowArray as $i => $tablerow) {
             $elements[$i + 1]['text'] = $tablerow['award_phrase'];
             $elements[$i + 1]['value'] = $tablerow['id'];
         }
         $elements = json_encode($elements);
         // yui data table will enjoy spending time with a json encoded array
         $customColDefs['award_phrase'] = "editor:'dropdown', editorOptions: {dropdownOptions: {$elements} }";
     }
     if ($this->setting('display_viewing_location')) {
         $personsFields['location_phrase'] = $this->tr('Viewing Location');
         $vLocDropDown = OptionList::suggestionList('person_to_training_viewing_loc_option', array('id', 'location_phrase'), false, 9999, false, false);
         $elements = array(0 => array('text' => '', 'value' => 0));
         foreach ($vLocDropDown as $i => $tablerow) {
             $elements[$i + 1]['text'] = $tablerow['location_phrase'];
             $elements[$i + 1]['value'] = $tablerow['id'];
         }
         $elements = json_encode($elements);
         $customColDefs['location_phrase'] = "editor:'dropdown', editorOptions: {dropdownOptions: {$elements} }";
     }
     if ($this->setting('display_budget_code')) {
         $personsFields['budget_code_phrase'] = $this->tr('Budget Code');
         $budgetDropDown = OptionList::suggestionList('person_to_training_budget_option', array('id', 'budget_code_phrase'), false, 9999, false, false);
         $elements = array(0 => array('text' => '', 'value' => 0));
         foreach ($budgetDropDown as $i => $tablerow) {
             $elements[$i + 1]['text'] = $tablerow['budget_code_phrase'];
             $elements[$i + 1]['value'] = $tablerow['id'];
         }
         $elements = json_encode($elements);
         $customColDefs['budget_code_phrase'] = "editor: 'dropdown' , editorOptions:{dropdownOptions: {$elements}} ";
     }
     if ($this->setting('display_region_i')) {
         $personsFields['region_i_name'] = $this->tr('Region I');
     } else {
         if ($this->setting('display_region_h')) {
             $personsFields['region_h_name'] = $this->tr('Region H');
         } else {
             if ($this->setting('display_region_g')) {
                 $personsFields['region_g_name'] = $this->tr('Region G');
             } else {
                 if ($this->setting('display_region_f')) {
                     $personsFields['region_f_name'] = $this->tr('Region F');
                 } else {
                     if ($this->setting('display_region_e')) {
                         $personsFields['region_e_name'] = $this->tr('Region E');
                     } else {
                         if ($this->setting('display_region_d')) {
                             $personsFields['region_d_name'] = $this->tr('Region D');
                         } else {
                             if ($this->setting('display_region_c')) {
                                 $personsFields['region_c_name'] = $this->tr('Region C (Local Region)');
                             } else {
                                 if ($this->setting('display_region_b')) {
                                     $personsFields['district_name'] = $this->tr('Region B (Health District)');
                                 } else {
                                     $personsFields['province_name'] = $this->tr('Region A (Province)');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $colStatic = array_keys($personsFields);
     // static calumns (From field keys)
     if ($this->setting('module_attendance_enabled') || $this->setting('display_viewing_location') || $this->setting('display_budget_code')) {
         foreach ($colStatic as $i => $v) {
             if ($v == 'duration_days' || $v == 'award_phrase' || $v == 'budget_code_phrase' || $v == 'location_phrase') {
                 unset($colStatic[$i]);
             }
         }
         // remove 1 so we can edit the field
     }
     if ($this->view->viewonly) {
         $editLinkInfo['disabled'] = 1;
         $linkInfo = array();
     } else {
         $linkInfo = array('linkFields' => $colStatic, 'linkId' => 'person_id', 'linkUrl' => Settings::$COUNTRY_BASE_URL . '/person/edit/id/%person_id%');
         $linkInfo['linkUrl'] = "javascript:submitThenRedirect('{$linkInfo['linkUrl']}/trainingredirect/{$training_id}');";
         $editLinkInfo = array();
         // add link next to "Remove"
         if ($this->setting('display_training_pre_test')) {
             $editLinkInfo[] = array('linkName' => t('Pre-Test'), 'linkId' => 'id', 'linkUrl' => "javascript:updateScore('Pre-Test', %id%, '" . Settings::$COUNTRY_BASE_URL . "/training/scores-update', '%score_pre%');");
             // do not translate label/key
         }
         if ($this->setting('display_training_post_test')) {
             $editLinkInfo[] = array('linkName' => t('Post-Test'), 'linkId' => 'id', 'linkUrl' => "javascript:updateScore('Post-Test', %id%, '" . Settings::$COUNTRY_BASE_URL . "/training/scores-update', '%score_post%');");
             // do not translate label/key
         }
         $editLinkInfo[] = array('linkName' => t('Scores'), 'linkId' => 'id', 'linkUrl' => "javascript:submitThenRedirect('" . Settings::$COUNTRY_BASE_URL . "/training/scores/ptt_id/%id%');");
         // old
         //'linkUrl' => Settings::$COUNTRY_BASE_URL."/training/scores/training/$training_id/person/%person_id%",
         //$editLinkInfo['linkUrl'] = "javascript:submitThenRedirect('{$editLinkInfo['linkUrl']}');";
     }
     $html = EditTableHelper::generateHtmlTraining('Persons', $persons, $personsFields, $colStatic, $linkInfo, $editLinkInfo, $customColDefs);
     $this->view->assign('tablePersons', $html);
     /****************************************************************************************************************/
     /* Attached Files */
     FileUpload::displayFiles($this, 'training', $row->id, !$this->view->viewonly);
     //$this->view->assign('files', 'x' . FileUpload::displayFiles($this, 'training', $row->id));
     // File upload form
     if (!$this->view->viewonly) {
         $this->view->assign('filesForm', FileUpload::displayUploadForm('training', $row->id, FileUpload::$FILETYPES));
     }
     /****************************************************************************************************************/
     /* Approval status */
     if ($this->setting('module_approvals_enabled')) {
         $canApprove = $this->hasACL('master_approver') && $row->is_approved == 2 || $this->hasACL('approve_trainings') && !$row->is_approved;
         $this->view->assign('can_approve', $canApprove);
         if ($canApprove) {
             $this->view->assign('approve_val', '');
         } else {
             $this->view->assign('approve_val', $row->is_approved);
         }
         // disable control
         if (!$canApprove or !$this->hasACL('approve_trainings')) {
             $this->view->assign('approve_disable_str', 'disabled');
         } else {
             $this->view->assign('approve_disable_str', '');
         }
     }
     /****************************************************************************************************************/
     /* Attached Files */
     // mode
     $this->view->assign('mode', $this->_getParam('action'));
     switch ($this->_getParam('msg')) {
         case 'duplicate':
             $this->view->assign('msg', t('Training') . ' ' . t('session has been duplicated.<br>You can edit the duplicate session below.'));
             break;
         default:
             break;
     }
     // edit variables
     if ($this->_getParam('action') != 'add') {
         //audit history
         $creatorObj = new User();
         $updaterObj = new User();
         $creatorrow = $creatorObj->findOrCreate($row->created_by);
         $rowRay['creator'] = $creatorrow->first_name . ' ' . $creatorrow->last_name;
         $updaterrow = $updaterObj->findOrCreate($row->modified_by);
         $rowRay['updater'] = $updaterrow->first_name . ' ' . $updaterrow->last_name;
     }
     if (empty($trainers) || empty($persons)) {
         $this->view->assign('isIncomplete', true);
     }
     // default start date?
     if ($this->getSanParam('start-date')) {
         $parts = explode('/', $this->getSanParam('start-date'));
         if (count($parts) == 3) {
             $rowRay['start-day'] = $parts[0];
             $rowRay['start-month'] = $parts[1];
             $rowRay['start-year'] = $parts[2];
         }
     }
     // row values
     $this->view->assign('row', $rowRay);
 }
 public function trainingAssignTitleAction()
 {
     require_once 'views/helpers/MultiAssign.php';
     $multiAssign = new multiAssign();
     $multiAssign->table = 'training_category_option_to_training_title_option';
     $multiAssign->option_table = 'training_title_option';
     $multiAssign->option_field = array('training_title_phrase' => 'Title');
     $multiAssign->parent_table = 'training_category_option';
     $multiAssign->parent_field = array('training_category_phrase' => 'Training Category');
     $output = $multiAssign->init($this);
     if (is_array($output)) {
         // json
         $this->sendData($output);
     } else {
         $this->view->assign('multiAssign', $output);
     }
     if ($this->getRequest()->isPost()) {
         // Redirect
         // redirect to next page
         if ($this->_getParam('redirect')) {
             header("Location: " . $this->_getParam('redirect'));
             exit;
         } else {
             if ($this->_getParam('saveonly')) {
                 $status = ValidationContainer::instance();
                 $status->setStatusMessage('Your assigned categories have been saved.');
             }
         }
     }
     return;
     $NUM_TOPICS = 20;
     $this->view->assign('NUM_TOPICS', $NUM_TOPICS);
     /* checkbox */
     $fieldSystem = 'display_training_recommend';
     if ($this->getRequest()->isPost() && !$this->_getParam("id")) {
         // Update db
         $this->putSetting($fieldSystem, $this->_getParam($fieldSystem));
     }
     $checkbox = array('name' => $fieldSystem, 'label' => 'Display recommended trainings per individual', 'value' => $this->getSetting($fieldSystem));
     $this->view->assign('checkbox', $checkbox);
     require_once 'models/table/TrainingRecommend.php';
     // Save POST
     if ($this->getRequest()->isPost()) {
         // Update db
         if (is_numeric($this->_getParam('person_qualification_option_id'))) {
             TrainingRecommend::saveRecommendations($this->_getParam('person_qualification_option_id'), $this->_getParam('training_topic_option_id'));
             // Remove current, then redirect to clean page
             if ($this->_getParam('edit') && $this->_getParam('edit') != $this->_getParam('person_qualification_option_id')) {
                 TrainingRecommend::saveRecommendations($this->_getParam('edit'), array());
                 header("Location: " . Settings::$COUNTRY_BASE_URL . '/admin/training-recommend');
                 exit;
             }
         }
         // redirect to next page
         if ($this->_getParam('redirect')) {
             header("Location: " . $this->_getParam('redirect'));
             exit;
         } else {
             if ($this->_getParam('saveonly')) {
                 $status = ValidationContainer::instance();
                 $status->setStatusMessage('Your recommended trainings have been saved.');
             }
         }
     }
     // Edting
     if ($this->_getParam('edit') || $this->_getParam('edit') === '0') {
         $qualId = $this->_getParam('edit');
         $topicId = array_fill(1, $NUM_TOPICS, '');
         $topics = TrainingRecommend::getRecommendations($this->_getParam('edit'));
         $pos = 0;
         foreach ($topics->ToArray() as $row) {
             $topicId[++$pos] = $row['training_topic_option_id'];
         }
     } else {
         // New
         $qualId = 0;
         $topicId = array_fill(1, $NUM_TOPICS, '');
     }
     // Delete
     if ($delete = $this->_getParam('delete')) {
         TrainingRecommend::saveRecommendations($this->_getParam('delete'), array());
     }
     require_once 'views/helpers/DropDown.php';
     require_once 'models/table/OptionList.php';
     //$allowIds = TrainingRecommend::getQualificationIds(); // primary qualifications only
     //$this->view->assign('dropDownQuals', DropDown::generateHtml('person_qualification_option','qualification_phrase',$qualId, false, false, $allowIds));
     $qualificationsArray = OptionList::suggestionListHierarchical('person_qualification_option', 'qualification_phrase', false, false);
     // remove children qualifications and unknown as an option
     foreach ($qualificationsArray as $k => $qualArray) {
         if ($qualArray['id'] || $qualArray['parent_phrase'] == 'unknown') {
             unset($qualificationsArray[$k]);
         }
     }
     $this->viewAssignEscaped('qualifications', $qualificationsArray);
     $this->viewAssignEscaped('qualId', $qualId);
     for ($j = 1; $j <= $NUM_TOPICS; $j++) {
         $this->view->assign('dropDownTopic' . $j, DropDown::generateHtml('training_topic_option', 'training_topic_phrase', $topicId[$j], false, false, false, true));
     }
 }
Пример #11
0
 }
 $header = createHeader(array_keys($res[0]));
 $row = "";
 $table = "";
 foreach ($res as $result) {
     $keys = array_keys($result);
     $formElements = "";
     foreach ($keys as $key) {
         if ($key === "id") {
             $input = PartialParser::Parse('hidden', ["name" => "id[]", "value" => $result['id']]) . $result['id'];
         } else {
             if ($key === "email") {
                 $input = PartialParser::Parse('text', ["name" => "email" . $result['id'], "value" => $result[$key], "size" => 15]);
             } else {
                 if ($key === "pLevel") {
                     $dropdown = new DropDown("userlevel" . $result['id'], $userLevels, array_search($result[$key], $userLevels));
                     $input = $dropdown->Html();
                 } else {
                     if ($key === "activated") {
                         $checked = $result[$key];
                         $values = [["Yes", "1"], ["No", "0"]];
                         $radio = new RadioGroup($key . $result['id'], $checked, $values);
                         $input = $radio->Html();
                     } else {
                         $input = $result[$key];
                     }
                 }
             }
         }
         $formElements .= PartialParser::Parse('table-cell', ["content" => $input]);
     }
 public function partnersAction()
 {
     require_once 'models/table/Helper.php';
     require_once 'views/helpers/FormHelper.php';
     require_once 'views/helpers/DropDown.php';
     require_once 'views/helpers/Location.php';
     require_once 'views/helpers/CheckBoxes.php';
     require_once 'views/helpers/TrainingViewHelper.php';
     $criteria = $this->getAllParams();
     if ($criteria['go']) {
         $where = array();
         $criteria['last_selected_rgn'] = regionFiltersGetLastID('', $criteria);
         list($a, $location_tier, $location_id) = $this->getLocationCriteriaValues($criteria);
         list($locationFlds, $locationsubquery) = Location::subquery($this->setting('num_location_tiers'), $location_tier, $location_id);
         $sql = "SELECT\r\n\t\t\t\t\tpartner.*,\r\n\t\t\t\t\tpartner.id,partner.partner,partner.location_id," . implode(',', $locationFlds) . "\r\n\t\t\t\t\t,GROUP_CONCAT(distinct facility.facility_name) as facilities\r\n\t\t\t\t\t,CASE WHEN annual_cost REGEXP '[^!0-9,\\.][0-9\\.,]+' THEN SUBSTRING(annual_cost, 2) ELSE annual_cost END AS 'annual_cost_to_compare'\r\n\t\t\t\t\t,COUNT(e.id) AS pcnt\r\n\t\t\t\t\tFROM partner LEFT JOIN ({$locationsubquery}) as l ON l.id = partner.location_id\r\n\t\t\t\t\tLEFT JOIN partner_to_funder funders ON partner.id = funders.partner_id\r\n\t\t\t\t\tLEFT JOIN partner_funder_option funderopt ON funders.partner_funder_option_id = funderopt.id\r\n\t\t\t\t\tLEFT JOIN partner_to_subpartner subpartners ON subpartners.partner_id = partner.id\r\n\t\t\t\t\tLEFT JOIN employee e on e.partner_id = partner.id\r\n\t\t\t\t\tLEFT JOIN facility ON e.site_id = facility.id\r\n\t\t\t\t\t";
         if ($criteria['facility_type_option_id']) {
             $sql .= " LEFT JOIN facility_type_option fto ON fto.id = facility.type_option_id ";
         }
         // restricted access?? only show partners by organizers that we have the ACL to view
         #$org_allowed_ids = allowed_org_access_full_list($this); // doesnt have acl 'training_organizer_option_all'
         #if ($org_allowed_ids)                             $where[] = "partner.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[] = "partner.organizer_option_id in ({$site_orgs})";
         }
         // criteria
         if ($criteria['partner_id']) {
             $where[] = 'partner.id = ' . $criteria['partner_id'];
         }
         if ($criteria['last_selected_rgn']) {
             $where[] = 'province_name is not null';
         }
         // bugfix - location subquery is not working like a inner join or where, not sure why
         if ($criteria['facilityInput']) {
             $where[] = 'facility.id = ' . $criteria['facilityInput'];
         }
         if ($criteria['facility_type_option_id']) {
             $where[] = 'facility.type_option_id = ' . $criteria['facility_type_option_id'];
         }
         if ($criteria['employee_qualification_option_id']) {
             $where[] = 'employee_qualification_option_id = ' . $criteria['employee_qualification_option_id'];
         }
         if ($criteria['employee_category_option_id']) {
             $where[] = 'employee_category_option_id = ' . $criteria['employee_category_option_id'];
         }
         if ($criteria['hours_min']) {
             $where[] = 'e.funded_hours_per_week >=' . $criteria['hours_min'];
         }
         if ($criteria['hours_max']) {
             $where[] = 'e.funded_hours_per_week <=' . $criteria['hours_min'];
         }
         if ($criteria['cost_min']) {
             $where[] = 'e.annual_cost_to_compare >=' . $criteria['cost_min'];
         }
         if ($criteria['cost_max']) {
             $where[] = 'e.annual_cost_to_compare <=' . $criteria['cost_max'];
         }
         if ($criteria['employee_role_option_id']) {
             $where[] = 'funder_end_date >= \'' . $this->_date_to_sql($criteria['start_date']) . ' 00:00:00\'';
         }
         if ($criteria['partner_importance_option_id']) {
             $where[] = 'partner_importance_option_id = ' . $criteria['partner_importance_option_id'];
         }
         if ($criteria['start_date']) {
             $where[] = 'funder_end_date >= \'' . $this->_date_to_sql($criteria['start_date']) . ' 00:00:00\'';
         }
         if ($criteria['end_date']) {
             $where[] = 'funder_end_date <= \'' . $this->_date_to_sql($criteria['end_date']) . ' 23:59:59\'';
         }
         if ($criteria['employee_transition_option_id']) {
             $where[] = 'employee_transition_option_id = ' . $criteria['employee_transition_option_id'];
         }
         if ($criteria['transition_confirmed']) {
             $where[] = 'transition_confirmed = 1';
         }
         if (count($where)) {
             $sql .= ' WHERE ' . implode(' AND ', $where);
         }
         $sql .= ' GROUP BY partner.id ';
         $db = $this->dbfunc();
         $rowArray = $db->fetchAll($sql);
         $this->viewAssignEscaped('results', $rowArray);
         $this->view->assign('count', count($rowArray));
         if ($criteria['outputType']) {
             $this->sendData($this->reportHeaders(false, $rowArray));
         }
     }
     // assign form drop downs
     $this->view->assign('status', $status);
     $this->view->assign('criteria', $criteria);
     $this->view->assign('pageTitle', t('Reports'));
     $this->viewAssignEscaped('locations', Location::getAll());
     $this->view->assign('partners', DropDown::generateHtml('partner', 'partner', $criteria['partner_id'], false, $this->view->viewonly, false));
     //table, col, selected_value
     $this->view->assign('subpartners', DropDown::generateHtml('partner', 'partner', $criteria['subpartner_id'], false, $this->view->viewonly, false, true, array('name' => 'subpartner_id'), true));
     $this->view->assign('importance', DropDown::generateHtml('partner_importance_option', 'importance_phrase', $criteria['partner_importance_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('transitions', DropDown::generateHtml('employee_transition_option', 'transition_phrase', $criteria['employee_transition_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('incomingPartners', DropDown::generateHtml('partner', 'partner', $criteria['incoming_partner'], false, $this->view->viewonly, false, true, array('name' => 'incoming_partner'), true));
     $helper = new Helper();
     $this->viewAssignEscaped('facilities', $helper->getFacilities());
     $this->view->assign('facilitytypes', DropDown::generateHtml('facility_type_option', 'facility_type_phrase', $criteria['facility_type_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('cadres', DropDown::qualificationsDropDown('employee_qualification_option_id', $criteria['employee_qualification_option_id']));
     $this->view->assign('categories', DropDown::generateHtml('employee_category_option', 'category_phrase', $criteria['employee_category_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('roles', DropDown::generateHtml('employee_role_option', 'role_phrase', $criteria['employee_role_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('transitions', DropDown::generateHtml('employee_transition_option', 'transition_phrase', $criteria['employee_transition_option_id'], false, $this->view->viewonly, false));
 }