dolibarr 25.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';
31require_once DOL_DOCUMENT_ROOT . '/core/lib/html.lib.php';
32
40function checkNbPostsForASpeceificIp($object, $nb_post_max)
41{
42 global $db, $langs;
43
44 $nb_post_ip = 0;
45 $now = dol_now();
46 $minmonthpost = dol_time_plus_duree($now, -1, "w");
47
48 if (empty($object->ip)) {
50 }
51
52 if ($nb_post_max > 0) { // Calculate only if there is a limit to check
53 $sql = "SELECT COUNT(".(!empty($object->table_rowid) ? $object->table_rowid : 'rowid').") as nb_posts";
54 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element;
55 $sql .= " WHERE ip = '".$db->escape($object->ip)."'";
56 if (array_key_exists('date_creation', $object->fields)) {
57 $sql .= " AND date_creation > '".$db->idate($minmonthpost)."'";
58 } else {
59 $sql .= " AND datec > '".$db->idate($minmonthpost)."'";
60 }
61 $resql = $db->query($sql);
62 if ($resql) {
63 $num = $db->num_rows($resql);
64 $i = 0;
65 while ($i < $num) {
66 $i++;
67 $obj = $db->fetch_object($resql);
68 $nb_post_ip = $obj->nb_posts;
69 }
70 } else {
71 array_push($object->errors, $db->lasterror());
72 return -1;
73 }
74 }
75 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
76 array_push($object->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
77 return -1;
78 }
79 return 1;
80}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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 $db
API class for accounts.
dol_now($mode='gmt')
Return date for now.
getUserRemoteIP($trusted=0)
Return the real 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.