dolibarr 21.0.0-alpha
public.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
4 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2019 Eric Seigne <eric.seigne@cap-rel.fr>
6 * Copyright (C) 2021-2024 Frédéric France <frederic.france@netlogic.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
30require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php';
31
39function checkNbPostsForASpeceificIp($object, $nb_post_max)
40{
41 global $db, $langs;
42
43 $nb_post_ip = 0;
44 $now = dol_now();
45 $minmonthpost = dol_time_plus_duree($now, -1, "w");
46
47 if (empty($object->ip)) {
49 }
50
51 if ($nb_post_max > 0) { // Calculate only if there is a limit to check
52 $sql = "SELECT COUNT(".(!empty($object->table_rowid) ? $object->table_rowid : 'rowid').") as nb_posts";
53 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element;
54 $sql .= " WHERE ip = '".$db->escape($object->ip)."'";
55 $sql .= " AND datec > '".$db->idate($minmonthpost)."'";
56 $resql = $db->query($sql);
57 if ($resql) {
58 $num = $db->num_rows($resql);
59 $i = 0;
60 while ($i < $num) {
61 $i++;
62 $obj = $db->fetch_object($resql);
63 $nb_post_ip = $obj->nb_posts;
64 }
65 } else {
66 array_push($object->errors, $db->lasterror());
67 return -1;
68 }
69 }
70 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
71 array_push($object->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
72 return -1;
73 }
74 return 1;
75}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:124
dol_now($mode='auto')
Return date for now.
getUserRemoteIP()
Return the IP of remote user.
checkNbPostsForASpeceificIp($object, $nb_post_max)
Check if the object exceeded the number of posts for a specific ip in the same week.