Do not allow to remove task with children
This commit is contained in:
parent
4d7e695d86
commit
5cf2356bcb
@ -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.
|
||||
@ -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)
|
||||
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.
|
||||
@ -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<EFBFBD>s base de donn<EFBFBD>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;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* 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 '<table class="border" width="100%">';
|
||||
|
||||
print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>'.$projet->ref.'</td></tr>';
|
||||
print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
|
||||
print $form->showrefnav($projet,'ref','',1,'ref','ref');
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projet->title.'</td></tr>';
|
||||
|
||||
|
||||
@ -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 '<table class="border" width="100%">';
|
||||
|
||||
// Ref
|
||||
print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>'.$projet->ref.'</td></tr>';
|
||||
print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
|
||||
print $html->showrefnav($projet,'ref','',1,'ref','ref');
|
||||
print '</td></tr>';
|
||||
|
||||
// Label
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projet->title.'</td></tr>';
|
||||
|
||||
@ -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 '<form action="fiche.php" method="post">';
|
||||
print '<input type="hidden" name="action" value="createtask">';
|
||||
|
||||
if ($_GET['id']) print '<input type="hidden" name="id" value="'.$_GET['id'].'">';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr><td>'.$langs->trans("NewTask").'</td><td colspan="3">';
|
||||
@ -165,10 +177,17 @@ else
|
||||
$head=project_prepare_head($projet);
|
||||
dolibarr_fiche_head($head, 'tasks', $langs->trans("Project"));
|
||||
|
||||
|
||||
print '<form name="addtime" method="POST" action="fiche.php?id='.$projet->id.'">';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>'.$projet->ref.'</td></tr>';
|
||||
// Ref
|
||||
print '<tr><td width="30%">';
|
||||
print $langs->trans("Ref");
|
||||
print '</td><td>';
|
||||
print $form->showrefnav($projet,'ref','',1,'ref','ref');
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projet->title.'</td></tr>';
|
||||
print '<td>'.$langs->trans("Company").'</td><td>';
|
||||
if (! empty($projet->societe->id)) print $projet->societe->getNomUrl(1);
|
||||
@ -180,28 +199,13 @@ else
|
||||
$tasksarray=$projet->getTasksArray();
|
||||
|
||||
print '</table>';
|
||||
print '<br>';
|
||||
|
||||
print '<form name="addtime" method="POST" action="fiche.php?id='.$projet->id.'">';
|
||||
print '<input type="hidden" name="action" value="addtime">';
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Project").'</td>';
|
||||
print '<td>'.$langs->trans("RefTask").'</td>';
|
||||
print '<td>'.$langs->trans("LabelTask").'</td>';
|
||||
print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
|
||||
|
||||
print "</tr>\n";
|
||||
$j=0;
|
||||
PLines($j, 0, $tasksarray, $level, true);
|
||||
print '</form>';
|
||||
|
||||
|
||||
print "</table>";
|
||||
print '</div>';
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
@ -213,6 +217,20 @@ else
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
|
||||
print '<br>';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Project").'</td>';
|
||||
print '<td>'.$langs->trans("RefTask").'</td>';
|
||||
print '<td>'.$langs->trans("LabelTask").'</td>';
|
||||
print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
|
||||
print "</tr>\n";
|
||||
$j=0;
|
||||
PLines($j, 0, $tasksarray, $level, true);
|
||||
print "</table>";
|
||||
print '</div>';
|
||||
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2006-2009 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
|
||||
@ -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='<div class="error">'.$langs->trans($task->error).'</div>';
|
||||
$_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.'<br>';
|
||||
|
||||
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 '</td></tr>';
|
||||
|
||||
print '<td>'.$langs->trans("Company").'</td><td>'.$projet->societe->getNomUrl(1).'</td></tr>';
|
||||
print '<td>'.$langs->trans("Company").'</td><td>';
|
||||
if ($projet->societe->id) print $projet->societe->getNomUrl(1);
|
||||
else print ' ';
|
||||
print '</td></tr>';
|
||||
|
||||
/* 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 '</table></form><br />';
|
||||
|
||||
print '<input type="hidden" name="action" value="addtime">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Date").'</td>';
|
||||
print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
|
||||
print '<td align="right">'.$langs->trans("User").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
foreach ($tasks as $task_time)
|
||||
{
|
||||
$var=!$var;
|
||||
print "<tr ".$bc[$var].">";
|
||||
print '<td>'.dolibarr_print_date($task_time[0],'day').'</td>';
|
||||
print '<td align="right">'.$task_time[1].'</td>';
|
||||
$user->id=$task_time[4];
|
||||
$user->nom=$task_time[3];
|
||||
print '<td align="right">'.$user->getNomUrl(1).'</td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
print '</table></form>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
/*
|
||||
* Actions
|
||||
@ -180,6 +160,30 @@ if ($_GET["id"] > 0)
|
||||
}
|
||||
|
||||
print '</div>';
|
||||
|
||||
print '<br>';
|
||||
print '<input type="hidden" name="action" value="addtime">';
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Date").'</td>';
|
||||
print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
|
||||
print '<td align="right">'.$langs->trans("User").'</td>';
|
||||
print "</tr>\n";
|
||||
|
||||
foreach ($tasks as $task_time)
|
||||
{
|
||||
$var=!$var;
|
||||
print "<tr ".$bc[$var].">";
|
||||
print '<td>'.dolibarr_print_date($db->jdate($task_time->task_date),'day').'</td>';
|
||||
print '<td align="right">'.$task_time->task_duration.'</td>';
|
||||
$user->id=$task_time->rowid;
|
||||
$user->nom=$task_time->login;
|
||||
print '<td align="right">'.$user->getNomUrl(1).'</td>';
|
||||
print "</tr>\n";
|
||||
}
|
||||
|
||||
print "</table>";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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='';
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user