コード例 #1
0
ファイル: Projects.php プロジェクト: ranvijayj/htmlasa
    /**
     * Assign projects to new client admin
     * @param $userId
     * @param $clientId
     */
    public static function assignClientAdminProjects($userId, $clientId)
    {
        $condition = new CDbCriteria();
        $condition->condition = "t.Client_ID = '" . $clientId . "'";
        $projects = Projects::model()->findAll($condition);

        foreach($projects as $project) {
            $userProject = UsersProjectList::model()->findByAttributes(array(
                'User_ID' => $userId,
                'Project_ID' => $project->Project_ID,
            ));

            if (!$userProject) {
                $userProject = new UsersProjectList();
                $userProject->User_ID = $userId;
                $userProject->Client_ID = $clientId;
                $userProject->Project_ID = $project->Project_ID;
                $userProject->save();
            }
        }
    }
コード例 #2
0
ファイル: UserIdentity.php プロジェクト: ranvijayj/htmlasa
    /**
     * Authenticates a user.
     * Makes sure if the username and password
     * @param int $timezoneOffset
     * @return boolean whether authentication succeeds.
     */
    public function authenticate($timezoneOffset = 0)
	{
		$user = Users::model()->getAuthenticateInfo($this->username,$this->password,UsersDevices::getDevHash(''));
		if(!empty($user->User_ID)) {
            $user->Last_IP = $_SERVER['REMOTE_ADDR'];
            $user->Last_Login = date("Y-m-d H:i:s");
            $user->save();

            // Set user info
            $this->setState('userInfo', $user->person->First_Name . ' ' . $user->person->Last_Name);
            $this->setState('userID', $user->User_ID);
            $this->setState('userLogin', $user->User_Login);
            $this->setState('userTimezoneOffset', $timezoneOffset);

            // get default client and project
            $default_client = false;
            $condition = new CDbCriteria();
            $condition->condition = "users_project_list.User_ID = '" . $user->User_ID . "'";
            $condition->addCondition("users_project_list.Project_ID = '" . $user->Default_Project . "'");
            $condition->join = "LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID";
            $default_project = Projects::model()->with('client.company')->find($condition);
            if ($default_project) {
                $default_client = $default_project->client;
            } else {
                $settings = $user->settings;
                $settings->scenario = 'newClientScenario';
                $settings->Default_Project = 0;
                $settings->save();

                $condition = new CDbCriteria();
                $condition->condition = "users_project_list.User_ID = '" . $user->User_ID . "'";
                $condition->join = "LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID";
                $default_project = Projects::model()->with('client.company')->find($condition);
                if ($default_project) {
                    $user->Default_Project = $default_project->Project_ID;
                    $user->save();
                    $default_client = $default_project->client;
                } else {
                    $user->Default_Project = 0;
                    $user->save();
                }
            }

            // get client
            $client = false;
            foreach ($user->clients as $cl) {
                if ($cl->Client_ID == $default_client->Client_ID) {
                    $client = $cl;
                    break;
                } else {
                    $client = $cl;
                }
            }

            if ($client) {
                $this->setState('clientInfo', $client->company->Company_Name);
                $this->setState('clientID', $client->Client_ID);

                $projects = UsersProjectList::model()->with('project')->findAllByAttributes(array(
                    'User_ID' =>$user->User_ID,
                    'Client_ID' =>$client->Client_ID,
                ));

                if ($default_project) {
                    $project = $default_project;
                    $this->setState('projectInfo', $project->Project_Name);
                    $this->setState('projectID', $project->Project_ID);
                    $this->errorCode=self::ERROR_NONE;
                } else if ($projects) {
                    $project = $projects[0];
                    $this->setState('projectInfo', $project->project->Project_Name);
                    $this->setState('projectID', $project->Project_ID);
                    $this->errorCode=self::ERROR_NONE;
                } else {
                    $this->setState('projectInfo', 'No project');
                    $this->setState('projectID', 0);
                    $this->errorCode=self::ERROR_UNKNOWN_IDENTITY;
                }

                //set user's tier settings

                //check for delayed settings
                DelayedClientServiceSettings::checkDate(date('Y-m-d'),$client->Client_ID);

                $user_client_settings = $client->service_settings;
                $user_tier_settings = TiersSettings::agregateTiersSettings($user_client_settings->Service_Level_ID);
                $this->setState('tier_settings', $user_tier_settings);

                $userClientRelation = UsersClientList::model()->findByAttributes(array(
                    'User_ID' =>$user->User_ID,
                    'Client_ID' =>$client->Client_ID,
                ));

                // set user type from user-client relation
                if ($userClientRelation->User_Type == UsersClientList::CLIENT_ADMIN) {
                    $this->username = '******';
                } else if ($userClientRelation->User_Type == UsersClientList::APPROVER) {
                    $this->username = '******';
                } else if ($userClientRelation->User_Type == UsersClientList::PROCESSOR) {
                    $this->username = '******';
                } else if ($userClientRelation->User_Type == UsersClientList::USER) {
                    $this->username = '******';
                } else {
                    $this->username = '******';
                }

                // reset user type if he id Admin, DB Admin OR DEC
                if ($user->User_Type == Users::ADMIN) {
                    $this->username = '******';
                } else if ($user->User_Type == Users::DB_ADMIN) {
                    $this->username = '******';
                } else if ($user->User_Type == Users::DATA_ENTRY_CLERK) {
                    $this->username = '******';
                }

                if ($user->User_Type == Users::USER) {
                    $this->setState('userType', $userClientRelation->User_Type);
                } else {
                    $this->setState('userType', $user->User_Type);
                }
            } else {
                $this->setState('clientInfo', 'No company');
                $this->setState('clientID', 0);
                $this->setState('projectInfo', 'No project');
                $this->setState('userType', 'Single User');
                $this->setState('projectID', 0);
                $this->username = '******';
                $this->errorCode=self::ERROR_NONE;
            }

            UserLog::createLogRecord($user->User_ID, '', 0, 0);
        }
		return !$this->errorCode;
	}
コード例 #3
0
    /**
     * Approve users action
     */
    public function actionApproveUsers()
    {
        if (isset($_GET['users']) && isset($_GET['userTypes'])) {
            foreach ($_GET['users'] as $id => $value) {
                if (is_numeric($id) && ($value == 'Y' || $value == 'N') && isset($_GET['userTypes'][$id]) && isset($this->userTypes[$_GET['userTypes'][$id]])) {
                    // get user type
                    $userType = $this->userTypes[$_GET['userTypes'][$id]];
                    $id = intval($id);

                    //get users to approve row
                    $usersToApprove = UsersToApprove::model()->with('user', 'client')->findByPk($id);
                    if ($usersToApprove && $value == 'Y') {
                        //approve user
                        if ($usersToApprove->New_Client == UsersToApprove::NEW_CLIENT) {
                            $client = $usersToApprove->client;
                            $client->Client_Type = 1;
                            $client->Client_Status = Clients::ACTIVE;
                            $client->Client_Number = $client->Client_ID;
                            $client->save();

                            ClientServiceSettings::addClientServiceSettings($client->Client_ID, true);

                            $password = Helper::generatePassword();
                            $user = $usersToApprove->user;
                            $user->Active = Users::ACTIVE;
                            $user->User_Pwd = md5($password);
                            $user->save();

                            $userClientRelation = UsersClientList::model()->findByAttributes(array(
                                'User_ID' =>$user->User_ID,
                                'Client_ID' =>$client->Client_ID,
                            ));

                            if ($userClientRelation) {
                                $userClientRelation->User_Type = $userType;

                                if (in_array($userType, UsersClientList::$clientAdmins)) {
                                    $userClientRelation->User_Approval_Value = Aps::APPROVED;
                                } else if ($userType == UsersClientList::APPROVER) {
                                    $userClientRelation->User_Approval_Value = Aps::READY_FOR_APPROVAL + 1;
                                } else {
                                    $userClientRelation->User_Approval_Value = 0;
                                }
                                $userClientRelation->save();
                            }

                            $emailSuccess = Mail::sendRegistrationMail($user->person->Email, $user->User_Login,$password, $user->person->First_Name, $user->person->Last_Name, $client->company->Company_Name);
                            $usersToApprove->delete();
                        } else {
                            $usersToApprove->Approved_By_Admin = UsersToApprove::APPR_BY_ADMIN;
                            $usersToApprove->save();

                            $client = $usersToApprove->client;
                            $client->Client_Type = 1;
                            $client->Client_Status = Clients::ACTIVE;
                            $client->Client_Number = $client->Client_ID;
                            $client->save();

                            $user = $usersToApprove->user;

                            if ($user->User_Pwd == md5('temp100')) {
                                // if user requested to join company by registration form
                                $password = Helper::generatePassword();
                                $user->Active = Users::ACTIVE;
                                $user->User_Pwd = md5($password);
                                $user->Default_Project = 0;
                                $user->save();

                                Mail::sendUserRegistrationMail($user->person->Email, $user->User_Login, $password, $user->person->First_Name, $user->person->Last_Name, $client->company->Company_Name);
                            } else {
                                // if user requested to join company and there is not client-admins
                                $user->Active = Users::ACTIVE;
                                $user->save();
                            }

                            $condition = UsersClientList::getClientAdminCondition($usersToApprove->Client_ID);

                            $client_admins_list = UsersClientList::model()->findAll($condition); //this is client admins for current client

                            if ($client_admins_list) {
                                // if client has client-admins
                                foreach ($client_admins_list as $clientAdm) {
                                    $clientAdmin = Users::model()->with('person')->findByPk($clientAdm->User_ID);
                                    $emailSuccess = Mail::sendClientOfUserRegistrationMail($clientAdmin->person->Email, $clientAdmin->person->First_Name, $clientAdmin->person->Last_Name, $user->person->First_Name, $user->person->Last_Name, $client->company->Company_Name);
                                }

                            }



                                // if client hasn't client admins
                                $usersClientList = UsersClientList::model()->findByAttributes(array(
                                   'Client_ID' => $usersToApprove->Client_ID,
                                    'User_ID' => $usersToApprove->User_ID
                                ));

                                if (!$usersClientList) {
                                    $usersClientList = new UsersClientList;
                                }

                                $usersClientList->User_ID = $usersToApprove->User_ID;
                                $usersClientList->Client_ID = $usersToApprove->Client_ID;
                                $usersClientList->User_Type = $userType;

                                if (in_array($userType, UsersClientList::$clientAdmins)) {
                                    $usersClientList->User_Approval_Value = Aps::APPROVED;
                                } else if ($userType == UsersClientList::APPROVER) {
                                    $usersClientList->User_Approval_Value = Aps::READY_FOR_APPROVAL + 1;
                                } else {
                                    $usersClientList->User_Approval_Value = 0;
                                }

                                $usersClientList->save();

                                $project = Projects::model()->findByAttributes(array(
                                    'Client_ID' => $usersToApprove->Client_ID,
                                ));

                                $usersProjectList = new UsersProjectList;
                                $usersProjectList->User_ID = $usersToApprove->User_ID;
                                $usersProjectList->Client_ID = $usersToApprove->Client_ID;
                                $usersProjectList->Project_ID =  $project->Project_ID;
                                $usersProjectList->save();

                                if ($user->Default_Project == 0) {
                                    $user->Default_Project = $project->Project_ID;
                                }
                                $user->save();

                                $usersToApprove->delete();

                                Mail::sendAddUserToClientMail($user->person->Email, $user->person->First_Name, $user->person->Last_Name, $client->company->Company_Name);

                        }
                    } else if ($usersToApprove && $value == 'N') {
                        //reject user
                        $user = $usersToApprove->user;
                        $client = $usersToApprove->client;

                        if ($usersToApprove->New_Client == UsersToApprove::NEW_CLIENT) {
                            $company = $client->company;
                            $addresses = $company->adreses;

                            //delete company addresses
                            foreach ($addresses as $address) {
                                $companyAddress = CompanyAddresses::model()->findByAttributes(array(
                                    'Company_ID' => $company->Company_ID,
                                    'Address_ID' => $address->Address_ID,
                                ));

                                if ($companyAddress) {
                                    $companyAddress->delete();
                                }
                                $address->delete();
                            }

                            $company->delete();

                            $usersClientList = UsersClientList::model()->findByAttributes(array(
                                'User_ID' => $user->User_ID,
                                'Client_ID' => $client->Client_ID,
                            ));

                            if ($usersClientList) {
                                $usersClientList->delete();
                            }

                            $usersToApprove->delete();
                            $client->delete();
                        } else {
                            $usersToApprove->delete();
                        }

                        if ($user->User_Pwd == md5('temp100')) {
                            $user->Active = Users::NOT_ACTIVE;
                            $user->Default_Project = 0;
                            $user->save();

                            Mail::sendRejectUserByAdminMail($user->person->Email, $user->person->First_Name, $user->person->Last_Name);
                        } else {
                            Mail::sendRejectMail($user->person->Email, $user->person->First_Name, $user->person->Last_Name, $client->company->Company_Name);
                        }
                    }
                }
            }

            Yii::app()->user->setFlash('success', "Users have been successfully approved/rejected!");
        } else {
            Yii::app()->user->setFlash('success', "Users was not approved/rejected!");
        }
        $this->redirect('/admin?tab=reg_requests');
    }
コード例 #4
0
	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
        if (isset($_POST['oper']) && $_POST['oper'] == 'edit') {
            $companyId = intval($_POST["id"]);
            $company = Companies::model()->with('client', 'adreses')->findByPk($companyId);
            if ($company) {
                if ($company->client) {
                    $client = $company->client;
                    $client->Client_Number = $_POST["Client_Number"];
                    $client->Client_Logo_Name = $_POST["Client_Logo_Name"];
                    $client->Client_Approval_Amount_1 = $_POST["Client_Approval_Amount_1"] ? $_POST["Client_Approval_Amount_1"] : null;
                    $client->Client_Approval_Amount_2 = $_POST["Client_Approval_Amount_2"] ? $_POST["Client_Approval_Amount_2"] : null;
                    if ($client->validate()) {
                        $client->save();
                        echo "client\n";
                    }
                }

                if ($company->adreses) {
                    $addresses = $company->adreses;
                    if (isset($addresses[0])) {
                        $address = $addresses[0];
                        $address->Address1 =  $_POST["Address1"];
                        $address->Address2 =  $_POST["Address2"];
                        $address->City =  $_POST["City"];
                        $address->State =  $_POST["State"];
                        $address->ZIP =  $_POST["ZIP"];
                        $address->Country =  $_POST["Country"];
                        $address->Phone =  $_POST["Phone"];
                        $address->Fax =  $_POST["Fax"];

                        if ($address->validate()) {
                            $address->save();
                            echo "address\n";
                        }
                    }
                }

                $company->Company_Name = $_POST["Company_Name"];
                $company->Company_Fed_ID = $_POST["Company_Fed_ID"];
                $company->Email = $_POST["Email"];
                $company->SSN = $_POST["SSN"];
                $company->Business_NameW9 = $_POST["Business_NameW9"];

                if ($company->validate()) {
                    $company->save();
                    echo "company\n";
                }
            }
            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'add') {
            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'del') {
            $companyId = intval($_POST["id"]);
            $company = Companies::model()->with('client', 'adreses')->findByPk($companyId);
            $documents = Documents::model()->findByAttributes(array(
                'Client_ID' => $company->client->Client_ID,
            ));

            if ($company && !$documents) {
                if ($company->client) {
                    $client = $company->client;

                    UsersToApprove::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    UsersClientList::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    UsersProjectList::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    BankAcctNums::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    Coa::model()->deleteAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    Vendors::model()->deleteAllByAttributes(array(
                        'Client_Client_ID' => $client->Client_ID,
                    ));

                    Vendors::model()->deleteAllByAttributes(array(
                        'Vendor_Client_ID' => $client->Client_ID,
                    ));

                    $w9s = W9::model()->findAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    if ($w9s) {
                        foreach ($w9s as $w9) {
                            W9::deleteW9($w9->W9_ID);
                        }
                    }

                    $projects = Projects::model()->findAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));

                    if ($projects) {
                        foreach ($projects as $project) {
                            PoFormatting::model()->deleteAllByAttributes(array(
                                'Project_ID' => $project->Project_ID,
                            ));
                            $project->delete();
                        }
                    }

                    $client->delete();
                }

                if ($company->adreses) {
                    $addresses = $company->adreses;
                    foreach ($addresses as $address) {
                        $address->delete();
                    }
                }

                CompanyAddresses::model()->deleteAllByAttributes(array(
                    'Company_ID' => $companyId,
                ));

                $company->delete();
            }
            die;
        }

        $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword);
        mysql_select_db(Yii::app()->params->dbname);
        mysql_query("SET NAMES 'utf8'");

        Yii::import('ext.phpgrid.inc.jqgrid');

        // set columns
        $col = array();
        $col["title"] = "Company ID"; // caption of column
        $col["name"] = "Company_ID";
        $col["dbname"] = "companies.Company_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Company Name"; // caption of column
        $col["name"] = "Company_Name";
        $col["dbname"] = "companies.Company_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fed ID"; // caption of column
        $col["name"] = "Company_Fed_ID";
        $col["dbname"] = "companies.Company_Fed_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "SSN"; // caption of column
        $col["name"] = "SSN";
        $col["dbname"] = "companies.SSN"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Email"; // caption of column
        $col["name"] = "Email";
        $col["dbname"] = "companies.Email"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Business_NameW9"; // caption of column
        $col["name"] = "Business_NameW9";
        $col["dbname"] = "companies.Business_NameW9"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Client ID"; // caption of column
        $col["name"] = "Client_ID";
        $col["dbname"] = "clients.Client_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Client Number"; // caption of column
        $col["name"] = "Client_Number";
        $col["dbname"] = "clients.Client_Number"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Client Logo Name"; // caption of column
        $col["name"] = "Client_Logo_Name";
        $col["dbname"] = "clients.Client_Logo_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Client Approval Amount 1"; // caption of column
        $col["name"] = "Client_Approval_Amount_1";
        $col["dbname"] = "clients.Client_Approval_Amount_1"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Client Approval Amount 2"; // caption of column
        $col["name"] = "Client_Approval_Amount_2";
        $col["dbname"] = "clients.Client_Approval_Amount_2"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Address ID"; // caption of column
        $col["name"] = "Address_ID";
        $col["dbname"] = "addresses.Address_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address1"; // caption of column
        $col["name"] = "Address1";
        $col["dbname"] = "addresses.Address1"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address2"; // caption of column
        $col["name"] = "Address2";
        $col["dbname"] = "addresses.Address2"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "City"; // caption of column
        $col["name"] = "City";
        $col["dbname"] = "addresses.City"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "State"; // caption of column
        $col["name"] = "State";
        $col["dbname"] = "addresses.State"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "ZIP"; // caption of column
        $col["name"] = "ZIP";
        $col["dbname"] = "addresses.ZIP"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Country"; // caption of column
        $col["name"] = "Country";
        $col["dbname"] = "addresses.Country"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Phone"; // caption of column
        $col["name"] = "Phone";
        $col["dbname"] = "addresses.Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fax"; // caption of column
        $col["name"] = "Fax";
        $col["dbname"] = "addresses.Fax"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $g = new jqgrid();

        $grid["caption"] = "Clients";
       // $grid["multiselect"] = true;
        $grid["autowidth"] = true;
        $grid["resizable"] = true;
        //$grid["toppager"] = true;
        $grid["sortname"] = 'companies.Company_Name';
        $grid["sortorder"] = "ASC";
        $grid["add_options"] = array(
            'width'=>'420',
            "closeAfterEdit"=>true, // close dialog after add/edit
            "top"=>"200", // absolute top position of dialog
            "left"=>"200" // absolute left position of dialog
        );

        $g->set_options($grid);

        $g->set_actions(array(
                "add"=>false, // allow/disallow add
                "edit"=>true, // allow/disallow edit
                "delete"=>true, // allow/disallow delete
                "rowactions"=>true, // show/hide row wise edit/del/save option
                "export"=>true, // show/hide export to excel option
                "autofilter" => true, // show/hide autofilter for search
                "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
            )
        );

        $g->select_command = "SELECT  clients.Client_ID, clients.Client_Number, clients.Client_Logo_Name,
                                      companies.*, addresses.*, clients.Client_Approval_Amount_1,
                                      clients.Client_Approval_Amount_2
                              FROM clients
                              LEFT JOIN companies ON clients.Company_ID = companies.Company_ID
                              LEFT JOIN company_addresses ON company_addresses.Company_ID = companies.Company_ID
                              LEFT JOIN addresses ON addresses.Address_ID = company_addresses.Address_ID";

        // set database table for CRUD operations
        $g->table = "clients";

        $g->set_columns($cols);

        // group columns header
        $g->set_group_header( array(
                "useColSpanStyle"=>true,
                "groupHeaders"=>array(
                    array(
                        "startColumnName"=>'Company_ID', // group starts from this column
                        "numberOfColumns"=>6, // group span to next 2 columns
                        "titleText"=>'Company Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Client_ID', // group starts from this column
                        "numberOfColumns"=>5, // group span to next 2 columns
                        "titleText"=>'Client Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Address1', // group starts from this column
                        "numberOfColumns"=>8, // group span to next 2 columns
                        "titleText"=>"Company's Address" // caption of group header
                    )
                )
            )
        );

        // render grid and get html/js output
        $out = $g->render("Clients");

        $this->render('index',array(
            'out'=>$out,
        ));
	}
コード例 #5
0
	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
        if (isset($_POST['oper']) && $_POST['oper'] == 'edit') {
            $ids = explode(',', $_POST["id"]);
            $userId = $ids[0];
            $clientId = $ids[1];

            if (is_numeric($userId) && is_numeric($clientId)) {
                $userClientRow = UsersClientList::model()->with('client', 'user')->findByAttributes(array(
                    'User_ID' => $userId,
                    'Client_ID' => $clientId,
                ));

                if ($userClientRow) {
                    $client = $userClientRow->client;
                    $company = $client->company;
                    $user = $userClientRow->user;
                    $person = $user->person;
                    $addresses = $company->adreses;

                    $userClientRow->User_Type = $_POST["User_Type"];
                    $userClientRow->User_Approval_Value = intval($_POST["User_Approval_Value"]);
                    if ($userClientRow->validate()) {
                        $userClientRow->save();
                        echo "UsersClientList\n";
                    }

                    if (isset($addresses[0])) {
                        $address = $addresses[0];
                        $address->Address1 =  $_POST["Address1"];
                        $address->Address2 =  $_POST["Address2"];
                        $address->City =  $_POST["City"];
                        $address->State =  $_POST["State"];
                        $address->ZIP =  $_POST["ZIP"];
                        $address->Country =  $_POST["Country"];
                        $address->Phone =  $_POST["Phone"];
                        $address->Fax =  $_POST["Fax"];

                        if ($address->validate()) {
                            $address->save();
                            echo "adresses\n";
                        }
                    }

                    if ($company) {
                        $company->Company_Name = $_POST["Company_Name"];
                        if ($company->validate()) {
                            $company->save();
                            echo "company\n";
                        }
                    }

                    $user->User_Login = $_POST["User_Login"];
                    $user->Last_Login = $_POST["Last_Login"] ? $_POST["Last_Login"] : null;
                    $user->Active = intval($_POST["Active"]);
                    if ($user->validate()) {
                        $user->save();
                        echo "user\n";
                    }

                    $person->First_Name = $_POST["First_Name"];
                    $person->Last_Name = $_POST["Last_Name"];
                    $person->Email = $_POST["Email"];
                    $person->Mobile_Phone = $_POST["Mobile_Phone"];
                    $person->Direct_Phone = $_POST["Direct_Phone"];
                    $person->Direct_Fax = $_POST["Direct_Fax"];
                    if ($person->validate()) {
                        $person->save();
                        echo "person\n";
                    }
                }
            }

            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'add') {
            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'del') {
            $ids = explode(',', $_POST["id"]);
            $userId = $ids[0];
            $clientId = $ids[1];
            if (is_numeric($userId) && is_numeric($clientId)) {
                $userClientRow = UsersClientList::model()->with('client', 'user')->findByAttributes(array(
                    'User_ID' => $userId,
                    'Client_ID' => $clientId,
                ));

                if ($userClientRow) {
                    $userClientRow->delete();
                    UsersProjectList::model()->deleteAllByAttributes(array(
                        'User_ID' => $userId,
                        'Client_ID' => $clientId,
                    ));
                }
            }
            die;
        }

        $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword);
        mysql_select_db(Yii::app()->params->dbname);
        mysql_query("SET NAMES 'utf8'");

        Yii::import('ext.phpgrid.inc.jqgrid');

        // set columns
        $col = array();
        $col["title"] = "Joined Key (User_ID, Client_ID)"; // caption of column
        $col["name"] = "joined_key";
        $col["dbname"] = "joined_key"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "User Type"; // caption of column
        $col["name"] = "User_Type";
        $col["dbname"] = "users_client_list.User_Type"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["edittype"] = "select";
        $col["editoptions"] = array("value"=>'User:User;Approver:Approver;Processor:Processor;Client Admin:Client Admin');
        $cols[] = $col;

        $approvalValues = array();
        for ($i = 0; $i <= 100; $i++) {
            $approvalValues[] = $i . ':' . $i;
        }

        $col = array();
        $col["title"] = "User Approval Value"; // caption of column
        $col["name"] = "User_Approval_Value";
        $col["dbname"] = "users_client_list.User_Approval_Value"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = true; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = true;
        $col["edittype"] = "select";
        $col["editoptions"] = array("value"=>implode(';', $approvalValues));
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "User ID"; // caption of column
        $col["name"] = "User_ID";
        $col["dbname"] = "users.User_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "User Login"; // caption of column
        $col["name"] = "User_Login";
        $col["dbname"] = "users.User_Login"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Last Login"; // caption of column
        $col["name"] = "Last_Login";
        $col["dbname"] = "users.Last_Login"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Active"; // caption of column
        $col["name"] = "Active";
        $col["dbname"] = "users.Active"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = true;
        $col["edittype"] = "select";
        $col["editoptions"] = array("value"=>'0:0;1:1');
        $cols[] = $col;

        $col = array();
        $col["title"] = "Last_IP"; // caption of column
        $col["name"] = "Last_IP";
        $col["dbname"] = "users.Last_IP"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = false; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Person ID"; // caption of column
        $col["name"] = "Person_ID";
        $col["dbname"] = "persons.Person_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "First Name"; // caption of column
        $col["name"] = "First_Name";
        $col["dbname"] = "persons.First_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Last Name"; // caption of column
        $col["name"] = "Last_Name";
        $col["dbname"] = "persons.Last_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Email"; // caption of column
        $col["name"] = "Email";
        $col["dbname"] = "persons.Email"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Mobile Phone"; // caption of column
        $col["name"] = "Mobile_Phone";
        $col["dbname"] = "persons.Mobile_Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Direct Phone"; // caption of column
        $col["name"] = "Direct_Phone";
        $col["dbname"] = "persons.Direct_Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Direct Fax"; // caption of column
        $col["name"] = "Direct_Fax";
        $col["dbname"] = "persons.Direct_Fax"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Company ID"; // caption of column
        $col["name"] = "Company_ID";
        $col["dbname"] = "companies.Company_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Company Name"; // caption of column
        $col["name"] = "Company_Name";
        $col["dbname"] = "companies.Company_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Address ID"; // caption of column
        $col["name"] = "Address_ID";
        $col["dbname"] = "addresses.Address_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address1"; // caption of column
        $col["name"] = "Address1";
        $col["dbname"] = "addresses.Address1"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address2"; // caption of column
        $col["name"] = "Address2";
        $col["dbname"] = "addresses.Address2"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "City"; // caption of column
        $col["name"] = "City";
        $col["dbname"] = "addresses.City"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "State"; // caption of column
        $col["name"] = "State";
        $col["dbname"] = "addresses.State"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "ZIP"; // caption of column
        $col["name"] = "ZIP";
        $col["dbname"] = "addresses.ZIP"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Country"; // caption of column
        $col["name"] = "Country";
        $col["dbname"] = "addresses.Country"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Phone"; // caption of column
        $col["name"] = "Phone";
        $col["dbname"] = "addresses.Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fax"; // caption of column
        $col["name"] = "Fax";
        $col["dbname"] = "addresses.Fax"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $g = new jqgrid();

        $grid["caption"] = "Client/User List";
       // $grid["multiselect"] = true;
        $grid["autowidth"] = true;
        $grid["resizable"] = true;
        //$grid["toppager"] = true;
        $grid["sortname"] = 'users.User_ID';
        $grid["sortorder"] = "ASC";
        $grid["add_options"] = array(
            'width'=>'420',
            "closeAfterEdit"=>true, // close dialog after add/edit
            "top"=>"200", // absolute top position of dialog
            "left"=>"200" // absolute left position of dialog
        );

        $g->set_options($grid);

        $g->set_actions(array(
                "add"=>false, // allow/disallow add
                "edit"=>true, // allow/disallow edit
                "delete"=>true, // allow/disallow delete
                "rowactions"=>true, // show/hide row wise edit/del/save option
                "export"=>true, // show/hide export to excel option
                "autofilter" => true, // show/hide autofilter for search
                "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
            )
        );

        $g->select_command = "SELECT   concat(users_client_list.User_ID, ',', users_client_list.Client_ID) as joined_key,
                                       users_client_list.User_Type, users_client_list.User_Approval_Value,
                                       companies.Company_Name, companies.Company_ID, addresses.*, persons.*,
                                       users.User_ID, users.Default_Project, users.User_Login, users.Last_Login,
                                       users.Active, users.Last_IP
                              FROM users_client_list
                              LEFT JOIN clients ON clients.Client_ID = users_client_list.Client_ID
                              LEFT JOIN companies ON clients.Company_ID = companies.Company_ID
                              LEFT JOIN users ON users.User_ID = users_client_list.User_ID
                              LEFT JOIN persons ON users.Person_ID = persons.Person_ID
                              LEFT JOIN company_addresses ON company_addresses.Company_ID = companies.Company_ID
                              LEFT JOIN addresses ON addresses.Address_ID = company_addresses.Address_ID";

        // set database table for CRUD operations
        $g->table = "users_client_list";

        $g->set_columns($cols);


        // group columns header
        $g->set_group_header( array(
                "useColSpanStyle"=>true,
                "groupHeaders"=>array(
                    array(
                        "startColumnName"=>'User_Type', // group starts from this column
                        "numberOfColumns"=>2, // group span to next 2 columns
                        "titleText"=>'User-Client Rel.' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'User_ID', // group starts from this column
                        "numberOfColumns"=>5, // group span to next 2 columns
                        "titleText"=>'User Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'First_Name', // group starts from this column
                        "numberOfColumns"=>6, // group span to next 2 columns
                        "titleText"=>'Person Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Company_ID', // group starts from this column
                        "numberOfColumns"=>2, // group span to next 2 columns
                        "titleText"=>'Company Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Address1', // group starts from this column
                        "numberOfColumns"=>8, // group span to next 2 columns
                        "titleText"=>"Company's Address" // caption of group header
                    )
                )
            )
        );

        // render grid and get html/js output
        $out = $g->render("Client_User_List");

        $this->render('index',array(
            'out'=>$out,
        ));
	}
コード例 #6
0
ファイル: UsersController.php プロジェクト: ranvijayj/htmlasa
    /**
     * Lists all models.
     */
    public function actionIndex()
    {
        if (isset($_POST['oper']) && $_POST['oper'] == 'edit') {
            $userId =  intval($_POST["id"]);

            $user = Users::model()->with('person')->findByPk($userId);

            if ($user) {
                $person = $user->person;
                $addresses = $person->adresses;

                if (isset($addresses[0])) {
                    $address = $addresses[0];
                    $address->Address1 =  $_POST["Address1"];
                    $address->Address2 =  $_POST["Address2"];
                    $address->City =  $_POST["City"];
                    $address->State =  $_POST["State"];
                    $address->ZIP =  $_POST["ZIP"];
                    $address->Country =  $_POST["Country"];
                    $address->Phone =  $_POST["Phone"];
                    $address->Fax =  $_POST["Fax"];
                    if ($address->validate()) {
                        $address->save();
                        echo "adresses\n";
                    }
                }

                $user->User_Login = $_POST["User_Login"];
                $user->User_Type = $_POST["User_Type"];
                $user->Last_Login = $_POST["Last_Login"] ? $_POST["Last_Login"] : null;
                $user->Active = intval($_POST["Active"]);
                if ($user->validate()) {
                    $user->save();
                    echo "user\n";
                }

                $person->First_Name = $_POST["First_Name"];
                $person->Last_Name = $_POST["Last_Name"];
                $person->Email = $_POST["Email"];
                $person->Mobile_Phone = $_POST["Mobile_Phone"];
                $person->Direct_Phone = $_POST["Direct_Phone"];
                $person->Direct_Fax = $_POST["Direct_Fax"];
                if ($person->validate()) {
                    $person->save();
                    echo "person\n";
                }
            }

            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'add') {
            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'del') {
            $userId =  intval($_POST["id"]);
            $user = Users::model()->with('person')->findByPk($userId);
            $documents = Documents::model()->findByAttributes(array(
                'User_ID' => $userId,
            ));

            if ($user && !$documents) {
                $person = $user->person;
                $addresses = $person->adresses;

                if (count($addresses) > 0) {
                    foreach ($addresses as $address) {
                        $address->delete();
                    }
                }

                PersonAddresses::model()->deleteAllByAttributes(array(
                    'Person_ID' => $person->Person_ID,
                ));

                $person->delete();

                UsersSettings::model()->deleteAllByAttributes(array(
                    'User_ID' => $user->User_ID,
                ));

                UsersToApprove::model()->deleteAllByAttributes(array(
                    'User_ID' => $user->User_ID,
                ));

                UsersClientList::model()->deleteAllByAttributes(array(
                    'User_ID' => $user->User_ID,
                ));

                UsersProjectList::model()->deleteAllByAttributes(array(
                    'User_ID' => $user->User_ID,
                ));

                Notes::model()->deleteAllByAttributes(array(
                    'User_ID' => $user->User_ID,
                ));


                $user->delete();
            }

            die;
        }



        $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword);
        mysql_select_db(Yii::app()->params->dbname);
        mysql_query("SET NAMES 'utf8'");

        Yii::import('ext.phpgrid.inc.jqgrid');

        // set columns
        $col = array();
        $col["title"] = "User ID"; // caption of column
        $col["name"] = "User_ID";
        $col["dbname"] = "users.User_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Default Project"; // caption of column
        $col["name"] = "Default_Project";
        $col["dbname"] = "users.Default_Project"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "User Login"; // caption of column
        $col["name"] = "User_Login";
        $col["dbname"] = "users.User_Login"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "User Type"; // caption of column
        $col["name"] = "User_Type";
        $col["dbname"] = "users.User_Type"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["edittype"] = "select";
        $col["editoptions"] = array("value"=>'User:User;Admin:Admin;DB Admin:DB Admin;Data Entry Clerk:Data Entry Clerk');
        $cols[] = $col;

        $col = array();
        $col["title"] = "Last Login"; // caption of column
        $col["name"] = "Last_Login";
        $col["dbname"] = "users.Last_Login"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Active"; // caption of column
        $col["name"] = "Active";
        $col["dbname"] = "users.Active"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = true;
        $col["edittype"] = "select";
        $col["editoptions"] = array("value"=>'0:0;1:1');
        $cols[] = $col;

        $col = array();
        $col["title"] = "Last_IP"; // caption of column
        $col["name"] = "Last_IP";
        $col["dbname"] = "users.Last_IP"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = false; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Person ID"; // caption of column
        $col["name"] = "Person_ID";
        $col["dbname"] = "persons.Person_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "First Name"; // caption of column
        $col["name"] = "First_Name";
        $col["dbname"] = "persons.First_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Last Name"; // caption of column
        $col["name"] = "Last_Name";
        $col["dbname"] = "persons.Last_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Email"; // caption of column
        $col["name"] = "Email";
        $col["dbname"] = "persons.Email"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Mobile Phone"; // caption of column
        $col["name"] = "Mobile_Phone";
        $col["dbname"] = "persons.Mobile_Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Direct Phone"; // caption of column
        $col["name"] = "Direct_Phone";
        $col["dbname"] = "persons.Direct_Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Direct Fax"; // caption of column
        $col["name"] = "Direct_Fax";
        $col["dbname"] = "persons.Direct_Fax"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Address ID"; // caption of column
        $col["name"] = "Address_ID";
        $col["dbname"] = "addresses.Address_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address1"; // caption of column
        $col["name"] = "Address1";
        $col["dbname"] = "addresses.Address1"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address2"; // caption of column
        $col["name"] = "Address2";
        $col["dbname"] = "addresses.Address2"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "City"; // caption of column
        $col["name"] = "City";
        $col["dbname"] = "addresses.City"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "State"; // caption of column
        $col["name"] = "State";
        $col["dbname"] = "addresses.State"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "ZIP"; // caption of column
        $col["name"] = "ZIP";
        $col["dbname"] = "addresses.ZIP"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Country"; // caption of column
        $col["name"] = "Country";
        $col["dbname"] = "addresses.Country"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Phone"; // caption of column
        $col["name"] = "Phone";
        $col["dbname"] = "addresses.Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fax"; // caption of column
        $col["name"] = "Fax";
        $col["dbname"] = "addresses.Fax"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $g = new jqgrid();

        $grid["caption"] = "Users";
        // $grid["multiselect"] = true;
        $grid["autowidth"] = true;
        $grid["resizable"] = true;
        //$grid["toppager"] = true;
        $grid["sortname"] = 'persons.Last_Name';
        $grid["sortorder"] = "ASC";
        $grid["add_options"] = array(
            'width'=>'420',
            "closeAfterEdit"=>true, // close dialog after add/edit
            "top"=>"200", // absolute top position of dialog
            "left"=>"200" // absolute left position of dialog
        );

        $g->set_options($grid);

        $g->set_actions(
            array(
                "add"=>false, // allow/disallow add
                "edit"=>true, // allow/disallow edit
                "delete"=>true, // allow/disallow delete
                "rowactions"=>true, // show/hide row wise edit/del/save option
                "export"=>true, // show/hide export to excel option
                "autofilter" => true, // show/hide autofilter for search
                "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
            )
        );

        $g->select_command = "SELECT addresses.*, persons.*, users.User_ID, users.Default_Project,
                                     users.User_Login, users.User_Type, users.Last_Login, users.Active,
                                     users.Last_IP
                              FROM users
                              LEFT JOIN persons ON users.Person_ID = persons.Person_ID
                              LEFT JOIN person_addresses ON person_addresses.Person_ID = persons.Person_ID
                              LEFT JOIN addresses ON addresses.Address_ID = person_addresses.Address_ID";

        // set database table for CRUD operations
        $g->table = "users";

        $g->set_columns($cols);

        // group columns header
        $g->set_group_header( array(
                "useColSpanStyle"=>true,
                "groupHeaders"=>array(
                    array(
                        "startColumnName"=>'User_ID', // group starts from this column
                        "numberOfColumns"=>7, // group span to next 2 columns
                        "titleText"=>'User Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Person_ID', // group starts from this column
                        "numberOfColumns"=>7, // group span to next 2 columns
                        "titleText"=>'Person Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Address1', // group starts from this column
                        "numberOfColumns"=>8, // group span to next 2 columns
                        "titleText"=>"User's Address" // caption of group header
                    )
                )
            )
        );

        // render grid and get html/js output
        $out = $g->render("Users");

        $this->render('index',array(
            'out'=>$out,
        ));
    }