コード例 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $this->layout = '//layouts/column2_noblock';
     $model = new Person();
     $model->Birthday = date("d.m.Y", mktime(0, 0, 0, 1, 1, date('Y') - 18));
     $searchRes = array();
     // Обработка формы поиска
     if (isset($_POST['search'])) {
         $findRes = 0;
         //$this->FindLocalPersonByDoc($_POST['search']['attestatSeries'],$_POST['search']['attestatNumber']);
         try {
             if ($findRes == 0) {
                 $fio = trim($_POST['search']['fio']);
                 if (empty($fio)) {
                     $res = WebServices::findPerson($_POST['search']['series'], $_POST['search']['number']);
                 } else {
                     $res = WebServices::findPersonByFio($_POST['search']['fio']);
                 }
                 $searchRes = Person::JsonDataAsArray($res);
                 Yii::app()->session['searchRes'] = $searchRes;
             } else {
                 Yii::app()->user->setFlash("message", "Персона вже існує в системі з кодом {$findRes}");
                 $this->redirect(Yii::app()->createUrl("person/update", array("id" => $findRes)));
             }
         } catch (Exception $e) {
             Yii::app()->user->setFlash("message", $e->getMessage());
         }
     }
     // Обработка пролистывания найденных персон
     if (isset($_GET['page'])) {
         $searchRes = Yii::app()->session['searchRes'];
     }
     // Загрузка данный из ЕДЕБО по коду персоны
     if (isset($_GET['personCodeU'])) {
         try {
             if ($model->loadByUCode($_GET['personCodeU'])) {
                 try {
                     $response = WebServices::findPersonDocumentsByCodeU($_GET['personCodeU']);
                     Yii::app()->session[$_GET['personCodeU'] . "-tmp_documents"] = $response;
                     $searchRes = $model->loadDocumentsFromJSON($response);
                     $response = WebServices::findPersonContactsByCodeU($_GET['personCodeU']);
                     $searchRes = $model->loadContactsFromJSON($response);
                 } catch (Exception $e) {
                     Yii::app()->user->setFlash("message", $e->getMessage());
                 }
             }
         } catch (Exception $e) {
             Yii::app()->user->setFlash("message", $e->getMessage());
         }
     }
     if (isset($_POST['Person'])) {
         $model->attributes = $_POST['Person'];
         if (isset($_POST['Documents']['persondoc'])) {
             $model->persondoc->attributes = $_POST['Documents']['persondoc'];
             //$model->validate();
         }
         if (!empty($model->codeU)) {
             if (isset(Yii::app()->session[$model->codeU . "-tmp_documents"])) {
                 $model->loadDocumentsFromJSON(Yii::app()->session[$model->codeU . "-tmp_documents"]);
             }
         }
         if (isset($_POST['Documents']['entrantdoc'])) {
             $model->entrantdoc->attributes = $_POST['Documents']['entrantdoc'];
         }
         if (isset($_POST['PersonContacts']['homephone'])) {
             $model->homephone->attributes = $_POST['PersonContacts']['homephone'];
         }
         if (isset($_POST['PersonContacts']['mobphone'])) {
             $model->mobphone->attributes = $_POST['PersonContacts']['mobphone'];
         }
         $entrant_valid = true;
         $showPersonEntrantDocForm = Yii::app()->user->checkAccess("showPersonEntrantDocForm");
         if ($showPersonEntrantDocForm && isset($_POST['Documents']['entrantdoc'])) {
             $entrant_valid = $model->entrantdoc->validate("ENTRANT");
         }
         $asEDBOReqOperator = Yii::app()->user->checkAccess("asEDBOReqOperator");
         // Обробка для електронных заяв
         if ($asEDBOReqOperator) {
             $model->scenario = "EDBOREQ";
             if ($model->LanguageID == 0) {
                 $model->LanguageID = 2;
             }
             if ($model->homephone->validate() && $model->mobphone->validate() && $model->save()) {
                 $model->homephone->PersonID = $model->idPerson;
                 $model->mobphone->PersonID = $model->idPerson;
                 $model->homephone->save();
                 $model->mobphone->save();
                 if (isset(Yii::app()->session[$model->codeU . "-documents"])) {
                     Documents::loadAndSave($model->idPerson, unserialize(Yii::app()->session[$model->codeU . "-documents"]));
                 }
                 $this->redirect(array('view', 'id' => $model->idPerson));
             }
         } else {
             // Обробка обычной заявки
             if (!empty($model->persondoc->edboID) && $model->persondoc->TypeID == 1) {
                 $model->persondoc->scenario = "FULLINPUT";
             }
             if ($entrant_valid && $model->persondoc->validate() && $model->homephone->validate() && $model->mobphone->validate() && $model->save()) {
                 $model->persondoc->PersonID = $model->idPerson;
                 $model->homephone->PersonID = $model->idPerson;
                 $model->mobphone->PersonID = $model->idPerson;
                 $model->persondoc->save();
                 if ($showPersonEntrantDocForm && isset($_POST['Documents']['entrantdoc'])) {
                     $model->entrantdoc->PersonID = $model->idPerson;
                     $model->entrantdoc->save();
                 } else {
                     foreach ($model->allentrantdocs as $obj) {
                         if ($obj->TypeID != $model->entrantdoc->TypeID) {
                             $obj->PersonID = $model->idPerson;
                             $obj->scenario = "FULLINPUT";
                             $obj->save();
                         }
                     }
                 }
                 $model->homephone->save();
                 $model->mobphone->save();
                 if (isset(Yii::app()->session[$model->codeU . "-documents"])) {
                     Documents::loadAndSave($model->idPerson, unserialize(Yii::app()->session[$model->codeU . "-documents"]));
                 }
                 $this->redirect(array('view', 'id' => $model->idPerson));
             }
         }
     }
     if (empty($model->LanguageID)) {
         $model->LanguageID = 2;
     }
     $this->render('create', array('model' => $model, "searchres" => $searchRes));
 }
コード例 #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $this->layout = '//layouts/column2_noblock';
     $model = new Person();
     $model->Birthday = date("d.m.Y", mktime(0, 0, 0, 1, 1, date('Y') - 18));
     $searchRes = array();
     // Обработка формы поиска
     if (isset($_POST['search'])) {
         $findRes = 0;
         //$this->FindLocalPersonByDoc($_POST['search']['attestatSeries'],$_POST['search']['attestatNumber']);
         try {
             if ($findRes == 0) {
                 $fio = trim($_POST['search']['fio']);
                 if (empty($fio)) {
                     $res = WebServices::findPerson($_POST['search']['series'], $_POST['search']['number']);
                 } else {
                     $res = WebServices::findPersonByFio($_POST['search']['fio']);
                 }
                 $searchRes = Person::JsonDataAsArray($res);
                 Yii::app()->session['searchRes'] = $searchRes;
             } else {
                 Yii::app()->user->setFlash("message", "Персона вже існує в системі з кодом {$findRes}");
                 $this->redirect(Yii::app()->createUrl("person/update", array("id" => $findRes)));
             }
         } catch (Exception $e) {
             Yii::app()->user->setFlash("message", $e->getMessage());
         }
     }
     // Обработка пролистывания найденных персон
     if (isset($_GET['page'])) {
         $searchRes = Yii::app()->session['searchRes'];
     }
     // Загрузка данный из ЕДЕБО по коду персоны
     if (isset($_GET['personCodeU'])) {
         try {
             if ($model->loadByUCode($_GET['personCodeU'])) {
                 try {
                     $response = WebServices::findPersonDocumentsByCodeU($_GET['personCodeU']);
                     $searchRes = $model->loadDocumentsFromJSON($response);
                     $response = WebServices::findPersonContactsByCodeU($_GET['personCodeU']);
                     $searchRes = $model->loadContactsFromJSON($response);
                 } catch (Exception $e) {
                     Yii::app()->user->setFlash("message", $e->getMessage());
                 }
             }
         } catch (Exception $e) {
             Yii::app()->user->setFlash("message", $e->getMessage());
         }
     }
     if (isset($_POST['Person'])) {
         $model->attributes = $_POST['Person'];
         /* if (isset($_POST['Documents']['inndoc'])) {
                $model->inndoc->attributes = $_POST['Documents']['inndoc'];
            }*/
         if (isset($_POST['PersonContacts']['homephone'])) {
             $model->homephone->attributes = $_POST['PersonContacts']['homephone'];
         }
         if (isset($_POST['PersonContacts']['mobphone'])) {
             $model->mobphone->attributes = $_POST['PersonContacts']['mobphone'];
         }
         //if ($model->inndoc->validate("INN") && $model->homephone->validate() && $model->mobphone->validate() && $model->save()) {
         if ($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);
                 $id = $model->idPerson;
                 $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->PersonID = $model->idPerson;
             $model->hospdoc->PersonID = $model->idPerson;
             $model->homephone->PersonID = $model->idPerson;
             $model->mobphone->PersonID = $model->idPerson;
             //$model->inndoc->save();
             $model->hospdoc->save();
             $model->homephone->save();
             $model->mobphone->save();
             $this->redirect(array('view', 'id' => $model->idPerson));
         }
     }
     if (empty($model->LanguageID)) {
         $model->LanguageID = 2;
     }
     $this->render('create', array('model' => $model, "searchres" => $searchRes));
 }