Merge remote-tracking branch 'upstream/develop' into new_branch_14_02_2019

This commit is contained in:
Philippe GRAND 2019-02-14 16:35:04 +01:00
commit da26ff6c89
5 changed files with 9 additions and 1185 deletions

View File

@ -1,492 +0,0 @@
<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/comm/address.php
* \ingroup societe
* \brief Tab address of thirdparty
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/address.class.php';
// Load translation files required by the page
$langs->loadLangs(array('companies', 'commercial'));
$id = GETPOST('id', 'int');
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
$backtopage = GETPOST('backtopage', 'alpha');
$origin = GETPOST('origin', 'alpha');
$originid = GETPOST('originid', 'int');
$socid = GETPOST('socid', 'int');
if (! $socid && ($action != 'create' && $action != 'add' && $action != 'update')) accessforbidden();
// Security check
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'societe', $socid);
$object = new Address($db);
/*
* Actions
*/
// Cancel
if (GETPOST('cancel', 'alpha') && ! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
if ($action == 'add' || $action == 'update')
{
$object->socid = $socid;
$object->label = ($_POST["label"]!=$langs->trans('RequiredField')?$_POST["label"]:'');
$object->name = ($_POST["name"]!=$langs->trans('RequiredField')?$_POST["name"]:'');
$object->address = $_POST["address"];
$object->zip = $_POST["zipcode"];
$object->town = $_POST["town"];
$object->country_id = $_POST["country_id"];
$object->phone = $_POST["phone"];
$object->fax = $_POST["fax"];
$object->note = $_POST["note"];
// Add new address
if ($action == 'add')
{
$result = $object->create($socid, $user);
if ($result >= 0)
{
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
elseif ($origin == 'commande')
{
header("Location: ../commande/contact.php?action=editdelivery_adress&socid=".$socid."&id=".$originid);
exit;
}
elseif ($origin == 'propal')
{
header("Location: ../comm/propal/contact.php?action=editdelivery_adress&socid=".$socid."&id=".$originid);
exit;
}
elseif ($origin == 'shipment')
{
header("Location: ../expedition/card.php?id=".$originid);
exit;
}
else
{
header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid);
exit;
}
}
else
{
setEventMessages($object->error, $object->errors, 'errors');
$action='create';
}
}
// Update address
elseif ($action == 'update')
{
$result = $object->update($id, $socid, $user);
if ($result >= 0)
{
if (! empty($backtopage))
{
header("Location: ".$backtopage);
exit;
}
elseif ($origin == 'commande')
{
header("Location: ../commande/contact.php?id=".$originid);
exit;
}
elseif ($origin == 'propal')
{
header("Location: ../comm/propal/contact.php?id=".$originid);
exit;
}
elseif ($origin == 'shipment')
{
header("Location: ../expedition/card.php?id=".$originid);
exit;
}
else
{
header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid);
exit;
}
}
else
{
$reload = 0;
setEventMessages($object->error, $object->errors, 'errors');
$action= "edit";
}
}
}
elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->societe->supprimer)
{
$result = $object->delete($id, $socid);
if ($result == 0)
{
header("Location: ".$_SERVER['PHP_SELF']."?socid=".$socid);
exit ;
}
else
{
$reload = 0;
$action='';
}
}
/**
*
*
*/
llxHeader();
$form = new Form($db);
$formcompany = new FormCompany($db);
$countrynotdefined=$langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
if ($action == 'create')
{
if ($user->rights->societe->creer)
{
/*
* Creation
*/
if ($_POST["label"] && $_POST["name"])
{
$object->socid = $socid;
$object->label = $_POST["label"];
$object->name = $_POST["name"];
$object->address = $_POST["address"];
$object->zip = $_POST["zipcode"];
$object->town = $_POST["town"];
$object->phone = $_POST["phone"];
$object->fax = $_POST["fax"];
$object->note = $_POST["note"];
}
// On positionne country_id, country_code and label of the chosen country
$object->country_id = (GETPOST('country_id', 'int') ? GETPOST('country_id', 'int') : $mysoc->country_id);
if ($object->country_id)
{
$tmparray=getCountry($object->country_id, 'all');
$object->country_code = $tmparray['code'];
$object->country = $tmparray['label'];
}
print load_fiche_titre($langs->trans("AddAddress"));
print "<br>\n";
// If javascript enabled, we add interactivity on mandatory fields
if ($conf->use_javascript_ajax)
{
print "\n".'<script type="text/javascript" language="javascript">';
print '$(document).ready(function () {
$("#label").focus(function() {
hideMessage("label","'.$langs->trans('RequiredField').'");
});
$("#label").blur(function() {
displayMessage("label","'.$langs->trans('RequiredField').'");
});
$("#name").focus(function() {
hideMessage("name","'.$langs->trans('RequiredField').'");
});
$("#name").blur(function() {
displayMessage("name","'.$langs->trans('RequiredField').'");
});
displayMessage("label","'.$langs->trans('RequiredField').'");
displayMessage("name","'.$langs->trans('RequiredField').'");
$("#label").css("color","grey");
$("#name").css("color","grey");
})';
print '</script>'."\n";
}
print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" name="formsoc">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'"/>';
print '<input type="hidden" name="socid" value="'.$socid.'"/>';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'"/>';
print '<input type="hidden" name="origin" value="'.$origin.'"/>';
print '<input type="hidden" name="originid" value="'.$originid.'"/>';
print '<input type="hidden" name="action" value="add"/>';
print '<table class="border" width="100%">';
print '<tr><td class="fieldrequired">'.$langs->trans('Label').'</td><td><input type="text" size="30" name="label" id="label" value="'.($object->label?$object->label:$langs->trans('RequiredField')).'"></td></tr>';
print '<tr><td class="fieldrequired">'.$langs->trans('Name').'</td><td><input type="text" size="30" name="name" id="name" value="'.($object->name?$object->name:$langs->trans('RequiredField')).'"></td></tr>';
print '<tr><td class="tdtop">'.$langs->trans('Address').'</td><td colspan="3"><textarea name="address" class="quatrevingtpercent" rows="3" wrap="soft">';
print $object->address;
print '</textarea></td></tr>';
// Zip
print '<tr><td>'.$langs->trans('Zip').'</td><td>';
print $formcompany->select_ziptown($object->zip, 'zipcode', array('town','selectcountry_id'), 6);
print '</td></tr>';
// Town
print '<tr><td>'.$langs->trans('Town').'</td><td>';
print $formcompany->select_ziptown($object->town, 'town', array('zipcode','selectcountry_id'));
print '</td></tr>';
print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
print $form->select_country($object->country_id, 'selectcountry_id');
print '</td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="phone" value="'.$object->phone.'"></td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td><input type="text" name="fax" value="'.$object->fax.'"></td></tr>';
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3"><textarea name="note" cols="40" rows="6" wrap="soft">';
print $object->note;
print '</textarea></td></tr>';
print '</table>'."\n";
print '<br><div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans('Add').'">';
if (! empty($backtopage))
{
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
}
print '</div>'."\n";
print '</form>'."\n";
}
}
elseif ($action == 'edit')
{
/*
* Fiche societe en mode edition
*/
$societe=new Societe($db);
$societe->fetch($socid);
$head = societe_prepare_head($societe);
dol_fiche_head($head, 'card', $societe->name);
print load_fiche_titre($langs->trans("EditAddress"));
print "<br>\n";
if ($socid)
{
if ($reload || ! $_POST["name"])
{
$object->socid = $socid;
$object->fetch_address($id);
}
else
{
$object->id = $id;
$object->socid = $socid;
$object->label = $_POST["label"];
$object->name = $_POST["name"];
$object->address = $_POST["address"];
$object->zip = $_POST["zipcode"];
$object->town = $_POST["town"];
$object->country_id = $_POST["country_id"]?$_POST["country_id"]:$mysoc->country_id;
$object->phone = $_POST["phone"];
$object->fax = $_POST["fax"];
$object->note = $_POST["note"];
// On positionne country_id, country_code and label of the chosen country
if ($object->country_id)
{
$tmparray=getCountry($object->country_id, 'all');
$object->country_code = $tmparray['code'];
$object->country = $tmparray['label'];
}
}
print '<form action="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'" method="POST" name="formsoc">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'"/>';
print '<input type="hidden" name="action" value="update"/>';
print '<input type="hidden" name="socid" value="'.$object->socid.'"/>';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'"/>';
print '<input type="hidden" name="origin" value="'.$origin.'"/>';
print '<input type="hidden" name="originid" value="'.$originid.'"/>';
print '<input type="hidden" name="id" value="'.$object->id.'"/>';
print '<table class="border" width="100%">';
print '<tr><td>'.$langs->trans('AddressLabel').'</td><td colspan="3"><input type="text" size="40" name="label" value="'.$object->label.'"></td></tr>';
print '<tr><td>'.$langs->trans('Name').'</td><td colspan="3"><input type="text" size="40" name="name" value="'.$object->name.'"></td></tr>';
print '<tr><td class="tdtop">'.$langs->trans('Address').'</td><td colspan="3"><textarea name="address" class="quatrevingtpercent" rows="3" wrap="soft">';
print $object->address;
print '</textarea></td></tr>';
// Zip
print '<tr><td>'.$langs->trans('Zip').'</td><td>';
print $formcompany->select_ziptown($object->zip, 'zipcode', array('town','selectcountry_id'), 6);
print '</td></tr>';
// Town
print '<tr><td>'.$langs->trans('Town').'</td><td>';
print $formcompany->select_ziptown($object->town, 'town', array('zipcode','selectcountry_id'));
print '</td></tr>';
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">';
print $form->select_country($object->country_id, 'country_id');
print '</td></tr>';
print '<tr><td>'.$langs->trans('Phone').'</td><td><input type="text" name="phone" value="'.$object->phone.'"></td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td><input type="text" name="fax" value="'.$object->fax.'"></td></tr>';
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3"><textarea name="note" cols="40" rows="6" wrap="soft">';
print $object->note;
print '</textarea></td></tr>';
print '</table><br>';
print '<div class="center">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>';
print '</form>';
}
}
else
{
/*
* Fiche societe en mode visu
*/
$result=$object->fetch_lines($socid);
if ($result < 0)
{
dol_print_error($db, $object->error);
exit;
}
$societe=new Societe($db);
$societe->fetch($object->socid);
$head = societe_prepare_head($societe);
dol_fiche_head($head, 'customer', $societe->name);
// Confirmation delete
if ($action == 'delete')
{
print $form->formconfirm($_SERVER['PHP_SELF']."?socid=".$object->socid."&amp;id=".$id, $langs->trans("DeleteAddress"), $langs->trans("ConfirmDeleteAddress"), "confirm_delete");
}
$nblines = count($object->lines);
if ($nblines)
{
for ($i = 0 ; $i < $nblines ; $i++)
{
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans('AddressLabel').'</td><td colspan="3">'.$object->lines[$i]->label.'</td>';
print '<td valign="top" colspan="2" width="50%" rowspan="6">'.$langs->trans('Note').' :<br>'.nl2br($object->lines[$i]->note).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans('Name').'</td><td colspan="3">'.$object->lines[$i]->name.'</td></tr>';
print "<tr><td valign=\"top\">".$langs->trans('Address')."</td><td colspan=\"3\">".nl2br($object->lines[$i]->address)."</td></tr>";
print '<tr><td width="25%">'.$langs->trans('Zip').'</td><td width="25%">'.$object->lines[$i]->zip."</td></tr>";
print '<tr><td width="25%">'.$langs->trans('Town').'</td><td width="25%">'.$object->lines[$i]->town."</td></tr>";
print '<tr><td>'.$langs->trans('Country').'</td><td colspan="3">'.$object->lines[$i]->country.'</td>';
print '<tr><td>'.$langs->trans('Phone').'</td><td>'.dol_print_phone($object->lines[$i]->phone, $object->lines[$i]->country_code, 0, $object->socid, 'AC_TEL').'</td></tr>';
print '<tr><td>'.$langs->trans('Fax').'</td><td>'.dol_print_phone($object->lines[$i]->fax, $object->lines[$i]->country_code, 0, $object->socid, 'AC_FAX').'</td></tr>';
print '</td></tr>';
print '</table>';
/*
*
*/
print '<div class="tabsAction">';
if ($user->rights->societe->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&amp;id='.$object->lines[$i]->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>';
}
if ($user->rights->societe->supprimer)
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&amp;id='.$object->lines[$i]->id.'&amp;action=delete">'.$langs->trans("Delete").'</a></div>';
}
print '</div>';
print '<br>';
}
}
else
{
print $langs->trans("None");
}
print '</div>';
/*
* Bouton actions
*/
if ($action == '')
{
print '<div class="tabsAction">';
if ($user->rights->societe->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&amp;action=create">'.$langs->trans("Add").'</a></div>';
}
print '</div>';
}
}
// End of page
llxFooter();
$db->close();

View File

@ -956,52 +956,6 @@ class FormOther
return $out;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
/**
* Show form to select address
*
* @param int $page Page
* @param string $selected Id condition pre-selectionne
* @param int $socid Id of third party
* @param string $htmlname Nom du formulaire select
* @param string $origin Origine de l'appel pour pouvoir creer un retour
* @param int $originid Id de l'origine
* @return void
*/
function form_address($page, $selected, $socid, $htmlname = 'address_id', $origin = '', $originid = '')
{
// phpcs:enable
global $langs,$conf;
global $form;
if ($htmlname != "none")
{
print '<form method="post" action="'.$page.'">';
print '<input type="hidden" name="action" value="setaddress">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$form->select_address($selected, $socid, $htmlname, 1);
print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
$langs->load("companies");
print ' &nbsp; <a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$socid.'&action=create&origin='.$origin.'&originid='.$originid.'>'.$langs->trans("AddAddress").'</a>';
print '</form>';
}
else
{
if ($selected)
{
require_once DOL_DOCUMENT_ROOT .'/societe/class/address.class.php';
$address=new Address($this->db);
$result=$address->fetch_address($selected);
print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>';
}
else
{
print "&nbsp;";
}
}
}
/**
* Get array with HTML tabs with boxes of a particular area including personalized choices of user.

View File

@ -1166,97 +1166,6 @@ function show_contacts($conf, $langs, $db, $object, $backtopage = '')
return $i;
}
/**
* Show html area for list of addresses
*
* @param Conf $conf Object conf
* @param Translate $langs Object langs
* @param DoliDB $db Database handler
* @param Societe $object Third party object
* @param string $backtopage Url to go once address is created
* @return int
*/
function show_addresses($conf, $langs, $db, $object, $backtopage = '')
{
global $user;
require_once DOL_DOCUMENT_ROOT.'/societe/class/address.class.php';
$addressstatic = new Address($db);
$num = $addressstatic->fetch_lines($object->id);
$newcardbutton='';
if ($user->rights->societe->creer)
{
$newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/address.php?socid='.$object->id.'&amp;action=create&amp;backtopage='.urlencode($backtopage).'"><span class="valignmiddle">'.$langs->trans("AddAddress").'</span>';
$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
$newcardbutton.= '</a>';
}
print "\n";
print load_fiche_titre($langs->trans("AddressesForCompany"), $newcardbutton, '');
print "\n".'<table class="noborder" width="100%">'."\n";
print '<tr class="liste_titre"><td>'.$langs->trans("Label").'</td>';
print '<td>'.$langs->trans("CompanyName").'</td>';
print '<td>'.$langs->trans("Town").'</td>';
print '<td>'.$langs->trans("Country").'</td>';
print '<td>'.$langs->trans("Phone").'</td>';
print '<td>'.$langs->trans("Fax").'</td>';
print "<td>&nbsp;</td>";
print "</tr>";
if ($num > 0)
{
foreach ($addressstatic->lines as $address)
{
print '<tr class="oddeven">';
print '<td>';
$addressstatic->id = $address->id;
$addressstatic->label = $address->label;
print $addressstatic->getNomUrl(1);
print '</td>';
print '<td>'.$address->name.'</td>';
print '<td>'.$address->town.'</td>';
$img=picto_from_langcode($address->country_code);
print '<td>'.($img?$img.' ':'').$address->country.'</td>';
// Lien click to dial
print '<td>';
print dol_print_phone($address->phone, $address->country_code, $address->id, $object->id, 'AC_TEL');
print '</td>';
print '<td>';
print dol_print_phone($address->fax, $address->country_code, $address->id, $object->id, 'AC_FAX');
print '</td>';
if ($user->rights->societe->creer)
{
print '<td align="right">';
print '<a href="'.DOL_URL_ROOT.'/comm/address.php?action=edit&amp;id='.$address->id.'&amp;socid='.$object->id.'&amp;backtopage='.urlencode($backtopage).'">';
print img_edit();
print '</a></td>';
}
print "</tr>\n";
}
}
//else
//{
//print '<tr class="oddeven">';
//print '<td>'.$langs->trans("NoAddressYetDefined").'</td>';
//print "</tr>\n";
//}
print "\n</table>\n";
print "<br>\n";
return $num;
}
/**
* Show html area with actions to do

View File

@ -1,553 +0,0 @@
<?php
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/societe/class/address.class.php
* \ingroup societe
* \brief File of class to manage addresses. This class is deprecated.
*/
/**
* Class to manage addresses
*
* @deprecated This class is dedicated to a not supported and deprecated feature.
*/
class Address
{
protected $db;
/**
* @var int ID
*/
public $id;
public $type;
/**
* @var string Address label
*/
public $label;
public $socid;
public $name;
/**
* @var string Address
*/
public $address;
public $zip;
public $town;
public $country_id;
public $country_code;
public $phone;
public $fax;
public $note;
/**
* Adresses liees a la societe
* @var array
*/
public $lines;
/**
* Constructor
*
* @param DoliDB $db Database handler
* @deprecated
*/
function __construct($db)
{
$this->db = $db;
}
/**
* Create address into database
*
* @param int $socid Company socid
* @param User $user Object user making creation
* @return int 0 if OK, < 0 if KO
*/
function create($socid, $user = '')
{
global $langs,$conf;
// Nettoyage parametres
$this->name = trim($this->name);
$this->label = trim($this->label);
dol_syslog(get_class($this)."::create label=".$this->label);
$this->db->begin();
$result = $this->verify();
if ($result >= 0)
{
$now=dol_now();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_address (label, fk_soc, name, datec, fk_user_creat) ";
$sql .= " VALUES ('".$this->db->escape($this->label)."', '".$socid."', '".$this->db->escape($this->name)."', '".$this->db->idate($now)."', '".$user->id."')";
$result=$this->db->query($sql);
if ($result)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_address");
$ret = $this->update($this->id, $socid, $user);
if ($ret >= 0)
{
dol_syslog(get_class($this)."::create success id=".$this->id);
$this->db->commit();
return 0;
}
else
{
dol_syslog(get_class($this)."::create echec update");
$this->db->rollback();
return -3;
}
}
else
{
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$this->error=$langs->trans("ErrorCompanyNameAlreadyExists", $this->name);
}
$this->db->rollback();
return -2;
}
}
else
{
$this->db->rollback();
dol_syslog(get_class($this)."::create echec verify sql=$sql");
return -1;
}
}
/**
* Verification lors de la modification de l'adresse
*
* @return int 0 if OK, <0 if KO
*/
function verify()
{
$this->label = trim($this->label);
$this->name = trim($this->name);
$result = 0;
if (!$this->name || !$this->label)
{
$this->error = "The name of company and the label can not be empty.\n";
$result = -2;
}
return $result;
}
/**
* Mise a jour des parametres de l'adresse
*
* @param int $id id address
* @param int $socid id third party
* @param User $user Utilisateur qui demande la mise a jour
* @return int <0 if KO, >=0 if OK
*/
function update($id, $socid, $user = '')
{
global $langs;
// Clean parameters
$this->fk_soc = $socid;
$this->label = trim($this->label);
$this->name = trim($this->name);
$this->address = trim($this->address);
$this->zip = trim($this->zip);
$this->town = trim($this->town);
$this->country_id = trim($this->country_id);
$this->phone = trim($this->phone);
$this->phone = preg_replace("/\s/", "", $this->phone);
$this->phone = preg_replace("/\./", "", $this->phone);
$this->fax = trim($this->fax);
$this->fax = preg_replace("/\s/", "", $this->fax);
$this->fax = preg_replace("/\./", "", $this->fax);
$this->note = trim($this->note);
$result = $this->verify(); // Verifie que name et label obligatoire
if ($result >= 0)
{
dol_syslog(get_class($this)."::Update verify ok");
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."societe_address";
$sql.= " SET label = '" . $this->db->escape($this->label) ."'"; // Champ obligatoire
$sql.= ", name = '" . $this->db->escape($this->name) ."'"; // Champ obligatoire
$sql.= ", address = ".($this->address?"'".$this->db->escape($this->address)."'":"null");
$sql.= ", zip = ".($this->zip?"'".$this->db->escape($this->zip)."'":"null");
$sql.= ", town = ".($this->town?"'".$this->db->escape($this->town)."'":"null");
$sql.= ", fk_pays = '" . ($this->country_id?$this->db->escape($this->country_id):'0') ."'";
$sql.= ", note = ".($this->note?"'".$this->db->escape($this->note)."'":"null");
$sql.= ", phone = ".($this->phone?"'".$this->db->escape($this->phone)."'":"null");
$sql.= ", fax = ".($this->fax?"'".$this->db->escape($this->fax)."'":"null");
if ($user) $sql .= ",fk_user_modif = '".$user->id."'";
$sql .= " WHERE fk_soc = '" . $socid ."' AND rowid = '" . $this->db->escape($id) ."'";
dol_syslog(get_class($this)."::Update", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
dol_syslog(get_class($this)."::Update success");
$this->db->commit();
return 1;
}
else
{
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
{
$this->error=$langs->trans("ErrorDuplicateField", $this->name);
$result=-1;
}
else
{
$this->error=$this->db->lasterror();
$result=-2;
}
$this->db->rollback();
return $result;
}
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
/**
* Charge depuis la base toutes les adresses d'une societe
*
* @param int $socid Id de la societe a charger en memoire
* @param User $user Objet de l'utilisateur
* @return int >0 si ok, <0 si ko
*/
function fetch_lines($socid, $user = null)
{
// phpcs:enable
global $langs, $conf;
$sql = 'SELECT rowid, nom as name, client, fournisseur';
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe';
$sql .= ' WHERE rowid = '.$socid;
$resqlsoc=$this->db->query($sql);
if ($resqlsoc)
{
if ($this->db->num_rows($resqlsoc))
{
$obj = $this->db->fetch_object($resqlsoc);
$this->socname = $obj->name;
$this->socid = $obj->rowid;
$this->id = $obj->rowid;
$this->client = $obj->client;
$this->fournisseur = $obj->fournisseur;
}
$this->db->free($resqlsoc);
$this->lines = array();
// Adresses liees a la societe
if ($this->socid)
{
$sql = 'SELECT a.rowid as id, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification, a.fk_soc';
$sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax';
$sql .= ', c.code as country_code, c.label as country';
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid';
$sql .= ' WHERE a.fk_soc = '.$this->socid;
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$objp = $this->db->fetch_object($resql);
$line = new AddressLine($this->db);
$line->id = $objp->id;
$line->date_creation = $this->db->jdate($objp->date_creation);
$line->date_modification = $this->db->jdate($objp->date_modification);
$line->label = $objp->label;
$line->name = $objp->name;
$line->address = $objp->address;
$line->zip = $objp->zip;
$line->town = $objp->town;
$line->country_id = $objp->country_id;
$line->country_code = $objp->country_id?$objp->country_code:'';
$line->country = $objp->country_id?($langs->trans('Country'.$objp->country_code)!='Country'.$objp->country_code?$langs->trans('Country'.$objp->country_code):$objp->country):'';
$line->phone = $objp->phone;
$line->fax = $objp->fax;
$line->note = $objp->note;
$this->lines[$i] = $line;
$i++;
}
$this->db->free($resql);
return $num;
}
else
{
dol_syslog(get_class($this).'::Fetch Erreur: aucune adresse', LOG_ERR);
return 0;
}
}
else
{
dol_syslog(get_class($this).'::Fetch Erreur: societe inconnue', LOG_ERR);
return -1;
}
}
else
{
$this->error=$this->db->error();
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
/**
* Charge depuis la base l'objet adresse
*
* @param int $id Id de l'adresse a charger en memoire
* @param User $user Objet de l'utilisateur
* @return int >0 si ok, <0 si ko
*/
function fetch_address($id, $user = null)
{
// phpcs:enable
global $langs;
global $conf;
$sql = 'SELECT a.rowid, a.fk_soc, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification';
$sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax';
$sql .= ', c.code as country_code, c.label as country';
$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid';
$sql .= ' WHERE a.rowid = '.$id;
$resql=$this->db->query($sql);
if ($resql)
{
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->socid = $obj->fk_soc;
$this->date_modification = $this->db->jdate($obj->date_modification);
$this->date_creation = $this->db->jdate($obj->date_creation);
$this->label = $obj->label;
$this->name = $obj->name;
$this->address = $obj->address;
$this->zip = $obj->zip;
$this->town = $obj->town;
$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->trans('Country'.$obj->country_code):$obj->country):'';
$this->phone = $obj->phone;
$this->fax = $obj->fax;
$this->note = $obj->note;
$result = 1;
}
else
{
dol_syslog('Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql);
$this->error='Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql;
$result = -2;
}
$this->db->free($resql);
}
else
{
dol_syslog('Erreur Societe::Fetch echec', LOG_DEBUG);
dol_syslog('Erreur Societe::Fetch '.$this->db->error());
$this->error=$this->db->error();
$result = -3;
}
return $result;
}
/**
* Suppression d'une adresse
*
* @param int $id id de la societe a supprimer
* @param int $socid id third party
* @return <0 KO >0 OK
*/
function delete($id, $socid)
{
dol_syslog("Address::Delete");
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_address";
$sql.= " WHERE rowid = ".$id;
$sql.= " AND fk_soc = ".$socid;
$result = $this->db->query($sql);
if (!$result) {
return -1;
}
return 1;
}
/**
* Return name of address with link (and eventually picto)
* Use $this->id, $this->label, $this->socid
*
* @param int $withpicto Include picto with link
* @param string $option Where the link point to
* @return string String with URL
*/
function getNomUrl($withpicto = 0, $option = '')
{
global $langs;
$result='';
$label = $langs->trans("ShowAddress").': '.$this->label;
$link = '<a href="'.DOL_URL_ROOT.'/comm/address.php?id='.$this->id.'&socid='.$this->socid.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend='</a>';
if ($withpicto) $result.=($link.img_object($langs->trans("ShowAddress").': '.$this->label, 'address', 'class="classfortooltip"').$linkend.' ');
$result.=$link.$this->label.$linkend;
return $result;
}
/**
* Charge les informations d'ordre info dans l'objet societe
*
* @param int $id id de la societe a charger
* @return void
*/
function info($id)
{
$sql = "SELECT s.rowid, s.nom as name, datec as date_creation, tms as date_modification,";
$sql.= " fk_user_creat, fk_user_modif";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
$sql.= " WHERE s.rowid = ".$id;
$result=$this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
if ($obj->fk_user_creat) {
$cuser = new User($this->db);
$cuser->fetch($obj->fk_user_creat);
$this->user_creation = $cuser;
}
if ($obj->fk_user_modif) {
$muser = new User($this->db);
$muser->fetch($obj->fk_user_modif);
$this->user_modification = $muser;
}
$this->ref = $obj->name;
$this->date_creation = $this->db->jdate($obj->date_creation);
$this->date_modification = $this->db->jdate($obj->date_modification);
}
$this->db->free($result);
}
else
{
dol_print_error($this->db);
}
}
}
/**
* Class to manage one address line
*/
class AddressLine
{
protected $db;
/**
* @var int ID
*/
public $id;
public $date_creation;
public $date_modification;
/**
* @var string stock movements label
*/
public $label;
public $name;
/**
* @var string Address
*/
public $address;
public $zip;
public $town;
public $country_id;
public $country_code;
public $country;
public $phone;
public $fax;
public $note;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
function __construct($db)
{
$this->db = $db;
}
}

View File

@ -61,12 +61,13 @@ class Contacts extends DolibarrApi
*
* Return an array with contact informations
*
* @param int $id ID of contact
* @param int $id ID of contact
* @param int $includecount Count and return also number of elements the contact is used as a link for
* @return array|mixed data without useless information
*
* @throws RestException
*/
function get($id)
function get($id, $includecount = 0)
{
if (!DolibarrApiAccess::$user->rights->societe->contact->lire)
{
@ -74,7 +75,7 @@ class Contacts extends DolibarrApi
}
$result = $this->contact->fetch($id);
$this->contact->load_ref_elements();
if (!$result)
{
throw new RestException(404, 'Contact not found');
@ -85,6 +86,11 @@ class Contacts extends DolibarrApi
throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
}
if ($includecount)
{
$this->contact->load_ref_elements();
}
return $this->_cleanObjectDatas($this->contact);
}