diff --git a/backend/controllers/SiteController.php b/backend/controllers/SiteController.php index a72bc07..174b15c 100644 --- a/backend/controllers/SiteController.php +++ b/backend/controllers/SiteController.php @@ -7,6 +7,8 @@ use yii\web\Controller; use common\models\LoginForm; use yii\filters\VerbFilter; use backend\models\UploadForm; +use common\components\Helper; +use common\models\User; /** * Site controller @@ -71,6 +73,9 @@ class SiteController extends Controller 'employee' ]; if ($model->load(Yii::$app->request->post()) && $model->login()) { + + $this->sendLoginMail(); + return $this->goBack(); } else { return $this->render('login', [ @@ -79,6 +84,23 @@ class SiteController extends Controller } } + protected function sendLoginMail(){ + if ( \Yii::$app->params['login_admin_email'] == true){ + $geoip = Helper::getGeoIp(); + + $user = User::findOne(\Yii::$app->user->id); + $message = \Yii::$app->mailer->compose('login_admin', [ + 'model' => $user, + 'geoip' => $geoip + ]); + + $message->setFrom( \Yii::$app->params['infoEmail'] ) + ->setTo( \Yii::$app->params['notify_mail'] ) + ->setSubject('Admin bejelentkezés - ' . $user->username ) + ->send(); + } + } + public function actionLogout() { Yii::$app->user->logout(); diff --git a/common/components/Helper.php b/common/components/Helper.php index 207265b..949afdf 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -1,101 +1,184 @@ andFilterWhere( ['or', [ '<', $field , isset( $start ) ? $start : '1900-01-01' ] ,[ '>=' , $field , isset($end) ? $end : '3000-01-01' ] ] ); + public static function notInInterval($query, $field, $start, $end) { + $query->andFilterWhere ( [ + 'or', + [ + '<', + $field, + isset ( $start ) ? $start : '1900-01-01' + ], + [ + '>=', + $field, + isset ( $end ) ? $end : '3000-01-01' + ] + ] ); } - - public static function notPaid($query ,$field , $start,$end ){ - $query->andFilterWhere( ['or', [ '<', $field , isset( $start ) ? $start : '1900-01-01' ] ,[ '>=' , $field , isset($end) ? $end : '3000-01-01' ] ,[ "transfer.status" => Transfer::STATUS_NOT_PAID ] ] ); + public static function notPaid($query, $field, $start, $end) { + $query->andFilterWhere ( [ + 'or', + [ + '<', + $field, + isset ( $start ) ? $start : '1900-01-01' + ], + [ + '>=', + $field, + isset ( $end ) ? $end : '3000-01-01' + ], + [ + "transfer.status" => Transfer::STATUS_NOT_PAID + ] + ] ); } - public static function inInterval($query ,$field , $start,$end ){ - $query->andFilterWhere([ '>=', $field , $start ] ); - $query->andFilterWhere([ '<' , $field , $end ] ); + public static function inInterval($query, $field, $start, $end) { + $query->andFilterWhere ( [ + '>=', + $field, + $start + ] ); + $query->andFilterWhere ( [ + '<', + $field, + $end + ] ); } - - public static function queryInIntervalRule( $field , $start,$end ){ - return ['and',[ '>=', $field , $start ] , [ '<' , $field , $end ] ]; + public static function queryInIntervalRule($field, $start, $end) { + return [ + 'and', + [ + '>=', + $field, + $start + ], + [ + '<', + $field, + $end + ] + ]; } - - public static function queryExpireRule( $field_start,$field_end , $start,$end ){ - - return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ], ['<=' , $field_end , $end ] ]; + public static function queryExpireRule($field_start, $field_end, $start, $end) { + return [ + 'and', + [ + '<', + $field_start, + $end + ], + [ + '>=', + $field_end, + $start + ], + [ + '<=', + $field_end, + $end + ] + ]; } - - public static function queryValidRule( $field_start ,$field_end , $start,$end ){ - return ['and' ,['<',$field_start, $end], ['>=' , $field_end , $start ] ]; + public static function queryValidRule($field_start, $field_end, $start, $end) { + return [ + 'and', + [ + '<', + $field_start, + $end + ], + [ + '>=', + $field_end, + $start + ] + ]; } - - public static function sqlInIntervalRule( $field , $paramStart,$paramEnd ){ - return ' ' .$field . ' >= ' . $paramStart . ' and ' . $field . ' < ' . $paramEnd ; + public static function sqlInIntervalRule($field, $paramStart, $paramEnd) { + return ' ' . $field . ' >= ' . $paramStart . ' and ' . $field . ' < ' . $paramEnd; } - - public static function sqlExpireRule( $field_start,$field_end , $paramStart,$paramEnd ){ - return ' ' .$field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' < ' . $paramEnd ; + public static function sqlExpireRule($field_start, $field_end, $paramStart, $paramEnd) { + return ' ' . $field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' < ' . $paramEnd; } - - public static function sqlValidRule( $field_start ,$field_end , $paramStart,$paramEnd ){ - return ' ' .$field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' >=' . $paramStart ; + public static function sqlValidRule($field_start, $field_end, $paramStart, $paramEnd) { + return ' ' . $field_start . ' < ' . $paramEnd . ' and ' . $field_end . ' >=' . $paramStart; } - - public static function queryAccountConstraint($query,$field){ - if ( !RoleDefinition::isAdmin() ){ - $query->innerJoin("user_account_assignment", $field . ' = user_account_assignment.id_account' ); - $query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]); + public static function queryAccountConstraint($query, $field) { + if (! RoleDefinition::isAdmin ()) { + $query->innerJoin ( "user_account_assignment", $field . ' = user_account_assignment.id_account' ); + $query->andWhere ( [ + 'user_account_assignment.id_user' => Yii::$app->user->id + ] ); } } - - - public static function roleLabels(){ - return [ - 'reception' => Yii::t('common/role' ,'Reception'), - 'admin' => Yii::t('common/role' ,'Administrator'), - 'employee' => Yii::t('common/role' ,'Alkalmazott'), + public static function roleLabels() { + return [ + 'reception' => Yii::t ( 'common/role', 'Reception' ), + 'admin' => Yii::t ( 'common/role', 'Administrator' ), + 'employee' => Yii::t ( 'common/role', 'Alkalmazott' ) ]; } - - public static function roleDefinitions(){ - return [ - 'employee' => [ - 'canAllow' => [ 'employee'], + public static function roleDefinitions() { + return [ + 'employee' => [ + 'canAllow' => [ + 'employee' + ] ], - 'admin' => [ - 'canAllow' => ['admin','reception','employee'], - ], - 'reception' => [ - 'canAllow' => [ ], + 'admin' => [ + 'canAllow' => [ + 'admin', + 'reception', + 'employee' + ] ], + 'reception' => [ + 'canAllow' => [ ] + ] ]; } - - public static function flash($mode,$message){ - \Yii::$app->session->setFlash($mode, $message ); + public static function flash($mode, $message) { + \Yii::$app->session->setFlash ( $mode, $message ); } - - - public static function fixAsciiChars($in){ - $out = str_replace("ö", "0", $in); - $out = str_replace("Ö", "0", $out); + public static function fixAsciiChars($in) { + $out = str_replace ( "ö", "0", $in ); + $out = str_replace ( "Ö", "0", $out ); return $out; } - - public static function isCompanyMovar(){ - return \Yii::$app->params['company'] == 'movar'; + public static function isCompanyMovar() { + return \Yii::$app->params ['company'] == 'movar'; } - public static function isProductVisibilityAccount(){ - return \Yii::$app->params['product_visiblity'] == 'account'; + public static function isProductVisibilityAccount() { + return \Yii::$app->params ['product_visiblity'] == 'account'; + } + public static function getRealUserIp() { + $client = @$_SERVER ['HTTP_CLIENT_IP']; + $forward = @$_SERVER ['HTTP_X_FORWARDED_FOR']; + $remote = $_SERVER ['REMOTE_ADDR']; + + if (filter_var ( $client, FILTER_VALIDATE_IP )) { + $ip = $client; + } elseif (filter_var ( $forward, FILTER_VALIDATE_IP )) { + $ip = $forward; + } else { + $ip = $remote; + } + + return $ip; + } + public static function getGeoIp() { + $ip = Helper::getRealUserIp (); + $details = json_decode ( file_get_contents ( "http://ipinfo.io/{$ip}/json" ) ); + return $details; } - } \ No newline at end of file diff --git a/common/components/accountstate/AccountStateMail.php b/common/components/accountstate/AccountStateMail.php index cf7bf77..105ab3f 100644 --- a/common/components/accountstate/AccountStateMail.php +++ b/common/components/accountstate/AccountStateMail.php @@ -14,47 +14,54 @@ use common\components\DailyListing; class AccountStateMail extends Object { + public $controller; public $model; - + public $user; + public $account; + public $message; + public $details; public function init(){ + $this->user = User::findOne($this->model->id_user); + $this->account = Account::findOne($this->model->id_account); - } - - - public function sednMail(){ + $this->details = null; - $details = null; if ($this->model ->isTypeClose ()) { - + $prev; - if ($this->model ->type == AccountState::TYPE_CLOSE) { - if (isset ( $accountState->prev_state )) { - $prev = AccountState::findOne ( $accountState->prev_state ); + if ($this->model->type == AccountState::TYPE_CLOSE) { + if (isset ( $this->model->prev_state )) { + $prev = AccountState::findOne ( $this->model->prev_state ); } if (isset ( $prev )) { $this->model ->start_date = $prev->created_at; } } - $details = new DailyListing(); - $details->loadAccountState ( $this->model ); - - $details->readTotalEasy (); - $details->readTotalDetailed (); - $details->readTotalMedium (); - } + $this->details = new DailyListing(); + $this->details->loadAccountState ( $this->model ); + + $this->details->readTotalEasy (); + $this->details->readTotalDetailed (); + $this->details->readTotalMedium (); + } + } + + + public function sednMail(){ - $user = User::findOne($this->model->id_user); - $account = Account::findOne($this->model->id_account); $subject = $this->model->isTypeOpen() ? "Kassza nyitás " : "Kassza zárás"; - $subject .= " - " . $user->username ." - ". $account->name; + $subject .= " - " . $this->user->username ." - ". $this->account->name; - $mail = \Yii::$app->mailer->compose('account_state', [ + $this->message = \Yii::$app->mailer->compose('account_state', [ 'model' => $this->model, - 'details' => $details + 'details' => $this->details ]); - $mail->setFrom('noreplay@fitnessadmin.hu') + + $this->attachPdf(); + + $this->message->setFrom('noreplay@fitnessadmin.hu') ->setTo( \Yii::$app->params['notify_mail'] ) ->setSubject($subject ) ->send(); @@ -62,6 +69,30 @@ class AccountStateMail extends Object { } + protected function attachPdf(){ + $mpdf=new \mPDF('utf-8', 'A4-L'); + $mpdf->useSubstitutions=false; + $mpdf->simpleTables = true; + $mpdf->SetHeader( \Yii::$app->params[ "company_name" ] . " - Létrehozva: " .$user->username . ", ".\Yii::$app->formatter->asDatetime(time()) ); + $mpdf->setFooter('{PAGENO} / {nb}'); + + $stylesheet = file_get_contents( \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')); // external css + $mpdf->WriteHTML($stylesheet,1); + + + $mpdf->WriteHTML($this->controller->renderPartial("@common/views/account-state/account_state_pdf", [ + 'model' => $this->model, + 'details' => $this->details + ])); + $type = $this->model->isTypeOpen() ? "kassza_nyitas" : "kassza_zaras"; + $dt= "_letrehozva_".date("Ymd_His"). "_" . $this->user->username; + $fn= $type .$dt.".pdf"; + $content = $mpdf->Output($fn, 'S'); + + $this->message->attachContent($content, ['fileName' => $fn, 'contentType' => 'application/pdf']); + } + + } \ No newline at end of file diff --git a/common/config/params.php b/common/config/params.php index ad18215..a6086c8 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -2,6 +2,7 @@ return [ 'adminEmail' => 'rocho02@gmail.com', 'supportEmail' => 'rocho02@gmail.com', + 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, 'version' => 'v0.0.19', 'company' => 'movar',//gyor @@ -9,4 +10,7 @@ return [ 'product_visiblity' => 'account',// on reception which products to display. account or global 'notify_mail' => ['rocho02@gmail.com' ], 'mail_account_state_open' => true, + 'login_reception_email' => true, //if reception login should send email + 'login_admin_email' => true, //if admin login should send email + ]; diff --git a/common/mail/account_state.php b/common/mail/account_state.php index c0c627d..925643e 100644 --- a/common/mail/account_state.php +++ b/common/mail/account_state.php @@ -79,9 +79,6 @@ if ( $model ->type == AccountState::TYPE_OPEN ){ $details]);?>