Exemplo n.º 1
0
 public function actionselectCompany()
 {
     $login = new LoginUser();
     $this->layout = 'select_company_main';
     if (Yii::app()->user->isGuest) {
         Yii::app()->user->loginRequired();
     }
     $model = new SelectCompany();
     $company_list = assignCompanyUserTable::model()->findAll(array('condition' => 'assign_user_id=:x', 'params' => array(':x' => Yii::app()->user->id)));
     foreach ($company_list as $list1) {
         $company[] = Organization::model()->findByPk($list1->assign_org_id);
         //			$listdata[] =  array('id'=>$company->organization_id,'name'=>$company->organization_name);  /// CREATE ARRAY WITH TWO KEY INDEX (ORG_ID,ORG_NAME)
     }
     if (isset($_POST['SelectCompany'])) {
         $model->attributes = $_POST['SelectCompany'];
         if (isset($_POST['select_org']) && $model->organization_name != null) {
             Yii::app()->user->setState('org_id', $model->organization_name);
             $login->user_id = Yii::app()->user->id;
             $login->status = 1;
             $login->log_in_time = new CDbExpression('NOW()');
             $login->user_ip_address = $_SERVER['REMOTE_ADDR'];
             $login->login_organization_id = Yii::app()->user->getState('org_id');
             $login->save();
             $this->redirect(array('site/dashboard'));
         } else {
             Yii::app()->user->setFlash('not-select', "Please selecte any Organization!");
             $this->redirect(array('selectCompany'));
         }
     } else {
         $this->render('select_company', array('model' => $model, 'company' => $company));
     }
 }
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $result = assignCompanyUserTable::model()->findByAttributes(array('assign_user_id' => $this->assign_user_id, 'assign_org_id' => $this->assign_org_id));
         if (count($result)) {
             $this->addErrors(array('assign_user_id' => 'Record already exist with this criteria', 'assign_org_id' => 'Record already exist with this criteria'));
             return false;
         } else {
             return true;
         }
     } else {
         $temp = assignCompanyUserTable::model()->findByPk($this->id);
         if ($this->assign_user_id == $temp['assign_user_id'] && $this->assign_org_id == $temp['assign_org_id']) {
             return true;
         } else {
             $result = assignCompanyUserTable::model()->findByAttributes(array('assign_user_id' => $this->assign_user_id, 'assign_org_id' => $this->assign_org_id));
             if (count($result)) {
                 $this->addErrors(array('assign_user_id' => 'Record already exist with this criteria', 'assign_org_id' => 'Record already exist with this criteria'));
                 return false;
             } else {
                 return true;
             }
         }
     }
 }
			{

				$company = Organization::model()->findByPk($new_org_id);
				echo "Welcome to ".$company->organization_name;
			}*/
?>
		</div>--></div></div>
	</div><!-- header -->
<div id="main-content">

<div id="page">
	

	<?php 
if (isset($_REQUEST['organization_name'])) {
    $role_id = assignCompanyUserTable::model()->find('assign_org_id=:org_id AND assign_user_id=:user_id', array(':org_id' => Yii::app()->user->getState('org_id'), ':user_id' => Yii::app()->user->id));
    $role_name = RoleMaster::model()->findByPk($role_id->assign_role_id);
    //echo $role_name->role_master_name;
    if (Yii::app()->user->id != 1) {
        Yii::app()->user->setState('role', $role_name->role_master_name);
    } else {
        Yii::app()->user->setState('role', 'sadmin');
    }
}
?>

	<div id="mainmenu">
		<div id="nav-bar">	
		
		<?php 
$empsession = 0;