1<?php 2/* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net> 3 * Copyright (C) 2005-2009 Destailleur Laurent <eldy@users.sourceforge.net> 4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com> 5 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 */ 20 21/** 22 * \file htdocs/fourn/commande/contact.php 23 * \ingroup commande 24 * \brief Onglet de gestion des contacts de commande 25 */ 26 27require '../../main.inc.php'; 28require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; 29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 32if (!empty($conf->projet->enabled)) { 33 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; 34} 35 36// Load translation files required by the page 37$langs->loadLangs(array("facture", "orders", "sendings", "companies")); 38 39$id = GETPOST('id', 'int'); 40$ref = GETPOST('ref', 'alpha'); 41$action = GETPOST('action', 'aZ09'); 42 43// Security check 44if ($user->socid) { 45 $socid = $user->socid; 46} 47$result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande'); 48$hookmanager->initHooks(array('ordersuppliercardcontact')); 49 50$object = new CommandeFournisseur($db); 51 52 53/* 54 * Add a new contact 55 */ 56 57if ($action == 'addcontact' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) { 58 $result = $object->fetch($id); 59 60 if ($result > 0 && $id > 0) { 61 $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); 62 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); 63 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); 64 } 65 66 if ($result >= 0) { 67 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); 68 exit; 69 } else { 70 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { 71 $langs->load("errors"); 72 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); 73 } else { 74 setEventMessages($object->error, $object->errors, 'errors'); 75 } 76 } 77} elseif ($action == 'swapstatut' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) { 78 // Toggle the status of a contact 79 if ($object->fetch($id)) { 80 $result = $object->swapContactStatus(GETPOST('ligne', 'int')); 81 } else { 82 setEventMessages($object->error, $object->errors, 'errors'); 83 } 84} elseif ($action == 'deletecontact' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) { 85 // Deleting a contact 86 $object->fetch($id); 87 $result = $object->delete_contact(GETPOST("lineid", 'int')); 88 89 if ($result >= 0) { 90 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); 91 exit; 92 } else { 93 setEventMessages($object->error, $object->errors, 'errors'); 94 } 95} 96 97 98 99/* 100 * View 101 */ 102$title = $langs->trans('SupplierOrder')." - ".$langs->trans('ContactsAddresses'); 103$help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores'; 104llxHeader('', $title, $help_url); 105 106$form = new Form($db); 107$formcompany = new FormCompany($db); 108$contactstatic = new Contact($db); 109$userstatic = new User($db); 110 111 112/* *************************************************************************** */ 113/* */ 114/* Mode vue et edition */ 115/* */ 116/* *************************************************************************** */ 117 118if ($id > 0 || !empty($ref)) { 119 $langs->trans("OrderCard"); 120 121 if ($object->fetch($id, $ref) > 0) { 122 $object->fetch_thirdparty(); 123 124 $head = ordersupplier_prepare_head($object); 125 print dol_get_fiche_head($head, 'contact', $langs->trans("SupplierOrder"), -1, 'order'); 126 127 // Supplier order card 128 129 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; 130 131 $morehtmlref = '<div class="refidno">'; 132 // Ref supplier 133 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); 134 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); 135 // Thirdparty 136 $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); 137 // Project 138 if (!empty($conf->projet->enabled)) { 139 $langs->load("projects"); 140 $morehtmlref .= '<br>'.$langs->trans('Project').' '; 141 if ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer) { 142 if ($action != 'classify') { 143 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; 144 $morehtmlref .= ' : '; 145 } 146 if ($action == 'classify') { 147 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); 148 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; 149 $morehtmlref .= '<input type="hidden" name="action" value="classin">'; 150 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; 151 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); 152 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; 153 $morehtmlref .= '</form>'; 154 } else { 155 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); 156 } 157 } else { 158 if (!empty($object->fk_project)) { 159 $proj = new Project($db); 160 $proj->fetch($object->fk_project); 161 $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">'; 162 $morehtmlref .= $proj->ref; 163 $morehtmlref .= '</a>'; 164 } else { 165 $morehtmlref .= ''; 166 } 167 } 168 } 169 $morehtmlref .= '</div>'; 170 171 172 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); 173 174 print dol_get_fiche_end(); 175 176 // Contacts lines 177 include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php'; 178 } else { 179 // Contact not found 180 print "ErrorRecordNotFound"; 181 } 182} 183 184// End of page 185llxFooter(); 186$db->close(); 187