dolibarr 21.0.0-beta
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 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
34require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
36require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array('facture', 'orders', 'sendings', 'companies', 'stocks'));
48
49$id = GETPOSTINT('id');
50$ref = GETPOST('ref', 'alpha');
51$lineid = GETPOSTINT('lineid');
52
53$action = GETPOST('action', 'alpha');
54
55$object = new StockTransfer($db);
56$error = 0;
57
58// Load object
59//include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
60if ($id > 0 || !empty($ref)) {
61 $ret = $object->fetch($id, $ref);
62 if ($ret == 0) {
63 $langs->load("errors");
64 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
65 $error++;
66 } elseif ($ret < 0) {
67 setEventMessages($object->error, $object->errors, 'errors');
68 $error++;
69 }
70}
71if (!$error) {
72 $object->fetch_thirdparty();
73} else {
74 header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1));
75 exit;
76}
77
78// Security check
79if ($user->socid) {
80 $socid = $user->socid;
81}
82
83
84$permissiontoread = $user->hasRight('stocktransfer', 'stocktransfer', 'read');
85$permissiontoadd = $user->hasRight('stocktransfer', 'stocktransfer', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
86$permissionnote = $user->hasRight('stocktransfer', 'stocktransfer', 'write'); // Used by the include of actions_setnotes.inc.php
87$permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status < $object::STATUS_TRANSFERED);
88$permissiondellink = $user->hasRight('stocktransfer', 'stocktransfer', 'write'); // Used by the include of actions_dellink.inc.php
89$upload_dir = $conf->stocktransfer->multidir_output[isset($object->entity) ? $object->entity : 1];
90
91// Security check - Protection if external user
92//if ($user->socid > 0) accessforbidden();
93//if ($user->socid > 0) $socid = $user->socid;
94//$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
95//$result = restrictedArea($user, 'stocktransfer', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
96//$result = restrictedArea($user, 'stocktransfer', $object->id, '', 'stocktransfer');
97
98if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) {
100}
101
102
103/*
104 * Add a new contact
105 */
106
107if ($action == 'addcontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) {
108 if ($object->id > 0) {
109 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
110 $result = $object->add_contact($contactid, GETPOST("typecontact") ? GETPOST("typecontact") : GETPOST("type"), GETPOST("source"));
111 }
112
113 if ($result >= 0) {
114 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
115 exit;
116 } else {
117 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
118 $langs->load("errors");
119 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
120 } else {
121 setEventMessages($object->error, $object->errors, 'errors');
122 }
123 }
124} elseif ($action == 'swapstatut' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Toggle the status of a contact
125 if ($object->id > 0) {
126 $result = $object->swapContactStatus(GETPOST('ligne'));
127 }
128} elseif ($action == 'deletecontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Deletes a contact
129 $result = $object->delete_contact($lineid);
130
131 if ($result >= 0) {
132 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
133 exit;
134 } else {
135 dol_print_error($db);
136 }
137}
138
139
140/*
141 * View
142 */
143
144llxHeader('', $langs->trans('ModuleStockTransferName'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
145
146$form = new Form($db);
147$formcompany = new FormCompany($db);
148$formother = new FormOther($db);
149
150if ($object->id > 0) {
151 $head = stocktransferPrepareHead($object);
152 print dol_get_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
153
154
155 // Proposal card
156
157 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
158
159
160 $morehtmlref = '<div class="refidno">';
161 // Thirdparty
162 $morehtmlref .= empty($object->thirdparty) ? '' : $object->thirdparty->getNomUrl(1, 'customer');
163 if (!getDolGlobalInt('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
164 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
165 }
166 // Project
167 if (isModEnabled('project')) {
168 $langs->load("projects");
169 if (!empty($object->fk_project)) {
170 $morehtmlref .= '<br>';
171 $proj = new Project($db);
172 $proj->fetch($object->fk_project);
173 $morehtmlref .= $proj->getNomUrl(1);
174 if ($proj->title) {
175 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
176 }
177 }
178 }
179 $morehtmlref .= '</div>';
180
181 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
182
183 print dol_get_fiche_end();
184
185 $user->rights->stocktransfer->write = $user->hasRight('stocktransfer', 'stocktransfer', 'write');
186 // Contacts lines (modules that overwrite templates must declare this into descriptor)
187 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
188 foreach ($dirtpls as $reldir) {
189 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
190 if ($res) {
191 break;
192 }
193 }
194}
195
196// End of page
197llxFooter();
198$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
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.
llxFooter()
Footer empty.
Definition document.php:107
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)
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.