changes for mysql 5.7 with strict mode

Dieser Commit ist enthalten in:
Oldperl 2018-02-13 19:45:20 +00:00
Ursprung 2a933cea61
Commit dec7056fca
4 geänderte Dateien mit 230 neuen und 231 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Project: * Project:
* Contenido Content Management System * Contenido Content Management System
@ -17,277 +18,266 @@
* *
* $Id: class.activeusers.php 362 2015-10-05 16:31:26Z oldperl $; * $Id: class.activeusers.php 362 2015-10-05 16:31:26Z oldperl $;
*/ */
if (!defined('CON_FRAMEWORK')) {
if(!defined('CON_FRAMEWORK')) { die('Illegal call');
die('Illegal call');
} }
class ActiveUsers { class ActiveUsers {
var $oDb; var $oDb;
var $oCfg; var $oCfg;
var $oAuth; var $oAuth;
var $iUserId; var $iUserId;
/** /**
* Constructor * Constructor
* *
* @param object $db - Contenido Database Object * @param object $db - Contenido Database Object
* @param object $cfg * @param object $cfg
* @param object $auth * @param object $auth
* *
* @return * @return
**/ * */
function ActiveUsers($oDb, $oCfg, $oAuth) { function ActiveUsers($oDb, $oCfg, $oAuth) {
$this->oCfg= $oCfg; $this->oCfg = $oCfg;
$this->oAuth= $oAuth; $this->oAuth = $oAuth;
$this->oDb= $oDb; $this->oDb = $oDb;
// init db object // init db object
if (!is_object($this->oDb) || (is_null($this->oDb))) { if (!is_object($this->oDb) || (is_null($this->oDb))) {
$this->oDb= new DB_ConLite; $this->oDb = new DB_ConLite;
} }
if (!is_resource($this->oDb->Link_ID)) { if (!is_resource($this->oDb->Link_ID)) {
$this->oDb->connect(); $this->oDb->connect();
} }
// Load the userid // Load the userid
$this->iUserId= $this->oAuth->auth["uid"]; $this->iUserId = $this->oAuth->auth["uid"];
} }
/** /**
* Start the User Tracking: * Start the User Tracking:
* 1) First delete all inactive users with timelimit is off * 1) First delete all inactive users with timelimit is off
* 2) If find user in the table, do update * 2) If find user in the table, do update
* 3) Else there is no current user do insert new user * 3) Else there is no current user do insert new user
* *
* *
* @return * @return
**/ * */
function startUsersTracking() { function startUsersTracking() {
// Delete all Contains in the table "online_user" that is older as timeout(current is 60 minutes) // Delete all Contains in the table "online_user" that is older as timeout(current is 60 minutes)
$this->deleteInactiveUser(); $this->deleteInactiveUser();
$bResult= $this->findUser($this->iUserId); $bResult = $this->findUser($this->iUserId);
if ($bResult) { if ($bResult) {
// update the curent user // update the curent user
$this->updateUser($this->iUserId); $this->updateUser($this->iUserId);
} else { } else {
// User not found, we can insert the new user // User not found, we can insert the new user
$this->insertOnlineUser($this->iUserId); $this->insertOnlineUser($this->iUserId);
} }
} }
/** /**
* Insert this user in online_user table * Insert this user in online_user table
* *
* @param object $db - Contenido Database Object * @param object $db - Contenido Database Object
* *
* @return Returns true if successful else false * @return Returns true if successful else false
**/ * */
function insertOnlineUser($sUserId) { function insertOnlineUser($sUserId) {
$userid = (string) $sUserId;
$sql= "INSERT INTO `" . $this->oCfg["tab"]["online_user"] . "`(`user_id`,`lastaccessed`) VALUES('".Contenido_Security::escapeDB($userid, $this->oDb)."', NOW())";
if ($this->oDb->query($sql)) { $userid = (string) $sUserId;
return true; $sql = "INSERT INTO `" . $this->oCfg["tab"]["online_user"] . "`(`user_id`,`lastaccessed`) VALUES('" . Contenido_Security::escapeDB($userid, $this->oDb) . "', NOW())";
} else {
return false;
}
}
/** if ($this->oDb->query($sql)) {
* Find the this user if exists in the table "online_user" return true;
* } else {
* @param integer $iUserId - Is the User-Id (get from auth object) return false;
* }
* @return Returns true if this User is found, else false }
**/
function findUser($sUserId) {
$userid = (string) $sUserId; /**
$bReturn = false; * Find the this user if exists in the table "online_user"
$sql= "SELECT user_id FROM `" . $this->oCfg["tab"]["online_user"] . "` WHERE `user_id`='".Contenido_Security::escapeDB($userid, $this->oDb)."'"; *
$this->oDb->query($sql); * @param integer $iUserId - Is the User-Id (get from auth object)
if ($this->oDb->next_record()) { *
$bReturn= true; * @return Returns true if this User is found, else false
} * */
return $bReturn; function findUser($sUserId) {
}
/** $userid = (string) $sUserId;
* Find all user_ids in the table 'online_user' for get rest information from $bReturn = false;
* table 'con_phplib_auth_user_md5' $sql = "SELECT user_id FROM `" . $this->oCfg["tab"]["online_user"] . "` WHERE `user_id`='" . Contenido_Security::escapeDB($userid, $this->oDb) . "'";
* $this->oDb->query($sql);
* if ($this->oDb->next_record()) {
* @return Returns array of user-information $bReturn = true;
**/ }
function findAllUser() { return $bReturn;
}
$aAllUser= array (); /**
$aUser= array (); * Find all user_ids in the table 'online_user' for get rest information from
$sWebsiteName= ""; * table 'con_phplib_auth_user_md5'
// get all user_ids *
$sql= "SELECT `user_id` FROM `" . $this->oCfg["tab"]["online_user"]."`"; *
* @return Returns array of user-information
* */
function findAllUser() {
if ($this->oDb->query($sql) && $this->oDb->Errno == 0) { $aAllUser = array();
$aUser = array();
$sWebsiteName = "";
// get all user_ids
$sql = "SELECT `user_id` FROM `" . $this->oCfg["tab"]["online_user"] . "`";
if ($this->oDb->num_rows() > 0) { if ($this->oDb->query($sql) && $this->oDb->Errno == 0) {
while ($this->oDb->next_record()) { // Table Online User
$aUser[]= "'" . $this->oDb->f('user_id') . "'"; if ($this->oDb->num_rows() > 0) {
} while ($this->oDb->next_record()) { // Table Online User
} $aUser[] = "'" . $this->oDb->f('user_id') . "'";
} }
// get data of those users }
$aAllUser= array (); }
// get data of those users
$aAllUser = array();
$sSqlIn= implode(', ', $aUser); // '1','2','5','8' $sSqlIn = implode(', ', $aUser); // '1','2','5','8'
$sql= "SELECT user_id, realname, username, perms " . $sql = "SELECT user_id, realname, username, perms " .
"FROM " . $this->oCfg["tab"]["phplib_auth_user_md5"] . " " . "FROM " . $this->oCfg["tab"]["phplib_auth_user_md5"] . " " .
"WHERE user_id IN(" . $sSqlIn . ")"; "WHERE user_id IN(" . $sSqlIn . ")";
if ($this->oDb->query($sql) && $this->oDb->Errno == 0) {
if ($this->oDb->num_rows() > 0) { if ($this->oDb->query($sql) && $this->oDb->Errno == 0) {
while ($this->oDb->next_record()) { // Table Online User
if ($this->oDb->num_rows() > 0) {
while ($this->oDb->next_record()) { // Table Online User
$sWebsiteNames = ''; $sWebsiteNames = '';
$sUserId= $this->oDb->f("user_id"); $sUserId = $this->oDb->f("user_id");
$aAllUser[$sUserId]['realname']= $this->oDb->f("realname"); $aAllUser[$sUserId]['realname'] = $this->oDb->f("realname");
$aAllUser[$sUserId]['username']= $this->oDb->f("username"); $aAllUser[$sUserId]['username'] = $this->oDb->f("username");
$sPerms= $this->oDb->f("perms"); $sPerms = $this->oDb->f("perms");
$aPerms= explode(",", $sPerms); //Alle Rechte als array in aPerms packen $aPerms = explode(",", $sPerms); //Alle Rechte als array in aPerms packen
if (in_array("sysadmin", $aPerms)) { if (in_array("sysadmin", $aPerms)) {
$aAllUser[$sUserId]['perms']= 'Systemadministrator'; $aAllUser[$sUserId]['perms'] = 'Systemadministrator';
} else {
} else { $bIsAdmin = false;
$iCounter = 0;
$bIsAdmin= false; foreach ($aPerms as $sPerm) {
$iCounter= 0;
foreach ($aPerms as $sPerm) {
$aResults = array(); $aResults = array();
if (preg_match('/^admin\[(\d+)\]$/', $sPerm, $aResults)) { if (preg_match('/^admin\[(\d+)\]$/', $sPerm, $aResults)) {
$iClientId= $aResults[1]; $iClientId = $aResults[1];
$bIsAdmin= true; $bIsAdmin = true;
$sWebsiteName = $this->getWebsiteName($iClientId); $sWebsiteName = $this->getWebsiteName($iClientId);
if ($iCounter == 0 && $sWebsiteName != "") { if ($iCounter == 0 && $sWebsiteName != "") {
$sWebsiteNames .= $sWebsiteName; $sWebsiteNames .= $sWebsiteName;
} else if ($sWebsiteName != "") { } else if ($sWebsiteName != "") {
$sWebsiteNames .= ', ' . $sWebsiteName; $sWebsiteNames .= ', ' . $sWebsiteName;
} }
$aAllUser[$sUserId]['perms']= "Administrator (" . $sWebsiteNames . ")"; $aAllUser[$sUserId]['perms'] = "Administrator (" . $sWebsiteNames . ")";
$iCounter++; $iCounter++;
} else if (preg_match('/^client\[(\d+)\]$/', $sPerm, $aResults) && !$bIsAdmin) {
$iClientId = $aResults[1];
$sWebsiteName = $this->getWebsiteName($iClientId);
if ($iCounter == 0 && $sWebsiteName != "") {
$sWebsiteNames .= $sWebsiteName;
} else if ($sWebsiteName != "") {
$sWebsiteNames .= ', ' . $sWebsiteName;
}
} else if (preg_match('/^client\[(\d+)\]$/', $sPerm, $aResults) && !$bIsAdmin) { $aAllUser[$sUserId]['perms'] = '(' . $sWebsiteNames . ')';
$iClientId= $aResults[1]; $iCounter++;
$sWebsiteName = $this->getWebsiteName($iClientId); }
if ($iCounter == 0 && $sWebsiteName != "") { }
$sWebsiteNames .= $sWebsiteName; }
} else if ($sWebsiteName != "") { }
$sWebsiteNames .= ', ' . $sWebsiteName; }
} }
$aAllUser[$sUserId]['perms']= '(' . $sWebsiteNames . ')'; return $aAllUser;
$iCounter++; }
}
} /**
* This function do an update of current timestamp in "online_user"
*
* @param integer $iUserId - Is the User-Id (get from auth object)
*
* @return Returns true if successful, else false
* */
function updateUser($sUserId) {
} $userid = (string) $sUserId;
$sql = "UPDATE `" . $this->oCfg["tab"]["online_user"] . "` SET `lastaccessed`=NOW() WHERE `user_id`='" . Contenido_Security::escapeDB($userid, $this->oDb) . "'";
if ($this->oDb->query($sql)) {
return true;
} else
return false;
}
} /**
* Delete all Contains in the table "online_user" that is older as
* Backend timeout(currently is $cfg["backend"]["timeout"] = 60)
*
*
* @return Returns true if successful else false
* */
function deleteInactiveUser() {
} cInclude("config", "config.misc.php");
} $iSetTimeOut = $this->oCfg["backend"]["timeout"];
if ($iSetTimeOut == 0)
$iSetTimeOut = 10;
$sql = "";
$sql = "DELETE FROM `" . $this->oCfg["tab"]["online_user"] . "` WHERE DATE_SUB(now(), INTERVAL '$iSetTimeOut' Minute) >= `lastaccessed`";
if ($this->oDb->query($sql)) {
return true;
} else {
return false;
}
}
return $aAllUser; /**
} * Get the number of users from the table "online_user"
*
*
* @return Returns if exists a number of users
* */
function getNumberOfUsers() {
/** $iAnzahl = 0;
* This function do an update of current timestamp in "online_user" $sql = "SELECT user_id FROM `" . $this->oCfg["tab"]["online_user"] . "`";
* if ($this->oDb->query($sql)) {
* @param integer $iUserId - Is the User-Id (get from auth object) $iAnzahl = $this->oDb->num_rows();
* }
* @return Returns true if successful, else false
**/
function updateUser($sUserId) {
$userid= (string) $sUserId; return $iAnzahl;
$sql= "UPDATE `" . $this->oCfg["tab"]["online_user"] . "` SET `lastaccessed`=NOW() WHERE `user_id`='".Contenido_Security::escapeDB($userid, $this->oDb)."'"; }
if ($this->oDb->query($sql)) {
return true;
} else
return false;
} /**
* Delete this user from 'online user' table
*
* @param integer $iUserId - Is the User-Id (get from auth object)
*
* @return Returns true if successful, else false
* */
function deleteUser($sUserId) {
/** $userid = (string) $sUserId;
* Delete all Contains in the table "online_user" that is older as $sql = "DELETE FROM `" . $this->oCfg["tab"]["online_user"] . "` WHERE `user_id` = '" . Contenido_Security::escapeDB($userid, $this->oDb) . "'";
* Backend timeout(currently is $cfg["backend"]["timeout"] = 60)
*
*
* @return Returns true if successful else false
**/
function deleteInactiveUser() {
cInclude("config", "config.misc.php"); if ($this->oDb->query($sql)) {
$iSetTimeOut= $this->oCfg["backend"]["timeout"]; return true;
if ($iSetTimeOut == 0) } else {
$iSetTimeOut= 10; return false;
$sql= ""; }
$sql= "DELETE FROM `" . $this->oCfg["tab"]["online_user"] . "` WHERE DATE_SUB(now(), INTERVAL '$iSetTimeOut' Minute) >= `lastaccessed`"; }
if ($this->oDb->query($sql)) {
return true;
} else {
return false;
}
}
/**
* Get the number of users from the table "online_user"
*
*
* @return Returns if exists a number of users
**/
function getNumberOfUsers() {
$iAnzahl= 0;
$sql= "SELECT user_id FROM `" . $this->oCfg["tab"]["online_user"]."`";
if ($this->oDb->query($sql)) {
$iAnzahl= $this->oDb->num_rows();
}
return $iAnzahl;
}
/**
* Delete this user from 'online user' table
*
* @param integer $iUserId - Is the User-Id (get from auth object)
*
* @return Returns true if successful, else false
**/
function deleteUser($sUserId) {
$userid= (string) $sUserId;
$sql= "DELETE FROM `" . $this->oCfg["tab"]["online_user"] . "` WHERE `user_id` = '".Contenido_Security::escapeDB($userid, $this->oDb)."'";
if ($this->oDb->query($sql)) {
return true;
} else {
return false;
}
}
/** /**
* Get the website name from table con_clients * Get the website name from table con_clients
* *
@ -298,5 +288,7 @@ class ActiveUsers {
$oClient = new cApiClient($iIdClient); $oClient = new cApiClient($iIdClient);
return $oClient->get('name'); return $oClient->get('name');
} }
} }
?> ?>

Datei anzeigen

@ -85,6 +85,8 @@ abstract class cItemBaseAbstract {
* @var string * @var string
*/ */
protected $_className; protected $_className;
protected $_bDebug;
/** /**
* Sets some common properties * Sets some common properties

Datei anzeigen

@ -50,9 +50,9 @@ if (!isRunningFromWeb() || function_exists("runJob") || $area == "cronjobs")
$sSql = "UPDATE " . $cfg['tab']['frontendusers'] . " $sSql = "UPDATE " . $cfg['tab']['frontendusers'] . "
SET active = 0 SET active = 0
WHERE WHERE
(valid_to < NOW() AND valid_to != '0000-00-00' AND valid_to != '1000-01-01') (valid_to < NOW() AND valid_to != '1000-01-01')
OR OR
(valid_from > NOW() AND valid_from != '0000-00-00' AND valid_from != '1000-01-01')"; (valid_from > NOW() AND valid_from != '1000-01-01')";
//echo $sSql; //echo $sSql;
$db->query($sSql); $db->query($sSql);

Datei anzeigen

@ -125,6 +125,11 @@ $cfg['AvailableCharsets'] = array(
'SHIFT_JIS' 'SHIFT_JIS'
); );
// (bool) Flag to use native i18n.
// Note: Enabling this could create unwanted side effects, because of
// native gettext() behavior.
$cfg['native_i18n'] = false;
/* Error handling settings /* Error handling settings
* ---------------------------------- * ----------------------------------