forked from bbalet/jorani
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
412 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,41 +20,35 @@ | |
|
||
class Leaves extends CI_Controller { | ||
|
||
/** | ||
* Connected user fullname | ||
* @var string $fullname | ||
*/ | ||
private $fullname; | ||
|
||
/** | ||
* Connected user privilege | ||
* @var bool true if admin, false otherwise | ||
*/ | ||
private $is_admin; | ||
|
||
public function __construct() { | ||
parent::__construct(); | ||
//Check if user is connected | ||
if (!$this->session->userdata('logged_in')) { | ||
redirect('session/login'); | ||
} | ||
|
||
$this->fullname = $this->session->userdata('firstname') . ' ' . | ||
$this->session->userdata('lastname'); | ||
$this->is_admin = $this->session->userdata('is_admin'); | ||
$this->load->model('leaves_model'); | ||
/* | ||
//See: http://www.codeigniter.fr/user_guide/libraries/email.html | ||
$this->load->library('email'); | ||
$config['protocol'] = 'sendmail'; | ||
$config['mailpath'] = '/usr/sbin/sendmail'; | ||
$config['charset'] = 'iso-8859-1'; | ||
$config['wordwrap'] = TRUE; | ||
$this->email->initialize($config); | ||
$this->email->from('[email protected]', 'Your Name'); | ||
$this->email->to('[email protected]'); | ||
$this->email->cc('[email protected]'); | ||
$this->email->bcc('[email protected]'); | ||
$this->email->subject('Email Test'); | ||
$this->email->message('Testing the email class.'); | ||
$this->email->send(); | ||
echo $this->email->print_debugger(); */ | ||
} | ||
|
||
public function index() { | ||
$data['leaves'] = $this->leaves_model->get_leaves(); | ||
$data['title'] = 'My Leave Requests'; | ||
$data['fullname'] = $this->fullname; | ||
$data['is_admin'] = $this->is_admin; | ||
$this->load->view('templates/header', $data); | ||
$this->load->view('menu/index', $data); | ||
$this->load->view('leaves/index', $data); | ||
|
@@ -66,7 +60,9 @@ public function view($id) { | |
if (empty($data['leaves_item'])) { | ||
show_404(); | ||
} | ||
$data['title'] = 'User'; | ||
$data['title'] = 'Leave details'; | ||
$data['fullname'] = $this->fullname; | ||
$data['is_admin'] = $this->is_admin; | ||
$this->load->view('templates/header', $data); | ||
$this->load->view('menu/index', $data); | ||
$this->load->view('leaves/view', $data); | ||
|
@@ -77,6 +73,8 @@ public function create() { | |
$this->load->helper('form'); | ||
$this->load->library('form_validation'); | ||
$data['title'] = 'Request a leave'; | ||
$data['fullname'] = $this->fullname; | ||
$data['is_admin'] = $this->is_admin; | ||
|
||
$this->form_validation->set_rules('startdate', 'Start Date', 'required'); | ||
$this->form_validation->set_rules('startdatetype', 'Start Date type', 'required'); | ||
|
@@ -93,6 +91,34 @@ public function create() { | |
$this->load->view('templates/footer'); | ||
} else { | ||
$this->leaves_model->set_leaves(); | ||
$this->load->model('users_model'); | ||
$this->load->model('settings_model'); | ||
$manager = $this->users_model->get_users($this->session->userdata('manager')); | ||
|
||
//Send an e-mail to the manager | ||
//See: http://www.codeigniter.fr/user_guide/libraries/email.html | ||
$this->load->library('email'); | ||
$config = $this->settings_model->get_mail_config(); | ||
$this->email->initialize($config); | ||
|
||
$this->load->library('parser'); | ||
$data = array( | ||
'Title' => 'Leave Request', | ||
'Firstname' => $this->session->userdata('firstname'), | ||
'Lastname' => $this->session->userdata('lastname'), | ||
'StartDate' => $this->input->post('startdate'), | ||
'EndDate' => $this->input->post('enddate') | ||
); | ||
$message = $this->parser->parse('emails/request', $data, TRUE); | ||
|
||
$this->email->from('[email protected]', 'LMS'); | ||
$this->email->to($manager['email']); | ||
$this->email->subject('[LMS] Leave Request from ' . | ||
$this->session->userdata('firstname') . ' ' . | ||
$this->session->userdata('lastname')); | ||
$this->email->message($message); | ||
$this->email->send(); | ||
//echo $this->email->print_debugger(); | ||
$this->index(); | ||
} | ||
} | ||
|
@@ -140,7 +166,7 @@ public function export() { | |
$line++; | ||
} | ||
|
||
/*//For debug purposes | ||
/*//For debuging purposes | ||
$filename = 'testFile.csv'; | ||
header('Content-Type: text/csv'); | ||
header('Content-Disposition: attachment;filename="' . $filename . '"'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.