Fix: uniformize code

This commit is contained in:
Regis Houssin 2012-03-14 09:40:11 +01:00
parent fdd7b71417
commit 6b54f50dd4

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2012 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
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -31,11 +31,12 @@ require_once(DOL_DOCUMENT_ROOT."/societe/class/address.class.php");
$langs->load("companies"); $langs->load("companies");
$langs->load("commercial"); $langs->load("commercial");
$id = isset($_GET["id"])?$_GET["id"]:''; $id = GETPOST('id','int');
$origin = isset($_GET["origin"])?$_GET["origin"]:''; $action = GETPOST('action','alpha');
$originid = isset($_GET["originid"])?$_GET["originid"]:''; $origin = GETPOST('origin','alpha');
$socid = isset($_REQUEST["socid"])?$_REQUEST["socid"]:''; $originid = GETPOST('originid','int');
if (! $socid && ($_REQUEST["action"] != 'create' && $_REQUEST["action"] != 'add' && $_REQUEST["action"] != 'update')) accessforbidden(); $socid = GETPOST('socid','int');
if (! $socid && ($action != 'create' && $action != 'add' && $action != 'update')) accessforbidden();
// Security check // Security check
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
@ -46,11 +47,11 @@ $result = restrictedArea($user, 'societe', $socid);
* Actions * Actions
*/ */
if ($_POST["action"] == 'add' || $_POST["action"] == 'update') if ($action == 'add' || $action == 'update')
{ {
$address = new Address($db); $address = new Address($db);
$address->socid = $_POST["socid"]; $address->socid = $socid;
$address->label = ($_POST["label"]!=$langs->trans('RequiredField')?$_POST["label"]:''); $address->label = ($_POST["label"]!=$langs->trans('RequiredField')?$_POST["label"]:'');
$address->name = ($_POST["name"]!=$langs->trans('RequiredField')?$_POST["name"]:''); $address->name = ($_POST["name"]!=$langs->trans('RequiredField')?$_POST["name"]:'');
$address->address = $_POST["address"]; $address->address = $_POST["address"];
@ -64,23 +65,28 @@ if ($_POST["action"] == 'add' || $_POST["action"] == 'update')
$address->fax = $_POST["fax"]; $address->fax = $_POST["fax"];
$address->note = $_POST["note"]; $address->note = $_POST["note"];
if ($_POST["action"] == 'add') if ($action == 'add')
{ {
$socid = $_POST["socid"]; $socid = $socid;
$origin = $_POST["origin"]; $origin = $origin;
$originid = $_POST["originid"]; $originid = $originid;
$result = $address->create($socid, $user); $result = $address->create($socid, $user);
if ($result >= 0) if ($result >= 0)
{ {
if ($origin == 'commande') if ($origin == 'commande')
{ {
Header("Location: ../commande/fiche.php?action=editdelivery_adress&socid=".$socid."&id=".$originid); Header("Location: ../commande/contact.php?action=editdelivery_adress&socid=".$socid."&id=".$originid);
exit; exit;
} }
elseif ($origin == 'propal') elseif ($origin == 'propal')
{ {
Header("Location: ../comm/propal.php?action=editdelivery_adress&socid=".$socid."&id=".$originid); Header("Location: ../comm/propal/contact.php?action=editdelivery_adress&socid=".$socid."&id=".$originid);
exit;
}
elseif ($origin == 'shipment')
{
Header("Location: ../expedition/fiche.php?id=".$originid);
exit; exit;
} }
else else
@ -92,11 +98,11 @@ if ($_POST["action"] == 'add' || $_POST["action"] == 'update')
else else
{ {
$mesg = $address->error; $mesg = $address->error;
$_GET["action"]='create'; $action='create';
} }
} }
if ($_POST["action"] == 'update') if ($action == 'update')
{ {
$socid = $_POST["socid"]; $socid = $_POST["socid"];
$origin = $_POST["origin"]; $origin = $_POST["origin"];
@ -107,12 +113,12 @@ if ($_POST["action"] == 'add' || $_POST["action"] == 'update')
{ {
if ($origin == 'commande') if ($origin == 'commande')
{ {
Header("Location: ../commande/fiche.php?id=".$originid); Header("Location: ../commande/contact.php?id=".$originid);
exit; exit;
} }
elseif ($origin == 'propal') elseif ($origin == 'propal')
{ {
Header("Location: ../comm/propal.php?id=".$originid); Header("Location: ../comm/propal/contact.php?id=".$originid);
exit; exit;
} }
elseif ($origin == 'shipment') elseif ($origin == 'shipment')
@ -130,16 +136,16 @@ if ($_POST["action"] == 'add' || $_POST["action"] == 'update')
{ {
$reload = 0; $reload = 0;
$mesg = $address->error; $mesg = $address->error;
$_GET["action"]= "edit"; $actino= "edit";
} }
} }
} }
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->societe->supprimer) if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer)
{ {
$address = new Address($db); $address = new Address($db);
$result = $address->delete($_GET["id"], $socid); $result = $address->delete($id, $socid);
if ($result == 0) if ($result == 0)
{ {
@ -167,7 +173,7 @@ $countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("Se
dol_htmloutput_errors($mesg); dol_htmloutput_errors($mesg);
if ($_GET["action"] == 'create' || $_POST["action"] == 'create') if ($action == 'create')
{ {
if ($user->rights->societe->creer) if ($user->rights->societe->creer)
{ {
@ -221,23 +227,23 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create')
if ($conf->use_javascript_ajax) if ($conf->use_javascript_ajax)
{ {
print "\n".'<script type="text/javascript" language="javascript">'; print "\n".'<script type="text/javascript" language="javascript">';
print 'jQuery(document).ready(function () { print '$(document).ready(function () {
jQuery("#label").focus(function() { $("#label").focus(function() {
hideMessage("label","'.$langs->trans('RequiredField').'"); hideMessage("label","'.$langs->trans('RequiredField').'");
}); });
jQuery("#label").blur(function() { $("#label").blur(function() {
displayMessage("label","'.$langs->trans('RequiredField').'"); displayMessage("label","'.$langs->trans('RequiredField').'");
}); });
jQuery("#name").focus(function() { $("#name").focus(function() {
hideMessage("name","'.$langs->trans('RequiredField').'"); hideMessage("name","'.$langs->trans('RequiredField').'");
}); });
jQuery("#name").blur(function() { $("#name").blur(function() {
displayMessage("name","'.$langs->trans('RequiredField').'"); displayMessage("name","'.$langs->trans('RequiredField').'");
}); });
displayMessage("label","'.$langs->trans('RequiredField').'"); displayMessage("label","'.$langs->trans('RequiredField').'");
displayMessage("name","'.$langs->trans('RequiredField').'"); displayMessage("name","'.$langs->trans('RequiredField').'");
jQuery("#label").css("color","grey"); $("#label").css("color","grey");
jQuery("#name").css("color","grey"); $("#name").css("color","grey");
})'; })';
print '</script>'."\n"; print '</script>'."\n";
} }
@ -289,7 +295,7 @@ if ($_GET["action"] == 'create' || $_POST["action"] == 'create')
} }
} }
elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit') elseif ($action == 'edit')
{ {
/* /*
* Fiche societe en mode edition * Fiche societe en mode edition
@ -314,8 +320,8 @@ elseif ($_GET["action"] == 'edit' || $_POST["action"] == 'edit')
} }
else else
{ {
$address->id = $_POST["id"]; $address->id = $id;
$address->socid = $_POST["socid"]; $address->socid = $socid;
$address->label = $_POST["label"]; $address->label = $_POST["label"];
$address->name = $_POST["name"]; $address->name = $_POST["name"];
$address->address = $_POST["address"]; $address->address = $_POST["address"];
@ -484,7 +490,7 @@ else
* Bouton actions * Bouton actions
*/ */
if ($_GET["action"] == '') if ($action == '')
{ {
print '<div class="tabsAction">'; print '<div class="tabsAction">';
@ -497,8 +503,7 @@ else
} }
$db->close(); $db->close();
llxFooter(); llxFooter();
?> ?>