1<?php 2/* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net> 3 * Copyright (C) 2005-2011 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com> 5 * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com> 6 * Copyright (C) 2014 Charles-Fr Benke <charles.fr@benke.fr> 7 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com> 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program. If not, see <https://www.gnu.org/licenses/>. 21 */ 22 23/** 24 * \file htdocs/societe/societecontact.php 25 * \ingroup societe 26 * \brief Onglet de gestion des contacts additionnel d'une société 27 */ 28 29require '../main.inc.php'; 30require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; 32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; 33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 34 35$langs->loadLangs(array("orders", "companies")); 36 37$id = GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('socid', 'int'); 38$ref = GETPOST('ref', 'alpha'); 39$action = GETPOST('action', 'aZ09'); 40$massaction = GETPOST('massaction', 'alpha'); 41 42$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; 43$sortfield = GETPOST("sortfield", 'alpha'); 44$sortorder = GETPOST("sortorder", 'alpha'); 45$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); 46if (!$sortorder) { 47 $sortorder = "ASC"; 48} 49if (!$sortfield) { 50 $sortfield = "s.nom"; 51} 52if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) { 53 $page = 0; 54} 55$offset = $limit * $page; 56$pageprev = $page - 1; 57$pagenext = $page + 1; 58 59// Security check 60if ($user->socid) { 61 $socid = $user->socid; 62} 63$result = restrictedArea($user, 'societe', $id, ''); 64 65$object = new Societe($db); 66 67// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context 68$hookmanager->initHooks(array('contactthirdparty', 'globalcard')); 69 70 71/* 72 * Actions 73 */ 74 75if ($action == 'addcontact' && $user->rights->societe->creer) { 76 $result = $object->fetch($id); 77 78 if ($result > 0 && $id > 0) { 79 $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); 80 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); 81 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); 82 } 83 84 if ($result >= 0) { 85 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); 86 exit; 87 } else { 88 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { 89 $langs->load("errors"); 90 $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>'; 91 } else { 92 $mesg = '<div class="error">'.$object->error.'</div>'; 93 } 94 } 95} elseif ($action == 'swapstatut' && $user->rights->societe->creer) { 96 // bascule du statut d'un contact 97 if ($object->fetch($id)) { 98 $result = $object->swapContactStatus(GETPOST('ligne', 'int')); 99 } else { 100 dol_print_error($db); 101 } 102} elseif ($action == 'deletecontact' && $user->rights->societe->creer) { 103 // Efface un contact 104 $object->fetch($id); 105 $result = $object->delete_contact(GETPOST("lineid", 'int')); 106 107 if ($result >= 0) { 108 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); 109 exit; 110 } else { 111 dol_print_error($db); 112 } 113} 114/* 115elseif ($action == 'setaddress' && $user->rights->societe->creer) 116{ 117 $object->fetch($id); 118 $result=$object->setDeliveryAddress($_POST['fk_address']); 119 if ($result < 0) dol_print_error($db,$object->error); 120}*/ 121 122 123/* 124 * View 125 */ 126 127$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; 128llxHeader('', $langs->trans("ThirdParty"), $help_url); 129 130 131$form = new Form($db); 132$formcompany = new FormCompany($db); 133$formother = new FormOther($db); 134$contactstatic = new Contact($db); 135$userstatic = new User($db); 136 137 138/* *************************************************************************** */ 139/* */ 140/* Mode vue et edition */ 141/* */ 142/* *************************************************************************** */ 143 144if ($id > 0 || !empty($ref)) { 145 if ($object->fetch($id, $ref) > 0) { 146 $soc = new Societe($db); 147 $soc->fetch($object->socid); 148 149 $head = societe_prepare_head($object); 150 print dol_get_fiche_head($head, 'contact', $langs->trans("ThirdParty"), -1, 'company'); 151 152 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">'; 153 print '<input type="hidden" name="token" value="'.newToken().'">'; 154 155 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; 156 157 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); 158 159 print '<div class="fichecenter">'; 160 161 print '<div class="underbanner clearboth"></div>'; 162 print '<table class="border centpercent">'; 163 164 // Prospect/Customer 165 /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>'; 166 print $object->getLibCustProspStatut(); 167 print '</td></tr>'; 168 169 // Supplier 170 print '<tr><td>'.$langs->trans('Supplier').'</td><td>'; 171 print yn($object->fournisseur); 172 print '</td></tr>';*/ 173 174 if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field 175 print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; 176 } 177 178 if ($object->client) { 179 print '<tr><td class="titlefield">'; 180 print $langs->trans('CustomerCode').'</td><td colspan="3">'; 181 print $object->code_client; 182 $tmpcheck = $object->check_codeclient(); 183 if ($tmpcheck != 0 && $tmpcheck != -5) { 184 print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; 185 } 186 print '</td></tr>'; 187 } 188 189 if ($object->fournisseur) { 190 print '<tr><td class="titlefield">'; 191 print $langs->trans('SupplierCode').'</td><td colspan="3">'; 192 print $object->code_fournisseur; 193 $tmpcheck = $object->check_codefournisseur(); 194 if ($tmpcheck != 0 && $tmpcheck != -5) { 195 print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; 196 } 197 print '</td></tr>'; 198 } 199 print '</table>'; 200 201 print '</div>'; 202 203 print '</form>'; 204 print '<br>'; 205 206 // Contacts lines (modules that overwrite templates must declare this into descriptor) 207 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); 208 foreach ($dirtpls as $reldir) { 209 $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); 210 if ($res) { 211 break; 212 } 213 } 214 215 // additionnal list with adherents of company 216 if (!empty($conf->adherent->enabled) && $user->rights->adherent->lire) { 217 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; 218 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; 219 220 $membertypestatic = new AdherentType($db); 221 $memberstatic = new Adherent($db); 222 223 $langs->load("members"); 224 $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,"; 225 $sql .= " d.datefin,"; 226 $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,"; 227 $sql .= " t.libelle as type, t.subscription"; 228 $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d"; 229 $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t"; 230 $sql .= " WHERE d.fk_soc = ".((int) $id); 231 $sql .= " AND d.fk_adherent_type = t.rowid"; 232 233 dol_syslog("get list sql=".$sql); 234 $resql = $db->query($sql); 235 if ($resql) { 236 $num = $db->num_rows($resql); 237 238 if ($num > 0) { 239 $param = ''; 240 241 $titre = $langs->trans("MembersListOfTiers"); 242 print '<br>'; 243 244 print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, 0, ''); 245 246 print "<table class=\"noborder\" width=\"100%\">"; 247 print '<tr class="liste_titre">'; 248 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", $param, "", "", $sortfield, $sortorder); 249 print_liste_field_titre("NameSlashCompany", $_SERVER["PHP_SELF"], "d.lastname", $param, "", "", $sortfield, $sortorder); 250 print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", $param, "", "", $sortfield, $sortorder); 251 print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "t.libelle", $param, "", "", $sortfield, $sortorder); 252 print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "d.morphy", $param, "", "", $sortfield, $sortorder); 253 print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", $param, "", "", $sortfield, $sortorder); 254 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", $param, "", "", $sortfield, $sortorder); 255 print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", $param, "", '', $sortfield, $sortorder, 'center '); 256 print "</tr>\n"; 257 258 $i = 0; 259 while ($i < $num && $i < $conf->liste_limit) { 260 $objp = $db->fetch_object($resql); 261 262 $datefin = $db->jdate($objp->datefin); 263 $memberstatic->id = $objp->rowid; 264 $memberstatic->ref = $objp->rowid; 265 $memberstatic->lastname = $objp->lastname; 266 $memberstatic->firstname = $objp->firstname; 267 $memberstatic->statut = $objp->statut; 268 $memberstatic->datefin = $db->jdate($objp->datefin); 269 270 $companyname = $objp->company; 271 272 print '<tr class="oddeven">'; 273 274 // Ref 275 print "<td>"; 276 print $memberstatic->getNomUrl(1); 277 print "</td>\n"; 278 279 // Lastname 280 print "<td><a href=\"card.php?rowid=$objp->rowid\">"; 281 print ((!empty($objp->lastname) || !empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : ''); 282 print (((!empty($objp->lastname) || !empty($objp->firstname)) && !empty($companyname)) ? ' / ' : ''); 283 print (!empty($companyname) ? dol_trunc($companyname, 32) : ''); 284 print "</a></td>\n"; 285 286 // Login 287 print "<td>".$objp->login."</td>\n"; 288 289 // Type 290 $membertypestatic->id = $objp->type_id; 291 $membertypestatic->libelle = $objp->type; 292 $membertypestatic->label = $objp->type; 293 294 print '<td class="nowrap">'; 295 print $membertypestatic->getNomUrl(1, 32); 296 print '</td>'; 297 298 // Moral/Physique 299 print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n"; 300 301 // EMail 302 print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n"; 303 304 // Statut 305 print '<td class="nowrap">'; 306 print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2); 307 print "</td>"; 308 309 // End of subscription date 310 if ($datefin) { 311 print '<td class="center nowrap">'; 312 print dol_print_date($datefin, 'day'); 313 if ($memberstatic->hasDelay()) { 314 print " ".img_warning($langs->trans("SubscriptionLate")); 315 } 316 print '</td>'; 317 } else { 318 print '<td class="left nowrap">'; 319 if (!empty($objp->subscription)) { 320 print $langs->trans("SubscriptionNotReceived"); 321 if ($objp->statut > 0) { 322 print " ".img_warning(); 323 } 324 } else { 325 print ' '; 326 } 327 print '</td>'; 328 } 329 330 print "</tr>\n"; 331 $i++; 332 } 333 print "</table>\n"; 334 } 335 } 336 } 337 } else { 338 // Contrat non trouve 339 print "ErrorRecordNotFound"; 340 } 341} 342 343// End of page 344llxFooter(); 345$db->close(); 346