dolibarr 24.0.2
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
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
93restrictedArea($user, 'stocktransfer', $object->id, 'stocktransfer_stocktransfer', 'stocktransfer', 'fk_soc', 'rowid');
94
95if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) {
97}
98
99
100/*
101 * Add a new contact
102 */
103
104if ($action == 'addcontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) {
105 $result = -1;
106 if ($object->id > 0) {
107 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
108 $result = $object->add_contact($contactid, GETPOST("typecontact") ? GETPOST("typecontact") : GETPOST("type"), GETPOST("source"));
109 }
110
111 if ($result >= 0) {
112 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
113 exit;
114 } else {
115 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
116 $langs->load("errors");
117 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
118 } else {
119 setEventMessages($object->error, $object->errors, 'errors');
120 }
121 }
122} elseif ($action == 'swapstatut' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Toggle the status of a contact
123 if ($object->id > 0) {
124 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
125 }
126} elseif ($action == 'deletecontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Deletes a contact
127 $result = $object->delete_contact($lineid);
128
129 if ($result >= 0) {
130 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
131 exit;
132 } else {
134 }
135}
136
137
138/*
139 * View
140 */
141
142llxHeader('', $langs->trans('ModuleStockTransferName'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
143
144$form = new Form($db);
145$formcompany = new FormCompany($db);
146$formother = new FormOther($db);
147
148if ($object->id > 0) {
149 $head = stocktransferPrepareHead($object);
150 print dol_get_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
151
152
153 // Proposal card
154
155 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
156
157
158 $morehtmlref = '<div class="refidno">';
159 // Thirdparty
160 $morehtmlref .= empty($object->thirdparty) ? '' : $object->thirdparty->getNomUrl(1, 'customer');
161 if (!getDolGlobalInt('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
162 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'">'.$langs->trans("OtherOrders").'</a>)';
163 }
164 // Project
165 if (isModEnabled('project')) {
166 $langs->load("projects");
167 if (!empty($object->fk_project)) {
168 $morehtmlref .= '<br>';
169 $proj = new Project($db);
170 $proj->fetch($object->fk_project);
171 $morehtmlref .= $proj->getNomUrl(1);
172 if ($proj->title) {
173 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
174 }
175 }
176 }
177 $morehtmlref .= '</div>';
178
179 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
180
181 print dol_get_fiche_end();
182
183 $user->rights->stocktransfer->write = $user->hasRight('stocktransfer', 'stocktransfer', 'write');
184 // Contacts lines (modules that overwrite templates must declare this into descriptor)
185 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
186 foreach ($dirtpls as $reldir) {
187 $file = dol_buildpath($reldir.'/contacts.tpl.php');
188 if (file_exists($file)) {
189 $res = @include $file;
190 if ($res) {
191 break;
192 }
193 }
194 }
195}
196
197// End of page
198llxFooter();
199$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 to help generate other html components Only common components are here.
Class to manage projects.
Class for StockTransfer.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
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.