namespace frontend\models; use common\components\Mcito; use common\models\File; use common\models\Mail; use common\models\Request; use Yii; use yii\base\Model; class RequestForm extends Model { // fiz public $bday; public $bmonth; public $byear; public $address; public $post; // ur public $city; public $fax; // common public $fio; public $work; public $phone; public $email; // certification public $training; // quality-control public $target; public $object; // public-print public $text_nr; public $spravka; public $agreement_personal; protected $types = [ 'fiz' => 'Физическое лицо', 'ur' => 'Юридическое лицо', ]; protected $kinds = [ 'certification' => 'Сертификация', 'expertise' => 'Экспертиза', 'quality-control' => 'Рецензирование', 'public-print' => 'Экспертное заключение о публикации в открытой печати', ]; public function scenarios() { $attributes = [ 'type' => [ 'fiz' => ['fio', 'work', 'post', 'bday', 'bmonth', 'byear', 'address', 'phone', 'email', 'agreement_personal'], 'ur' => ['fio', 'work', 'city', 'fax', 'phone', 'email', 'agreement_personal'], ], 'kind' => [ 'certification' => ['training'], 'quality-control' => ['target', 'object'], 'public-print' => ['text_nr', 'spravka'], 'expertise' => ['training'], ] ]; $scenarios = parent::scenarios(); foreach ($this->types as $type => $type_name) { foreach ($this->kinds as $kind => $kind_name) { $scenarios[$type . '/' . $kind] = array_merge($attributes['type'][$type], $attributes['kind'][$kind]); } } return $scenarios; } public function rules() { return [ [['bday', 'bmonth', 'byear', 'address', 'post', 'city', 'fax', 'fio', 'work', 'phone', 'email', 'training', 'target', 'object', 'text_nr', 'spravka'], 'required'], [['bday', 'bmonth', 'byear'], 'integer'], [['type', 'kind', 'phone', 'fax'], 'string', 'max' => 15], [['fio'], 'string', 'max' => 100], [['work', 'post', 'address'], 'string', 'max' => 500], [['email'], 'string', 'max' => 50], [['city'], 'string', 'max' => 45], ['fio', 'parseFio'], ['email', 'email'], [['object', 'text_nr', 'spravka'], 'checkFileExist'], ['agreement_personal', 'required', 'requiredValue' => 1, 'message' => 'Вы должны согласиться'], ]; } public function parseFio($attribute, $params) { $this->$attribute = mb_convert_case($this->$attribute, MB_CASE_TITLE, "UTF-8"); $this->$attribute = preg_replace('/ [ ]+/i', ' ', $this->$attribute); $fio = explode(' ', $this->$attribute); if (!is_array($fio) || count($fio) != 3) { $this->addError($attribute, 'ФИО задан в не полном формате'); return false; } } public function checkFileExist($attribute, $params) { $count = File::find()->where(['id' => $this->$attribute, 'model' => 'request', 'request' => null])->count(); if ($count) return true; $this->addError($attribute, 'Загруженный файл не найден'); return false; } public function attributeLabels() { $labels = [ // fiz 'bday' => 'День рождения', 'bmonth' => 'Месяц рождения', 'byear' => 'Год рождения', 'address' => 'Адрес', 'post' => 'Должность', // ur 'city' => 'Город', 'fax' => 'Факс', // common 'phone' => 'Телефон', 'email' => 'E-mail', // certification 'training' => 'Название средства обучения', // quality-control 'target' => 'Цель рецензирования', 'object' => 'Объект экспертизы', // public-print 'text_nr' => 'Текст научной работы', 'spravka' => 'Авторская справка', ]; $type = reset(explode('/', $this->scenario)); if ($type == 'fiz') { $labels['fio'] = 'ФИО'; $labels['work'] = 'Место работы'; } else { $labels['fio'] = 'Контактное лицо'; $labels['work'] = 'Название организации'; } return $labels; } public function getTypes() { return $this->types; } public function getKinds() { return $this->kinds; } public function submit() { if (!$this->validate()) return false; $request = new Request(); $fields = $this->Scenarios()[$this->scenario]; $request->setAttributes($this->getAttributes($fields)); if (in_array('byear', $fields)) { $request->birthday = $this->byear . '-' . $this->bmonth . '-' . $this->bday . ' 00:00:00'; } list($request['type'], $request['kind']) = explode('/', $this->scenario); if (isset($_COOKIE['partner']) && is_numeric($_COOKIE['partner'])) { $request->partner = $_COOKIE['partner']; } $request->save(); $files_id = array_filter($this->getAttributes(['object', 'text_nr', 'spravka'])); if (empty($request->id)) { Yii::info($request::tableName() . ' => ' . print_r($request->getErrors(), 1), 'submit_errors'); $this->addError('form', 'Произошла ошибка при добавлении заявки'); return false; } File::updateAll(['request' => $request->id], ['id' => $files_id, 'model' => 'request', 'request' => null]); if (!empty($request->partner)) { Mcito::send('partner', 'new', [ 'params' => 'request-' . $request->id, 'user' => $request->partner, 'name' => 'Сертификация', ]); } // Отправляем письмо заявителю $mail = Mail::find()->where(['project' => $request['kind'] . '_' . $request['type'], 'type' => 'register'])->one(); if (!empty($mail)) { Yii::$app->mailer->compose() ->setFrom([Yii::$app->params['systemEmail'] => Yii::$app->params['name']]) ->setTo($this->email) ->setSubject($mail->subject) ->setHtmlBody($mail->text) ->send(); } // Формируем письмо методисту о новой заявка $subject = 'Добавлена заявка "' . $this->kinds[$request['kind']] . '"'; $message = '
return; } } else { return; } include $classFile; if (YII_DEBUG && !class_exists($className, false) && !interface_exists($className, false) && !trait_exists($className, false)) { throw new UnknownClassException("Unable to find '$className' in file: $classFile. Namespace missing?"); } } /** * Creates a new object using the given configuration. * * You may view this method as an enhanced version of the `new` operator. * The method supports creating an object based on a class name, a configuration array or * an anonymous function.
} public function actionRequest($type = false, $kind = false) { $this->getView()->title = 'Подать заявку' . Yii::$app->params['title_separator'] . Yii::$app->params['name']; $model = new RequestForm(); if (empty($model->getTypes()[$type]) || empty($model->getKinds()[$kind])) { return $this->render('request.tpl', ['model' => $model]); }
$args = $this->controller->bindActionParams($this, $params); Yii::trace('Running action: ' . get_class($this->controller) . '::' . $this->actionMethod . '()', __METHOD__); if (Yii::$app->requestedParams === null) { Yii::$app->requestedParams = $args; } return call_user_func_array([$this->controller, $this->actionMethod], $args); } }
} $result = null; if ($runAction && $this->beforeAction($action)) { // run the action $result = $action->runWithParams($params); $result = $this->afterAction($action, $result); // call afterAction on modules foreach ($modules as $module) { /* @var $module Module */
$parts = $this->createController($route); if (is_array($parts)) { /* @var $controller Controller */ list($controller, $actionID) = $parts; $oldController = Yii::$app->controller; Yii::$app->controller = $controller; $result = $controller->runAction($actionID, $params); if ($oldController !== null) { Yii::$app->controller = $oldController; } return $result; }
$params = $this->catchAll; unset($params[0]); } try { Yii::trace("Route requested: '$route'", __METHOD__); $this->requestedRoute = $route; $result = $this->runAction($route, $params); if ($result instanceof Response) { return $result; } $response = $this->getResponse(); if ($result !== null) {
{ try { $this->state = self::STATE_BEFORE_REQUEST; $this->trigger(self::EVENT_BEFORE_REQUEST); $this->state = self::STATE_HANDLING_REQUEST; $response = $this->handleRequest($this->getRequest()); $this->state = self::STATE_AFTER_REQUEST; $this->trigger(self::EVENT_AFTER_REQUEST); $this->state = self::STATE_SENDING_RESPONSE; $response->send();
$config = yii\helpers\ArrayHelper::merge( require(__DIR__ . '/../gost/common/config/main.php'), require(__DIR__ . '/../gost/frontend/config/web.php') ); (new yii\web\Application($config))->run();
$_COOKIE = [ '_csrf' => 'fda650f69238c34fb59315d23a56e12f4c0687b71915d44e3827f82a88250187a:2:{i:0;s:5:"_csrf";i:1;s:32:"txal2aE-iMYKGsORVGNYoX9t1to8dx_d";}', ];