[ 'class' => AccessControl::className (), 'only' => [ 'logout', 'signup' ], 'rules' => [ [ 'actions' => [ 'signup', 'captcha' ], 'allow' => true, 'roles' => [ '?' ] ], [ 'actions' => [ 'logout' ], 'allow' => true, 'roles' => [ '@' ] ] ] ], 'verbs' => [ 'class' => VerbFilter::className (), 'actions' => [ 'logout' => [ 'post' ] ] ] ]; } /** * @inheritdoc */ public function actions() { return [ /* 'error' => [ 'class' => 'yii\web\ErrorAction' ],*/ 'captcha' => [ 'class' => 'common\models\CaptchaRefreshableAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, ] ]; } public function actionError() { $exception = Yii::$app->errorHandler->exception; $name = ""; $message = ""; $name = $exception->getName(); $message = $exception->getMessage(); if ($exception !== null) { return $this->render('error', ['exception' => $exception, 'message' => $message, 'name' => $name]); } } public function actionIndex() { // Redirect admin to validation page, if the admin accessed the site following // an activation link // if (Yii::$app->params ['useLogin'] && in_array ( Yii::$app->request->userIP, Yii::$app->params ['authorizedIPs'] )) // $this->layout = "mainIcons"; if (isset ( \Yii::$app->session ['activationKey'] )) { $token = \Yii::$app->session ['activationKey']; \Yii::$app->session->remove ( 'activationKey' ); return $this->redirect ( Yii::$app->getUrlManager ()->createAbsoluteUrl ( [ 'validation/validation', 'token' => $token ] ) ); } $totalRecords = Carousel::getCountsTotal (); //$totalRecords = ""; $totalSamples = Carousel::getCountsSamples (); $totalEnviroSamples = Carousel::getCountsEnviroSamples (); $totalVouchers = Carousel::getCountsVouchers (); $totalSpecies = Carousel::getCountsSpecies (); $counts = ""; if (Yii::$app->params ['viewsCountsService']) $counts = $this->getCounts ( $totalRecords ); $news = [ ]; if (Yii::$app->params ['newsService']) { try { $news = WikiAPI::getNewsoldpage (); } catch ( Exception $e ) { $news = [ ]; } } $nbMembers=Carousel::getNbMembers(); return $this->render ( 'index', [ 'counts' => $counts, 'contentleft' => "", 'contentright' => $counts, 'news' => $news, 'totalRecords' => $totalRecords, 'totalSamples' => $totalSamples, 'totalEnviroSamples' => $totalEnviroSamples, 'totalVouchers' => $totalVouchers, 'totalSpecies' => $totalSpecies, 'nbMembers'=>$nbMembers ] ); } public function actionCookies() { return $this->render ( 'cookies' ); } /** * renders the login site and resets the session timeout * * @return \yii\web\Response|Ambigous */ public function actionLogin() { Yii::$app->session->set ( 'userSessionTimeout', time () + Yii::$app->params ['sessionTimeoutSeconds'] ); /* set cookie for individual instance */ $cookie = Yii::$app->response->cookies; $cookie = new \yii\web\Cookie ([ 'name' => 'siteName', 'value' => Yii::$app->params['siteName'], 'expire' => time() + 86400 * 365, ]); Yii::$app->getResponse()->getCookies()->add($cookie); //check cookie is exist or not if(! \Yii::$app->user->isGuest) { return $this->goHome (); } $model = new LoginForm (); if ($model->load ( Yii::$app->request->post () ) && $model->login ()) { if (Yii::$app->session->get ( 'comeFrom', NULL ) != NULL) return $this->redirect ( Yii::$app->session->get ( 'comeFrom' ) ); else return $this->goHome (); } else { Yii::$app->session->set ( 'comeFrom', Yii::$app->request->referrer ); return $this->render ( 'login', [ 'model' => $model ] ); } } /** * Overrides the parent function, in order to check before each action whether * the user is still logged-in or whether he was logged out due to long inactivity. * (non-PHPdoc) * * @see \yii\web\Controller::beforeAction() */ public function beforeAction($action) { if (! parent::beforeAction ( $action )) { return false; } // Check only when the user is logged in if (! Yii::$app->user->isGuest) { if (Yii::$app->session ['userSessionTimeout'] < time ()) { Yii::$app->user->logout (); $this->goHome (); Yii::$app->session->setFlash ( 'success', 'You have been logged out!' ); } else { Yii::$app->session->set ( 'userSessionTimeout', time () + Yii::$app->params ['sessionTimeoutSeconds'] ); return true; } } else { return true; } } /** * logs the user out and redirects to main page. * * @return \yii\web\Response */ public function actionLogout() { Yii::$app->user->logout (); return $this->goHome (); } public function actionContact() { $model = new ContactForm (); if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { if ($model->sendEmail ( Yii::$app->params ['adminEmail'] )) { Yii::$app->session->setFlash ( 'success', 'Thank you for contacting us. We will respond to you as soon as possible.' ); } else { Yii::$app->session->setFlash ( 'error', 'There was an error sending email.' ); Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'An email could not be sent' )->setTextBody ( 'actionContact: check the Email address ' . $model->email )->send (); } return $this->refresh (); } else { return $this->render ( 'contact', [ 'model' => $model ] ); } } public function actionAbout() { { if (Yii::$app->request->isPjax) { throw new \ErrorException (); return $this->renderPartial ( 'about' ); } else { return $this->render ( 'about' ); } } } /** * renders the signup page and is responsible for form validation. * redirects the user to "home" after signup. Due to manual user validation * the user is not automatically logged-in after signup. * * @return \yii\web\Response|Ambigous */ public function actionSignup() { $model = new SignupForm (); if ($model->load ( Yii::$app->request->post () )) { if ($user = $model->signup ()) { Yii::$app->getSession ()->setFlash ( 'success', 'Your registration will be validated manually' ); return $this->goHome (); } } $countries = DBInterface::getCountries (); $countryList = [ ]; foreach ( $countries as $i ) { $countryList [$i ['iso']] = $i ['country']; } if(Yii::$app->params ['ipenList'] == true) { $ipen = DBInterface::getIpenlist (); $ipenList = [ ]; foreach ( $ipen as $i ) { $ipenList [$i ['acronym']] = $i ['acronym']." (". $i ['name'] .")"; } } else { $ipenList = []; } return $this->render ( 'signup', [ 'model' => $model, 'countryList' => $countryList, 'ipenList' => $ipenList ] ); } public function actionRequestPasswordReset() { $model = new PasswordResetRequestForm (); if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { if ($model->sendEmail ()) { Yii::$app->getSession ()->setFlash ( 'success', 'Check your email for further instructions.' ); return $this->goHome (); } else { Yii::$app->getSession ()->setFlash ( 'error', 'Sorry, we are unable to reset password for email provided.' ); Yii::$app->mailer->compose ()->setFrom ( Yii::$app->params ['noreplyMail'] )->setTo ( Yii::$app->params ['feedbackMail'] )->setSubject ( 'An email could not be sent' )->setTextBody ( 'actionRequestPasswordReset: check the Email address ' . $model->email )->send (); } } return $this->render ( 'requestPasswordResetToken', [ 'model' => $model ] ); } public function actionResetPassword($token) { try { $model = new ResetPasswordForm ( $token ); } catch ( InvalidParamException $e ) { throw new BadRequestHttpException ( $e->getMessage () ); } if ($model->load ( Yii::$app->request->post () ) && $model->validate () && $model->resetPassword ()) { Yii::$app->getSession ()->setFlash ( 'success', 'New password was saved.' ); return $this->goHome (); } return $this->render ( 'resetPassword', [ 'model' => $model ] ); } public function actionSearch() { return $this->redirect ( Yii::$app->getUrlManager ()->createUrl ( [ 'search/query' ] ) ); } public function actionValidation() { return $this->redirect ( Yii::$app->getUrlManager ()->createUrl ( [ 'validation/validation' ] ) ); } public function actionAccount() { return $this->redirect ( Yii::$app->getUrlManager ()->createUrl ( [ 'account/profile' ] ) ); } //TODO Funktion in ein Model auslagern public function getCounts() { $jsonfile = Carousel::getCounts(); $json_array = json_decode($jsonfile); if(isset($json_array->{'nbFamilies'})) { $nbFamilies = $json_array->{'nbFamilies'}; } else { $nbFamilies = ""; } if(isset($json_array->{'nbGenera'})) { $nbGenera = $json_array->{'nbGenera'}; } else { $nbGenera = ""; } if(isset($json_array->{'nbSpecies'})) { $nbSpecies = $json_array->{'nbSpecies'}; } else { $nbSpecies = ""; } if(isset($json_array->{'samples'}->{'DNA'})) { $nbDNA = $json_array->{'samples'}->{'DNA'}; } else { $nbDNA = ""; } if(isset($json_array->{'samples'}->{'tissue'})) { $nbTissue = $json_array->{'samples'}->{'tissue'}; } else { $nbTissue = ""; } if(isset($json_array->{'samples'}->{'environmental sample'})) { $nbEnviro = $json_array->{'samples'}->{'environmental sample'}; } else { $nbEnviro = ""; } if(isset($json_array->{'samples'}->{'culture'})) { $nbCulture = $json_array->{'samples'}->{'culture'}; } else { $nbCulture = ""; } if(isset($json_array->{'samples'}->{'eVoucher'})) { $nbEVoucher = $json_array->{'samples'}->{'eVoucher'}; } else { $nbEVoucher = ""; } if(isset($json_array->{'samples'}->{'specimen'})) { $nbSpecimen = $json_array->{'samples'}->{'specimen'}; } else { $nbSpecimen = ""; } if(isset($json_array->{'samples'}->{'unknown'})) { $nbUnknown = $json_array->{'samples'}->{'unknown'}; } else { $nbUnknown = ""; } if(isset($json_array->{'nbSamples'})) { $nbTotal = $json_array->{'nbSamples'}; } else { $nTotal = ""; } $connection = new \yii\db\Connection ( Yii::$app->db ); $connection->open (); $command = $connection->createCommand ( "SELECT count(distinct concat(IFNULL(institution,'institutionName'),', ',IFNULL(city,'CityName'))) as cnt FROM occurrence join unitkind on unitkindid=fk_kindofunitid join bio_datasource on id=fk_datasourceid where kindofunit_clean in ('culture','specimen','unknown','eVoucher')" . Yii::$app->params['thematicB-HITfilter']); $dataReader = $command->queryAll (); $nbColVouchers = 0; foreach ( $dataReader as $row ) { $nbColVouchers = $row ["cnt"]; } $command = $connection->createCommand ( "SELECT count(distinct concat(IFNULL(institution,'institutionName'),', ',IFNULL(city,'CityName'))) as cnt FROM occurrence join unitkind on unitkindid=fk_kindofunitid join bio_datasource on id=fk_datasourceid where kindofunit_clean in ('DNA','tissue','environmental sample')" . Yii::$app->params['thematicB-HITfilter']); $dataReader = $command->queryAll (); $nbColSamples = 0; foreach ( $dataReader as $row ) { $nbColSamples = $row ["cnt"]; } $counts = "Members "; $counts .= ""; $counts = $counts . "Samples"; if($nbDNA > 0) { $counts .= "
DNA
"; $counts .= "
" . number_format($nbDNA) . "
"; } if($nbTissue > 0) { $counts .= "
Tissues
"; } $counts .= "
" . number_format($nbTissue) . "
"; if($nbEnviro > 0) { $counts .= "
Enviros
"; $counts .= "
" . number_format($nbEnviro) . "
"; } if($nbColSamples > 0) { $counts .= "
Repositories
"; $counts .= "
" . number_format($nbColSamples) . "
"; } $counts .= "Vouchers"; if($nbCulture > 0) { $counts .= "
Cultures
"; $counts .= "
" . number_format($nbCulture) . "
";} if($nbEVoucher > 0) { $counts .= "
eVouchers
"; $counts .= "
" . number_format($nbEVoucher) . "
";} if($nbSpecimen > 0) { $counts .= "
Specimens
"; $counts .= "
" . number_format($nbSpecimen) . "
";} if($nbUnknown > 0) { $counts .= "
Unknown
"; $counts .= "
" . number_format($nbUnknown) . "
";} if($nbColVouchers > 0) { $counts .= "
Collections
"; $counts .= "
" . number_format($nbColVouchers) . "
"; } $counts = $counts . "Taxa"; $counts .= "
Families
"; $counts .= "
" . number_format($nbFamilies) . "
"; $counts .= "
Genera
"; $counts .= "
" . number_format($nbGenera) . "
"; $counts .= "
Species
"; $counts .= "
" . number_format($nbSpecies) . "
"; $counts = $counts . "
Total records online"; $counts .= "
"; $counts .= "
" . number_format($nbTotal) . "
"; Yii::$app->db->close (); return $counts; } //TODO Funktion löschen, siehe common/models/WikiAPI /*function getNews() { ini_set ( 'default_socket_timeout', 3 ); $news = @file_get_contents ( "http://wiki.bgbm.org/ggbnwiki/api.php?action=parse&prop=sections&page=News&format=json" ); if (! $news) $news = [ ]; else { if (strpos ( $news, "internal_api_error" ) > 0) return [ ]; else try { $jsonnews = json_decode ( $news ); $newsitems = $jsonnews->parse->sections; $news = [ ]; $year = date ( "Y" ); foreach ( $newsitems as $newsitem ) { if (strpos ( explode("-", $newsitem->line)[0], strval ( $year ) )) array_push ( $news, [ $newsitem->line, "http://wiki.ggbn.org/ggbn/News#" . $newsitem->anchor ] ); } if (sizeof ( $news ) === 0) { // get last year $year --; foreach ( $newsitems as $newsitem ) { $tmp = $newsitem->line; if (stripos ( explode("-", $newsitem->line)[0], strval ( $year ) )) array_push ( $news, [ $newsitem->line, "http://wiki.ggbn.org/ggbn/News#" . $newsitem->anchor ] ); } } } catch ( Exception $e ) { $news = [ ]; } } return $news; } */ public function actionFeedback() { $model = new FeedbackForm (); if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { if ($model->sendEmail ()) { Yii::$app->session->setFlash ( 'success', 'Thank you for your feedback.' ); } else { Yii::$app->session->setFlash ( 'error', 'There was an error sending email.' ); } // Yii::info ( "FEEDBACK " . $model->getURL () ); // Yii::info ( "URL " . Yii::$app->request->referrer ); if (empty ( $model->getURL () )) { if (empty ( Yii::$app->request->referrer )) return $this->goHome (); else return $this->redirect ( Yii::$app->request->referrer ); } else return $this->redirect ( $model->getURL () ); } else { return $this->renderPartial ( 'feedback', [ 'model' => $model, 'errors' => $model->errors ] ); } } }