Example #1
0
    public function appendUserClientList ($client_id){
        $users_client_list = UsersClientList::getClientsUsersArray($client_id);

        $xml_ucl = $this->xml->createElement("users_client_list");

        foreach ($users_client_list as $row) {
            $xml_row = $this->xml->createElement("row");

                foreach ($row as $key=>$value) {
                    $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1'));
                    $xml_field->setAttribute('name', $key);
                    $xml_row->appendChild($xml_field);
                }
            $xml_ucl->appendChild($xml_row);
        }
        $this->wrapper->appendChild($xml_ucl);
    }
Example #2
0
    /**
     * Generate PDF for fake AP using FPDF library without saving to database.
     * @param $poId
     * @param bool $approved
     */
    public static function generatePdfFpdfPreview($ap, $ckRequest, $apDists,$approved = false)
    {
        // get PO formatting
        $poFormatting = PoFormatting::model()->findByAttributes(array(
            'Project_ID' => Yii::app()->user->projectID,
        ));

        // get Sign_Requested_By user info
        $signRequestedByUser = Users::model()->with('person')->findByPk($ckRequest->Sign_Requested_By);

        $aproval_detail_list = Audits::getApprovalDetailList($ap->Document_ID);
        // get current vendor info
        $currentVendor = Vendors::model()->with('client.company.adreses')->findByPk($ap->Vendor_ID);

        $condition = UsersClientList::getClientAdminCondition($currentVendor->client->Client_ID);
        $vendorAdmin = UsersClientList::model()->with('user.person')->find($condition);

        $pdf = new FpdfAp('P','mm','Letter');

        $pdf->AddFont('HelveticaB','','helveticab.php');
        $pdf->AddFont('Courier','','courier.php');
        $pdf->AddFont('CourierB','','courierb.php');
        $pdf->SetAutoPageBreak(true, 10);

        $pdf->setVariables($ap,$poFormatting,$ckRequest,$apDists,$currentVendor,$vendorAdmin,$signRequestedByUser,$aproval_detail_list,$approved);
        $pdf->AliasNbPages();
        $pdf->setPageNo(1);
        //$pdf->AliasNbPages();
        $pdf->AddPage('P');
        $pdf->SetFont('Helvetica','',13.5);
        $pdf->SetXY(5,10);
        $pdf->PrintContent();

        //$path=Helper::createDirectory('batches');// creates directory "protected/data/batches" if not exists
        $fileName = 'ApTempPdf'.date('Y-m-d h:i:s').'.pdf';
        $filepath = Helper::createDirectory('ap');
        $filepath = Helper::createDirectory('ap/'.Yii::app()->user->clientID);
        $filepath.= '/'.$fileName;
        $pdf->Output($filepath, 'F');
        //$pdf->Output();

        $last_page = $pdf->custom_page_num;
        $pdf->Close();


        return array(
            'filename'=>$fileName,
            'filepath'=>$filepath
        );
    }
Example #3
0
    /**
     * Assign project users, when project was edited or created
     * @param $projectId
     */
    public static function assignProjectUsers($projectId)
    {
        $condition = new CDbCriteria();
        $condition->join = "LEFT JOIN users ON users.User_ID = t.User_ID";
        $condition->condition = "t.User_Type = '" . UsersClientList::APPROVER . "'";
        $condition->addCondition("users.User_Type = '" . Users::ADMIN . "'", 'OR');
        $condition->addCondition("users.User_Type = '" . Users::DB_ADMIN . "'", 'OR');
        $condition->addCondition("t.User_Type = '" . UsersClientList::CLIENT_ADMIN . "'", 'OR');
        $condition->addCondition("t.Client_ID = '" . Yii::app()->user->clientID . "'");
        $clientAdminsAndApprovers = UsersClientList::model()->findAll($condition);

        foreach($clientAdminsAndApprovers as $clientAdminsAndApprover) {
            $userProject = UsersProjectList::model()->findByAttributes(array(
                'User_ID' => $clientAdminsAndApprover->User_ID,
                'Project_ID' => $projectId,
            ));

            if (!$userProject) {
                $userProject = new UsersProjectList();
                $userProject->User_ID = $clientAdminsAndApprover->User_ID;
                $userProject->Client_ID = Yii::app()->user->clientID;
                $userProject->Project_ID = $projectId;
                $userProject->save();
            }
        }
    }
Example #4
0
    public static  function LogAction ($doc_id,$event_type) {

        $ucl =UsersClientList::model()->findByAttributes(array(
            'User_ID' => Yii::app()->user->userID,
            'Client_ID' => Yii::app()->user->clientID,
        ));

        $audit = new Audits();
        $audit->Document_ID = $doc_id;
        $audit->Event_Type = $event_type;
        $audit->Event_User_ID = Yii::app()->user->userID;
        $audit->User_Appr_Value = $ucl->User_Approval_Value;
        $audit->Event_Date = date("Y-m-d H:i:s");
        $audit->save();


        //list of actions that cause update of FileCache

        $events_for_cashe_update = array(self::ACTION_PDF,self::ACTION_REPDF,self::ACTION_REVERT,self::ACTION_REUPLOAD,self::ACTION_ROTATE);

        if (in_array($event_type,$events_for_cashe_update)) {
            FileCache::updateFileInCache($doc_id);
        }


    }
Example #5
0
    /**
     * Generate or regenerate PDF for AP using FPDF library
     * @param $apId
     * @param bool $approved
     */
    public static function generatePdfFpdf($doc_id, $doc_type, $approved = false)
    {


        if ( $doc_type == 'AP' ) {
            // get AP
            $ap = Aps::model()->with('dists', 'document', 'ck_req_detail')->findByAttributes(
                array('Document_ID' => $doc_id)
            );

            $ckRequest = $ap->ck_req_detail;

            // get PO dists
            $apDists = $ap->dists;

            // get PO formatting
            $poFormatting = PoFormatting::model()->findByAttributes(array(
                'Project_ID' => $ap->document->Project_ID,
            ));

            // get Sign_Requested_By user info
            $signRequestedByUser = Users::model()->with('person')->findByPk($ckRequest->Sign_Requested_By);

            $aproval_detail_list = Audits::getApprovalDetailList($ap->Document_ID);
            // get current vendor info
            $currentVendor = Vendors::model()->with('client.company.adreses')->findByPk($ap->Vendor_ID);

            $condition = UsersClientList::getClientAdminCondition($currentVendor->client->Client_ID);
            $vendorAdmin = UsersClientList::model()->with('user.person')->find($condition);

            $pdf = new FpdfAp('P','mm','Letter');

            $pdf->AddFont('HelveticaB','','helveticab.php');
            $pdf->AddFont('Courier','','courier.php');
            $pdf->AddFont('CourierB','','courierb.php');
            $pdf->SetAutoPageBreak(true, 10);

            $pdf->setVariables($ap,$poFormatting,$ckRequest,$apDists,$currentVendor,$vendorAdmin,$signRequestedByUser,$aproval_detail_list,$approved);
            $pdf->AliasNbPages();
            $pdf->setPageNo(1);
            //$pdf->AliasNbPages();
            $pdf->AddPage('P');
            $pdf->SetFont('Helvetica','',13.5);
            $pdf->SetXY(5,10);
            $pdf->PrintContent();

            //$path=Helper::createDirectory('batches');// creates directory "protected/data/batches" if not exists
            $fileName = 'ApTempPdf'.date('Y-m-d h:i:s').'.pdf';
            $filepath = Helper::createDirectory('ap');
            $filepath = Helper::createDirectory('ap/'.Yii::app()->user->clientID);
            $filepath.= '/'.$fileName;
            $pdf->Output($filepath, 'F');
            //$pdf->Output();

            $last_page = $pdf->custom_page_num;



            $pdf->Close();
        }
        if (( $doc_type == 'PO' )) {

            $po = Pos::model()->findByAttributes(
                array('Document_ID' => $doc_id)
            );

            // get PO dists
            $poDists = $po->dists;

            // get PO details
            $poDecrDetails = $po->decr_details;

            // get PO formatting
            $poFormatting = PoFormatting::model()->findByAttributes(array(
                'Project_ID' => $po->document->Project_ID,
            ));

            // get Sign_Requested_By user info
            $signRequestedByUser = Users::model()->with('person')->findByPk($po->Sign_Requested_By);

            $aproval_detail_list = Audits::getApprovalDetailList($po->Document_ID);

            // get current vendor info
            $currentVendor = Vendors::model()->with('client.company.adreses')->findByPk($po->Vendor_ID);

            $condition = UsersClientList::getClientAdminCondition($currentVendor->client->Client_ID);
            $vendorAdmin = UsersClientList::model()->with('user.person')->find($condition);

            $paymentTypes = array(
                'OA' => 'On Account',
                'CC' => 'Credit Card',
                'DP' => 'Deposit',
                'CK' => 'Payment Check',
                'PC' => 'Petty Cash',
            );


            $pdf = new FpdfPo('P','mm','Letter');

            $pdf->AddFont('HelveticaB','','helveticab.php');
            $pdf->AddFont('Courier','','courier.php');
            $pdf->AddFont('CourierB','','courierb.php');
            $pdf->SetAutoPageBreak(true, 10);

            $pdf->setVariables($po,$poFormatting,$poDecrDetails,$poDists,$currentVendor,$vendorAdmin,$signRequestedByUser,$aproval_detail_list,$approved,$paymentTypes);
            $pdf->AliasNbPages();
            $pdf->setPageNo(1);
            //$pdf->AliasNbPages();
            $pdf->AddPage('P');
            $pdf->SetFont('Helvetica','',13.5);
            $pdf->SetXY(5,10);
            $pdf->PrintContent();

            //$path=Helper::createDirectory('batches');// creates directory "protected/data/batches" if not exists
            $fileName = 'TempFile.pdf';
            $filepath = Helper::createDirectory('po');
            $filepath = Helper::createDirectory('po/'.Yii::app()->user->clientID);
            $filepath.= '/'.$fileName;
            $pdf->Output($filepath, 'F');
            //$pdf->Output();

            $last_page = $pdf->custom_page_num;
            $pdf->Close();
        }


        return array(
          'path' => $filepath,
          'pages'=> $last_page
        );
    }
Example #6
0
    /**
     * Get list of documents that can be deleted. Used for Ajax request
     * @param $queryString
     * @param $options
     * @param $sortOptions
     * @param int $limit
     * @return CActiveRecord[]
     */
    public static function getDeleteDocListByQueryString($queryString, $options,$sortOptions , $limit = 50)
    {

        $sql="SELECT  d.Document_ID,d.Document_Type,i.File_Name,i.Mime_Type,d.Created,u.User_Login,p.First_Name, p.Last_Name,
                ap.Approved,ap.AP_Approval_Value,po.PO_Approved,po.PO_Approval_Value
            ";

        $sql .="    FROM documents as d
                    right join  images as i on d.Document_ID=i.Document_ID
                    left join  users as u on d.User_ID=u.User_ID
                    left join  persons as p on u.Person_ID=p.Person_ID
                    left join  aps as ap on  ap.Document_ID=d.Document_ID
                    left join  pos as po on   po.Document_ID=d.Document_ID
                    where (ap.Approved!=1 or ap.Approved is null)
                            and (ap.AP_Approval_Value!=100 or ap.AP_Approval_Value is null)
                            and (po.PO_Approved!=1 or po.PO_Approved is null)
                            and (po.PO_Approval_Value!=100 or po.PO_Approval_Value is null)  ";
        //cheking user for client-admin priveleges

        //  1.create instanse of current user
        $user=UsersClientList::model()->findByAttributes(array(
            'User_ID'=>Yii::app()->user->userID,
            'Client_ID'=>Yii::app()->user->clientID,
        ));
        //  2. check for clientadmin priveleges
        if(!$user->hasClientAdminPrivileges()) {
            $sql=$sql." and d.User_ID=".Yii::app()->user->userID ;
        }

        if(Yii::app()->user->projectID != 'all') {
            $sql=$sql." and d.Project_ID=".Yii::app()->user->projectID ;
        }


        if (count($options) > 0 && trim($queryString) != '') {


            $countCond = 0;

            if ($options['search_option_filename']) {
                $sql=$sql." and i.File_Name like('%".$queryString."%') ";
            }
            if ($options['search_option_doctype']) {
                $sql=$sql." and lower(d.Document_Type) like('%".$queryString."%')";
            }
            if ($options['search_option_date']) {
                $sql=$sql." and d.Created>=' ".$queryString." ' ";
            }
            if ($options['search_option_createdby']) {
                $sql=$sql." and (lower(u.User_Login) like('%".$queryString."%') or upper(p.First_Name) like('%".$queryString."%') or upper(p.Last_Name) like('%".$queryString."%')) ";
            }
            if ($options['search_option_modified']) {

            }
        }

        if($sortOptions['sort_by']!='' && $sortOptions['sort_direction']!='') {
            $sql = $sql." order by ".$sortOptions['sort_by'] . " " . $sortOptions['sort_direction'];
        } else {$sql = $sql." order by d.Created desc"; }

        $sql=$sql." limit ".$limit;


        $row = Yii::app()->db->createCommand($sql)->queryAll();
        return $row;

    }
Example #7
0
    public static function getApproversArray ($clientId) {
        $client = Clients::model()->with('company', 'users')->findByPk($clientId);
        $client_users = $client->users;
        $admins_array = array();
        $approvalValue = array();
        $approvers_array = array();


        if ($client_users) {

            //$_SESSION['tabs_to_auto_load']['client_users_list_appr_value'] = array('client_id'=> $client->Client_ID);
            //$_SESSION['admin_active_tab']='us_appr_value';


            foreach ($client_users as $key => $cuser) {

                $uClRow = UsersClientList::model()->findByAttributes(array(
                    'User_ID'=>$cuser->User_ID,
                    'Client_ID'=>$clientId,
                ));

                self::$approversIdValueArray[$cuser->User_ID] = $uClRow->User_Approval_Value;

                $state_appr = $uClRow->hasApproverPrivileges();

                if($state_appr) {
                    $approvers_array[] = array(
                        'user' =>$cuser,
                        'approval_value' =>$uClRow->User_Approval_Value
                    );
                }


            }

            self::$approversArray = $approvers_array;
            usort(self::$approversArray, 'self::sortClientUsersByApprovalValue');
            $approvers_array = self::$approversArray;


        }
        return $approvers_array;
    }
    /**
     * Returns array of summarized settings for current client
     * @return array Tier_Name,Users_Count, Projects_Count, Storage_Count, Base_Fee, Additional_Users,Additional_Projects,Additional_Storage,Additional_Fee
     */
    public static function getSummarySettings($client_id) {
        $result = array();
        $i= 0;
        $limiter ='';
        $client_id = $client_id ? $client_id :Yii::app()->user->clientID;

        $css = ClientServiceSettings::model()->findByPk($client_id);
        $result['Tiers_Str'] = $css->Service_Level_ID;
        $tiers_array = explode(',',$result['Tiers_Str']);
        foreach ($tiers_array as $id) {
            $settings = ServiceLevelSettings::model()->findByPk($id);

            if ($i != 0) {$limiter = ', ';}
            if ($settings->Service_Level_ID == 1) {
                $w9_exist =true;
                $w9_price = $settings->Base_Fee;
                $result['levels_checksum']+=1;
            }
            if ($settings->Service_Level_ID == 2) {
                $result['levels_checksum']+=5;
            }
            if ($settings->Service_Level_ID == 3) {
                $result['levels_checksum']+=10;
            }if ($settings->Service_Level_ID == 4) {
                $result['levels_checksum']+=20;
            }

            $result['Tier_Name'] .= $limiter.$settings->Tier_Name;
            $i++;
         }

        $add_users_price = $settings->Additional_User_Fee;
        $add_projects_price = $settings->Additional_Project_Fee;
        $add_storage_price = $settings->Additional_Storage_Fee;

        $result['Base_Fee'] =  ClientServiceSettings::CalculateBaseFee($tiers_array);
        $result['Users_Count'] = $settings->Users_Count;
        $result['Projects_Count'] = $settings->Projects_Count;
        $result['Storage_Count'] = $settings->Storage_Count;

            $result['Additional_Users'] =$css->Additional_Users;
            $result['Additional_Projects'] =$css->Additional_Projects;
            $result['Additional_Storage'] =$css->Additional_Storage;
            $result['Storage_Index'] = ServiceLevelSettings::getStorageIndexByValue($css->Additional_Storage);
            $result['Additional_Fee'] = $add_users_price * $css->Additional_Users + $add_projects_price*($css->Additional_Projects) + $add_storage_price* ($result['Storage_Index']);

            //$result['Additional_Storage'] =$settings->	Additional_Storage;

        $users = UsersClientList::model()->findAllByAttributes(array(
            'Client_ID'=>$client_id
        ));
        $result['Used_Users'] =count($users);

        $result['Used_Projects'] = Projects::clientProjectUsage();
        $result['Used_Storage'] = ceil(Images::getUsedStorage($client_id));


        return $result;
    }
Example #9
0
    /**
     * ReAuthenticates a user.
     * @param int $timezoneOffset
     * @return boolean whether authentication succeeds.
     */
    public function reauthenticate($timezoneOffset = 0)
    {
        $user = Users::model()->with('person','clients')->find('User_Login=:login',
            array(':login'=>$this->username));
        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 client
            $client = false;
            foreach ($user->clients as $cl) {
                if ($cl->Client_ID == $_SESSION['last_client']) {
                    $client = $cl;
                    break;
                } else {
                    $client = $cl;
                }
            }

            //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);

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

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

                //get projects
                if ($userClientRow->hasClientAdminPrivileges()) {
                    $projects = Projects::model()->findAllByAttributes(array(
                        'Client_ID' => $client->Client_ID,
                    ));
                } else {
                    $condition = new CDbCriteria();
                    $condition->condition = "users_project_list.User_ID = '" . Yii::app()->user->userID . "'";
                    $condition->addCondition("t.Client_ID = '" . $client->Client_ID . "'");
                    $condition->join = "LEFT JOIN users_project_list ON users_project_list.Project_ID = t.Project_ID";
                    $projects = Projects::model()->findAll($condition);
                }

                if ($projects) {
                    if (isset($_SESSION['last_project']) && $_SESSION['last_project'] == 'all') {
                        $this->setState('projectInfo', 'All Projects');
                        $this->setState('projectID', 'all');
                        unset($_SESSION['last_project']);
                        $this->errorCode=self::ERROR_NONE;
                    } elseif (isset($_SESSION['last_project']) && is_numeric($_SESSION['last_project'])) {
                        foreach($projects as $project) {
                            if ($project->Project_ID == $_SESSION['last_project']) {
                                $this->setState('projectInfo', $project->Project_Name);
                                $this->setState('projectID', $project->Project_ID);
                                unset($_SESSION['last_project']);
                                $this->errorCode=self::ERROR_NONE;
                                break;
                            }
                        }
                    } else {
                        $project = $projects[0];
                        $this->setState('projectInfo', $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;
                }

                if ($userClientRow->User_Type == UsersClientList::CLIENT_ADMIN) {
                    $this->username = '******';
                } else if ($userClientRow->User_Type == UsersClientList::APPROVER) {
                    $this->username = '******';
                } else if ($userClientRow->User_Type == UsersClientList::PROCESSOR) {
                    $this->username = '******';
                } else if ($userClientRow->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', $userClientRow->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('projectID', 0);
                $this->setState('userType', 'Single User');
                $this->username = '******';
                $this->errorCode=self::ERROR_NONE;
            }
        }
        return !$this->errorCode;
    }
Example #10
0
    public function generateTabsForAutoLoad (){

        if ( $_SESSION['tabs_to_auto_load']['client_service_level_settings']) {

                $client_id_to_rewiev = intval($_SESSION['tabs_to_auto_load']['client_service_level_settings']['client_id']);

                $client = Clients::model()->with('service_settings', 'service_payments','company')->findByPk($client_id_to_rewiev);
                if ($client) {
                    $serviceLevels = ServiceLevelSettings::getServiceLevelsOptionsList();
                    $settings = $client->service_settings;
                    $items =  ServiceLevelSettings::getServiceLevelsOptionsList();
                    $summary_sl_settings = ServiceLevelSettings::getSummarySettings($client_id_to_rewiev);
                    $dcss = DelayedClientServiceSettings::model()->findByPk($client_id_to_rewiev);
                    $pending_client_service_settings = PendingClientServiceSettings::model()->findByAttributes(array(
                        'Client_ID'=> $client->Client_ID,
                        'Approved'=>1
                    ));

                    $view_data =  $this->renderPartial('client_service_level_settings' , array(
                        'client' => $client,
                        'settings' => $settings,
                        'payments' => $client->service_payments,
                        'serviceLevels' => $serviceLevels,
                        'items'=>$items,
                        'summary_sl_settings'=>$summary_sl_settings,
                        'pending_client_service_settings'=>$pending_client_service_settings,
                        'dcss'=>$dcss
                    ),true);

                    $return_array['client_service_level_settings']['auto_loaded_data'] = $view_data;
                    $return_array['client_service_level_settings']['client'] = $client;
                }
        }

        if ( $_SESSION['tabs_to_auto_load']['client_users_list_appr_value']) {
            $client_id_to_rewiev = intval($_SESSION['tabs_to_auto_load']['client_users_list_appr_value']['client_id']);
            $approvers_array = UsersClientList::getApproversArray($client_id_to_rewiev);

            $view_data =  $this->renderPartial('client_users_list_appr_value' , array(
                         'approvers_array'=>$approvers_array,
            ),true);

            $return_array['client_users_list_appr_value']['auto_loaded_data'] = $view_data;
            $return_array['client_users_list_appr_value']['client'] = Clients::model()->with('company', 'users')->findByPk($client_id_to_rewiev);;
        }

        return $return_array;
    }
    <div id="client_admin_appr_value" class="grid-view">

        <h2>At least one Approver must have an Approval value of 100.</h2>
        <div id="ua_loaded_client_id" data-id="<?=$client->Client_ID?>" ><?='Client '.$client->Client_ID.' / '.$client->company->Company_Name?></div>
        <form method="post" action="/myaccount/updateUsersApprovalValues" id="appr_value_form" autocomplete="off">
            <input type="hidden" name="clientID" value="" id="client_id_input"/>
            <table class="items mbot0">
                <thead>
                <tr>
                    <th class="width160"><span>Name</span></th><th class="width160"><span>Email</span></th><th><span>Approval Value</span></th>
                </tr>
                </thead>
            </table>
            <div style="max-height: 400px; overflow: auto">
                <table class="items" id="client_admin_appr_value_table">
                    <?     $approvers_array = UsersClientList::getApproversArray(Yii::app()->user->clientID);
                    if (count($approvers_array)) {
                        foreach ($approvers_array as $item) {
                            $user = $item['user'];
                            $apr_value = $item['approval_value'];
                            echo '<tr id="user' . $user->User_ID  . '">';
                            echo '<td class="width160">' . CHtml::encode($user->person->First_Name . ' '  . $user->person->Last_Name) .  '</td><td class="width160"><span class="ov_hidden width160">' . CHtml::encode($user->person->Email) .  '</span></td><td><input class="input_in_grid appr_value_input" type="text" size="5" maxlength="3" name="users[' . $user->User_ID . ']" value="' . $apr_value .'"/></td>';
                            echo '</tr>';

                        }
                    } else {
                        echo '<tr id="user0">';
                        echo '<td clospan="3">Users were not found</td>';
                        echo '</tr>';
                    } ?>
                </table>
Example #12
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,
        ));
	}
	/**
	 * 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,
        ));
	}
Example #14
0
    /**
     * 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,
        ));
    }