/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { try { $model = $this->loadModel($id); //$model = new Person; $model->scenario = "PHOTO"; if (isset($_POST['Person'])) { $oldPhoto = $model->PhotoName; $model->PhotoName = $_POST['Person']['PhotoName']; $tfio = Transliteration::text($model->FirstName) . "_" . Transliteration::text($model->LastName) . "_" . Transliteration::text($model->MiddleName); if ($model->validate()) { $file = CUploadedFile::getInstance($model, 'PhotoName'); $path = Yii::app()->basePath . "/.." . Yii::app()->params['photosPath']; $bigpath = Yii::app()->basePath . "/.." . Yii::app()->params['photosBigPath']; $img = EWideImage::loadFromFile($file->getTempName()); if ($img->getWidth() < $img->getHeight()) { $img->resize(120, null)->crop("center", "middle", 120, 150)->saveToFile($path . "person_{$id}" . "_{$tfio}.jpg"); $img->resize(180, null)->crop("center", "middle", 180, 225)->saveToFile($bigpath . "person_{$id}" . "_{$tfio}.jpg"); } else { $img->resize(null, 150)->crop("center", "middle", 120, 150)->saveToFile($path . "person_{$id}" . "_{$tfio}.jpg"); $img->resize(null, 225)->crop("center", "middle", 180, 225)->saveToFile($bigpath . "person_{$id}" . "_{$tfio}.jpg"); } //unlink($file->getTempName()); $model->PhotoName = "person_{$id}" . "_{$tfio}.jpg"; if ($model->save()) { $this->redirect(array('update', 'id' => $model->idPerson, 'r' => md5(time()))); } } else { $model->PhotoName = $oldPhoto; } } $this->render('update', array('model' => $model)); Yii::app()->end(); } catch (Exception $e) { Yii::app()->user->setFlash("message", "Абітуріент із кодом '{$id}' відсутній у системі! " . $e->getMessage()); $this->redirect(Yii::app()->createUrl("photoloader")); } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $this->layout = '//layouts/column2_noblock'; $model = $this->loadModel($id); //var_dump($_POST); //var_dump($model); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Person'])) { $model->attributes = $_POST['Person']; if (empty($_POST['Person']['KOATUUCodeL2ID'])) { $model->KOATUUCodeL2ID = null; } if (empty($_POST['Person']['KOATUUCodeL3ID'])) { $model->KOATUUCodeL3ID = null; } /*if (isset($_POST['Documents']['inndoc'])) { $model->inndoc->attributes = $_POST['Documents']['inndoc']; $model->inndoc->PersonID = $model->idPerson; }*/ if (isset($_POST['PersonContacts']['homephone'])) { $model->homephone->attributes = $_POST['PersonContacts']['homephone']; $model->homephone->PersonID = $model->idPerson; } if (isset($_POST['PersonContacts']['mobphone'])) { $model->mobphone->attributes = $_POST['PersonContacts']['mobphone']; $model->mobphone->PersonID = $model->idPerson; } //if ($model->validate() && $model->inndoc->validate("INN") && $model->homephone->validate() && $model->mobphone->validate() && $model->save()) { if ($model->validate() && $model->homephone->validate() && $model->mobphone->validate() && $model->save()) { $file = CUploadedFile::getInstance($model, 'image'); if (!empty($file)) { $tfio = Transliteration::text($model->FirstName) . "_" . Transliteration::text($model->LastName) . "_" . Transliteration::text($model->MiddleName); $path = Yii::app()->basePath . "/.." . Yii::app()->params['photosPath']; $bigpath = Yii::app()->basePath . "/.." . Yii::app()->params['photosBigPath']; $img = EWideImage::loadFromFile($file->getTempName()); if (file_exists($path . "person_{$id}" . "_{$tfio}.jpg")) { unlink($path . "person_{$id}" . "_{$tfio}.jpg"); } if (file_exists($bigpath . "person_{$id}" . "_{$tfio}.jpg")) { unlink($bigpath . "person_{$id}" . "_{$tfio}.jpg"); } if ($img->getWidth() < $img->getHeight()) { $img->resize(120, null)->crop("center", "middle", 120, 150)->saveToFile($path . "person_{$id}" . "_{$tfio}.jpg"); $img->resize(180, null)->crop("center", "middle", 180, 225)->saveToFile($bigpath . "person_{$id}" . "_{$tfio}.jpg"); } else { $img->resize(null, 150)->crop("center", "middle", 120, 150)->saveToFile($path . "person_{$id}" . "_{$tfio}.jpg"); $img->resize(null, 225)->crop("center", "middle", 180, 225)->saveToFile($bigpath . "person_{$id}" . "_{$tfio}.jpg"); } unlink($file->getTempName()); $model->PhotoName = "person_{$id}" . "_{$tfio}.jpg"; $model->save(); } //$model->inndoc->save(); $model->homephone->save(); $model->mobphone->save(); //$model->SendEdboRequest(); $this->redirect(array('view', 'id' => $model->idPerson)); } } $this->render('update', array('model' => $model)); }