function check_permissions() { if (user_permissions_get("timekeeping")) { // check if user has permissions to write as the selected employee if ($this->employeeid) { if (!user_permissions_staff_get("timereg_write", $this->employeeid)) { log_write("error", "page_output", "Sorry, you do not have permissions to adjust the timesheet for the selected employee"); return 0; } } // accept user if they have write access to all staff if (user_permissions_get("timekeeping_all_write")) { return 1; } // select the IDs that the user does have write access to if ($this->access_staff_ids_write = user_permissions_staff_getarray("timereg_write")) { return 1; } else { log_render("error", "page", "Before you can add or edit timesheet hours, your administrator must configure the staff accounts you may access, or set the timekeeping_all_write permission."); } } }
function render_html() { // title + summary print "<h3>TIME REGISTRATION - " . date("l d F Y", mktime(0, 0, 0, $this->date_split[1], $this->date_split[2], $this->date_split[0])) . "</h3><br>"; // links $date_previous = mktime(0, 0, 0, $this->date_split[1], $this->date_split[2] - 1, $this->date_split[0]); $date_previous = date("Y-m-d", $date_previous); $date_next = mktime(0, 0, 0, $this->date_split[1], $this->date_split[2] + 1, $this->date_split[0]); $date_next = date("Y-m-d", $date_next); print "<p><b>"; print "<a class=\"button\" href=\"index.php?page=timekeeping/timereg-day.php&date={$date_previous}&employeeid=" . $this->employeeid . "\"><< Previous Day</a>"; if ($this->config_timesheet_booktofuture == "disabled") { if (time_date_to_timestamp($date_next) < time()) { print " <a class=\"button\" href=\"index.php?page=timekeeping/timereg-day.php&date={$date_next}&employeeid=" . $this->employeeid . "\">Next Day >></a>"; } } else { print " <a class=\"button\" href=\"index.php?page=timekeeping/timereg-day.php&date={$date_next}&employeeid=" . $this->employeeid . "\">Next Day >></a>"; } print "</b></p><br>"; // Employee selection form // // we use a custom form display method here, since the normal form // class will draw a fully styled form in a table. // if ($this->employeeid) { print "<table class=\"table_highlight\" width=\"100%\"><tr><td width=\"100%\">"; } else { print "<table class=\"table_highlight_important\" width=\"100%\"><tr><td width=\"100%\">"; } print "<form method=\"get\" action=\"index.php\">"; print "<p><b>Select an employee to view:</b></p>"; $this->obj_form_employee->render_field("employeeid"); $this->obj_form_employee->render_field("date"); $this->obj_form_employee->render_field("page"); $this->obj_form_employee->render_field("submit"); print "</form>"; print "</td></tr></table><br>"; if ($this->employeeid) { if (!$this->obj_table_day->data_num_rows) { format_msgbox("info", "<p><b>There is currently no time registered to this day.</b></p>"); } else { if (user_permissions_staff_get("timereg_write", $this->employeeid)) { // edit link $structure = NULL; $structure["id"]["column"] = "id"; $structure["date"]["value"] = $this->date; $this->obj_table_day->add_link("edit", "timekeeping/timereg-day-edit.php", $structure); // delete link $structure = NULL; $structure["id"]["column"] = "id"; $structure["date"]["value"] = $this->date; $structure["full_link"] = "yes"; $this->obj_table_day->add_link("delete", "timekeeping/timereg-day-delete-process.php", $structure); } // display table $this->obj_table_day->render_table_html(); } print "<table width=\"100%\">"; // add time link if (user_permissions_staff_get("timereg_write", $this->employeeid)) { print "<td align=\"left\" valign=\"top\"><p><a class=\"button\" href=\"index.php?page=timekeeping/timereg-day-edit.php&date=" . $this->date . "&employeeid=" . $this->employeeid . "\">Add new time entry</a></p></td>"; } else { print "<p><i>You have read-only access to this employee and therefore can not add any more time.</i></p>"; } // display CSV/PDF download link if ($this->obj_table_day->data_num_rows) { print "<td align=\"right\">"; print "<p><a class=\"button_export\" href=\"index-export.php?mode=csv&page=timekeeping/timereg-day.php&date=" . $this->date . "&employeeid=" . $this->employeeid . "\">Export as CSV</a></p>"; print "<p><a class=\"button_export\" href=\"index-export.php?mode=pdf&page=timekeeping/timereg-day.php&date=" . $this->date . "&employeeid=" . $this->employeeid . "\">Export as PDF</a></p>"; print "</td>"; } print "</table>"; } }
function render_html() { // calcuate next/previous week/year if ($this->date_selected_weekofyear == 1) { $date_option_previousyear = $this->date_selected_year - 1; $date_option_previousweek = 52; $date_option_nextyear = $this->date_selected_year; $date_option_nextweek = 2; } elseif ($this->date_selected_weekofyear == 52) { $date_option_previousyear = $this->date_selected_year; $date_option_previousweek = 51; $date_option_nextyear = $this->date_selected_year + 1; $date_option_nextweek = 1; } else { $date_option_previousyear = $this->date_selected_year; $date_option_previousweek = $this->date_selected_weekofyear - 1; $date_option_nextyear = $this->date_selected_year; $date_option_nextweek = $this->date_selected_weekofyear + 1; } // Week view header print "<h3>TIME REGISTRATION</h3><br><br>"; /* Unbilled Time */ if (user_permissions_get("projects_timegroup")) { /* Create an array of all unbilled time records. We need to do the following to create this list: 1. Exclude any internal_only projects. 2. Include time which belongs to a time_group, but ONLY if the time group has not been added to an invoice. */ $unbilled_ids = array(); // select non-internal projects $sql_projects_obj = new sql_query(); $sql_projects_obj->string = "SELECT projects.id as projectid, project_phases.id as phaseid FROM project_phases LEFT JOIN projects ON projects.id = project_phases.projectid WHERE projects.internal_only='0'"; $sql_projects_obj->execute(); if ($sql_projects_obj->num_rows()) { $sql_projects_obj->fetch_array(); foreach ($sql_projects_obj->data as $project_data) { // select non-group time records $sql_obj = new sql_query(); $sql_obj->string = "SELECT id FROM timereg WHERE groupid='0' AND phaseid='" . $project_data["phaseid"] . "'"; $sql_obj->execute(); if ($sql_obj->num_rows()) { $sql_obj->fetch_array(); foreach ($sql_obj->data as $data_tmp) { // we store the ID inside an array key, since they are unique // and this will prevent us needed to check for the existance of // the ID already. $unbilled_ids[$data_tmp["id"]] = "on"; } } unset($sql_obj); // select unpaid group IDs $sql_obj = new sql_query(); $sql_obj->string = "SELECT id FROM time_groups WHERE projectid='" . $project_data["projectid"] . "' AND invoiceid='0'"; $sql_obj->execute(); if ($sql_obj->num_rows()) { $sql_obj->fetch_array(); foreach ($sql_obj->data as $data_group) { // fetch all the time reg IDs belonging this group, but only select time entries marked as billable - we // don't want to report a timegroup with unbillable time as being billed! $sql_reg_obj = new sql_query(); $sql_reg_obj->string = "SELECT id FROM timereg WHERE groupid='" . $data_group["id"] . "' AND billable='1'"; $sql_reg_obj->execute(); if ($sql_reg_obj->num_rows()) { $sql_reg_obj->fetch_array(); foreach ($sql_reg_obj->data as $data_tmp) { // we store the ID inside an array key, since they are unique // and this will prevent us needed to check for the existance of // the ID already. $unbilled_ids[$data_tmp["id"]] = "on"; } } unset($sql_reg_obj); } } unset($sql_obj); } } // fetch amount of unbilled time $sql_obj = new sql_query(); $sql_obj->prepare_sql_settable("timereg"); $sql_obj->prepare_sql_addfield("timebooked", "SUM(timereg.time_booked)"); if ($this->access_staff_ids) { $sql_obj->prepare_sql_addwhere("employeeid IN (" . format_arraytocommastring($this->access_staff_ids) . ")"); } $sql_obj->prepare_sql_addjoin("LEFT JOIN time_groups ON timereg.groupid = time_groups.id"); // provide list of valid IDs $unbilled_ids_keys = array_keys($unbilled_ids); $unbilled_ids_count = count($unbilled_ids_keys); $unbilled_ids_sql = ""; if ($unbilled_ids_count) { $i = 0; foreach ($unbilled_ids_keys as $id) { $i++; if ($i == $unbilled_ids_count) { $unbilled_ids_sql .= "timereg.id='{$id}' "; } else { $unbilled_ids_sql .= "timereg.id='{$id}' OR "; } } $sql_obj->prepare_sql_addwhere("({$unbilled_ids_sql})"); $sql_obj->generate_sql(); $sql_obj->execute(); $sql_obj->fetch_array(); list($unbilled_time_hours, $unbilled_time_mins) = explode(":", time_format_hourmins($sql_obj->data[0]["timebooked"])); if ($unbilled_time_hours > 0 && $unbilled_time_mins > 0) { $message = "There are currently {$unbilled_time_hours} hours and {$unbilled_time_mins} minutes of unbilled time to be processed. Click here to view."; } elseif ($unbilled_time_hours > 0) { $message = "There are currently {$unbilled_time_hours} hours of unbilled time to be processed. Click here to view."; } elseif ($unbilled_time_mins > 0) { $message = "There are currently {$unbilled_time_mins} minutes of unbilled time to be processed. Click here to view."; } } else { $message = "There is no unbilled time to be processed."; } // display print "<br>"; format_linkbox("default", "index.php?page=timekeeping/unbilled.php", "<p><b>UNBILLED TIME</b></p><p>{$message}</p>"); } /*end unbilled time*/ print "<br />"; /* Time booked */ // fetch amount of time booked for today $sql_obj = new sql_query(); $sql_obj->prepare_sql_settable("timereg"); $sql_obj->prepare_sql_addfield("timebooked", "SUM(timereg.time_booked)"); $sql_obj->prepare_sql_addwhere("date='" . date("Y-m-d") . "'"); if ($this->access_staff_ids) { $sql_obj->prepare_sql_addwhere("employeeid IN (" . format_arraytocommastring($this->access_staff_ids) . ")"); } $sql_obj->generate_sql(); $sql_obj->execute(); $sql_obj->fetch_array(); list($booked_time_hours, $booked_time_mins) = explode(":", time_format_hourmins($sql_obj->data[0]["timebooked"])); if ($booked_time_hours > 0 && $booked_time_mins > 0) { $message = "<b>Time booked for today: {$booked_time_hours} hours and {$booked_time_mins} minutes.</b><br />Click here to add more time."; } elseif ($booked_time_hours > 0) { $message = "<b>Time booked for today: {$booked_time_hours} hours.</b><br />Click here to add more time."; } elseif ($booked_time_mins > 0) { $message = "<b>Time booked for today: {$booked_time_mins} minutes.</b><br />Click here to add more time."; } else { $message = "<b>No time has been booked for today</b><br />Click here to add time.</b>"; } format_linkbox("default", "index.php?page=timekeeping/timereg-day-edit.php", "<p>{$message}</p>"); print "<br />"; print "<table class=\"table_highlight\" width=\"100%\"><tr>"; // Week selection links print "<td width=\"70%\">"; print "<b>WEEK " . $this->date_selected_weekofyear . ", " . $this->date_selected_year . "</b><br>"; print "(" . time_format_humandate($this->date_selected_start) . " to " . time_format_humandate($this->date_selected_end) . ")<br>"; print "<br>"; print "<p><b>"; print "<a class=\"button\" href=\"index.php?page=timekeeping/timereg.php&employeeid=" . $this->employeeid . "&weekofyear=" . $date_option_previousweek . "&year=" . $date_option_previousyear . "\"><< Previous Week</a>"; // check for date in the future if ($this->config_timesheet_booktofuture == "disabled") { if (time_date_to_timestamp(time_calculate_weekstart($date_option_nextweek, $date_option_nextyear)) < time()) { // end date is in not in the future print " <a class=\"button\" href=\"index.php?page=timekeeping/timereg.php&employeeid=" . $this->employeeid . "&weekofyear=" . $date_option_nextweek . "&year=" . $date_option_nextyear . "\">Next Week >></a>"; } } else { print " <a class=\"button\" href=\"index.php?page=timekeeping/timereg.php&employeeid=" . $this->employeeid . "&weekofyear=" . $date_option_nextweek . "&year=" . $date_option_nextyear . "\">Next Week >></a>"; } print "</b></p>"; print "</td>"; // goto date form print "<td width=\"30%\">"; print "<form method=\"get\" action=\"index.php\" class=\"form_standard\">"; $this->obj_form_goto->render_field("date"); print "<br>"; $this->obj_form_goto->render_field("page"); $this->obj_form_goto->render_field("submit"); print "</form>"; print "</td>"; print "</tr></table><br>"; // Employee selection form // // we use a custom form display method here, since the normal form // class will draw a fully styled form in a table. // if ($this->employeeid) { print "<table class=\"table_highlight\" width=\"100%\"><tr><td width=\"100%\">"; } else { print "<table class=\"table_highlight_important\" width=\"100%\"><tr><td width=\"100%\">"; } print "<form method=\"get\" action=\"index.php\" class=\"form_standard\">"; print "<p><b>Select an employee to view:</b></p>"; $this->obj_form_employee->render_field("employeeid"); $this->obj_form_employee->render_field("weekofyear"); $this->obj_form_employee->render_field("year"); $this->obj_form_employee->render_field("page"); $this->obj_form_employee->render_field("submit"); print "</form>"; print "</td></tr></table><br>"; if ($this->employeeid) { // custom labels and links if ($this->config_timesheet_booktofuture == "disabled") { if (time_date_to_timestamp($this->date_selected_daysofweek[0]) < time()) { $this->obj_table_week->custom_column_link("monday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[0] . ""); } if (time_date_to_timestamp($this->date_selected_daysofweek[1]) < time()) { $this->obj_table_week->custom_column_link("tuesday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[1] . ""); } if (time_date_to_timestamp($this->date_selected_daysofweek[2]) < time()) { $this->obj_table_week->custom_column_link("wednesday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[2] . ""); } if (time_date_to_timestamp($this->date_selected_daysofweek[3]) < time()) { $this->obj_table_week->custom_column_link("thursday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[3] . ""); } if (time_date_to_timestamp($this->date_selected_daysofweek[4]) < time()) { $this->obj_table_week->custom_column_link("friday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[4] . ""); } if (time_date_to_timestamp($this->date_selected_daysofweek[5]) < time()) { $this->obj_table_week->custom_column_link("saturday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[5] . ""); } if (time_date_to_timestamp($this->date_selected_daysofweek[6]) < time()) { $this->obj_table_week->custom_column_link("sunday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[6] . ""); } } else { // add links $this->obj_table_week->custom_column_link("monday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[0] . ""); $this->obj_table_week->custom_column_link("tuesday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[1] . ""); $this->obj_table_week->custom_column_link("wednesday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[2] . ""); $this->obj_table_week->custom_column_link("thursday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[3] . ""); $this->obj_table_week->custom_column_link("friday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[4] . ""); $this->obj_table_week->custom_column_link("saturday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[5] . ""); $this->obj_table_week->custom_column_link("sunday", "index.php?page=timekeeping/timereg-day.php&date=" . $this->date_selected_daysofweek[6] . ""); } // column labels $this->obj_table_week->custom_column_label("monday", "Monday<br><font style=\"font-size: 8px;\">(" . time_format_humandate($this->date_selected_daysofweek[0]) . ")</font>"); $this->obj_table_week->custom_column_label("tuesday", "Tuesday<br><font style=\"font-size: 8px;\">(" . time_format_humandate($this->date_selected_daysofweek[1]) . ")</font>"); $this->obj_table_week->custom_column_label("wednesday", "Wednesday<br><font style=\"font-size: 8px;\">(" . time_format_humandate($this->date_selected_daysofweek[2]) . ")</font>"); $this->obj_table_week->custom_column_label("thursday", "Thursday<br><font style=\"font-size: 8px;\">(" . time_format_humandate($this->date_selected_daysofweek[3]) . ")</font>"); $this->obj_table_week->custom_column_label("friday", "Friday<br><font style=\"font-size: 8px;\">(" . time_format_humandate($this->date_selected_daysofweek[4]) . ")</font>"); $this->obj_table_week->custom_column_label("saturday", "Saturday<br><font style=\"font-size: 8px;\">(" . time_format_humandate($this->date_selected_daysofweek[5]) . ")</font>"); $this->obj_table_week->custom_column_label("sunday", "Sunday<br><font style=\"font-size: 8px;\">(" . time_format_humandate($this->date_selected_daysofweek[6]) . ")</font>"); // display week time table $this->obj_table_week->render_table_html(); print "<table width=\"100%\">"; // add time link if (user_permissions_staff_get("timereg_write", $this->employeeid)) { print "<td align=\"left\" valign=\"top\"><p><a class=\"button\" href=\"index.php?page=timekeeping/timereg-day-edit.php\">Add new time entry</a></p></td>"; } else { print "<p><i>You have read-only access to this employee and therefore can not add any more time.</i></p>"; } // display CSV/PDF download link print "<td align=\"right\">"; print "<p><a class=\"button_export\" href=\"index-export.php?mode=csv&page=timekeeping/timereg.php\">Export as CSV</a></p>"; print "<p><a class=\"button_export\" href=\"index-export.php?mode=pdf&page=timekeeping/timereg.php\">Export as PDF</a></p>"; print "</td>"; print "</table>"; } }
$sql_obj->string = "SELECT id, locked FROM `timereg` WHERE id='{$id}' LIMIT 1"; $sql_obj->execute(); if (!$sql_obj->num_rows()) { log_write("error", "process", "The time entry you have attempted to edit - {$id} - does not exist in this system."); } else { $sql_obj->fetch_array(); if ($sql_obj->data[0]["locked"]) { log_write("error", "process", "This time entry has been locked and can not be adjusted."); } } } else { $mode = "add"; } //// ERROR CHECKING /////////////////////// // make sure user has per if (!user_permissions_get("timekeeping_all_write") && !user_permissions_staff_get("timereg_write", $employeeid)) { log_write("error", "process", "Sorry, you do not have access rights to book time for this employee."); } // make sure we don't end up with more than 24 hours booked for one day // get a total of the time currently booked for this date $sql_obj = new sql_query(); $sql_obj->string = "SELECT time_booked FROM `timereg` WHERE date='" . $data["date"] . "' AND employeeid='{$employeeid}'"; if ($id) { $sql_obj->string .= " AND id!='{$id}'"; } $sql_obj->execute(); $timetotal = 0; if ($sql_obj->num_rows()) { $sql_obj->fetch_array(); foreach ($sql_obj->data as $data_sql) { $timetotal += $data_sql["time_booked"];