/** * 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() { $dept_id = $this->user !== NULL ? Users::model()->getDeptId($this->user->id) : NULL; if ($this->user === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($this->user->validatePassword($this->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { if ($this->user->status === Users::STATUS_BLOCKED) { $this->errorCode = self::ERROR_ACC_BLOCKED; } else { if ($this->user->status === Users::STATUS_PENDING) { $this->errorCode = self::ERROR_ACC_PENDING; } else { if (!empty($dept_id) && Dept::model()->get($dept_id, 'status') === Dept::STATUS_CLOSED) { $this->errorCode = self::ERROR_DEPT_CLOSED; } else { $this->completeLogin($dept_id); } } } } } return $this->errorCode === self::ERROR_NONE; }
public function actionIndex() { $this->hasPrivilege(Acl::ACTION_VIEW); $this->pageTitle = Lang::t(Common::pluralize($this->resourceLabel)); $searchModel = Dept::model()->searchModel(array(), $this->settings[Constants::KEY_PAGINATION], 'name'); $this->render('default/index', array('model' => $searchModel)); }
public function actionDelete($id) { $this->hasPrivilege(Acl::ACTION_DELETE); Dept::model()->loadModel($id)->delete(); if (!Yii::app()->request->isAjaxRequest) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index')); } }
public function actionDynamicRows() { $selectionid = $_POST['selection']; $depts = Dept::model()->findAllByAttributes(array('orgid' => $selectionid)); foreach ($depts as $row) { $dataOptions[$row->id] = $row->name; } foreach ($dataOptions as $value => $name) { $opt = array(); $opt['value'] = $value; echo CHtml::tag('option', $opt, CHtml::encode($name), true); } die; }
public function actionGetDeptInfo() { $this->retVal = new stdClass(); $request = Yii::app()->request; if ($request->isPostRequest && isset($_POST)) { try { $faculty_id = $request->getPost('faculty_id'); $dept_id = $request->getPost('dept_id'); $dept_data = Dept::model()->findAllByAttributes(array('dept_id' => $dept_id, 'dept_faculty' => $faculty_id)); $this->retVal->dept_data = $dept_data; } catch (exception $e) { $this->retVal->message = $e->getMessage(); } echo CJSON::encode($this->retVal); Yii::app()->end(); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($dept_id = NULL, $user_level = NULL) { $this->hasPrivilege(Acl::ACTION_CREATE); $this->pageTitle = Lang::t('Add ' . $this->resourceLabel); //account information $user_model = new Users(ActiveRecord::SCENARIO_CREATE); $user_model->status = Users::STATUS_ACTIVE; $user_model_class_name = $user_model->getClassName(); //personal information $person_model = new Person(); $person_model_class_name = $person_model->getClassName(); if (Yii::app()->request->isPostRequest) { $user_model->attributes = $_POST[$user_model_class_name]; $person_model->attributes = $_POST[$person_model_class_name]; $user_model->validate(); $person_model->validate(); if (!$user_model->hasErrors() && !$person_model->hasErrors()) { if ($user_model->save(FALSE)) { $person_model->id = $user_model->id; $person_model->save(FALSE); $user_model->updateDeptUser(); if (!empty($user_model->dept_id)) { Dept::model()->updateContactPerson($user_model->dept_id, $person_model->id); } Yii::app()->user->setFlash('success', Lang::t('SUCCESS_MESSAGE')); $this->redirect(Controller::getReturnUrl($this->createUrl('view', array('id' => $user_model->id)))); } } } $user_model->timezone = Yii::app()->settings->get(Constants::CATEGORY_GENERAL, Constants::KEY_DEFAULT_TIMEZONE, SettingsTimezone::DEFAULT_TIME_ZONE); if (!empty($dept_id)) { $user_model->dept_id = $dept_id; } if (!empty($user_level)) { $user_model->user_level = $user_level; } $this->render('create', array('user_model' => $user_model, 'person_model' => $person_model)); }
if (trim($labelParams['fileType']) != '') { $fileType = $labelParams['fileType']; $filetypeRow = FileType::model()->findByAttributes(array('id' => $fileType)); } else { $filetypeRow['label_width'] = 400; $filetypeRow['label_height'] = 100; } $label_width = (int) $filetypeRow['label_width'] . 'px'; $label_height = (int) $filetypeRow['label_height'] . 'px'; $paper = $labelParams['paper']; $numColumns = floor($paperWidth / $filetypeRow['label_width']); $connection = Yii::app()->db; if (trim($labelParams['depts']) == '') { $sql = "select CODE,TITLE from fopen"; } else { $deptRow = Dept::model()->find('id=:id', array(':id' => $labelParams['depts'])); $deptName = $deptRow['name']; /* Which all Files??*/ if (isset($labelParams['fileNames'])) { $fileIDsText = implode(',', $labelParams['fileNames']); $sql = "select CODE,TITLE from fopen where ID IN ({$fileIDsText})"; } else { if (!isset($labelParams['fileNames'])) { $sql = "select CODE,TITLE from fopen where DEPARTMENT='" . $deptName . "'"; } } } $command = $connection->createCommand($sql); $dataReader = $command->queryAll(); echo "<table>"; $numRows = ceil(count($dataReader) / $numColumns);
public function afterSave() { if ($this->scenario === self::SCENARIO_UPDATE) { $this->updateDeptUser(); Dept::model()->updateContactPerson($this->dept_id, $this->id); } return parent::afterSave(); }
/** * Lists all models. */ public function actionIndex($dept_id = NULL) { $this->hasPrivilege(Acl::ACTION_VIEW); $this->pageTitle = Lang::t(Common::pluralize($this->resourceLabel)); $dept_model = NULL; if (!empty($dept_id)) { $dept_model = Dept::model()->loadModel($dept_id); $this->pageDescription = $this->pageTitle; $this->pageTitle = $dept_model->name; $this->activeTab = 7; } if (!empty(Controller::$dept_id)) { $dept_id = Controller::$dept_id; } $searchModel = UsersView::model()->searchModel(array('dept_id' => $dept_id), $this->settings[Constants::KEY_PAGINATION], 'username', Users::model()->getFetchCondition()); $this->render('index', array('model' => $searchModel, 'dept_model' => $dept_model)); }
<tr><td> <?php $this->widget('ext.DetailView4Col', array('htmlOptions' => array('class' => 'table table-striped table-condensed table-hover'), 'data' => $model, 'attributes' => array('name', 'password', 'organisation_id', 'pw_md5', 'email', 'phone', 'phones', 'mobile', 'fn', 'ln', 'active', 'id_auth', 'auth_method', 'last_login', 'date_mod', 'designation'))); ?> </td> <td> <?php $grps = Usergroup::model()->findAllByAttributes(array('uid' => $model->id)); $depts = Userdept::model()->findAllByAttributes(array('uid' => $model->id)); echo "<table class='table table-bordered'>"; if (count($depts) == 0) { echo "<tr style='background:#F7819F;color:white'><td>{$model->name} doesn't belong to any department</td></tr>"; } else { echo "<tr style='background:#F5A9A9;'><th colspan='2'>Departments</th></tr>"; foreach ($depts as $d) { $department = Dept::model()->findByAttributes(array('id' => $d['dept_id'])); $deptName = $department['name']; echo "<tr><td colspan='2'>{$deptName}</td></tr>"; } } if (count($grps) == 0) { echo "<tr style='background:#F7819F;color:white'><td>{$model->name} doesn't belong to any group</td></tr>"; } else { echo "<tr style='background:#F5A9A9;'><th colspan='2'>Groups</th></tr>"; foreach ($grps as $g) { $group = Group::model()->findByAttributes(array('id' => $g['gid'])); $groupName = $group['name']; echo "<tr><td colspan='2'>{$groupName}</td></tr>"; } } echo "</table>";
<p class="help-block">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <?php if (isset($_GET['owner'])) { $owner = $_GET['owner']; $ownerRow = User::model()->findByAttributes(array('name' => $owner)); $ownerId = $ownerRow['id']; } else { $ownerId = ''; } if (isset($_GET['deptName'])) { $deptName = $_GET['deptName']; $deptRow = Dept::model()->findByAttributes(array('name' => $deptName)); $deptId = $deptRow['id']; } else { $deptId = ''; } $validUsersIdRows = Userdept::model()->findAll('dept_id =:dept_id AND uid !=:uid', array('dept_id' => $deptId, 'uid' => $ownerId)); $transferTo = []; foreach ($validUsersIdRows as $user) { $u = User::model()->findByPk($user['uid']); $transferTo[$u['id']] = $u['name']; } ?> <table>
<div class="span3"><?php echo $form->textField($model, 'name', array('span' => 2, 'maxlength' => 50, 'placeHolder' => 'Group Name')); ?> </div> </div> </div> </tr> <tr> <div class="row"> <div class="col-md-3 col-sm-6"> <div class="span2"><?php echo $form->labelEx($model, 'dept_id', array('class' => 'inline-labels')); ?> </div> <div class="span3"><?php echo $form->dropDownList($model, 'dept_id', CHtml::listData(Dept::model()->findAllByAttributes(array('orgid' => Yii::app()->user->getState("org_id"))), 'id', 'name'), array('span' => 2, 'prompt' => '---')); ?> </div> </div> </div> </tr> <tr> <div class="row"> <div class="col-md-3 col-sm-6"> <div class="span2"><?php echo $form->labelEx($model, 'comments', array('class' => 'inline-labels')); ?> </div> <div class="span3"><?php echo $form->textArea($model, 'comments', array('span' => 3, 'row' => 4)); ?>
<div class="panel-heading"> <h4 class="panel-title"> <i class="fa fa-chevron-down"></i> <a data-toggle="collapse" data-parent="#accordion" href="#account_info"><?php echo Lang::t('Account Details'); ?> </a> <?php if ($can_update || Users::isMyAccount($model->id)) { ?> <span><a class="pull-right" href="<?php echo $this->createUrl('view', array('id' => $model->id, 'action' => Users::ACTION_UPDATE_ACCOUNT)); ?> "><i class="fa fa-edit"></i> <?php echo Lang::t('Edit'); ?> </a></span> <?php } ?> </h4> </div> <div id="account_info" class="panel-collapse collapse in"> <div class="panel-body"> <div class="detail-view"> <?php $this->widget('application.components.widgets.DetailView', array('data' => $model, 'attributes' => array(array('name' => 'id'), array('label' => Lang::t('Department'), 'visible' => !empty($model->dept_id), 'value' => CHtml::link(CHtml::encode(Dept::model()->get($model->dept_id, "name")), Yii::app()->createUrl('dept/default/view', array('id' => $model->dept_id)), array()), 'type' => 'raw'), array('name' => 'status', 'value' => CHtml::tag('span', array('class' => $model->status === Users::STATUS_ACTIVE ? 'badge badge-success' : 'badge badge-danger'), $model->status), 'type' => 'raw'), array('name' => 'username'), array('name' => 'email'), array('name' => 'user_level'), array('name' => 'role_id', 'visible' => !empty($model->role_id), 'value' => UserRoles::model()->get($model->role_id, 'name')), array('name' => 'timezone'), array('name' => 'date_created', 'value' => MyYiiUtils::formatDate($model->date_created)), array('name' => 'created_by', 'value' => Users::model()->get($model->created_by, "username"), 'visible' => !empty($model->created_by)), array('name' => 'last_modified', 'value' => MyYiiUtils::formatDate($model->last_modified), 'visible' => !empty($model->last_modified)), array('name' => 'last_modified_by', 'value' => Users::model()->get($model->last_modified_by, "username"), 'visible' => !empty($model->last_modified_by)), array('name' => 'last_login', 'value' => MyYiiUtils::formatDate($model->last_login))))); ?> </div> </div> </div> </div>
<?php return array("fields" => array("doc_id" => array("label" => "Doc ID"), "doc_path" => array("label" => "File", "type" => "_document", "modelFile" => "doc_path_file"), "doc_url" => array("label" => "Preview", "type" => "_image"), "doc_name" => array("label" => "Doc Name"), "doc_description" => array("label" => "Doc Description", "type" => "_textarea"), "doc_author_name" => array("label" => "User upload"), "subject_dept" => array("label" => "Department", "type" => "_dropdown", "_list" => array("primary" => "dept_id", "displayAttr" => "dept_name", "src" => function () { $rows = Dept::model()->findAll(); return $rows; })), "subject_doc" => array("label" => "Subject", "type" => "_dropdown", "_list" => array("primary" => "subject_id", "displayAttr" => "subject_name", "src" => function () { $rows = Subject::model()->findAll(); return $rows; })), "subject_faculty" => array("label" => "Faculty", "type" => "_dropdown", "_list" => array("primary" => "faculty_id", "displayAttr" => "faculty_name", "src" => function () { $rows = Faculty::model()->findAll(); return $rows; })), "subject_type" => array("label" => "Subject Type", "type" => "_dropdown", "_list" => array("primary" => "id", "displayAttr" => "subject_type_name", "src" => function () { $rows = SubjectType::model()->findAll(); return $rows; })), "doc_dept_name" => array("label" => "Department", "src" => "dept.dept_name")), "columns" => array("doc_id", "doc_url", "doc_name", "doc_description", "doc_author_name", "subject_faculty", "doc_dept_name", "doc_path"), "actions" => array("_view" => true, "_edit" => array("doc_name", "doc_description", "doc_author_name", "subject_dept", "subject_faculty", "subject_type"), "_delete" => true, "_new" => array("type" => "popup", "attr" => array("doc_name", "doc_description", "doc_path", "subject_doc"), "extend" => array("doc_author" => Util::param("ADMIN_ID"), "doc_author_name" => "Admin")), "_search" => array("doc_id", "doc_name"), "_search_advanced" => array("doc_author_name", "subject_dept", "subject_faculty", "doc_name"), "_customButtons" => array()), "default" => array("orderBy" => "doc_id", "orderType" => "desc", "page" => 1, "per_page" => 10, "search" => "", "search_advanced" => ""), "join" => array("dept" => array("table" => "select dept_id, dept_name from tbl_dept", "type" => "left join", "selected_properties" => array("dept_name" => "doc_dept_name"), "on" => array("dept_id" => "t.subject_dept"))), "tableAlias" => "document", "title" => "Document Manager", "condition" => false, "limit_values" => array(10, 20, 30, 40), "model" => "Doc", "primary" => "doc_id", "itemLabel" => "Document", "additionalFiles" => array(), "insertScenario" => "fromAdmin", "updateScenario" => "fromAdmin", "formUpload" => TRUE);
public function actionListOfSubjectInfo() { $this->retVal = new stdClass(); $request = Yii::app()->request; if ($request->isPostRequest && isset($_POST)) { try { $listSubjectData = array('subject_dept' => StringHelper::filterString($_POST['subject_dept']), 'subject_faculty' => StringHelper::filterString($_POST['subject_faculty']), 'subject_type' => StringHelper::filterString($_POST['subject_type']), 'dept_id' => StringHelper::filterString($_POST['subject_dept']), 'faculty_id' => StringHelper::filterString($_POST['subject_faculty'])); $subject_data = Subject::model()->findAll(array('select' => '*', 'condition' => 'subject_faculty = ' . $listSubjectData['subject_faculty'] . ' AND subject_type = ' . $listSubjectData['subject_type'] . ' AND (subject_general_faculty_id = ' . $listSubjectData['faculty_id'] . ' OR subject_dept = ' . $listSubjectData['subject_dept'] . ')')); $subject_type_group = SubjectGroupType::model()->findAllByAttributes(array('subject_group' => $listSubjectData['subject_type'], 'subject_dept' => $listSubjectData['subject_dept'], 'subject_faculty' => $listSubjectData['subject_faculty'])); // var_dump($subject_data); // exit(); $subject_type_name = SubjectType::model()->findAllByAttributes(array('id' => $listSubjectData['subject_type'])); $this->retVal->subject_data = $subject_data; $this->retVal->subject_group_type = $subject_type_group; $dept_data = Dept::model()->findAllByAttributes(array('dept_id' => $listSubjectData['dept_id'], 'dept_faculty' => $listSubjectData['faculty_id'])); $this->retVal->subject_type = $subject_type_name; $this->retVal->message = 1; } catch (exception $e) { $this->retVal->message = $e->getMessage(); } echo CJSON::encode($this->retVal); Yii::app()->end(); } }
public function actionListTeacherDeptFaculty() { $this->retVal = new stdClass(); $request = Yii::app()->request; if ($request->isPostRequest && isset($_POST)) { try { $listSubjectData = array('dept_id' => StringHelper::filterString($_POST['dept_id']), 'faculty_id' => StringHelper::filterString($_POST['faculty_id'])); $dept_data = Dept::model()->findAllByAttributes(array('dept_id' => $listSubjectData['dept_id'])); $teacher_data = Teacher::model()->findAllByAttributes(array('teacher_dept' => $listSubjectData['dept_id'], 'teacher_faculty' => $listSubjectData['faculty_id'])); $this->retVal->teacher_data = $teacher_data; $this->retVal->dept_data = $dept_data; $this->retVal->message = 1; } catch (exception $e) { $this->retVal->message = $e->getMessage(); } echo CJSON::encode($this->retVal); Yii::app()->end(); } }
/** * 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 Dept the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Dept::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
$input_class = "col-md-{$input_size}"; if (!$model->getIsNewRecord()) { $can_update = $this->showLink(Users::USER_RESOURCE_PREFIX . $model->user_level, Acl::ACTION_UPDATE) && !Users::isMyAccount($model->id); } if ($model->getIsNewRecord() || $can_update) { ?> <div class="form-group"> <?php echo CHtml::activeLabelEx($model, 'dept_id', array('class' => $label_class, 'label' => Lang::t('Department'))); ?> <div class="<?php echo $input_class; ?> "> <?php echo CHtml::activeDropDownList($model, 'dept_id', Dept::model()->getListData('id', 'name', Lang::t('--Can manage all departments--'), '`status`=:t1', array(':t1' => Dept::STATUS_OPEN)), array('class' => 'form-control')); ?> </div> </div> <div class="form-group"> <?php echo CHtml::activeLabelEx($model, 'user_level', array('class' => $label_class)); ?> <div class="<?php echo $input_class; ?> "> <?php echo CHtml::activeDropDownList($model, 'user_level', Users::model()->getUserLevels($this), array('class' => 'form-control', 'data-show-role' => UserLevels::LEVEL_ADMIN)); ?> </div>
border-color: #d0d6d9; "> <h3 id="second">Các ngành học</h3> <div class="widget"> <nav class="w-nav"> <div class="w-nav-h"> <div class="w-nav-list layout_ver level_1"> <div class="w-nav-list-h"> <?php foreach ($category_father as $category) { ?> <div class="w-nav-item level_1 active"> <?php $dept = Dept::model()->findAllByAttributes(array('dept_faculty' => $category->faculty_id)); ?> <div class="w-nav-item-h"> <a href="#faculty-<?php echo $category->faculty_id; ?> " class="w-nav-anchor level_1 faculty" faculty-id="<?php echo $category->faculty_id; ?> "><?php echo $category->faculty_name; ?> <span class="w-nav-title " ></span> </a>
</tr>--> <tr> <div class="row"> <div class="col-md-3 col-sm-6"> <?php //if(isset($model->dept_id)) $array = $model->dept_id; //else $array = array(); ?> <div class="span2"><?php echo $form->labelEx($model, 'dept_id', array('class' => 'inline-labels')); ?> </div> <div class="span3"><?php echo Select2::activeMultiSelect($model, 'dept_id', CHtml::listData(Dept::model()->findAllByAttributes(array('orgid' => Yii::app()->user->getState("org_id"))), 'id', 'name'), array('select2Options' => array('width' => '65%', 'placeholder' => '--- Select Departments ---'))); ?> </div> <div class="span2"><?php echo $form->labelEx($model, 'groups', array('class' => 'inline-labels')); ?> </div> <div class="span3"><?php echo Select2::activeMultiSelect($model, 'g_id', CHtml::listData(group::model()->findAll(), 'id', 'name'), array('select2Options' => array('width' => '65%', 'placeholder' => '--- Select Groups ---'))); ?> </div> </div> </div> </tr>
echo $form->dropDownList($model, 'fileType', CHtml::listData(FileType::model()->findAll(), 'id', 'name'), array('prompt' => '---', 'ajax' => array('type' => 'POST', 'id' => 'drop_selection', 'url' => CController::createUrl('dynamicrows2'), 'update' => '#details', 'data' => array('selection' => 'js:this.value')))); ?> </div> <div class="span2" id="details"><span class="label label-info"> Default : Label Size:100px X 50px</span></div> </div> </div> </tr> <tr> <div class="row"> <div class="col-md-3 col-sm-6"> <div class="span2"><?php echo $form->labelEx($model, 'depts', array('class' => 'inline-labels')); ?> </div> <div class="span3"><?php echo $form->dropDownList($model, 'depts', CHtml::listData(Dept::model()->findAllByAttributes(array('orgid' => Yii::app()->user->getState("org_id"))), 'id', 'name'), array('prompt' => '--- Select Department ---', 'ajax' => array('type' => 'POST', 'id' => 'drop_selection', 'url' => CController::createUrl('dynamicrows'), 'update' => '#Label_fileNames', 'data' => array('selection' => 'js:this.value')))); ?> </div> <div class="span2"><span class="label label-info"> Default : All Departments Selected</span></div> </div> </div> </tr> <br/> <tr> <div class="row"> <div class="col-md-3 col-sm-6"> <div class="span2"><?php echo $form->labelEx($model, 'fileNames', array('class' => 'inline-labels')); ?> </div> <div class="span3"><?php
public function getDepartment($id) { if (empty($id)) { return NULL; } $dept = Dept::model()->getScaler('name', '`id`=:t1 ', array(':t1' => $id)); return !empty($dept) ? $dept : NULL; }