/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $data = Input::all();
     $district = new District();
     $district->name = $data['name'];
     try {
         $district->save();
     } catch (ValidationException $errors) {
         return Redirect::route('admin.districts.create')->withErrors($errors->getErrors())->withInput();
     }
     return Redirect::route('admin.districts.create')->withErrors(array('mainSuccess' => 'Областта е добавена.'));
 }
Exemplo n.º 2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new District();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['District'])) {
         $model->attributes = $_POST['District'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 3
0
 /**
  * 录入
  *
  */
 public function actionCreate()
 {
     parent::_acl('district_create');
     $model = new District();
     if (isset($_POST['District'])) {
         $model->attributes = $_POST['District'];
         if ($model->save()) {
             AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入地区,ID:' . $model->id));
             $this->redirect(array('index'));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 4
0
 public function actionCreate()
 {
     $model = new District();
     if (isset($_POST['District'])) {
         $model->setAttributes($_POST['District']);
         if ($model->save()) {
             if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                 Yii::app()->end();
             } else {
                 $this->redirect(array('view', 'id' => $model->id));
             }
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function save()
 {
     $name = $this->input->post("name");
     $province = $this->input->post("province");
     $latitude = $this->input->post("latitude");
     $longitude = $this->input->post("longitude");
     $district_id = $this->input->post("district_id");
     //Check if we are in editing mode first; if so, retrieve the edited record. if not, create a new one!
     if (strlen($district_id) > 0) {
         $district = District::getDistrict($district_id);
         $district = $district[0];
     } else {
         $district = new District();
     }
     $district->Name = $name;
     $district->Province = $province;
     $district->Latitude = $latitude;
     $district->Longitude = $longitude;
     $district->save();
     redirect("district_management");
 }
Exemplo n.º 6
0
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     // create connection to import database
     $this->logSection('connection', 'creating connection to import source');
     $source = Propel::getConnection($options['source'] ? $options['source'] : null);
     // create static counties and offices
     $this->logSection('static', 'creating static counties and offices');
     $connection->beginTransaction();
     try {
         OfficePeer::doDeleteAll($connection);
         $o1 = new Office();
         $o1->setName('Plattsburgh');
         $o1->save($connection);
         $o1 = new Office();
         $o1->setName('Rouses Point');
         $o1->save($connection);
         CountyPeer::doDeleteAll($connection);
         $c1 = new County();
         $c1->setName('Clinton');
         $c1->save($connection);
         $c1 = new County();
         $c1->setName('Essex');
         $c1->save($connection);
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // read in and create objects for district, frequency, icd9, job, services tables
     // DISTRICT
     $query = 'SELECT * FROM %s';
     $query = sprintf($query, 'tbl_district');
     $statement = $source->prepare($query);
     $statement->execute();
     $districts = $statement->fetchAll();
     $connection->beginTransaction();
     try {
         DistrictPeer::doDeleteAll($connection);
         foreach ($districts as $district) {
             $this->logSection('district', 'creating district ' . $district['district_name']);
             $d1 = new District();
             $d1->setName($district['district_name']);
             $d1->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // FREQUENCY
     $query = 'SELECT * FROM %s';
     $query = sprintf($query, 'tbl_frequency');
     $statement = $source->prepare($query);
     $statement->execute();
     $frequencies = $statement->fetchAll();
     $connection->beginTransaction();
     try {
         FrequencyPeer::doDeleteAll($connection);
         foreach ($frequencies as $freq) {
             $this->logSection('freq', 'reading frequency ' . $freq['freq_title']);
             $f1 = new Frequency();
             $f1->setName($freq['freq_title']);
             $f1->setDescription($freq['freq_description']);
             $f1->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // ICD9
     $query = 'SELECT * FROM %s';
     $query = sprintf($query, 'tbl_icd9');
     $statement = $source->prepare($query);
     $statement->execute();
     $icd9s = $statement->fetchAll();
     $connection->beginTransaction();
     try {
         Icd9Peer::doDeleteAll($connection);
         foreach ($icd9s as $icd9) {
             $this->logSection('icd9', 'reading icd9 ' . $icd9['icd9_value']);
             $i1 = new Icd9();
             $i1->setName($icd9['icd9_value']);
             $i1->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // JOB
     $query = 'SELECT * FROM %s';
     $query = sprintf($query, 'tbl_job');
     $statement = $source->prepare($query);
     $statement->execute();
     $jobs = $statement->fetchAll();
     $connection->beginTransaction();
     try {
         JobPeer::doDeleteAll($connection);
         foreach ($jobs as $job) {
             $this->logSection('job', 'reading job ' . $job['job_title']);
             $j1 = new Job();
             $j1->setName($job['job_title']);
             $j1->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // SERVICES
     $query = 'SELECT * FROM %s';
     $query = sprintf($query, 'tbl_services');
     $statement = $source->prepare($query);
     $statement->execute();
     $services = $statement->fetchAll();
     $connection->beginTransaction();
     try {
         ServicePeer::doDeleteAll($connection);
         foreach ($services as $service) {
             $this->logSection('service', 'reading service ' . $service['service_title']);
             $s1 = new Service();
             $s1->setName($service['service_title']);
             $s1->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // EMPLOYEES
     $query = 'SELECT * FROM %s LEFT JOIN (%s) ON (%s.emp_job_title = %s.job_id)';
     $query = sprintf($query, 'tbl_employee', 'tbl_job', 'tbl_employee', 'tbl_job');
     $statement = $source->prepare($query);
     $statement->execute();
     $employees = $statement->fetchAll();
     $connection->beginTransaction();
     try {
         EmployeePeer::doDeleteAll($connection);
         foreach ($employees as $employee) {
             $this->logSection('employee', 'reading employee ' . $employee['emp_id']);
             $emp = new Employee();
             $emp_fields = array('clearance' => $employee['emp_scr_clearance'], 'first_name' => $employee['emp_fn'], 'middle' => $employee['emp_mi'], 'last_name' => $employee['emp_ln'], 'address' => $employee['emp_address'], 'address_2' => $employee['emp_address2'], 'city' => $employee['emp_city'], 'state' => $employee['emp_state'], 'zip' => $employee['emp_zip'], 'home_phone' => $employee['emp_phone'], 'cell_phone' => $employee['emp_cell'], 'company_email' => $employee['emp_email'], 'personal_email' => $employee['emp_p_email'], 'license_number' => $employee['emp_license_number'], 'license_expiration' => $employee['emp_license_exp'], 'dob' => $employee['emp_dob'], 'doh' => $employee['emp_hire_date'], 'dof' => $employee['emp_end_date'], 'ssn' => $employee['emp_ssn'], 'health_insurance' => $employee['emp_health'], 'retirement_plan' => $employee['emp_401k'], 'suplimental_health' => $employee['emp_health_sup'], 'health_type' => $employee['emp_health_type'], 'tb_date' => $employee['emp_tb'], 'osha_date' => $employee['emp_osha'], 'cpr_date' => $employee['emp_cpr'], 'finger_prints' => $employee['emp_fp'], 'finger_print_notes' => $employee['emp_fp_n'], 'notes' => $employee['emp_notes']);
             $emp->fromArray($emp_fields, BasePeer::TYPE_FIELDNAME);
             // find the job - check for errors
             $emp->setJob(JobPeer::getByName($employee['job_title']));
             // if physical has a date then create a new physical object for employee
             if ($employee['emp_physical']) {
                 $this->logSection('physical', 'employee ' . $employee['emp_fn'] . ' had a physical on ' . $employee['emp_physical']);
                 $ph1 = new Physical();
                 $ph1->setEmployee($emp);
                 $ph1->setDateGiven($employee['emp_physical']);
                 $ph1->save($connection);
             }
             $emp->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // read in and create client objects - linking to employee
     // CLIENTS
     $query = 'SELECT * FROM %s LEFT JOIN (%s) ON (%s.client_district = %s.district_id)';
     $query = sprintf($query, 'tbl_client', 'tbl_district', 'tbl_client', 'tbl_district');
     $statement = $source->prepare($query);
     $statement->execute();
     $clients = $statement->fetchAll();
     $connection->beginTransaction();
     try {
         ClientPeer::doDeleteAll($connection);
         foreach ($clients as $client) {
             $this->logSection('client', 'reading client ' . $client['client_ln']);
             $cl = new Client();
             $client_fields = array('first_name' => $client['client_fn'], 'last_name' => $client['client_ln'], 'dob' => $client['client_dob'], 'parent_first' => $client['client_parent_fn'], 'parent_last' => $client['client_parent_ln'], 'address' => $client['client_address'], 'address_2' => $client['client_address2'], 'city' => $client['client_city'], 'state' => $client['client_state'], 'zip' => $client['client_zip'], 'home_phone' => $client['home_phone'], 'work_phone' => $client['work_phone'], 'cell_phone' => $client['cell_phone'], 'blue_card' => $client['blue_card'], 'physical_exp' => $client['physical_exp_date'], 'immunizations' => $client['immunizations'], 'waiting_list' => $client['waiting_list']);
             // county
             $cl->setCounty(CountyPeer::getByName($client['client_county']));
             // district
             $cl->setDistrict(DistrictPeer::getByName($client['district_name']));
             $cl->fromArray($client_fields, BasePeer::TYPE_FIELDNAME);
             $cl->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // CLIENT SERVICES
     // CLASSROOM
     $query = 'SELECT * FROM tbl_classroom LEFT JOIN (tbl_client) ON (tbl_classroom.class_client_id = tbl_client.client_id)
 LEFT JOIN (tbl_employee) ON (tbl_classroom.class_provider_id = tbl_employee.emp_id)
 LEFT JOIN (tbl_services) ON (tbl_classroom.class_service_id = tbl_services.service_id)
 LEFT JOIN (tbl_frequency) ON (tbl_classroom.class_freq_id = tbl_frequency.freq_id)';
     $statement = $source->prepare($query);
     $statement->execute();
     $classrooms = $statement->fetchAll();
     $connection->beginTransaction();
     $c = new Criteria();
     $c->add(ClientServicePeer::OBJECT_TYPE, ClientServicePeer::CLASSKEY_CLASSROOM);
     try {
         ClientServicePeer::doDelete($c, $connection);
         foreach ($classrooms as $classroom) {
             $this->logSection('classroom', 'reading service ' . $classroom['class_id']);
             $cr_cl = new Classroom();
             $cr_cl->setStartDate($classroom['class_start_date']);
             $cr_cl->setEndDate($classroom['class_exp_date']);
             $cr_cl->setChangeDate($classroom['class_chng_date']);
             $cr_cl->setNotes($classroom['class_notes']);
             // client
             $cr_cl->setClient(ClientPeer::getByFullName($classroom['client_fn'], $classroom['client_ln']));
             // employee
             $cr_cl->setEmployee(EmployeePeer::getByFullName($classroom['emp_fn'], $classroom['emp_ln']));
             // service
             $cr_cl->setService(ServicePeer::getByName($classroom['service_title']));
             // frequency
             $cr_cl->setFrequency(FrequencyPeer::getByName($classroom['freq_title']));
             // office
             $cr_cl->setOffice(OfficePeer::getByName($classroom['class_location']));
             $cr_cl->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // EI
     $query = 'SELECT * FROM tbl_ei LEFT JOIN (tbl_client) ON (tbl_ei.ei_client_id = tbl_client.client_id)
 LEFT JOIN (tbl_employee) ON (tbl_ei.ei_provider_id = tbl_employee.emp_id)
 LEFT JOIN (tbl_services) ON (tbl_ei.ei_service_id = tbl_services.service_id)
 LEFT JOIN (tbl_frequency) ON (tbl_ei.ei_freq_id = tbl_frequency.freq_id)
 LEFT JOIN (tbl_icd9) ON (tbl_ei.ei_icd9_id = tbl_icd9.icd9_id)';
     $statement = $source->prepare($query);
     $statement->execute();
     $eis = $statement->fetchAll();
     $connection->beginTransaction();
     $c = new Criteria();
     $c->add(ClientServicePeer::OBJECT_TYPE, ClientServicePeer::CLASSKEY_EI);
     try {
         ClientServicePeer::doDelete($c, $connection);
         foreach ($eis as $ei) {
             $this->logSection('ei', 'reading service ' . $ei['ei_id']);
             $ei_cl = new Ei();
             $ei_cl->setStartDate($ei['ei_start_date']);
             $ei_cl->setEndDate($ei['ei_exp_date']);
             $ei_cl->setChangeDate($ei['ei_chng_date']);
             $ei_cl->setNotes($ei['ei_serv_notes']);
             $ei_cl->setAuthorization($ei['ei_auth']);
             $ei_cl->setPhysiciansOrder($ei['ei_p_order']);
             // client
             $ei_cl->setClient(ClientPeer::getByFullName($ei['client_fn'], $ei['client_ln']));
             // employee
             $ei_cl->setEmployee(EmployeePeer::getByFullName($ei['emp_fn'], $ei['emp_ln']));
             // service
             $ei_cl->setService(ServicePeer::getByName($ei['service_title']));
             // frequency
             $ei_cl->setFrequency(FrequencyPeer::getByName($ei['freq_title']));
             // office
             $ei_cl->setIcd9(Icd9Peer::getByName($ei['icd9_value']));
             $ei_cl->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // PRESCHOOL
     $query = 'SELECT * FROM tbl_preschool LEFT JOIN (tbl_client) ON (tbl_preschool.pre_client_id = tbl_client.client_id)
 LEFT JOIN (tbl_employee) ON (tbl_preschool.pre_provider_id = tbl_employee.emp_id)
 LEFT JOIN (tbl_services) ON (tbl_preschool.pre_service_id = tbl_services.service_id)
 LEFT JOIN (tbl_frequency) ON (tbl_preschool.pre_freq_id = tbl_frequency.freq_id)';
     $statement = $source->prepare($query);
     $statement->execute();
     $preschools = $statement->fetchAll();
     $connection->beginTransaction();
     $c = new Criteria();
     $c->add(ClientServicePeer::OBJECT_TYPE, ClientServicePeer::CLASSKEY_PRESCHOOL);
     try {
         ClientServicePeer::doDelete($c, $connection);
         foreach ($preschools as $preschool) {
             $this->logSection('preschool', 'reading service ' . $preschool['pre_id']);
             $pr_cl = new Preschool();
             $pr_cl->setStartDate($preschool['pre_start_date']);
             $pr_cl->setEndDate($preschool['pre_exp_date']);
             $pr_cl->setChangeDate($preschool['pre_chng_date']);
             // client
             $pr_cl->setClient(ClientPeer::getByFullName($preschool['client_fn'], $preschool['client_ln']));
             // employee
             $pr_cl->setEmployee(EmployeePeer::getByFullName($preschool['emp_fn'], $preschool['emp_ln']));
             // service
             $pr_cl->setService(ServicePeer::getByName($preschool['service_title']));
             // frequency
             $pr_cl->setFrequency(FrequencyPeer::getByName($preschool['freq_title']));
             $pr_cl->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
     // SEIT
     $query = 'SELECT * FROM tbl_seit LEFT JOIN (tbl_client) ON (tbl_seit.seit_client_id = tbl_client.client_id)
 LEFT JOIN (tbl_employee) ON (tbl_seit.seit_provider_id = tbl_employee.emp_id)
 LEFT JOIN (tbl_services) ON (tbl_seit.seit_service_id = tbl_services.service_id)
 LEFT JOIN (tbl_frequency) ON (tbl_seit.seit_freq_id = tbl_frequency.freq_id)';
     $statement = $source->prepare($query);
     $statement->execute();
     $seits = $statement->fetchAll();
     $connection->beginTransaction();
     $c = new Criteria();
     $c->add(ClientServicePeer::OBJECT_TYPE, ClientServicePeer::CLASSKEY_SEIT);
     try {
         ClientServicePeer::doDelete($c, $connection);
         foreach ($seits as $seit) {
             $this->logSection('seit', 'reading service ' . $seit['seit_id']);
             $seit_cl = new Seit();
             $seit_cl->setStartDate($seit['seit_start_date']);
             $seit_cl->setEndDate($seit['seit_exp_date']);
             $seit_cl->setChangeDate($seit['seit_chng_date']);
             $seit_cl->setNotes($seit['seit_notes']);
             // client
             $seit_cl->setClient(ClientPeer::getByFullName($seit['client_fn'], $seit['client_ln']));
             // employee
             $seit_cl->setEmployee(EmployeePeer::getByFullName($seit['emp_fn'], $seit['emp_ln']));
             // service
             $seit_cl->setService(ServicePeer::getByName($seit['service_title']));
             // frequency
             $seit_cl->setFrequency(FrequencyPeer::getByName($seit['freq_title']));
             $seit_cl->save($connection);
         }
         $connection->commit();
     } catch (PropelException $e) {
         $connection->rollBack();
         throw $e;
     }
 }
Exemplo n.º 7
0
 public function getRows($pq)
 {
     $rows = $pq->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
     $n = count($rows);
     echo 'Jumlah propinsi: ' . $n . " \n";
     $count = 0;
     foreach ($rows as $value) {
         $count++;
         $row = pq($value);
         $kolom_provinsi = $row->find('td:eq(1) > a');
         $nama_provinsi = $kolom_provinsi->text();
         $link_provinsi = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolom_provinsi->attr('href')) . '&perhal=1000';
         echo sprintf("Memproses propinsi %d dari %d\n", $count, $n);
         echo sprintf("Propinsi: %s Link: %s\n", $nama_provinsi, $link_provinsi);
         $province = Province::model()->findByAttributes(array('name' => $nama_provinsi));
         if (!$province instanceof Province) {
             $province = new Province();
             $province->name = $nama_provinsi;
             if (!$province->save()) {
                 throw new CException('Cannot save province');
             }
         }
         $countdistrict = 0;
         $pqDist = phpQuery::newDocumentHtml($this->getContents($link_provinsi));
         $rowsDist = $pqDist->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
         $nDist = count($rowsDist);
         $countDist = 0;
         foreach ($rowsDist as $valueDist) {
             $countDist++;
             $rowDist = pq($valueDist);
             switch ($rowDist->find('td:eq(2)')->text()) {
                 case 'Kota':
                     $tipeDist = 'kota';
                     break;
                 default:
                 case 'Kab.':
                     $tipeDist = 'kabupaten';
                     break;
             }
             $kolomDist = $rowDist->find('td:eq(3) > a');
             $namaDist = $kolomDist->text();
             $linkDist = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolomDist->attr('href')) . '&perhal=1000';
             echo sprintf("Memproses distrik " . $province->name . " %d dari %d\n", $countDist, $nDist);
             echo sprintf("Distrik: %s Link: %s\n", $namaDist, $linkDist);
             $distrik = District::model()->findByAttributes(array('name' => $namaDist, 'province_id' => $province->id, 'type' => $tipeDist));
             if (!$distrik instanceof District) {
                 $distrik = new District();
                 $distrik->name = $namaDist;
                 $distrik->type = $tipeDist;
                 $distrik->province_id = $province->id;
                 if (!$distrik->save()) {
                     throw new CException('Cannot save district');
                 }
             }
             $pqZone = phpQuery::newDocumentHtml($this->getContents($linkDist));
             $rowsZone = $pqZone->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
             $nZone = count($rowsZone);
             $countZone = 0;
             foreach ($rowsZone as $valueZone) {
                 $countZone++;
                 $rowZone = pq($valueZone);
                 $kolomZone = $rowZone->find('td:eq(4) > a');
                 $namaZone = $kolomZone->text();
                 $linkZone = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolomZone->attr('href')) . '&perhal=1000';
                 echo sprintf("Memproses zone  %d dari %d\n", $countZone, $nZone);
                 echo sprintf("zone: %s Link: %s\n", $namaZone, $linkZone);
                 $new_zone = false;
                 $zone = Zone::model()->findByAttributes(array('name' => $namaZone, 'district_id' => $distrik->id));
                 if (!$zone instanceof Zone) {
                     $zone = new Zone();
                     $zone->name = $namaZone;
                     $zone->active = 1;
                     $zone->district_id = $distrik->id;
                     if (!$zone->save()) {
                         throw new CException('Cannot save Zone');
                     }
                     $new_zone = true;
                 }
                 echo 'sukses saving zone' . "\n";
                 $countArea = 0;
                 $pqArea = phpQuery::newDocumentHtml($this->getContents($linkZone));
                 $rowsArea = $pqArea->find("table[bgcolor='#ffccff'] tr[bgcolor='#ccffff']");
                 $nArea = count($rowsArea);
                 // Let's speed up things a bit
                 $trans = Yii::app()->db->beginTransaction();
                 foreach ($rowsArea as $valueArea) {
                     $countArea++;
                     $rowArea = pq($valueArea);
                     $kolomArea = $rowArea->find('td:eq(2) > a');
                     $kolomKodePos = $rowArea->find('td:eq(1)');
                     $namaArea = $kolomArea->text();
                     $kodePos = $kolomKodePos->text();
                     $linkKodePos = str_replace(' ', '%20', self::NomorNetKodePosBaseUrl . $kolomArea->attr('href')) . '&perhal=1000';
                     $area = $new_zone ? null : Area::model()->findByAttributes(array('name' => $namaArea, 'zone_id' => $zone->id));
                     if (!$area instanceof Area) {
                         $area = new Area();
                         $area->name = $namaArea;
                         $area->postcode = $kodePos;
                         $area->zone_id = $zone->id;
                         if (!$area->save()) {
                             throw new CException('Cannot save area');
                         }
                     }
                     echo 'Sukses Saving Code Post' . "/n kode pos adalah " . $area->postcode . "\n";
                 }
                 $trans->commit();
             }
         }
     }
 }
Exemplo n.º 8
0
 public function save($table = "")
 {
     if ($table == "counties") {
         $county_name = $this->input->post("name");
         $new_county = new Counties();
         $new_county->county = $county_name;
         $new_county->save();
         $this->session->set_userdata('msg_success', 'County: ' . $county_name . ' was Added');
         $this->session->set_userdata('default_link', 'addCounty');
     } else {
         if ($table == "facilities") {
             $satellite_code = $this->input->post("facility");
             if ($satellite_code) {
                 $central_code = $this->session->userdata("facility");
                 $sql = "update facilities set parent='{$central_code}' where facilitycode='{$satellite_code}'";
                 $this->db->query($sql);
                 $this->session->set_userdata('msg_success', 'Facility No: ' . $satellite_code . ' was Added as a Satellite');
             }
             $this->session->set_userdata('default_link', 'addSatellite');
         } else {
             if ($table == "district") {
                 $disrict_name = $this->input->post("name");
                 $new_district = new District();
                 $new_district->Name = $disrict_name;
                 $new_district->save();
                 $this->session->set_userdata('msg_success', 'District: ' . $disrict_name . ' was Added');
                 $this->session->set_userdata('default_link', 'addDistrict');
             } else {
                 if ($table == "menu") {
                     $menu_name = $this->input->post("menu_name");
                     $menu_url = $this->input->post("menu_url");
                     $menu_desc = $this->input->post("menu_description");
                     $new_menu = new Menu();
                     $new_menu->Menu_Text = $menu_name;
                     $new_menu->Menu_Url = $menu_url;
                     $new_menu->Description = $menu_desc;
                     $new_menu->save();
                     $this->session->set_userdata('msg_success', 'Menu: ' . $menu_name . ' was Added');
                     $this->session->set_userdata('default_link', 'addMenu');
                 } else {
                     if ($table == "faq") {
                         $faq_module = $this->input->post("faq_module");
                         $faq_question = $this->input->post("faq_question");
                         $faq_answer = $this->input->post("faq_answer");
                         $new_faq = new Faq();
                         $new_faq->modules = $faq_module;
                         $new_faq->questions = $faq_question;
                         $new_faq->answers = $faq_answer;
                         $new_faq->save();
                         $this->session->set_userdata('msg_success', 'FAQ was Added');
                         $this->session->set_userdata('default_link', 'addFAQ');
                     } else {
                         if ($table == "users") {
                             //default password
                             $default_password = '******';
                             $user_data = array('Name' => $this->input->post('fullname', TRUE), 'Username' => $this->input->post('username', TRUE), 'Password' => md5($this->encrypt->get_key() . $default_password), 'Access_Level' => $this->input->post('access_level', TRUE), 'Facility_Code' => $this->input->post('facility', TRUE), 'Created_By' => $this->session->userdata('user_id'), 'Time_Created' => date('Y-m-d,h:i:s A'), 'Phone_Number' => $this->input->post('phone', TRUE), 'Email_Address' => $this->input->post('email', TRUE), 'Active' => 1, 'Signature' => 1);
                             $this->db->insert("users", $user_data);
                             $this->session->set_userdata('msg_success', 'User: '******'fullname', TRUE) . ' was Added');
                             $this->session->set_userdata('default_link', 'addUsers');
                         } else {
                             if ($table == "user_right") {
                                 $access_level = $this->input->post("access_level");
                                 $menu = $this->input->post("menus");
                                 if ($menu) {
                                     $new_right = new User_Right();
                                     $new_right->Access_Level = $access_level;
                                     $new_right->Menu = $menu;
                                     $new_right->Access_Type = "4";
                                     $new_right->save();
                                     $this->session->set_userdata('msg_success', 'User Right was Added');
                                     $this->session->set_userdata('default_link', 'assignRights');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     redirect("home_controller/home");
 }