dolibarr 19.0.4
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2015 ATM Consulting <support@atm-consulting.fr>
3 * Copyright (C) 2019-2020 Open-DSI <support@open-dsi.fr>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
36// Load Dolibarr environment
37require '../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
40require_once DOL_DOCUMENT_ROOT.'/intracommreport/class/intracommreport.class.php';
41
42// Load translation files required by the page
43$langs->loadLangs(array("intracommreport"));
44
45// Get Parameters
46$id = GETPOST('id', 'int');
47$action = GETPOST('action');
48$year = GETPOSTINT('year');
49$month = GETPOSTINT('month');
50$label = (string) GETPOST('label', 'alphanohtml');
51
52$exporttype = GETPOSTISSET('exporttype') ? GETPOST('exporttype', 'alphanohtml') : 'deb'; // DEB or DES
53$type_declaration = (string) GETPOST('type_declaration', 'alphanohtml'); // 'introduction' or 'expedition'
54
55$backtopage = GETPOST('backtopage', 'alpha');
56
57$declaration = array(
58 "deb" => $langs->trans("DEB"),
59 "des" => $langs->trans("DES"),
60);
61
62$typeOfDeclaration = array(
63 "introduction" => $langs->trans("Introduction"),
64 "expedition" => $langs->trans("Expedition"),
65);
66
67// Initialize technical objects
68$object = new IntracommReport($db);
69if ($id > 0) {
70 $object->fetch($id);
71}
72$form = new Form($db);
73$formother = new FormOther($db);
74
75// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
76$hookmanager->initHooks(array('intracommcard', 'globalcard'));
77
78$error = 0;
79
80// Permissions
81$permissiontoread = $user->rights->intracommreport->read;
82$permissiontoadd = $user->rights->intracommreport->write;
83$permissiontodelete = $user->rights->intracommreport->delete;
84
85// Security check (enable the most restrictive one)
86//if ($user->socid > 0) accessforbidden();
87//if ($user->socid > 0) $socid = $user->socid;
88//$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0);
89//restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
90if (empty($conf->intracommreport->enabled)) {
92}
93if (!$permissiontoread) {
95}
96
97
98
99/*
100 * Actions
101 */
102
103$parameters = array('id' => $id);
104// Note that $action and $object may have been modified by some hooks
105$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
106if ($reshook < 0) {
107 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
108}
109
110if ($permissiontodelete && $action == 'confirm_delete' && $confirm == 'yes') {
111 $result = $object->delete($id, $user);
112 if ($result > 0) {
113 if (!empty($backtopage)) {
114 header("Location: ".$backtopage);
115 exit;
116 } else {
117 header("Location: list.php");
118 exit;
119 }
120 } else {
121 $errmesg = $object->error;
122 }
123}
124
125if ($action == 'add' && $permissiontoadd) {
126 $object->label = trim($label);
127 $object->exporttype = trim($exporttype); // 'des' or 'deb'
128 $object->type_declaration = $type_declaration; // 'introduction' or 'expedition'
129 //$object->subscription = (int) $subscription;
130
131 // Fill array 'array_options' with data from add form
132 // $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
133 // if ($ret < 0) {
134 // $error++;
135 // }
136
137 if (empty($object->label)) {
138 $error++;
139 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
140 } else {
141 $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."intracommreport WHERE ref='".$db->escape($object->label)."'";
142 $result = $db->query($sql);
143 if ($result) {
144 $num = $db->num_rows($result);
145 }
146 if ($num) {
147 $error++;
148 $langs->load("errors");
149 setEventMessages($langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors');
150 }
151 }
152
153 if (!$error) {
154 $id = $object->create($user);
155 if ($id > 0) {
156 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id);
157 exit;
158 } else {
159 setEventMessages($object->error, $object->errors, 'errors');
160 $action = 'create';
161 }
162 } else {
163 $action = 'create';
164 }
165}
166
167
168/*
169 * View
170 */
171
172$title = $langs->trans("IntracommReportTitle");
173llxHeader("", $title);
174
175// Creation mode
176if ($action == 'create') {
177 print load_fiche_titre($langs->trans("IntracommReportTitle"));
178
179 print '<form name="charge" method="post" action="'.$_SERVER["PHP_SELF"].'">';
180 print '<input type="hidden" name="token" value="'.newToken().'">';
181 print '<input type="hidden" name="action" value="add" />';
182
183 print dol_get_fiche_head();
184
185 print '<table class="border" width="100%">';
186
187 // Label
188 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" class="minwidth200" name="label" autofocus="autofocus"></td></tr>';
189
190 // Declaration
191 print '<tr><td class="fieldrequired">'.$langs->trans("Declaration")."</td><td>\n";
192 print $form->selectarray("declaration", $declaration, GETPOST('declaration', 'alpha') ? GETPOST('declaration', 'alpha') : $object->declaration, 0);
193 print "</td>\n";
194
195 // Analysis period
196 print '<tr>';
197 print '<td class="titlefieldcreate fieldrequired">';
198 print $langs->trans("AnalysisPeriod");
199 print '</td>';
200 print '<td>';
201 print $formother->select_month($month ? date('M') : $month, 'month', 0, 1, 'widthauto valignmiddle ', true);
202 print $formother->selectyear($year ? date('Y') : $year, 'year', 0, 3, 3, 0, 0, '', '', true);
203 print '</td>';
204 print '</tr>';
205
206 // Type of declaration
207 print '<tr><td class="fieldrequired">'.$langs->trans("TypeOfDeclaration")."</td><td>\n";
208 print $form->selectarray("type_declaration", $typeOfDeclaration, GETPOST('type_declaration', 'alpha') ? GETPOST('type_declaration', 'alpha') : $object->type_declaration, 0);
209 print "</td>\n";
210
211 print '</table>';
212
213 print dol_get_fiche_end();
214
215 print $form->buttonsSaveCancel();
216
217 print '</form>';
218}
219
220if ($id > 0 && $action != 'edit') {
221 /* ************************************************************************** */
222 /* */
223 /* View mode */
224 /* */
225 /* ************************************************************************** */
226 $res = $object->fetch($id);
227 if ($res < 0) {
228 dol_print_error($db, $object->error);
229 exit;
230 }
231
232 /*
233 * Show tabs
234 */
235 //$head = intracommreport_prepare_head($object);
236
237 print dol_get_fiche_head("", 'general', $langs->trans("IntracommReport"), -1, 'user');
238
239 // Confirm remove report
240 if ($action == 'delete') {
241 $formquestion = array();
242 if ($backtopage) {
243 $formquestion[] = array(
244 'type' => 'hidden',
245 'name' => 'backtopage',
246 'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])
247 );
248 }
249 print $form->formconfirm(
250 "card.php?rowid=".urlencode($id),
251 $langs->trans("DeleteReport"),
252 $langs->trans("ConfirmDeleteReport"),
253 "confirm_delete",
254 $formquestion,
255 'no',
256 1
257 );
258 }
259
260 $linkback = '<a href="'.DOL_URL_ROOT.'/intracommreport/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
261
262 dol_banner_tab($object, 'rowid', $linkback);
263
264 print '<div class="fichecenter">';
265 print '<div class="fichehalfleft">';
266
267 print '<div class="underbanner clearboth"></div>';
268 print '<table class="border tableforfield centpercent">';
269
270 // Type
271 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$object->declaration."</td></tr>\n";
272
273 // Analysis period
274 print '<tr><td>'.$langs->trans("AnalysisPeriod").'</td><td class="valeur">'.$object->period.'</td>';
275 print '</tr>';
276
277 // Type of Declaration
278 print '<tr><td>'.$langs->trans("TypeOfDeclaration").'</td><td class="valeur">'.$object->exporttype.'</td>';
279 print '</tr>';
280
281 print "</table>\n";
282
283 print "</div></div></div>\n";
284 print '<div class="clearboth"></div>';
285
286 print dol_get_fiche_end();
287}
288
289// End of page
290llxFooter();
291$db->close();
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 manage generation of HTML components Only common components must be here.
Classe permettant la generation de composants html autre Only common components are here.
Class to manage intracomm report.
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
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_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.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.