/** * JSON request to insert a new value into an option table (used for dynamic drop-downs and adding a dynamic checkbox) */ public function insertTableAction() { $request = $this->getRequest(); if ($request->isXmlHttpRequest()) { $table = $this->getSanParam('table'); $column = $this->getSanParam('column'); $value = $this->getSanParam('value'); if ($table && $column && $value) { $tableObj = new ITechTable(array('name' => $table)); $undelete = $this->getSanParam('undelete'); if ($undelete) { try { $row = $tableObj->undelete($column, $value); $sendRay['insert'] = $row->id; $this->sendData($sendRay); } catch (Zend_Exception $e) { $this->sendData(array("insert" => 0, 'error' => $e->getMessage())); } } else { // Attempt to insert new try { $insert = $tableObj->insertUnique($column, $value); $sendRay['insert'] = "{$insert}"; if ($insert == -1) { $sendRay['error'] = '"%s" ' . t('already exists') . '.'; } if ($insert == -2) { $sendRay['error'] = '"%s" ' . 'already exists, but was deleted. Would you like to undelete?'; } // associate new training title with training category if ($table == 'training_title_option' && !isset($sendRay['error']) && ($cat_id = $this->getSanParam('cat_id'))) { $tableCatObj = new ITechTable(array('name' => 'training_category_option_to_training_title_option')); $tableCatObj->insert(array('training_category_option_id' => $cat_id, 'training_title_option_id' => $insert)); } $this->sendData($sendRay); } catch (Zend_Exception $e) { $this->sendData(array("insert" => 0, 'error' => $e->getMessage())); error_log($e); } } } } }
public function countryRegionAction() { require_once 'models/table/Location.php'; //CSV STUFF if (@$_FILES['import']['tmp_name']) { $filename = $_FILES['import']['tmp_name']; if ($filename) { $location_obj = new ITechTable(array('name' => 'location')); while ($row = $this->_csv_get_row($filename)) { if (is_array($row)) { //add province if (isset($row[0])) { $prov_id = $location_obj->insertUnique('location_name', $row[0], true, 'tier', 1); } //add city (basically offset all our if(display_region) by 1, because city does not have a display_city setting if (isset($row[1])) { $dist_id = $location_obj->insertUnique('location_name', $row[1], true, 'parent_id', $prov_id, 'tier', 2); } //add district if (isset($row[2]) && $this->setting('display_region_b')) { $dist_id = $location_obj->insertUnique('location_name', $row[2], true, 'parent_id', $dist_id, 'tier', 3); } //add region c if (isset($row[3]) && $this->setting('display_region_c')) { $dist_id = $location_obj->insertUnique('location_name', $row[3], true, 'parent_id', $dist_id, 'tier', 4); } if (isset($row[4]) && $this->setting('display_region_d')) { $dist_id = $location_obj->insertUnique('location_name', $row[4], true, 'parent_id', $dist_id, 'tier', 5); } if (isset($row[5]) && $this->setting('display_region_e')) { $dist_id = $location_obj->insertUnique('location_name', $row[5], true, 'parent_id', $dist_id, 'tier', 6); } if (isset($row[6]) && $this->setting('display_region_f')) { $dist_id = $location_obj->insertUnique('location_name', $row[6], true, 'parent_id', $dist_id, 'tier', 7); } if (isset($row[7]) && $this->setting('display_region_g')) { $dist_id = $location_obj->insertUnique('location_name', $row[7], true, 'parent_id', $dist_id, 'tier', 8); } if (isset($row[8]) && $this->setting('display_region_h')) { $dist_id = $location_obj->insertUnique('location_name', $row[8], true, 'parent_id', $dist_id, 'tier', 9); } if (isset($row[9]) && $this->setting('display_region_i')) { $dist_id = $location_obj->insertUnique('location_name', $row[9], true, 'parent_id', $dist_id, 'tier', 10); } } } if (isset($dist_id) || isset($prov_id)) { $_SESSION['status'] = t('Your changes have been saved.'); } } //kinda ugly, but $this->_setParam doesn't do it $_POST['redirect'] = null; } $location_id = $this->getSanParam('location'); $tier = $this->getSanParam('tier'); if (!$tier) { $tier = 1; } $this->view->assign('tier', $tier); if ($tier == 1) { $location_id = null; } $locations = Location::getAll(); $this->viewAssignEscaped('locations', $locations); //assign district and region filters $loc_parts = explode('_', $location_id); $location_id = $loc_parts[count($loc_parts) - 1]; //defaults if ($location_id) { // viewing a location/children if (count($loc_parts)) { $this->view->assign('province_id', $loc_parts[0]); $this->view->assign('district_id', $loc_parts[1]); $this->view->assign('region_c_id', $loc_parts[2]); $this->view->assign('region_d_id', $loc_parts[3]); $this->view->assign('region_e_id', $loc_parts[4]); $this->view->assign('region_f_id', $loc_parts[5]); $this->view->assign('region_g_id', $loc_parts[6]); $this->view->assign('region_h_id', $loc_parts[7]); $this->view->assign('region_i_id', $loc_parts[8]); $this->view->assign('city_id', $loc_parts[9]); } else { $loc_parts = null; } } // handy fields for translation... tr( $name[$tier] ) $name = array(''); // prepend 1 for readability, tiers start at 1 $flds = array(''); // always show // this form has to be dynamic becasue city tier is num_tiers - 1 $name[] = 'Region A (Province)'; $flds[] = 'province_id'; if ($this->setting('display_region_b')) { $name[] = 'Region B (Health District)'; $flds[] = 'district_id'; } if ($this->setting('display_region_c')) { $name[] = 'Region C (Local Region)'; $flds[] = 'region_c_id'; } if ($this->setting('display_region_d')) { $name[] = 'Region D'; $flds[] = 'region_d_id'; } if ($this->setting('display_region_e')) { $name[] = 'Region E'; $flds[] = 'region_e_id'; } if ($this->setting('display_region_f')) { $name[] = 'Region F'; $flds[] = 'region_f_id'; } if ($this->setting('display_region_g')) { $name[] = 'Region G'; $flds[] = 'region_g_id'; } if ($this->setting('display_region_h')) { $name[] = 'Region H'; $flds[] = 'region_h_id'; } if ($this->setting('display_region_i')) { $name[] = 'Region I'; $flds[] = 'region_i_id'; } $name[] = 'City or Town'; // always show $flds[] = 'city_id'; $flds[] = ''; // make the edit table if ($tier == 1 or $location_id && $locations[$location_id]['tier'] + 1 == $tier) { $editTable = new EditTableController($this); $editTable->table = 'location'; $editTable->fields = array('location_name' => $this->tr($name[$tier])); $editTable->label = $this->tr($name[$tier]); $editTable->dependencies = array('parent_id' => 'self', 'location_id' => 'training_location', 'home_location_id' => 'person', 'location_id' => 'facility'); $editTable->where = 'tier = ' . $tier . ($location_id ? ' AND parent_id = ' . $location_id : ' '); if ($location_id) { $editTable->insertExtra = array('parent_id' => $location_id, 'tier' => $tier); } else { $editTable->insertExtra = array('tier' => 1); } $editTable->allowDefault = true; $editTable->noEdit = false; $editTable->execute(); } }