diff --git a/common/mail/appointment.php b/common/mail/appointment.php new file mode 100644 index 0000000..2360ac8 --- /dev/null +++ b/common/mail/appointment.php @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
name ?>
phone ?>
date ?>
time ?>
service ?>
url ?>
diff --git a/common/mail/feedback.php b/common/mail/feedback.php index 3b0eabf..2427a89 100755 --- a/common/mail/feedback.php +++ b/common/mail/feedback.php @@ -27,5 +27,9 @@ message ?> + + + url ?> + diff --git a/composer.json b/composer.json index c08476d..ef46d42 100755 --- a/composer.json +++ b/composer.json @@ -34,8 +34,7 @@ "artweb/artbox-core": "@dev", "artweb/artbox-weblog": "@dev", "artweb/artbox-webcomment": "@dev", - "modernkernel/yii2-photoswipe": "*", - "udokmeci/yii2-phone-validator" : "dev-master" + "modernkernel/yii2-photoswipe": "*" }, "require-dev": { "yiisoft/yii2-debug": "~2.0.0", diff --git a/console/migrations/m171109_141930_add_date_service_column_to_feedback_table.php b/console/migrations/m171109_141930_add_date_service_column_to_feedback_table.php new file mode 100644 index 0000000..3fdc545 --- /dev/null +++ b/console/migrations/m171109_141930_add_date_service_column_to_feedback_table.php @@ -0,0 +1,27 @@ +addColumn('feedback', 'date', $this->string()); + $this->addColumn('feedback', 'service', $this->string()); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropColumn('feedback', 'date'); + $this->dropColumn('feedback', 'service'); + } +} diff --git a/console/migrations/m171109_143936_add_time_column_to_feedback_table.php b/console/migrations/m171109_143936_add_time_column_to_feedback_table.php new file mode 100644 index 0000000..b16507e --- /dev/null +++ b/console/migrations/m171109_143936_add_time_column_to_feedback_table.php @@ -0,0 +1,25 @@ +addColumn('feedback', 'time', $this->string()); + } + + /** + * @inheritdoc + */ + public function down() + { + $this->dropColumn('feedback', 'time'); + } +} diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index d005f40..46fc447 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -1,7 +1,7 @@ request->post())) { throw new BadRequestHttpException(); } else { - $model = new Feedback(); + $type = Yii::$app->request->post("type"); + + $viewFileName = "feedback"; + $model = new Feedback(['scenario' => Feedback::SCENARIO_WRITE_US]); + + if ( $type === "write_us" ){ + $viewFileName = "feedback"; + $model = new Feedback(['scenario' => Feedback::SCENARIO_WRITE_US]); + } + elseif ( $type === "appointment" ){ + $viewFileName = "appointment"; + $model = new Feedback(['scenario' => Feedback::SCENARIO_APPOINTMENT]); + } + + if ($model->load(Yii::$app->request->post()) && $model->save()) { $pattern = '/([a-zA-Z0-9\._-]*@[a-zA-Z0-9\._-]*)([;\s,:]*)/'; @@ -136,8 +150,9 @@ $emails = explode("; ", $emailStr); + $mailer->compose( - 'feedback', + $viewFileName, [ 'model' => $model, ] @@ -160,6 +175,8 @@ 'alert' => $alert, ]; } else { + Yii::$app->response->setStatusCode(500); + return [ 'success' => false, 'error' => $model->errors, diff --git a/frontend/models/Feedback.php b/frontend/models/Feedback.php index 9d18162..75f13cd 100644 --- a/frontend/models/Feedback.php +++ b/frontend/models/Feedback.php @@ -1,13 +1,19 @@ [ + self::SCENARIO_APPOINTMENT => [ 'name', 'phone', 'date', 'time', 'service', - 'url' ], self::SCENARIO_WRITE_US => [ @@ -32,8 +37,7 @@ 'email', 'phone', 'message', - 'url' - ] + ], ] ); @@ -48,7 +52,6 @@ 'name', 'phone', 'date', - 'url' ], 'required', 'on' => self::SCENARIO_APPOINTMENT, @@ -58,7 +61,6 @@ 'name', 'email', 'phone', - 'url', ], 'required', 'on' => self::SCENARIO_WRITE_US, @@ -71,14 +73,16 @@ [ 'name', 'date', - 'phone', + 'service', + 'time', ], 'string', - 'max' => 255, + 'max' => 55, ], [ - [ 'url' ], - 'url' + [ 'phone' ], + 'match', + 'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/', ], [ [ 'message' ], @@ -91,4 +95,24 @@ ]; } + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'id' => Yii::t('core', 'id'), + 'name' => Yii::t('core', 'name'), + 'phone' => Yii::t('core', 'phone'), + 'created_at' => Yii::t('core', 'created_at'), + 'ip' => Yii::t('core', 'ip'), + 'url' => Yii::t('core', 'url'), + 'status' => Yii::t('core', 'status'), + 'message' => Yii::t('core', 'message'), + 'email' => Yii::t('core', 'email'), + 'service' => Yii::t('core', 'service'), + 'date' => Yii::t('core', 'date'), + ]; + } + } \ No newline at end of file diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index 1a349cb..05e5893 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -10,7 +10,7 @@ use artbox\core\components\SeoComponent; use artbox\core\helpers\ImageHelper; - use artbox\core\models\Feedback; + use frontend\models\Feedback; use artbox\core\models\PageCategory; use artbox\core\models\User; use common\models\Settings; @@ -27,7 +27,8 @@ AppAsset::register($this); $user = \Yii::$app->user->identity; $seo = Yii::$app->get('seo'); - $feedback = new Feedback(); + $feedback = new Feedback(['scenario' => Feedback::SCENARIO_WRITE_US]); + $appointment = new Feedback(['scenario' => Feedback::SCENARIO_APPOINTMENT]); $settings = Settings::getInstance(); $controller = Yii::$app->controller; $default_controller = Yii::$app->defaultRoute; @@ -66,7 +67,19 @@ 'name' => 'robots', 'content' => $seo->robots, ] - ) + ); + + $this->registerJsFile( + '/js/jquery.maskedinput.js', + [ + 'depends' => 'yii\web\JqueryAsset' + ] + ); + + $js = <<registerJs($js, View::POS_READY); ?> beginPage() ?> @@ -374,49 +387,144 @@ _________________________________________________________ --> @@ -444,6 +552,8 @@ _________________________________________________________ --> ] ); ?> + + field($feedback, 'name') ->textInput() ->Label('Имя'); ?> diff --git a/frontend/web/js/jquery.maskedinput.js b/frontend/web/js/jquery.maskedinput.js new file mode 100644 index 0000000..d4dfd01 --- /dev/null +++ b/frontend/web/js/jquery.maskedinput.js @@ -0,0 +1,7 @@ +/* + jQuery Masked Input Plugin + Copyright (c) 2007 - 2015 Josh Bush (digitalbush.com) + Licensed under the MIT license (http://digitalbush.com/projects/masked-input-plugin/#license) + Version: 1.4.1 +*/ +!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){var b,c=navigator.userAgent,d=/iphone/i.test(c),e=/chrome/i.test(c),f=/android/i.test(c);a.mask={definitions:{9:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(c,g){var h,i,j,k,l,m,n,o;if(!c&&this.length>0){h=a(this[0]);var p=h.data(a.mask.dataName);return p?p():void 0}return g=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},g),i=a.mask.definitions,j=[],k=n=c.length,l=null,a.each(c.split(""),function(a,b){"?"==b?(n--,k=a):i[b]?(j.push(new RegExp(i[b])),null===l&&(l=j.length-1),k>a&&(m=j.length-1)):j.push(null)}),this.trigger("unmask").each(function(){function h(){if(g.completed){for(var a=l;m>=a;a++)if(j[a]&&C[a]===p(a))return;g.completed.call(B)}}function p(a){return g.placeholder.charAt(a=0&&!j[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);n>c;c++)if(j[c]){if(!(n>d&&j[c].test(C[d])))break;C[c]=C[d],C[d]=p(d),d=q(d)}z(),B.caret(Math.max(l,a))}}function t(a){var b,c,d,e;for(b=a,c=p(a);n>b;b++)if(j[b]){if(d=q(b),e=C[b],C[b]=c,!(n>d&&j[d].test(e)))break;c=e}}function u(){var a=B.val(),b=B.caret();if(o&&o.length&&o.length>a.length){for(A(!0);b.begin>0&&!j[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beging)&&g&&13!==g){if(i.end-i.begin!==0&&(y(i.begin,i.end),s(i.begin,i.end-1)),c=q(i.begin-1),n>c&&(d=String.fromCharCode(g),j[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),f){var k=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(k,0)}else B.caret(e);i.begin<=m&&h()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&n>c;c++)j[c]&&(C[c]=p(c))}function z(){B.val(C.join(""))}function A(a){var b,c,d,e=B.val(),f=-1;for(b=0,d=0;n>b;b++)if(j[b]){for(C[b]=p(b);d++e.length){y(b+1,n);break}}else C[b]===e.charAt(d)&&d++,k>b&&(f=b);return a?z():k>f+1?g.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,n)):z():(z(),B.val(B.val().substring(0,f+1))),k?b:l}var B=a(this),C=a.map(c.split(""),function(a,b){return"?"!=a?i[a]?p(b):a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return j[b]&&a!=p(b)?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(b);var a;E=B.val(),a=A(),b=setTimeout(function(){B.get(0)===document.activeElement&&(z(),a==c.replace("?","").length?B.caret(0,a):B.caret(a))},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on("input.mask paste.mask",function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),h()},0)}),e&&f&&B.off("input.mask").on("input.mask",u),A()})}})}); \ No newline at end of file -- libgit2 0.21.4