dolibarr  17.0.4
stocktransfer_contact.php
1 <?php
2 /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
3  * Copyright (C) 2005-2016 Destailleur Laurent <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
6  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 // Load Dolibarr environment
29 require '../../../main.inc.php';
30 // Load translation files required by the page
31 $langs->loadLangs(array('facture', 'orders', 'sendings', 'companies', 'stocks'));
32 
33 $id = GETPOST('id', 'int');
34 $ref = GETPOST('ref', 'alpha');
35 $lineid = GETPOST('lineid', 'int');
36 $action = GETPOST('action', 'alpha');
37 
38 // Security check
39 if ($user->socid) $socid = $user->socid;
40 
41 $result = restrictedArea($user, 'stocktransfer', $id, '', 'stocktransfer');
42 
43 $object = new StockTransfer($db);
44 
45 // Load object
46 if ($id > 0 || !empty($ref)) {
47  $ret = $object->fetch($id, $ref);
48  if ($ret == 0) {
49  $langs->load("errors");
50  setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
51  $error++;
52  } elseif ($ret < 0) {
53  setEventMessages($object->error, $object->errors, 'errors');
54  $error++;
55  }
56 }
57 if (!$error) {
58  $object->fetch_thirdparty();
59 } else {
60  header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1));
61  exit;
62 }
63 
64 
65 /*
66  * Add a new contact
67  */
68 
69 if ($action == 'addcontact' && $user->rights->stocktransfer->stocktransfer->write) {
70  if ($object->id > 0) {
71  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
72  $result = $object->add_contact($contactid, !empty($_POST["typecontact"]) ? $_POST["typecontact"] : $_POST["type"], $_POST["source"]);
73  }
74 
75  if ($result >= 0) {
76  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
77  exit;
78  } else {
79  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
80  $langs->load("errors");
81  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
82  } else {
83  setEventMessages($object->error, $object->errors, 'errors');
84  }
85  }
86 } elseif ($action == 'swapstatut' && $user->rights->stocktransfer->stocktransfer->write) { // Toggle the status of a contact
87  if ($object->id > 0) {
88  $result = $object->swapContactStatus(GETPOST('ligne'));
89  }
90 } elseif ($action == 'deletecontact' && $user->rights->stocktransfer->stocktransfer->write) { // Deletes a contact
91  $result = $object->delete_contact($lineid);
92 
93  if ($result >= 0) {
94  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
95  exit;
96  } else {
97  dol_print_error($db);
98  }
99 }
100 /*
101 elseif ($action == 'setaddress' && $user->rights->stocktransfer->stocktransfer->write)
102 {
103  $result=$object->setDeliveryAddress($_POST['fk_address']);
104  if ($result < 0) dol_print_error($db,$object->error);
105 }*/
106 
107 
108 /*
109  * View
110  */
111 
112 llxHeader('', $langs->trans('ModuleStockTransferName'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
113 
114 $form = new Form($db);
115 $formcompany = new FormCompany($db);
116 $formother = new FormOther($db);
117 
118 if ($object->id > 0) {
119  $head = stocktransferPrepareHead($object);
120  print dol_get_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
121 
122 
123  // Proposal card
124 
125  $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
126 
127 
128  $morehtmlref = '<div class="refidno">';
129  // Ref customer
130  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
131  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
132  // Thirdparty
133  if (!empty($object->thirdparty)) {
134  $morehtmlref .= '<br>' . $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'customer');
135  }
136  // Project
137  if (!empty($conf->project->enabled)) {
138  $langs->load("projects");
139  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
140  if ($user->rights->stocktransfer->stocktransfer->write) {
141  if ($action != 'classify') {
142  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;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, '', 'maxwidth300');
155  }
156  } else {
157  if (!empty($object->fk_project)) {
158  $proj = new Project($db);
159  $proj->fetch($object->fk_project);
160  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
161  $morehtmlref .= $proj->ref;
162  $morehtmlref .= '</a>';
163  } else {
164  $morehtmlref .= '';
165  }
166  }
167  }
168  $morehtmlref .= '</div>';
169 
170  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
171 
172  print dol_get_fiche_end();
173 
174  $user->rights->stocktransfer->write = $user->rights->stocktransfer->stocktransfer->write;
175  // Contacts lines (modules that overwrite templates must declare this into descriptor)
176  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
177  foreach ($dirtpls as $reldir) {
178  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
179  if ($res) break;
180  }
181 }
182 
183 // End of page
184 llxFooter();
185 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
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.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage projects.
Class for StockTransfer.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
restrictedArea(User $user, $features, $object=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.
stocktransferPrepareHead($object)
Prepare array of tabs for StockTransfer.