[eluser]afro[/eluser]
1.the view
Code:
<div id="leaveapproval"><?php echo $num_results;?> pending leave(s)found</b>
<?php echo form_open('administration/processleave');?><table border="1" align="center" id="leaveapprovaltable"><tbody><?php foreach($leaves as $leave):?><tr><td>Application Id</td><td><input type="text" name="applicationid" value="<?php echo $leave->ApplicationId;?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Staff Name</td><td><input type="text" name="staffname" value="<?php echo $leave->StaffName; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr>
<tr><td>Leave Balance</td><td><input type="text" name="leavebalance" value="<?php echo $leave->LeaveBalance; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Days Requested</td><td><input type="text" name="noofdaysrequested" value="<?php echo $leave->NoofDaysRequested; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Leave Type</td><td><input type="text" name="leavetype" value="<?php echo $leave->LeaveType; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Commencement Date</td><td><input type="text" name="commencementdate" value="<?php echo $leave->CommencementDate; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Reporting Back</td><td><input type="text" name="Dateforreportingback" value="<?php echo $leave->Dateforreportingback;?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Current Project</td><td><input type="text" name="currentproject" value="<?php echo $leave->CurrentProject; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Handed To</td><td><input type="text" name="handedto" value="<?php echo $leave->HandedTo; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Comment</td><td><input type="text" name="comment" value="<?php echo $leave->Comment;?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td colspan="2" align="center"> Appove:<?php echo form_radio('approve','Approved');?>Reject: <?php echo form_radio('approve','Rejected');?></td></tr><tr><td colspan="2" align="center"><?php echo form_submit('leaveapproval','Submit Form'), form_reset('reset','Cancel');?></td></tr><?php endforeach; ?></tbody></table>
2.The controller
Code:
class Administration extends Controller{
function processleave(){
parent::controller();$this->load->helper(array ('url')); $this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div id="prompt_error">', '</div>'); $this->form_validation->set_rules('approve','Approval','required');
if($this->form_validation->run()==FALSE)
{$this->load->view('administration'); else{$this->load->model('Administration_model');
$query = $this->Administration_model->approvedleaves();}
if($query){$offset=0,$limit = 1; $this->load->model('Administration_model');
$results = $this->Administration_model->search($limit, $offset);$data['leaves'] = $results['rows'];
$data['num_results'] = $results['num_rows'];$this->load->library('pagination');
$config = array();$config['base_url'] = site_url("Administration_model/search");
$config['total_rows'] = $data['num_results'];$config['per_page'] = $limit; $config['uri_segment'] = 5; $this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links();
redirect('administration',$data);}}
public function nextleave()
{$offset=0,$limit = 1;$results = $this->search($limit, $offset);$data['leaves'] = $results['rows'];
$data['num_results'] = $results['num_rows'];$this->load->library('pagination'); $config = array(); $config['base_url'] = site_url("Administration_model/search"); $config['total_rows'] = $data['num_results']; $config['per_page'] = $limit; $config['uri_segment'] = 5;$this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links(); redirect('administration',$data);}}
3. The model class is as follows
Code:
class Administration_model extends Model{
public function search($limit, $offset)
{parent::Model();
$q = $this->db->select('ApplicationId, StaffName, LeaveBalance, NoofDaysRequested, LeaveType, CommencementDate, Dateforreportingback, CurrentProject, HandedTo, Comment');
$this->db->from('appliedleaves');
$where = "Status = 'Pending'";
$this->db->where($where);$this->db->limit($limit, $offset);$ret['rows'] = $q->get()->result();
$q= $this->db->select('COUNT(*) as count', FALSE); $where = "Status = 'Pending'"; $this->db->where($where);
$this->db->from('appliedleaves'); $tmp = $q->get()->result(); $ret['num_rows'] = $tmp[0]->count;return $ret;}
function approvedleaves(){
$approve = "Status ='" . mysql_real_escape_string($this->input->post('approve')) . "' WHERE ApplicationId LIKE " . mysql_real_escape_string($this->input->post('applicationid'));
$query = $this->db->update('appliedleaves',$approve);
if($query = 1)
{$approvedleaves=array('ApplicationId'=>$this->input->post('applicationid'),'StaffName'=>$this->input->post('staffname'),'LeaveBalance'=>$this->input->post('leavebalance'),'DaysRequested'=>$this->input->post('noofdaysrequested'),'LeaveType'=>$this->input->post('leavetype'),'CommencementDate'=>$this->input->post('commencedate'),'ReportingBack'=>$this->input->post('dateforreportingdate'),'CurrentProject'=>$this->input->post('currentproject'),'HandedTo'=>$this->input->post('handedto'),'Comment'=>$this->input->post('comment') );
$query = $this->db->insert('helpdesklevel_leaves', $approvedleaves);
if($query){
/*i want after the approved/rejected leave has been saved, i want the system to load the next leave from the db to the view at this point*/
class Administration::nextleave();}}}}