dolibarr  9.0.0
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
3  * Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
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 <http://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array('interventions', 'sendings', 'companies'));
36 
37 $id = GETPOST('id','int');
38 $ref = GETPOST('ref', 'alpha');
39 $action = GETPOST('action','alpha');
40 
41 // Security check
42 if ($user->societe_id) $socid=$user->societe_id;
43 $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
44 
45 $object = new Fichinter($db);
46 $result = $object->fetch($id,$ref);
47 if (! $result)
48 {
49  print 'Record not found';
50  exit;
51 }
52 
53 /*
54  * Adding a new contact
55  */
56 
57 if ($action == 'addcontact' && $user->rights->ficheinter->creer)
58 {
59  if ($result > 0 && $id > 0)
60  {
61  $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
62  $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha'));
63  }
64 
65  if ($result >= 0)
66  {
67  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
68  exit;
69  }
70  else
71  {
72  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
73  $langs->load("errors");
74  $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
75  } else {
76  $mesg = $object->error;
77  }
78 
79  setEventMessages($mesg, null, 'errors');
80  }
81 }
82 
83 // Toggle the status of a contact
84 else if ($action == 'swapstatut' && $user->rights->ficheinter->creer)
85 {
86  $result=$object->swapContactStatus(GETPOST('ligne','int'));
87 }
88 
89 // Deletes a contact
90 else if ($action == 'deletecontact' && $user->rights->ficheinter->creer)
91 {
92  $result = $object->delete_contact(GETPOST('lineid','int'));
93 
94  if ($result >= 0)
95  {
96  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
97  exit;
98  }
99  else {
100  dol_print_error($db);
101  }
102 }
103 
104 
105 /*
106  * View
107  */
108 
109 $form = new Form($db);
110 $formcompany = new FormCompany($db);
111 $contactstatic=new Contact($db);
112 $userstatic=new User($db);
113 $formproject=new FormProjets($db);
114 
115 llxHeader('',$langs->trans("Intervention"));
116 
117 // Mode vue et edition
118 
119 if ($id > 0 || ! empty($ref))
120 {
121  $object->fetch_thirdparty();
122 
123  $head = fichinter_prepare_head($object);
124  dol_fiche_head($head, 'contact', $langs->trans("InterventionCard"), -1, 'intervention');
125 
126 
127  // Intervention card
128  $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(! empty($socid)?'&socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
129 
130 
131  $morehtmlref='<div class="refidno">';
132  // Ref customer
133  //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
134  //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
135  // Thirdparty
136  $morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
137  // Project
138  if (! empty($conf->projet->enabled))
139  {
140  $langs->load("projects");
141  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
142  if ($user->rights->ficheinter->creer)
143  {
144  if ($action != 'classify')
145  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
146  $morehtmlref.=' : ';
147  if ($action == 'classify') {
148  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
149  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
150  $morehtmlref.='<input type="hidden" name="action" value="classin">';
151  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
152  $morehtmlref.=$formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
153  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
154  $morehtmlref.='</form>';
155  } else {
156  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
157  }
158  } else {
159  if (! empty($object->fk_project)) {
160  $proj = new Project($db);
161  $proj->fetch($object->fk_project);
162  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
163  $morehtmlref.=$proj->ref;
164  $morehtmlref.='</a>';
165  } else {
166  $morehtmlref.='';
167  }
168  }
169  }
170  $morehtmlref.='</div>';
171 
172  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
173 
174  dol_fiche_end();
175 
176  print '<br>';
177 
178  if (! empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_USER)) $hideaddcontactforuser=1;
179  if (! empty($conf->global->FICHINTER_HIDE_ADD_CONTACT_THIPARTY)) $hideaddcontactforthirdparty=1;
180 
181  // Contacts lines (modules that overwrite templates must declare this into descriptor)
182  $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
183  foreach($dirtpls as $reldir)
184  {
185  $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
186  if ($res) break;
187  }
188 }
189 
190 
191 llxFooter();
192 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage contact/addresses.
Class to manage interventions.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Class to manage Dolibarr users.
Definition: user.class.php:41
fichinter_prepare_head($object)
Prepare array with list of tabs.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to build HTML component for third parties management Only common components are here...
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage building of HTML components.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.