dolibarr  16.0.5
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", "supplier_proposal", "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) {
43  $socid = $user->socid;
44 }
45 $result = restrictedArea($user, 'supplier_proposal', $id, 'supplier_proposal', '');
46 
47 $object = new SupplierProposal($db);
48 
49 $permissiontoedit = $user->rights->supplier_proposal->creer;
50 
51 
52 /*
53  * Add a new contact
54  */
55 
56 if ($action == 'addcontact' && $permissiontoedit) {
57  $result = $object->fetch($id);
58 
59  if ($result > 0 && $id > 0) {
60  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
61  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
62  $result = $object->add_contact($contactid, $typeid, GETPOST("source"));
63  }
64 
65  if ($result >= 0) {
66  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
67  exit;
68  } else {
69  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
70  $langs->load("errors");
71  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
72  } else {
73  setEventMessages($object->error, $object->errors, 'errors');
74  }
75  }
76 } elseif ($action == 'swapstatut' && $permissiontoedit) {
77  // Toggle the status of a contact
78  if ($object->fetch($id)) {
79  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
80  } else {
81  setEventMessages($object->error, $object->errors, 'errors');
82  }
83 } elseif ($action == 'deletecontact' && $permissiontoedit) {
84  // Deleting a contact
85  $object->fetch($id);
86  $result = $object->delete_contact(GETPOST("lineid", 'int'));
87 
88  if ($result >= 0) {
89  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
90  exit;
91  } else {
92  setEventMessages($object->error, $object->errors, 'errors');
93  }
94 }
95 
96 
97 
98 /*
99  * View
100  */
101 $title = $langs->trans('CommRequest')." - ".$langs->trans('ContactsAddresses');
102 $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
103 llxHeader('', $title, $help_url);
104 
105 $form = new Form($db);
106 $formcompany = new FormCompany($db);
107 $contactstatic = new Contact($db);
108 $userstatic = new User($db);
109 
110 
111 /* *************************************************************************** */
112 /* */
113 /* Mode vue et edition */
114 /* */
115 /* *************************************************************************** */
116 
117 if ($id > 0 || !empty($ref)) {
118  $langs->trans("SupplierProposal");
119 
120  if ($object->fetch($id, $ref) > 0) {
121  $object->fetch_thirdparty();
122 
123  $head = supplier_proposal_prepare_head($object);
124  print dol_get_fiche_head($head, 'contact', $langs->trans("CommRequest"), -1, 'supplier_proposal');
125 
126  // Supplier order card
127 
128  $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
129 
130  $morehtmlref = '<div class="refidno">';
131  // Ref supplier
132  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
133  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
134  // Thirdparty
135  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
136  // Project
137  if (!empty($conf->project->enabled)) {
138  $langs->load("projects");
139  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
140  if ($permissiontoedit) {
141  if ($action != 'classify') {
142  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
143  $morehtmlref .= ' : ';
144  }
145  if ($action == 'classify') {
146  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
147  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
148  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
149  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
150  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
151  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
152  $morehtmlref .= '</form>';
153  } else {
154  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
155  }
156  } else {
157  if (!empty($object->fk_project)) {
158  $proj = new Project($db);
159  $proj->fetch($object->fk_project);
160  $morehtmlref .= ' : '.$proj->getNomUrl(1);
161  if ($proj->title) {
162  $morehtmlref .= ' - '.$proj->title;
163  }
164  } else {
165  $morehtmlref .= '';
166  }
167  }
168  }
169  $morehtmlref .= '</div>';
170 
171 
172  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
173 
174  print dol_get_fiche_end();
175 
176  // Contacts lines
177  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
178  } else {
179  // Contact not found
180  print "ErrorRecordNotFound";
181  }
182 }
183 
184 // End of page
185 llxFooter();
186 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Project
Class to manage projects.
Definition: project.class.php:35
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
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.
Definition: functions.lib.php:2046
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:116
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
SupplierProposal
Class to manage price ask supplier.
Definition: supplier_proposal.class.php:50
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59