dolibarr 21.0.0-alpha
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 *
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
29require '../../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
33require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
35require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
36
37// Load translation files required by the page
38$langs->loadLangs(array('facture', 'orders', 'sendings', 'companies', 'stocks'));
39
40$id = GETPOSTINT('id');
41$ref = GETPOST('ref', 'alpha');
42$lineid = GETPOSTINT('lineid');
43
44$action = GETPOST('action', 'alpha');
45
46$object = new StockTransfer($db);
47
48// Load object
49//include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'.
50if ($id > 0 || !empty($ref)) {
51 $ret = $object->fetch($id, $ref);
52 if ($ret == 0) {
53 $langs->load("errors");
54 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
55 $error++;
56 } elseif ($ret < 0) {
57 setEventMessages($object->error, $object->errors, 'errors');
58 $error++;
59 }
60}
61if (!$error) {
62 $object->fetch_thirdparty();
63} else {
64 header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1));
65 exit;
66}
67
68// Security check
69if ($user->socid) {
70 $socid = $user->socid;
71}
72
73
74$permissiontoread = $user->hasRight('stocktransfer', 'stocktransfer', 'read');
75$permissiontoadd = $user->hasRight('stocktransfer', 'stocktransfer', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
76$permissionnote = $user->hasRight('stocktransfer', 'stocktransfer', 'write'); // Used by the include of actions_setnotes.inc.php
77$permissiontodelete = $user->rights->stocktransfer->stocktransfer->delete || ($permissiontoadd && isset($object->status) && $object->status < $object::STATUS_TRANSFERED);
78$permissiondellink = $user->hasRight('stocktransfer', 'stocktransfer', 'write'); // Used by the include of actions_dellink.inc.php
79$upload_dir = $conf->stocktransfer->multidir_output[isset($object->entity) ? $object->entity : 1];
80
81// Security check - Protection if external user
82//if ($user->socid > 0) accessforbidden();
83//if ($user->socid > 0) $socid = $user->socid;
84//$isdraft = (($object->statut == $object::STATUS_DRAFT) ? 1 : 0);
85//$result = restrictedArea($user, 'stocktransfer', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
86//$result = restrictedArea($user, 'stocktransfer', $object->id, '', 'stocktransfer');
87
88if (!$permissiontoread || ($action === 'create' && !$permissiontoadd)) {
90}
91
92
93/*
94 * Add a new contact
95 */
96
97if ($action == 'addcontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) {
98 if ($object->id > 0) {
99 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
100 $result = $object->add_contact($contactid, GETPOST("typecontact") ? GETPOST("typecontact") : GETPOST("type"), GETPOST("source"));
101 }
102
103 if ($result >= 0) {
104 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
105 exit;
106 } else {
107 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
108 $langs->load("errors");
109 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
110 } else {
111 setEventMessages($object->error, $object->errors, 'errors');
112 }
113 }
114} elseif ($action == 'swapstatut' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Toggle the status of a contact
115 if ($object->id > 0) {
116 $result = $object->swapContactStatus(GETPOST('ligne'));
117 }
118} elseif ($action == 'deletecontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Deletes a contact
119 $result = $object->delete_contact($lineid);
120
121 if ($result >= 0) {
122 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
123 exit;
124 } else {
125 dol_print_error($db);
126 }
127}
128
129
130/*
131 * View
132 */
133
134llxHeader('', $langs->trans('ModuleStockTransferName'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
135
136$form = new Form($db);
137$formcompany = new FormCompany($db);
138$formother = new FormOther($db);
139
140if ($object->id > 0) {
141 $head = stocktransferPrepareHead($object);
142 print dol_get_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
143
144
145 // Proposal card
146
147 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
148
149
150 $morehtmlref = '<div class="refidno">';
151 // Thirdparty
152 $morehtmlref .= empty($object->thirdparty) ? '' : $object->thirdparty->getNomUrl(1, 'customer');
153 if (!getDolGlobalInt('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
154 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
155 }
156 // Project
157 if (isModEnabled('project')) {
158 $langs->load("projects");
159 if (!empty($object->fk_project)) {
160 $morehtmlref .= '<br>';
161 $proj = new Project($db);
162 $proj->fetch($object->fk_project);
163 $morehtmlref .= $proj->getNomUrl(1);
164 if ($proj->title) {
165 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
166 }
167 }
168 }
169 $morehtmlref .= '</div>';
170
171 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
172
173 print dol_get_fiche_end();
174
175 $user->rights->stocktransfer->write = $user->hasRight('stocktransfer', 'stocktransfer', 'write');
176 // Contacts lines (modules that overwrite templates must declare this into descriptor)
177 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
178 foreach ($dirtpls as $reldir) {
179 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
180 if ($res) {
181 break;
182 }
183 }
184}
185
186// End of page
187llxFooter();
188$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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: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.
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...
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.