Skip to content

Commit

Permalink
Fix: wrong entity with multicompany thirdparty sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Jan 10, 2018
1 parent e5c26f8 commit bd1acca
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 65 deletions.
105 changes: 54 additions & 51 deletions htdocs/contact/card.php
Expand Up @@ -2,7 +2,7 @@
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2005-2017 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
Expand Down Expand Up @@ -50,8 +50,8 @@
$mesg=''; $error=0; $errors=array();

$action = (GETPOST('action','alpha') ? GETPOST('action','alpha') : 'view');
$confirm = GETPOST('confirm','alpha');
$backtopage = GETPOST('backtopage','alpha');
$confirm = GETPOST('confirm','alpha');
$backtopage = GETPOST('backtopage','alpha');
$id = GETPOST('id','int');
$socid = GETPOST('socid','int');

Expand Down Expand Up @@ -137,63 +137,64 @@
}


// Confirmation desactivation
if ($action == 'disable')
{
$object->fetch($id);
if ($object->setstatus(0)<0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}
// Confirmation desactivation
if ($action == 'disable')
{
$object->fetch($id);
if ($object->setstatus(0)<0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}

// Confirmation activation
if ($action == 'enable')
{
$object->fetch($id);
if ($object->setstatus(1)<0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}
// Confirmation activation
if ($action == 'enable')
{
$object->fetch($id);
if ($object->setstatus(1)<0)
{
setEventMessages($object->error, $object->errors, 'errors');
}
else
{
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
exit;
}
}

// Add contact
if ($action == 'add' && $user->rights->societe->contact->creer)
{
$db->begin();
// Add contact
if ($action == 'add' && $user->rights->societe->contact->creer)
{
$db->begin();

if ($canvas) $object->canvas=$canvas;

$object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity);
$object->socid = GETPOST("socid",'int');
$object->lastname = GETPOST("lastname");
$object->firstname = GETPOST("firstname");
$object->civility_id = GETPOST("civility_id",'alpha');
$object->civility_id = GETPOST("civility_id",'alpha');
$object->poste = GETPOST("poste");
$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->town = GETPOST("town");
$object->country_id = GETPOST("country_id",'int');
$object->state_id = GETPOST("state_id",'int');
$object->state_id = GETPOST("state_id",'int');
$object->skype = GETPOST("skype");
$object->email = GETPOST("email",'alpha');
$object->phone_pro = GETPOST("phone_pro");
$object->phone_perso = GETPOST("phone_perso");
$object->phone_perso = GETPOST("phone_perso");
$object->phone_mobile = GETPOST("phone_mobile");
$object->fax = GETPOST("fax");
$object->fax = GETPOST("fax");
$object->jabberid = GETPOST("jabberid",'alpha');
$object->no_email = GETPOST("no_email",'int');
$object->priv = GETPOST("priv",'int');
$object->note_public = GETPOST("note_public");
$object->note_public = GETPOST("note_public");
$object->note_private = GETPOST("note_private");
$object->statut = 1; //Defult status to Actif

Expand Down Expand Up @@ -347,26 +348,26 @@
$object->socid = GETPOST("socid",'int');
$object->lastname = GETPOST("lastname");
$object->firstname = GETPOST("firstname");
$object->civility_id = GETPOST("civility_id",'alpha');
$object->civility_id = GETPOST("civility_id",'alpha');
$object->poste = GETPOST("poste");

$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->address = GETPOST("address");
$object->zip = GETPOST("zipcode");
$object->town = GETPOST("town");
$object->state_id = GETPOST("state_id",'int');
$object->state_id = GETPOST("state_id",'int');
$object->fk_departement = GETPOST("state_id",'int'); // For backward compatibility
$object->country_id = GETPOST("country_id",'int');

$object->email = GETPOST("email",'alpha');
$object->skype = GETPOST("skype",'alpha');
$object->phone_pro = GETPOST("phone_pro");
$object->phone_perso = GETPOST("phone_perso");
$object->phone_perso = GETPOST("phone_perso");
$object->phone_mobile = GETPOST("phone_mobile");
$object->fax = GETPOST("fax");
$object->fax = GETPOST("fax");
$object->jabberid = GETPOST("jabberid",'alpha');
$object->no_email = GETPOST("no_email",'int');
$object->priv = GETPOST("priv",'int');
$object->note_public = GETPOST("note_public");
$object->note_public = GETPOST("note_public");
$object->note_private = GETPOST("note_private");

// Fill array 'array_options' with data from add form
Expand Down Expand Up @@ -531,12 +532,14 @@
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
if (! empty($objsoc)) {
print '<input type="hidden" name="entity" value="'.$objsoc->entity.'">';
}

dol_fiche_head($head, 'card', '', 0, '');

print '<table class="border" width="100%">';


// Name
print '<tr><td class="titlefieldcreate fieldrequired"><label for="lastname">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</label></td>';
print '<td><input name="lastname" id="lastname" type="text" class="maxwidth100onsmartphone" maxlength="80" value="'.dol_escape_htmltag(GETPOST("lastname")?GETPOST("lastname"):$object->lastname).'" autofocus="autofocus"></td>';
Expand Down Expand Up @@ -673,7 +676,7 @@
}

// Other attributes
$parameters=array('colspan' => ' colspan="3"','cols'=>3);
$parameters=array('socid' => $socid, 'objsoc' => $objsoc, 'colspan' => ' colspan="3"', 'cols' => 3);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
print $hookmanager->resPrint;
if (empty($reshook) && ! empty($extrafields->attribute_label))
Expand Down
29 changes: 15 additions & 14 deletions htdocs/contact/class/contact.class.php
Expand Up @@ -187,7 +187,7 @@ function create($user)
$sql.= ", statut";
$sql.= ", canvas";
$sql.= ", entity";
$sql.= ",ref_ext";
$sql.= ", ref_ext";
$sql.= ", import_key";
$sql.= ") VALUES (";
$sql.= "'".$this->db->idate($now)."',";
Expand All @@ -199,7 +199,7 @@ function create($user)
$sql.= " ".$this->priv.",";
$sql.= " ".$this->statut.",";
$sql.= " ".(! empty($this->canvas)?"'".$this->db->escape($this->canvas)."'":"null").",";
$sql.= " ".$conf->entity.",";
$sql.= " ".$this->entity.",";
$sql.= "'".$this->db->escape($this->ref_ext)."',";
$sql.= " ".(! empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
$sql.= ")";
Expand Down Expand Up @@ -642,7 +642,7 @@ function fetch($id, $user=0, $ref_ext='')

$langs->load("companies");

$sql = "SELECT c.rowid, c.fk_soc, c.ref_ext, c.civility as civility_id, c.lastname, c.firstname,";
$sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_id, c.lastname, c.firstname,";
$sql.= " c.address, c.statut, c.zip, c.town,";
$sql.= " c.fk_pays as country_id,";
$sql.= " c.fk_departement,";
Expand Down Expand Up @@ -671,41 +671,42 @@ function fetch($id, $user=0, $ref_ext='')
$obj = $this->db->fetch_object($resql);

$this->id = $obj->rowid;
$this->entity = $obj->entity;
$this->ref = $obj->rowid;
$this->ref_ext = $obj->ref_ext;
$this->civility_id = $obj->civility_id;
$this->civility_code = $obj->civility_id;
$this->civility_code = $obj->civility_id;
$this->lastname = $obj->lastname;
$this->firstname = $obj->firstname;
$this->firstname = $obj->firstname;
$this->address = $obj->address;
$this->zip = $obj->zip;
$this->town = $obj->town;

$this->fk_departement = $obj->fk_departement; // deprecated
$this->state_id = $obj->fk_departement;
$this->departement_code = $obj->state_code; // deprecated
$this->state_code = $obj->state_code;
$this->departement_code = $obj->state_code; // deprecated
$this->state_code = $obj->state_code;
$this->departement = $obj->state; // deprecated
$this->state = $obj->state;
$this->state = $obj->state;

$this->country_id = $obj->country_id;
$this->country_code = $obj->country_id?$obj->country_code:'';
$this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';

$this->socid = $obj->fk_soc;
$this->socid = $obj->fk_soc;
$this->socname = $obj->socname;
$this->poste = $obj->poste;
$this->poste = $obj->poste;
$this->statut = $obj->statut;

$this->phone_pro = trim($obj->phone);
$this->phone_pro = trim($obj->phone);
$this->fax = trim($obj->fax);
$this->phone_perso = trim($obj->phone_perso);
$this->phone_mobile = trim($obj->phone_mobile);

$this->email = $obj->email;
$this->email = $obj->email;
$this->jabberid = $obj->jabberid;
$this->skype = $obj->skype;
$this->photo = $obj->photo;
$this->skype = $obj->skype;
$this->photo = $obj->photo;
$this->priv = $obj->priv;
$this->mail = $obj->email;

Expand Down

0 comments on commit bd1acca

Please sign in to comment.