diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index ee623a7d3fc..f0890567b3e 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -104,7 +104,8 @@ class Commande extends CommonObject } - /** \brief Cree la commande depuis une propale existante + /** + * \brief Cree la commande depuis une propale existante * \param user Utilisateur qui cree * \param propale_id id de la propale qui sert de modele */ diff --git a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN index 44fda22015a..5fbbeb28be9 100644 --- a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN +++ b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN @@ -239,6 +239,10 @@ class InterfaceDemo { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } + elseif ($action == 'PROPAL_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } // Contracts elseif ($action == 'CONTRACT_CREATE') diff --git a/htdocs/lib/project.lib.php b/htdocs/lib/project.lib.php index a773923bc42..b6156bd181b 100644 --- a/htdocs/lib/project.lib.php +++ b/htdocs/lib/project.lib.php @@ -35,11 +35,6 @@ function project_prepare_head($object) $head[$h][2] = 'project'; $h++; - $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id; - $head[$h][1] = $langs->trans("ProjectContact"); - $head[$h][2] = 'contact'; - $h++; - $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/fiche.php?id='.$object->id; $head[$h][1] = $langs->trans("Tasks"); $head[$h][2] = 'tasks'; @@ -58,6 +53,11 @@ function project_prepare_head($object) $h++; } + $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id; + $head[$h][1] = $langs->trans("ProjectContact"); + $head[$h][2] = 'contact'; + $h++; + $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id; /*$filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref); include_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php'); diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index f134dfdfa54..abe25de62b7 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -211,9 +211,9 @@ if ($_REQUEST['action'] == 'confirm_reopen' && $_REQUEST['confirm'] == 'yes') if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->rights->projet->supprimer) { $project = new Project($db); - $project->id = $_GET["id"]; + $project->fetch($_GET["id"]); $result=$project->delete($user); - if ($result >= 0) + if ($result > 0) { Header("Location: index.php"); exit; @@ -483,7 +483,7 @@ else } // Close - if ($project->statut != 2 && $user->rights->projet->creer) + if ($project->statut == 1 && $user->rights->projet->creer) { if ($userAccess) { diff --git a/htdocs/projet/project.class.php b/htdocs/projet/project.class.php index 945de0fbefb..ba98207d772 100644 --- a/htdocs/projet/project.class.php +++ b/htdocs/projet/project.class.php @@ -49,7 +49,6 @@ class Project extends CommonObject var $date_end; var $socid; var $user_author_id; //!< Id of project creator. Not defined if shared project. - //var $user_resp_id; //!< Id of project responsible. Not defined if shared project. var $public; //!< Tell if this is a public or private project var $note_private; var $note_public; @@ -350,13 +349,45 @@ class Project extends CommonObject */ function delete($user, $notrigger=0) { + global $conf; + + $this->db->begin(); + $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet"; $sql.= " WHERE rowid=".$this->id; - dol_syslog("Project::delete sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { + // We remove directory + $projectref = dol_sanitizeFileName($this->ref); + if ($conf->projet->dir_output) + { + $dir = $conf->projet->dir_output . "/" . $projectref ; + $file = $conf->projet->dir_output . "/" . $projectref . "/" . $projectref . ".pdf"; + if (file_exists($file)) + { + //project_delete_preview($this->db, $this->id, $this->ref); + + if (!dol_delete_file($file)) + { + $this->error='ErrorFailToDeleteFile'; + $this->db->rollback(); + return 0; + } + } + if (file_exists($dir)) + { + $res=@dol_delete_dir($dir); + if (! $res) + { + $this->error='ErrorFailToDeleteDir'; + $this->db->rollback(); + return 0; + } + } + } + if (! $notrigger) { // Call triggers @@ -366,13 +397,16 @@ class Project extends CommonObject if ($result < 0) { $error++; $this->errors=$interface->errors; } // End call triggers } - + + dol_syslog("Project::delete sql=".$sql, LOG_DEBUG); + $this->db->commit(); return 1; } else { $this->error=$this->db->lasterror(); dol_syslog("Project::delete ".$this->error, LOG_ERR); + $this->db->rollback(); return -1; } } diff --git a/htdocs/projet/tasks/task.class.php b/htdocs/projet/tasks/task.class.php index 9cbb48bea26..74adcf2dacb 100644 --- a/htdocs/projet/tasks/task.class.php +++ b/htdocs/projet/tasks/task.class.php @@ -115,7 +115,7 @@ class Task extends CommonObject $sql.= ", ".$user->id; $sql.= ", ".($this->date_start!=''?$this->db->idate($this->date_start):'null'); $sql.= ", ".($this->date_end!=''?$this->db->idate($this->date_end):'null'); - $sql.= ", ".$this->progress; + $sql.= ", ".($this->progress!=''?$this->progress:0); $sql.= ")"; $this->db->begin(); diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index 1ce7850ae97..326d6d591ed 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -519,7 +519,7 @@ class Propal extends CommonObject * \return int <0 if KO, >=0 if OK * \remarks this->ref can be set or empty. If empty, we will use "(PROV)" */ - function create($user='') + function create($user='', $notrigger=0) { global $langs,$conf,$mysoc; $error=0; @@ -661,12 +661,15 @@ class Propal extends CommonObject $resql=$this->update_price(); if ($resql) { - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + if (! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } $this->db->commit(); dol_syslog("Propal::ass::Create done id=".$this->id); @@ -949,7 +952,7 @@ class Propal extends CommonObject * \param user Objet utilisateur qui valide * \return int <0 si ko, >=0 si ok */ - function valid($user) + function valid($user, $notrigger=0) { global $conf,$langs; @@ -965,12 +968,15 @@ class Propal extends CommonObject { $this->use_webcal=($conf->global->PHPWEBCALENDAR_PROPALSTATUS=='always'?1:0); - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result=$interface->run_triggers('PROPAL_VALIDATE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers + if (! $notrigger) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('PROPAL_VALIDATE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + } $this->db->commit(); return 1; @@ -1562,7 +1568,7 @@ class Propal extends CommonObject * \brief Efface propal * \param user Objet du user qui efface */ - function delete($user) + function delete($user, $notrigger=0) { global $conf; @@ -1602,6 +1608,16 @@ class Propal extends CommonObject } } } + + if (! $notrigger) + { + // Call triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('PROPAL_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // End call triggers + } dol_syslog("Suppression de la proposition $this->id par $user->id", LOG_DEBUG); $this->db->commit();