dolibarr  16.0.5
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 require '../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/intracommreport/class/intracommreport.class.php';
40 
41 $langs->loadLangs(array("intracommreport"));
42 
43 $id = GETPOST('id', 'int');
44 $action = GETPOST('action');
45 $exporttype = GETPOSTISSET('exporttype') ? GETPOST('exporttype', 'alphanohtml') : 'deb'; // DEB or DES
46 $year = GETPOSTINT('year');
47 $month = GETPOSTINT('month');
48 $label = (string) GETPOST('label', 'alphanohtml');
49 $type_declaration = (string) GETPOST('type_declaration', 'alphanohtml');
50 $backtopage = GETPOST('backtopage', 'alpha');
51 $declaration = array(
52  "deb" => $langs->trans("DEB"),
53  "des" => $langs->trans("DES"),
54 );
55 $typeOfDeclaration = array(
56  "introduction" => $langs->trans("Introduction"),
57  "expedition" => $langs->trans("Expedition"),
58 );
59 $object = new IntracommReport($db);
60 if ($id > 0) {
61  $object->fetch($id);
62 }
63 $form = new Form($db);
64 $formother = new FormOther($db);
65 
66 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
67 $hookmanager->initHooks(array('intracommcard', 'globalcard'));
68 
69 $error = 0;
70 
71 $permissiontoread = $user->rights->intracommreport->read;
72 $permissiontoadd = $user->rights->intracommreport->write;
73 $permissiontodelete = $user->rights->intracommreport->delete;
74 
75 // Security check (enable the most restrictive one)
76 //if ($user->socid > 0) accessforbidden();
77 //if ($user->socid > 0) $socid = $user->socid;
78 //$isdraft = (isset($object->status) && ($object->status == $object::STATUS_DRAFT) ? 1 : 0);
79 //restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
80 if (empty($conf->intracommreport->enabled)) accessforbidden();
81 if (!$permissiontoread) accessforbidden();
82 
83 
84 
85 /*
86  * Actions
87  */
88 
89 $parameters = array('id' => $id);
90 // Note that $action and $object may have been modified by some hooks
91 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
92 if ($reshook < 0) {
93  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
94 }
95 
96 if ($permissiontodelete && $action == 'confirm_delete' && $confirm == 'yes') {
97  $result = $object->delete($id, $user);
98  if ($result > 0) {
99  if (!empty($backtopage)) {
100  header("Location: ".$backtopage);
101  exit;
102  } else {
103  header("Location: list.php");
104  exit;
105  }
106  } else {
107  $errmesg = $object->error;
108  }
109 }
110 
111 if ($action == 'add' && $permissiontoadd) {
112  $object->label = trim($label);
113  $object->type = trim($exporttype);
114  $object->type_declaration = $type_declaration;
115  $object->subscription = (int) $subscription;
116 
117  // Fill array 'array_options' with data from add form
118  // $ret = $extrafields->setOptionalsFromPost($extralabels, $object);
119  // if ($ret < 0) {
120  // $error++;
121  // }
122 
123  if (empty($object->label)) {
124  $error++;
125  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
126  } else {
127  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."intracommreport WHERE ref='".$db->escape($object->label)."'";
128  $result = $db->query($sql);
129  if ($result) {
130  $num = $db->num_rows($result);
131  }
132  if ($num) {
133  $error++;
134  $langs->load("errors");
135  setEventMessages($langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors');
136  }
137  }
138 
139  if (!$error) {
140  $id = $object->create($user);
141  if ($id > 0) {
142  header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id);
143  exit;
144  } else {
145  setEventMessages($object->error, $object->errors, 'errors');
146  $action = 'create';
147  }
148  } else {
149  $action = 'create';
150  }
151 }
152 
153 
154 /*
155  * View
156  */
157 
158 // Creation mode
159 if ($action == 'create') {
160  $title = $langs->trans("IntracommReportTitle");
161  llxHeader("", $title);
162  print load_fiche_titre($langs->trans("IntracommReportTitle"));
163 
164  print '<form name="charge" method="post" action="'.$_SERVER["PHP_SELF"].'">';
165  print '<input type="hidden" name="token" value="'.newToken().'">';
166  print '<input type="hidden" name="action" value="add" />';
167 
168  print dol_get_fiche_head();
169 
170  print '<table class="border" width="100%">';
171 
172  // Label
173  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" class="minwidth200" name="label" autofocus="autofocus"></td></tr>';
174 
175  // Declaration
176  print '<tr><td class="fieldrequired">'.$langs->trans("Declaration")."</td><td>\n";
177  print $form->selectarray("declaration", $declaration, GETPOST('declaration', 'alpha') ? GETPOST('declaration', 'alpha') : $object->declaration, 0);
178  print "</td>\n";
179 
180  // Analysis period
181  print '<tr>';
182  print '<td class="titlefieldcreate fieldrequired">';
183  print $langs->trans("AnalysisPeriod");
184  print '</td>';
185  print '<td>';
186  print $formother->select_month($month ? date('M') : $month, 'month', 0, 1, 'widthauto valignmiddle ', true);
187  print $formother->selectyear($year ? date('Y') : $year, 'year', 0, 3, 3, 0, 0, '', '', true);
188  print '</td>';
189  print '</tr>';
190 
191  // Type of declaration
192  print '<tr><td class="fieldrequired">'.$langs->trans("TypeOfDeclaration")."</td><td>\n";
193  print $form->selectarray("type_declaration", $typeOfDeclaration, GETPOST('type_declaration', 'alpha') ? GETPOST('type_declaration', 'alpha') : $object->type_declaration, 0);
194  print "</td>\n";
195 
196  print '</table>';
197 
198  print dol_get_fiche_end();
199 
200  print $form->buttonsSaveCancel();
201 
202  print '</form>';
203 }
204 
205 if ($id > 0 && $action != 'edit') {
206  /* ************************************************************************** */
207  /* */
208  /* View mode */
209  /* */
210  /* ************************************************************************** */
211  $res = $object->fetch($id);
212  if ($res < 0) {
213  dol_print_error($db, $object->error);
214  exit;
215  }
216 
217  /*
218  * Show tabs
219  */
220  //$head = intracommreport_prepare_head($object);
221 
222  print dol_get_fiche_head("", 'general', $langs->trans("IntracommReport"), -1, 'user');
223 
224  // Confirm remove report
225  if ($action == 'delete') {
226  $formquestion = array();
227  if ($backtopage) {
228  $formquestion[] = array(
229  'type' => 'hidden',
230  'name' => 'backtopage',
231  'value' => ($backtopage != '1' ? $backtopage : $_SERVER["HTTP_REFERER"])
232  );
233  }
234  print $form->formconfirm(
235  "card.php?rowid=".urlencode($id),
236  $langs->trans("DeleteReport"),
237  $langs->trans("ConfirmDeleteReport"),
238  "confirm_delete",
239  $formquestion,
240  'no',
241  1
242  );
243  }
244 
245  $linkback = '<a href="'.DOL_URL_ROOT.'/intracommreport/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
246 
247  dol_banner_tab($object, 'rowid', $linkback);
248 
249  print '<div class="fichecenter">';
250  print '<div class="fichehalfleft">';
251 
252  print '<div class="underbanner clearboth"></div>';
253  print '<table class="border tableforfield centpercent">';
254 
255  // Type
256  print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$object->declaration."</td></tr>\n";
257 
258  // Analysis Period
259  print '<tr><td>'.$langs->trans("AnalysisPeriod").'</td><td class="valeur">'.$object->period.'</td>';
260  print '</tr>';
261 
262  // Type of Declaration
263  print '<tr><td>'.$langs->trans("TypeOfDeclaration").'</td><td class="valeur">'.$object->type_declaration.'</td>';
264  print '</tr>';
265 
266  print "</table>\n";
267 
268  print "</div></div></div>\n";
269  print '<div style="clear:both"></div>';
270 
271  print dol_get_fiche_end();
272 }
273 
274  /*
275  switch($action) {
276  case 'generateXML':
277  $obj = new TDebProdouane($PDOdb);
278  $obj->load($PDOdb, GETPOST('id_declaration'));
279  $obj->generateXMLFile();
280  break;
281  case 'list':
282  _liste($exporttype);
283  break;
284  case 'export':
285  if ($exporttype == 'deb') _export_xml_deb($type_declaration, $year, str_pad($month, 2, 0, STR_PAD_LEFT));
286  else _export_xml_des($type_declaration, $year, str_pad($month, 2, 0, STR_PAD_LEFT));
287  default:
288  if ($exporttype == 'deb') _print_form_deb();
289  else _print_form_des();
290  break;
291  }
292 
293  function _print_form_des()
294  {
295  global $langs, $formother, $year, $month, $type_declaration;
296 
297  $title = $langs->trans("IntracommReportDESTitle");
298  llxHeader("", $title);
299  print load_fiche_titre($langs->trans("IntracommReportDESTitle"));
300 
301  print dol_get_fiche_head();
302 
303  print '<form action="'.$_SERVER['PHP_SELF'].'" name="save" method="POST">';
304  print '<input type="hidden" name="token" value="'.newToken().'">';
305  print '<input type="hidden" name="action" value="export" />';
306  print '<input type="hidden" name="exporttype" value="des" />';
307  print '<input type="hidden" name="type" value="expedition" />'; // Permet d'utiliser le bon select de la requête sql
308 
309  print '<table width="100%" class="noborder">';
310 
311  print '<tr class="liste_titre"><td colspan="2">';
312  print 'Paramètres de l\'export';
313  print '</td></tr>';
314 
315  print '<tr>';
316  print '<td>Période d\'analyse</td>';
317  print '<td>';
318  $TabMonth = array();
319  for($i=1;$i<=12;$i++) $TabMonth[$i] = $langs->trans('Month'.str_pad($i, 2, 0, STR_PAD_LEFT));
320  //print $ATMform->combo('','month', $TabMonth, empty($month) ? date('m') : $month);
321  print $formother->selectyear(empty($year) ? date('Y') : $year,'year',0, 20, 5);
322  print '</td>';
323  print '</tr>';
324 
325  print '</table>';
326 
327  print '<div class="tabsAction">';
328  print '<input class="butAction" type="submit" value="Exporter XML" />';
329  print '</div>';
330 
331  print '</form>';
332  }
333 
334  function _export_xml_deb($type_declaration, $period_year, $period_month) {
335 
336  global $db, $conf;
337 
338  $obj = new TDebProdouane($db);
339  $obj->entity = $conf->entity;
340  $obj->mode = 'O';
341  $obj->periode = $period_year.'-'.$period_month;
342  $obj->type_declaration = $type_declaration;
343  $obj->numero_declaration = $obj->getNextNumeroDeclaration();
344  $obj->content_xml = $obj->getXML('O', $type_declaration, $period_year.'-'.$period_month);
345  if(empty($obj->errors)) {
346  $obj->save($PDOdb);
347  $obj->generateXMLFile();
348  }
349  else setEventMessage($obj->errors, 'warnings');
350  }
351 
352  function _export_xml_des($type_declaration, $period_year, $period_month) {
353 
354  global $PDOdb, $conf;
355 
356  $obj = new TDebProdouane($PDOdb);
357  $obj->entity = $conf->entity;
358  $obj->periode = $period_year.'-'.$period_month;
359  $obj->type_declaration = $type_declaration;
360  $obj->exporttype = 'des';
361  $obj->numero_declaration = $obj->getNextNumeroDeclaration();
362  $obj->content_xml = $obj->getXMLDes($period_year, $period_month, $type_declaration);
363  if(empty($obj->errors)) {
364  $obj->save($PDOdb);
365  $obj->generateXMLFile();
366  }
367  else setEventMessage($obj->errors, 'warnings');
368  }
369  */
370 
371 // End of page
372 llxFooter();
373 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
IntracommReport
Class to manage intracomm report.
Definition: intracommreport.class.php:31
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
dol_banner_tab
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.
Definition: functions.lib.php:2046
GETPOSTINT
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:795
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$parameters
$parameters
Actions.
Definition: card.php:78
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
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