Example #1
0
 public function actionCreatein($id = null)
 {
     $model = new Regions();
     $comm = json_decode($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Regions'])) {
         $model->attributes = $_POST['Regions'];
         if ($model->save()) {
             $this->redirect(array('admins'));
         }
     }
     $rec = $this->loadModel($comm->e);
     if ($comm->a == "ca") {
         $model->setAttribute('next', $rec->id);
         $model->setAttribute('region_id', $rec->region_id);
     } elseif ($comm->a == "cb") {
         $model->setAttribute('next', $rec->next);
         $model->setAttribute('region_id', $rec->region_id);
     } elseif ($comm->a == "ci") {
         if (!is_null($rec->region_id)) {
             $this->redirect(array('admins'));
         }
         $model->setAttribute('next', null);
         $model->setAttribute('region_id', $rec->id);
     }
     $this->render('create', array('model' => $model));
 }
Example #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Regions();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Regions'])) {
         $model->attributes = $_POST['Regions'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->regionID));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #3
0
 public static function getIdRegionByName($nameRegion)
 {
     $idRegion = 0;
     $region = self::model()->findByAttributes(array('name' => $nameRegion), array('select' => 'idRegion'));
     if (!isset($region->idRegion)) {
         $Region = new Regions();
         $Region->name = $nameRegion;
         $Region->save();
         $idRegion = $Region->idRegion;
     } else {
         $idRegion = $region->idRegion;
     }
     return $idRegion;
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Regions();
     if (isset($_POST['Regions'])) {
         $model->attributes = $_POST['Regions'];
         if ($model->save()) {
             Yii::app()->user->setFlash('success', Yii::t('main', 'Данные успешно сохранены!'));
             $this->redirect(array('update', 'id' => $model->id));
         } else {
             Yii::app()->user->setFlash('error', Yii::t('main', 'Ошибка сохранения данных!'));
         }
     }
     $this->render('create', array('model' => $model));
 }
Example #5
0
 public function getSave()
 {
     $id = Input::get('id');
     if ($id) {
         $regions = Regions::find($id);
         $regions->name = Input::get('name');
         $regions->save();
         Session::flash('message', 'The records are updated successfully');
     } else {
         $regions = new Regions();
         $regions->name = Input::get('name');
         $regions->save();
         Session::flash('message', 'The records are inserted successfully');
     }
     return Redirect::to('regions');
 }
Example #6
0
	public function save() { 		
		$name = $this -> input -> post("name"); 
		$latitude = $this -> input -> post("latitude");
		$longitude = $this -> input -> post("longitude");
		$years = $this -> input -> post("years");
		$populations = $this -> input -> post("populations");
		$region_id = $this -> input -> post("region_id"); 
		//Check if we are in editing mode first; if so, retrieve the edited record. if not, create a new one!
		if(strlen($region_id)>0){
			
			 $region = Regions::getRegion($region_id); 
			 
			 //also, retrieve the region-population combinations for future comparisons. Delete the old ones
			 $region_populations = Regional_Populations::getAllForRegion($region_id);
			 foreach($region_populations as $region_population){ 
			 	$region_population->delete();
			 }
		}
		else{
			$region = new Regions();
		}
		
		$region -> name = $name; 
		$region -> latitude = $latitude;
		$region -> longitude = $longitude;
		$region -> save(); 
		$region_id = $region -> id;
		$counter = 0;  
		//Loop to get all the year-population combinations. Only add the ones that have actual values
		foreach ($years as $year) { 
			if (strlen($year)>1) { 
				$region_population = new Regional_Populations();
				$region_population -> name = $name;
				$region_population -> population = $populations[$counter];
				$region_population -> year = $years[$counter];
				$region_population -> region_id = $region_id;  
				$region_population -> save();
				$counter++;
			} else {
				$counter++;
				continue;
			}

		} 
		redirect("region_management");
	}
 /**
  * Show the POST form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function doSave()
 {
     $validator = Validator::make(Input::all(), Regions::$rules);
     if ($validator->passes()) {
         $id = Input::get('id');
         if (isset($id) && $id > 0) {
             $regions = Regions::find($id);
         } else {
             $regions = new Regions();
         }
         $regions->name = Input::get('name');
         $regions->description = Input::get('description');
         $regions->country_id = Input::get('country');
         $regions->save();
         return Redirect::route('region-list')->with('message', 'Region has been added/changed.');
     } else {
         return Redirect::route('region-edit')->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
     }
 }