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