⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Search Column issues



vallstn

vallstn
  • profile picture
  • Member

Posted 20 June 2020 - 05:32 AM

I Have Developed a website using Grocery Crud Enterprise. I Have restricted the data column based on the user login credential. I have  encountered the following issues.

1. The search column list all the values of the column, however table shows only restricted data.

2. Some of the users start enter data on search column and press enter, which results the data submission on db leads to data corruption. Hence i have disabled the search columns to avoid data corruption. Now it is ok, but could not use search column.

 

The controller code as follows,

 

public function worder()
    {
        $office_id = $this->ion_auth->user()->row()->company;
        $emp_id = $this->ion_auth->user()->row()->first_name;    
        
        $this->session->set_userdata('menu', 'Work Order');
        
        $crud = $this->_getGroceryCrudEnterprise();
        $crud->setTable('solar_workorder');
        $crud->setSubject('Work Order', 'Solar Powered Pumpset - Work Order List');
        $crud->columns(['farmerid','wonumber','wodate', 'model', 'pumptype', 'pumpcapacity', 'totalcost', 'farmercontrib', 'subsidy']);
        $crud->unsetSearchColumns(['farmerid','wonumber','wodate', 'model', 'pumptype', 'pumpcapacity', 'totalcost', 'farmercontrib', 'subsidy']);
        $crud->editFields(['solar_company_id', 'wonumber', 'wodate', 'wocopy', 'model', 'pumptype', 'pumpcapacity']);
        $crud->requiredFields(['solar_company_id', 'wonumber', 'wodate', 'wocopy', 'model', 'pumptype', 'pumpcapacity']);
        $crud->unsetFields(['farmerid', 'officeid']);
        
        $crud->fieldType('solar_company_id', 'hidden');
        $crud->fieldType('totalcost', 'hidden');
        $crud->fieldType('farmercontrib', 'hidden');
        $crud->fieldType('subsidy', 'hidden');
        
        $crud->displayAs('farmerid', 'Name of Farmer');
        $crud->displayAs('officeid', 'Name of Office');
        $crud->displayAs('solar_company_id', 'Solar Firm');
        $crud->displayAs('wonumber', 'Work Order Number');
        $crud->displayAs('wodate', 'Date of Work Order');
        $crud->displayAs('wocopy', 'Workorder Document');
        $crud->displayAs('pumptype', 'Pumpset - Type');
        $crud->displayAs('pumpcapacity', 'Pump HP');
        $crud->displayAs('totalcost', 'Total Cost (Rs.)');
        $crud->displayAs('farmercontrib', 'Farmer Contribution (Rs.)');
        $crud->displayAs('subsidy', 'Subsidy (Rs.)');    
        
        $crud->setRule('wonumber', 'regex', '/^[A-Za-z0-9,]+([\ A-Za-z0-9,]+)*/');
        //$crud->setRule('wodate', 'date');
        
        $crud->unsetAdd();
        $crud->unsetDelete();
        
        $crud->setFieldUpload('wocopy', 'UuploadD/wocopy', 'wocopy');
        
        $aeegroup = 'AEE'; $eegroup = 'EE'; $segroup = 'SE';
        if ($this->ion_auth->in_group($aeegroup))
        {    
            $crud->where(['officeid' => $office_id]);
        } else {
            $crud->unsetEdit();
            
            if ($this->ion_auth->in_group($eegroup))
            {    
                $this->db->select('sdkey');
                $this->db->from('aed_admin_subdivision');
                $this->db->where('sdfkey_division', $office_id);
                $filter=$this->db->get()->result();

                $count='0';
                $this->db->select('sdkey');
                $this->db->from('aed_admin_subdivision');
                $this->db->where('sdfkey_division', $office_id);
                $count=$this->db->count_all_results();
                
                $con='(';
                $id=$count;
                foreach ($filter as $row) {
                    $cat = $row->sdkey;
                    if ($id==1) { $con = $con . $cat ; } else { $con = $con . $cat . ','; }
                    $id=$id-1;
                }
                $con = 'officeid'.' '.'IN'.' '.$con . ')'.' ';                
                $crud->where([$con ]);
            } else if ($this->ion_auth->in_group($segroup)) {
                $this->db->select('sdkey');
                $this->db->from('aed_admin_subdivision');
                $this->db->where('sdfkey_region', $office_id);
                $filter=$this->db->get()->result();

                $count='0';
                $this->db->select('sdkey');
                $this->db->from('aed_admin_subdivision');
                $this->db->where('sdfkey_region', $office_id);
                $count=$this->db->count_all_results();
                
                $con='(';
                $id=$count;
                foreach ($filter as $row) {
                    $cat = $row->sdkey;
                    if ($id==1) { $con = $con . $cat ; } else { $con = $con . $cat . ','; }
                    $id=$id-1;
                }
                $con = 'officeid'.' '.'IN'.' '.$con . ')'.' ';                
                $crud->where([$con ]);
            }
        }
        
        $crud->setRelation('farmerid', 'solar_benificiery', 'bname');
        $crud->setRelation('officeid', 'aed_offices', 'ename');
        $crud->setRelation('model', 'solar_master_ptype', 'description');
        $crud->setRelation('pumptype', 'solar_master_ptype2', 'description');
        $crud->setRelation('pumpcapacity', 'solar_master_php', 'description');
        
        $crud->unsetBootstrap();
        $crud->unsetJquery();
        
        $crud->callbackAfterUpdate(function ($stateParameters)  {
            $office_id = $this->ion_auth->user()->row()->company;
            
            $this->db->select('farmerid, officeid, solar_company_id, dealer');
            $this->db->where('pkey', $stateParameters->primaryKeyValue);
            $farmer = $this->db->get('solar_workorder')->row();
            
            if ($farmer->officeid == $office_id)
            {
                $data = array(
                    'farmerid' => $farmer->farmerid,
                    'officeid' => $farmer->officeid,
                    'solar_company_id' => $farmer->solar_company_id,
                    'dealer' => $farmer->dealer
                );
                
                $this->db->where('farmerid', $farmer->farmerid);
                $test = $this->db->get('solar_ins_material')->row();
                
                if (!empty($test)) {
                    $this->db->update('solar_ins_material', $data);
                } else {$this->db->insert('solar_ins_material', $data);}

                $data1 = array(
                    'workorder_status' => '1',
                );
                
                $this->db->where('beneficiery_id', $farmer->farmerid);
                $test1 = $this->db->get('solar_farmer_status')->row();
                
                if (!empty($test1)) {
                    $this->db->update('solar_farmer_status', $data1);
                } else {$this->db->insert('solar_farmer_status', $data1);}    
            }
            return $stateParameters;
        });
        
        $crud->setCsrfTokenName($this->security->get_csrf_token_name());
        $crud->setCsrfTokenValue($this->security->get_csrf_hash());
        
        $output = $crud->render();
        return $this->_crud_output($output);
    }

Can you kindly guide me to fix this issue.