dolibarr 23.0.3
block-add.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
27// This script is called with a POST method.
28// Directory to scan (full path) is inside POST['dir'].
29
30if (!defined('NOTOKENRENEWAL')) {
31 define('NOTOKENRENEWAL', 1); // Disables token renewal
32}
33if (!defined('NOREQUIREMENU')) {
34 define('NOREQUIREMENU', '1');
35}
36if (!defined('NOREQUIREHTML')) {
37 define('NOREQUIREHTML', '1');
38}
39
40require '../../main.inc.php';
49$id = GETPOSTINT('id');
50$element = GETPOST('element', 'alpha');
51$action = GETPOST('action', 'aZ09'); // Can be DOC_PREVIEW or DOC_DOWNLOAD
52
53if (! in_array($action, array('DOC_PREVIEW', 'DOC_DOWNLOAD'))) {
54 accessforbidden('Bad value for action. Must be DOC_PREVIEW or DOC_DOWNLOAD');
55}
56
57if ($element === 'facture') {
58 restrictedArea($user, 'facture', $id, '', '', 'fk_soc', 'rowid', 0);
59} else {
60 accessforbidden('Bad value for element');
61}
62
63
64/*
65 * View
66 */
67
69
70if ($element === 'facture') { // Test on permission done in top of page
71 require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php';
72 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
73
74 $facture = new Facture($db);
75 if ($facture->fetch($id) > 0) {
76 //print 'Object '.$element.' logged with action code = '.$action." pos_print_counter is currently ".$facture->pos_print_counter;
77
78 if ($facture->status > Facture::STATUS_DRAFT) {
79 // Increase counter by 1
80 $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET pos_print_counter = pos_print_counter + 1";
81 $sql .= " WHERE rowid = ".((int) $facture->id);
82 $db->query($sql);
83
84 $facture->pos_print_counter += 1;
85 // $facture->update($user, 1); // disabled update, we did a direct sql update before. We disable trigger here because we already call the trigger $action = DOC_PREVIEW or DOC_DOWNLOAD just after.
86 }
87
88 $facture->call_trigger($action, $user);
89 }
90
91 print 'Object '.$element.' logged with action code = '.$action." pos_print_counter is now ".$facture->pos_print_counter;
92}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
Class to manage invoices.
const STATUS_DRAFT
Draft status.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
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.