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
$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

View File

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

View File

@ -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<EFBFBD>s base de donn<EFBFBD>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 <EFBFBD> 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<EFBFBD>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<EFBFBD>e une tache dans le projet
* \param user Id utilisateur qui cr<EFBFBD>e
* \param title titre de la t<EFBFBD>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<EFBFBD>e une tache dans le projet
* \param user Id utilisateur qui cr<EFBFBD>e
* \param title titre de la t<EFBFBD>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<EFBFBD>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";

View File

@ -1,6 +1,6 @@
<?php
/* 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>
*
* 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 '<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 '<input type="hidden" name="action" value="add">';
// 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
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
print '<tr><td>'.$langs->trans("Company").'</td><td>';
/* 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 '</td></tr>';
// Auteur du projet