'',
'from_name' => '',
'email_enabled' => '',
'hide_dcac_ad' => '',
'email_late_timesheets' => 'checked'
);
// Add options
add_option('time_sheets', $options);
$setup = new time_sheets_setup();
$setup->create_db_objects();
$cron = new time_sheets_cron();
$cron->add_cron();
}
function deactivation() {
//delete_option('time_sheets');
$cron = new time_sheets_cron();
$cron->remove_cron();
}
function upgrade() {
$setup = new time_sheets_setup();
$setup->create_db_objects();
$cron = new time_sheets_cron();
$cron->add_cron();
}
function custom_menu() {
if (($_GET['page'] == "payroll_timesheet" || $_GET['page'] == "invoice_timesheet" || $_GET['page'] == "approve_timesheet" || $_GET['page'] == "enter_timesheet" || $_GET['page'] == "search_timesheet" || $_GET['page'] == "timesheet_manage_clients" || $_GET['page'] == "timesheet_settings" || $_GET['page'] == "my_settings" ) && !$_GET['action']) {
$this->footer();
}
$options = get_option('time_sheets');
$time_sheets_main = new time_sheets_main();
$time_sheets_entry = new time_sheets_entry();
$time_sheets_settings = new time_sheets_settings();
$time_sheets_manage_projects = new time_sheets_manage_projects();
$client_managers = new time_sheets_client_managers();
$my = new time_sheets_my_settings();
$cron = new time_sheets_cron();
if ($this->employee_approver_check()!=0) {
$vcount_pending_approval = $this->count_pending_approval();
} else {
$vcount_pending_approval = 0;
}
if ($this->employee_invoicer_check()!=0) {
$vcount_pending_invoice = $this->count_pending_invoice();
} else {
$vcount_pending_invoice = 0;
}
if ($this->employee_payroll_check()!=0) {
$vcount_pending_payroll = $this->count_pending_payroll();
} else {
$vcount_pending_payroll = 0;
}
$timesheets_not_complete = $this->count_users_open_invoice();
$pending_stuff = $vcount_pending_approval->NotRetainer + $vcount_pending_approval->Retainer + $vcount_pending_invoice->NotRetainer + $vcount_pending_invoice->Retainer + $vcount_pending_payroll+$timesheets_not_complete;
if ($pending_stuff != 0) {
$tag = "Time Sheets {$pending_stuff}";
} else {
$tag = 'Time Sheets';
}
add_menu_page('Time Sheets', $tag, '', 'time_sheets_top', array($time_sheets_entry, 'enter_time_sheet'), plugins_url( 'time-sheets/icon.png' ));
add_submenu_page('time_sheets_top', 'Enter Timesheet', 'Enter Timesheet', 'read', 'enter_timesheet', array($time_sheets_entry, 'enter_timesheet'));
if ($timesheets_not_complete == 0) {
$tag = "Old Timesheets";
} else {
$tag = "Old Timesheets{$timesheets_not_complete}";
}
add_submenu_page('time_sheets_top', 'View Old Timesheets', $tag, 'read', 'search_timesheet', array($time_sheets_entry, 'search_timesheet'));
if ($client_managers->client_manager_check()==1) {
add_submenu_page('time_sheets_top', 'Manage Clients & Projects', 'Manage Clients', 'read', 'timesheet_manage_clients', array($time_sheets_manage_projects, 'main'));
}
if ($this->employee_approver_check('true')!=0) {
$vcount_pending_approval = $this->count_pending_approval();
if ($vcount_pending_approval->NotRetainer+$vcount_pending_approval->Retainer != 0) {
$tag = "Approval Queue{$vcount_pending_approval->NotRetainer}/{$vcount_pending_approval->Retainer}";
} else {
$tag = "Approval Queue";
}
add_submenu_page('time_sheets_top', 'Approvel Queue', $tag, 'read', 'approve_timesheet', array($time_sheets_entry, 'approve_timesheet'));
}
if ($this->employee_invoicer_check()!=0) {
$vcount_pending_invoicing = $this->count_pending_invoice();
if ($vcount_pending_invoicing->NotRetainer+$vcount_pending_invoicing->Retainer != 0) {
$tag = "Invoice Queue{$vcount_pending_invoicing->NotRetainer}/{$vcount_pending_invoicing->Retainer}";
} else {
$tag = "Invoice Queue";
}
add_submenu_page('time_sheets_top', 'Invoice Queue', $tag, 'read', 'invoice_timesheet', array($time_sheets_entry, 'invoice_timesheet'));
}
if ($this->employee_payroll_check()!=0) {
$vcount_pending_payroll = $this->count_pending_payroll();
if ($vcount_pending_payroll != 0) {
$tag = "Payroll Queue{$vcount_pending_payroll}";
} else {
$tag = "Payroll Queue";
}
add_submenu_page('time_sheets_top', 'Payroll Queue', $tag, 'read', 'payroll_timesheet', array($time_sheets_entry, 'payroll_timesheet'));
add_submenu_page('time_sheets_top', 'Employees Who Always Are Sent to Payroll for Processing', 'Force Payroll Setup', 'read', 'employees_allways_to_payroll', array($time_sheets_settings, 'employees_allways_to_payroll'));
}
add_submenu_page('time_sheets_top', 'Manage Approvers', 'Manage Approvers', 'manage_options', 'time_sheets_manage_approvers', array($time_sheets_settings, 'manage_approvers'));
add_submenu_page('time_sheets_top', 'Manage Employees Who Process Invoices', 'Manage Invoicers', 'manage_options', 'time_sheets_manage_invoicers', array($time_sheets_settings, 'manage_invoicers'));
add_submenu_page('time_sheets_top', 'Manage Payroll Processors', 'Manage Payroll', 'manage_options', 'time_sheets_manage_payroll', array($time_sheets_settings, 'manage_payrollers'));
add_submenu_page('time_sheets_top', 'Manage Client Managers', 'Manage Client Managers', 'manage_options', 'time_sheets_client_managers', array($client_managers, 'manage_client_managers'));
if ($this->employee_approver_check('false')!=0) {
add_submenu_page('time_sheets_top', 'Setup Approval Teams', 'Setup Approval Teams', 'read', 'setup_approval_teams', array($time_sheets_settings, 'setup_approval_teams'));
}
add_submenu_page('time_sheets_top', 'Time Sheet Global Settings', 'Global Settings', 'manage_options', 'time_sheets_settings', array($time_sheets_settings, 'show_settings_page'));
add_submenu_page('time_sheets_top', 'My Settings', 'My Settings', 'read', 'my_settings', array($my, 'main'));
if ($_SERVER[HTTP_HOST]=="dev.dcac.co") {
add_submenu_page('time_sheets_top', 'Run Nightly Cron', 'Run Nightly Cron', 'read', 'timesheet_nightly_cron', array($cron, 'InsertMonthlyInvoices'));
add_submenu_page('time_sheets_top', 'Run Email Cron', 'Run Email Cron', 'read', 'timesheet_email_cron', array(&$this, 'manual_email_kick'));
add_submenu_page('time_sheets_top', 'Run Late Timesheets Cron', 'Run Late Timesheets Cron', 'read', 'timesheet_email_late_timesheets', array($cron, 'email_late_timesheets'));
add_submenu_page('time_sheets_top', 'Run Retainer Reminder', 'Run Retainer Reminder', 'read', 'email_retainers_due', array($cron, 'email_retainers_due'));
add_submenu_page('time_sheets_top', 'Run Setup', 'Run Setup', 'read', 'timesheet_setup2', array($time_sheets_main, 'upgrade'));
}
}
function manual_email_kick() {
$cron = new time_sheets_cron();
$cron->process_email('true');
}
function employee_payroll_check() {
global $wpdb;
$user_id = get_current_user_id();
$db = new time_sheets_db();
$sql = "select count(*) from {$wpdb->prefix}timesheet_payrollers where user_id = {$user_id}";
$count = $db->get_var($sql);
return $count;
}
function count_pending_payroll() {
global $wpdb;
$user_id = get_current_user_id();
$db = new time_sheets_db();
$sql = "select count(*)
from {$wpdb->prefix}timesheet t
where t.invoiced = 1 and t.payrolled = 0";
$count = $db->get_var($sql);
return $count;
}
function employee_approver_check($includeBackups=true) {
global $wpdb;
$user_id = get_current_user_id();
$db = new time_sheets_db();
if ($includeBackups=='true') {
$sql = "select count(*) from {$wpdb->prefix}timesheet_approvers where (user_id = {$user_id}) OR (backup_user_id = {$user_id} and backup_expires_on > now())";
} else {
$sql = "select count(*) from {$wpdb->prefix}timesheet_approvers where user_id = {$user_id}";
}
$count = $db->get_var($sql);
return $count;
}
function count_pending_approval() {
global $wpdb;
$user_id = get_current_user_id();
$db = new time_sheets_db();
$sql = "select sum(case when tcp.IsRetainer=1 then 1 else 0 end) Retainer, sum(case when tcp.IsRetainer=0 then 1 else 0 end) NotRetainer
from {$wpdb->prefix}timesheet t
join {$wpdb->prefix}timesheet_approvers_approvies aa ON aa.approvie_user_id = t.user_id
join {$wpdb->prefix}timesheet_approvers ta on aa.approver_user_id = ta.user_id
and (ta.user_id = {$user_id} OR (ta.backup_user_id = {$user_id} and ta.backup_expires_on > now()))
join {$wpdb->prefix}timesheet_client_projects tcp on t.ProjectId = tcp.ProjectId
where approved = 0 and week_complete = 1 and (EmbargoPendingProjectClose = 0 or EmbargoPendingProjectClose IS NULL)";
$count = $db->get_row($sql);
return $count;
}
function count_pending_invoice() {
global $wpdb;
$user_id = get_current_user_id();
$db = new time_sheets_db();
$sql = "select sum(case when tcp.IsRetainer=1 then 1 else 0 end) Retainer, sum(case when tcp.IsRetainer=0 then 1 else 0 end) NotRetainer
from {$wpdb->prefix}timesheet t
join {$wpdb->prefix}timesheet_client_projects tcp on t.ProjectId = tcp.ProjectId
where t.approved = 1 and t.invoiced = 0";
$count = $db->get_row($sql);
return $count;
}
function count_users_open_invoice() {
global $wpdb;
$user_id = get_current_user_id();
$db = new time_sheets_db();
$sql = "select count(*)
from {$wpdb->prefix}timesheet t
join {$wpdb->prefix}timesheet_client_projects tcp on t.ProjectId = tcp.ProjectId
where t.week_complete = 0 and t.user_id = {$user_id}";
$count = $db->get_var($sql);
return $count;
}
function employee_invoicer_check () {
global $wpdb;
$user_id = get_current_user_id();
$db = new time_sheets_db();
$sql = "select count(*)
from {$wpdb->prefix}timesheet_invoicers t
where user_id = {$user_id}";
$count = $db->get_var($sql);
return $count;
}
function init_settings(){
$settings = new time_sheets_settings();
$settings->register_settings();
}
function footer() {
$options=get_option('time_sheets');
$time_sheets_main = new time_sheets_main();
if (!$options['hide_dcac_ad']) {
add_filter('admin_footer_text', array($time_sheets_main, 'show_footer'));
add_filter( 'update_footer', array($time_sheets_main, 'show_footer_version'));
} #else {
# remove_filter('admin_footer_text', array($time_sheets_main, 'show_footer'));
# remove_filter( 'update_footer', array($time_sheets_main, 'show_footer_version'));
#}
if (get_site_option('time_sheet_license_valid', -1) != 1) {
add_filter('admin_footer_text', array($time_sheets_main, 'show_license_error'));
} #else {
# remove_filter('admin_footer_text', array($time_sheets_main, 'show_license_error'));
#}
}
function show_footer() {
echo '';
}
function show_license_error() {
echo '