/** * Authenticates a user. * The example implementation makes sure if the username and password * are both 'demo'. * In practical applications, this should be changed to authenticate * against some persistent user identity storage (e.g. database). * @return boolean whether authentication succeeds. */ public function authenticate() { $user = User::model()->find('username=:username', array(':username' => $this->username)); if ($user) { if ($user->username !== $this->username) { $this->errorCode = self::ERROR_USERNAME_INVALID; } elseif ($user->password !== $user->hashPassword($this->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->errorCode = self::ERROR_NONE; $this->_id = $user->id; Yii::app()->user->setState('user_id', $user->id); $loggedInUser = $user->first_name . ' ' . $user->middle_name . ' ' . $user->last_name; Yii::app()->user->setState('loggedInUser', $loggedInUser); if ($user->is_mda) { Yii::app()->user->setState('is_mda', true); Yii::app()->user->setState('mda_id', $user->mda_id); $decisionModel = new EacDecision(); $pendingDecisions = $decisionModel->getPendingMdaDecisions($user->mda_id); $pendingDecisionsCount = count($pendingDecisions); if ($pendingDecisionsCount > 0) { Yii::app()->user->setState('pendingDecisions', $pendingDecisionsCount); } } else { Yii::app()->user->setState('is_mda', false); } } } return !$this->errorCode; }
public function getDecisionsApproachingDeadlineByMda($mda_id) { $criteria = new CDbCriteria(); $criteria->addInCondition('id', EacDecision::model()->getDecisionIdsFromResponsibleMdaMappings($mda_id)); $criteria->addInCondition("datediff(deadline,now())", [14, 7, 3]); $decisions = EacDecision::model()->find($criteria); return $decisions; }
public function exportDecisions($export_key) { if (!Yii::app()->user->checkAccess("Export Decisions")) { throw new CHttpException(403, 'You are not authorized to access this feature'); } if (isset($export_key)) { $export_key = $export_key; } else { throw new CHttpException(404, 'Invalid request'); } //get decision source $decisionSourceModel = EacLookup::model()->find('`key` = :key', [':key' => $export_key]); $models = EacDecision::model()->findAll('decision_source_id = :id', [':id' => $decisionSourceModel->id]); spl_autoload_unregister(array('YiiBase', 'autoload')); $phpExcelPath = Yii::getPathOfAlias('application.vendor.phpoffice'); include $phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php'; // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setCreator("EAMS Country TZ")->setLastModifiedBy("EAMs")->setTitle("EAMS TZ Decisions Export")->setSubject("EAMS TZ Decisions Export")->setDescription("EAMS TZ Decisions Export")->setKeywords("office 2007 openxml php")->setCategory("decisions"); $objPHPExcel->getActiveSheet()->setTitle('decisions'); // Add heading row $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Decision Reference')->setCellValue('B1', 'Description')->setCellValue('C1', 'Responsibility Center')->setCellValue('D1', 'Time Frame')->setCellValue('E1', 'Performance Indicators')->setCellValue('F1', 'Implementation Status')->setCellValue('G1', 'Status / Comments')->setCellValue('H1', 'ImplementationStatusID')->setCellValue('I1', 'id'); $rowCount = 2; foreach ($models as $model) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A{$rowCount}", $model->decision_reference)->setCellValue("B{$rowCount}", $model->description)->setCellValue("C{$rowCount}", $model->responsibility_center)->setCellValue("D{$rowCount}", $model->time_frame)->setCellValue("E{$rowCount}", $model->performance_indicators)->setCellValue("F{$rowCount}", $model->implementation_status_id)->setCellValue("G{$rowCount}", $model->sectoral_council_id . 'Status / Comments')->setCellValue("H{$rowCount}", $model->implementation_status_id)->setCellValue("I{$rowCount}", $model->eams_central_id); $rowCount++; } // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); // header('Content-Disposition: attachment;filename="template.xlsx"'); // header('Cache-Control: max-age=0'); $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel); //$objWriter->save('php://output'); $targetDir = Yii::getPathOfAlias('webroot') . '/uploads/exports/'; $filename = 'desicion_export_' . md5(time() . uniqid('export', true)) . '.xlsx'; $objWriter->save($targetDir . $filename); spl_autoload_register(array('YiiBase', 'autoload')); $fileExportModel = new EamsFilesExport(); $fileExportModel->name = $filename; $fileExportModel->export_key = $export_key; $fileExportModel->mime_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; $fileExportModel->file_extension = 'xlsx'; $fileExportModel->file_size = filesize($targetDir . $filename); $fileExportModel->date_created = date('Y-m-d H:i:s'); $fileExportModel->save(); $this->sendFileToEamsCentral($fileExportModel); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($id) { $model = new EacStatusLog(); $decision = EacDecision::model()->findByPk($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['EacStatusLog'])) { $model->attributes = $_POST['EacStatusLog']; $model->decision_id = $id; $model->approved = 0; //not approved $model->create_user_id = Yii::app()->user->id; $model->date_created = date('Y-m-d H:i:s'); $model->date_updated = date('Y-m-d H:i:s'); if ($model->save()) { if ($decision) { $decision->implementation_status_id = $model->status_id; $decision->save(); Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Status updated successfully.'); } $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('is_mda' => 0), 'OR'); $mdas = $decision->getAssignedMdasIds(); $criteria->addInCondition('mda_id', $mdas); $recipients = User::getNotificationSubscribers($criteria); $loggedInUser = User::model()->findByPk(Yii::app()->user->user_id); $from = ""; if (Yii::app()->user->is_mda) { $mda = $loggedInUser->mda; $from = $mda->description; } else { $meacOffice = $loggedInUser->meacOffice; $from = $meacOffice->description; } $message = "Decision {$decision->decision_reference}-({$decision->description}) has been updated by " . Yii::app()->user->getState('loggedInUser') . " from {$from}<br />"; $message .= $model->status_narrative . "<br />"; $message .= "For more information click " . TbHtml::link("here", Yii::app()->getBaseUrl(true) . "/index.php?r=eacDecision/view&id={$decision->id}"); $this->notify($recipients, 'Decision Update', $message); $this->redirect(array('/eacDecision/view', 'id' => $id)); } } $this->render('create', array('model' => $model, 'decision' => $decision)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return EacDecision the loaded model * @throws CHttpException */ public function loadModel($id) { $model = EacDecision::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
'pointFormat' => '{series.name}: <b>{point.percentage:.1f}%</b>' ), 'plotOptions' => array( 'allowPointSelect' => true, 'cursor' => 'pointer', 'dataLabels' => array( 'enabled' => true, 'format' => '<b>{point.name}</b>: {point.percentage:.1f} %', 'style' => array( // 'color'=> 'js:(Highcharts.theme && Highcharts.theme.contrastTextColor)' || 'black' ) ) ), 'series' => array( array( 'type' => 'pie', 'name' => 'Percentage', 'data' => EacDecision::getImplementationStatusDistribution() ) ) ), )); ?> </div>
public function actionSaveDecisions() { if (isset($_POST['data'])) { $data = json_decode($_POST['data']); $internalScId = NULL; $eamsCentralScId = $data[0]->sectoral_council_id; if (!empty($eamsCentralScId)) { $scModel = EacLookup::model()->find('eams_central_id=:id', [':id' => $eamsCentralScId]); $internalScId = $scModel->id; } foreach ($data as $item) { $decision = new EacDecision(); $decision->eams_central_id = $item->eams_central_id; $decision->decision_reference = $item->decision_reference; $decision->decision_source_id = $item->decision_source_id; $decision->sectoral_council_id = $internalScId; $decision->decision_date = $item->decision_date; $decision->description = $item->description; $decision->budgetary_implications = $item->budgetary_implications; $decision->time_frame = $item->time_frame; $decision->performance_indicators = $item->performance_indicators; $decision->responsibility_center = $item->responsibility_center; $decision->meeting_no = $item->meeting_no; $decision->date_created = date('Y-m-d H:i:s'); $decision->create_user_id = Yii::app()->user->id; if (!$decision->decisionExists()) { $decision->save(); } //if } //foreach } }