function all_project_tree($id_user, $completion, $project_kind)
{
    include "../include/config.php";
    $config["id_user"] = $id_user;
    $dotfilename = $config["homedir"] . "/attachment/tmp/{$id_user}.all.dot";
    $pngfilename = $config["homedir"] . "/attachment/tmp/{$id_user}.projectall.png";
    $mapfilename = $config["homedir"] . "/attachment/tmp/{$id_user}.projectall.map";
    $dotfile = fopen($dotfilename, "w");
    fwrite($dotfile, "digraph Integria {\n");
    fwrite($dotfile, "\t  ranksep=1.8;\n");
    fwrite($dotfile, "\t  ratio=auto;\n");
    fwrite($dotfile, "\t  size=\"9,9\";\n");
    fwrite($dotfile, 'URL="' . $config["base_url"] . '/index.php?sec=projects&sec2=operation/projects/project_tree";' . "\n");
    fwrite($dotfile, "\t  node[fontsize=" . $config['fontsize'] . "];\n");
    fwrite($dotfile, "\t  me [label=\"{$id_user}\", style=\"filled\", color=\"yellow\"]; \n");
    $total_project = 0;
    $total_task = 0;
    if ($project_kind == "all") {
        $sql1 = "SELECT * FROM tproject WHERE disabled = 0";
    } else {
        $sql1 = "SELECT * FROM tproject WHERE disabled = 0 AND end != '0000-00-00 00:00:00'";
    }
    if ($result1 = mysql_query($sql1)) {
        while ($row1 = mysql_fetch_array($result1)) {
            if (user_belong_project($id_user, $row1["id"], 1) == 1) {
                $project[$total_project] = $row1["id"];
                $project_name[$total_project] = $row1["name"];
                if ($completion < 0) {
                    $sql2 = "SELECT * FROM ttask WHERE id_project = " . $row1["id"];
                } elseif ($completion < 101) {
                    $sql2 = "SELECT * FROM ttask WHERE completion < {$completion} AND id_project = " . $row1["id"];
                } else {
                    $sql2 = "SELECT * FROM ttask WHERE completion = 100 AND id_project = " . $row1["id"];
                }
                if ($result2 = mysql_query($sql2)) {
                    while ($row2 = mysql_fetch_array($result2)) {
                        if (user_belong_task($id_user, $row2["id"], 1) == 1) {
                            $task[$total_task] = $row2["id"];
                            $task_name[$total_task] = $row2["name"];
                            $task_parent[$total_task] = $row2["id_parent_task"];
                            $task_project[$total_task] = $project[$total_project];
                            $task_workunit[$total_task] = get_task_workunit_hours($row2["id"]);
                            $task_completion[$total_task] = $row2["completion"];
                            $total_task++;
                        }
                    }
                }
                $total_project++;
            }
        }
    }
    // Add project items
    for ($ax = 0; $ax < $total_project; $ax++) {
        fwrite($dotfile, 'PROY' . $project[$ax] . ' [label="' . wordwrap($project_name[$ax], 12, '\\n') . '", style="filled", color="grey", URL="' . $config["base_url"] . '/index.php?sec=projects&sec2=operation/projects/task&id_project=' . $project[$ax] . '"];');
        fwrite($dotfile, "\n");
    }
    // Add task items
    for ($ax = 0; $ax < $total_task; $ax++) {
        $temp = 'TASK' . $task[$ax] . ' [label="' . wordwrap($task_name[$ax], 12, '\\n') . '"';
        if ($task_completion[$ax] < 10) {
            $temp .= 'color="red"';
        } elseif ($task_completion[$ax] < 100) {
            $temp .= 'color="yellow"';
        } elseif ($task_completion[$ax] == 100) {
            $temp .= 'color="green"';
        }
        $temp .= "URL=\"" . $config["base_url"] . "/index.php?sec=projects&sec2=operation/projects/task_detail&id_project=" . $task_project[$ax] . "&id_task=" . $task[$ax] . "&operation=view\"";
        $temp .= "];";
        fwrite($dotfile, $temp);
        fwrite($dotfile, "\n");
    }
    // Make project attach to user "me"
    for ($ax = 0; $ax < $total_project; $ax++) {
        fwrite($dotfile, 'me -> PROY' . $project[$ax] . ';');
        fwrite($dotfile, "\n");
    }
    // Make project first parent task relation visible
    for ($ax = 0; $ax < $total_task; $ax++) {
        if ($task_parent[$ax] == 0) {
            fwrite($dotfile, 'PROY' . $task_project[$ax] . ' -> TASK' . $task[$ax] . ';');
            fwrite($dotfile, "\n");
        }
    }
    // Make task-subtask parent task relation visible
    for ($ax = 0; $ax < $total_task; $ax++) {
        if ($task_parent[$ax] != 0) {
            fwrite($dotfile, 'TASK' . $task_parent[$ax] . ' -> TASK' . $task[$ax] . ';');
            fwrite($dotfile, "\n");
        }
    }
    fwrite($dotfile, "}");
    fwrite($dotfile, "\n");
    // exec ("twopi -Tpng $dotfilename -o $pngfilename");
    exec("twopi -Tcmapx -o{$mapfilename} -Tpng -o{$pngfilename} {$dotfilename}");
    Header('Content-type: image/png');
    $imgPng = imageCreateFromPng($pngfilename);
    imageAlphaBlending($imgPng, true);
    imageSaveAlpha($imgPng, true);
    imagePng($imgPng);
    require $mapfilename;
    //unlink ($pngfilename);
    unlink($dotfilename);
}
Exemple #2
0
function show_task_tree (&$table, $id_project, $level, $id_parent_task, $where_clause) {
	global $config;
	
	$sql = sprintf ('SELECT * FROM ttask
		WHERE %s
		AND id_project = %d
		AND id_parent_task = %d
		ORDER BY name',
		$where_clause, $id_project, $id_parent_task);
	$tasks = get_db_all_rows_sql ($sql);
	if ($tasks === false)
		return;
	foreach ($tasks as $task) {
		if (user_belong_task ($config['id_user'], $task['id']))
			show_task_row ($table, $id_project, $task, $level);
		show_task_tree ($table, $id_project, $level + 1, $task['id'], $where_clause);
	}
}
    // Try to get id_task from tworkunit_task
    $id_task = get_db_sql ("SELECT id_task FROM tworkunit_task WHERE id_workunit = $id_workunit");
}

// If id_task is set, ignore id_project and get it from the task
if ($id_task) {
	$id_project = get_db_value ('id_project', 'ttask', 'id', $id_task);
}

if ($id_incident == 0){
	$id_incident = get_db_value ('id_incident', 'tworkunit_incident', 'id_workunit', $id_workunit);
}

if ($id_task >0){ // Skip vacations, holidays etc

	if (! user_belong_task ($config["id_user"], $id_task) && !give_acl($config["id_user"], 0, "UM") ){
		// Doesn't have access to this page
		audit_db ($config['id_user'], $config["REMOTE_ADDR"], "ACL Violation", "Trying to access to task workunit form without permission");
		no_permission();
	}
}

// Lock Workunit
if ($operation == "lock") {
	$success = lock_task_workunit ($id_workunit);
	if (! $success) {
		audit_db ($config['id_user'], $config["REMOTE_ADDR"], "ACL Violation",
			"Trying to lock WU $id_workunit without rigths");
		if (!defined ('AJAX'))
			include ("general/noaccess.php");
		return;
$sql = get_projects_query($id_user, "", 0, true);
$new = true;
$color = 1;
while ($project = get_db_all_row_by_steps_sql($new, $result_project, $sql)) {
    $sql = get_tasks_query($id_user, $project['id'], "", 0, true);
    $new = true;
    $project_access = get_project_access($config['id_user'], $project['id']);
    // ACL - To see the project, you should have read access
    if (!$project_access['read']) {
        $new = false;
        continue;
        // Does not show this project tasks
    }
    while ($task = get_db_all_row_by_steps_sql($new, $result_task, $sql)) {
        $new = false;
        $belong_task = user_belong_task($id_user, $task['id'], true);
        $task_access = get_project_access($config['id_user'], $project['id'], $task['id'], false, true);
        // ACL - To see the task, you should have read access
        if (!$task_access['read']) {
            continue;
            // Does not show this task
        }
        $role = get_db_sql("SELECT name\n\t\t\t\t\t\t\t FROM trole\n\t\t\t\t\t\t\t WHERE id IN(SELECT id_role\n\t\t\t\t\t\t\t\t\t\t FROM trole_people_task\n\t\t\t\t\t\t\t\t\t\t WHERE id_user='******'\n\t\t\t\t\t\t\t\t\t\t\tAND id_task=" . $task['id'] . ")");
        echo "<tr>";
        echo "<td>";
        echo "<a href='index.php?sec=projects&sec2=operation/projects/project_detail&id_project=" . $project['id'] . "'>" . $project['name'] . "</a>";
        echo "<td><b><a href='index.php?sec=projects&sec2=operation/projects/task_detail&id_project=" . $project['id'] . "&id_task=" . $task['id'] . "&operation=view'>" . $task['name'] . "</a></b>";
        echo "<td>" . $role;
        if ($belong_task) {
            echo "<td>" . get_task_workunit_hours_user($task["id"], $id_user);
            echo "<td>" . get_task_workunit_hours($task["id"]);