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); }
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)); }