public function actionIndex() { $form = new EmployeeLogin(); if (isset($_POST['EmployeeLogin'])) { $form->setAttributes($_POST['EmployeeLogin']); if ($form->validate()) { Yii::app()->user->login($form->identity); AdminUser::model()->deleteAll('userid=:id', array(':id' => Yii::app()->user->id)); // Update admin login table $admin = new AdminUser(); $admin->save(); // Add to session the last time we clicked Yii::app()->session['admin_clicked'] = time(); fok(at('Thank You! You are now logged in.')); // Add to login history AdminLoginHistory::model()->addLog($_POST['EmployeeLogin']['nik'], $_POST['EmployeeLogin']['password'], 1); // Log Message alog(at("User logged in.")); // Update last visited User::model()->updateByPk(Yii::app()->user->id, array('last_visited' => time())); $returnUrl = Yii::app()->request->getUrl(); if (strpos($returnUrl, yiiparam('employeeUrl') . '?r=login') !== false) { $returnUrl = array('/'); } $this->redirect($returnUrl); } else { ferror(at('Sorry, There were errors with the information provided.')); // Add to login history AdminLoginHistory::model()->addLog($_POST['EmployeeLogin']['nik'], $_POST['EmployeeLogin']['password'], 0); } } $this->render('login', array('form' => $form)); }
public function moveDataToRecap() { try { $query = "\n\t\t\t\tINSERT INTO attendance_presences_recap (employee_id, date, shift_id, check_in, check_out, break_out, break_in, total_hours, is_late, created_at ) \n\t\t\t\tSELECT employee_id, date, shift_id\n\t\t\t\t\t, min(case type when 'CI' then presence_date else NULL end) as `CheckIn`\n\t\t\t\t\t, max(case type when 'CO' then presence_date else NULL end) as `CheckOut`\n\t\t\t\t\t, max(case type when 'BO' then presence_date else NULL end) as `BreakOut`\n\t\t\t\t\t, min(case type when 'BI' then presence_date else NULL end) as `BreakIn`\n\t\t\t\t\t, 0, 0, now()\n\t\t\t\tFROM (SELECT employee_id, date, case type when 'LV' then 2 else (case type when 'S' then 3 else (case when shift_id IS NULL then 1 else shift_id end) end) end AS `shift_id`, type, presence_date\n\t\t\t\t\t\tFROM `attendance_presences`\n\t\t\t\t\t\tWHERE date BETWEEN '" . $this->start_date . "' AND '" . $this->end_date . "') AS A\n\t\t\t\tGROUP BY employee_id, date, shift_id\n\t\t\t"; $command = Yii::app()->db->createCommand($query); $command->execute(); fok(at('Data recapitulation successfully Generated.')); } catch (Exception $e) { ferror(at('Failed to generate data recapitulation. \\n' . $e)); exit; $transaction->rollBack(); } }
public function init() { // Login required if (Yii::app()->getController()->id != 'login') { $returnUrl = Yii::app()->request->getUrl(); if (strpos($returnUrl, '/admin') === false) { $returnUrl = array('/admin'); } Yii::app()->user->setReturnUrl($returnUrl); } // Make sure we have access if (!Yii::app()->user->id || !checkAccess('admin')) { // Do we need to login if (!Yii::app()->user->id && Yii::app()->getController()->id != 'login') { $this->redirect(array('/admin/login')); } // Make sure we are not in login page if (Yii::app()->getController()->id != 'login') { throw new CHttpException(at('Sorry, You are not allowed to enter this section.')); } } // Make sure we have a valid admin user record if (Yii::app()->getController()->id != 'login' && Yii::app()->user->id && !AdminUser::model()->exists('userid=:id', array(':id' => Yii::app()->user->id))) { Yii::app()->user->logout(); ferror(at('Your session expired. Please login.')); $this->redirect(array('/admin/login')); } // Check if we haven't clicked more then X amount of time $maxIdleTime = 60 * 60 * getParam('admin_logged_in_time', 5); // 5 hour default // Were we using an old session if (Yii::app()->getController()->id != 'login' && time() - $maxIdleTime > Yii::app()->session['admin_clicked']) { // Loguser out and redirect to login AdminUser::model()->deleteAll('userid=:id', array(':id' => Yii::app()->user->id)); Yii::app()->user->logout(); ferror(at('Your session expired. Please login.')); $this->redirect(array('/admin/login')); } // Delete old records AdminUser::model()->deleteAll('lastclick_time < :time', array(':time' => time() - $maxIdleTime)); // Update only if this is not an ajax request if (!request()->isAjaxRequest) { // Update record info Yii::app()->session['admin_clicked'] = time(); AdminUser::model()->updateAll(array('lastclick_time' => time(), 'location' => Yii::app()->getController()->id), 'userid=:id', array(':id' => Yii::app()->user->id)); } // Add Breadcrumb $this->addBreadCrumb(at('Dashboard'), array('index/index')); parent::init(); }
public function actionUpgrade($id) { // print_r($_POST);die(); $employee = $this->loadModel($id); $model = new EmployeeSalaryUpgrade(); if (isset($_POST['EmployeeSalaryUpgrade']) or isset($_POST['is_ajax'])) { if (isset($_POST['EmployeeSalaryUpgrade'])) { $model->attributes = $_POST['EmployeeSalaryUpgrade']; } else { $model->attributes = $_POST; } // print_r($model);die(); $employee->department_id = $model->department_id; $employee->section_id = $model->section_id; $employee->position_id = $model->position_id; $employee->level_id = $model->level_id; $employee->grade_id = $model->grade_id; $employee->city_area_id = $model->city_area_id; if (!$employee->save()) { ferror(at('Cannot upgrade employee grade.')); $_POST['ajax_error'] = 'Cannot upgrade employee grade.'; } else { if (!$employee->saveSalary(true)) { ferror(at('Cannot save new salary.')); $_POST['ajax_error'] = ''; } } } else { $model->id = $id; $model->department_id = $employee->department_id; $model->section_id = $employee->section_id; $model->position_id = $employee->position_id; $model->level_id = $employee->level_id; $model->grade_id = $employee->grade_id; $model->city_area_id = $employee->city_area_id; } if (isset($_POST['is_ajax'])) { echo json_encode($_POST); } else { $this->render('upgrade', array('model' => $model)); } }
public function ImportFile($model, $table, $columns) { if ($model->validate()) { $csvFile = CUploadedFile::getInstance($model, 'file'); $tempLoc = $csvFile->getTempName(); $rnd = rand(0, 9999); $fileName = importPaths("{$rnd}-{$csvFile}"); $csvFile->saveAs($fileName); $sql = "LOAD DATA INFILE '" . $fileName . "'\n\t\t\t\tINTO TABLE `" . $table . "`\n\t\t\t\tFIELDS TERMINATED BY ','\n\t\t\t\tENCLOSED BY '\"'\n\t\t\t\tLINES TERMINATED BY '\r\n'\n\t\t\t\tIGNORE 1 LINES\n\t\t\t\t({$columns})\n\t\t\t\t"; $connection = Yii::app()->db; $transaction = $connection->beginTransaction(); try { $connection->createCommand($sql)->execute(); $transaction->commit(); fok(at('Data successfully imported.')); } catch (Exception $e) { ferror(at('Failed to import data. \\n' . $e)); exit; $transaction->rollBack(); } } }
public function moveDataImport($table_name, $table_name_temp) { try { $query = "\n\t\t\t\tINSERT INTO " . $table_name . " (employee_id, date, shift_id, type, presence_date) \n\t\t\t\tSELECT * \n\t\t\t\tFROM " . $table_name_temp . "\n\t\t\t\tWHERE concat(employee_id, date, case when shift_id IS NULL then '' else shift_id end, type, case when presence_date IS NULL then '' else presence_date end) NOT IN \n\t\t\t\t\t(SELECT concat(employee_id, date, case when shift_id IS NULL then '' else shift_id end, type, case when presence_date IS NULL then '' else presence_date end) \n\t\t\t\t\tFROM " . $table_name . ");\n\t\t\t"; $command = Yii::app()->db->createCommand($query); $command->execute(); fok(at('Data successfully Saved.')); } catch (Exception $e) { ferror(at('Failed to save data. \\n' . $e)); exit; $transaction->rollBack(); } }
/** * view city action */ public function actionView() { // Check Access checkAccessThrowException('op_uscities_viewpages'); if (isset($_GET['id']) && ($model = USCity::model()->findByPk($_GET['id']))) { alog(at("Viewed City Record '{name}'.", array('{name}' => $model->city_name))); // Add Breadcrumb $this->addBreadCrumb(at('Viewing City')); $this->title[] = at('Viewing City Record "{name}"', array('{name}' => $model->city_name)); // Display form $this->render('view', array('model' => $model)); } else { ferror(at('Could not find that ID.')); $this->redirect(array('city/index')); } }
/** * view help topic action */ public function actionView() { // Check Access checkAccessThrowException('op_helptopics_view'); if (isset($_GET['id']) && ($model = HelpTopic::model()->findByPk($_GET['id']))) { alog(at("Viewed Help Topic '{name}'.", array('{name}' => $model->name))); // Add Breadcrumb $this->addBreadCrumb(at('Viewing Help Topic')); $this->title[] = at('Viewing Help Topic "{name}"', array('{name}' => $model->name)); // Display form $this->render('view', array('model' => $model)); } else { ferror(at('Could not find that ID.')); $this->redirect(array('helptopics/index')); } }
/** * Delete help topic action */ public function actionDelete() { // Check Access checkAccessThrowException('op_personalmessages_delete'); if (isset($_GET['id']) && ($model = PersonalMessageTopic::model()->findByPk($_GET['id']))) { alog(at("Deleted Personal Message '{name}'.", array('{name}' => $model->title))); // Make sure we are allowed to delete this if ($model->author_id != Yii::app()->user->id) { ferror(at('Sorry, You are not the author of this personal message so you can not delete it.')); alog(at("Tried Deleting a Personal Message '{name}' When he is not the author.", array('{name}' => $model->title))); $this->redirect(getReferrer('personalmessages/index')); } $model->delete(); fok(at('Personal Message Deleted.')); $this->redirect(array('personalmessages/index')); } else { $this->redirect(array('personalmessages/index')); } }
/** * view field action */ public function actionView() { // Check Access checkAccessThrowException('op_usercustomfields_viewposts'); if (isset($_GET['id']) && ($model = UserCustomField::model()->findByPk($_GET['id']))) { alog(at("Viewed Custom Field '{name}'.", array('{name}' => $model->title))); // Add Breadcrumb $this->addBreadCrumb(at('Viewing Custom Field')); $this->title[] = at('Viewing Custom Field "{name}"', array('{name}' => $model->title)); // Display form $this->render('view', array('model' => $model)); } else { ferror(at('Could not find that ID.')); $this->redirect(array('usercustomfields/index')); } }
/** * Delete setting action */ public function actiondeletesetting() { // Check Access checkAccessThrowException('op_settings_delete_settings'); if (isset($_GET['id'])) { $model = Setting::model()->findByPk($_GET['id']); // Make sure the setting is not protected as we can't edit protected settings if (!YII_DEBUG && $model->is_protected) { // Log Message alog(at("Tried Deleting Protected Setting '{name}'", array('{name}' => $model->title))); ferror(at("Can't delete that setting as it's a protected setting.")); $this->redirect(getReferrer('setting/index')); } // Log Message alog(at("Deleted Setting '{name}'", array('{name}' => $model->title))); Setting::model()->deleteByPk($_GET['id']); // Clear cache Yii::app()->settings->clearCache(); fok(at('Setting deleted.')); if ($model) { $this->redirect(array('setting/viewgroup', 'id' => $model->category)); } $this->redirect(array('setting/index')); } else { $this->redirect(array('setting/index')); } }
/** * view Email Template action */ public function actionView() { // Check Access checkAccessThrowException('op_emailtemplate_view'); if (isset($_GET['id']) && ($model = EmailTemplate::model()->findByPk($_GET['id']))) { alog(at("Viewed Email Template '{name}'.", array('{name}' => $model->title))); // Add Breadcrumb $this->addBreadCrumb(at('Viewing Email Template')); $this->title[] = at('Viewing Email Template "{name}"', array('{name}' => $model->title)); // Display email $this->render('view', array('model' => $model)); } else { ferror(at('Could not find that ID.')); $this->redirect(array('emailtemplate/index')); } }
/** * Revert a string to it's original form */ public function actionRevert() { // Check Access checkAccessThrowException('op_language_translate'); $id = getRParam('id', 0); $string = getRParam('string', 0); // Check if it exists $model = Language::model()->findByPk($id); if (!$model) { ferror(at('That language was not found.')); $this->redirect(array('index')); } // Grab the string and source $source = SourceMessage::model()->findByPk($string); $stringdata = Message::model()->find('language_id=:lang AND id=:id', array(':id' => $string, ':lang' => $id)); if (!$source || !$stringdata) { ferror(at('That language string was not found.')); $this->redirect(array('index')); } // Update the stringdata based on the soruce Message::model()->updateAll(array('translation' => $source->message), 'language_id=:lang AND id=:id', array(':id' => $string, ':lang' => $id)); fok(at('String Reverted.')); $this->redirect(array('language/view', 'id' => $id)); }
public function actionGenerateSalary($id) { $model = $this->loadModel($id); $message = $model->generateNewStandardSalaries(); if ($message == '') { fok('New salary standard generated successfully.'); } else { ferror($message); } $this->render('generate', array('model' => $model)); }
/** * View theme */ public function actionView($id) { // Check Access checkAccessThrowException('op_theme_view'); $model = Theme::model()->findByPk($id); // Make sure it exists if (!$model) { ferror(at('Could not find that ID.')); $this->redirect(array('themes/index')); } // Render theme view $this->render('theme_view', array('model' => $model)); }