1<?php 2/* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net> 3 * Copyright (C) 2005-2016 Destailleur Laurent <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 * 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/comm/propal/contact.php 23 * \ingroup propal 24 * \brief Tab to manage contacts/adresses of proposal 25 */ 26 27require '../../main.inc.php'; 28require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; 29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php'; 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; 32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 33require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; 34 35// Load translation files required by the page 36$langs->loadLangs(array('facture', 'orders', 'sendings', 'companies')); 37 38$id = GETPOST('id', 'int'); 39$ref = GETPOST('ref', 'alpha'); 40$lineid = GETPOST('lineid', 'int'); 41$action = GETPOST('action', 'aZ09'); 42 43// Security check 44if ($user->socid) $socid = $user->socid; 45$result = restrictedArea($user, 'propal', $id); 46 47$object = new Propal($db); 48 49// Load object 50if ($id > 0 || !empty($ref)) 51{ 52 $ret = $object->fetch($id, $ref); 53 if ($ret == 0) 54 { 55 $langs->load("errors"); 56 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors'); 57 $error++; 58 } elseif ($ret < 0) 59 { 60 setEventMessages($object->error, $object->errors, 'errors'); 61 $error++; 62 } 63} 64if (!$error) 65{ 66 $object->fetch_thirdparty(); 67} else { 68 header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php'); 69 exit; 70} 71 72 73/* 74 * Add a new contact 75 */ 76 77if ($action == 'addcontact' && $user->rights->propale->creer) 78{ 79 if ($object->id > 0) 80 { 81 $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); 82 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); 83 $result = $object->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 ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') 92 { 93 $langs->load("errors"); 94 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); 95 } else { 96 setEventMessages($object->error, $object->errors, 'errors'); 97 } 98 } 99} // Toggle the status of a contact 100elseif ($action == 'swapstatut' && $user->rights->propale->creer) 101{ 102 if ($object->id > 0) 103 { 104 $result = $object->swapContactStatus(GETPOST('ligne')); 105 } 106} // Deletes a contact 107elseif ($action == 'deletecontact' && $user->rights->propale->creer) 108{ 109 $result = $object->delete_contact($lineid); 110 111 if ($result >= 0) 112 { 113 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); 114 exit; 115 } else { 116 dol_print_error($db); 117 } 118} 119/* 120elseif ($action == 'setaddress' && $user->rights->propale->creer) 121{ 122 $result=$object->setDeliveryAddress($_POST['fk_address']); 123 if ($result < 0) dol_print_error($db,$object->error); 124}*/ 125 126 127/* 128 * View 129 */ 130 131llxHeader('', $langs->trans('Proposal'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos'); 132 133$form = new Form($db); 134$formcompany = new FormCompany($db); 135$formother = new FormOther($db); 136 137if ($object->id > 0) 138{ 139 $head = propal_prepare_head($object); 140 print dol_get_fiche_head($head, 'contact', $langs->trans("Proposal"), -1, 'propal'); 141 142 143 // Proposal card 144 145 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>'; 146 147 148 $morehtmlref = '<div class="refidno">'; 149 // Ref customer 150 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); 151 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1); 152 // Thirdparty 153 $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer'); 154 // Project 155 if (!empty($conf->projet->enabled)) 156 { 157 $langs->load("projects"); 158 $morehtmlref .= '<br>'.$langs->trans('Project').' '; 159 if ($user->rights->propal->creer) 160 { 161 if ($action != 'classify') { 162 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>'; 163 $morehtmlref .= ' : '; 164 } 165 if ($action == 'classify') { 166 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); 167 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; 168 $morehtmlref .= '<input type="hidden" name="action" value="classin">'; 169 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; 170 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); 171 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; 172 $morehtmlref .= '</form>'; 173 } else { 174 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); 175 } 176 } else { 177 if (!empty($object->fk_project)) { 178 $proj = new Project($db); 179 $proj->fetch($object->fk_project); 180 $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">'; 181 $morehtmlref .= $proj->ref; 182 $morehtmlref .= '</a>'; 183 } else { 184 $morehtmlref .= ''; 185 } 186 } 187 } 188 $morehtmlref .= '</div>'; 189 190 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); 191 192 print dol_get_fiche_end(); 193 194 195 // Contacts lines (modules that overwrite templates must declare this into descriptor) 196 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); 197 foreach ($dirtpls as $reldir) 198 { 199 $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); 200 if ($res) break; 201 } 202} 203 204// End of page 205llxFooter(); 206$db->close(); 207