dolibarr 23.0.3
stocktransfer_contact.php
Go to the documentation of this file.
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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
35require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
36require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
37require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
38
47// Load translation files required by the page
48$langs->loadLangs(array('facture', 'orders', 'sendings', 'companies', 'stocks'));
49
50$id = GETPOSTINT('id');
51$ref = GETPOST('ref', 'alpha');
52$lineid = GETPOSTINT('lineid');
53
54$action = GETPOST('action', 'alpha');
55
56$object = new StockTransfer($db);
57$error = 0;
58
59// Load object
60//include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
61if ($id > 0 || !empty($ref)) {
62 $ret = $object->fetch($id, $ref);
63 if ($ret == 0) {
64 $langs->load("errors");
65 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
66 $error++;
67 } elseif ($ret < 0) {
68 setEventMessages($object->error, $object->errors, 'errors');
69 $error++;
70 }
71}
72if (!$error) {
73 $object->fetch_thirdparty();
74} else {
75 header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1));
76 exit;
77}
78
79// Security check
80if ($user->socid) {
81 $socid = $user->socid;
82}
83
84
85$permissiontoread = $user->hasRight('stocktransfer', 'stocktransfer', 'read');
86$permissiontoadd = $user->hasRight('stocktransfer', 'stocktransfer', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
87$permissionnote = $user->hasRight('stocktransfer', 'stocktransfer', 'write'); // Used by the include of actions_setnotes.inc.php
88$permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status < $object::STATUS_TRANSFERED);
89$permissiondellink = $user->hasRight('stocktransfer', 'stocktransfer', 'write'); // Used by the include of actions_dellink.inc.php
90$upload_dir = $conf->stocktransfer->multidir_output[isset($object->entity) ? $object->entity : 1];
91
92// Security check - Protection if external user
93//if ($user->socid > 0) accessforbidden();
94//if ($user->socid > 0) $socid = $user->socid;
95//$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
96//restrictedArea($user, 'stocktransfer', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
97//restrictedArea($user, 'stocktransfer', $object->id, '', 'stocktransfer');
98
99if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) {
101}
102
103
104/*
105 * Add a new contact
106 */
107
108if ($action == 'addcontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) {
109 if ($object->id > 0) {
110 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
111 $result = $object->add_contact($contactid, GETPOST("typecontact") ? GETPOST("typecontact") : GETPOST("type"), GETPOST("source"));
112 }
113
114 if ($result >= 0) {
115 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
116 exit;
117 } else {
118 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
119 $langs->load("errors");
120 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
121 } else {
122 setEventMessages($object->error, $object->errors, 'errors');
123 }
124 }
125} elseif ($action == 'swapstatut' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Toggle the status of a contact
126 if ($object->id > 0) {
127 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
128 }
129} elseif ($action == 'deletecontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Deletes a contact
130 $result = $object->delete_contact($lineid);
131
132 if ($result >= 0) {
133 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
134 exit;
135 } else {
136 dol_print_error($db);
137 }
138}
139
140
141/*
142 * View
143 */
144
145llxHeader('', $langs->trans('ModuleStockTransferName'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
146
147$form = new Form($db);
148$formcompany = new FormCompany($db);
149$formother = new FormOther($db);
150
151if ($object->id > 0) {
152 $head = stocktransferPrepareHead($object);
153 print dol_get_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
154
155
156 // Proposal card
157
158 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
159
160
161 $morehtmlref = '<div class="refidno">';
162 // Thirdparty
163 $morehtmlref .= empty($object->thirdparty) ? '' : $object->thirdparty->getNomUrl(1, 'customer');
164 if (!getDolGlobalInt('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
165 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
166 }
167 // Project
168 if (isModEnabled('project')) {
169 $langs->load("projects");
170 if (!empty($object->fk_project)) {
171 $morehtmlref .= '<br>';
172 $proj = new Project($db);
173 $proj->fetch($object->fk_project);
174 $morehtmlref .= $proj->getNomUrl(1);
175 if ($proj->title) {
176 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
177 }
178 }
179 }
180 $morehtmlref .= '</div>';
181
182 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
183
184 print dol_get_fiche_end();
185
186 $user->rights->stocktransfer->write = $user->hasRight('stocktransfer', 'stocktransfer', 'write');
187 // Contacts lines (modules that overwrite templates must declare this into descriptor)
188 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
189 foreach ($dirtpls as $reldir) {
190 $file = dol_buildpath($reldir.'/contacts.tpl.php');
191 if (file_exists($file)) {
192 $res = @include $file;
193 if ($res) {
194 break;
195 }
196 }
197 }
198}
199
200// End of page
201llxFooter();
202$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
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 permettant la generation de composants html autre Only common components are here.
Class to manage projects.
Class for StockTransfer.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
stocktransferPrepareHead($object)
Prepare array of tabs for StockTransfer.