dolibarr  13.0.2
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
3  * Copyright (C) 2005-2018 Destailleur Laurent <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.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 <https://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/supplier_proposal.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.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("propal", "facture", "orders", "sendings", "companies"));
36 
37 $id = GETPOST('id', 'int');
38 $ref = GETPOST('ref', 'alpha');
39 $action = GETPOST('action', 'aZ09');
40 
41 // Security check
42 if ($user->socid) $socid = $user->socid;
43 $result = restrictedArea($user, 'supplier_proposal', $id, 'supplier_proposal', '');
44 
45 $object = new SupplierProposal($db);
46 
47 $permissiontoedit = $user->rights->supplier_proposal->creer;
48 
49 
50 /*
51  * Add a new contact
52  */
53 
54 if ($action == 'addcontact' && $permissiontoedit)
55 {
56  $result = $object->fetch($id);
57 
58  if ($result > 0 && $id > 0)
59  {
60  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
61  $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
62  }
63 
64  if ($result >= 0)
65  {
66  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
67  exit;
68  } else {
69  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
70  {
71  $langs->load("errors");
72  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
73  } else {
74  setEventMessages($object->error, $object->errors, 'errors');
75  }
76  }
77 }
78 
79 // Toggle the status of a contact
80 elseif ($action == 'swapstatut' && $permissiontoedit)
81 {
82  if ($object->fetch($id))
83  {
84  $result = $object->swapContactStatus(GETPOST('ligne'));
85  } else {
86  dol_print_error($db);
87  }
88 }
89 
90 // Deleting a contact
91 elseif ($action == 'deletecontact' && $permissiontoedit)
92 {
93  $object->fetch($id);
94  $result = $object->delete_contact(GETPOST("lineid", 'int'));
95 
96  if ($result >= 0)
97  {
98  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
99  exit;
100  } else {
101  dol_print_error($db);
102  }
103 }
104 
105 
106 
107 /*
108  * View
109  */
110 
111 $help_url = '';
112 llxHeader('', $langs->trans("SupplierProposals"), $help_url);
113 
114 $form = new Form($db);
115 $formcompany = new FormCompany($db);
116 $contactstatic = new Contact($db);
117 $userstatic = new User($db);
118 
119 
120 /* *************************************************************************** */
121 /* */
122 /* Mode vue et edition */
123 /* */
124 /* *************************************************************************** */
125 
126 if ($id > 0 || !empty($ref))
127 {
128  $langs->trans("SupplierProposal");
129 
130  if ($object->fetch($id, $ref) > 0)
131  {
132  $object->fetch_thirdparty();
133 
134  $head = supplier_proposal_prepare_head($object);
135  print dol_get_fiche_head($head, 'contact', $langs->trans("CommRequest"), -1, 'supplier_proposal');
136 
137  // Supplier order card
138 
139  $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
140 
141  $morehtmlref = '<div class="refidno">';
142  // Ref supplier
143  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
144  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
145  // Thirdparty
146  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
147  // Project
148  if (!empty($conf->projet->enabled))
149  {
150  $langs->load("projects");
151  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
152  if ($permissiontoedit)
153  {
154  if ($action != 'classify') {
155  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
156  $morehtmlref .= ' : ';
157  }
158  if ($action == 'classify') {
159  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
160  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
161  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
162  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
163  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
164  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
165  $morehtmlref .= '</form>';
166  } else {
167  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
168  }
169  } else {
170  if (!empty($object->fk_project)) {
171  $proj = new Project($db);
172  $proj->fetch($object->fk_project);
173  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
174  $morehtmlref .= $proj->ref;
175  $morehtmlref .= '</a>';
176  } else {
177  $morehtmlref .= '';
178  }
179  }
180  }
181  $morehtmlref .= '</div>';
182 
183 
184  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
185 
187 
188  // Contacts lines
189  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
190  } else {
191  // Contact not found
192  print "ErrorRecordNotFound";
193  }
194 }
195 
196 // End of page
197 llxFooter();
198 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
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.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
Class to manage price ask supplier.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59