dolibarr  16.0.1
stocktransfer_contact.php
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 if (!$res && file_exists("../main.inc.php")) $res = @include "../main.inc.php";
29 if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
30 if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
31 if (!$res) die("Include of main fails");
32 require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/lib/stocktransfer_stocktransfer.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('facture', 'orders', 'sendings', 'companies', 'stocks'));
41 
42 $id = GETPOST('id', 'int');
43 $ref = GETPOST('ref', 'alpha');
44 $lineid = GETPOST('lineid', 'int');
45 $action = GETPOST('action', 'alpha');
46 
47 // Security check
48 if ($user->socid) $socid = $user->socid;
49 
50 $result = restrictedArea($user, 'stocktransfer', $id, '', 'stocktransfer');
51 
52 $object = new StockTransfer($db);
53 
54 // Load object
55 if ($id > 0 || !empty($ref)) {
56  $ret = $object->fetch($id, $ref);
57  if ($ret == 0) {
58  $langs->load("errors");
59  setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
60  $error++;
61  } elseif ($ret < 0) {
62  setEventMessages($object->error, $object->errors, 'errors');
63  $error++;
64  }
65 }
66 if (!$error) {
67  $object->fetch_thirdparty();
68 } else {
69  header('Location: '.dol_buildpath('/stocktransfer/stocktransfer_list.php', 1));
70  exit;
71 }
72 
73 
74 /*
75  * Add a new contact
76  */
77 
78 if ($action == 'addcontact' && $user->rights->stocktransfer->stocktransfer->write) {
79  if ($object->id > 0) {
80  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
81  $result = $object->add_contact($contactid, !empty($_POST["typecontact"]) ? $_POST["typecontact"] : $_POST["type"], $_POST["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->rights->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->rights->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 elseif ($action == 'setaddress' && $user->rights->stocktransfer->stocktransfer->write)
111 {
112  $result=$object->setDeliveryAddress($_POST['fk_address']);
113  if ($result < 0) dol_print_error($db,$object->error);
114 }*/
115 
116 
117 /*
118  * View
119  */
120 
121 llxHeader('', $langs->trans('ModuleStockTransferName'), 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
122 
123 $form = new Form($db);
124 $formcompany = new FormCompany($db);
125 $formother = new FormOther($db);
126 
127 if ($object->id > 0) {
128  $head = stocktransferPrepareHead($object);
129  print dol_get_fiche_head($head, 'contact', $langs->trans("StockTransfer"), -1, 'stock');
130 
131 
132  // Proposal card
133 
134  $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
135 
136 
137  $morehtmlref = '<div class="refidno">';
138  // Ref customer
139  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
140  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
141  // Thirdparty
142  if (!empty($object->thirdparty)) {
143  $morehtmlref .= '<br>' . $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'customer');
144  }
145  // Project
146  if (!empty($conf->project->enabled)) {
147  $langs->load("projects");
148  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
149  if ($user->rights->stocktransfer->stocktransfer->write) {
150  if ($action != 'classify') {
151  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a>';
152  $morehtmlref .= ' : ';
153  }
154  if ($action == 'classify') {
155  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
156  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
157  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
158  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
159  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
160  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
161  $morehtmlref .= '</form>';
162  } else {
163  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
164  }
165  } else {
166  if (!empty($object->fk_project)) {
167  $proj = new Project($db);
168  $proj->fetch($object->fk_project);
169  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
170  $morehtmlref .= $proj->ref;
171  $morehtmlref .= '</a>';
172  } else {
173  $morehtmlref .= '';
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->rights->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  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
188  if ($res) break;
189  }
190 }
191 
192 // End of page
193 llxFooter();
194 $db->close();
Class for StockTransfer.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
stocktransferPrepareHead($object)
Prepare array of tabs for StockTransfer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to build HTML component for third parties management Only common components are here...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=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.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:73