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@capnetworks.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20/** 21 * \file htdocs/reception/contact.php 22 * \ingroup reception 23 * \brief Onglet de gestion des contacts de reception 24 */ 25 26require '../main.inc.php'; 27require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.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/reception.lib.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; 32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 33if (!empty($conf->projet->enabled)) { 34 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; 35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; 36} 37 38$langs->load("orders"); 39$langs->load("receptions"); 40$langs->load("companies"); 41 42$id = GETPOST('id', 'int'); 43$ref = GETPOST('ref', 'alpha'); 44$action = GETPOST('action', 'aZ09'); 45 46// Security check 47if ($user->socid) $socid = $user->socid; 48$result = restrictedArea($user, 'reception', $id, ''); 49 50$object = new Reception($db); 51if ($id > 0 || !empty($ref)) 52{ 53 $object->fetch($id, $ref); 54 $object->fetch_thirdparty(); 55 56 if (!empty($object->origin)) 57 { 58 $origin = $object->origin; 59 60 $object->fetch_origin(); 61 $typeobject = $object->origin; 62 } 63 64 // Linked documents 65 if ($origin == 'order_supplier' && $object->$typeobject->id && !empty($conf->fournisseur->enabled)) 66 { 67 $objectsrc = new CommandeFournisseur($db); 68 $objectsrc->fetch($object->$typeobject->id); 69 } 70} 71 72 73/* 74 * Actions 75 */ 76 77if ($action == 'addcontact' && $user->rights->reception->creer) 78{ 79 if ($result > 0 && $id > 0) 80 { 81 $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); 82 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); 83 $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); 84 } 85 86 if ($result >= 0) 87 { 88 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); 89 exit; 90 } else { 91 if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') 92 { 93 $langs->load("errors"); 94 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); 95 } else { 96 $mesg = $objectsrc->error; 97 $mesgs = $objectsrc->errors; 98 } 99 setEventMessages($mesg, $mesgs, 'errors'); 100 } 101} 102 103// bascule du statut d'un contact 104elseif ($action == 'swapstatut' && $user->rights->reception->creer) 105{ 106 $result = $objectsrc->swapContactStatus(GETPOST('ligne')); 107} 108 109// Efface un contact 110elseif ($action == 'deletecontact' && $user->rights->reception->creer) 111{ 112 $result = $objectsrc->delete_contact(GETPOST("lineid")); 113 114 if ($result >= 0) 115 { 116 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); 117 exit; 118 } else { 119 dol_print_error($db); 120 } 121} 122/* 123elseif ($action == 'setaddress' && $user->rights->reception->creer) 124{ 125 $object->fetch($id); 126 $result=$object->setDeliveryAddress($_POST['fk_address']); 127 if ($result < 0) dol_print_error($db,$object->error); 128}*/ 129 130 131/* 132 * View 133 */ 134 135llxHeader('', $langs->trans('Reception'), 'EN:Customers_Orders|FR:receptions_Clients|ES:Pedidos de clientes'); 136 137$form = new Form($db); 138$formcompany = new FormCompany($db); 139$formother = new FormOther($db); 140$contactstatic = new Contact($db); 141$userstatic = new User($db); 142 143 144/* *************************************************************************** */ 145/* */ 146/* Mode vue et edition */ 147/* */ 148/* *************************************************************************** */ 149 150if ($id > 0 || !empty($ref)) 151{ 152 $langs->trans("OrderCard"); 153 154 $head = reception_prepare_head($object); 155 print dol_get_fiche_head($head, 'contact', $langs->trans("Reception"), -1, 'dollyrevert'); 156 157 158 // Reception card 159 $linkback = '<a href="'.DOL_URL_ROOT.'/reception/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; 160 161 $morehtmlref = '<div class="refidno">'; 162 // Ref customer reception 163 $morehtmlref .= $form->editfieldkey("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', 0, 1); 164 $morehtmlref .= $form->editfieldval("RefSupplier", '', $object->ref_supplier, $object, $user->rights->reception->creer, 'string', '', null, null, '', 1); 165 // Thirdparty 166 $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); 167 // Project 168 if (!empty($conf->projet->enabled)) { 169 $langs->load("projects"); 170 $morehtmlref .= '<br>'.$langs->trans('Project').' '; 171 if (0) { // Do not change on reception 172 if ($action != 'classify') { 173 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : '; 174 } 175 if ($action == 'classify') { 176 // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); 177 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; 178 $morehtmlref .= '<input type="hidden" name="action" value="classin">'; 179 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; 180 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); 181 $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; 182 $morehtmlref .= '</form>'; 183 } else { 184 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); 185 } 186 } else { 187 // We don't have project on reception, so we will use the project or source object instead 188 // TODO Add project on reception 189 $morehtmlref .= ' : '; 190 if (!empty($objectsrc->fk_project)) { 191 $proj = new Project($db); 192 $proj->fetch($objectsrc->fk_project); 193 $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">'; 194 $morehtmlref .= $proj->ref; 195 $morehtmlref .= '</a>'; 196 } else { 197 $morehtmlref .= ''; 198 } 199 } 200 } 201 $morehtmlref .= '</div>'; 202 203 $object->picto = 'sending'; 204 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); 205 206 207 print '<div class="fichecenter">'; 208 //print '<div class="fichehalfleft">'; 209 print '<div class="underbanner clearboth"></div>'; 210 211 print '<table class="border centpercent">'; 212 // Linked documents 213 if ($origin == 'order_supplier' && $object->$typeobject->id && !empty($conf->fournisseur->enabled)) 214 { 215 print '<tr><td class="titlefield">'; 216 $objectsrc = new CommandeFournisseur($db); 217 $objectsrc->fetch($object->$typeobject->id); 218 print $langs->trans("RefOrder").'</td>'; 219 print '<td colspan="3">'; 220 print $objectsrc->getNomUrl(1, 'commande'); 221 print "</td>\n"; 222 print '</tr>'; 223 } 224 if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) 225 { 226 print '<tr><td class="titlefield">'; 227 $objectsrc = new Propal($db); 228 $objectsrc->fetch($object->$typeobject->id); 229 print $langs->trans("RefProposal").'</td>'; 230 print '<td colspan="3">'; 231 print $objectsrc->getNomUrl(1, 'reception'); 232 print "</td>\n"; 233 print '</tr>'; 234 } 235 236 print "</table>"; 237 238 239 //print '</div>'; 240 //print '<div class="fichehalfright">'; 241 //print '<div class="ficheaddleft">'; 242 //print '<div class="underbanner clearboth"></div>'; 243 244 245 //print '</div>'; 246 //print '</div>'; 247 print '</div>'; 248 249 print '<div class="clearboth"></div>'; 250 251 252 print dol_get_fiche_end(); 253 254 // Lines of contacts 255 echo '<br>'; 256 257 // Contacts lines (modules that overwrite templates must declare this into descriptor) 258 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); 259 foreach ($dirtpls as $reldir) 260 { 261 $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); 262 if ($res) break; 263 } 264} 265 266llxFooter(); 267 268$db->close(); 269