dolibarr  7.0.0-beta
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
3  * Copyright (C) 2005-2009 Destailleur Laurent <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
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 <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32 if (! empty($conf->projet->enabled)) {
33  require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
34 }
35 
36 $langs->load("facture");
37 $langs->load("orders");
38 $langs->load("sendings");
39 $langs->load("companies");
40 
41 $id = GETPOST('id', 'int');
42 $ref = GETPOST('ref', 'alpha');
43 $action = GETPOST('action', 'alpha');
44 
45 // Security check
46 if ($user->societe_id) $socid=$user->societe_id;
47 $result = restrictedArea($user, 'fournisseur', $id, '', 'commande');
48 
49 $object = new CommandeFournisseur($db);
50 
51 
52 /*
53  * Add a new contact
54  */
55 
56 if ($action == 'addcontact' && $user->rights->fournisseur->commande->creer)
57 {
58  $result = $object->fetch($id);
59 
60  if ($result > 0 && $id > 0)
61  {
62  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
63  $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
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  {
75  $langs->load("errors");
76  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
77  }
78  else
79  {
80  setEventMessages($object->error, $object->errors, 'errors');
81  }
82  }
83 }
84 
85 // Toggle the status of a contact
86 else if ($action == 'swapstatut' && $user->rights->fournisseur->commande->creer)
87 {
88  if ($object->fetch($id))
89  {
90  $result=$object->swapContactStatus(GETPOST('ligne'));
91  }
92  else
93  {
94  dol_print_error($db);
95  }
96 }
97 
98 // Deleting a contact
99 else if ($action == 'deletecontact' && $user->rights->fournisseur->commande->creer)
100 {
101  $object->fetch($id);
102  $result = $object->delete_contact($_GET["lineid"]);
103 
104  if ($result >= 0)
105  {
106  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
107  exit;
108  }
109  else {
110  dol_print_error($db);
111  }
112 }
113 
114 
115 
116 /*
117  * View
118  */
119 $help_url='EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
120 llxHeader('',$langs->trans("Order"),$help_url);
121 
122 $form = new Form($db);
123 $formcompany = new FormCompany($db);
124 $contactstatic=new Contact($db);
125 $userstatic=new User($db);
126 
127 
128 /* *************************************************************************** */
129 /* */
130 /* Mode vue et edition */
131 /* */
132 /* *************************************************************************** */
133 
134 if ($id > 0 || ! empty($ref))
135 {
136  $langs->trans("OrderCard");
137 
138  if ($object->fetch($id, $ref) > 0)
139  {
140  $object->fetch_thirdparty();
141 
142  $head = ordersupplier_prepare_head($object);
143  dol_fiche_head($head, 'contact', $langs->trans("SupplierOrder"), 0, 'order');
144 
145  // Supplier order card
146 
147  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
148 
149  $morehtmlref='<div class="refidno">';
150  // Ref supplier
151  $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
152  $morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
153  // Thirdparty
154  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
155  // Project
156  if (! empty($conf->projet->enabled))
157  {
158  $langs->load("projects");
159  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
160  if ($user->rights->fournisseur->commande->creer)
161  {
162  if ($action != 'classify')
163  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
164  $morehtmlref.=' : ';
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="'.$_SESSION['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 
191  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
192 
193  dol_fiche_end();
194 
195  // Contacts lines
196  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
197 
198  }
199  else
200  {
201  // Contact not found
202  print "ErrorRecordNotFound";
203  }
204 }
205 
206 
207 llxFooter();
208 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
ordersupplier_prepare_head($object)
Prepare array with list of tabs.
Definition: fourn.lib.php:102
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.
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
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
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.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:46
Class to manage predefined suppliers products.
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.