';
print '';
}
@@ -668,6 +687,10 @@ function fieldListWebsites($fieldlist, $obj = '', $tabname = '', $context = '')
$formadmin = new FormAdmin($db);
foreach ($fieldlist as $field => $value) {
+ if (in_array($fieldlist[$field], array('lastaccess', 'pageviews_previous_month', 'pageviews_month', 'pageviews_total'))) {
+ continue;
+ }
+
$fieldname = $fieldlist[$field];
if ($fieldlist[$field] == 'lang') {
diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php
index 32a6d9d962a..de5779a3f51 100644
--- a/htdocs/core/lib/website.lib.php
+++ b/htdocs/core/lib/website.lib.php
@@ -438,7 +438,14 @@ function dolWebsiteIncrementCounter($websiteid, $websitepagetype, $websitepageid
if (in_array($websitepagetype, array('blogpost', 'page'))) {
global $db;
- $sql = "UPDATE ".$db->prefix()."website SET pageviews_total = pageviews_total + 1, lastaccess = '".$db->idate(dol_now())."'";
+ $tmpnow = dol_getdate(dol_now('gmt'), true, 'gmt');
+
+ $sql = "UPDATE ".$db->prefix()."website SET ";
+ $sql .= " pageviews_total = pageviews_total + 1,";
+ $sql .= " pageviews_month = pageviews_month + 1,";
+ // if last access was done during previous month, we save pageview_month into pageviews_previous_month
+ $sql .= " pageviews_previous_month = ".$db->ifsql("lastaccess < '".$db->idate(dol_mktime(0, 0, 0, $tmpnow['month'], 1, $tmpnow['year'], 'gmt', 0), 'gmt')."'", 'pageviews_month', 'pageviews_previous_month').",";
+ $sql .= " lastaccess = '".$db->idate(dol_now('gmt'), 'gmt')."'";
$sql .= " WHERE rowid = ".((int) $websiteid);
$resql = $db->query($sql);
if (! $resql) {
diff --git a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql
index 376d89861f2..d8e1b4c12c9 100644
--- a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql
+++ b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql
@@ -59,3 +59,5 @@ INSERT INTO llx_c_tva(rowid,fk_pays,code,taux,localtax1,localtax1_type,localtax2
ALTER TABLE llx_user ADD COLUMN flagdelsessionsbefore datetime DEFAULT NULL;
+ALTER TABLE llx_website ADD COLUMN pageviews_previous_month BIGINT UNSIGNED DEFAULT 0;
+
diff --git a/htdocs/install/mysql/tables/llx_website-website.sql b/htdocs/install/mysql/tables/llx_website-website.sql
index 0df6ccf8ef3..8ac580919aa 100644
--- a/htdocs/install/mysql/tables/llx_website-website.sql
+++ b/htdocs/install/mysql/tables/llx_website-website.sql
@@ -36,9 +36,10 @@ CREATE TABLE llx_website
fk_user_modif integer,
date_creation datetime,
position integer DEFAULT 0,
- lastaccess datetime NULL,
- pageviews_month BIGINT UNSIGNED DEFAULT 0,
- pageviews_total BIGINT UNSIGNED DEFAULT 0,
+ lastaccess datetime NULL, -- updated at each page access
+ pageviews_previous_month BIGINT UNSIGNED DEFAULT 0,
+ pageviews_month BIGINT UNSIGNED DEFAULT 0, -- increased by 1 at each page access, saved into pageviews_previous_month when on different month than lastaccess
+ pageviews_total BIGINT UNSIGNED DEFAULT 0, -- increased by 1 at each page access, no reset
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
import_key varchar(14) -- import key
) ENGINE=innodb;
diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index 2473659a5c7..bdd0ef2bd0d 100644
--- a/htdocs/langs/en_US/main.lang
+++ b/htdocs/langs/en_US/main.lang
@@ -1216,3 +1216,4 @@ NoSpecificContactAddress=No specific contact or address
NoSpecificContactAddressBis=This tab is dedicated to force specific contacts or addresses for the current object. Use it only if you want to define one or several specific contacts or addresses for the object when the information on the thirdparty is not enough or not accurate.
HideOnVCard=Hide %s
AddToContacts=Add address to my contacts
+LastAccess=Last access
\ No newline at end of file
diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang
index 742e3afff67..7b2cc90f7ac 100644
--- a/htdocs/langs/en_US/website.lang
+++ b/htdocs/langs/en_US/website.lang
@@ -155,3 +155,5 @@ WebpageMustBeDisabled=The web page must have the status "%s"
SetWebsiteOnlineBefore=When website is offline, all pages are offline. Change status of website first.
Booking=Booking
Reservation=Reservation
+PagesViewedPreviousMonth=Pages viewed (previous month)
+PagesViewedTotal=Pages viewed (total)
\ No newline at end of file