1<?php 2/* Copyright (C) 2011-2016 Jean-François Ferry <hello@librethic.io> 3 * Copyright (C) 2011 Regis Houssin <regis.houssin@inodbox.com> 4 * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr> 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, write to the Free Software 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 21/** 22 * \file htdocs/ticket/contact.php 23 * \ingroup ticket 24 * \brief Contacts of tickets 25 */ 26 27require '../main.inc.php'; 28 29require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; 30require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php'; 31 32require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; 33require_once DOL_DOCUMENT_ROOT."/core/lib/company.lib.php"; 34require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; 35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 36 37// Load translation files required by the page 38$langs->loadLangs(array('companies', 'ticket')); 39 40// Get parameters 41$socid = GETPOST("socid", 'int'); 42$action = GETPOST("action", 'alpha'); 43$track_id = GETPOST("track_id", 'alpha'); 44$id = GETPOST("id", 'int'); 45$ref = GETPOST('ref', 'alpha'); 46 47$type = GETPOST('type', 'alpha'); 48$source = GETPOST('source', 'alpha'); 49 50$ligne = GETPOST('ligne', 'int'); 51$lineid = GETPOST('lineid', 'int'); 52 53// Protection if external user 54if ($user->socid > 0) { 55 $socid = $user->socid; 56 accessforbidden(); 57} 58 59// Store current page url 60$url_page_current = dol_buildpath('/ticket/contact.php', 1); 61 62$object = new Ticket($db); 63 64 65/* 66 * Actions 67 */ 68 69if ($action == 'addcontact' && $user->rights->ticket->write) { 70 $result = $object->fetch($id, '', $track_id); 71 72 if ($result > 0 && ($id > 0 || (!empty($track_id)))) { 73 $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); 74 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); 75 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); 76 } 77 78 if ($result >= 0) { 79 Header("Location: ".$url_page_current."?id=".$object->id); 80 exit; 81 } else { 82 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { 83 $langs->load("errors"); 84 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); 85 } else { 86 setEventMessages($object->error, $object->errors, 'errors'); 87 } 88 } 89} 90 91// bascule du statut d'un contact 92if ($action == 'swapstatut' && $user->rights->ticket->write) { 93 if ($object->fetch($id, '', $track_id)) { 94 $result = $object->swapContactStatus($ligne); 95 } else { 96 dol_print_error($db, $object->error); 97 } 98} 99 100// Efface un contact 101if ($action == 'deletecontact' && $user->rights->ticket->write) { 102 if ($object->fetch($id, '', $track_id)) { 103 $result = $object->delete_contact($lineid); 104 105 if ($result >= 0) { 106 Header("Location: ".$url_page_current."?id=".$object->id); 107 exit; 108 } 109 } 110} 111 112 113 114/* 115 * View 116 */ 117 118$help_url = 'FR:DocumentationModuleTicket'; 119llxHeader('', $langs->trans("TicketContacts"), $help_url); 120 121$form = new Form($db); 122$formcompany = new FormCompany($db); 123$contactstatic = new Contact($db); 124$userstatic = new User($db); 125 126if ($id > 0 || !empty($track_id) || !empty($ref)) { 127 if ($object->fetch($id, $ref, $track_id) > 0) 128 { 129 if ($socid > 0) { 130 $object->fetch_thirdparty(); 131 $head = societe_prepare_head($object->thirdparty); 132 print dol_get_fiche_head($head, 'ticket', $langs->trans("ThirdParty"), 0, 'company'); 133 dol_banner_tab($object->thirdparty, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom'); 134 print dol_get_fiche_end(); 135 } 136 137 if (!$user->socid && $conf->global->TICKET_LIMIT_VIEW_ASSIGNED_ONLY) { 138 $object->next_prev_filter = "te.fk_user_assign = '".$user->id."'"; 139 } elseif ($user->socid > 0) { 140 $object->next_prev_filter = "te.fk_soc = '".$user->socid."'"; 141 } 142 143 $head = ticket_prepare_head($object); 144 145 print dol_get_fiche_head($head, 'contact', $langs->trans("Ticket"), -1, 'ticket'); 146 147 $morehtmlref = '<div class="refidno">'; 148 $morehtmlref .= $object->subject; 149 // Author 150 if ($object->fk_user_create > 0) { 151 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : '; 152 153 $langs->load("users"); 154 $fuser = new User($db); 155 $fuser->fetch($object->fk_user_create); 156 $morehtmlref .= $fuser->getNomUrl(0); 157 } 158 if (!empty($object->origin_email)) { 159 $morehtmlref .= '<br>'.$langs->trans("CreatedBy").' : '; 160 $morehtmlref .= $object->origin_email.' <small>('.$langs->trans("TicketEmailOriginIssuer").')</small>'; 161 } 162 163 // Thirdparty 164 if (!empty($conf->societe->enabled)) 165 { 166 $morehtmlref .= '<br>'.$langs->trans('ThirdParty'); 167 /*if ($action != 'editcustomer' && $object->fk_statut < 8 && !$user->socid && $user->rights->ticket->write) { 168 $morehtmlref.='<a class="editfielda" href="' . $url_page_current . '?action=editcustomer&track_id=' . $object->track_id . '">' . img_edit($langs->transnoentitiesnoconv('Edit'), 1) . '</a>'; 169 }*/ 170 $morehtmlref .= ' : '; 171 if ($action == 'editcustomer') { 172 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'editcustomer', '', 1, 0, 0, array(), 1); 173 } else { 174 $morehtmlref .= $form->form_thirdparty($url_page_current.'?track_id='.$object->track_id, $object->socid, 'none', '', 1, 0, 0, array(), 1); 175 } 176 } 177 178 // Project 179 if (!empty($conf->projet->enabled)) 180 { 181 $langs->load("projects"); 182 $morehtmlref .= '<br>'.$langs->trans('Project').' '; 183 if ($user->rights->ticket->write) 184 { 185 if ($action != 'classify') { 186 //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>'; 187 $morehtmlref .= ' : '; 188 } 189 if ($action == 'classify') { 190 //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); 191 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">'; 192 $morehtmlref .= '<input type="hidden" name="action" value="classin">'; 193 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">'; 194 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', 0, 0, 1, 0, 1, 0, 0, '', 1); 195 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">'; 196 $morehtmlref .= '</form>'; 197 } else { 198 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); 199 } 200 } else { 201 if (!empty($object->fk_project)) { 202 $proj = new Project($db); 203 $proj->fetch($object->fk_project); 204 $morehtmlref .= $proj->getNomUrl(1); 205 } else { 206 $morehtmlref .= ''; 207 } 208 } 209 } 210 211 $morehtmlref .= '</div>'; 212 213 $linkback = '<a href="'.dol_buildpath('/ticket/list.php', 1).'"><strong>'.$langs->trans("BackToList").'</strong></a> '; 214 215 dol_banner_tab($object, 'ref', $linkback, ($user->socid ? 0 : 1), 'ref', 'ref', $morehtmlref, $param, 0, '', '', 1, ''); 216 217 print dol_get_fiche_end(); 218 219 //print '<br>'; 220 221 $permission = $user->rights->ticket->write; 222 223 // Contacts lines (modules that overwrite templates must declare this into descriptor) 224 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); 225 foreach ($dirtpls as $reldir) { 226 $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); 227 if ($res) { 228 break; 229 } 230 } 231 } else { 232 print "ErrorRecordNotFound"; 233 } 234} 235 236// End of page 237llxFooter(); 238$db->close(); 239