Is a user has composed a message, other users be able to should approve the message but the message Author should only delete and edit not approve. The below if statement is supposed to work for that but its not
Code:
<td>
<?php $author = array(
$message->user_id == $this->session->userdata('id')
); ?>
<?php if($author): ?>
<?php echo anchor('admin/messages/edit/'.$message->id.'', 'Edit', 'class="btn btn-primary"'); ?>
<?php echo anchor('admin/messages/delete/'.$message->id.'', 'Delete', 'class="btn btn-danger"'); ?>
<?php endif; ?>
<?php if(!$author): ?>
<?php echo anchor('admin/messages/approve/'.$message->id.'', 'Approve', 'class="btn btn-success"'); ?>
<?php endif; ?>
</td>
The code below is the *approve* METHOD in my CONTROLLER which is supposed to check the **condition** before passing data to the MODEL
Code:
public function approve($id)
{
$this->db->select('*');
$this->db->from('approval');
$this->db->join('messages', 'messages.id = approval.sms_id');
$query = $this->db->get();
$first_approval = $query->row('first_approval');
$second_approval = $query->row('second_approval');
$third_approval = $query->row('third_approval');
if ($first_approval == null) {
$data = array(
'first_approval' => $this->session->userdata('user_id')
);
$approval_data = array(
'approvals' => 'one'
);
$this->Message_model->some_approve($id, $approval_data);
$this->Message_model->approve($id, $data);
//Activity array
$data = array(
'resource_id' => '',
'type' => 'message',
'action' => 'approved',
'user_id' => $this->session->userdata('user_id'),
'message' => 'Message was approved'
);
//Insert Activity
$this->Activity_model->add($data);
//isset Message
$this->session->set_flashdata('success', 'Your approval was send');
//Redirect
redirect('admin/messages');
} elseif ($second_approval == null && $this->session->userdata('user_id') != $first_approval) {
$data = array(
'second_approval' => $this->session->userdata('user_id')
);
$approval_data = array(
'approvals' => 'two'
);
$this->Message_model->some_approve($id, $approval_data);
$this->Message_model->approve($id, $data);
//Activity array
$data = array(
'resource_id' => '',
'type' => 'message',
'action' => 'approved',
'user_id' => $this->session->userdata('user_id'),
'message' => 'Message was approved'
);
//Insert Activity
$this->Activity_model->add($data);
//isset Message
$this->session->set_flashdata('success', 'Your approval was send');
//Redirect
redirect('admin/messages');
} elseif ($third_approval == null && $this->session->userdata('user_id') != $second_approval && $this->session->userdata('user_id') != $first_approval) {
$data = array(
'third_approval' => $this->session->userdata('user_id')
);
$approval_data = array(
'status' => 'Approved',
'approvals' => 'three'
);
$this->Message_model->approve($id, $data);
$this->Message_model->some_approve($id, $approval_data);
//Activity array
$data = array(
'resource_id' => '',
'type' => 'message',
'action' => 'approved',
'user_id' => $this->session->userdata('user_id'),
'message' => 'Message was approved'
);
//Insert Activity
$this->Activity_model->add($data);
//isset Message
$this->session->set_flashdata('success', 'Your approval was send and the message has passed');
//Redirect
redirect('admin/messages');
} elseif ($third_approval == $this->session->userdata('user_id') || $this->session->userdata('user_id') == $second_approval || $this->session->userdata('user_id') == $first_approval) {
//isset Message
$this->session->set_flashdata('success', 'You already have send an approval');
//Redirect
redirect('admin/messages');
} else {
$approval_data = array(
'status' => 'Approved',
'approvals' => 'three'
);
$this->Message_model->some_approve($id, $approval_data);
//isset Message
$this->session->set_flashdata('success', 'Your approval was send and the message has already been send');
//Redirect
redirect('admin/messages');
}
}
The METHODS below are working
Code:
public function approve($id, $data) {
$this->db->where('sms_id', $id);
$this->db->update('approval',$data);
}
public function some_approve($id, $approval_data)
{
$this->db->where('id', $id);
$this->db->update('messages',$approval_data);
}
The if conditions in my controller and on the buttons are the ones which I need help on because the are not showing any error but they are not working as they should