Fix: regression, canvas is broken and societe.class and contact.class are incompatible with callHook function

This commit is contained in:
Regis Houssin 2011-06-30 13:25:32 +00:00
parent 6385641a8e
commit 79880a1aea
3 changed files with 463 additions and 455 deletions

View File

@ -24,7 +24,7 @@
* \file htdocs/contact/fiche.php
* \ingroup societe
* \brief Card of a contact
* \version $Id: fiche.php,v 1.214 2011/06/29 22:29:51 eldy Exp $
* \version $Id: fiche.php,v 1.215 2011/06/30 13:25:32 hregis 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,53 +68,63 @@ 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
*/
// Hook of actions
if (! empty($object->hooks['contactcard']))
// 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'))
{
foreach($object->hooks['contactcard'] as $module)
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
$objcanvas->doActions($id);
if (empty($objcanvas->error) && (empty($objcanvas->errors) || sizeof($objcanvas->errors) == 0))
{
$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 ($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'; }
}
}
// Creation utilisateur depuis contact
if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer)
else
{
// Recuperation contact actuel
$result = $object->fetch($_GET["id"]);
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
if ($result > 0)
// Creation utilisateur depuis contact
if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $user->rights->user->user->creer)
{
$db->begin();
// Creation user
$nuser = new User($db);
$result=$nuser->create_from_contact($object,$_POST["login"]);
// Recuperation contact actuel
$result = $object->fetch($_GET["id"]);
if ($result > 0)
{
$result2=$nuser->setPassword($user,$_POST["password"],0,1,1);
if ($result2)
$db->begin();
// Creation user
$nuser = new User($db);
$result=$nuser->create_from_contact($object,$_POST["login"]);
if ($result > 0)
{
$db->commit();
$result2=$nuser->setPassword($user,$_POST["password"],0,1,1);
if ($result2)
{
$db->commit();
}
else
{
$error=$nuser->error; $errors=$nuser->errors;
$db->rollback();
}
}
else
{
@ -124,131 +134,34 @@ if ($_POST["action"] == 'confirm_create_user' && $_POST["confirm"] == 'yes' && $
}
else
{
$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';
$error=$object->error; $errors=$object->errors;
}
}
if (! $error && $id > 0)
// Cancel
if (GETPOST("cancel") && GETPOST('backtopage'))
{
$db->commit();
if (GETPOST('backtopage')) $url=GETPOST('backtopage');
else $url='fiche.php?id='.$id;
Header("Location: ".$url);
header("Location: ".GETPOST('backtopage'));
exit;
}
else
// Add contact
if (GETPOST("action") == 'add' && $user->rights->societe->contact->creer)
{
$db->rollback();
}
}
$db->begin();
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"];
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_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"];
@ -258,16 +171,108 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->societe
$object->priv = $_POST["priv"];
$object->note = $_POST["note"];
$result = $object->update($_POST["contactid"], $user);
// 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 ($result > 0)
if (! $_POST["name"])
{
$object->old_name='';
$object->old_firstname='';
$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
{
$error=$object->error; $errors=$object->errors;
$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;
}
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;
}
}
}
}
@ -945,5 +950,5 @@ else
$db->close();
llxFooter('$Date: 2011/06/29 22:29:51 $ - $Revision: 1.214 $');
llxFooter('$Date: 2011/06/30 13:25:32 $ - $Revision: 1.215 $');
?>

View File

@ -21,7 +21,7 @@
* \file htdocs/societe/canvas/actions_card_common.class.php
* \ingroup thirdparty
* \brief Fichier de la classe Thirdparty card controller (common)
* \version $Id$
* \version $Id: actions_card_common.class.php,v 1.22 2011/06/30 13:25:32 hregis Exp $
*/
/**
@ -259,7 +259,7 @@ class ActionsCardCommon
$oldsoccanvas = new Canvas($this->db);
$oldsoccanvas->getCanvas('thirdparty','card',$this->object->canvas);
$result=$oldsoccanvas->fetch($socid);
$result=$oldsoccanvas->control->object->fetch($socid);
// To avoid setting code if third party is not concerned. But if it had values, we keep them.
if (empty($this->object->client) && empty($oldsoccanvas->control->object->code_client)) $this->object->code_client='';

View File

@ -26,7 +26,7 @@
* \file htdocs/societe/soc.php
* \ingroup societe
* \brief Third party card page
* \version $Id: soc.php,v 1.112 2011/06/29 22:29:51 eldy Exp $
* \version $Id: soc.php,v 1.113 2011/06/30 13:25:33 hregis Exp $
*/
require("../main.inc.php");
@ -50,17 +50,11 @@ 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"));
@ -79,202 +73,294 @@ else
$result = restrictedArea($user, 'societe', $socid);
}
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('thirdpartycard');
}
$error=0; $errors=array();
$extrafields = new ExtraFields($db);
/*
* Actions
*/
// Hook of actions
if (! empty($object->hooks['thirdpartycard']))
// 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'))
{
foreach($object->hooks['thirdpartycard'] as $module)
// -----------------------------------------
// When used with CANVAS
// -----------------------------------------
$objcanvas->doActions($socid);
if (empty($objcanvas->error) && (empty($objcanvas->errors) || sizeof($objcanvas->errors) == 0))
{
$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"];
if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if ($action=='update') { $objcanvas->action='view'; $action='view'; }
}
else
{
$soc->name = $_POST["nom"];
$soc->nom = $soc->name; // TODO obsolete
$error=$objcanvas->error; $errors=$objcanvas->errors;
if ($action=='add') { $objcanvas->action='create'; $action='create'; }
if ($action=='update') { $objcanvas->action='edit'; $action='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"];
}
else
{
// -----------------------------------------
// When used in standard mode
// -----------------------------------------
$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 ($_POST["getcustomercode"])
{
$soc->typent_id = 8; // TODO predict another method if the field "special" change of rowid
}
else
{
$soc->typent_id = $_POST["typent_id"];
// We defined value code_client
$_POST["code_client"]="Acompleter";
}
$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)
if ($_POST["getsuppliercode"])
{
if (preg_match("/^options_/",$key))
// 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->array_options[$key]=$_POST[$key];
$soc->fetch($socid);
}
}
else if ($canvas) $soc->canvas=$canvas;
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))
if ($_REQUEST["private"] == 1)
{
$langs->load("errors");
$error++; $errors[] = $langs->trans("ErrorBadEMail",$soc->email);
$action = ($action=='add'?'create':'edit');
$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"];
}
if (! empty($soc->url) && ! isValidUrl($soc->url))
else
{
$langs->load("errors");
$error++; $errors[] = $langs->trans("ErrorBadUrl",$soc->url);
$action = ($action=='add'?'create':'edit');
$soc->name = $_POST["nom"];
$soc->nom = $soc->name; // TODO obsolete
}
if ($soc->fournisseur && ! $conf->fournisseur->enabled)
$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)
{
$langs->load("errors");
$error++; $errors[] = $langs->trans("ErrorSupplierModuleNotEnabled");
$action = ($action=='add'?'create':'edit');
$soc->typent_id = 8; // TODO predict another method if the field "special" change of rowid
}
}
if (! $error)
{
if ($action == 'add')
else
{
$db->begin();
$soc->typent_id = $_POST["typent_id"];
}
if (empty($soc->client)) $soc->code_client='';
if (empty($soc->fournisseur)) $soc->code_fournisseur='';
$soc->client = $_POST["client"];
$soc->fournisseur = $_POST["fournisseur"];
$soc->fournisseur_categorie = $_POST["fournisseur_categorie"];
$result = $soc->create($user);
if ($result >= 0)
$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))
{
if ($soc->particulier)
$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)
{
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)
if ($soc->particulier)
{
$error=$contact->error; $errors=$contact->errors;
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;
}
}
### 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 (image_format_supported($_FILES['photo']['name']))
if (GETPOST('deletephoto'))
{
create_exdir($dir);
$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))
{
@ -297,169 +383,86 @@ if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
}
}
}
else
{
$errors[] = "ErrorBadImageFormat";
}
}
### 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";
$file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
if ($file_OK)
{
if (GETPOST('deletephoto'))
if (! $error && ! sizeof($errors))
{
$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);
}
}
Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
exit;
}
else
{
$errors[] = "ErrorBadImageFormat";
$soc->id = $socid;
$action= "edit";
}
}
### 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)
// Delete third party
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer)
{
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();
$result = $soc->delete($socid);
// 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))
if ($result >= 0)
{
$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);
Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$soc->nom."");
exit;
}
else
{
Header ('Location: '.$_SERVER["PHP_SELF"].'?socid='.$soc->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
exit;
$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;
}
}
}
}
@ -1943,5 +1946,5 @@ else
$db->close();
llxFooter('$Date: 2011/06/29 22:29:51 $ - $Revision: 1.112 $');
llxFooter('$Date: 2011/06/30 13:25:33 $ - $Revision: 1.113 $');
?>