<?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> <tr> <div class="row"> <div class="col-md-3 col-sm-6"> <div class="span2"><?php echo $form->labelEx($model, 'transfer_to', array('class' => 'inline-labels'));
/** * 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 Userdept the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Userdept::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
<?php echo CHtml::link('<i class="icon-pencil"></i>', array('update', 'id' => $model->id), array('class' => 'btn-warning btn buttonDesign', 'title' => 'Update')); echo CHtml::link('<i class="icon-trash"></i>', '#', array('class' => 'btn-warning btn buttonDesign', 'title' => 'Delete', 'submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')); ?> </h1> <table> <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>";
?> </div> <div class="span3"><?php $this->widget('zii.widgets.jui.CJuiDatePicker', array('attribute' => 'updatedon', 'name' => 'updatedon', 'htmlOptions' => array('value' => date('Y-m-d')), 'model' => $model, 'options' => array('showAnim' => 'fold', 'dateFormat' => 'yy-mm-dd'))); ?> </div> </div> </div> </tr> <?php if (isset($_GET['deptName'])) { $deptName = $_GET['deptName']; $deptRow = Dept::model()->findByAttributes(array('name' => $deptName)); $deptId = $deptRow['id']; } $validUsersIdRows = Userdept::model()->findAll('dept_id =:dept_id', array('dept_id' => $deptId)); $updateBy = []; foreach ($validUsersIdRows as $user) { $u = User::model()->findByPk($user['uid']); $updateBy[$u['id']] = $u['name']; } $connection = Yii::app()->db; $sql = "select OWNER,MAINTENED_BY from fopen WHERE ID={$temp}"; $command = $connection->createCommand($sql); $dataReader = $command->queryAll(); $allowedUsers = []; foreach ($dataReader[0] as $key => $value) { $user = User::model()->findByAttributes(array('name' => $value)); $allowedUsers[$user['id']] = $value; } ?>
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $model->pw_md5 = md5($_POST['User']['password']); if ($model->save()) { /* REMOVE PAST GRPS*/ $pastGrps = Usergroup::model()->findAllByAttributes(array('uid' => $id)); foreach ($pastGrps as $ug) { $m = Usergroup::model()->findByPk($ug['id']); $m->delete(); } /* ADD NEW GRPS */ if (isset($_POST['User']['g_id'])) { $grps = $_POST['User']['g_id']; foreach ($grps as $grp) { $model1 = new Usergroup(); $model1->uid = $model->id; $model1->gid = $grp; $model1->save(); } } /* REMOVE PAST DEPTS*/ $pastDepts = Userdept::model()->findAllByAttributes(array('uid' => $id)); foreach ($pastDepts as $ud) { $m = Userdept::model()->findByPk($ud['id']); $m->delete(); } /* ADD NEW DEPTS */ if (isset($_POST['User']['dept_id'])) { $depts = $_POST['User']['dept_id']; foreach ($depts as $d) { $model1 = new Userdept(); $model1->uid = $model->id; $model1->dept_id = $d; $model1->save(); } } $this->redirect(array('view', 'id' => $model->id)); } } else { $grpsRow = Usergroup::model()->findAllByAttributes(array('uid' => $id)); $grps = []; foreach ($grpsRow as $row) { $grps[] = $row['gid']; } $model->g_id = $grps; $deptsRow = Userdept::model()->findAllByAttributes(array('uid' => $id)); $depts = []; foreach ($deptsRow as $row) { $depts[] = $row['dept_id']; } $model->dept_id = $depts; } $this->render('update', array('model' => $model)); }