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