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