dolibarr 20.0.0
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$action = GETPOST('action', 'alpha');
44
45$object = new StockTransfer($db);
46
47// Load object
48if ($id > 0 || !empty($ref)) {
49 $ret = $object->fetch($id, $ref);
50 if ($ret == 0) {
51 $langs->load("errors");
52 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
53 $error++;
54 } elseif ($ret < 0) {
55 setEventMessages($object->error, $object->errors, 'errors');
56 $error++;
57 }
58}
59if (!$error) {
60 $object->fetch_thirdparty();
61} else {
62 header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1));
63 exit;
64}
65
66// Security check
67if ($user->socid) {
68 $socid = $user->socid;
69}
70
71$result = restrictedArea($user, 'stocktransfer', $id, '', 'stocktransfer');
72
73
74/*
75 * Add a new contact
76 */
77
78if ($action == 'addcontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) {
79 if ($object->id > 0) {
80 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
81 $result = $object->add_contact($contactid, GETPOST("typecontact") ? GETPOST("typecontact") : GETPOST("type"), GETPOST("source"));
82 }
83
84 if ($result >= 0) {
85 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
86 exit;
87 } else {
88 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
89 $langs->load("errors");
90 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
91 } else {
92 setEventMessages($object->error, $object->errors, 'errors');
93 }
94 }
95} elseif ($action == 'swapstatut' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Toggle the status of a contact
96 if ($object->id > 0) {
97 $result = $object->swapContactStatus(GETPOST('ligne'));
98 }
99} elseif ($action == 'deletecontact' && $user->hasRight('stocktransfer', 'stocktransfer', 'write')) { // Deletes a contact
100 $result = $object->delete_contact($lineid);
101
102 if ($result >= 0) {
103 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
104 exit;
105 } else {
106 dol_print_error($db);
107 }
108}
109
110
111/*
112 * View
113 */
114
115llxHeader('', $langs->trans('ModuleStockTransferName'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
116
117$form = new Form($db);
118$formcompany = new FormCompany($db);
119$formother = new FormOther($db);
120
121if ($object->id > 0) {
122 $head = stocktransferPrepareHead($object);
123 print dol_get_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
124
125
126 // Proposal card
127
128 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
129
130
131 $morehtmlref = '<div class="refidno">';
132 // Thirdparty
133 $morehtmlref .= empty($object->thirdparty) ? '' : $object->thirdparty->getNomUrl(1, 'customer');
134 if (!getDolGlobalInt('MAIN_DISABLE_OTHER_LINK') && $object->thirdparty->id > 0) {
135 $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->thirdparty->id.'&search_societe='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherOrders").'</a>)';
136 }
137 // Project
138 if (isModEnabled('project')) {
139 $langs->load("projects");
140 if (!empty($object->fk_project)) {
141 $morehtmlref .= '<br>';
142 $proj = new Project($db);
143 $proj->fetch($object->fk_project);
144 $morehtmlref .= $proj->getNomUrl(1);
145 if ($proj->title) {
146 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
147 }
148 }
149 }
150 $morehtmlref .= '</div>';
151
152 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
153
154 print dol_get_fiche_end();
155
156 $user->rights->stocktransfer->write = $user->hasRight('stocktransfer', 'stocktransfer', 'write');
157 // Contacts lines (modules that overwrite templates must declare this into descriptor)
158 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
159 foreach ($dirtpls as $reldir) {
160 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
161 if ($res) {
162 break;
163 }
164 }
165}
166
167// End of page
168llxFooter();
169$db->close();
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()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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...
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.