New: Add experimental gant diagramm for project module

This commit is contained in:
Laurent Destailleur 2010-05-22 16:53:36 +00:00
parent 54d097a464
commit 8bdbf014e4
7 changed files with 401 additions and 8 deletions

View File

@ -29,6 +29,16 @@ FPDFI and FPDF_TPL:
* Replaced all sprintf(%0.2f) by sprintf(%0.2F) (Fix bug)
JSGANTT:
--------
* Replace in function JSGantt.taskLink
var OpenWindow=window.open(pRef, "newwin", "height="+vHeight+",width="+vWidth);
with
// LDR To open in same window
//var OpenWindow=window.open(pRef, "newwin", "height="+vHeight+",width="+vWidth);
window.location.href=pRef
PHP-BARCODE:
------------
If files are replaced by new version, following changes must be done:

View File

@ -1905,9 +1905,9 @@ JSGantt.folder= function (pID,ganttObj) {
JSGantt.show(pID, 1, ganttObj);
if (JSGantt.isIE())
{JSGantt.findObj('group_'+pID).innerText = '';}
{JSGantt.findObj('group_'+pID).innerText = '<EFBFBD>';}
else
{JSGantt.findObj('group_'+pID).textContent = '';}
{JSGantt.findObj('group_'+pID).textContent = '<EFBFBD>';}
}
@ -1979,7 +1979,7 @@ JSGantt.show = function (pID, pTop, ganttObj) {
} else {
if (JSGantt.isIE()) { // IE;
if( JSGantt.findObj('group_'+pID).innerText == '') {
if( JSGantt.findObj('group_'+pID).innerText == '<EFBFBD>') {
JSGantt.findObj('child_'+vID).style.display = "";
JSGantt.findObj('childgrid_'+vID).style.display = "";
vList[i].setVisible(1);
@ -1987,7 +1987,7 @@ JSGantt.show = function (pID, pTop, ganttObj) {
} else {
if( JSGantt.findObj('group_'+pID).textContent == '') {
if( JSGantt.findObj('group_'+pID).textContent == '<EFBFBD>') {
JSGantt.findObj('child_'+vID).style.display = "";
JSGantt.findObj('childgrid_'+vID).style.display = "";
vList[i].setVisible(1);
@ -2017,7 +2017,9 @@ JSGantt.taskLink = function(pRef,pWidth,pHeight)
if(pWidth) {vWidth =pWidth;} else {vWidth =400;}
if(pHeight) {vHeight=pHeight;} else {vHeight=400;}
var OpenWindow=window.open(pRef, "newwin", "height="+vHeight+",width="+vWidth);
// LDR To open in same window
//var OpenWindow=window.open(pRef, "newwin", "height="+vHeight+",width="+vWidth);
window.location.href=pRef
};

View File

@ -76,6 +76,7 @@ DeleteATimeSpent=Delete time spent
ConfirmDeleteATimeSpent=Are you sure you want to delete this time spent ?
DoNotShowMyTasksOnly=See also tasks i am not affected to
ShowMyTasksOnly=View only tasks i am affected to
TaskRessourceLinks=Ressources
##### Types de contacts #####
TypeContact_project_internal_PROJECTLEADER=Project leader
TypeContact_project_external_PROJECTLEADER=Project leader

View File

@ -76,6 +76,7 @@ DeleteATimeSpent=Suppression du temps consommé
ConfirmDeleteATimeSpent=Êtes-vous sûr de vouloir supprimer ce temps consommé ?
DoNotShowMyTasksOnly=Voir aussi les taches qui ne me sont pas affectées
ShowMyTasksOnly=Ne voir que les taches qui me sont affectées
TaskRessourceLinks=Affectation ressources
##### Types de contacts #####
TypeContact_project_internal_PROJECTLEADER=Chef de projet
TypeContact_project_external_PROJECTLEADER=Chef de projet

View File

@ -92,9 +92,9 @@ function project_prepare_head($object)
$h++;
*/
if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
if ($conf->global->MAIN_FEATURES_LEVEL >= 1)
{
$head[$h][0] = DOL_URL_ROOT.'/projet/gant/gantview.php?id='.$object->id;
$head[$h][0] = DOL_URL_ROOT.'/projet/ganttview.php?id='.$object->id;
$head[$h][1] = $langs->trans("Gantt");
$head[$h][2] = 'gantt';
$h++;
@ -122,7 +122,7 @@ function task_prepare_head($object)
$h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id;
$head[$h][1] = $langs->trans("Affectations");
$head[$h][1] = $langs->trans("TaskRessourceLinks");
$head[$h][2] = 'contact';
$h++;

View File

@ -0,0 +1,173 @@
<?php
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file htdocs/projet/ganttview.php
* \ingroup projet
* \brief Gantt diagrame of a project
* \version $Id$
*/
?>
<div id="principal_content" style="margin-left: 0px;">
<div style="margin-left: 0; position: relative;" class="gantt" id="GanttChartDIV"></div>
<script language="javascript" type="text/javascript">
var g = new JSGantt.GanttChart('g',document.getElementById('GanttChartDIV'), 'day');
var booShowRessources = 1;
var booShowDurations = 1;
var booShowComplete = 1;
var barText = "Resource";
var graphFormat = "day";
function DisplayHideRessources(boxName) {
graphFormat = g.getFormat();
if(boxName.checked == true) {
booShowRessources = 1;
}
else {
booShowRessources = 0;
}
reloadGraph();
}
function DisplayHideDurations(boxName) {
graphFormat = g.getFormat();
if(boxName.checked == true) {
booShowDurations = 1;
}
else {
booShowDurations = 0;
}
reloadGraph();
}
function DisplayHideComplete(boxName) {
graphFormat = g.getFormat();
if(boxName.checked == true) {
booShowComplete = 1;
}
else {
booShowComplete = 0;
}
reloadGraph();
}
function selectBarText(value) {
graphFormat = g.getFormat();
id=value.options[value.selectedIndex].value;
barText = id;
reloadGraph();
}
function reloadGraph() {
g.setShowRes(booShowRessources);
g.setShowComp(booShowComplete);
g.setShowDur(booShowDurations);
g.setCaptionType(barText);
g.setFormat(graphFormat);
g.Draw($("#tabs").width()-40);
}
g.setDateInputFormat('mm/dd/yyyy'); // Set format of input dates ('mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy-mm-dd')
g.setDateDisplayFormat('<?php echo $dateformat; ?>'); // Set format to display dates ('mm/dd/yyyy', 'dd/mm/yyyy', 'yyyy-mm-dd')
g.setShowRes(1); // Show/Hide Responsible (0/1)
g.setShowDur(1); // Show/Hide Duration (0/1)
g.setShowComp(1); // Show/Hide % Complete(0/1)
g.setShowStartDate(1); // Show/Hide % Complete(0/1)
g.setShowEndDate(1); // Show/Hide % Complete(0/1)
g.setFormatArr("day","week","month","quarter") // Set format options (up to 4 : "minute","hour","day","week","month","quarter")
g.setCaptionType('Caption'); // Set to Show Caption (None,Caption,Resource,Duration,Complete)
if(g) {
<?php
$level=0;
$tnums = count($tasks);
for ($tcursor=0; $tcursor < $tnums; $tcursor++) {
$t = $tasks[$tcursor];
if ($t["task_parent"] == 0) {
constructGanttLine($array_contacts,$tasks,$t,$project_dependencies,$level,$project_id);
findChildGanttLine($array_contacts,$tasks,$t["task_id"],$project_dependencies,$level+1);
}
}
?>
g.Draw($("#tabs").width()-40);
setTimeout('g.DrawDependencies()',100);
}
else
{
alert("<?php echo $langs->trans("FailedToDefinGraph"); ?>");
}
</script></div>
<?php
function constructGanttLine($array_contacts,$tarr,$task,$project_dependencies,$level=0,$project_id=null){
$start_date = $task["task_start_date"];
$end_date = $task["task_end_date"];
if (!$end_date) $end_date = $start_date;
$start_date = dol_print_date($start_date,"%m/%d/%Y");
$end_date = dol_print_date($end_date,"%m/%d/%Y");
// Ressources
$ressources = $array_contacts[$task["task_id"]];
//$ressources = 'ee'; // TODO Add list of ressources
// Define depend (ex: "", "4,13", ...)
$depend = "\"";
$count = 0;
foreach ($project_dependencies as $value) { // Not yet used project_dependencies = array(array(0=>idtask,1=>idtasktofinishfisrt))
if ($value[0] == $task['task_id']) {
$depend.=($count>0?",":"").$value[1];
$count ++;
}
}
$depend .= "\"";
// Define parent
if ($project_id && $level < 0)
$parent = 'p'.$project_id;
else
$parent = $task["task_parent"];
// Define percent
$percent = $task['task_percent_complete']?$task['task_percent_complete']:0;
// Link
$link=DOL_URL_ROOT.'/projet/tasks/task?id='.$task["task_id"];
// Name
$name=$task['task_name'];
for($i=0; $i < $level; $i++) { $name=' &nbsp; &nbsp; '.$name; }
// Add line to gantt
$s = "// Add taks id=".$tasks["task_id"]." level = ".$level."\n";
//$s.= "g.AddElementItem(new JSGantt.ElementItem('task',".$task['task_id'].",'".$name."','".$start_date."', '".$end_date."', 'b4d1ea', '', ".$task['task_milestone'].", '".$ressources."', ".$percent.", ".($task["task_is_group"]>0?1:0).", ".$parent.", 1".($depend?", ".$depend:"")."));";
$s = "g.AddTaskItem(new JSGantt.TaskItem(".$task['task_id'].",'".$name."','".$start_date."', '".$end_date."', 'b4d1ea', '".$link."', ".$task['task_milestone'].", '".$ressources."', ".$percent.", ".($task["task_is_group"]>0?1:0).", '".$parent."', 1".($depend?",".$depend:"")."));";
echo $s."\n";
}
function findChildGanttLine($array_contacts,$tarr,$parent,$project_dependencies,$level) {
$n=count( $tarr );
for ($x=0; $x < $n; $x++) {
if($tarr[$x]["task_parent"] == $parent && $tarr[$x]["task_parent"] != $tarr[$x]["task_id"])
{
constructGanttLine($array_contacts,$tarr,$tarr[$x],$project_dependencies,$level,null);
findChildGanttLine($array_contacts,$tarr,$tarr[$x]["task_id"],$project_dependencies,$level+1);
}
}
}
?>

206
htdocs/projet/ganttview.php Normal file
View File

@ -0,0 +1,206 @@
<?php
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file htdocs/projet/ganttview.php
* \ingroup projet
* \brief Gantt diagrame of a project
* \version $Id$
*/
define('DISABLE_PROTOTYPE',1);
define('DISABLE_SCRIPTACULOUS',1);
define('DISABLE_PWC',1);
require ("../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
require_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php");
$projectid='';
$projectid=isset($_REQUEST["id"])?$_REQUEST["id"]:$_POST["id"];
// Security check
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'projet', $projectid);
$userAccess=0;
$langs->load("users");
$langs->load("projects");
/*
* Actions
*/
/*
* View
*/
$arrayofcss=array(
'/includes/jsgantt/jsgantt.css'
);
$arrayofjs=array(
'/includes/jsgantt/jsgantt.js',
'/includes/jquery/jquery.min.js',
);
$form=new Form($db);
$formother=new FormOther($db);
$help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
llxHeader("",$langs->trans("Tasks"),$help_url,'',0,0,$arrayofjs,$arrayofcss);
$task = new Task($db);
$id = $_REQUEST['id'];
$ref= $_GET['ref'];
if ($id > 0 || ! empty($ref))
{
$project = new Project($db);
$project->fetch($_REQUEST["id"],$_GET["ref"]);
if ($project->societe->id > 0) $result=$project->societe->fetch($project->societe->id);
// To verify role of users
$userAccess = $project->restrictedProjectArea($user);
}
$userstatic=new User($db);
$tab='gantt';
$head=project_prepare_head($project);
dol_fiche_head($head, $tab, $langs->trans("Project"),0,($project->public?'projectpub':'project'));
$param=($_REQUEST["mode"]=='mine'?'&mode=mine':'');
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="30%">';
print $langs->trans("Ref");
print '</td><td>';
print $form->showrefnav($project,'ref','',1,'ref','ref','',$param);
print '</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$project->title.'</td></tr>';
print '<tr><td>'.$langs->trans("Company").'</td><td>';
if (! empty($project->societe->id)) print $project->societe->getNomUrl(1);
else print '&nbsp;';
print '</td>';
print '</tr>';
// Visibility
print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
if ($project->public) print $langs->trans('SharedProject');
else print $langs->trans('PrivateProject');
print '</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$project->getLibStatut(4).'</td></tr>';
print '</table>';
print '</div>';
/*
* Actions
*/
/*
print '<div class="tabsAction">';
if ($user->rights->projet->all->creer || $user->rights->projet->creer)
{
if ($project->public || $userAccess)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$project->id.'&action=create'.$param.'">'.$langs->trans('AddTask').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
}
}
else
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans("NoPermission").'">'.$langs->trans('AddTask').'</a>';
}
print '</div>';
print '<br>';
*/
// Get list of tasks in tasksarray and taskarrayfiltered
// We need all tasks (even not limited to a user because a task to user
// can have a parent that is not affected to him).
$tasksarray=$task->getTasksArray(0, 0, $project->id, $socid, 0);
// We load also tasks limited to a particular user
$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getUserRolesForProjectsOrTasks(0,$user,$project->id,0) : '');
//var_dump($tasksarray);
//var_dump($tasksrole);
// Show Gant diagram from $taskarray using JSGantt
$dateformat=$langs->trans("FormatDateShort");
$dateformat=strtolower($langs->trans("FormatDateShortJava"));
$array_contacts=array();
$tasks=array();
$project_dependencies=array();
$project_id=$project->id;
$i=0;
foreach($tasksarray as $key => $val)
{
// if ($val->date_start && $val->date_end)
// {
$tasks[$i]['task_id']=$val->id;
$tasks[$i]['task_parent']=$val->fk_parent;
$tasks[$i]['task_is_group']=0;
$tasks[$i]['task_milestone']=0;
$tasks[$i]['task_percent_complete']=$val->progress;
$tasks[$i]['task_name']=$val->label;
$tasks[$i]['task_start_date']=$val->date_start;
$tasks[$i]['task_end_date']=$val->date_end;
$i++;
// }
}
//var_dump($tasks);
print "\n";
print '<div id="tabs">'."\n";
include_once(DOL_DOCUMENT_ROOT.'/projet/ganttchart.php');
print '</div>'."\n";
$db->close();
llxFooter('$Date$ - $Revision$');
?>