| Server IP : 10.200.247.200 / Your IP : 216.73.217.19 Web Server : Apache System : Linux synergy-usa-sites 6.8.0-138-generic #138-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 22:41:49 UTC 2026 x86_64 User : jeremy ( 1001) PHP Version : 8.4.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/hans_sites/phonelesswork.com/ |
Upload File : |
<?php
session_start();
include_once($_SERVER['DOCUMENT_ROOT'].'/php/mysql.php');
/*if(empty($_SESSION['company_db'])) {
header("Location: /login.php");
exit(0);
}*/
if(!empty($_POST['action'])) {
switch($_POST['action']) {
case 'update_company_info':
if(!empty($_SESSION['company_db'])) {
$db->query("UPDATE timeclock_devices
SET company_name='".$db->clean($_POST['company_name'])."'
,company_email='".$db->clean($_POST['company_email'])."'
,company_phone='".$db->clean(preg_replace('/[^0-9]/','',$_POST['company_phone']))."'
,company_address='".$db->clean($_POST['company_address'])."'
,company_ste='".$db->clean($_POST['company_ste'])."'
,api_7shift='".$db->clean((!empty($_POST['api_7shift'])) ? '1' : '0')."'
,api_7shift_key='".$db->clean($_POST['api_7shift_key'])."'
WHERE device_id='".$db->clean($_SESSION['company_db'])."'");
if(!empty($_POST['api_7shift']) && !empty($_POST['api_7shift_key'])) {
//check to see if the database exists
$res = $db->get_results("SHOW TABLES LIKE timeclock_".$db->clean($_SESSION['company_db'])."_7shifts_employees");
if(empty($res)) {
$db->query("CREATE TABLE timeclock_".$db->clean($_SESSION['company_db'])."_7shifts_employees
(
id INT NOT NULL AUTO_INCREMENT
,firstname VARCHAR(32) NOT NULL
,lastname VARCHAR(64) NOT NULL
,user_type_id INT NOT NULL
,email VARCHAR(255) NOT NULL
,mobile_phone VARCHAR(10) NOT NULL
,home_phone VARCHAR(10) NOT NULL
,payroll_id INT NOT NULL
,employee_id INT NOT NULL
,active TINYINT(1) NOT NULL
,location_id INT NOT NULL
,department_id INT NOT NULL
,role_id INT NOT NULL
,hourly_wage DOUBLE
,phonelesswork_employee_id INT NOT NULL
,ts TIMESTAMP DEFAULT NOW()
,PRIMARY KEY (id)
)");
$db->query("CREATE INDEX emp_id ON timeclock_".$db->clean($_SESSION['company_db'])."_7shifts_employees (phonelesswork_employee_id)");
$db->query("CREATE INDEX emp_name ON timeclock_".$db->clean($_SESSION['company_db'])."_7shifts_employees (firstname,lastname)");
include_once($_SERVER['DOCUMENT_ROOT'].'/php/api_7shifts.php');
$users = get_user_list($_POST['api_7shift_key']);
if(!empty($users)) {
foreach($users as $u) {
$db->query("INSERT INTO timeclock_".$db->clean($_SESSION['company_db'])."_7shifts_employees
(
firstname
,lastname
,user_type_id
,email
,mobile_phone
,home_phone
,payroll_id
,employee_id
,active
,location_id
,department_id
,role_id
,hourly_wage
,phonelesswork_employee_id
,ts
) VALUES (
'".$db->clean($u['firstname'])."'
,'".$db->clean($u['lastname'])."'
,'".$db->clean($u['user_type_id'])."'
,'".$db->clean($u['email'])."'
,'".$db->clean($u['mobile_phone'])."'
,'".$db->clean($u['home_phone'])."'
,'".$db->clean($u['payroll_id'])."'
,'".$db->clean($u['employee_id'])."'
,'".$db->clean($u['active'])."'
,'".$db->clean($u['location_id'])."'
,'".$db->clean($u['department_id'])."'
,'".$db->clean($u['role_id'])."'
,'".$db->clean($u['hourly_wage'])."'
,'0'
,NOW()
)");
}
}
}
}
}
break;
case 'update_device_info':
if(!empty($_SESSION['company_db'])) {
if(!empty($_POST['id_7shift'])) {
$res_7shift = $db->get_results("SELECT * FROM timeclock_{$_SESSION['company_db']}_7shifts_employees
WHERE id='".$db->clean($_POST['id_7shift'])."'");
if(!empty($res_7shift)) {
$res = $db->get_results("SELECT id FROM timeclock_users_".$db->clean($_SESSION['company_db'])."
WHERE serial_number='".$db->clean($_POST['serial'])."'");
if(!empty($res)) {
$db->query("UPDATE timeclock_users_".$db->clean($_SESSION['company_db'])."
SET first_name='".$db->clean($res_7shift[0]->firstname)."'
,last_name='".$db->clean($res_7shift[0]->lastname)."'
,email='".$db->clean($res_7shift[0]->email)."'
,phone='".$db->clean(preg_replace('/[^0-9]/','',$res_7shift[0]->mobile_phone))."'
WHERE id='".$db->clean($res[0]->id)."'");
$db->query("UPDATE timeclock_{$_SESSION['company_db']}_7shifts_employees
SET phonelesswork_employee_id='".$db->clean($res[0]->id)."'
WHERE id='".$db->clean($_POST['id_7shift'])."'");
} else {
$db->query("INSERT INTO timeclock_users_".$db->clean($_SESSION['company_db'])."
(
serial_number
,first_name
,last_name
,phone
,email
) VALUES (
'".$db->clean($_POST['serial'])."'
,'".$db->clean($res_7shift[0]->firstname)."'
,'".$db->clean($res_7shift[0]->lastname)."'
,'".$db->clean(preg_replace('/[^0-9]/','',$res_7shift[0]->mobile_phone))."'
,'".$db->clean($res_7shift[0]->email)."'
)");
$db->query("UPDATE timeclock_{$_SESSION['company_db']}_7shifts_employees
SET phonelesswork_employee_id='".$db->clean($db->last_insert_id())."'
WHERE id='".$db->clean($_POST['id_7shift'])."'");
}
}
} else {
$res = $db->get_results("SELECT id FROM timeclock_users_".$db->clean($_SESSION['company_db'])."
WHERE serial_number='".$db->clean($_POST['serial'])."'");
if(!empty($res)) {
$db->query("UPDATE timeclock_users_".$db->clean($_SESSION['company_db'])."
SET first_name='".$db->clean($_POST['first_name'])."'
,last_name='".$db->clean($_POST['last_name'])."'
,email='".$db->clean($_POST['email'])."'
,phone='".$db->clean(preg_replace('/[^0-9]/','',$_POST['phone']))."'
WHERE id='".$db->clean($res[0]->id)."'");
} else {
$db->query("INSERT INTO timeclock_users_".$db->clean($_SESSION['company_db'])."
(
serial_number
,first_name
,last_name
,phone
,email
) VALUES (
'".$db->clean($_POST['serial'])."'
,'".$db->clean($_POST['first_name'])."'
,'".$db->clean($_POST['last_name'])."'
,'".$db->clean(preg_replace('/[^0-9]/','',$_POST['phone']))."'
,'".$db->clean($_POST['email'])."'
)");
}
}
//Update the timeclock_all_pis_users database
$company_id_res = $db->get_results("SELECT company_id FROM timeclock_devices WHERE device_id='".$db->clean($_SESSION['company_db'])."'");
$company_id = (empty($company_id_res)) ? 0 : $company_id_res[0]->company_id;
$res = $db->get_results("SELECT id FROM timeclock_all_pis_users
WHERE serial_number='".$db->clean($_POST['serial'])."'
AND (pi_id='".$db->clean($_SESSION['company_db'])."' OR (company_id='".$db->clean($company_id)."' AND company_id<>0))");
if(!empty($res)) {
$db->query("UPDATE timeclock_all_pis_users
SET company_id='".$db->clean($company_id)."'
,first_name='".$db->clean($_POST['first_name'])."'
,last_name='".$db->clean($_POST['last_name'])."'
,email='".$db->clean($_POST['email'])."'
,phone='".$db->clean(preg_replace('/[^0-9]/','',$_POST['phone']))."'
WHERE id='".$db->clean($res[0]->id)."'");
} else {
$db->query("INSERT INTO phonelesswork.timeclock_all_pis_users
(
pi_id
,company_id
,serial_number
,first_name
,last_name
,phone
,email
,date_created
) VALUES (
'".$db->clean($_SESSION['company_db'])."'
,'".$db->clean($company_id)."'
,'".$db->clean($_POST['serial'])."'
,'".$db->clean($_POST['first_name'])."'
,'".$db->clean($_POST['last_name'])."'
,'".$db->clean(preg_replace('/[^0-9]/','',$_POST['phone']))."'
,'".$db->clean($_POST['email'])."'
,NOW()
)");
}
}
break;
case 'delete_entries_today':
$db->query("DELETE FROM timeclock_".$db->clean($_SESSION['company_db'])."
WHERE clock_in >= CURDATE()");
$db->query("DELETE FROM debug_from_pi
WHERE ts >= CURDATE()
AND pi_id='".$db->clean($_SESSION['company_db'])."'");
echo 'Finished clearing entries for today.';
break;
case 'run_timeclock_report':
$db->query("DELETE FROM timeclock_".$db->clean($_SESSION['company_db'])."
WHERE clock_in BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND clock_out='0000-00-00 00:00:00'
AND DATE(clock_in) < CURDATE()");
if($_POST['report_type']=='currently_clocked_in') {
/*$res = $db->get_results("SELECT t.serial_number,t.clock_in,t.clock_out,u.first_name,u.last_name
FROM timeclock_".$db->clean($_SESSION['company_db'])." t
LEFT JOIN timeclock_users_".$db->clean($_SESSION['company_db'])." u ON u.serial_number=t.serial_number
WHERE t.clock_in >= CURDATE()
AND t.clock_out='0000-00-00 00:00:00'
GROUP BY t.serial_number
ORDER BY t.clock_in ASC");
*/
$res = $db->get_results("SELECT id,ts,debug_info
FROM phonelesswork.debug_from_pi
WHERE ts BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND pi_id='".$db->clean($_SESSION['company_db'])."'
ORDER BY ts ASC");
$sns = array();
$users = array();
$clocked_in = array();
foreach($res as $r) {
$json = json_decode($r->debug_info);
$json->id = $r->id;
if(empty($sns[$json->phone_id])) {
$res2 = $db->get_results("SELECT first_name,last_name
FROM timeclock_users_".$db->clean($_SESSION['company_db'])."
WHERE serial_number='".$db->clean($json->phone_id)."'");
if(empty($res2)) {
$sns[$json->phone_id] = $json->phone_id;
$users[$json->phone_id] = array();
} else {
$sns[$json->phone_id] = $res2[0]->first_name.' '.$res2[0]->last_name;
$users[$res2[0]->first_name.' '.$res2[0]->last_name] = array();
}
}
$username = $sns[$json->phone_id];
$users[$username][] = $json;
}
foreach($users as $name=>$timeclock) {
$is_clocked_in = false;
$clocked_in_time = '';
foreach($timeclock as $t) {
if($t->action_type=='ADD') {
$is_clocked_in = true;
$clocked_in_time = date('M j, Y g:i:s a',strtotime($t->date));
} else {
$is_clocked_in = false;
}
}
if($is_clocked_in) {
$clocked_in[$name] = $clocked_in_time;
}
}
ksort($clocked_in);
foreach($clocked_in as $name=>$time) {
?>
<div style="margin:10px 0px;"><strong><?= $name;?></strong> - <?= $time;?></div>
<?php
}
} elseif($_POST['report_type']=='show_debug_info') {
if($_POST['employees']=='all') {
$res = $db->get_results("SELECT id,ts,debug_info
FROM phonelesswork.debug_from_pi
WHERE ts BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND pi_id='".$db->clean($_SESSION['company_db'])."'
ORDER BY ts ASC");
} else {
$res = $db->get_results("SELECT id,ts,debug_info
FROM phonelesswork.debug_from_pi
WHERE ts BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND pi_id='".$db->clean($_SESSION['company_db'])."'
AND phone_id='".$db->clean($_POST['employees'])."'
ORDER BY ts ASC");
}
$sns = array();
$users = array();
foreach($res as $r) {
$json = json_decode($r->debug_info);
$json->id = $r->id;
if(empty($sns[$json->phone_id])) {
$res2 = $db->get_results("SELECT first_name,last_name
FROM timeclock_users_".$db->clean($_SESSION['company_db'])."
WHERE serial_number='".$db->clean($json->phone_id)."'");
if(empty($res2)) {
$sns[$json->phone_id] = $json->phone_id;
$users[$json->phone_id] = array();
} else {
$sns[$json->phone_id] = $res2[0]->first_name.' '.$res2[0]->last_name;
$users[$res2[0]->first_name.' '.$res2[0]->last_name] = array();
}
}
$username = $sns[$json->phone_id];
$users[$username][] = $json;
}
foreach($users as $name=>$timeclock) {
?>
<div style="margin-top:20px;"><?= $name;?></div>
<table class="timeclock_table" cellpadding="0" cellspacing="0">
<tr>
<tr>
<th>Pi ID</th>
<th>Phone ID</th>
<th>Action Type</th>
<th>Live/CSV</th>
<th>Version</th>
<th>Date (MST)</th>
<?php if(!empty($_SESSION['company_id'])) { ?>
<th>Edit</th>
<th>Delete</th>
<?php } ?>
</tr>
</tr>
<?php
$total = 0;
foreach($timeclock as $t) {
if($t->date=='0000-00-00 00:00:00') {
continue;
}
?>
<tr>
<td><?= $t->pi_id;?></td>
<td><?= $t->phone_id;?></td>
<td><?= $t->action_type;?></td>
<td><?= $t->is_live;?></td>
<td><?= $t->version;?></td>
<td><?= date('M j, Y g:i:s a',strtotime($t->date));?></td>
<?php if(!empty($_SESSION['company_id'])) { ?>
<td>
<div style="padding:0px 10px;"><button onclick="$('#edit_container_<?= $t->id;?>').toggle(); return false;" class="submit_button" style="border:1px solid #2DADFB; font-size:14px;padding:10px 20px;margin-top:0px;width:90px;">Edit</button></div>
<div id="edit_container_<?= $t->id;?>" style="display:none;">
<hr />
<form onsubmit="really_edit_timeclock(this); return false;" method="post" action="#" style="padding:5px;text-align:center;">
<input type="hidden" name="id" value="<?= trim($t->id);?>" />
<input type="hidden" name="pi_id" value="<?= trim($t->pi_id);?>" />
<input type="hidden" name="phone_id" value="<?= trim($t->phone_id);?>" />
<input type="hidden" name="is_live" value="<?= trim($t->is_live);?>" />
<input type="hidden" name="version" value="<?= trim($t->version);?>" />
<input type="hidden" name="debug_version" value="<?= trim($t->debug_version);?>" />
<div style="margin:5px 0px;">
<label>
Action Type<br />
<select name="action_type" style="border:1px solid #2DADFB;font-size:13px;">
<option value="ADD" <?= ($t->action_type=='ADD') ? 'selected' : '';?>>ADD</option>
<option value="REMOVE" <?= ($t->action_type=='REMOVE') ? 'selected' : '';?>>REMOVE</option>
</select>
</label>
</div>
<div style="margin:5px 0px;">
<label>
Date<br />
<input type="text" name="date" value="<?= $t->date;?>" style="border:1px solid #2DADFB;font-size:13px;" />
</label>
</div>
<div style="margin:5px 0px;" class="save_button_container">
<input type="submit" name="submit" value="Save" class="submit_button" style="border:1px solid #2DADFB; font-size:14px;padding:10px 20px;margin-top:0px;width:90px;" />
</div>
</form>
</div>
</td>
<td>
<button onclick="really_delete_timeclock(this,'<?= $t->id;?>'); return false;" class="submit_button" style="border:1px solid #2DADFB; font-size:14px;padding:10px 20px;margin-top:0px;width:90px;">Delete</button>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
<?php
}
} elseif($_POST['report_type']=='first_clock_in_last_clock_out') {
function make_pretty_time($sec) {
$hours = 0;
$minutes = 0;
$seconds = $sec;
if($seconds >= 3600) {
while($seconds>=3600) {
$seconds -= 3600;
$hours++;
}
}
if($seconds >= 60) {
while($seconds >= 60) {
$seconds -= 60;
$minutes++;
}
}
return str_pad($hours,2,"0",STR_PAD_LEFT).':'.str_pad($minutes,2,"0",STR_PAD_LEFT).':'.str_pad($seconds,2,"0",STR_PAD_LEFT);
}
function figure_out_bonus($seconds) {
$hours = $seconds/3600;
if($hours>=2.83) {
return $hours * 1.5;
} elseif($hours>=1.83) {
return $hours * 1;
} elseif($hours>=0.83) {
return $hours * 0.5;
} else {
return 0;
}
}
if($_POST['employees']=='all') {
$res = $db->get_results("SELECT ts,debug_info
FROM phonelesswork.debug_from_pi
WHERE ts BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND pi_id='".$db->clean($_SESSION['company_db'])."'
ORDER BY ts ASC");
} else {
$res = $db->get_results("SELECT ts,debug_info
FROM phonelesswork.debug_from_pi
WHERE ts BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND pi_id='".$db->clean($_SESSION['company_db'])."'
AND phone_id = '".$db->clean($_POST['employees'])."'
ORDER BY ts ASC");
}
$sns = array();
$users = array();
foreach($res as $r) {
$json = json_decode($r->debug_info);
if(empty($sns[$json->phone_id])) {
$res2 = $db->get_results("SELECT first_name,last_name
FROM timeclock_users_".$db->clean($_SESSION['company_db'])."
WHERE serial_number='".$db->clean($json->phone_id)."'");
if(empty($res2)) {
$sns[$json->phone_id] = $json->phone_id;
$users[$json->phone_id] = array();
} else {
$sns[$json->phone_id] = $res2[0]->first_name.' '.$res2[0]->last_name;
$users[$res2[0]->first_name.' '.$res2[0]->last_name] = array();
}
}
$username = $sns[$json->phone_id];
$users[$username][] = $json;
}
foreach($users as $name=>$times) {
$first_clockin_days = array();
$last_clockout_days = array();
foreach($times as $time) {
$time_date = date('Y-m-d',strtotime($time->date));
if(empty($first_clockin_days[$time_date])) {
$first_clockin_days[$time_date] = $time->date;
} elseif(strtotime($first_clockin_days[$time_date]) > strtotime($time->date)) {
$first_clockin_days[$time_date] = $time->date;
}
if(empty($last_clockout_days[$time_date])) {
$last_clockout_days[$time_date] = $time->date;
} elseif(strtotime($last_clockout_days[$time_date]) < strtotime($time->date)) {
$last_clockout_days[$time_date] = $time->date;
}
}
$new_times = array();
foreach($first_clockin_days as $k=>$v) {
$new_times[] = (object) array('serial_number'=>$times[0]->serial_number,'clock_in'=>$first_clockin_days[$k],'clock_out'=>$last_clockout_days[$k],'first_name'=>$times[0]->first_name,'last_name'=>$times[0]->last_name);
}
$users[$name] = $new_times;
}
?>
<div>Bonus is based on:</div>
<table class="timeclock_table" cellpadding="0" cellspacing="0">
<tr>
<th>Hours</th>
<th>Bonus Amount</th>
</tr>
<tr>
<td>1+ Hours</td>
<td>$0.50</td>
</tr>
<tr>
<td>2+ Hours</td>
<td>$1.00</td>
</tr>
<tr>
<td>3+ Hours</td>
<td>$1.50</td>
</tr>
</table>
<?php
foreach($users as $name=>$timeclock) {
?>
<div style="margin-top:20px;"><?= $name;?></div>
<table class="timeclock_table" cellpadding="0" cellspacing="0">
<tr>
<th>CLOCKED IN</th>
<th>CLOCKED OUT</th>
<th>HOURS</th>
<th>BONUS</th>
</tr>
<?php
$total = 0;
$total_bonus = 0;
$days_total = array();
$days_total_bonus = array();
$current_day = '';
foreach($timeclock as $t) {
if($current_day=='') {
$current_day = date('Y-m-d',strtotime($t->clock_in));
}
if($current_day!=date('Y-m-d',strtotime($t->clock_in))) {
?>
<tr>
<td colspan="2"><?= date('M j, Y',strtotime($current_day));?> Total</td>
<td><?= make_pretty_time($days_total[$current_day]);?></td>
<td>$<?= number_format(round($days_total_bonus[$current_day],2),2);?></td>
</tr>
<?php
$current_day = date('Y-m-d',strtotime($t->clock_in));
}
$tclock_out = $t->clock_out;
if($t->clock_out=='0000-00-00 00:00:00') {
$total += (time() - strtotime($t->clock_in));
$tclock_out = date('Y-m-d H:i:s');
} else {
$total += (strtotime($t->clock_out) - strtotime($t->clock_in));
}
$bonus = figure_out_bonus(strtotime($tclock_out) - strtotime($t->clock_in));
$total_bonus += $bonus;
if(empty($days_total[$current_day])) {
$days_total[$current_day] = 0;
}
if(empty($days_total_bonus[$current_day])) {
$days_total_bonus[$current_day] = 0;
}
$days_total[$current_day] += (strtotime($t->clock_out) - strtotime($t->clock_in));
$days_total_bonus[$current_day] += $bonus;
?>
<tr>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>><?= date('M j, Y g:i:s a',strtotime($t->clock_in));?></td>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>><?= ($t->clock_out=='0000-00-00 00:00:00') ? 'Still Clocked In' : date('M j, Y g:i:s a',strtotime($t->clock_out));?></td>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>><?= make_pretty_time(strtotime($tclock_out) - strtotime($t->clock_in));?></td>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>>$<?= number_format(round($bonus,2),2);?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2"><?= date('M j, Y',strtotime($current_day));?> Total</td>
<td><?= make_pretty_time($days_total[$current_day]);?></td>
<td>$<?= number_format(round($days_total_bonus[$current_day],2),2);?></td>
</tr>
<tr>
<td colspan="2">TOTAL</td>
<td><?= make_pretty_time($total);?></td>
<td>$<?= number_format(round($total_bonus,2),2);?></td>
</tr>
</table>
<?php
}
} elseif($_POST['report_type']=='ignore_multiple_removes') {
function make_pretty_time($sec) {
$hours = 0;
$minutes = 0;
$seconds = $sec;
if($seconds >= 3600) {
while($seconds>=3600) {
$seconds -= 3600;
$hours++;
}
}
if($seconds >= 60) {
while($seconds >= 60) {
$seconds -= 60;
$minutes++;
}
}
return str_pad($hours,2,"0",STR_PAD_LEFT).':'.str_pad($minutes,2,"0",STR_PAD_LEFT).':'.str_pad($seconds,2,"0",STR_PAD_LEFT);
}
function figure_out_bonus($seconds) {
$hours = $seconds/3600;
if($hours>=2.83) {
return $hours * 1.5;
} elseif($hours>=1.83) {
return $hours * 1;
} elseif($hours>=0.83) {
return $hours * 0.5;
} else {
return 0;
}
}
if($_POST['employees']=='all') {
$res = $db->get_results("SELECT ts,debug_info
FROM phonelesswork.debug_from_pi
WHERE ts BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND pi_id='".$db->clean($_SESSION['company_db'])."'
ORDER BY ts ASC");
} else {
$res = $db->get_results("SELECT ts,debug_info
FROM phonelesswork.debug_from_pi
WHERE ts BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND pi_id='".$db->clean($_SESSION['company_db'])."'
AND phone_id = '".$db->clean($_POST['employees'])."'
ORDER BY ts ASC");
}
$sns = array();
$users = array();
foreach($res as $r) {
$json = json_decode($r->debug_info);
if(empty($sns[$json->phone_id])) {
$res2 = $db->get_results("SELECT first_name,last_name
FROM timeclock_users_".$db->clean($_SESSION['company_db'])."
WHERE serial_number='".$db->clean($json->phone_id)."'");
if(empty($res2)) {
$sns[$json->phone_id] = $json->phone_id;
$users[$json->phone_id] = array();
} else {
$sns[$json->phone_id] = $res2[0]->first_name.' '.$res2[0]->last_name;
$users[$res2[0]->first_name.' '.$res2[0]->last_name] = array();
}
}
$username = $sns[$json->phone_id];
$users[$username][] = $json;
}
foreach($users as $name=>$times) {
$new_times = array();
$first_clock_ins = array();
$current_add = '0000-00-00 00:00:00';
foreach($times as $time) {
if($time->action_type=='ADD') {
$current_add = $time->date;
} else {
if(strtotime(date('Y-m-d',strtotime($current_add)))==strtotime(date('Y-m-d',strtotime($time->date)))) {
if(empty($first_clock_ins[$current_add])) {
$first_clock_ins[$current_add] = $time->date;
} elseif(strtotime($first_clock_ins[$current_add]) < strtotime($time->date)) {
$first_clock_ins[$current_add] = $time->date;
}
} else {
$first_clock_ins[$time->date] = $time->date;
}
}
}
foreach($first_clock_ins as $k=>$v) {
$new_times[] = (object) array('serial_number'=>$times[0]->serial_number,'clock_in'=>$k,'clock_out'=>$first_clock_ins[$k],'first_name'=>$times[0]->first_name,'last_name'=>$times[0]->last_name);
}
$users[$name] = $new_times;
/*
$first_clockin_days = array();
$last_clockout_days = array();
foreach($times as $time) {
$time_date = date('Y-m-d',strtotime($time->date));
if(empty($first_clockin_days[$time_date])) {
$first_clockin_days[$time_date] = $time->date;
} elseif(strtotime($first_clockin_days[$time_date]) > strtotime($time->date)) {
$first_clockin_days[$time_date] = $time->date;
}
if(empty($last_clockout_days[$time_date])) {
$last_clockout_days[$time_date] = $time->date;
} elseif(strtotime($last_clockout_days[$time_date]) < strtotime($time->date)) {
$last_clockout_days[$time_date] = $time->date;
}
}
$new_times = array();
foreach($first_clockin_days as $k=>$v) {
$new_times[] = (object) array('serial_number'=>$times[0]->serial_number,'clock_in'=>$first_clockin_days[$k],'clock_out'=>$last_clockout_days[$k],'first_name'=>$times[0]->first_name,'last_name'=>$times[0]->last_name);
}
$users[$name] = $new_times;*/
}
if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) {
?>
<div>Bonus is based on:</div>
<table class="timeclock_table" cellpadding="0" cellspacing="0">
<tr>
<th>Hours</th>
<th>Bonus Amount</th>
</tr>
<tr>
<td>1+ Hours</td>
<td>$0.50</td>
</tr>
<tr>
<td>2+ Hours</td>
<td>$1.00</td>
</tr>
<tr>
<td>3+ Hours</td>
<td>$1.50</td>
</tr>
</table>
<?php
}
foreach($users as $name=>$timeclock) {
?>
<div style="margin-top:20px;"><?= $name;?></div>
<table class="timeclock_table" cellpadding="0" cellspacing="0">
<tr>
<th>CLOCKED IN</th>
<th>CLOCKED OUT</th>
<th>HOURS</th>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<th>BONUS</th>
<th>DAY BONUS</th>
<?php } ?>
</tr>
<?php
$total = 0;
$total_bonus = 0;
$days_total = array();
$days_total_bonus = array();
$current_day = '';
foreach($timeclock as $t) {
if($current_day=='') {
$current_day = date('Y-m-d',strtotime($t->clock_in));
}
if($current_day!=date('Y-m-d',strtotime($t->clock_in))) {
?>
<tr>
<td colspan="2"><?= date('M j, Y',strtotime($current_day));?> Total</td>
<td><?= make_pretty_time($days_total[$current_day]);?></td>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<td>$<?= number_format(round($days_total_bonus[$current_day],2),2);?></td>
<td>$<?= number_format(round(figure_out_bonus($days_total[$current_day]),2),2);?></td>
<?php } ?>
</tr>
<?php
$current_day = date('Y-m-d',strtotime($t->clock_in));
}
$tclock_out = $t->clock_out;
if($t->clock_out=='0000-00-00 00:00:00') {
$total += (time() - strtotime($t->clock_in));
$tclock_out = date('Y-m-d H:i:s');
} else {
$total += (strtotime($t->clock_out) - strtotime($t->clock_in));
}
$bonus = figure_out_bonus(strtotime($tclock_out) - strtotime($t->clock_in));
$total_bonus += $bonus;
if(empty($days_total[$current_day])) {
$days_total[$current_day] = 0;
}
if(empty($days_total_bonus[$current_day])) {
$days_total_bonus[$current_day] = 0;
}
$days_total[$current_day] += (strtotime($t->clock_out) - strtotime($t->clock_in));
$days_total_bonus[$current_day] += $bonus;
?>
<tr>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>><?= date('M j, Y g:i:s a',strtotime($t->clock_in));?></td>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>><?= ($t->clock_out=='0000-00-00 00:00:00') ? 'Still Clocked In' : date('M j, Y g:i:s a',strtotime($t->clock_out));?></td>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>><?= make_pretty_time(strtotime($tclock_out) - strtotime($t->clock_in));?></td>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>>$<?= number_format(round($bonus,2),2);?></td>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>></td>
<?php } ?>
</tr>
<?php } ?>
<?php if(!empty($current_day)) { ?>
<tr>
<td colspan="2"><?= date('M j, Y',strtotime($current_day));?> Total</td>
<td><?= make_pretty_time($days_total[$current_day]);?></td>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<td>$<?= number_format(round($days_total_bonus[$current_day],2),2);?></td>
<td>$<?= number_format(round(figure_out_bonus($days_total[$current_day]),2),2);?></td>
<?php } ?>
</tr>
<?php } ?>
<tr>
<td colspan="2">TOTAL</td>
<td><?= make_pretty_time($total);?></td>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<td>$<?= number_format(round($total_bonus,2),2);?></td>
<td>$<?= number_format(round(figure_out_bonus($total),2),2);?></td>
<?php } ?>
</tr>
</table>
<?php
}
} elseif($_POST['report_type']=='ignore_multiple_removes_new') {
function make_pretty_time($sec) {
$hours = 0;
$minutes = 0;
$seconds = $sec;
if($seconds >= 3600) {
while($seconds>=3600) {
$seconds -= 3600;
$hours++;
}
}
if($seconds >= 60) {
while($seconds >= 60) {
$seconds -= 60;
$minutes++;
}
}
return str_pad($hours,2,"0",STR_PAD_LEFT).':'.str_pad($minutes,2,"0",STR_PAD_LEFT).':'.str_pad($seconds,2,"0",STR_PAD_LEFT);
}
function figure_out_bonus($seconds) {
$hours = $seconds/3600;
if($hours>=2.83) {
return $hours * 1.5;
} elseif($hours>=1.83) {
return $hours * 1;
} elseif($hours>=0.83) {
return $hours * 0.5;
} else {
return 0;
}
}
if($_POST['employees']=='all') {
$res = $db->get_results("SELECT ts,debug_info
FROM phonelesswork.debug_from_pi
WHERE ts BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND pi_id='".$db->clean($_SESSION['company_db'])."'
ORDER BY ts ASC");
} else {
$res = $db->get_results("SELECT ts,debug_info
FROM phonelesswork.debug_from_pi
WHERE ts BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
AND pi_id='".$db->clean($_SESSION['company_db'])."'
AND phone_id = '".$db->clean($_POST['employees'])."'
ORDER BY ts ASC");
}
$sns = array();
$users = array();
foreach($res as $r) {
$json = json_decode($r->debug_info);
if(empty($sns[$json->phone_id])) {
$res2 = $db->get_results("SELECT first_name,last_name
FROM timeclock_users_".$db->clean($_SESSION['company_db'])."
WHERE serial_number='".$db->clean($json->phone_id)."'");
if(empty($res2)) {
$sns[$json->phone_id] = $json->phone_id;
$users[$json->phone_id] = array();
} else {
$sns[$json->phone_id] = $res2[0]->first_name.' '.$res2[0]->last_name;
$users[$res2[0]->first_name.' '.$res2[0]->last_name] = array();
}
}
$username = $sns[$json->phone_id];
$users[$username][] = $json;
}
foreach($users as $name=>$times) {
$new_times = array();
$first_clock_ins = array();
$current_add = '0000-00-00 00:00:00';
$last_actions = array();
foreach($times as $k=>$time) {
if(empty($last_actions[$time->serial_number])) {
$last_actions[$time->serial_number] = 'ADD';
} else {
if($last_actions[$time->serial_number]=='ADD') {
$last_actions[$time->serial_number] = 'REMOVE';
} else {
$last_actions[$time->serial_number] = 'ADD';
}
}
$times[$k]->action_type = $last_actions[$time->serial_number];
}
foreach($times as $time) {
if($time->action_type=='ADD') {
$current_add = $time->date;
} else {
if(strtotime(date('Y-m-d',strtotime($current_add)))==strtotime(date('Y-m-d',strtotime($time->date)))) {
if(empty($first_clock_ins[$current_add])) {
$first_clock_ins[$current_add] = $time->date;
} elseif(strtotime($first_clock_ins[$current_add]) < strtotime($time->date)) {
$first_clock_ins[$current_add] = $time->date;
}
} else {
$first_clock_ins[$time->date] = $time->date;
}
}
}
foreach($first_clock_ins as $k=>$v) {
$new_times[] = (object) array('serial_number'=>$times[0]->serial_number,'clock_in'=>$k,'clock_out'=>$first_clock_ins[$k],'first_name'=>$times[0]->first_name,'last_name'=>$times[0]->last_name);
}
$users[$name] = $new_times;
/*
$first_clockin_days = array();
$last_clockout_days = array();
foreach($times as $time) {
$time_date = date('Y-m-d',strtotime($time->date));
if(empty($first_clockin_days[$time_date])) {
$first_clockin_days[$time_date] = $time->date;
} elseif(strtotime($first_clockin_days[$time_date]) > strtotime($time->date)) {
$first_clockin_days[$time_date] = $time->date;
}
if(empty($last_clockout_days[$time_date])) {
$last_clockout_days[$time_date] = $time->date;
} elseif(strtotime($last_clockout_days[$time_date]) < strtotime($time->date)) {
$last_clockout_days[$time_date] = $time->date;
}
}
$new_times = array();
foreach($first_clockin_days as $k=>$v) {
$new_times[] = (object) array('serial_number'=>$times[0]->serial_number,'clock_in'=>$first_clockin_days[$k],'clock_out'=>$last_clockout_days[$k],'first_name'=>$times[0]->first_name,'last_name'=>$times[0]->last_name);
}
$users[$name] = $new_times;*/
}
if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) {
?>
<div>Bonus is based on:</div>
<table class="timeclock_table" cellpadding="0" cellspacing="0">
<tr>
<th>Hours</th>
<th>Bonus Amount</th>
</tr>
<tr>
<td>1+ Hours</td>
<td>$0.50</td>
</tr>
<tr>
<td>2+ Hours</td>
<td>$1.00</td>
</tr>
<tr>
<td>3+ Hours</td>
<td>$1.50</td>
</tr>
</table>
<?php
}
foreach($users as $name=>$timeclock) {
?>
<div style="margin-top:20px;"><?= $name;?></div>
<table class="timeclock_table" cellpadding="0" cellspacing="0">
<tr>
<th>CLOCKED IN</th>
<th>CLOCKED OUT</th>
<th>HOURS</th>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<th>BONUS</th>
<th>DAY BONUS</th>
<?php } ?>
</tr>
<?php
$total = 0;
$total_bonus = 0;
$days_total = array();
$days_total_bonus = array();
$current_day = '';
foreach($timeclock as $t) {
if($current_day=='') {
$current_day = date('Y-m-d',strtotime($t->clock_in));
}
if($current_day!=date('Y-m-d',strtotime($t->clock_in))) {
?>
<tr>
<td colspan="2"><?= date('M j, Y',strtotime($current_day));?> Total</td>
<td><?= make_pretty_time($days_total[$current_day]);?></td>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<td>$<?= number_format(round($days_total_bonus[$current_day],2),2);?></td>
<td>$<?= number_format(round(figure_out_bonus($days_total[$current_day]),2),2);?></td>
<?php } ?>
</tr>
<?php
$current_day = date('Y-m-d',strtotime($t->clock_in));
}
$tclock_out = $t->clock_out;
if($t->clock_out=='0000-00-00 00:00:00') {
$total += (time() - strtotime($t->clock_in));
$tclock_out = date('Y-m-d H:i:s');
} else {
$total += (strtotime($t->clock_out) - strtotime($t->clock_in));
}
$bonus = figure_out_bonus(strtotime($tclock_out) - strtotime($t->clock_in));
$total_bonus += $bonus;
if(empty($days_total[$current_day])) {
$days_total[$current_day] = 0;
}
if(empty($days_total_bonus[$current_day])) {
$days_total_bonus[$current_day] = 0;
}
$days_total[$current_day] += (strtotime($t->clock_out) - strtotime($t->clock_in));
$days_total_bonus[$current_day] += $bonus;
?>
<tr>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>><?= date('M j, Y g:i:s a',strtotime($t->clock_in));?></td>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>><?= ($t->clock_out=='0000-00-00 00:00:00') ? 'Still Clocked In' : date('M j, Y g:i:s a',strtotime($t->clock_out));?></td>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>><?= make_pretty_time(strtotime($tclock_out) - strtotime($t->clock_in));?></td>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>>$<?= number_format(round($bonus,2),2);?></td>
<td <?= ($tclock_out==$t->clock_in) ? 'style="color:red;"' : '';?>></td>
<?php } ?>
</tr>
<?php } ?>
<?php if(!empty($current_day)) { ?>
<tr>
<td colspan="2"><?= date('M j, Y',strtotime($current_day));?> Total</td>
<td><?= make_pretty_time($days_total[$current_day]);?></td>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<td>$<?= number_format(round($days_total_bonus[$current_day],2),2);?></td>
<td>$<?= number_format(round(figure_out_bonus($days_total[$current_day]),2),2);?></td>
<?php } ?>
</tr>
<?php } ?>
<tr>
<td colspan="2">TOTAL</td>
<td><?= make_pretty_time($total);?></td>
<?php if(!empty($_SESSION['company_id']) && in_array($_SESSION['company_id'],array('1','3'))) { ?>
<td>$<?= number_format(round($total_bonus,2),2);?></td>
<td>$<?= number_format(round(figure_out_bonus($total),2),2);?></td>
<?php } ?>
</tr>
</table>
<?php
}
} else {
if($_POST['employees']=='all') {
$res = $db->get_results("SELECT t.serial_number,t.clock_in,t.clock_out,u.first_name,u.last_name
FROM timeclock_".$db->clean($_SESSION['company_db'])." t
LEFT JOIN timeclock_users_".$db->clean($_SESSION['company_db'])." u ON u.serial_number=t.serial_number
WHERE t.clock_in BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
ORDER BY t.clock_in ASC");
} else {
$res = $db->get_results("SELECT t.serial_number,t.clock_in,t.clock_out,u.first_name,u.last_name
FROM timeclock_".$db->clean($_SESSION['company_db'])." t
LEFT JOIN timeclock_users_".$db->clean($_SESSION['company_db'])." u ON u.serial_number=t.serial_number
WHERE t.serial_number='".$db->clean($_POST['employees'])."'
AND t.clock_in BETWEEN '".$db->clean($_POST['start_date'])." 00:00:00' AND '".$db->clean($_POST['end_date'])." 23:59:59'
ORDER BY t.clock_in ASC");
}
$users = array();
foreach($res as $r) {
if(empty($r->first_name)) {
$users[$r->serial_number][] = $r;
} else {
$users[$r->first_name.' '.$r->last_name][] = $r;
}
}
ksort($users);
if(!empty($_POST['report_type']=='combine_close_times')) {
$combine_times_time = 60; //if the clock out and next clock in are within this many seconds combine them.
foreach($users as $uk=>$times) {
$changes = true;
while($changes) {
$i=0;
$changes = false;
$times_temp = array();
foreach($times as $k=>$v) {
$times_temp[] = $v;
}
$times = $times_temp;
foreach($times as $k=>$time) {
$i++;
if($i<count($times)) {
if(strtotime($times[$i]->clock_in) - $combine_times_time <= strtotime($times[$k]->clock_out)) {
if(strtotime($times[$i]->clock_out) > strtotime($times[$k]->clock_out)) {
$times[$k]->clock_out = $times[$i]->clock_out;
}
unset($times[$i]);
$changes = true;
break;
}
}
}
}
$users[$uk] = $times;
}
} elseif($_POST['report_type']=='first_clock_in_last_clock_out') {
foreach($users as $uk=>$times) {
$first_clockin_days = array();
$last_clockout_days = array();
foreach($times as $time) {
if($time->clock_out=='0000-00-00 00:00:00') {
$time->clock_out = date('Y-m-d H:i:s');
}
$start_time_date = date('Y-m-d',strtotime($time->clock_in));
$end_time_date = date('Y-m-d',strtotime($time->clock_out));
if(empty($first_clockin_days[$start_time_date])) {
$first_clockin_days[$start_time_date] = $time->clock_in;
} elseif(strtotime($first_clockin_days[$start_time_date]) > strtotime($time->clock_in)) {
$first_clockin_days[$start_time_date] = $time->clock_in;
}
if(empty($last_clockout_days[$end_time_date])) {
$last_clockout_days[$end_time_date] = $time->clock_out;
} elseif(strtotime($last_clockout_days[$end_time_date]) < strtotime($time->clock_out)) {
$last_clockout_days[$end_time_date] = $time->clock_out;
}
}
$new_times = array();
foreach($first_clockin_days as $k=>$v) {
$new_times[] = (object) array('serial_number'=>$times[0]->serial_number,'clock_in'=>$first_clockin_days[$k],'clock_out'=>$last_clockout_days[$k],'first_name'=>$times[0]->first_name,'last_name'=>$times[0]->last_name);
}
$users[$uk] = $new_times;
}
}
function make_pretty_time($sec) {
$hours = 0;
$minutes = 0;
$seconds = $sec;
if($seconds >= 3600) {
while($seconds>=3600) {
$seconds -= 3600;
$hours++;
}
}
if($seconds >= 60) {
while($seconds >= 60) {
$seconds -= 60;
$minutes++;
}
}
return str_pad($hours,2,"0",STR_PAD_LEFT).':'.str_pad($minutes,2,"0",STR_PAD_LEFT).':'.str_pad($seconds,2,"0",STR_PAD_LEFT);
}
foreach($users as $name=>$timeclock) {
?>
<div style="margin-top:20px;"><?= $name;?></div>
<table class="timeclock_table" cellpadding="0" cellspacing="0">
<tr>
<th>CLOCKED IN</th>
<th>CLOCKED OUT</th>
<th>HOURS</th>
</tr>
<?php
$total = 0;
foreach($timeclock as $t) {
$tclock_out = $t->clock_out;
if($t->clock_out=='0000-00-00 00:00:00') {
$total += (time() - strtotime($t->clock_in));
$tclock_out = date('Y-m-d H:i:s');
} else {
$total += (strtotime($t->clock_out) - strtotime($t->clock_in));
}
?>
<tr>
<td><?= date('M j, Y g:i:s a',strtotime($t->clock_in));?></td>
<td><?= ($t->clock_out=='0000-00-00 00:00:00') ? 'Still Clocked In' : date('M j, Y g:i:s a',strtotime($t->clock_out));?></td>
<td><?= make_pretty_time(strtotime($tclock_out) - strtotime($t->clock_in));?></td>
</tr>
<?php } ?>
<tr>
<td colspan="2">TOTAL</td>
<td><?= make_pretty_time($total);?></td>
</tr>
</table>
<?php
}
}
break;
case 'send_contact_form':
$to = 'hanskirchhausen@gmail.com';
$from = 'NoReply@surfcrm.com';
$subject = 'PhoneLessWork.com Contact';
$body = "<p>{$_POST['fullname']} filled out the contact form.</p>
<p>
Full Name: {$_POST['fullname']}<br />
Email: {$_POST['email']}<br />
Cell Phone: {$_POST['cell_phone']}<br />
Notes: {$_POST['notes']}
</p>";
require_once($_SERVER['DOCUMENT_ROOT'].'/php/mailgun.php');
mailgun_send_message($to,$from,$subject,$body,1,'PhoneLessWork Contact','heinz57@gmail.com','','',0,array(),'',0);
break;
case 'take_break':
if($_POST['break_type']=='10 Minute Paid') {
$db->query("INSERT INTO timeclock_".$db->clean($_SESSION['company_db'])."
(
serial_number
,clock_in
,clock_out
) VALUES (
'".$db->clean($_POST['serial'])."'
,'".$db->clean($_POST['tm'])."'
,'".$db->clean(date('Y-m-d H:i:s',strtotime('+10 minute',strtotime($_POST['tm']))))."'
)");
}
$db->query("INSERT INTO timeclock_breaks_".$db->clean($_SESSION['company_db'])."
(
serial_number
,break_type
,break_time
) VALUES (
'".$db->clean($_POST['serial'])."'
,'".$db->clean($_POST['break_type'])."'
,'".$db->clean($_POST['tm'])."'
)");
?>
<h3>Enjoy your break!</h3>
<p><?= $_POST['break_type'];?></p>
<?php
break;
case 'work_related_phone_use':
?>
<form method="post" action="#" onsubmit="send_work_related_phone_use(this); return false;">
<input type="hidden" name="serial_number" value="<?= $_POST['serial'];?>" />
<input type="hidden" name="date_used" value="<?= $_POST['tm'];?>" />
<div>Reason for Phone Use</div>
<div><textarea name="reason_for_phone_use" style="height:150px;"></textarea></div>
<div>How many minutes did you need your phone?</div>
<div><input type="number" name="minutes_used" value="0" /></div>
<div><input type="submit" name="submit" value="Submit for Approval" class="submit_button" /></div>
</form>
<?php
break;
case 'send_work_related_phone_use':
$db->query("INSERT INTO timeclock_phone_use_".$db->clean($_SESSION['company_db'])."
(
serial_number
,reason_for_phone_use
,minutes_used
,date_used
,approved
) VALUES (
'".$db->clean($_POST['serial_number'])."'
,'".$db->clean($_POST['reason_for_phone_use'])."'
,'".$db->clean($_POST['minutes_used'])."'
,'".$db->clean($_POST['date_used'])."'
,'0'
)");
break;
case 'really_edit_timeclock':
$arr = array();
$arr['pi_id'] = $_POST['pi_id'];
$arr['phone_id'] = $_POST['phone_id'];
$arr['action_type'] = $_POST['action_type'];
$arr['date'] = date('Y-m-d H:i:s',strtotime($_POST['date']));
$arr['action'] = $_POST['action'];
$arr['is_live'] = $_POST['is_live'];
$arr['version'] = $_POST['version'];
$arr['debug_version'] = $_POST['debug_version'];
$debug_info = json_encode($arr);
$db->query("UPDATE phonelesswork.debug_from_pi
SET debug_info='".$db->clean($debug_info)."'
,pi_id = '".$db->clean($arr['pi_id'])."'
,phone_id = '".$db->clean($arr['phone_id'])."'
,action_type = '".$db->clean($arr['action_type'])."'
,punch_date = '".$db->clean($arr['date'])."'
,is_live = '".$db->clean($arr['is_live'])."'
,version = '".$db->clean($arr['version'])."'
,debug_version = '".$db->clean($arr['debug_version'])."'
WHERE id='".$db->clean($_POST['id'])."'");
break;
case 'really_delete_timeclock':
$db->query("DELETE FROM phonelesswork.debug_from_pi WHERE id='".$db->clean($_POST['id'])."'");
break;
case 'add_pingback':
$db->query("UPDATE phonelesswork.timeclock_devices
SET date_last_hit=NOW()
WHERE device_id='".$db->clean($_POST['pi_id'])."'");
echo 'pingback recorded';
break;
case 'edit_company_user':
$res = $db->get_results("SELECT * FROM phonelesswork.timeclock_companies WHERE 1 ORDER BY company_name ASC");
$companies = array();
foreach($res as $r) {
$companies[$r->id] = $r->company_name;
}
$res = $db->get_results("SELECT * FROM phonelesswork.timeclock_users WHERE id='".$db->clean($_POST['id'])."'");
$r = (empty($res)) ? (object) array('id'=>0) : $res[0];
?>
<form method="post" action="#" onsubmit="really_edit_phoneless_user(this); return false;" style="padding:20px;">
<input type="hidden" name="id" value="<?= $_POST['id'];?>" />
<div style="margin:10px 0px;">
<label>
First Name<br />
<input type="text" name="first_name" value="<?= $r->first_name;?>" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Last Name<br />
<input type="text" name="last_name" value="<?= $r->last_name;?>" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Email<br />
<input type="text" name="email" value="<?= $r->email;?>" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Phone<br />
<input type="text" name="phone" value="<?= $r->phone;?>" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Password<br />
<input type="text" name="password" value="" placeholder="Type to Change" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Company<br />
<select name="company_id">
<option value="0">Select Company</option>
<?php foreach($companies as $cid=>$cname) { ?>
<option value="<?= $cid;?>" <?= ($r->company_id==$cid) ? 'selected' : '';?>><?= $cname;?></option>
<?php } ?>
</select>
</label>
</div>
<div style="margin:10px 0px;">
<label>
Has Dashboard<br />
<select name="can_see_dashboard">
<option value="1" <?= ($r->can_see_dashboard=='1') ? 'selected' : '';?>>Yes</option>
<option value="0" <?= ($r->can_see_dashboard=='0') ? 'selected' : '';?>>No</option>
</select>
</label>
</div>
<div style="margin:10px 0px;">
<input type="submit" name="submit" value="Save" class="ui-save-button" />
</div>
</form>
<?php
break;
case 'add_user_to_company':
?>
<form method="post" action="#" onsubmit="really_edit_phoneless_user(this); return false;" style="padding:20px;">
<input type="hidden" name="id" value="0" />
<input type="hidden" name="company_id" value="<?= $_POST['id'];?>" />
<div style="margin:10px 0px;">
<label>
First Name<br />
<input type="text" name="first_name" value="" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Last Name<br />
<input type="text" name="last_name" value="" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Email<br />
<input type="text" name="email" value="" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Phone<br />
<input type="text" name="phone" value="" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Password<br />
<input type="text" name="password" value="" />
</label>
</div>
<div style="margin:10px 0px;">
<label>
Has Dashboard<br />
<select name="can_see_dashboard">
<option value="1">Yes</option>
<option value="0" selected>No</option>
</select>
</label>
</div>
<div style="margin:10px 0px;">
<input type="submit" name="submit" value="Save" class="ui-save-button" />
</div>
</form>
<?php
break;
case 'really_edit_phoneless_user':
if(empty($_POST['id'])) {
$db->query("INSERT INTO phonelesswork.timeclock_users
(
first_name
,last_name
,email
,phone
,pass
,company_id
,can_see_dashboard
) VALUES (
'".$db->clean($_POST['first_name'])."'
,'".$db->clean($_POST['last_name'])."'
,'".$db->clean($_POST['email'])."'
,'".$db->clean(preg_replace('/[^0-9]/','',$_POST['phone']))."'
,PASSWORD('".$db->clean($_POST['password'])."')
,'".$db->clean($_POST['company_id'])."'
,'".$db->clean($_POST['can_see_dashboard'])."'
)");
} else {
$db->query("UPDATE phonelesswork.timeclock_users
SET first_name='".$db->clean($_POST['first_name'])."'
,last_name='".$db->clean($_POST['last_name'])."'
,email='".$db->clean($_POST['email'])."'
,phone='".$db->clean(preg_replace('/[^0-9]/','',$_POST['phone']))."'
,company_id='".$db->clean($_POST['company_id'])."'
,can_see_dashboard='".$db->clean($_POST['can_see_dashboard'])."'
WHERE id='".$db->clean($_POST['id'])."'");
if(!empty($_POST['password'])) {
$db->query("UPDATE phonelesswork.timeclock_users
set pass=PASSWORD('".$db->clean($_POST['password'])."')
WHERE id='".$db->clean($_POST['id'])."'");
}
}
break;
case 'show_company_device_info':
$res = $db->get_results("SELECT d.*
FROM phonelesswork.timeclock_devices d
WHERE d.id='".$db->clean($_POST['id'])."'");
if(!empty($res)) {
foreach($res as $r) {;
?>
<table>
<tr>
<th>Locker Name</th>
<td><?= $r->company_name;?></td>
</tr>
<tr>
<th>Pi ID</th>
<td><?= $r->device_id;?></td>
</tr>
<th>Date Added</th>
<td><?= date('M d, Y g:i a',strtotime($r->device_added));?></td>
</tr>
<tr>
<th>Login Link</th>
<td><a href="https://phonelesswork.com/login.php?id=<?= $r->device_id;?>" target="_blank">Login</a></td>
</tr>
<tr>
<th>Wifi Setup QR Code</th>
<td><a href="https://phonelesswork.com/images/qr_code_for_wifi_setup.png" target="_blank">Wifi QR Code</a></td>
</tr>
<tr>
<th>Login QR Code</th>
<td><a href="https://phonelesswork.com/php/qr_code_login.php?id=<?= $r->device_id;?>" target="_blank">Login QR Code</a></td>
</tr>
<tr>
<th>Quick Start Guide</th>
<td><a href="https://phonelesswork.com/setup.php?id=<?= $r->device_id;?>" target="_blank">Quick Start Guide</a></td>
</tr>
</table>
<?php }
} ?>
<?php
break;
case 'update_phoneless_pi_company_id':
$db->query("UPDATE phonelesswork.timeclock_devices
SET company_id='".$db->clean($_POST['company_id'])."'
WHERE id='".$db->clean($_POST['device_id'])."'");
break;
}
}
?>