dolibarr  7.0.0-beta
api_setup.class.php
1 <?php
2 /* Copyright (C) 2016 Xebax Christy <xebax@wanadoo.fr>
3  * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2017 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2017 Neil Orley <neil.orley@oeris.fr>
6  *
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 use Luracast\Restler\RestException;
23 
24 require_once DOL_DOCUMENT_ROOT.'/main.inc.php';
25 require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
26 
33 class Setup extends DolibarrApi
34 {
35  private $translations = null;
36 
40  function __construct()
41  {
42  global $db;
43  $this->db = $db;
44  }
45 
63  function getPaymentTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
64  {
65  $list = array();
66 
67  $sql = "SELECT id, code, type, libelle as label, module";
68  $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement as t";
69  $sql.= " WHERE t.active = ".$active;
70  // Add sql filters
71  if ($sqlfilters)
72  {
73  if (! DolibarrApi::_checkFilters($sqlfilters))
74  {
75  throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
76  }
77  $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
78  $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
79  }
80 
81 
82  $sql.= $this->db->order($sortfield, $sortorder);
83 
84  if ($limit) {
85  if ($page < 0) {
86  $page = 0;
87  }
88  $offset = $limit * $page;
89 
90  $sql .= $this->db->plimit($limit, $offset);
91  }
92 
93  $result = $this->db->query($sql);
94 
95  if ($result) {
96  $num = $this->db->num_rows($result);
97  $min = min($num, ($limit <= 0 ? $num : $limit));
98  for ($i = 0; $i < $min; $i++) {
99  $list[] = $this->db->fetch_object($result);
100  }
101  } else {
102  throw new RestException(400, $this->db->lasterror());
103  }
104 
105  return $list;
106  }
107 
129  function getListOfCountries($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $lang = '', $sqlfilters = '')
130  {
131  $list = array();
132 
133  // Note: The filter is not applied in the SQL request because it must
134  // be applied to the translated names, not to the names in database.
135  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t";
136  $sql.=" WHERE 1 = 1";
137  // Add sql filters
138  if ($sqlfilters)
139  {
140  if (! DolibarrApi::_checkFilters($sqlfilters))
141  {
142  throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
143  }
144  $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
145  $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
146  }
147 
148  $sql.= $this->db->order($sortfield, $sortorder);
149 
150  if ($limit) {
151  if ($page < 0) {
152  $page = 0;
153  }
154  $offset = $limit * $page;
155 
156  $sql .= $this->db->plimit($limit, $offset);
157  }
158 
159  $result = $this->db->query($sql);
160 
161  if ($result) {
162  $num = $this->db->num_rows($result);
163  $min = min($num, ($limit <= 0 ? $num : $limit));
164  for ($i = 0; $i < $min; $i++) {
165  $obj = $this->db->fetch_object($result);
166  $country = new Ccountry($this->db);
167  if ($country->fetch($obj->rowid) > 0) {
168  // Translate the name of the country if needed
169  // and then apply the filter if there is one.
170  $this->translateLabel($country, $lang);
171 
172  if (empty($filter) || stripos($country->label, $filter) !== FALSE) {
173  $list[] = $this->_cleanObjectDatas($country);
174  }
175  }
176  }
177  } else {
178  throw new RestException(503, 'Error when retrieving list of countries : '.$country->error);
179  }
180 
181  return $list;
182  }
183 
195  function getCountryByID($id, $lang = '')
196  {
197  $country = new Ccountry($this->db);
198 
199  if ($country->fetch($id) < 0) {
200  throw new RestException(503, 'Error when retrieving country : '.$country->error);
201  }
202  else if ($country->fetch($id) == 0) {
203  throw new RestException(404, 'country not found');
204  }
205 
206  $this->translateLabel($country, $lang);
207 
208  return $this->_cleanObjectDatas($country);
209  }
210 
228  function getAvailability($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
229  {
230  $list = array();
231 
232  $sql = "SELECT rowid, code, label";
233  $sql.= " FROM ".MAIN_DB_PREFIX."c_availability as t";
234  $sql.= " WHERE t.active = ".$active;
235  // Add sql filters
236  if ($sqlfilters)
237  {
238  if (! DolibarrApi::_checkFilters($sqlfilters))
239  {
240  throw new RestException(400, 'error when validating parameter sqlfilters '.$sqlfilters);
241  }
242  $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
243  $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
244  }
245 
246 
247  $sql.= $this->db->order($sortfield, $sortorder);
248 
249  if ($limit) {
250  if ($page < 0) {
251  $page = 0;
252  }
253  $offset = $limit * $page;
254 
255  $sql .= $this->db->plimit($limit, $offset);
256  }
257 
258  $result = $this->db->query($sql);
259 
260  if ($result) {
261  $num = $this->db->num_rows($result);
262  $min = min($num, ($limit <= 0 ? $num : $limit));
263  for ($i = 0; $i < $min; $i++) {
264  $list[] = $this->db->fetch_object($result);
265  }
266  } else {
267  throw new RestException(400, $this->db->lasterror());
268  }
269 
270  return $list;
271  }
272 
279  function _cleanObjectDatas($object)
280  {
281  $object = parent::_cleanObjectDatas($object);
282 
283  unset($object->error);
284  unset($object->errors);
285 
286  return $object;
287  }
288 
296  private function translateLabel($country, $lang)
297  {
298  if (!empty($lang)) {
299  // Load the translations if this is a new language.
300  if ($this->translations == null || $this->translations->getDefaultLang() !== $lang) {
301  global $conf;
302  $this->translations = new Translate('', $conf);
303  $this->translations->setDefaultLang($lang);
304  $this->translations->load('dict');
305  }
306  if ($country->code) {
307  $key = 'Country'.$country->code;
308  $translation = $this->translations->trans($key);
309  if ($translation != $key) {
310  $country->label = html_entity_decode($translation);
311  }
312  }
313  }
314  }
315 
332  function getListOfEventTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $sqlfilters = '')
333  {
334  $list = array();
335 
336  $sql = "SELECT id, code, type, libelle as label, module";
337  $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
338  $sql.= " WHERE t.active = 1";
339  if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
340  if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
341  // Add sql filters
342  if ($sqlfilters)
343  {
344  if (! DolibarrApi::_checkFilters($sqlfilters))
345  {
346  throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
347  }
348  $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
349  $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
350  }
351 
352 
353  $sql.= $this->db->order($sortfield, $sortorder);
354 
355  if ($limit) {
356  if ($page < 0) {
357  $page = 0;
358  }
359  $offset = $limit * $page;
360 
361  $sql .= $this->db->plimit($limit, $offset);
362  }
363 
364  $result = $this->db->query($sql);
365 
366  if ($result) {
367  $num = $this->db->num_rows($result);
368  $min = min($num, ($limit <= 0 ? $num : $limit));
369  for ($i = 0; $i < $min; $i++) {
370  $list[] = $this->db->fetch_object($result);
371  }
372  } else {
373  throw new RestException(503, 'Error when retrieving list of events types : '.$this->db->lasterror());
374  }
375 
376  return $list;
377  }
378 
379 
393  function getListOfExtrafields($sortfield = "t.pos", $sortorder = 'ASC', $type = '', $sqlfilters = '')
394  {
395  $list = array();
396 
397  if ($type == 'thirdparty') $type='societe';
398  if ($type == 'contact') $type='socpeople';
399 
400  $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed";
401  $sql.= " FROM ".MAIN_DB_PREFIX."extrafields as t";
402  $sql.= " WHERE t.entity IN (".getEntity('extrafields').")";
403  if (! empty($type)) $sql.= " AND t.elementtype = '".$this->db->escape($type)."'";
404  // Add sql filters
405  if ($sqlfilters)
406  {
407  if (! DolibarrApi::_checkFilters($sqlfilters))
408  {
409  throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
410  }
411  $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
412  $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
413  }
414 
415  $sql.= $this->db->order($sortfield, $sortorder);
416 
417  $resql=$this->db->query($sql);
418  if ($resql)
419  {
420  if ($this->db->num_rows($resql))
421  {
422  while ($tab = $this->db->fetch_object($resql))
423  {
424  // New usage
425  $list[$tab->elementtype][$tab->name]['type']=$tab->type;
426  $list[$tab->elementtype][$tab->name]['label']=$tab->label;
427  $list[$tab->elementtype][$tab->name]['size']=$tab->size;
428  $list[$tab->elementtype][$tab->name]['elementtype']=$tab->elementtype;
429  $list[$tab->elementtype][$tab->name]['default']=$tab->fielddefault;
430  $list[$tab->elementtype][$tab->name]['computed']=$tab->fieldcomputed;
431  $list[$tab->elementtype][$tab->name]['unique']=$tab->fieldunique;
432  $list[$tab->elementtype][$tab->name]['required']=$tab->fieldrequired;
433  $list[$tab->elementtype][$tab->name]['param']=($tab->param ? unserialize($tab->param) : '');
434  $list[$tab->elementtype][$tab->name]['pos']=$tab->pos;
435  $list[$tab->elementtype][$tab->name]['alwayseditable']=$tab->alwayseditable;
436  $list[$tab->elementtype][$tab->name]['perms']=$tab->perms;
437  $list[$tab->elementtype][$tab->name]['list']=$tab->list;
438  }
439  }
440  }
441  else
442  {
443  throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror());
444  }
445 
446  if (! count($list))
447  {
448  throw new RestException(404, 'No extrafield found');
449  }
450 
451  return $list;
452  }
453 
454 
471  function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $sqlfilters = '')
472  {
473  $list = array();
474 
475  $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
476  $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
477  $sql.= " WHERE t.active = 1";
478  if ($zipcode) $sql.=" AND t.zip LIKE '%" . $this->db->escape($zipcode) . "%'";
479  if ($town) $sql.=" AND t.town LIKE '%" . $this->db->escape($town) . "%'";
480  // Add sql filters
481  if ($sqlfilters)
482  {
483  if (! DolibarrApi::_checkFilters($sqlfilters))
484  {
485  throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
486  }
487  $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
488  $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
489  }
490 
491 
492  $sql.= $this->db->order($sortfield, $sortorder);
493 
494  if ($limit) {
495  if ($page < 0) {
496  $page = 0;
497  }
498  $offset = $limit * $page;
499 
500  $sql .= $this->db->plimit($limit, $offset);
501  }
502 
503  $result = $this->db->query($sql);
504 
505  if ($result) {
506  $num = $this->db->num_rows($result);
507  $min = min($num, ($limit <= 0 ? $num : $limit));
508  for ($i = 0; $i < $min; $i++) {
509  $list[] = $this->db->fetch_object($result);
510  }
511  } else {
512  throw new RestException(503, 'Error when retrieving list of towns : '.$this->db->lasterror());
513  }
514 
515  return $list;
516  }
517 
535  function getPaymentTerms($sortfield = "sortorder", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
536  {
537  $list = array();
538 
539  $sql = "SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
540  $sql.= " FROM ".MAIN_DB_PREFIX."c_payment_term as t";
541  $sql.= " WHERE t.active = ".$active;
542  // Add sql filters
543  if ($sqlfilters)
544  {
545  if (! DolibarrApi::_checkFilters($sqlfilters))
546  {
547  throw new RestException(400, 'Error when validating parameter sqlfilters '.$sqlfilters);
548  }
549  $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
550  $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
551  }
552 
553 
554  $sql.= $this->db->order($sortfield, $sortorder);
555 
556  if ($limit) {
557  if ($page < 0) {
558  $page = 0;
559  }
560  $offset = $limit * $page;
561 
562  $sql .= $this->db->plimit($limit, $offset);
563  }
564 
565  $result = $this->db->query($sql);
566 
567  if ($result) {
568  $num = $this->db->num_rows($result);
569  $min = min($num, ($limit <= 0 ? $num : $limit));
570  for ($i = 0; $i < $min; $i++) {
571  $list[] = $this->db->fetch_object($result);
572  }
573  } else {
574  throw new RestException(400, $this->db->lasterror());
575  }
576 
577  return $list;
578  }
579 
580 
591  function getCheckIntegrity($target)
592  {
593  global $langs, $conf;
594 
595  if (! DolibarrApiAccess::$user->admin
596  && (empty($conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK))
597  {
598  throw new RestException(503, 'Error API open to admin users only or to login user defined with constant API_LOGIN_ALLOWED_FOR_INTEGRITY_CHECK');
599  }
600 
601  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
602  require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
603 
604  $langs->load("admin");
605 
606  $outexpectedchecksum = '';
607  $outcurrentchecksum = '';
608 
609  // Modified or missing files
610  $file_list = array('missing' => array(), 'updated' => array());
611 
612  // Local file to compare to
613  $xmlshortfile = GETPOST('xmlshortfile')?GETPOST('xmlshortfile'):'/install/filelist-'.DOL_VERSION.'.xml';
614  $xmlfile = DOL_DOCUMENT_ROOT.$xmlshortfile;
615  // Remote file to compare to
616  $xmlremote = ($target == 'default' ? '' : $target);
617  if (empty($xmlremote) && ! empty($conf->global->MAIN_FILECHECK_URL)) $xmlremote = $conf->global->MAIN_FILECHECK_URL;
618  $param='MAIN_FILECHECK_URL_'.DOL_VERSION;
619  if (empty($xmlremote) && ! empty($conf->global->$param)) $xmlremote = $conf->global->$param;
620  if (empty($xmlremote)) $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
621 
622  if ($target == 'local')
623  {
624  if (dol_is_file($xmlfile))
625  {
626  $xml = simplexml_load_file($xmlfile);
627  }
628  else
629  {
630  throw new RestException(500, $langs->trans('XmlNotFound') . ': ' . $xmlfile);
631  }
632  }
633  else
634  {
635  $xmlarray = getURLContent($xmlremote);
636 
637  // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
638  if (! $xmlarray['curl_error_no'] && $xmlarray['http_code'] != '404')
639  {
640  $xmlfile = $xmlarray['content'];
641  //print "eee".$xmlfile."eee";
642  $xml = simplexml_load_string($xmlfile);
643  }
644  else
645  {
646  $errormsg=$langs->trans('XmlNotFound') . ': ' . $xmlremote.' - '.$xmlarray['http_code'].' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
647  throw new RestException(500, $errormsg);
648  }
649  }
650 
651 
652 
653  if ($xml)
654  {
655  $checksumconcat = array();
656  $file_list = array();
657  $out = '';
658 
659  // Forced constants
660  if (is_object($xml->dolibarr_constants[0]))
661  {
662  $out.=load_fiche_titre($langs->trans("ForcedConstants"));
663 
664  $out.='<div class="div-table-responsive-no-min">';
665  $out.='<table class="noborder">';
666  $out.='<tr class="liste_titre">';
667  $out.='<td>#</td>';
668  $out.='<td>' . $langs->trans("Constant") . '</td>';
669  $out.='<td align="center">' . $langs->trans("ExpectedValue") . '</td>';
670  $out.='<td align="center">' . $langs->trans("Value") . '</td>';
671  $out.='</tr>'."\n";
672 
673  $i = 0;
674  foreach ($xml->dolibarr_constants[0]->constant as $constant) // $constant is a simpleXMLElement
675  {
676  $constname=$constant['name'];
677  $constvalue=(string) $constant;
678  $constvalue = (empty($constvalue)?'0':$constvalue);
679  // Value found
680  $value='';
681  if ($constname && $conf->global->$constname != '') $value=$conf->global->$constname;
682  $valueforchecksum=(empty($value)?'0':$value);
683 
684  $checksumconcat[]=$valueforchecksum;
685 
686  $i++;
687  $out.='<tr class="oddeven">';
688  $out.='<td>'.$i.'</td>' . "\n";
689  $out.='<td>'.$constname.'</td>' . "\n";
690  $out.='<td align="center">'.$constvalue.'</td>' . "\n";
691  $out.='<td align="center">'.$valueforchecksum.'</td>' . "\n";
692  $out.="</tr>\n";
693  }
694 
695  if ($i==0)
696  {
697  $out.='<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
698  }
699  $out.='</table>';
700  $out.='</div>';
701 
702  $out.='<br>';
703  }
704 
705  // Scan htdocs
706  if (is_object($xml->dolibarr_htdocs_dir[0]))
707  {
708  //var_dump($xml->dolibarr_htdocs_dir[0]['includecustom']);exit;
709  $includecustom=(empty($xml->dolibarr_htdocs_dir[0]['includecustom'])?0:$xml->dolibarr_htdocs_dir[0]['includecustom']);
710 
711  // Defined qualified files (must be same than into generate_filelist_xml.php)
712  $regextoinclude='\.(php|css|html|js|json|tpl|jpg|png|gif|sql|lang)$';
713  $regextoexclude='('.($includecustom?'':'custom|').'documents|conf|install|public\/test|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs
714  $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude);
715 
716  // Fill file_list with files in signature, new files, modified files
717  $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat, $scanfiles); // Fill array $file_list
718  // Complete with list of new files
719  foreach ($scanfiles as $keyfile => $valfile)
720  {
721  $tmprelativefilename=preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT,'/').'/','', $valfile['fullname']);
722  if (! in_array($tmprelativefilename, $file_list['insignature']))
723  {
724  $md5newfile=@md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file
725  $file_list['added'][]=array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
726  }
727  }
728 
729  // Files missings
730  $out.=load_fiche_titre($langs->trans("FilesMissing"));
731 
732  $out.='<div class="div-table-responsive-no-min">';
733  $out.='<table class="noborder">';
734  $out.='<tr class="liste_titre">';
735  $out.='<td>#</td>';
736  $out.='<td>' . $langs->trans("Filename") . '</td>';
737  $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
738  $out.='</tr>'."\n";
739  $tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
740  if (is_array($tmpfilelist) && count($tmpfilelist))
741  {
742  $i = 0;
743  foreach ($tmpfilelist as $file)
744  {
745  $i++;
746  $out.='<tr class="oddeven">';
747  $out.='<td>'.$i.'</td>' . "\n";
748  $out.='<td>'.$file['filename'].'</td>' . "\n";
749  $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
750  $out.="</tr>\n";
751  }
752  }
753  else
754  {
755  $out.='<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
756  }
757  $out.='</table>';
758  $out.='</div>';
759 
760  $out.='<br>';
761 
762  // Files modified
763  $out.=load_fiche_titre($langs->trans("FilesModified"));
764 
765  $totalsize=0;
766  $out.='<div class="div-table-responsive-no-min">';
767  $out.='<table class="noborder">';
768  $out.='<tr class="liste_titre">';
769  $out.='<td>#</td>';
770  $out.='<td>' . $langs->trans("Filename") . '</td>';
771  $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
772  $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>';
773  $out.='<td align="right">' . $langs->trans("Size") . '</td>';
774  $out.='<td align="right">' . $langs->trans("DateModification") . '</td>';
775  $out.='</tr>'."\n";
776  $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename');
777  if (is_array($tmpfilelist2) && count($tmpfilelist2))
778  {
779  $i = 0;
780  foreach ($tmpfilelist2 as $file)
781  {
782  $i++;
783  $out.='<tr class="oddeven">';
784  $out.='<td>'.$i.'</td>' . "\n";
785  $out.='<td>'.$file['filename'].'</td>' . "\n";
786  $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
787  $out.='<td align="center">'.$file['md5'].'</td>' . "\n";
788  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
789  $totalsize += $size;
790  $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n";
791  $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n";
792  $out.="</tr>\n";
793  }
794  $out.='<tr class="liste_total">';
795  $out.='<td></td>' . "\n";
796  $out.='<td>'.$langs->trans("Total").'</td>' . "\n";
797  $out.='<td align="center"></td>' . "\n";
798  $out.='<td align="center"></td>' . "\n";
799  $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
800  $out.='<td align="right"></td>' . "\n";
801  $out.="</tr>\n";
802  }
803  else
804  {
805  $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
806  }
807  $out.='</table>';
808  $out.='</div>';
809 
810  $out.='<br>';
811 
812  // Files added
813  $out.=load_fiche_titre($langs->trans("FilesAdded"));
814 
815  $totalsize = 0;
816  $out.='<div class="div-table-responsive-no-min">';
817  $out.='<table class="noborder">';
818  $out.='<tr class="liste_titre">';
819  $out.='<td>#</td>';
820  $out.='<td>' . $langs->trans("Filename") . '</td>';
821  $out.='<td align="center">' . $langs->trans("ExpectedChecksum") . '</td>';
822  $out.='<td align="center">' . $langs->trans("CurrentChecksum") . '</td>';
823  $out.='<td align="right">' . $langs->trans("Size") . '</td>';
824  $out.='<td align="right">' . $langs->trans("DateModification") . '</td>';
825  $out.='</tr>'."\n";
826  $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename');
827  if (is_array($tmpfilelist3) && count($tmpfilelist3))
828  {
829  $i = 0;
830  foreach ($tmpfilelist3 as $file)
831  {
832  $i++;
833  $out.='<tr class="oddeven">';
834  $out.='<td>'.$i.'</td>' . "\n";
835  $out.='<td>'.$file['filename'].'</td>' . "\n";
836  $out.='<td align="center">'.$file['expectedmd5'].'</td>' . "\n";
837  $out.='<td align="center">'.$file['md5'].'</td>' . "\n";
838  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
839  $totalsize += $size;
840  $out.='<td align="right">'.dol_print_size($size).'</td>' . "\n";
841  $out.='<td align="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']),'dayhour').'</td>' . "\n";
842  $out.="</tr>\n";
843  }
844  $out.='<tr class="liste_total">';
845  $out.='<td></td>' . "\n";
846  $out.='<td>'.$langs->trans("Total").'</td>' . "\n";
847  $out.='<td align="center"></td>' . "\n";
848  $out.='<td align="center"></td>' . "\n";
849  $out.='<td align="right">'.dol_print_size($totalsize).'</td>' . "\n";
850  $out.='<td align="right"></td>' . "\n";
851  $out.="</tr>\n";
852  }
853  else
854  {
855  $out.='<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
856  }
857  $out.='</table>';
858  $out.='</div>';
859 
860 
861  // Show warning
862  if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3))
863  {
864  //setEventMessage($langs->trans("FileIntegrityIsStrictlyConformedWithReference"));
865  }
866  else
867  {
868  //setEventMessage($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), 'warnings');
869  }
870  }
871  else
872  {
873  throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
874  }
875 
876 
877  // Scan scripts
878 
879 
880  asort($checksumconcat); // Sort list of checksum
881  //var_dump($checksumconcat);
882  $checksumget = md5(join(',',$checksumconcat));
883  $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum);
884 
885  $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown"));
886  if ($checksumget == $checksumtoget)
887  {
888  if (count($file_list['added']))
889  {
890  $resultcode = 'warning';
891  $resultcomment='FileIntegrityIsOkButFilesWereAdded';
892  //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
893  $outcurrentchecksum = $checksumget;
894  }
895  else
896  {
897  $resultcode = 'ok';
898  $resultcomment='Success';
899  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
900  $outcurrentchecksum = $checksumget;
901  }
902  }
903  else
904  {
905  $resultcode = 'error';
906  $resultcomment='Error';
907  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
908  $outcurrentchecksum = $checksumget;
909  }
910  }
911  else {
912  throw new RestException(404, 'No signature file known');
913  }
914 
915  return array('resultcode'=>$resultcode, 'resultcomment'=>$resultcomment, 'expectedchecksum'=> $outexpectedchecksum, 'currentchecksum'=> $outcurrentchecksum, 'out'=>$out);
916  }
917 
918 }
getAvailability($sortfield="code", $sortorder= 'ASC', $limit=100, $page=0, $active=1, $sqlfilters= '')
Get the list of delivery times.
getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path= '', $pathref= '', &$checksumconcat=array())
Function to get list of updated or modified files.
Definition: files.lib.php:2770
getListOfExtrafields($sortfield="t.pos", $sortorder= 'ASC', $type= '', $sqlfilters= '')
Get the list of extra fields.
getCheckIntegrity($target)
Do a test of integrity for files and setup.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:516
getPaymentTypes($sortfield="code", $sortorder= 'ASC', $limit=100, $page=0, $active=1, $sqlfilters= '')
Get the list of payments types.
Class to manage dictionary Countries (used by imports)
__construct()
Constructor.
_checkFilters($sqlfilters)
Return if a $sqlfilters parameter is valid.
Definition: api.class.php:246
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="")
Scan a directory and return a list of files/directories.
Definition: files.lib.php:58
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class for API REST v1.
Definition: api.class.php:29
getPaymentTerms($sortfield="sortorder", $sortorder= 'ASC', $limit=100, $page=0, $active=1, $sqlfilters= '')
Get the list of payments terms.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array())
Function get content from an URL (use proxy if proxy defined)
Definition: geturl.lib.php:34
translateLabel($country, $lang)
Translate the name of the country to the given language.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Class to manage translations.
getListOfCountries($sortfield="code", $sortorder= 'ASC', $limit=100, $page=0, $filter= '', $lang= '', $sqlfilters= '')
Get the list of countries.
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:427
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:528
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
_cleanObjectDatas($object)
Clean sensible object datas.
getListOfTowns($sortfield="zip,town", $sortorder= 'ASC', $limit=100, $page=0, $zipcode= '', $town= '', $sqlfilters= '')
Get the list of towns.
getListOfEventTypes($sortfield="code", $sortorder= 'ASC', $limit=100, $page=0, $type= '', $module= '', $sqlfilters= '')
Get the list of events types.
getCountryByID($id, $lang= '')
Get country by ID.