Qual: Uniformize code. Actions canvas conflicts with actions hook. So now we always hook to intercept actions. Name of hook must also be unique for each tab.

This commit is contained in:
Laurent Destailleur 2011-06-29 22:29:50 +00:00
parent b6a67885e3
commit 71770c4cfd
5 changed files with 507 additions and 501 deletions

View File

@ -27,7 +27,7 @@
* \file htdocs/comm/propal.php
* \ingroup propale
* \brief Page of commercial proposals card and list
* \version $Id$
* \version $Id: propal.php,v 1.605 2011/06/29 22:29:51 eldy Exp $
*/
require("../main.inc.php");
@ -59,6 +59,11 @@ $mesg=(GETPOST("msg") ? GETPOST("msg") : GETPOST("mesg"));
$year=GETPOST("year");
$month=GETPOST("month");
// Nombre de ligne pour choix de produit/service predefinis
$NBLINES=4;
$object = new Propal($db);
// Security check
$module='propale';
if (isset($socid))
@ -76,15 +81,10 @@ else if (isset($id) && $id > 0)
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, $module, $objectid, $dbtable);
// Nombre de ligne pour choix de produit/service predefinis
$NBLINES=4;
$object = new Propal($db);
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('objectcard');
$object->callHooks('propalcard');
}
@ -93,12 +93,17 @@ if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
/******************************************************************************/
// Hook of thirdparty module
if (! empty($object->hooks['objectcard']))
if (! empty($object->hooks['propalcard']))
{
foreach($object->hooks['objectcard'] as $module)
foreach($object->hooks['propalcard'] as $module)
{
$module->doActions($object);
$mesg = $module->error;
$reshook+=$module->doActions($object);
if (! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0))
{
$error=$module->error; $errors[]=$module->errors;
if ($action=='add') $action='create';
if ($action=='update') $action='edit';
}
}
}
@ -1950,6 +1955,6 @@ else
}
$db->close();
llxFooter('$Date$ - $Revision$');
llxFooter('$Date: 2011/06/29 22:29:51 $ - $Revision: 1.605 $');
?>

View File

@ -26,7 +26,7 @@
* \file htdocs/commande/fiche.php
* \ingroup commande
* \brief Page to show customer order
* \version $Id$
* \version $Id: fiche.php,v 1.520 2011/06/29 22:29:51 eldy Exp $
*/
require("../main.inc.php");
@ -57,19 +57,18 @@ $socid = GETPOST('socid');
$action = GETPOST('action');
$confirm = GETPOST('confirm');
$lineid = GETPOST('lineid');
$mesg = GETPOST('mesg');
$object = new Commande($db);
// Security check
if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,'commande',$id,'');
$mesg=isset($_GET['mesg'])?$_GET['mesg']:'';
$object = new Commande($db);
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('objectcard');
$object->callHooks('ordercard');
}
@ -77,13 +76,18 @@ if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
/* Actions */
/******************************************************************************/
// Hook of thirdparty module
if (! empty($object->hooks['objectcard']))
// Hook of actions
if (! empty($object->hooks['ordercard']))
{
foreach($object->hooks['objectcard'] as $module)
foreach($object->hooks['ordercard'] as $module)
{
$module->doActions($object);
$mesg = $module->error;
$reshook+=$module->doActions($object);
if (! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0))
{
$error=$module->error; $errors[]=$module->errors;
if ($action=='add') $action='create';
if ($action=='update') $action='edit';
}
}
}
@ -2097,5 +2101,5 @@ else
$db->close();
llxFooter('$Date$ - $Revision$');
llxFooter('$Date: 2011/06/29 22:29:51 $ - $Revision: 1.520 $');
?>

View File

@ -26,7 +26,7 @@
* \file htdocs/compta/facture.php
* \ingroup facture
* \brief Page to create/see an invoice
* \version $Id: facture.php,v 1.839 2011/06/29 15:48:02 grandoc Exp $
* \version $Id: facture.php,v 1.840 2011/06/29 22:29:50 eldy Exp $
*/
require('../main.inc.php');
@ -77,7 +77,7 @@ $object=new Facture($db);
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('objectcard');
$object->callHooks('invoicecard');
}
@ -86,13 +86,18 @@ if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
/* Actions */
/******************************************************************************/
// Hook of thirdparty module
if (! empty($object->hooks['objectcard']))
// Hook of actions
if (! empty($object->hooks['invoicecard']))
{
foreach($object->hooks['objectcard'] as $module)
foreach($object->hooks['invoicecard'] as $module)
{
$module->doActions($object);
$mesg = $module->error;
$reshook+=$module->doActions($object);
if (! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0))
{
$error=$module->error; $errors[]=$module->errors;
if ($action=='add') $action='create';
if ($action=='update') $action='edit';
}
}
}
@ -3196,5 +3201,5 @@ else
$db->close();
llxFooter('$Date: 2011/06/29 15:48:02 $ - $Revision: 1.839 $');
llxFooter('$Date: 2011/06/29 22:29:50 $ - $Revision: 1.840 $');
?>

View File

@ -24,7 +24,7 @@
* \file htdocs/contact/fiche.php
* \ingroup societe
* \brief Card of a contact
* \version $Id$
* \version $Id: fiche.php,v 1.214 2011/06/29 22:29:51 eldy Exp $
*/
require("../main.inc.php");
@ -45,11 +45,11 @@ $action = GETPOST('action');
$socid = GETPOST("socid");
$id = GETPOST("id");
$object = new Contact($db);
// Security check
if ($user->societe_id) $socid=$user->societe_id;
$object = new Contact($db);
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
if (!empty($id)) $object->getCanvas($id);
$canvas = (!empty($object->canvas)?$object->canvas:GETPOST("canvas"));
@ -68,63 +68,53 @@ else
$result = restrictedArea($user, 'contact', $id, 'socpeople'); // If we create a contact with no company (shared contacts), no check on write permission
}
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('contactcard');
}
/*
* Actions
*/
// If canvas actions are defined, because on url, or because contact was created with canvas feature on, we use the canvas feature.
// If canvas actions are not defined, we use standard feature.
if (method_exists($objcanvas->control,'doActions'))
// Hook of actions
if (! empty($object->hooks['contactcard']))
{
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
$objcanvas->doActions($id);
if (empty($objcanvas->error) && (empty($objcanvas->errors) || sizeof($objcanvas->errors) == 0))
foreach($object->hooks['contactcard'] as $module)
{
if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if ($action=='update') { $objcanvas->action='view'; $action='view'; }
}
else
{
$error=$objcanvas->error; $errors=$objcanvas->errors;
if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if ($action=='update') { $objcanvas->action='edit'; $action='edit'; }
$reshook+=$module->doActions($object);
if (! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0))
{
$error=$module->error; $errors[]=$module->errors;
if ($action=='add') $action='create';
if ($action=='update') $action='edit';
}
}
}
else
{
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
// Creation utilisateur depuis contact
if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer)
// Creation utilisateur depuis contact
if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer)
{
// Recuperation contact actuel
$result = $object->fetch($_GET["id"]);
if ($result > 0)
{
// Recuperation contact actuel
$result = $object->fetch($_GET["id"]);
$db->begin();
// Creation user
$nuser = new User($db);
$result=$nuser->create_from_contact($object,$_POST["login"]);
if ($result > 0)
{
$db->begin();
// Creation user
$nuser = new User($db);
$result=$nuser->create_from_contact($object,$_POST["login"]);
if ($result > 0)
$result2=$nuser->setPassword($user,$_POST["password"],0,1,1);
if ($result2)
{
$result2=$nuser->setPassword($user,$_POST["password"],0,1,1);
if ($result2)
{
$db->commit();
}
else
{
$error=$nuser->error; $errors=$nuser->errors;
$db->rollback();
}
$db->commit();
}
else
{
@ -134,34 +124,131 @@ else
}
else
{
$error=$object->error; $errors=$object->errors;
$error=$nuser->error; $errors=$nuser->errors;
$db->rollback();
}
}
else
{
$error=$object->error; $errors=$object->errors;
}
}
// Cancel
if (GETPOST("cancel") && GETPOST('backtopage'))
{
header("Location: ".GETPOST('backtopage'));
exit;
}
// Add contact
if (GETPOST("action") == 'add' && $user->rights->societe->contact->creer)
{
$db->begin();
if ($canvas) $object->canvas=$canvas;
$object->socid = $_POST["socid"];
$object->name = $_POST["name"];
$object->firstname = $_POST["firstname"];
$object->civilite_id = $_POST["civilite_id"];
$object->poste = $_POST["poste"];
$object->address = $_POST["address"];
$object->zip = $_POST["zipcode"];
$object->town = $_POST["town"];
$object->fk_pays = $_POST["pays_id"];
$object->fk_departement = $_POST["departement_id"];
$object->email = $_POST["email"];
$object->phone_pro = $_POST["phone_pro"];
$object->phone_perso = $_POST["phone_perso"];
$object->phone_mobile = $_POST["phone_mobile"];
$object->fax = $_POST["fax"];
$object->jabberid = $_POST["jabberid"];
$object->priv = $_POST["priv"];
$object->note = $_POST["note"];
// Note: Correct date should be completed with location to have exact GM time of birth.
$object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]);
$object->birthday_alert = $_POST["birthday_alert"];
if (! $_POST["name"])
{
$error++; $errors[]=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
$_GET["action"] = $_POST["action"] = 'create';
}
if ($_POST["name"])
{
$id = $object->create($user);
if ($id <= 0)
{
$error++; $errors[]=($object->error?array($object->error):$object->errors);
$_GET["action"] = $_POST["action"] = 'create';
}
}
// Cancel
if (GETPOST("cancel") && GETPOST('backtopage'))
if (! $error && $id > 0)
{
header("Location: ".GETPOST('backtopage'));
$db->commit();
if (GETPOST('backtopage')) $url=GETPOST('backtopage');
else $url='fiche.php?id='.$id;
Header("Location: ".$url);
exit;
}
// Add contact
if (GETPOST("action") == 'add' && $user->rights->societe->contact->creer)
else
{
$db->begin();
$db->rollback();
}
}
if ($canvas) $object->canvas=$canvas;
if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes' && $user->rights->societe->contact->supprimer)
{
$result=$object->fetch($_GET["id"]);
$object->old_name = $_POST["old_name"];
$object->old_firstname = $_POST["old_firstname"];
$result = $object->delete();
if ($result > 0)
{
Header("Location: index.php");
exit;
}
else
{
$error=$object->error; $errors[]=$object->errors;
}
}
if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
{
if (empty($_POST["name"]))
{
$error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
$_GET["action"] = $_POST["action"] = 'edit';
}
if (! sizeof($errors))
{
$object->fetch($_POST["contactid"]);
$object->oldcopy=dol_clone($object);
$object->old_name = $_POST["old_name"];
$object->old_firstname = $_POST["old_firstname"];
$object->socid = $_POST["socid"];
$object->name = $_POST["name"];
$object->firstname = $_POST["firstname"];
$object->civilite_id = $_POST["civilite_id"];
$object->poste = $_POST["poste"];
$object->address = $_POST["address"];
$object->zip = $_POST["zipcode"];
$object->town = $_POST["town"];
$object->fk_departement = $_POST["departement_id"];
$object->fk_pays = $_POST["pays_id"];
$object->fk_departement = $_POST["departement_id"];
$object->email = $_POST["email"];
$object->phone_pro = $_POST["phone_pro"];
$object->phone_perso = $_POST["phone_perso"];
@ -171,108 +258,16 @@ else
$object->priv = $_POST["priv"];
$object->note = $_POST["note"];
// Note: Correct date should be completed with location to have exact GM time of birth.
$object->birthday = dol_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]);
$object->birthday_alert = $_POST["birthday_alert"];
$result = $object->update($_POST["contactid"], $user);
if (! $_POST["name"])
{
$error++; $errors[]=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname").' / '.$langs->transnoentities("Label"));
$_GET["action"] = $_POST["action"] = 'create';
}
if ($_POST["name"])
{
$id = $object->create($user);
if ($id <= 0)
{
$error++; $errors[]=($object->error?array($object->error):$object->errors);
$_GET["action"] = $_POST["action"] = 'create';
}
}
if (! $error && $id > 0)
{
$db->commit();
if (GETPOST('backtopage')) $url=GETPOST('backtopage');
else $url='fiche.php?id='.$id;
Header("Location: ".$url);
exit;
}
else
{
$db->rollback();
}
}
if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes' && $user->rights->societe->contact->supprimer)
{
$result=$object->fetch($_GET["id"]);
$object->old_name = $_POST["old_name"];
$object->old_firstname = $_POST["old_firstname"];
$result = $object->delete();
if ($result > 0)
{
Header("Location: index.php");
exit;
$object->old_name='';
$object->old_firstname='';
}
else
{
$error=$object->error; $errors[]=$object->errors;
}
}
if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe->contact->creer)
{
if (empty($_POST["name"]))
{
$error++; $errors=array($langs->trans("ErrorFieldRequired",$langs->transnoentities("Name").' / '.$langs->transnoentities("Label")));
$_GET["action"] = $_POST["action"] = 'edit';
}
if (! sizeof($errors))
{
$object->fetch($_POST["contactid"]);
$object->oldcopy=dol_clone($object);
$object->old_name = $_POST["old_name"];
$object->old_firstname = $_POST["old_firstname"];
$object->socid = $_POST["socid"];
$object->name = $_POST["name"];
$object->firstname = $_POST["firstname"];
$object->civilite_id = $_POST["civilite_id"];
$object->poste = $_POST["poste"];
$object->address = $_POST["address"];
$object->zip = $_POST["zipcode"];
$object->town = $_POST["town"];
$object->fk_departement = $_POST["departement_id"];
$object->fk_pays = $_POST["pays_id"];
$object->email = $_POST["email"];
$object->phone_pro = $_POST["phone_pro"];
$object->phone_perso = $_POST["phone_perso"];
$object->phone_mobile = $_POST["phone_mobile"];
$object->fax = $_POST["fax"];
$object->jabberid = $_POST["jabberid"];
$object->priv = $_POST["priv"];
$object->note = $_POST["note"];
$result = $object->update($_POST["contactid"], $user);
if ($result > 0)
{
$object->old_name='';
$object->old_firstname='';
}
else
{
$error=$object->error; $errors=$object->errors;
}
$error=$object->error; $errors=$object->errors;
}
}
}
@ -950,5 +945,5 @@ else
$db->close();
llxFooter('$Date$ - $Revision$');
llxFooter('$Date: 2011/06/29 22:29:51 $ - $Revision: 1.214 $');
?>

View File

@ -26,7 +26,7 @@
* \file htdocs/societe/soc.php
* \ingroup societe
* \brief Third party card page
* \version $Id: soc.php,v 1.111 2011/06/25 19:55:36 eldy Exp $
* \version $Id: soc.php,v 1.112 2011/06/29 22:29:51 eldy Exp $
*/
require("../main.inc.php");
@ -50,11 +50,17 @@ if ($conf->notification->enabled) $langs->load("mails");
$action = GETPOST('action');
$confirm = GETPOST('confirm');
$error=0; $errors=array();
$extrafields = new ExtraFields($db);
$soc = new Societe($db); // TODO Replace this wit object
$object = new Societe($db);
// Security check
$socid = GETPOST("socid");
if ($user->societe_id) $socid=$user->societe_id;
$soc = new Societe($db);
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
if (!empty($socid)) $soc->getCanvas($socid);
$canvas = (!empty($soc->canvas)?$soc->canvas:GETPOST("canvas"));
@ -73,294 +79,202 @@ else
$result = restrictedArea($user, 'societe', $socid);
}
$error=0; $errors=array();
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('thirdpartycard');
}
$extrafields = new ExtraFields($db);
/*
* Actions
*/
// If canvas actions are defined, because on url, or because contact was created with canvas feature on, we use the canvas feature.
// If canvas actions are not defined, we use standard feature.
if (method_exists($objcanvas->control,'doActions'))
// Hook of actions
if (! empty($object->hooks['thirdpartycard']))
{
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
$objcanvas->doActions($socid);
if (empty($objcanvas->error) && (empty($objcanvas->errors) || sizeof($objcanvas->errors) == 0))
foreach($object->hooks['thirdpartycard'] as $module)
{
if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if ($action=='update') { $objcanvas->action='view'; $action='view'; }
$reshook+=$module->doActions($object);
if (! empty($module->error) || (! empty($module->errors) && sizeof($module->errors) > 0))
{
$error=$module->error; $errors[]=$module->errors;
if ($action=='add') $action='create';
if ($action=='update') $action='edit';
}
}
}
if ($_POST["getcustomercode"])
{
// We defined value code_client
$_POST["code_client"]="Acompleter";
}
if ($_POST["getsuppliercode"])
{
// We defined value code_fournisseur
$_POST["code_fournisseur"]="Acompleter";
}
// Add new third party
if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
&& ($action == 'add' || $action == 'update') && $user->rights->societe->creer)
{
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
if ($action == 'update')
{
$soc->fetch($socid);
}
else if ($canvas) $soc->canvas=$canvas;
if ($_REQUEST["private"] == 1)
{
$soc->particulier = $_REQUEST["private"];
$soc->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
$soc->nom = $soc->name; // TODO obsolete
$soc->nom_particulier = $_POST["nom"];
$soc->prenom = $_POST["prenom"];
$soc->civilite_id = $_POST["civilite_id"];
}
else
{
$error=$objcanvas->error; $errors=$objcanvas->errors;
if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if ($action=='update') { $objcanvas->action='edit'; $action='edit'; }
$soc->name = $_POST["nom"];
$soc->nom = $soc->name; // TODO obsolete
}
}
else
{
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
$soc->address = $_POST["adresse"];
$soc->adresse = $_POST["adresse"]; // TODO obsolete
$soc->zip = $_POST["zipcode"];
$soc->cp = $_POST["zipcode"]; // TODO obsolete
$soc->town = $_POST["town"];
$soc->ville = $_POST["town"]; // TODO obsolete
$soc->pays_id = $_POST["pays_id"];
$soc->departement_id = $_POST["departement_id"];
$soc->tel = $_POST["tel"];
$soc->fax = $_POST["fax"];
$soc->email = trim($_POST["email"]);
$soc->url = trim($_POST["url"]);
$soc->siren = $_POST["idprof1"];
$soc->siret = $_POST["idprof2"];
$soc->ape = $_POST["idprof3"];
$soc->idprof4 = $_POST["idprof4"];
$soc->prefix_comm = $_POST["prefix_comm"];
$soc->code_client = $_POST["code_client"];
$soc->code_fournisseur = $_POST["code_fournisseur"];
$soc->capital = $_POST["capital"];
$soc->gencod = $_POST["gencod"];
if ($_POST["getcustomercode"])
$soc->tva_intra = $_POST["tva_intra"];
$soc->tva_assuj = $_POST["assujtva_value"];
$soc->status = $_POST["status"];
// Local Taxes
$soc->localtax1_assuj = $_POST["localtax1assuj_value"];
$soc->localtax2_assuj = $_POST["localtax2assuj_value"];
$soc->forme_juridique_code = $_POST["forme_juridique_code"];
$soc->effectif_id = $_POST["effectif_id"];
if ($_REQUEST["private"] == 1)
{
// We defined value code_client
$_POST["code_client"]="Acompleter";
$soc->typent_id = 8; // TODO predict another method if the field "special" change of rowid
}
else
{
$soc->typent_id = $_POST["typent_id"];
}
if ($_POST["getsuppliercode"])
$soc->client = $_POST["client"];
$soc->fournisseur = $_POST["fournisseur"];
$soc->fournisseur_categorie = $_POST["fournisseur_categorie"];
$soc->commercial_id = $_POST["commercial_id"];
$soc->default_lang = $_POST["default_lang"];
// Get extra fields
foreach($_POST as $key => $value)
{
// We defined value code_fournisseur
$_POST["code_fournisseur"]="Acompleter";
if (preg_match("/^options_/",$key))
{
$soc->array_options[$key]=$_POST[$key];
}
}
// Add new third party
if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
&& ($action == 'add' || $action == 'update') && $user->rights->societe->creer)
if (GETPOST('deletephoto')) $soc->logo = '';
else if (! empty($_FILES['photo']['name'])) $soc->logo = dol_sanitizeFileName($_FILES['photo']['name']);
// Check parameters
if (empty($_POST["cancel"]))
{
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
if ($action == 'update')
if (! empty($soc->email) && ! isValidEMail($soc->email))
{
$soc->fetch($socid);
$langs->load("errors");
$error++; $errors[] = $langs->trans("ErrorBadEMail",$soc->email);
$action = ($action=='add'?'create':'edit');
}
else if ($canvas) $soc->canvas=$canvas;
if ($_REQUEST["private"] == 1)
if (! empty($soc->url) && ! isValidUrl($soc->url))
{
$soc->particulier = $_REQUEST["private"];
$soc->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
$soc->nom = $soc->name; // TODO obsolete
$soc->nom_particulier = $_POST["nom"];
$soc->prenom = $_POST["prenom"];
$soc->civilite_id = $_POST["civilite_id"];
$langs->load("errors");
$error++; $errors[] = $langs->trans("ErrorBadUrl",$soc->url);
$action = ($action=='add'?'create':'edit');
}
else
if ($soc->fournisseur && ! $conf->fournisseur->enabled)
{
$soc->name = $_POST["nom"];
$soc->nom = $soc->name; // TODO obsolete
$langs->load("errors");
$error++; $errors[] = $langs->trans("ErrorSupplierModuleNotEnabled");
$action = ($action=='add'?'create':'edit');
}
$soc->address = $_POST["adresse"];
$soc->adresse = $_POST["adresse"]; // TODO obsolete
$soc->zip = $_POST["zipcode"];
$soc->cp = $_POST["zipcode"]; // TODO obsolete
$soc->town = $_POST["town"];
$soc->ville = $_POST["town"]; // TODO obsolete
$soc->pays_id = $_POST["pays_id"];
$soc->departement_id = $_POST["departement_id"];
$soc->tel = $_POST["tel"];
$soc->fax = $_POST["fax"];
$soc->email = trim($_POST["email"]);
$soc->url = trim($_POST["url"]);
$soc->siren = $_POST["idprof1"];
$soc->siret = $_POST["idprof2"];
$soc->ape = $_POST["idprof3"];
$soc->idprof4 = $_POST["idprof4"];
$soc->prefix_comm = $_POST["prefix_comm"];
$soc->code_client = $_POST["code_client"];
$soc->code_fournisseur = $_POST["code_fournisseur"];
$soc->capital = $_POST["capital"];
$soc->gencod = $_POST["gencod"];
}
$soc->tva_intra = $_POST["tva_intra"];
$soc->tva_assuj = $_POST["assujtva_value"];
$soc->status = $_POST["status"];
// Local Taxes
$soc->localtax1_assuj = $_POST["localtax1assuj_value"];
$soc->localtax2_assuj = $_POST["localtax2assuj_value"];
$soc->forme_juridique_code = $_POST["forme_juridique_code"];
$soc->effectif_id = $_POST["effectif_id"];
if ($_REQUEST["private"] == 1)
if (! $error)
{
if ($action == 'add')
{
$soc->typent_id = 8; // TODO predict another method if the field "special" change of rowid
}
else
{
$soc->typent_id = $_POST["typent_id"];
}
$db->begin();
$soc->client = $_POST["client"];
$soc->fournisseur = $_POST["fournisseur"];
$soc->fournisseur_categorie = $_POST["fournisseur_categorie"];
if (empty($soc->client)) $soc->code_client='';
if (empty($soc->fournisseur)) $soc->code_fournisseur='';
$soc->commercial_id = $_POST["commercial_id"];
$soc->default_lang = $_POST["default_lang"];
// Get extra fields
foreach($_POST as $key => $value)
{
if (preg_match("/^options_/",$key))
$result = $soc->create($user);
if ($result >= 0)
{
$soc->array_options[$key]=$_POST[$key];
}
}
if (GETPOST('deletephoto')) $soc->logo = '';
else if (! empty($_FILES['photo']['name'])) $soc->logo = dol_sanitizeFileName($_FILES['photo']['name']);
// Check parameters
if (empty($_POST["cancel"]))
{
if (! empty($soc->email) && ! isValidEMail($soc->email))
{
$langs->load("errors");
$error++; $errors[] = $langs->trans("ErrorBadEMail",$soc->email);
$action = ($action=='add'?'create':'edit');
}
if (! empty($soc->url) && ! isValidUrl($soc->url))
{
$langs->load("errors");
$error++; $errors[] = $langs->trans("ErrorBadUrl",$soc->url);
$action = ($action=='add'?'create':'edit');
}
if ($soc->fournisseur && ! $conf->fournisseur->enabled)
{
$langs->load("errors");
$error++; $errors[] = $langs->trans("ErrorSupplierModuleNotEnabled");
$action = ($action=='add'?'create':'edit');
}
}
if (! $error)
{
if ($action == 'add')
{
$db->begin();
if (empty($soc->client)) $soc->code_client='';
if (empty($soc->fournisseur)) $soc->code_fournisseur='';
$result = $soc->create($user);
if ($result >= 0)
if ($soc->particulier)
{
if ($soc->particulier)
dol_syslog("This thirdparty is a personal people",LOG_DEBUG);
$contact=new Contact($db);
$contact->civilite_id = $soc->civilite_id;
$contact->name=$soc->nom_particulier;
$contact->firstname=$soc->prenom;
$contact->address=$soc->address;
$contact->zip=$soc->zip;
$contact->cp=$soc->cp;
$contact->town=$soc->town;
$contact->ville=$soc->ville;
$contact->fk_pays=$soc->fk_pays;
$contact->socid=$soc->id; // fk_soc
$contact->status=1;
$contact->email=$soc->email;
$contact->priv=0;
$result=$contact->create($user);
if (! $result >= 0)
{
dol_syslog("This thirdparty is a personal people",LOG_DEBUG);
$contact=new Contact($db);
$contact->civilite_id = $soc->civilite_id;
$contact->name=$soc->nom_particulier;
$contact->firstname=$soc->prenom;
$contact->address=$soc->address;
$contact->zip=$soc->zip;
$contact->cp=$soc->cp;
$contact->town=$soc->town;
$contact->ville=$soc->ville;
$contact->fk_pays=$soc->fk_pays;
$contact->socid=$soc->id; // fk_soc
$contact->status=1;
$contact->email=$soc->email;
$contact->priv=0;
$result=$contact->create($user);
if (! $result >= 0)
{
$error=$contact->error; $errors=$contact->errors;
}
$error=$contact->error; $errors=$contact->errors;
}
### Gestion du logo de la société
$dir = $conf->societe->dir_output."/".$soc->id."/logos/";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK)
{
if (image_format_supported($_FILES['photo']['name']))
{
create_exdir($dir);
if (@is_dir($dir))
{
$newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
if (! $result > 0)
{
$errors[] = "ErrorFailedToSaveFile";
}
else
{
// Create small thumbs for company (Ratio is near 16/9)
// Used on logon for example
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
// Create mini thumbs for company (Ratio is near 16/9)
// Used on menu or for setup page for example
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
}
}
}
}
### Gestion du logo de la société
}
else
{
$error=$soc->error; $errors=$soc->errors;
}
if ($result >= 0)
{
$db->commit();
$url=$_SERVER["PHP_SELF"]."?socid=".$soc->id;
if (($soc->client == 1 || $soc->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/fiche.php?socid=".$soc->id;
else if ($soc->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/fiche.php?socid=".$soc->id;
Header("Location: ".$url);
exit;
}
else
{
$db->rollback();
$action='create';
}
}
if ($action == 'update')
{
if ($_POST["cancel"])
{
Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
exit;
}
$soc->oldcopy=dol_clone($soc);
// To not set code if third party is not concerned. But if it had values, we keep them.
if (empty($soc->client) && empty($soc->oldcopy->code_client)) $soc->code_client='';
if (empty($soc->fournisseur)&& empty($soc->oldcopy->code_fournisseur)) $soc->code_fournisseur='';
//var_dump($soc);exit;
$result = $soc->update($socid,$user,1,$soc->oldcopy->codeclient_modifiable(),$soc->oldcopy->codefournisseur_modifiable());
if ($result <= 0)
{
$error = $soc->error; $errors = $soc->errors;
}
### Gestion du logo de la société
$dir = $conf->societe->dir_output."/".$soc->id."/logos";
$dir = $conf->societe->dir_output."/".$soc->id."/logos/";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK)
{
if (GETPOST('deletephoto'))
if (image_format_supported($_FILES['photo']['name']))
{
$fileimg=$conf->societe->dir_output.'/'.$soc->id.'/logos/'.$soc->logo;
$dirthumbs=$conf->societe->dir_output.'/'.$soc->id.'/logos/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
}
if (image_format_supported($_FILES['photo']['name']) > 0)
{
dol_mkdir($dir);
create_exdir($dir);
if (@is_dir($dir))
{
@ -383,86 +297,169 @@ else
}
}
}
else
{
$errors[] = "ErrorBadImageFormat";
}
}
### Gestion du logo de la société
if (! $error && ! sizeof($errors))
{
Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
exit;
}
else
{
$soc->id = $socid;
$action= "edit";
}
}
}
}
// Delete third party
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer)
{
$soc->fetch($socid);
$result = $soc->delete($socid);
if ($result >= 0)
{
Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$soc->nom."");
exit;
}
else
{
$langs->load("errors");
$error=$langs->trans($soc->error); $errors = $soc->errors;
$action='';
}
}
/*
* Generate document
*/
if ($action == 'builddoc') // En get ou en post
{
if (is_numeric(GETPOST('model')))
{
$error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
}
else
{
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php');
$soc = new Societe($db);
$soc->fetch($socid);
$soc->fetch_thirdparty();
// Define output language
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$fac->client->default_lang;
if (! empty($newlang))
else
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
$error=$soc->error; $errors=$soc->errors;
}
$result=thirdparty_doc_create($db, $soc->id, '', $_REQUEST['model'], $outputlangs);
if ($result <= 0)
if ($result >= 0)
{
dol_print_error($db,$result);
$db->commit();
$url=$_SERVER["PHP_SELF"]."?socid=".$soc->id;
if (($soc->client == 1 || $soc->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url=DOL_URL_ROOT."/comm/fiche.php?socid=".$soc->id;
else if ($soc->fournisseur == 1) $url=DOL_URL_ROOT."/fourn/fiche.php?socid=".$soc->id;
Header("Location: ".$url);
exit;
}
else
{
Header ('Location: '.$_SERVER["PHP_SELF"].'?socid='.$soc->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
$db->rollback();
$action='create';
}
}
if ($action == 'update')
{
if ($_POST["cancel"])
{
Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
exit;
}
$soc->oldcopy=dol_clone($soc);
// To not set code if third party is not concerned. But if it had values, we keep them.
if (empty($soc->client) && empty($soc->oldcopy->code_client)) $soc->code_client='';
if (empty($soc->fournisseur)&& empty($soc->oldcopy->code_fournisseur)) $soc->code_fournisseur='';
//var_dump($soc);exit;
$result = $soc->update($socid,$user,1,$soc->oldcopy->codeclient_modifiable(),$soc->oldcopy->codefournisseur_modifiable());
if ($result <= 0)
{
$error = $soc->error; $errors = $soc->errors;
}
### Gestion du logo de la société
$dir = $conf->societe->dir_output."/".$soc->id."/logos";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK)
{
if (GETPOST('deletephoto'))
{
$fileimg=$conf->societe->dir_output.'/'.$soc->id.'/logos/'.$soc->logo;
$dirthumbs=$conf->societe->dir_output.'/'.$soc->id.'/logos/thumbs';
dol_delete_file($fileimg);
dol_delete_dir_recursive($dirthumbs);
}
if (image_format_supported($_FILES['photo']['name']) > 0)
{
dol_mkdir($dir);
if (@is_dir($dir))
{
$newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
$result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1);
if (! $result > 0)
{
$errors[] = "ErrorFailedToSaveFile";
}
else
{
// Create small thumbs for company (Ratio is near 16/9)
// Used on logon for example
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
// Create mini thumbs for company (Ratio is near 16/9)
// Used on menu or for setup page for example
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
}
}
}
else
{
$errors[] = "ErrorBadImageFormat";
}
}
### Gestion du logo de la société
if (! $error && ! sizeof($errors))
{
Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
exit;
}
else
{
$soc->id = $socid;
$action= "edit";
}
}
}
}
// Delete third party
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer)
{
$soc->fetch($socid);
$result = $soc->delete($socid);
if ($result >= 0)
{
Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$soc->nom."");
exit;
}
else
{
$langs->load("errors");
$error=$langs->trans($soc->error); $errors = $soc->errors;
$action='';
}
}
/*
* Generate document
*/
if ($action == 'builddoc') // En get ou en post
{
if (is_numeric(GETPOST('model')))
{
$error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
}
else
{
require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php');
$soc = new Societe($db);
$soc->fetch($socid);
$soc->fetch_thirdparty();
// Define output language
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$fac->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$result=thirdparty_doc_create($db, $soc->id, '', $_REQUEST['model'], $outputlangs);
if ($result <= 0)
{
dol_print_error($db,$result);
exit;
}
else
{
Header ('Location: '.$_SERVER["PHP_SELF"].'?socid='.$soc->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
}
}
}
@ -1946,5 +1943,5 @@ else
$db->close();
llxFooter('$Date: 2011/06/25 19:55:36 $ - $Revision: 1.111 $');
llxFooter('$Date: 2011/06/29 22:29:51 $ - $Revision: 1.112 $');
?>