Fix: Creation of project

This commit is contained in:
Laurent Destailleur 2008-03-17 04:10:35 +00:00
parent 30240a8c5c
commit 2840d88415
4 changed files with 77 additions and 75 deletions

View File

@ -41,11 +41,12 @@ $langs->load("interventions");
// Get parameters // Get parameters
$fichinterid = isset($_GET["id"])?$_GET["id"]:''; $fichinterid = isset($_GET["id"])?$_GET["id"]:'';
//Recupere le resultat de la recherche Ajax
//Todo: voir pour le supprimer par la suite // If socid provided by ajax company selector
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && $_POST['socid_id']) if (! empty($_POST['socid_id']))
{ {
$_POST['socid'] = $_POST['socid_id']; $_POST['socid'] = $_POST['socid_id'];
$_REQUEST['socid'] = $_REQUEST['socid_id'];
} }
// Security check // Security check

View File

@ -652,7 +652,7 @@ class Form
{ {
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="'.$obj->nom.'"/>'; print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="'.$obj->nom.'"/>';
} }
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 '</td>'; print '</td>';
print '<td class="nobordernopadding" align="left" width="16">'; print '<td class="nobordernopadding" align="left" width="16">';
print ajax_indicator($htmlname,'working'); print ajax_indicator($htmlname,'working');
@ -661,28 +661,28 @@ class Form
} }
else else
{ {
print '<select class="flat" name="'.$htmlname.'">'; print '<select class="flat" name="'.$htmlname.'">';
if ($showempty) print '<option value="-1">&nbsp;</option>'; if ($showempty) print '<option value="-1">&nbsp;</option>';
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
if ($num) if ($num)
{ {
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
if ($selected > 0 && $selected == $obj->rowid) if ($selected > 0 && $selected == $obj->rowid)
{ {
print '<option value="'.$obj->rowid.'" selected="true">'.$obj->nom.'</option>'; print '<option value="'.$obj->rowid.'" selected="true">'.$obj->nom.'</option>';
} }
else else
{ {
print '<option value="'.$obj->rowid.'">'.$obj->nom.'</option>'; print '<option value="'.$obj->rowid.'">'.$obj->nom.'</option>';
} }
$i++; $i++;
} }
} }
print '</select>'; print '</select>';
} }
} }
else else
{ {

View File

@ -42,7 +42,7 @@ class Project extends CommonObject
/** /**
* \brief Constructeur de la classe * \brief Constructeur de la classe
* \param DB handler accès base de données * \param DB handler acc<EFBFBD>s base de donn<EFBFBD>es
*/ */
function Project($DB) function Project($DB)
{ {
@ -51,37 +51,38 @@ class Project extends CommonObject
} }
/* /*
* \brief Crée un projet en base * \brief Cree un projet en base
* \param user Id utilisateur qui crée * \param user Id utilisateur qui cree
* \return int <0 si ko, id du projet crée si ok * \return int <0 si ko, id du projet cree si ok
*/ */
function create($user) function create($user)
{ {
if (trim($this->ref)) // Check parameters
{ 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
{ {
$this->error='ErrorFieldsRequired'; $this->error='ErrorFieldsRequired';
dolibarr_syslog("Project::Create error -1 ref null"); 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; return $result;
@ -120,7 +121,7 @@ class Project extends CommonObject
/* /*
* \brief Charge objet projet depuis la base * \brief Charge objet projet depuis la base
* \param rowid id du projet à charger * \param rowid id du projet <EFBFBD> charger
*/ */
function fetch($rowid) 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<EFBFBD>es au projet
* *
* *
*/ */
@ -338,9 +339,9 @@ class Project extends CommonObject
} }
/* /*
* \brief Crée une tache dans le projet * \brief Cr<EFBFBD>e une tache dans le projet
* \param user Id utilisateur qui crée * \param user Id utilisateur qui cr<EFBFBD>e
* \param title titre de la tâche * \param title titre de la t<EFBFBD>che
* \param parent tache parente * \param parent tache parente
*/ */
function CreateTask($user, $title, $parent = 0) function CreateTask($user, $title, $parent = 0)
@ -395,9 +396,9 @@ class Project extends CommonObject
/* /*
* \brief Crée une tache dans le projet * \brief Cr<EFBFBD>e une tache dans le projet
* \param user Id utilisateur qui crée * \param user Id utilisateur qui cr<EFBFBD>e
* \param title titre de la tâche * \param title titre de la t<EFBFBD>che
* \param parent tache parente * \param parent tache parente
*/ */
function TaskAddTime($user, $task, $time, $date) function TaskAddTime($user, $task, $time, $date)
@ -476,7 +477,7 @@ class Project extends CommonObject
{ {
$tasks = array(); $tasks = array();
/* Liste des tâches dans $tasks */ /* Liste des t<EFBFBD>ches dans $tasks */
$sql = "SELECT t.rowid, t.title, t.fk_task_parent, t.duration_effective"; $sql = "SELECT t.rowid, t.title, t.fk_task_parent, t.duration_effective";
$sql .= " FROM ".MAIN_DB_PREFIX."projet_task as t"; $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as t";

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2007 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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=''; $projetid='';
if ($_GET["id"]) { $projetid=$_GET["id"]; } 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(); if ($projetid == '' && ($_GET['action'] != "create" && $_POST['action'] != "add" && $_POST["action"] != "update" && !$_POST["cancel"])) accessforbidden();
// Security check // Security check
@ -47,6 +54,7 @@ $result = restrictedArea($user, 'projet', $projetid);
if ($_POST["action"] == 'add' && $user->rights->projet->creer) if ($_POST["action"] == 'add' && $user->rights->projet->creer)
{ {
//print $_POST["socid"];
$pro = new Project($db); $pro = new Project($db);
$pro->socid = $_POST["socid"]; $pro->socid = $_POST["socid"];
$pro->ref = $_POST["ref"]; $pro->ref = $_POST["ref"];
@ -124,28 +132,20 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
if ($mesg) print $mesg; if ($mesg) print $mesg;
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
if ($_REQUEST["socid"]) print '<input type="hidden" value="'.$_REQUEST["socid"].'">'; //if ($_REQUEST["socid"]) print '<input type="hidden" name="socid" value="'.$_REQUEST["socid"].'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
// Ref // Ref
print '<tr><td>'.$langs->trans("Ref").'</td><td><input size="8" type="text" name="ref"></td></tr>'; print '<tr><td>'.$langs->trans("Ref").'</td><td><input size="8" type="text" name="ref" value="'.$_POST["ref"].'"></td></tr>';
// Label // Label
print '<tr><td>'.$langs->trans("Label").'</td><td><input size="30" type="text" name="title"></td></tr>'; print '<tr><td>'.$langs->trans("Label").'</td><td><input size="30" type="text" name="title" value="'.$_POST["title"].'"></td></tr>';
// Client // Client
print '<tr><td>'.$langs->trans("Company").'</td><td>'; print '<tr><td>'.$langs->trans("Company").'</td><td>';
/* if ($_GET["socid"]) //print $_REQUEST["socid"];
{ print $html->select_societes($_REQUEST["socid"],'socid','',1);
$societe = new Societe($db);
$societe->fetch($_GET["socid"]);
print $societe->getNomUrl(1);
}
else
{ */
print $html->select_societes($_REQUEST["socid"],'socid','',1);
// }
print '</td></tr>'; print '</td></tr>';
// Auteur du projet // Auteur du projet