Works on enhancement of project tasks

This commit is contained in:
Regis Houssin 2010-01-27 07:58:31 +00:00
parent 86d1b47534
commit b2a265a1a8
6 changed files with 82 additions and 102 deletions

View File

@ -223,7 +223,7 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
print "   ";
}
print $lines[$i]->title;
print $lines[$i]->label;
print "</td>\n";
// Project
@ -238,7 +238,7 @@ function PLinesb(&$inc, $parent, $lines, &$level, &$tasksrole)
$minutes = substr("00"."$minutes", -2);
print '<td align="right">'.$heure."&nbsp;h&nbsp;".$minutes."</td>\n";
if ($tasksrole[$lines[$i]->id] == 'admin')
if ($tasksrole[$lines[$i]->id] == 'TASKEXECUTIVE')
{
print '<td nowrap="nowrap">';
print $form->select_date('',$lines[$i]->id,'','','',"addtime");

View File

@ -227,7 +227,6 @@ if (! empty($_SESSION["disablemodules"]))
}
// Init Smarty
// TODO activer smarty par defaut ?
if (sizeof($conf->need_smarty) > 0 || $conf->global->MAIN_SMARTY)
{
// Usage of const in conf.php file can overwrite default dir.
@ -249,32 +248,6 @@ if (sizeof($conf->need_smarty) > 0 || $conf->global->MAIN_SMARTY)
}
}
// Init Dwoo
if ($conf->global->MAIN_DWOO2)
{
// Usage of const in conf.php file can overwrite default dir.
if (empty($dolibarr_dwoo_libs_dir)) $dolibarr_dwoo_libs_dir=DOL_DOCUMENT_ROOT.'/includes/dwoo/';
if (empty($dolibarr_dwoo_compile)) $dolibarr_dwoo_compile=DOL_DATA_ROOT.'/dwoo/templates/temp';
if (empty($dolibarr_dwoo_cache)) $dolibarr_dwoo_cache=DOL_DATA_ROOT.'/dwoo/cache/temp';
//$dwoo_libs = $dolibarr_dwoo_libs_dir. "dwooAutoload.php";
$dwoo_libs = $dolibarr_dwoo_libs_dir. "Dwoo.php";
$dwoo_smarty_adapter = $dolibarr_dwoo_libs_dir. "Dwoo/Smarty/Adapter.php";
if (include_once($dwoo_libs) && include_once($dwoo_smarty_adapter))
{
//$dwoo = new Dwoo($dolibarr_dwoo_compile,$dolibarr_dwoo_cache);
$smarty = new Dwoo_Smarty_Adapter();
$smarty->show_compat_errors = true;
$smarty->compile_dir = $dolibarr_smarty_compile;
$smarty->cache_dir = $dolibarr_smarty_cache;
}
else
{
dol_print_error('',"Library Dwoo ".$dwoo_libs." not found.");
}
}
/*
* Phase authentication / login
*/

View File

@ -31,7 +31,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php");
$mode=$_REQUEST["mode"];
$projectid='';
$projectid=isset($_GET["id"])?$_GET["id"]:$_POST["projetid"];
$projectid=isset($_GET["id"])?$_GET["id"]:$_POST["projectid"];
// Security check
if ($user->societe_id) $socid=$user->societe_id;
@ -74,11 +74,8 @@ if ($_POST["action"] == 'addtime' && $user->rights->projet->creer)
$task=new Task($db);
$task->fetch($id);
$project = new Project($db);
$result = $project->fetch($task->fk_projet);
$date = dol_mktime(12,0,0,$_POST["$id"."month"],$_POST["$id"."day"],$_POST["$id"."year"]);
$project->TaskAddTime($user, $id , $post, $date);
$task->addTimeSpent($user, $post, $date);
}
else
{
@ -100,11 +97,13 @@ if ($mode == 'mine') $title=$langs->trans("MyTimeSpent");
llxHeader("",$title,"");
$projet = new Project($db);
$project = new Project($db);
$task = new Task($db);
if ($_GET["id"])
{
$projet->fetch($_GET["id"]);
$projet->societe->fetch($projet->societe->id);
$project->fetch($_GET["id"]);
$project->societe->fetch($project->societe->id);
}
@ -117,11 +116,11 @@ print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorde
if ($mesg) print $mesg;
$tasksrole=$projet->getTasksRoleForUser($user);
$tasksarray=$projet->getTasksArray(0,0);
$tasksrole=$task->getTasksRoleForUser($user);
$tasksarray=$task->getTasksArray(0,0);
//var_dump($tasksarray);
print '<form name="addtime" method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$projet->id.'">';
print '<form name="addtime" method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addtime">';

View File

@ -209,18 +209,18 @@ class Project extends CommonObject
/**
* \brief Return list of projects
* \param id_societe To filter on a particular third party
* \param socid To filter on a particular third party
* \return array Liste of projects
*/
function liste_array($id_societe='')
function liste_array($socid='')
{
$projets = array();
global $conf;
$projects = array();
$sql = "SELECT rowid, title FROM ".MAIN_DB_PREFIX."projet";
if (! empty($id_societe))
{
$sql .= " WHERE fk_soc = ".$id_societe;
}
$sql.= " WHERE entity = ".$conf->entity;
if (! empty($socid)) $sql.= " AND fk_soc = ".$socid;
$resql=$this->db->query($sql);
if ($resql)
@ -234,11 +234,11 @@ class Project extends CommonObject
{
$obj = $this->db->fetch_object($resql);
$projets[$obj->rowid] = $obj->title;
$projects[$obj->rowid] = $obj->title;
$i++;
}
}
return $projets;
return $projects;
}
else
{
@ -500,55 +500,6 @@ class Project extends CommonObject
return $result;
}
/**
* \brief Cree une tache dans le projet
* \param user Id utilisateur qui cree
* \param title titre de la tache
* \param parent tache parente
*/
function TaskAddTime($user, $task, $time, $date)
{
$result = 0;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (fk_task, task_date, task_duration, fk_user)";
$sql .= " VALUES (".$task.",'".$this->db->idate($date)."',".$time.", ".$user->id.")";
dol_syslog("Project::TaskAddTime sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql) )
{
$task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
$result = 0;
}
else
{
$this->error=$this->db->lasterror();
dol_syslog("Project::TaskAddTime error -2 ".$this->error,LOG_ERR);
$result = -2;
}
if ($result == 0)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
$sql .= " SET duration_effective = duration_effective + '".price2num($time)."'";
$sql .= " WHERE rowid = '".$task."';";
dol_syslog("Project::TaskAddTime sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql) )
{
$result = 0;
}
else
{
$this->error=$this->db->lasterror();
dol_syslog("Project::TaskAddTime error -3 ".$this->error, LOG_ERR);
$result = -2;
}
}
return $result;
}
/**
* \brief Return status label of object
* \param mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto

View File

@ -98,8 +98,8 @@ if ($_POST["action"] == 'createtask' && $user->rights->projet->creer)
if ($_POST["action"] == 'addtime' && $user->rights->projet->creer)
{
$project = new Project($db);
$result = $project->fetch($_GET["id"]);
$task = new Task($db);
$result = $task->fetch($_GET["id"]);
if ($result == 0)
{
@ -116,12 +116,12 @@ if ($_POST["action"] == 'addtime' && $user->rights->projet->creer)
$id = str_replace("task","",$key);
$date = dol_mktime(12,0,0,$_POST["$id"."month"],$_POST["$id"."day"],$_POST["$id"."year"]);
$project->TaskAddTime($user, $id , $post, $date);
$task->addTimeSpent($user, $post, $date);
}
}
}
Header("Location:fiche.php?id=".$project->id);
Header("Location:fiche.php?id=".$task->id);
exit;
}
}

View File

@ -509,6 +509,63 @@ class Task extends CommonObject
return $tasksrole;
}
/**
* \brief Add time spent
* \param user Id utilisateur qui cree
* \param time Time spent
* \param date date
*/
function addTimeSpent($user, $time, $date)
{
$result = 0;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time (";
$sql.= "fk_task";
$sql.= ", task_date";
$sql.= ", task_duration";
$sql.= ", fk_user";
$sql.= ") VALUES (";
$sql.= $this->id;
$sql.= ", '".$this->db->idate($date)."'";
$sql.= ", ".$time;
$sql.= ", ".$user->id;
$sql.= ")";
dol_syslog("Project::addTimeSpent sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql) )
{
$task_id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task");
$result = 0;
}
else
{
$this->error=$this->db->lasterror();
dol_syslog("Project::addTimeSpent error -2 ".$this->error,LOG_ERR);
$result = -2;
}
if ($result == 0)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."projet_task";
$sql.= " SET duration_effective = duration_effective + '".price2num($time)."'";
$sql.= " WHERE rowid = ".$this->id;
dol_syslog("Project::addTimeSpent sql=".$sql, LOG_DEBUG);
if ($this->db->query($sql) )
{
$result = 0;
}
else
{
$this->error=$this->db->lasterror();
dol_syslog("Project::addTimeSpent error -3 ".$this->error, LOG_ERR);
$result = -2;
}
}
return $result;
}
}
?>