public function actionImportHoles()
 {
     set_time_limit(0);
     $holes = BHoles::model()->findAll();
     $count = 0;
     foreach ($holes as $hole) {
         //if (1){
         if ($hole->picturenames && isset($hole->picturenames['medium']['fresh']) && count($hole->picturenames['medium']['fresh']) > 0) {
             $model = new Holes('import');
             $model->attributes = $hole->attributes;
             $model->ID = $hole->ID;
             $type = HoleTypes::model()->find('alias = "' . $hole->TYPE . '"');
             $model->TYPE_ID = $type->id;
             if ($model->ADR_SUBJECTRF) {
                 $gibdd = GibddHeads::model()->find('is_regional=1 AND subject_id=' . $model->ADR_SUBJECTRF);
                 if ($gibdd) {
                     $model->gibdd_id = $gibdd->id;
                 } else {
                     $model->gibdd_id = 0;
                 }
             } else {
                 $model->gibdd_id = 0;
             }
             //if ($model->errors) print_r ($model->errors);
             if ($model->STATE == "inprogress") {
                 if (!$model->DATE_SENT) {
                     $model->DATE_SENT = $model->DATE_CREATED;
                 }
                 //echo date('d.m.Y', $model->DATE_SENT).'<br/>';
             }
             if ($model->save()) {
                 //if (0){
                 $count++;
                 foreach ($hole->picturenames['medium']['fresh'] as $i => $src) {
                     $picture = new HolePictures();
                     $picture->type = 'fresh';
                     $picture->filename = $src;
                     $picture->hole_id = $hole->ID;
                     $picture->user_id = $model->USER_ID;
                     $picture->ordering = $i;
                     $picture->save();
                 }
                 foreach ($hole->picturenames['medium']['fixed'] as $i => $src) {
                     $picture = new HolePictures();
                     $picture->type = 'fixed';
                     $picture->filename = $src;
                     $picture->hole_id = $hole->ID;
                     $picture->user_id = $model->USER_ID;
                     $picture->ordering = $i;
                     $picture->save();
                 }
                 if ($model->STATE == "fixed") {
                     $fixmodel = new HoleFixeds();
                     $fixmodel->user_id = $model->USER_ID;
                     $fixmodel->hole_id = $model->ID;
                     $fixmodel->date_fix = $model->DATE_STATUS;
                     $fixmodel->comment = $model->COMMENT2;
                     $fixmodel->save();
                 }
                 if ($model->STATE != "fresh") {
                     if (!$model->DATE_SENT) {
                         $model->DATE_SENT = $model->DATE_CREATED;
                     }
                     $request = new HoleRequests();
                     $request->hole_id = $model->ID;
                     $request->user_id = $model->USER_ID;
                     $request->gibdd_id = $model->gibdd_id;
                     $request->date_sent = $model->DATE_SENT;
                     $request->type = 'gibdd';
                     $request->save();
                     if ($model->GIBDD_REPLY_RECEIVED) {
                         $answer = new HoleAnswers('import');
                         //$answer->attributes=Array('uppload_files'=>Array(123,456));
                         $answer->isimport = true;
                         $answer->request_id = $request->id;
                         $answer->date = $model->DATE_STATUS;
                         $answer->comment = $model->COMMENT_GIBDD_REPLY;
                         if ($answer->save()) {
                             $dir = $_SERVER['DOCUMENT_ROOT'] . $answer->filesFolder;
                             if (!is_dir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/')) {
                                 mkdir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/');
                             }
                             if (!is_dir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/' . $answer->request->hole->ID)) {
                                 mkdir($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/answers/' . $answer->request->hole->ID);
                             }
                             if (!is_dir($dir)) {
                                 mkdir($dir);
                             }
                             if (!is_dir($dir . '/thumbs')) {
                                 mkdir($dir . '/thumbs');
                             }
                             foreach ($hole->picturenames['medium']['gibddreply'] as $i => $src) {
                                 $pict = new HoleAnswerFiles();
                                 $pict->file_name = $src;
                                 $pict->file_type = 'image';
                                 $pict->answer_id = $answer->id;
                                 copy($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/original/' . $answer->request->hole->ID . '/' . $src, $dir . '/' . $src);
                                 //unlink ($_SERVER['DOCUMENT_ROOT'].'/upload/st1234/original/'.$src);
                                 copy($_SERVER['DOCUMENT_ROOT'] . '/upload/st1234/medium/' . $answer->request->hole->ID . '/' . $src, $dir . '/thumbs/' . $src);
                                 //unlink ($_SERVER['DOCUMENT_ROOT'].'/upload/st1234/medium/'.$src);
                                 $pict->save();
                             }
                         } else {
                             print_r($answer->errors);
                             die;
                         }
                     }
                 }
             }
         }
     }
     echo "Добавлено {$count} ям.";
 }
Beispiel #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionAdd()
 {
     if (Yii::app()->user->userModel->relProfile->use_multi_upload) {
         $model = new Holes('add');
     } else {
         $model = new Holes();
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $cs = Yii::app()->getClientScript();
     $cs->registerCssFile('/css/add_form.css');
     if (isset($_POST['Holes'])) {
         $model->attributes = $_POST['Holes'];
         $model->USER_ID = Yii::app()->user->id;
         $model->DATE_CREATED = time();
         $model->ADR_CITY = trim($model->ADR_CITY);
         if (Yii::app()->user->level > 50 || !$model->upploadedPictures) {
             $model->PREMODERATED = 1;
         } else {
             $model->PREMODERATED = 0;
         }
         if ($model->gibdd_id) {
             $subj = $model->gibdd->subject->id;
             if ($subj) {
                 $model->ADR_SUBJECTRF = $subj;
             }
         } else {
             $subj = RfSubjects::model()->SearchID(trim($model->STR_SUBJECTRF));
             if ($subj) {
                 $model->ADR_SUBJECTRF = $subj;
             } else {
                 $model->ADR_SUBJECTRF = 0;
             }
         }
         if ($model->save() && $model->savePictures()) {
             $this->redirect(array('view', 'id' => $model->ID, 'fromadd' => true));
         }
     } else {
         //выставляем центр на карте по координатам IP юзера
         $request = new CHttpRequest();
         $geoIp = new EGeoIP();
         $geoIp->locate($request->userHostAddress);
         //echo ($request->userHostAddress);
         if ($geoIp->longitude) {
             $model->LONGITUDE = $geoIp->longitude;
         }
         if ($geoIp->latitude) {
             $model->LATITUDE = $geoIp->latitude;
         }
     }
     $this->flushUploadDir();
     $this->render('add', array('model' => $model));
 }
Beispiel #3
0
 public function actionAdd($id = null)
 {
     $user = $this->auth();
     $address = Yii::app()->request->getParam('address');
     if (!$address) {
         $this->error('NO_ADDRESS');
     }
     $latitude = Yii::app()->request->getParam('latitude');
     if (!$latitude) {
         $this->error('LATITUDE_NOT_SET');
     }
     $longitude = Yii::app()->request->getParam('longitude');
     if (!$longitude) {
         $this->error('LONGITUDE_NOT_SET');
     }
     $comment = Yii::app()->request->getParam('comment');
     //	$gibdd_id=Yii::app()->request->getParam('gibdd_id');
     $type = Yii::app()->request->getParam('type');
     if (!$type) {
         $this->error('INCORRECT_TYPE');
     } else {
         $typemodel = HoleTypes::model()->find('alias="' . $type . '"');
         if (!$typemodel) {
             $this->error('INCORRECT_TYPE');
         } elseif (!$typemodel->published) {
             $this->error('DEPRECATED_TYPE');
         }
     }
     //	$addressArr    = RfSubjects::model()->Address($address);
     //	$subject_rf = $addressArr['subject_rf'];
     //		$city       = $addressArr['city'];
     //		$address    = $addressArr['address'];
     /**
      * 		if((!$subject_rf || !$city || !$address) && ($latitude && $longitude)){
      * 				$addressArr    = RfSubjects::model()->AddressfromLatLng($latitude, $longitude, $this->mapkey);
      * 					if ($addressArr) {
      * 						$subject_rf = $addressArr['subject_rf'];
      * 						$city       = $addressArr['city'];
      * 						$address    = $addressArr['address'];	
      * 					}
      * 			}
      */
     /**
      * 		// ворнинги, если надо
      * 		if(!$subject_rf || $subject_rf==0) $this->error('CANNOT_REALISE_SUBJECTRF');
      */
     // if(!$city) $this->error('CANNOT_REALISE_CITY');
     $tags = array();
     $model = new Holes();
     $model->USER_ID = $user->id;
     $model->DATE_CREATED = time();
     //$model->region_id=$subject_rf;
     // $model->ADR_CITY=trim($city);
     $model->ADDRESS = trim($address);
     if ($user->level > 50) {
         $model->PREMODERATED = 1;
     } else {
         $model->PREMODERATED = 0;
     }
     $model->LATITUDE = $latitude;
     $model->LONGITUDE = $longitude;
     $model->TYPE_ID = $typemodel->id;
     $model->COMMENT1 = $comment;
     /**
      * 		if (!$gibdd_id){
      * 			$subjmodel=RfSubjects::model()->findByPk($subject_rf);
      * 			if ($subjmodel) $model->gibdd_id=$subjmodel->gibdd_ru->id;
      * 			else $model->gibdd_id=0;
      * 			}
      * 		else $model->gibdd_id=$gibdd_id;
      */
     if (!$model->upploadedPictures) {
         $this->error('NO_FILES');
     }
     if ($model->countUpploadFiles() > 5) {
         $this->error('TOO_MANY_FILES');
     }
     $model->validate();
     if ($model->getError('upploadedPictures')) {
         $this->getUploadError($model->getError('upploadedPictures'));
     }
     if ($model->save() && $model->savePictures()) {
         $tags[] = CHtml::tag('callresult', array('result' => 1, 'inserteddefectid' => $model->ID), 'ok', true);
     } else {
         $this->error('CANNOT_ADD_DEFECT');
     }
     $this->renderXml($tags);
 }
Beispiel #4
0
 public function actionAdd()
 {
     $this->pageTitle = Yii::t('titles', 'HOLES_ADD');
     $this->layout = '//layouts/header_blank';
     $model = new Holes();
     $model->USER_ID = Yii::app()->user->id;
     if (isset($_POST['Holes'])) {
         $model->attributes = $_POST['Holes'];
         if ($model->USER_ID === 0 || $model->USER_ID === null) {
             $users = UserGroupsUser::model()->findAllByAttributes(array(), "email=:email", array(":email" => $_POST['Holes']['EMAIL']));
             if (count($users) == 0) {
                 $umodel = new UserGroupsUser('autoregistration');
                 $umodel->username = $_POST['Holes']['EMAIL'];
                 $umodel->name = $_POST['Holes']['FIRST_NAME'];
                 $umodel->last_name = $_POST['Holes']['LAST_NAME'];
                 $umodel->email = $_POST['Holes']['EMAIL'];
                 $umodel->password = $this->randomPassword();
                 if ($umodel->save()) {
                     $model->USER_ID = $umodel->primaryKey;
                 }
             } else {
                 $model->USER_ID = $users[0]->id;
             }
         }
         $model->DATE_CREATED = strtotime($_POST['Holes']['DATE_CREATED']);
         if (!$model->DATE_CREATED) {
             $model->DATE_CREATED = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
         }
         if ($model->DATE_CREATED < time() - 7 * 86400) {
             $model->addError("DATE_CREATED", Yii::t('template', 'DATE_CANT_BE_PAST', array('{attribute}' => $model->getAttributeLabel('DATE_CREATED'))));
         }
         $model->PREMODERATED = Yii::app()->user->level > 50 ? 1 : 0;
         $model->ROAD_TYPE = $_POST['Holes']['ROAD_TYPE'];
         $tran = $model->dbConnection->beginTransaction();
         if ($model->validate(null, false)) {
             if ($model->save() && $model->savePictures()) {
                 $tran->commit();
                 if ($model->PREMODERATED && $model->ROAD_TYPE == 'highway') {
                     $this->sendMailToUkrautodor($model);
                 }
                 $this->redirect(array('view', 'id' => $model->ID));
             }
         }
     } else {
         //выставляем центр на карте по координатам IP юзера
         $request = new CHttpRequest();
         $geoIp = new EGeoIP();
         $geoIp->locate($request->userHostAddress);
         //echo ($request->userHostAddress);
         if ($geoIp->latitude) {
             $model->LATITUDE = $geoIp->latitude;
         } else {
             $model->LATITUDE = Yii::app()->params['latitude'];
         }
         if ($geoIp->longitude) {
             $model->LONGITUDE = $geoIp->longitude;
         } else {
             $model->LONGITUDE = Yii::app()->params['longitude'];
         }
         $model->DATE_CREATED = time();
     }
     $this->render('holeform', array('model' => $model));
 }