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