dolibarr 24.0.0-beta
blockedlog_control.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
3 * Copyright (C) 2017-2018 Laurent Destailleur <eldy@destailleur.fr>
4 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
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 <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
41require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
47
48// Load translation files required by the page
49$langs->loadLangs(array('admin', 'banks', 'bills', 'blockedlog', 'other'));
50
51// Get Parameters
52$action = GETPOST('action', 'aZ09');
53$confirm = GETPOST('confirm', 'aZ09'); // Used by the actions_linkedfiles.inc.php
54$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : getDolDefaultContextPage(__FILE__); // To manage different context of search
55$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
56$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
57$withtab = GETPOSTISSET('withtab') ? GETPOSTINT('withtab') : 1;
58
59//$hmacexportkey = GETPOST('hmacexportkey', 'password');
60$inputregistrationnumber = GETPOST('inputregistrationnumber');
61
62$search_showonlyerrors = GETPOSTINT('search_showonlyerrors');
63if ($search_showonlyerrors < 0) {
64 $search_showonlyerrors = 0;
65}
66
67$search_startyear = GETPOSTINT('search_startyear');
68$search_startmonth = GETPOSTINT('search_startmonth');
69$search_startday = GETPOSTINT('search_startday');
70$search_endyear = GETPOSTINT('search_endyear');
71$search_endmonth = GETPOSTINT('search_endmonth');
72$search_endday = GETPOSTINT('search_endday');
73$search_id = GETPOST('search_id', 'alpha');
74$search_fk_user = GETPOST('search_fk_user', 'intcomma');
75$search_start = -1;
76if (GETPOST('search_startyear') != '') {
77 $search_start = dol_mktime(0, 0, 0, $search_startmonth, $search_startday, $search_startyear);
78}
79$search_end = -1;
80if (GETPOST('search_endyear') != '') {
81 $search_end = dol_mktime(23, 59, 59, $search_endmonth, $search_endday, $search_endyear);
82}
83$search_code = GETPOST('search_code', 'array:alpha');
84$search_ref = GETPOST('search_ref', 'alpha');
85$search_amount = GETPOST('search_amount', 'alpha');
86$search_signature = GETPOST('search_signature', 'alpha');
87
88if (($search_start == -1 || empty($search_start)) && !GETPOSTISSET('search_startmonth') && !GETPOSTISSET('begin')) {
89 $search_start = dol_time_plus_duree(dol_now(), -1, 'w');
90 $tmparray = dol_getdate($search_start);
91 $search_startday = $tmparray['mday'];
92 $search_startmonth = $tmparray['mon'];
93 $search_startyear = $tmparray['year'];
94}
95
96// Load variable for pagination
97$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
98$sortfield = GETPOST('sortfield', 'aZ09comma');
99$sortorder = GETPOST('sortorder', 'aZ09comma');
100$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
101if (empty($page) || $page == -1) {
102 $page = 0;
103} // If $page is not defined, or '' or -1
104$offset = $limit * $page;
105$pageprev = $page - 1;
106$pagenext = $page + 1;
107
108if (empty($sortfield)) {
109 $sortfield = 'rowid';
110}
111if (empty($sortorder)) {
112 $sortorder = 'DESC';
113}
114
115$block_static = new BlockedLog($db);
116$block_static->loadTrackedEvents();
117
118// Access Control
119if (((!$user->admin && !$user->hasRight('blockedlog', 'read')) || !isModEnabled('blockedlog')) && !userIsTaxAuditor()) {
120 accessforbidden('Access to this page is reserved to an allowed tax auditors');
121}
122
123$result = restrictedArea($user, 'blockedlog', 0, '');
124
125$permission = $user->hasRight('blockedlog', 'read');
126$permissiontoadd = $user->hasRight('blockedlog', 'read'); // Permission is to upload new files to scan them
127$permtoedit = $permissiontoadd;
128
129$upload_dir = getMultidirOutput($block_static, 'blockedlog').'/archives';
130
131
132/*
133 * Actions
134 */
135
136if ($action == 'control' && $user->hasRight('blockedlog', 'read')) { // read is read/export for blockedlog
137 $action = '';
138}
139
140
141/*
142 * View
143 */
144
145$form = new Form($db);
146$formother = new FormOther($db);
147
148$title = $langs->trans("BrowseBlockedLog");
149$help_url = "EN:Module_Unalterable_Archives_-_Logs|FR:Module_Archives_-_Logs_Inaltérable";
150
151llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-blockedlog page-admin_blockedlog_list');
152
153$linkback = '';
154
155$morehtmlcenter = '';
156$texttop = '';
157
158$registrationnumber = getHashUniqueIdOfRegistration();
159if (!userIsTaxAuditor()) {
160 $texttop = '<small class="opacitymedium">'.$langs->trans("RegistrationNumber").':</small> <small>'.dol_trunc($registrationnumber, 10).'</small>';
162 $texttop = '';
163 }
164}
165
166print load_fiche_titre($title.'<br>'.$texttop, $linkback, 'blockedlog', 0, '', '', $morehtmlcenter);
167
168$head = blockedlogadmin_prepare_head($withtab);
169
170print dol_get_fiche_head($head, 'control', '', -1);
171
172//print $texttop;
173//print '<br><br>';
174
175print '<div class="opacitymedium hideonsmartphone justify">';
176print $langs->trans("ControlDesc")."<br>";
177print "</div>\n";
178
179
180print '<form method="POST" id="exportArchives" action="'.$_SERVER["PHP_SELF"].'?output=file">';
181print '<input type="hidden" name="token" value="'.newToken().'">';
182print '<input type="hidden" name="action" value="export">';
183
184print '<div class="neutral">';
185
186print '<span class="hideonsmartphone">'.$langs->trans("PleaseEnterPartialRegistrationNumber").': </span>';
187
188print '<input type="text" name="inputregistrationnumber" class="width300" placeholder="'.$langs->trans("RegistrationNumber").'" value="'.$inputregistrationnumber.'" spellcheck="false">';
189
190print '<br>';
191print '<br>';
192
193print '<center>';
194print '<input type="submit" class="button small" name="submit" value="'.$langs->trans("ControlSignals").'">';
195print '</center>';
196
197print ' </div>';
198
199print '</form>';
200
201print dol_get_fiche_end();
202
203print '<br>';
204
205if ($inputregistrationnumber && strlen($inputregistrationnumber) < 8) {
206 // Message
207 print img_picto('', 'cross', 'class="pictofixedwidth"').$langs->trans("RegistrationNumberIsTooShort");
208} elseif ($inputregistrationnumber) {
209 // Return known information on this registration number
210 if (!isModEnabled('captureserver')) {
211 print 'The module captureserver to capture the signals from installed instance is not enabled. Is this instance the master instance of the Dolibarr foundation ?';
212 } else {
213 // Report registration
214 $sql = "SELECT rowid, registerid, registername, registerprofid, registeremail, date_creation, tms, content, comment,";
215 $sql .= " versiondolibarr, versionblockedlog, country_code";
216 $sql .= " FROM ".MAIN_DB_PREFIX."captureserver_captureserver";
217 $sql .= " WHERE registerid LIKE '".$db->escape($inputregistrationnumber)."%'";
218 $sql .= " AND type = 'dolibarrregistration'";
219 $sql .= " LIMIT 100"; // Should have only 1 record, so a limit of 100 is enough
220
221 $resql = $db->query($sql);
222 if ($resql) {
223 $num = 0;
224 while ($obj = $db->fetch_object($resql)) {
225 $num++;
226 print img_picto('', 'tick', 'class="pictofixedwidth"').' <b>'.dol_print_date($obj->date_creation, 'dayhour', 'gmt').'</b> &nbsp; ';
227 print $langs->trans("RegistrationDone");
228 print ' - '.$langs->trans("BlockedLogInstance").' '.dolPrintHTML($obj->registerid);
229 print '<br>';
230 print $langs->trans("LastRegistrationUpdate").' '.dol_print_date($obj->tms, 'dayhour', 'gmt');
231 print '<br>';
232 print $obj->registername.' - '.$obj->registerprofid.' - '.$obj->country_code.' - '.$obj->registeremail;
233 print '<br>';
234 print $langs->trans("Version").': '.$obj->versiondolibarr.' - '.$langs->trans("VersionOfModule", $langs->transnoentitiesnoconv("BlockedLog")).': '.$obj->versionblockedlog;
235 /*
236 print '<div class="small">';
237 print $langs->trans("Note").': ';
238 print $obj->comment;
239 print '</div>';
240 */
241 print '<br>';
242 }
243 if ($num == 0) {
244 print img_picto('', 'cross', 'class="pictofixedwidth error"').$langs->trans("NoRegistrationFound");
245 print '<br>';
246 }
247 } else {
249 }
250
251 print '<br>';
252
253
254 // Report backup restoration or last lines deletion
255 $sql = "SELECT rowid, registerid, date_creation, content, comment from ".MAIN_DB_PREFIX."captureserver_captureserver";
256 $sql .= " WHERE registerid LIKE '".$db->escape($inputregistrationnumber)."%'";
257 $sql .= " AND type = 'deletion_or_backup_restoration'";
258 $sql .= " LIMIT 100"; // Should not happen, so a limit of 100 is enough
259
260 $resql = $db->query($sql);
261 if ($resql) {
262 $num = 0;
263 while ($obj = $db->fetch_object($resql)) {
264 $num++;
265 print img_picto('', 'cross', 'class="pictofixedwidth"').' <b>'.dol_print_date($obj->date_creation, 'dayhour').'</b> &nbsp; ';
266 print $langs->trans("BackupRestorationOrLastLineDeletionDetected");
267 print ' - '.$langs->trans("BlockedLogInstance").' '.dolPrintHTML($obj->registerid);
268 print '<br>';
269 print '<div class="small">';
270 print $langs->trans("Note").': ';
271 print $obj->comment;
272 print '</div>';
273 print '<br>';
274 /*
275 print '<textarea class=small">';
276 print dolPrintHTMLForTextArea($obj->content);
277 print '</textarea>';
278 */
279 print '<br>';
280 }
281 if ($num == 0) {
282 print img_picto('', 'tick', 'class="pictofixedwidth"').$langs->trans("NoBackupRestorationOrLastLineDeletionDetected");
283 }
284 } else {
286 }
287
288 print '<br>';
289 }
290}
291
292
293// End of page
294llxFooter();
295$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
userIsTaxAuditor()
Call remote API service to push the last counter and signature.
blockedlogadmin_prepare_head($withtabsetup)
Define head array for tabs of blockedlog tools setup pages.
isRegistrationDataSavedAndPushed()
Return if the KYC mandatory parameters are set AND pushed/registered centralized server.
getHashUniqueIdOfRegistration($algo='sha256')
Return a hash unique identifier of the registration (used to identify the registration of instance wi...
Class to manage Blocked Log.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:126
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
getDolDefaultContextPage($s)
Return the default context page string.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isModEnabled($module)
Is Dolibarr module enabled.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.