user->can('validateUser')){ $this->goHome(); } 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; } return true; // or false to not run the action } /** * The method renders the validation site for a single user given a token. * * @param unknown $token: * The activation key * @return \yii\web\Response|Ambigous */ public function actionValidation($token) { if (Yii::$app->user->isGuest ) { \Yii::$app->session ['activationKey'] = $token; return $this->redirect ( Yii::$app->getUrlManager ()->createUrl ( [ 'site/login' ] ) ); } if (! empty ( $token )) { // Redirect to main validation page if user-activation_link tupel where already treated. if (User::findByActivationKey ( $token ) === 'User active or rejected') { // \Yii::$app->getSession()->setFlash('succes', 'The user has already been validated or rejected.'); $this->redirectToOverview (); } $model = new ValidationForm ( $token ); if (isset ( $_POST ['accept-button'] )) { $user = User::findByActivationKey ( $token ); if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { $user->addComment ( $model->comment ); } $user->validateUser (); $user->sendMail ( 'userIsValidated', 'Your request to join the '.Yii::$app->params['siteTitle'] ); $this->redirectToOverview (); } if (isset ( $_POST ['reject-button'] )) { $user = User::findByActivationKey ( $token ); if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) { $user->addComment ( $model->comment ); } $user->rejectUser (); $user->sendMail ( 'userIsRejected', 'Your request to join the '.Yii::$app->params['siteTitle'] ); $this->redirectToOverview (); } return $this->render ( 'validation', [ 'model' => $model ] ); } else { // Yii::$app->getSession()->setFlash('succes', 'No users to validate!'); $this->redirectToOverview (); } } /* * A helper function which is written to improve code lisibility * @return \yii\web\Response */ public function redirectToOverview() { return $this->redirect ( Yii::$app->getUrlManager ()->createUrl ( [ 'validation/overview' ] ) ); } /** * This method renders the overview site for user validation, by passing an array * of all user having status inactive. * * @return Ambigous */ public function actionOverview() { $users_to_validate = User::findAll ( [ 'status' => User::STATUS_INACTIVE ] ); return $this->render ( 'overview', [ 'users_to_validate' => $users_to_validate ] ); } /** * renders the site which allows to enter a new contact person * @return \yii\web\Response|Ambigous */ public function actionContactperson(){ $model = new ContactForm(); if($model->load ( Yii::$app->request->post () ) && $model->validate ()){ if(DBInterface::addContact($model)){ Yii::$app->session->setFlash("success", 'The new contact is now in your database!'); return $this->redirect('contact'); } else{ Yii::$app->session->setFlash('error', 'There already is a contact with this email!'); } } if(isset($_GET['parentInstitutionID'])) { $model->parentInstitution = $_GET['parentInstitutionID']; } else $model->parentInstitution = ""; return $this->render('contactperson', ['model'=>$model]); } /** * Renders the page which allows to enter a new insititution * @return Ambigous */ public function actionNew(){ $modal = new InstitutionForm(); if($modal->load ( Yii::$app->request->post () ) && $modal->validate ()){ DBInterface::addInstitution($modal); $LastInstitution = DBInterface::getLastInstitution(); $institutionID = ArrayHelper::getColumn($LastInstitution, 'parentInstitutionID'); $this->redirect('contactperson?parentInstitutionID='.$institutionID[0]); } return $this->render('new', ['modal'=>$modal]); } /** * Renders the page which allows to enter a new insititution * @return Ambigous */ public function actionInstitution(){ $searchModel = new InstitutionForm(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->query->andFilterWhere(['!=', 'parentInstitutionID', '38']); $sort = $dataProvider->getSort(); $sort->defaultOrder = ['institutionFullName' => SORT_ASC]; $dataProvider->pagination->pageSize=25; return $this->render('institution', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } /** * Renders the page which allows to enter a new insititution * @return Ambigous */ public function actionContact(){ $searchModel = new ContactForm(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->query; $dataProvider->pagination->pageSize=25; return $this->render('contact', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } public function actionEditinstitution($institutionid){ $inst = DBInterface::getInstitution($institutionid); $modal=new InstitutionForm(); $modal->institutionFullName=$inst['institutionFullName']; $modal->institutionShort=$inst['institutionShort']; $modal->city=$inst['city']; $modal->country=$inst['iso']; $modal->Latitude=$inst['Latitude']; $modal->Longitude=$inst['Longitude']; $modal->logoURL=$inst['logoURL']; $modal->memberStatus=$inst['memberStatus']; $modal->votingMember=$inst['votingMember']; $modal->CITES_code=$inst['CITES_code']; $modal->dateOfJoining=$inst['dateOfJoining']; $modal->onlineSince=$inst['onlineSince']; $modal->IPEN_member=$inst['IPEN_member']; $modal->parentInstitutionID=$institutionid; $modal->isMember=$inst['isMember']; $modal->isPartner=$inst['isPartner']; $modal->isConsortium=$inst['isConsortium']; $modal->isMemberOfConsortium=$inst['isMemberOfConsortium']; $modal->urlMTA=$inst['urlMTA']; $modal->urlLoanPolicies=$inst['urlLoanPolicies']; if($modal->load ( Yii::$app->request->post () ) && $modal->validate ()){ DBInterface::updateInstitution($modal); $this->redirect('institution'); } return $this->render('editinstitution', ['modal'=>$modal]); } public function actionEditcontact($contactid){ $contact= DBInterface::getContact($contactid); $modal=new ContactForm(); $modal->name=$contact['name']; $modal->email=$contact['email']; $modal->role=$contact['role']; $modal->notes=$contact['notes']; $modal->shoppingSystem=$contact['shoppingSystem']; $modal->phone=$contact['phone']; $modal->parentInstitution=$contact['parentInstitution']; //$modal->fk_parentInstitutionID=$contact['fk_parentInstitutionID']; $modal->contactID=$contactid; if($modal->load ( Yii::$app->request->post () ) && $modal->validate ()){ DBInterface::updateContact($modal); $this->redirect('contact'); } /* $inst =DBInterface::getInstitutions(); $institutions = []; foreach($inst as $i){ $institutions[$i['parentInstitutionID']]=$i['institutionFullName']." (".$i['country'].")"; }*/ return $this->render('editcontact', ['modal'=>$modal]); } /** * renders an admin panel site * @return Ambigous */ public function actionAdminpanel(){ return $this->render('adminpanel'); } }