Fix: Control of input values

This commit is contained in:
Laurent Destailleur 2009-11-02 19:17:58 +00:00
parent 8922b93395
commit 771a8f7dc8

View File

@ -34,6 +34,7 @@ if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande
$projetid=''; $projetid='';
$ref=''; $ref='';
if (isset($_GET["id"])) { $projetid=$_GET["id"]; } if (isset($_GET["id"])) { $projetid=$_GET["id"]; }
else $_GET["id"]=$_POST["id"];
if (isset($_GET["ref"])) { $ref=$_GET["ref"]; } if (isset($_GET["ref"])) { $ref=$_GET["ref"]; }
//var_dump($_REQUEST);exit; //var_dump($_REQUEST);exit;
@ -60,64 +61,82 @@ $result = restrictedArea($user, 'projet', $projetid);
if ($_POST["action"] == 'add' && $user->rights->projet->creer) if ($_POST["action"] == 'add' && $user->rights->projet->creer)
{ {
//print $_POST["socid"]; $error=0;
$project = new Project($db); if (empty($_POST["ref"]))
$project->ref = $_POST["ref"];
$project->title = $_POST["title"];
$project->socid = $_POST["socid"];
$project->user_resp_id = $_POST["officer_project"];
$project->dateo=dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']);
$project->datec=dol_now('tzserver');
$result = $project->create($user);
if ($result > 0)
{ {
Header("Location:fiche.php?id=".$project->id); $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'</div>';
exit; $error++;
}
if (empty($_POST["title"]))
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
$error++;
}
if (! $error)
{
//print $_POST["socid"];
$project = new Project($db);
$project->ref = $_POST["ref"];
$project->title = $_POST["title"];
$project->socid = $_POST["socid"];
$project->user_resp_id = $_POST["officer_project"];
$project->dateo=dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']);
$project->datec=dol_now('tzserver');
$result = $project->create($user);
if ($result > 0)
{
Header("Location:fiche.php?id=".$project->id);
exit;
}
else
{
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans($project->error).'</div>';
$_GET["action"] = 'create';
}
} }
else else
{ {
$langs->load("errors");
$mesg='<div class="error">'.$langs->trans($project->error).'</div>';
$_GET["action"] = 'create'; $_GET["action"] = 'create';
} }
} }
if ($_POST["action"] == 'update' && $user->rights->projet->creer) if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
{ {
if (! $_POST["cancel"]) $error=0;
if (empty($_POST["ref"]))
{ {
$error=0; $error++;
if (empty($_POST["ref"])) //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
{ $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'</div>';
$error++; }
$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet if (empty($_POST["title"]))
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'</div>'; {
} $error++;
if (empty($_POST["title"])) //$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet
{ $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
$error++; }
$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet if (! $error)
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>'; {
} $projet = new Project($db);
if (! $error) $projet->id = $_POST["id"];
{ $projet->ref = $_POST["ref"];
$projet = new Project($db); $projet->title = $_POST["title"];
$projet->id = $_POST["id"]; $projet->socid = $_POST["socid"];
$projet->ref = $_POST["ref"]; $projet->user_resp_id = $_POST["officer_project"];
$projet->title = $_POST["title"]; $projet->dateo = dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']);
$projet->socid = $_POST["socid"];
$projet->user_resp_id = $_POST["officer_project"];
$projet->dateo = dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']);
$projet->update($user); $result=$projet->update($user);
$_GET["id"]=$projet->id; // On retourne sur la fiche projet $_GET["id"]=$projet->id; // On retourne sur la fiche projet
}
} }
else else
{ {
$_GET["id"]=$_POST["id"]; // On retourne sur la fiche projet $_GET["id"]=$_POST["id"];
$_GET['action']='edit';
} }
} }
@ -163,10 +182,10 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
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" value="'.$_POST["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" value="'.$_POST["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>';