function task_child_enddate($id_task) { global $config; $start_date = task_start_date($id_task); $tasktime = get_db_sql("SELECT hours FROM ttask WHERE id= {$id_task}"); $tasktime = $tasktime / $config["hours_perday"]; $end_date = calcdate_business($start_date, $tasktime); $max = '1980-01-01'; $query1 = "SELECT * FROM ttask WHERE id_parent_task = {$id_task}"; $resq1 = mysql_query($query1); while ($row = mysql_fetch_array($resq1)) { $thisvalue = $row["hours"]; $thisstart = $row["start"]; $childtime = $thisvalue / $config["hours_perday"]; $childdate = calcdate_business($thisstart, $childtime); $grandchilddate = task_child_enddate($row["id"]); if ($grandchilddate != $childdate) { $childdate = $grandchilddate; } if (strtotime($childdate) > strtotime($max)) { $max = $childdate; } } if (strtotime($max) > strtotime($end_date)) { return $max; } else { return $end_date; } }
$id_task = (int) get_parameter ("id_task", -1); $id_profile = (int) get_parameter ("id_profile"); $public = (bool) get_parameter ("public"); $forward = (bool) get_parameter ("forward"); $split = (bool) get_parameter ("split"); $id_user = (string) get_parameter ("id_username", $config['id_user']); $wu_user = $id_user; $work_home = get_parameter ("work_home"); // Multi-day assigment // Forward if (($forward) && ($duration > $config["hours_perday"])) { $total_days = ceil ($duration / $config["hours_perday"]); $total_days_sum = 0; $hours_day = 0; for ($i = 0; $i < $total_days; $i++) { $current_timestamp = calcdate_business ($timestamp, $i); if (($total_days_sum + 8) > $duration) $hours_day = $duration - $total_days_sum; else $hours_day = $config["hours_perday"]; $total_days_sum += $hours_day; $sql = sprintf ('INSERT INTO tworkunit (timestamp, duration, id_user, description, have_cost, id_profile, public, work_home) VALUES ("%s", %f, "%s", "%s", %d, %d, %d, %d)', $current_timestamp, $hours_day, $id_user, $description, $have_cost, $id_profile, $public, $work_home); $id_workunit = process_sql ($sql, 'insert_id'); if ($id_workunit !== false) {
function create_single_workunit($number) { global $config; $duration = (double) get_parameter("duration_" . $number); $timestamp = (string) get_parameter("start_date_" . $number); $description = (string) get_parameter("description_" . $number); $have_cost = (bool) get_parameter("have_cost_" . $number); $id_task = (int) get_parameter("id_task_" . $number, -1); $id_profile = (int) get_parameter("id_profile_" . $number); $public = (bool) get_parameter("public_" . $number); $split = (bool) get_parameter("split_" . $number); $id_user = (string) get_parameter("id_username_" . $number, $config['id_user']); $wu_user = $id_user; $forward = (bool) get_parameter("forward_" . $number); $work_home = (bool) get_parameter("work_home_" . $number); // Multi-day assigment if ($split && $duration > $config["hours_perday"]) { $total_days = ceil($duration / $config["hours_perday"]); $total_days_sum = 0; $hours_day = 0; for ($i = 0; $i < $total_days; $i++) { if (!$forward) { $current_timestamp = calcdate_business_prev($timestamp, $i); } else { $current_timestamp = calcdate_business($timestamp, $i); } if ($total_days_sum + 8 > $duration) { $hours_day = $duration - $total_days_sum; } else { $hours_day = $config["hours_perday"]; } $total_days_sum += $hours_day; $sql = sprintf('INSERT INTO tworkunit (timestamp, duration, id_user, description, have_cost, id_profile, public, work_home) VALUES ("%s", %f, "%s", "%s", %d, %d, %d, %d)', $current_timestamp, $hours_day, $id_user, $description, $have_cost, $id_profile, $public, $work_home); $id_workunit = process_sql($sql, 'insert_id'); if ($id_workunit !== false) { $sql = sprintf('INSERT INTO tworkunit_task (id_task, id_workunit) VALUES (%d, %d)', $id_task, $id_workunit); $result = process_sql($sql, 'insert_id'); if ($result !== false) { $result_output = true; } else { $result_output = false; } } else { $result_output = false; } } mail_project(0, $config['id_user'], $id_workunit, $id_task, "This is part of a multi-workunit assigment of {$duration} hours"); } else { // Single day workunit $sql = sprintf('INSERT INTO tworkunit (timestamp, duration, id_user, description, have_cost, id_profile, public, work_home) VALUES ("%s", %.2f, "%s", "%s", %d, %d, %d, %d)', $timestamp, $duration, $id_user, $description, $have_cost, $id_profile, $public, $work_home); $id_workunit = process_sql($sql, 'insert_id'); if ($id_workunit !== false) { $sql = sprintf('INSERT INTO tworkunit_task (id_task, id_workunit) VALUES (%d, %d)', $id_task, $id_workunit); $result = process_sql($sql, 'insert_id'); if ($result !== false) { $result_output = true; audit_db($config['id_user'], $config["REMOTE_ADDR"], "Spare work unit added", 'Workunit for ' . $config['id_user'] . ' added to Task ID #' . $id_task); mail_project(0, $config['id_user'], $id_workunit, $id_task); } else { $result_output = false; } } else { $result_output = false; } } if ($id_workunit !== false) { set_task_completion($id_task); } audit_db($config["id_user"], $config["REMOTE_ADDR"], "PWU INSERT", "Task {$id_task}. Desc: {$description}"); $return = array("task" => $id_task, "date" => $timestamp, "role" => $id_profile, "cost" => $have_cost, "public" => $public, "user" => $id_user, "duration" => $duration, "split" => $split, "forward" => $forward, "description" => $description, "result_out" => $result_output, "work_home" => $work_home); return $return; }