/htdocs/fourn/commande/contact.php
PHP | 206 lines | 128 code | 31 blank | 47 comment | 30 complexity | 88c52d9832a0513f8d3f6fabcd6456b7 MD5 | raw file
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', 'alpha'); 42 43// Security check 44if ($user->socid) $socid = $user->socid; 45$result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande'); 46 47$object = new CommandeFournisseur($db); 48 49 50/* 51 * Add a new contact 52 */ 53 54if ($action == 'addcontact' && $user->rights->fournisseur->commande->creer) 55{ 56 $result = $object->fetch($id); 57 58 if ($result > 0 && $id > 0) 59 { 60 $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); 61 $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); 62 } 63 64 if ($result >= 0) 65 { 66 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); 67 exit; 68 } 69 else 70 { 71 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') 72 { 73 $langs->load("errors"); 74 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); 75 } 76 else 77 { 78 setEventMessages($object->error, $object->errors, 'errors'); 79 } 80 } 81} 82 83// Toggle the status of a contact 84elseif ($action == 'swapstatut' && $user->rights->fournisseur->commande->creer) 85{ 86 if ($object->fetch($id)) 87 { 88 $result = $object->swapContactStatus(GETPOST('ligne')); 89 } 90 else 91 { 92 dol_print_error($db); 93 } 94} 95 96// Deleting a contact 97elseif ($action == 'deletecontact' && $user->rights->fournisseur->commande->creer) 98{ 99 $object->fetch($id); 100 $result = $object->delete_contact($_GET["lineid"]); 101 102 if ($result >= 0) 103 { 104 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); 105 exit; 106 } 107 else { 108 dol_print_error($db); 109 } 110} 111 112 113 114/* 115 * View 116 */ 117$help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores'; 118llxHeader('', $langs->trans("Order"), $help_url); 119 120$form = new Form($db); 121$formcompany = new FormCompany($db); 122$contactstatic = new Contact($db); 123$userstatic = new User($db); 124 125 126/* *************************************************************************** */ 127/* */ 128/* Mode vue et edition */ 129/* */ 130/* *************************************************************************** */ 131 132if ($id > 0 || !empty($ref)) 133{ 134 $langs->trans("OrderCard"); 135 136 if ($object->fetch($id, $ref) > 0) 137 { 138 $object->fetch_thirdparty(); 139 140 $head = ordersupplier_prepare_head($object); 141 dol_fiche_head($head, 'contact', $langs->trans("SupplierOrder"), -1, 'order'); 142 143 // Supplier order card 144 145 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; 146 147 $morehtmlref = '<div class="refidno">'; 148 // Ref supplier 149 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); 150 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); 151 // Thirdparty 152 $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); 153 // Project 154 if (!empty($conf->projet->enabled)) 155 { 156 $langs->load("projects"); 157 $morehtmlref .= '<br>'.$langs->trans('Project').' '; 158 if ($user->rights->fournisseur->commande->creer) 159 { 160 if ($action != 'classify') { 161 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : '; 162 $morehtmlref .= ' : '; 163 } 164 if ($action == 'classify') { 165 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); 166 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; 167 $morehtmlref .= '<input type="hidden" name="action" value="classin">'; 168 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; 169 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); 170 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; 171 $morehtmlref .= '</form>'; 172 } else { 173 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); 174 } 175 } else { 176 if (!empty($object->fk_project)) { 177 $proj = new Project($db); 178 $proj->fetch($object->fk_project); 179 $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">'; 180 $morehtmlref .= $proj->ref; 181 $morehtmlref .= '</a>'; 182 } else { 183 $morehtmlref .= ''; 184 } 185 } 186 } 187 $morehtmlref .= '</div>'; 188 189 190 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); 191 192 dol_fiche_end(); 193 194 // Contacts lines 195 include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php'; 196 } 197 else 198 { 199 // Contact not found 200 print "ErrorRecordNotFound"; 201 } 202} 203 204// End of page 205llxFooter(); 206$db->close();