New Client must be added.";
}
if ($queue_approval->employee_approver_check()!=0 && $disable_object=="") {
$page = $page . "Add a Client";
}
$page = $page . "
";
$page = $page . "
Project Name:
";
if ($queue_approval->employee_approver_check()!=0 && $disable_object=="") {
$page = $page . "Add a Project";
}
$page = $page . "
";
}
$js_projects[1] = $page;
return $js_projects;
}
function client_and_projects_javascript($js_projects, $html_formname, $billing_on_form, $timesheet) {
$page = '';
$page = $page . "
function clientChange() {
if ({$html_formname}.ClientId.value==-2) {
alert ('Invalid Client Selected');
}
resetProject();
";
if ($billing_on_form==1) {
$page = $page . "isProjectBilled();
isClientProjectBilled();";
}
$page = $page . "
}
function resetProject(){
var projectlist = {$js_projects};
{$html_formname}.ProjectId.options.length = 0;
var numberOfProjects = projectlist.length;
//alert(numberOfProjects);
for (var i = 0; i < numberOfProjects; i++) {
project = projectlist[i];
if (project['ClientId']=={$html_formname}.ClientId.value) {
var opt = document.createElement('option');
opt.value = project['ProjectId'];
opt.innerHTML = project['ProjectName'];
{$html_formname}.ProjectId.appendChild(opt);
}
//alert(project['ProjectName']);
}";
if (isset($timesheet->ProjectId)) {
$page = $page . "
{$html_formname}.ProjectId.value={$timesheet->ProjectId};";
}
$page = $page . "
}";
return $page;
}
function return_employee_list() {
global $wpdb;
$db = new time_sheets_db();
$sql = "select u.user_login, u.id, u.display_name
from {$wpdb->users} u
order by u.display_name";
$users = $db->get_results($sql);
return $users;
}
function return_approvers_team_list($approver_id, $members_only=0) {
global $wpdb;
$db = new time_sheets_db();
$sql = "select u.user_login, aa.approvie_user_id a, u.id, u.display_name
from {$wpdb->users} u ";
if ($members_only==1) {
$sql=$sql."inner";
} else {
$sql=$sql."left outer";
}
$sql = $sql." join {$wpdb->prefix}timesheet_approvers_approvies aa ON u.ID = aa.approvie_user_id
and aa.approver_user_id = %d
order by u.display_name";
$values = array($approver_id);
$users = $db->get_results($sql, $values);
return $users;
}
function intval($string) {
return intval($string);
}
function esc_textarea($string) {
$string = stripslashes($string);
return esc_textarea($string);
}
function clean_from_db($string) {
$string = str_replace("''", "'", $string);
$string = esc_textarea($string);
$string = stripslashes($string);
return $string;
}
function add_days_to_date($idate, $days, $holidays) {
$date = new DateTime($idate);
date_add($date, date_interval_create_from_date_string("{$days} days"));
$leading_color = "";
$trailing_color = "";
if ($holidays) {
foreach ($holidays as $dt) {
foreach ($dt as $daykey) {
if (date('m-d',strtotime((string)$daykey))==date_format($date, 'm-d')) {
$leading_color="";
$trailing_color="";
}
}
}
}
$date = date_format($date, 'm-d');
$return = "{$leading_color} {$date} {$trailing_color}";
return $return;
}
function show_clients_on_retainer($mine_only = 0) {
global $wpdb;
$db = new time_sheets_db();
$user = wp_get_current_user();
$user_id = $user->ID;
$sql = "select ClientName, im.MonthlyHours, im.HourlyRate, im.Notes
from {$wpdb->prefix}timesheet_clients tc
inner join {$wpdb->prefix}timesheet_recurring_invoices_monthly im on tc.clientid = im.client_id";
if ($mine_only == 1) {
$sql = $sql." inner join {$wpdb->prefix}timesheet_clients_users tcu on tc.clientid = tcu.clientid and tcu.user_id = {$user_id}";
}
$sql = $sql." where im.MonthlyHours <> 0
order by ClientName";
$clients = $db->get_results($sql);
if ($clients) {
echo "
>
Client Name
Number of Hours
Hourly Rate on Retainer
";
foreach ($clients as $client) {
echo "
{$client->ClientName}
{$client->MonthlyHours}
$ {$client->HourlyRate}
";
}
echo "
";
}
$sql = "select ClientName, im.MonthlyHours, im.HourlyRate, im.Notes
from {$wpdb->prefix}timesheet_clients tc
inner join {$wpdb->prefix}timesheet_recurring_invoices_monthly im on tc.clientid = im.client_id";
if ($mine_only == 1) {
$sql = $sql." inner join {$wpdb->prefix}timesheet_clients_users tcu on tc.clientid = tcu.clientid and tcu.user_id = {$user_id}";
}
$sql = $sql."
where im.MonthlyHours = 0
order by ClientName";
$clients = $db->get_results($sql);
if ($clients) {
echo "
Client Name
Notes
";
foreach ($clients as $client) {
echo "
{$client->ClientName}
";
}
echo "
";
}
$sql = "select ClientName, ProjectName, p.notes
from {$wpdb->prefix}timesheet_client_projects p
join {$wpdb->prefix}timesheet_clients c on p.ClientId = c.ClientId";
if ($mine_only == 1) {
$sql = $sql." inner join {$wpdb->prefix}timesheet_clients_users tcu on p.clientid = tcu.clientid and tcu.user_id = {$user_id}";
}
$sql = $sql."
where p.notes <> '' and (p.Active = 1
or (p.Active = 0 and p.HoursUsed = 0)
)
order by ClientName, ProjectName";
$clients = $db->get_results($sql);
if ($clients) {
echo "
Client Name
Project Name
Notes
";
foreach ($clients as $client) {
echo "
{$client->ClientName}
{$client->ProjectName}
";
}
echo "
";
}
}
function is_match($v1, $v2, $return, $debug=0) {
if ($debug==1) {
var_dump($v1);
var_dump($v2);
}
if (trim($v1)==trim($v2)) {
return $return;
} else {
return "";
}
}
function replace($search, $replace, $value) {
return str_replace($search, $replace, $value);
}
function f_date($date) {
$options = get_option('time_sheets');
$user = wp_get_current_user();
$user_id = $user->ID;
if ($options['override_date_format'] == 'system_defined') {
$date_format = get_option('date_format');
} else {
$date_format = $options['new_date_format'];
if ($options['user_specific_date_format']) {
if (get_user_option('user_date_format', $user_id)) {
$date_format = get_user_option('user_date_format', $user_id);
}
}
}
return date_i18n($date_format, strtotime($date));
}
function mysql_date($date) {
return date("Y-m-d", strtotime($date));
}
function send_email ($to, $subject, $body) {
global $wpdb;
$options = get_option('time_sheets');
$db = new time_sheets_db();
if($options['enable_email']) {
$sql = "insert into {$wpdb->prefix}timesheet_emailqueue
(send_to, send_from_email, send_from_name, subject, message_body, entered_on)
values (%s, %s, %s, %s, %s, now())";
$parms = array($to, $options['email_from'], $options['email_name'], $subject, $body);
$db->query($sql, $parms);
if ($options['show_email_notice']) {
echo "