Ejemplo n.º 1
0
				$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 = ui_print_success_message (__('Workunit added'), '', true, 'h3', 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 = ui_print_error_message (__('Problemd adding workunit.'), '', true, 'h3', true);
					}
				} else {
					$result_output = ui_print_error_message (__('Problemd adding workunit.'), '', true, 'h3', true);
				}
			}
		}
	}
	
	if ($id_workunit !== false) {
		set_task_completion ($id_task);
	}
	audit_db ($config["id_user"], $config["REMOTE_ADDR"], "PWU", "Inserted PWU. Task: $id_task. Desc: $description");
Ejemplo n.º 2
0
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;
}