diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 84f26a1f605..23beaa147fc 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -44,3 +44,4 @@ ErrorLDAPMakeManualTest=A .ldif file has been generated in directory %s. Try to ErrorCantSaveADoneUserWithZeroPercentage=Can't save an action with "statut not started" if field "done by" is also filled. ErrorBillRefAlreadyExists=Ref used for creation already exists. ErrorPleaseTypeBankTransactionReportName=Please type bank receipt name where transaction is reported (Format YYYYMM or YYYYMMDD) +ErrorRecordHasChildren=Failed to delete records since it has some childs. \ No newline at end of file diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 0c8a7e86b2a..21d186adf03 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -43,4 +43,5 @@ ErrorLDAPSetupNotComplete=Le matching Dolibarr-LDAP est incomplet. ErrorLDAPMakeManualTest=Un fichier .ldif a été généré dans le répertoire %s. Essayer de charger ce fichier en manuel depuis la ligne de commande pour plus de détail sur l'erreur. ErrorCantSaveADoneUserWithZeroPercentage=Impossible sauver une action à l'état non commencé avec un utilisateur défini comme ayant fait l'action. ErrorBillRefAlreadyExists=La référence utilisée pour la création existe déjà -ErrorPleaseTypeBankTransactionReportName=Veuiller saisir le nom de relevé bancaire sur lequel l'écriture est constaté (Format AAAAMM ou AAAMMJJ) \ No newline at end of file +ErrorPleaseTypeBankTransactionReportName=Veuiller saisir le nom de relevé bancaire sur lequel l'écriture est constaté (Format AAAAMM ou AAAMMJJ) +ErrorRecordHasChildren=Impossible de supprimer l'enregistrement car il possède des fils. \ No newline at end of file diff --git a/htdocs/project.class.php b/htdocs/project.class.php index 34415c01723..3fbae360f90 100644 --- a/htdocs/project.class.php +++ b/htdocs/project.class.php @@ -33,13 +33,19 @@ require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); */ class Project extends CommonObject { + var $db; //!< To store db handler + var $error; //!< To return error code (or message) + var $errors=array(); //!< To return several error codes (or messages) + var $element='project'; //!< Id that identify managed objects + var $table_element='projet'; //!< Name of table without prefix where object is stored + var $id; - var $db; var $ref; var $title; var $socid; var $user_resp_id; + /** * \brief Constructeur de la classe * \param DB handler acc�s base de donn�es @@ -121,17 +127,20 @@ class Project extends CommonObject } - /* - * \brief Charge objet projet depuis la base - * \param rowid id du projet a charger - */ - function fetch($rowid) + /** + * \brief Get object and lines from database + * \param rowid id of object to load + * \param ref Ref of project + * \return int >0 if OK, <0 if KO + */ + function fetch($id,$ref='') { - - $sql = "SELECT title, ref, fk_soc, fk_user_creat, fk_user_resp, fk_statut, note"; + $sql = "SELECT rowid, ref, title, fk_soc, fk_user_creat, fk_user_resp, fk_statut, note"; $sql.= " FROM ".MAIN_DB_PREFIX."projet"; - $sql.= " WHERE rowid=".$rowid; + if ($ref) $sql.= " WHERE ref='".$ref."'"; + else $sql.= " WHERE rowid=".$id; + dolibarr_syslog("Project::fetch sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -139,7 +148,7 @@ class Project extends CommonObject { $obj = $this->db->fetch_object($resql); - $this->id = $rowid; + $this->id = $obj->rowid; $this->ref = $obj->ref; $this->title = $obj->title; $this->titre = $obj->title; diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index 9f190af57b0..288a8bb6073 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2008 Laurent Destailleur + * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2008 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -43,9 +43,10 @@ if ($conf->propal->enabled) $langs->load("propal"); // Security check $projetid=''; -if ($_GET["id"]) { $projetid=$_GET["id"]; } - -if ($projetid == '') accessforbidden(); +$ref=''; +if (isset($_GET["id"])) { $projetid=$_GET["id"]; } +if (isset($_GET["ref"])) { $ref=$_GET["ref"]; } +if ($projetid == '' && $ref == '') accessforbidden(); // Security check if ($user->societe_id) $socid=$user->societe_id; @@ -58,8 +59,10 @@ $result = restrictedArea($user, 'projet', $projetid); llxHeader("",$langs->trans("Referers")); +$form = new Form($db); + $projet = new Project($db); -$projet->fetch($_GET["id"]); +$projet->fetch($_GET["id"],$_GET["ref"]); $projet->societe->fetch($projet->societe->id); $head=project_prepare_head($projet); @@ -68,7 +71,9 @@ dolibarr_fiche_head($head, 'element', $langs->trans("Project")); print ''; -print ''; +print ''; print ''; diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index 97c9f1005dd..61fcc0e35d6 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -32,7 +32,9 @@ require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); $projetid=''; -if ($_GET["id"]) { $projetid=$_GET["id"]; } +$ref=''; +if (isset($_GET["id"])) { $projetid=$_GET["id"]; } +if (isset($_GET["ref"])) { $ref=$_GET["ref"]; } // If socid provided by ajax company selector if (! empty($_POST['socid_id'])) @@ -41,7 +43,7 @@ if (! empty($_POST['socid_id'])) $_REQUEST['socid'] = $_REQUEST['socid_id']; } -if ($projetid == '' && ($_GET['action'] != "create" && $_POST['action'] != "add" && $_POST["action"] != "update" && !$_POST["cancel"])) accessforbidden(); +if ($projetid == '' && $ref == '' && ($_GET['action'] != "create" && $_POST['action'] != "add" && $_POST["action"] != "update" && !$_POST["cancel"])) accessforbidden(); // Security check if ($user->societe_id) $socid=$user->societe_id; @@ -180,7 +182,7 @@ else if ($mesg) print $mesg; $projet = new Project($db); - $projet->fetch($_GET["id"]); + $projet->fetch($_GET["id"],$_GET["ref"]); $projet->societe->fetch($projet->societe->id); $head=project_prepare_head($projet); @@ -227,7 +229,9 @@ else print '
'.$langs->trans("Ref").''.$projet->ref.'
'.$langs->trans("Ref").''; +print $form->showrefnav($projet,'ref','',1,'ref','ref'); +print '
'.$langs->trans("Label").''.$projet->title.'
'; // Ref - print ''; + print ''; // Label print ''; diff --git a/htdocs/projet/tasks/fiche.php b/htdocs/projet/tasks/fiche.php index 26695e46ae6..2c06a776c1b 100644 --- a/htdocs/projet/tasks/fiche.php +++ b/htdocs/projet/tasks/fiche.php @@ -29,7 +29,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); $projetid=''; -$projetid=isset($_GET["id"])?$_GET["id"]:$_POST["projetid"]; +$projetid=isset($_REQUEST["id"])?$_REQUEST["id"]:$_POST["projetid"]; // Security check if ($user->societe_id) $socid=$user->societe_id; @@ -39,7 +39,7 @@ $result = restrictedArea($user, 'projet', $projetid); * Actions */ -if ($_POST["action"] == 'createtask' && $user->rights->projet->creer && empty($_POST["cancel"])) +if ($_POST["action"] == 'createtask' && empty($_POST["cancel"]) && $user->rights->projet->creer) { $error=0; @@ -66,8 +66,16 @@ if ($_POST["action"] == 'createtask' && $user->rights->projet->creer && empty($_ if (! $error) { - Header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'); - exit; + if (empty($projetid)) + { + Header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'); + exit; + } + else + { + Header("Location: ".DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$projetid); + exit; + } } } @@ -111,9 +119,12 @@ $form=new Form($db); llxHeader("",$langs->trans("Tasks"),"Tasks"); $projet = new Project($db); -if ($_GET["id"]) + +$id = $_REQUEST['id']; +$ref= $_GET['ref']; +if ($id > 0 || ! empty($ref)) { - $projet->fetch($_GET["id"]); + $projet->fetch($_REQUEST["id"],$_GET["ref"]); $projet->societe->fetch($projet->societe->id); } @@ -127,7 +138,8 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer) print ''; print ''; - + if ($_GET['id']) print ''; + print '
'.$langs->trans("Ref").''.$projet->ref.'
'.$langs->trans("Ref").''; + print $html->showrefnav($projet,'ref','',1,'ref','ref'); + print '
'.$langs->trans("Label").''.$projet->title.'
'; print ''; - print ''; + print ''; /* Liste des tâches */ @@ -131,43 +134,20 @@ if ($_GET["id"] > 0) $tasks = array(); while ($i < $num) { - $row = $db->fetch_row($resql); + $row = $db->fetch_object($resql); $tasks[$i] = $row; $i++; } - $db->free(); + $db->free($resql); } else { dolibarr_print_error($db); } - - /* Nouvelle tâche */ - print '
'.$langs->trans("NewTask").''; @@ -165,10 +177,17 @@ else $head=project_prepare_head($projet); dolibarr_fiche_head($head, 'tasks', $langs->trans("Project")); - + print ''; + print ''; - print ''; + // Ref + print ''; + print ''; print '
'.$langs->trans("Ref").''.$projet->ref.'
'; + print $langs->trans("Ref"); + print ''; + print $form->showrefnav($projet,'ref','',1,'ref','ref'); + print '
'.$langs->trans("Label").''.$projet->title.'
'.$langs->trans("Company").''; if (! empty($projet->societe->id)) print $projet->societe->getNomUrl(1); @@ -180,28 +199,13 @@ else $tasksarray=$projet->getTasksArray(); print '
'; - print '
'; - print ''; print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print "\n"; - $j=0; - PLines($j, 0, $tasksarray, $level, true); print ''; - - - print "
'.$langs->trans("Project").''.$langs->trans("RefTask").''.$langs->trans("LabelTask").''.$langs->trans("TimeSpent").'
"; print ''; - - + + /* * Actions */ @@ -213,6 +217,20 @@ else } print ''; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + $j=0; + PLines($j, 0, $tasksarray, $level, true); + print "
'.$langs->trans("Project").''.$langs->trans("RefTask").''.$langs->trans("LabelTask").''.$langs->trans("TimeSpent").'
"; + print ''; + } $db->close(); diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 7f17e9171e7..6b51a7679fb 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -1,6 +1,6 @@ - * Copyright (C) 2006-2008 Laurent Destailleur + * Copyright (C) 2006-2009 Laurent Destailleur * * 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 @@ -45,14 +45,15 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == "yes" && $user- $projet->societe->fetch($projet->socid); } - if ($task->delete($user) >= 0) + if ($task->delete($user) > 0) { Header("Location: index.php"); exit; } else { - $mesg=$task->error; + $langs->load("errors"); + $mesg='
'.$langs->trans($task->error).'
'; $_POST["action"]=''; } } @@ -81,10 +82,7 @@ if ($_GET["id"] > 0) { $projet = new Project($db); $result=$projet->fetch($task->fk_projet); - if (! empty($projet->socid)) - { - $projet->societe->fetch($projet->socid); - } + if (! empty($projet->socid)) $projet->societe->fetch($projet->socid); $h=0; $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$task->id; @@ -94,6 +92,8 @@ if ($_GET["id"] > 0) dolibarr_fiche_head($head, 'tasks', $langs->trans("Tasks")); + if ($mesg) print $mesg.'
'; + if ($_GET["action"] == 'delete') { $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],$langs->trans("DeleteATask"),$langs->trans("ConfirmDeleteATask"),"confirm_delete"); @@ -111,7 +111,10 @@ if ($_GET["id"] > 0) print $projet->getNomUrl(1); print '
'.$langs->trans("Company").''.$projet->societe->getNomUrl(1).'
'.$langs->trans("Company").''; + if ($projet->societe->id) print $projet->societe->getNomUrl(1); + else print ' '; + print '

'; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - foreach ($tasks as $task_time) - { - $var=!$var; - print ""; - print ''; - print ''; - $user->id=$task_time[4]; - $user->nom=$task_time[3]; - print ''; - print "\n"; - } - - print "
'.$langs->trans("Date").''.$langs->trans("TimeSpent").''.$langs->trans("User").'
'.dolibarr_print_date($task_time[0],'day').''.$task_time[1].''.$user->getNomUrl(1).'
"; + print ''; print ''; + /* * Actions @@ -180,6 +160,30 @@ if ($_GET["id"] > 0) } print ''; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + foreach ($tasks as $task_time) + { + $var=!$var; + print ""; + print ''; + print ''; + $user->id=$task_time->rowid; + $user->nom=$task_time->login; + print ''; + print "\n"; + } + + print "
'.$langs->trans("Date").''.$langs->trans("TimeSpent").''.$langs->trans("User").'
'.dolibarr_print_date($db->jdate($task_time->task_date),'day').''.$task_time->task_duration.''.$user->getNomUrl(1).'
"; + } } diff --git a/htdocs/task.class.php b/htdocs/task.class.php index 1efa2e63392..21865b49b35 100644 --- a/htdocs/task.class.php +++ b/htdocs/task.class.php @@ -309,13 +309,18 @@ class Task // extends CommonObject global $conf, $langs; $error=0; - // TODO. Refused if there is some child. + $this->db->begin(); + if ($this->hasChildren() > 0) + { + dolibarr_syslog(get_class($this)."::delete Can't delete record as it has some child", LOG_WARNING); + $this->error='ErrorRecordHasChildren'; + $this->db->rollback(); + return 0; + } $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task"; $sql.= " WHERE rowid=".$this->id; - - $this->db->begin(); dolibarr_syslog(get_class($this)."::delete sql=".$sql); $resql = $this->db->query($sql); @@ -355,7 +360,36 @@ class Task // extends CommonObject } } - + /** + * \brief Return nb of children + * \return <0 if KO, 0 if no children, >0 if OK + */ + function hasChildren() + { + $ret=0; + + $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."projet_task"; + $sql.= " WHERE fk_task_parent=".$this->id; + + dolibarr_syslog(get_class($this)."::hasChildren sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + else + { + $obj=$this->db->fetch_object($resql); + if ($obj) $ret=$obj->nb; + } + + if (! $error) + { + return $ret; + } + else + { + return -1; + } + } + /** * \brief Initialise object with example values * \remarks id must be 0 if object instance is a specimen. @@ -371,8 +405,6 @@ class Task // extends CommonObject $this->fk_user_creat=''; $this->statut=''; $this->note=''; - - } }