From 2840d88415e867924835e8d6d6263acd6f16d4ba Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 17 Mar 2008 04:10:35 +0000 Subject: [PATCH] Fix: Creation of project --- htdocs/fichinter/fiche.php | 7 ++-- htdocs/html.form.class.php | 46 ++++++++++++------------ htdocs/project.class.php | 71 +++++++++++++++++++------------------- htdocs/projet/fiche.php | 28 +++++++-------- 4 files changed, 77 insertions(+), 75 deletions(-) diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index d913058610b..72c8ba7e514 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -41,11 +41,12 @@ $langs->load("interventions"); // Get parameters $fichinterid = isset($_GET["id"])?$_GET["id"]:''; -//Recupere le resultat de la recherche Ajax -//Todo: voir pour le supprimer par la suite -if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && $_POST['socid_id']) + +// If socid provided by ajax company selector +if (! empty($_POST['socid_id'])) { $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; } // Security check diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 17f95ee856e..401175de7f0 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -652,7 +652,7 @@ class Form { print ''; } - print ajax_autocompleter($socid,$htmlname,'/societe/ajaxcompanies.php?filter='.urlencode($filter), ''); + print ajax_autocompleter(($socid?$socid:-1),$htmlname,'/societe/ajaxcompanies.php?filter='.urlencode($filter), ''); print ''; print ''; print ajax_indicator($htmlname,'working'); @@ -661,28 +661,28 @@ class Form } else { - print ''; - } + print ''; + } } else { diff --git a/htdocs/project.class.php b/htdocs/project.class.php index ff2f2a9dc47..e691c88c0e5 100644 --- a/htdocs/project.class.php +++ b/htdocs/project.class.php @@ -42,7 +42,7 @@ class Project extends CommonObject /** * \brief Constructeur de la classe - * \param DB handler accès base de données + * \param DB handler acc�s base de donn�es */ function Project($DB) { @@ -51,37 +51,38 @@ class Project extends CommonObject } /* - * \brief Crée un projet en base - * \param user Id utilisateur qui crée - * \return int <0 si ko, id du projet crée si ok + * \brief Cree un projet en base + * \param user Id utilisateur qui cree + * \return int <0 si ko, id du projet cree si ok */ function create($user) { - if (trim($this->ref)) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, fk_user_resp, dateo)"; - $sql.= " VALUES ('".addslashes($this->ref)."', '".addslashes($this->title)."',"; - $sql.= " ".($this->socid > 0?$this->socid:"null").","; - $sql.= " ".$user->id.","; - $sql.= " ".$this->user_resp_id.", now())"; - - if ($this->db->query($sql) ) - { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet"); - $result = $this->id; - } - else - { - dolibarr_syslog("Project::Create error -2"); - $this->error=$this->db->error(); - $result = -2; - } - } - else + // Check parameters + if (! trim($this->ref)) { $this->error='ErrorFieldsRequired'; dolibarr_syslog("Project::Create error -1 ref null"); - $result = -1; + return -1; + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, fk_user_resp, dateo)"; + $sql.= " VALUES ('".addslashes($this->ref)."', '".addslashes($this->title)."',"; + $sql.= " ".($this->socid > 0?$this->socid:"null").","; + $sql.= " ".$user->id.","; + $sql.= " ".$this->user_resp_id.", now())"; + + dolibarr_syslog("Project::create sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet"); + $result = $this->id; + } + else + { + dolibarr_syslog("Project::Create error -2"); + $this->error=$this->db->error(); + $result = -2; } return $result; @@ -120,7 +121,7 @@ class Project extends CommonObject /* * \brief Charge objet projet depuis la base - * \param rowid id du projet à charger + * \param rowid id du projet � charger */ function fetch($rowid) { @@ -278,7 +279,7 @@ class Project extends CommonObject } } /** - * Renvoie la liste des commande associées au projet + * Renvoie la liste des commande associ�es au projet * * */ @@ -338,9 +339,9 @@ class Project extends CommonObject } /* - * \brief Crée une tache dans le projet - * \param user Id utilisateur qui crée - * \param title titre de la tâche + * \brief Cr�e une tache dans le projet + * \param user Id utilisateur qui cr�e + * \param title titre de la t�che * \param parent tache parente */ function CreateTask($user, $title, $parent = 0) @@ -395,9 +396,9 @@ class Project extends CommonObject /* - * \brief Crée une tache dans le projet - * \param user Id utilisateur qui crée - * \param title titre de la tâche + * \brief Cr�e une tache dans le projet + * \param user Id utilisateur qui cr�e + * \param title titre de la t�che * \param parent tache parente */ function TaskAddTime($user, $task, $time, $date) @@ -476,7 +477,7 @@ class Project extends CommonObject { $tasks = array(); - /* Liste des tâches dans $tasks */ + /* Liste des t�ches dans $tasks */ $sql = "SELECT t.rowid, t.title, t.fk_task_parent, t.duration_effective"; $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as t"; diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index 75baffe6480..6a1b4b888fd 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005-2007 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -34,6 +34,13 @@ require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); $projetid=''; if ($_GET["id"]) { $projetid=$_GET["id"]; } +// If socid provided by ajax company selector +if (! empty($_POST['socid_id'])) +{ + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + if ($projetid == '' && ($_GET['action'] != "create" && $_POST['action'] != "add" && $_POST["action"] != "update" && !$_POST["cancel"])) accessforbidden(); // Security check @@ -47,6 +54,7 @@ $result = restrictedArea($user, 'projet', $projetid); if ($_POST["action"] == 'add' && $user->rights->projet->creer) { + //print $_POST["socid"]; $pro = new Project($db); $pro->socid = $_POST["socid"]; $pro->ref = $_POST["ref"]; @@ -124,28 +132,20 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer) if ($mesg) print $mesg; print '
'; - if ($_REQUEST["socid"]) print ''; + //if ($_REQUEST["socid"]) print ''; print ''; print ''; // Ref - print ''; + print ''; // Label - print ''; + print ''; // Client print ''; // Auteur du projet
'.$langs->trans("Ref").'
'.$langs->trans("Ref").'
'.$langs->trans("Label").'
'.$langs->trans("Label").'
'.$langs->trans("Company").''; -/* if ($_GET["socid"]) - { - $societe = new Societe($db); - $societe->fetch($_GET["socid"]); - print $societe->getNomUrl(1); - } - else - { */ - print $html->select_societes($_REQUEST["socid"],'socid','',1); -// } + //print $_REQUEST["socid"]; + print $html->select_societes($_REQUEST["socid"],'socid','',1); print '