[eluser]originalmmd[/eluser]
Model
Code:
<?php
class employeeselect_model extends CI_Model {
function __construct() {
// Call the Model constructor
parent::__construct();
$this -> load -> database();
}
public function get_jobs() {
$this -> db -> select('*');
//change this to the two main values you want to use
$this -> db -> from('jobs');
$this -> db -> order_by("description", "asc");
//$this -> db -> where('category_online', 1);
$query = $this -> db -> get();
foreach ($query->result_array() as $row) {
$data[] = $row;
}
return $data;
}
public function get_people() {
$this -> db -> select('*');
//change this to the two main values you want to use
$this -> db -> from('person');
$this -> db -> order_by("department", "asc");
$this -> db -> order_by("userid", "asc");
//$this -> db -> where('category_online', 1);
$query = $this -> db -> get();
foreach ($query->result_array() as $row) {
$data[] = $row;
}
return $data;
}
function get_person() {
$query = $this -> db -> get('person');
return $query -> result();
}
function get_phase() {
$this -> load -> database();
$data = $_POST;
$data['phaseid'] = 1;
}
function newtimespan() {
$this -> load -> database();
$this -> load -> helper('date');
$datapst = $_POST;
$this -> db -> from('punch');
$this -> db -> where('firstname', $datapst['firstname']);
$this -> db -> order_by("id", "desc");
$this -> db -> limit(1);
$query = $this -> db -> get();
foreach ($query->result_array() as $row) {
$data = $row;
}
if ($data['projectid'] != '302') {
$data['workperiod'] = 'nothing';
//$current_time = getdate();
//MAKE TIME
$now = time();
$data['time'] = elapsed_time($data['timest'], $now);
$data['entrydate'] = timestamp_to_mysqldatetime($now);
$data['activitydate'] = timestamp_to_mysqldatetime($data['timest']);
unset($data['id']);
$this -> db -> insert('time', $data);
}
elseif ($data['projectid'] == '302' && $data['status'] = '1') {
$data['workperiod'] = 'nothing';
//$current_time = getdate();
//MAKE TIME
$now = time();
$data['time'] = elapsed_time($data['timest'], $now);
$data['entrydate'] = timestamp_to_mysqldatetime($now);
$data['activitydate'] = timestamp_to_mysqldatetime($data['timest']);
unset($data['id']);
$this -> db -> insert('time', $data);
}
}
function newpunch_in() {
$this -> load -> database();
$data = $_POST;
//get status
$sql = "SELECT status, projectid FROM punch WHERE firstname=? ORDER BY id DESC LIMIT 1";
$query = $this -> db -> query($sql, array($data['firstname']));
foreach ($query->result() as $row) {
$data['status'] = $row -> status;
$datanew['projectid'] = $row -> projectid;
}
//get phase
$data['phaseid'] = 1;
$data['activityid'] = '1';
$data['todate'] = '1';
$data['remark'] = '1';
$data['timest'] = now();
$data['workperiod'] = '1';
foreach ($datanew as $rows) {
//set status
if ($datanew['projectid'] != '302' && $datanew['projectid'] == $data['projectid']) {
$data['projectid'] = '302';
$data['status'] = '1';
}
else {
$data['status'] = '0';
$datanew['projectid'] = $data['projectid'];
}
}
unset($data['id']);
$this -> db -> insert('punch', $data);
}