[ 'class' => AccessControl::className (), 'only' => [ 'logout', 'signup' ], 'rules' => [ [ 'actions' => [ 'signup' ], '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' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null ] ]; } 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 = $this->getTotal (); $counts = ""; if (Yii::$app->params ['viewsCountsService']) $counts = $this->getCounts ( $totalRecords ); $news = [ ]; if (Yii::$app->params ['newsService']) { try { $news = $this->getNews (); } catch ( Exception $e ) { $news = [ ]; } } $nbMembers=$this->getNbMembers(); return $this->render ( 'index', [ 'counts' => $counts, 'contentleft' => "", 'contentright' => $counts, 'news' => $news, 'totalRecords' => $totalRecords, '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'] ); 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']; } return $this->render ( 'signup', [ 'model' => $model, 'countryList' => $countryList ] ); } 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' ] ) ); } public function getCounts($total) { $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') " ); $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 not in ('culture','specimen','unknown','eVoucher') " ); $dataReader = $command->queryAll (); $nbColSamples = 0; foreach ( $dataReader as $row ) { $nbColSamples = $row ["cnt"]; } $command = $connection->createCommand ( 'SELECT * FROM counts' ); $dataReader = $command->queryAll (); $counts = "Samples"; $taxa1 = [ ]; $taxa2 = [ ]; $col1 = [ ]; $col2 = [ ]; $col1b = [ ]; $col2b = [ ]; foreach ( $dataReader as $row ) { if ($row ['kind'] != "Genera" && $row ['kind'] != "Taxa" && $row ['kind'] != "Families" && $row ['kind'] != "Species" && $row ['kind'] != "Cultures" && $row ['kind'] != "Specimens" && $row ['kind'] != "Unknown" && $row ['kind'] != "eVouchers") { array_push ( $col1, explode ( " samples", $row ['kind'] ) [0] ); array_push ( $col2, $row ['counts'] ); } if ($row ['kind'] == "Cultures" || $row ['kind'] == "Specimens" || $row ['kind'] == "Unknown" || $row ['kind'] == "eVouchers") { array_push ( $col1b, explode ( " samples", $row ['kind'] ) [0] ); array_push ( $col2b, $row ['counts'] ); } if ($row ['kind'] == "Genera" || $row ['kind'] == "Families" || $row ['kind'] == "Species") { array_push ( $taxa1, explode ( " samples", $row ['kind'] ) [0] ); array_push ( $taxa2, $row ['counts'] ); } } $counts .= "
" . implode ( "
", $col1 ) . "
Repositories
"; $counts .= "
" . implode ( "
", $col2 ) . "
" . $nbColSamples . "
"; $counts .= "Vouchers"; $counts .= "
" . implode ( "
", $col1b ) . "
Collections
"; $counts .= "
" . implode ( "
", $col2b ) . "
" . $nbColVouchers . "
"; $counts = $counts . "Taxa"; $counts .= "
" . implode ( "
", $taxa1 ) . "
"; $counts .= "
" . implode ( "
", $taxa2 ) . "
"; $counts = $counts . "
Total "; $counts .= "
"; $counts .= "
" . $total . "
"; Yii::$app->db->close (); // Yii::info("getCounts: ".$counts); return $counts; } public function getTotal() { $connection = new \yii\db\Connection ( Yii::$app->db ); $connection->open (); $command = $connection->createCommand ( 'SELECT count(occurrenceid) as cnt FROM occurrence' ); $dataReader = $command->queryAll (); $total = 0; foreach ( $dataReader as $row ) { $total = $row ['cnt']; } Yii::$app->db->close (); // Yii::info("getCounts: ".$counts); return $total; } function getNbMembers(){ $connection = new \yii\db\Connection ( Yii::$app->db ); $connection->open (); $command = $connection->createCommand ( 'SELECT count(parentInstitutionID) as cnt FROM parentInstitution where parentInstitutionID!=38' ); $dataReader = $command->queryAll (); $total = 0; foreach ( $dataReader as $row ) { $total = $row ['cnt']; } Yii::$app->db->close (); // Yii::info("getCounts: ".$counts); return $total; } function getNews() { ini_set ( 'default_socket_timeout', 3 ); $news = @file_get_contents ( "http://wiki.bgbm.org/dnabankwiki/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 { echo $this->renderPartial ( 'feedback', [ 'model' => $model, 'errors' => $model->errors ] ); } } }