- session id is now generated from truly random value, previous used mysql UUID() had weak randomness
- added session id brute force prevention to old template engine (as used in new template engine) - forced login->verify() in old template engine - removed unused login/logout related codes from old template engine - uuid of new database records is now generated in before insert trigger
This commit is contained in:
+429
-429
@@ -1,430 +1,430 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* get/set has to be commited with save
|
||||
* add/remove etc. is executed instantly
|
||||
***************************************************************************/
|
||||
|
||||
require_once($opt['rootpath'] . 'lib2/logic/rowEditor.class.php');
|
||||
|
||||
class cache
|
||||
{
|
||||
var $nCacheId = 0;
|
||||
|
||||
var $reCache;
|
||||
|
||||
static function cacheIdFromWP($wp)
|
||||
{
|
||||
$cacheid = 0;
|
||||
if (mb_strtoupper(mb_substr($wp, 0, 2)) == 'GC')
|
||||
{
|
||||
$rs = sql("SELECT `cache_id` FROM `caches` WHERE `wp_gc`='&1'", $wp);
|
||||
if (sql_num_rows($rs) != 1)
|
||||
{
|
||||
sql_free_result($rs);
|
||||
return null;
|
||||
}
|
||||
$r = sql_fetch_assoc($rs);
|
||||
sql_free_result($rs);
|
||||
|
||||
$cacheid = $r['cache_id'];
|
||||
}
|
||||
else if (mb_strtoupper(mb_substr($wp, 0, 1)) == 'N')
|
||||
{
|
||||
$rs = sql("SELECT `cache_id` FROM `caches` WHERE `wp_nc`='&1'", $wp);
|
||||
if (sql_num_rows($rs) != 1)
|
||||
{
|
||||
sql_free_result($rs);
|
||||
return null;
|
||||
}
|
||||
$r = sql_fetch_assoc($rs);
|
||||
sql_free_result($rs);
|
||||
|
||||
$cacheid = $r['cache_id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$cacheid = sql_value("SELECT `cache_id` FROM `caches` WHERE `wp_oc`='&1'", 0, $wp);
|
||||
}
|
||||
|
||||
return $cacheid;
|
||||
}
|
||||
|
||||
static function fromWP($wp)
|
||||
{
|
||||
$cacheid = cache::cacheIdFromWP($wp);
|
||||
if ($cacheid == 0)
|
||||
return null;
|
||||
|
||||
return new cache($cacheid);
|
||||
}
|
||||
|
||||
static function cacheIdFromUUID($uuid)
|
||||
{
|
||||
$cacheid = sql_value("SELECT `cache_id` FROM `caches` WHERE `uuid`='&1'", 0, $uuid);
|
||||
return $cacheid;
|
||||
}
|
||||
|
||||
static function fromUUID($uuid)
|
||||
{
|
||||
$cacheid = cache::cacheIdFromUUID($uuid);
|
||||
if ($cacheid == 0)
|
||||
return null;
|
||||
|
||||
return new cache($cacheid);
|
||||
}
|
||||
|
||||
function __construct($nNewCacheId=ID_NEW)
|
||||
{
|
||||
$this->reCache = new rowEditor('caches');
|
||||
$this->reCache->addPKInt('cache_id', null, false, RE_INSERT_AUTOINCREMENT);
|
||||
$this->reCache->addString('uuid', '', false, RE_INSERT_OVERWRITE|RE_INSERT_UUID);
|
||||
$this->reCache->addInt('node', 0, false);
|
||||
$this->reCache->addDate('date_created', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reCache->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reCache->addInt('user_id', 0, false);
|
||||
$this->reCache->addString('name', '', false);
|
||||
$this->reCache->addDouble('longitude', 0, false);
|
||||
$this->reCache->addDouble('latitude', 0, false);
|
||||
$this->reCache->addInt('type', 1, false);
|
||||
$this->reCache->addInt('status', 5, false);
|
||||
$this->reCache->addString('country', '', false);
|
||||
$this->reCache->addDate('date_hidden', time(), false);
|
||||
$this->reCache->addInt('size', 1, false);
|
||||
$this->reCache->addFloat('difficulty', 1, false);
|
||||
$this->reCache->addFloat('terrain', 1, false);
|
||||
$this->reCache->addString('logpw', '', false);
|
||||
$this->reCache->addFloat('search_time', 0, false);
|
||||
$this->reCache->addFloat('way_length', 0, false);
|
||||
$this->reCache->addString('wp_oc', null, true);
|
||||
$this->reCache->addString('wp_gc', '', false);
|
||||
$this->reCache->addString('wp_nc', '', false);
|
||||
$this->reCache->addString('desc_languages', '', false, RE_INSERT_IGNORE);
|
||||
$this->reCache->addString('default_desclang', '', false);
|
||||
$this->reCache->addDate('date_activate', null, true);
|
||||
$this->reCache->addInt('need_npa_recalc', 1, false, RE_INSERT_IGNORE);
|
||||
|
||||
$this->nCacheId = $nNewCacheId+0;
|
||||
|
||||
if ($nNewCacheId == ID_NEW)
|
||||
{
|
||||
$this->reCache->addNew(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->reCache->load($this->nCacheId);
|
||||
}
|
||||
}
|
||||
|
||||
function exist()
|
||||
{
|
||||
return $this->reCache->exist();
|
||||
}
|
||||
|
||||
function getCacheId()
|
||||
{
|
||||
return $this->nCacheId;
|
||||
}
|
||||
function getStatus()
|
||||
{
|
||||
return $this->reCache->getValue('status');
|
||||
}
|
||||
function getType()
|
||||
{
|
||||
return $this->reCache->getValue('type');
|
||||
}
|
||||
function getName()
|
||||
{
|
||||
return $this->reCache->getValue('name');
|
||||
}
|
||||
function getLongitude()
|
||||
{
|
||||
return $this->reCache->getValue('longitude');
|
||||
}
|
||||
function getLatitude()
|
||||
{
|
||||
return $this->reCache->getValue('latitude');
|
||||
}
|
||||
function getUserId()
|
||||
{
|
||||
return $this->reCache->getValue('user_id');
|
||||
}
|
||||
function getUsername()
|
||||
{
|
||||
return sql_value("SELECT `username` FROM `user` WHERE `user_id`='&1'", '', $this->getUserId());
|
||||
}
|
||||
function getWPOC()
|
||||
{
|
||||
return $this->reCache->getValue('wp_oc');
|
||||
}
|
||||
function getWPGC()
|
||||
{
|
||||
return $this->reCache->getValue('wp_gc');
|
||||
}
|
||||
function getWPNC()
|
||||
{
|
||||
return $this->reCache->getValue('wp_nc');
|
||||
}
|
||||
|
||||
function getUUID()
|
||||
{
|
||||
return $this->reCache->getValue('uuid');
|
||||
}
|
||||
function getLastModified()
|
||||
{
|
||||
return $this->reCache->getValue('last_modified');
|
||||
}
|
||||
function getDateCreated()
|
||||
{
|
||||
return $this->reCache->getValue('date_created');
|
||||
}
|
||||
function getNode()
|
||||
{
|
||||
return $this->reCache->getValue('node');
|
||||
}
|
||||
function setNode($value)
|
||||
{
|
||||
return $this->reCache->setValue('node', $value);
|
||||
}
|
||||
function setStatus($value)
|
||||
{
|
||||
if (sql_value("SELECT COUNT(*) FROM `cache_status` WHERE `id`='&1'", 0, $value) == 1)
|
||||
{
|
||||
return $this->reCache->setValue('status', $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getAnyChanged()
|
||||
{
|
||||
return $this->reCache->getAnyChanged();
|
||||
}
|
||||
|
||||
// return if successfull (with insert)
|
||||
function save()
|
||||
{
|
||||
if ($this->reCache->save())
|
||||
{
|
||||
sql_slave_exclude();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function requireLogPW()
|
||||
{
|
||||
return $this->reCache->getValue('logpw') != '';
|
||||
}
|
||||
|
||||
// TODO: use prepared one way hash
|
||||
function validateLogPW($nLogType, $sLogPW)
|
||||
{
|
||||
if ($sLogPW == '')
|
||||
return true;
|
||||
|
||||
if (sql_value("SELECT `require_password` FROM `log_types` WHERE `id`='&1'", 0, $nLogType) == 0)
|
||||
return true;
|
||||
|
||||
return ($sLogPW == $this->reCache->getValue('logpw'));
|
||||
}
|
||||
|
||||
static function visitCounter($nVisitUserId, $sRemoteAddr, $nCacheId)
|
||||
{
|
||||
// delete cache_visits older 1 day 60*60*24 = 86400
|
||||
sql("DELETE FROM `cache_visits` WHERE `cache_id`='&1' AND `user_id_ip`!='0' AND NOW()-`last_modified`>86400", $nCacheId);
|
||||
|
||||
if ($nVisitUserId==0)
|
||||
$sIdentifier = $sRemoteAddr;
|
||||
else
|
||||
$sIdentifier = $nVisitUserId;
|
||||
|
||||
// note the visit of this user
|
||||
sql("INSERT INTO `cache_visits` (`cache_id`, `user_id_ip`, `count`) VALUES (&1, '&2', 1)
|
||||
ON DUPLICATE KEY UPDATE `count`=`count`+1", $nCacheId, $sIdentifier);
|
||||
|
||||
// if the previous statement does an INSERT, it was the first visit for this user
|
||||
if (sql_affected_rows() == 1)
|
||||
{
|
||||
if ($nVisitUserId != sql_value("SELECT `user_id` FROM `caches` WHERE `cache_id`='&1'", 0, $nCacheId))
|
||||
{
|
||||
// increment the counter for this cache
|
||||
sql("INSERT INTO `cache_visits` (`cache_id`, `user_id_ip`, `count`) VALUES (&1, '0', 1)
|
||||
ON DUPLICATE KEY UPDATE `count`=`count`+1", $nCacheId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function getLogsCount($cacheid)
|
||||
{
|
||||
//prepare the logs
|
||||
$rsLogs = sql("SELECT COUNT(*) FROM `cache_logs` WHERE `cache_id`='&1'", $cacheid);
|
||||
$rLog = sql_fetch_assoc($rsLogs);
|
||||
sql_free_result($rsLogs);
|
||||
|
||||
return $rLog;
|
||||
}
|
||||
|
||||
|
||||
static function getLogsArray($cacheid, $start, $count)
|
||||
{
|
||||
//prepare the logs
|
||||
$rsLogs = sql("
|
||||
SELECT `cache_logs`.`user_id` AS `userid`,
|
||||
`cache_logs`.`id` AS `id`,
|
||||
`cache_logs`.`uuid` AS `uuid`,
|
||||
`cache_logs`.`date` AS `date`,
|
||||
`cache_logs`.`type` AS `type`,
|
||||
`cache_logs`.`text` AS `text`,
|
||||
`cache_logs`.`text_html` AS `texthtml`,
|
||||
`cache_logs`.`picture`,
|
||||
`user`.`username` AS `username`,
|
||||
IF(ISNULL(`cache_rating`.`cache_id`), 0, `cache_logs`.`type` IN (1,7)) AS `recommended`
|
||||
FROM `cache_logs`
|
||||
INNER JOIN `user` ON `user`.`user_id` = `cache_logs`.`user_id`
|
||||
LEFT JOIN `cache_rating` ON `cache_logs`.`cache_id`=`cache_rating`.`cache_id` AND `cache_logs`.`user_id`=`cache_rating`.`user_id`
|
||||
WHERE `cache_logs`.`cache_id`='&1'
|
||||
ORDER BY `cache_logs`.`date` DESC, `cache_logs`.`Id` DESC LIMIT &2, &3", $cacheid, $start+0, $count+0);
|
||||
|
||||
$logs = array();
|
||||
while ($rLog = sql_fetch_assoc($rsLogs))
|
||||
{
|
||||
$pictures = array();
|
||||
$rsPictures = sql("SELECT `url`, `title`, `uuid` FROM `pictures` WHERE `object_id`='&1' AND `object_type`=1", $rLog['id']);
|
||||
while ($rPicture = sql_fetch_assoc($rsPictures))
|
||||
$pictures[] = $rPicture;
|
||||
sql_free_result($rsPictures);
|
||||
$rLog['pictures'] = $pictures;
|
||||
|
||||
$logs[] = $rLog;
|
||||
}
|
||||
sql_free_result($rsLogs);
|
||||
|
||||
return $logs;
|
||||
}
|
||||
|
||||
function report($userid, $reportreason, $reportnote)
|
||||
{
|
||||
sql("INSERT INTO cache_reports (`cacheid`, `userid`, `reason`, `note`)
|
||||
VALUES(&1, &2, &3, '&4')",
|
||||
$this->nCacheId, $userid, $reportreason, $reportnote);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function addAdoption($userid)
|
||||
{
|
||||
if ($this->allowEdit() == false)
|
||||
return false;
|
||||
|
||||
if (sql_value("SELECT COUNT(*) FROM `user` WHERE `user_id`='&1' AND `is_active_flag`=1", 0, $userid) == 0)
|
||||
return false;
|
||||
|
||||
// same user?
|
||||
if ($this->getUserId() == $userid)
|
||||
return false;
|
||||
|
||||
sql("INSERT IGNORE INTO `cache_adoption` (`cache_id`, `user_id`) VALUES ('&1', '&2')", $this->nCacheId, $userid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function cancelAdoption($userid)
|
||||
{
|
||||
global $login;
|
||||
|
||||
if ($this->allowEdit() == false && $login->userid != $userid)
|
||||
return false;
|
||||
|
||||
sql("DELETE FROM `cache_adoption` WHERE `user_id`='&1' AND `cache_id`='&2'", $userid, $this->nCacheId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function commitAdoption($userid)
|
||||
{
|
||||
global $login;
|
||||
|
||||
// cache_adoption exists?
|
||||
if (sql_value("SELECT COUNT(*) FROM `cache_adoption` WHERE `cache_id`='&1' AND `user_id`='&2'", 0, $this->nCacheId, $userid) == 0)
|
||||
return false;
|
||||
|
||||
// new user active?
|
||||
if (sql_value("SELECT `is_active_flag` FROM `user` WHERE `user_id`='&1'", 0, $userid) != 1)
|
||||
return false;
|
||||
|
||||
sql("INSERT INTO `logentries` (`module`, `eventid`, `userid`, `objectid1`, `objectid2`, `logtext`)
|
||||
VALUES ('cache', 5, '&1', '&2', '&3', '&4')",
|
||||
$login->userid, $this->nCacheId, 0,
|
||||
'Cache ' . sql_escape($this->nCacheId) . ' has changed the owner from userid ' . sql_escape($this->getUserId()) . ' to ' . sql_escape($userid) . ' by ' . sql_escape($login->userid));
|
||||
sql("UPDATE `caches` SET `user_id`='&1' WHERE `cache_id`='&2'", $userid, $this->nCacheId);
|
||||
sql("DELETE FROM `cache_adoption` WHERE `cache_id`='&1'", $this->nCacheId);
|
||||
|
||||
$this->reCache->setValue('user_id', $userid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// true if anyone can view the cache
|
||||
function isPublic()
|
||||
{
|
||||
return (sql_value("SELECT `allow_user_view` FROM `cache_status` WHERE `id`='&1'", 0, $this->getStatus()) == 1);
|
||||
}
|
||||
function allowView()
|
||||
{
|
||||
global $login;
|
||||
|
||||
if ($this->isPublic())
|
||||
return true;
|
||||
|
||||
$login->verify();
|
||||
|
||||
if (($login->admin & ADMIN_USER) == ADMIN_USER)
|
||||
return true;
|
||||
else if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
function allowEdit()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
function allowLog()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return (sql_value("SELECT `allow_user_log` FROM `cache_status` WHERE `id`='&1'", 0, $this->getStatus()) == 1);
|
||||
}
|
||||
|
||||
function isRecommendedByUser($nUserId)
|
||||
{
|
||||
return (sql_value("SELECT COUNT(*) FROM `cache_rating` WHERE `cache_id`='&1' AND `user_id`='&2'", 0, $this->nCacheId, $nUserId) > 0);
|
||||
}
|
||||
function addRecommendation($nUserId)
|
||||
{
|
||||
// rating_date will be set to NOW() by Insert-trigger
|
||||
sql("INSERT IGNORE INTO `cache_rating` (`cache_id`, `user_id`) VALUES ('&1', '&2')", $this->nCacheId, $nUserId);
|
||||
}
|
||||
function removeRecommendation($nUserId)
|
||||
{
|
||||
sql("DELETE FROM `cache_rating` WHERE `cache_id`='&1' AND `user_id`='&2'", $this->nCacheId, $nUserId);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* get/set has to be commited with save
|
||||
* add/remove etc. is executed instantly
|
||||
***************************************************************************/
|
||||
|
||||
require_once($opt['rootpath'] . 'lib2/logic/rowEditor.class.php');
|
||||
|
||||
class cache
|
||||
{
|
||||
var $nCacheId = 0;
|
||||
|
||||
var $reCache;
|
||||
|
||||
static function cacheIdFromWP($wp)
|
||||
{
|
||||
$cacheid = 0;
|
||||
if (mb_strtoupper(mb_substr($wp, 0, 2)) == 'GC')
|
||||
{
|
||||
$rs = sql("SELECT `cache_id` FROM `caches` WHERE `wp_gc`='&1'", $wp);
|
||||
if (sql_num_rows($rs) != 1)
|
||||
{
|
||||
sql_free_result($rs);
|
||||
return null;
|
||||
}
|
||||
$r = sql_fetch_assoc($rs);
|
||||
sql_free_result($rs);
|
||||
|
||||
$cacheid = $r['cache_id'];
|
||||
}
|
||||
else if (mb_strtoupper(mb_substr($wp, 0, 1)) == 'N')
|
||||
{
|
||||
$rs = sql("SELECT `cache_id` FROM `caches` WHERE `wp_nc`='&1'", $wp);
|
||||
if (sql_num_rows($rs) != 1)
|
||||
{
|
||||
sql_free_result($rs);
|
||||
return null;
|
||||
}
|
||||
$r = sql_fetch_assoc($rs);
|
||||
sql_free_result($rs);
|
||||
|
||||
$cacheid = $r['cache_id'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$cacheid = sql_value("SELECT `cache_id` FROM `caches` WHERE `wp_oc`='&1'", 0, $wp);
|
||||
}
|
||||
|
||||
return $cacheid;
|
||||
}
|
||||
|
||||
static function fromWP($wp)
|
||||
{
|
||||
$cacheid = cache::cacheIdFromWP($wp);
|
||||
if ($cacheid == 0)
|
||||
return null;
|
||||
|
||||
return new cache($cacheid);
|
||||
}
|
||||
|
||||
static function cacheIdFromUUID($uuid)
|
||||
{
|
||||
$cacheid = sql_value("SELECT `cache_id` FROM `caches` WHERE `uuid`='&1'", 0, $uuid);
|
||||
return $cacheid;
|
||||
}
|
||||
|
||||
static function fromUUID($uuid)
|
||||
{
|
||||
$cacheid = cache::cacheIdFromUUID($uuid);
|
||||
if ($cacheid == 0)
|
||||
return null;
|
||||
|
||||
return new cache($cacheid);
|
||||
}
|
||||
|
||||
function __construct($nNewCacheId=ID_NEW)
|
||||
{
|
||||
$this->reCache = new rowEditor('caches');
|
||||
$this->reCache->addPKInt('cache_id', null, false, RE_INSERT_AUTOINCREMENT);
|
||||
$this->reCache->addString('uuid', '', false, RE_INSERT_AUTOUUID);
|
||||
$this->reCache->addInt('node', 0, false);
|
||||
$this->reCache->addDate('date_created', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reCache->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reCache->addInt('user_id', 0, false);
|
||||
$this->reCache->addString('name', '', false);
|
||||
$this->reCache->addDouble('longitude', 0, false);
|
||||
$this->reCache->addDouble('latitude', 0, false);
|
||||
$this->reCache->addInt('type', 1, false);
|
||||
$this->reCache->addInt('status', 5, false);
|
||||
$this->reCache->addString('country', '', false);
|
||||
$this->reCache->addDate('date_hidden', time(), false);
|
||||
$this->reCache->addInt('size', 1, false);
|
||||
$this->reCache->addFloat('difficulty', 1, false);
|
||||
$this->reCache->addFloat('terrain', 1, false);
|
||||
$this->reCache->addString('logpw', '', false);
|
||||
$this->reCache->addFloat('search_time', 0, false);
|
||||
$this->reCache->addFloat('way_length', 0, false);
|
||||
$this->reCache->addString('wp_oc', null, true);
|
||||
$this->reCache->addString('wp_gc', '', false);
|
||||
$this->reCache->addString('wp_nc', '', false);
|
||||
$this->reCache->addString('desc_languages', '', false, RE_INSERT_IGNORE);
|
||||
$this->reCache->addString('default_desclang', '', false);
|
||||
$this->reCache->addDate('date_activate', null, true);
|
||||
$this->reCache->addInt('need_npa_recalc', 1, false, RE_INSERT_IGNORE);
|
||||
|
||||
$this->nCacheId = $nNewCacheId+0;
|
||||
|
||||
if ($nNewCacheId == ID_NEW)
|
||||
{
|
||||
$this->reCache->addNew(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->reCache->load($this->nCacheId);
|
||||
}
|
||||
}
|
||||
|
||||
function exist()
|
||||
{
|
||||
return $this->reCache->exist();
|
||||
}
|
||||
|
||||
function getCacheId()
|
||||
{
|
||||
return $this->nCacheId;
|
||||
}
|
||||
function getStatus()
|
||||
{
|
||||
return $this->reCache->getValue('status');
|
||||
}
|
||||
function getType()
|
||||
{
|
||||
return $this->reCache->getValue('type');
|
||||
}
|
||||
function getName()
|
||||
{
|
||||
return $this->reCache->getValue('name');
|
||||
}
|
||||
function getLongitude()
|
||||
{
|
||||
return $this->reCache->getValue('longitude');
|
||||
}
|
||||
function getLatitude()
|
||||
{
|
||||
return $this->reCache->getValue('latitude');
|
||||
}
|
||||
function getUserId()
|
||||
{
|
||||
return $this->reCache->getValue('user_id');
|
||||
}
|
||||
function getUsername()
|
||||
{
|
||||
return sql_value("SELECT `username` FROM `user` WHERE `user_id`='&1'", '', $this->getUserId());
|
||||
}
|
||||
function getWPOC()
|
||||
{
|
||||
return $this->reCache->getValue('wp_oc');
|
||||
}
|
||||
function getWPGC()
|
||||
{
|
||||
return $this->reCache->getValue('wp_gc');
|
||||
}
|
||||
function getWPNC()
|
||||
{
|
||||
return $this->reCache->getValue('wp_nc');
|
||||
}
|
||||
|
||||
function getUUID()
|
||||
{
|
||||
return $this->reCache->getValue('uuid');
|
||||
}
|
||||
function getLastModified()
|
||||
{
|
||||
return $this->reCache->getValue('last_modified');
|
||||
}
|
||||
function getDateCreated()
|
||||
{
|
||||
return $this->reCache->getValue('date_created');
|
||||
}
|
||||
function getNode()
|
||||
{
|
||||
return $this->reCache->getValue('node');
|
||||
}
|
||||
function setNode($value)
|
||||
{
|
||||
return $this->reCache->setValue('node', $value);
|
||||
}
|
||||
function setStatus($value)
|
||||
{
|
||||
if (sql_value("SELECT COUNT(*) FROM `cache_status` WHERE `id`='&1'", 0, $value) == 1)
|
||||
{
|
||||
return $this->reCache->setValue('status', $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getAnyChanged()
|
||||
{
|
||||
return $this->reCache->getAnyChanged();
|
||||
}
|
||||
|
||||
// return if successfull (with insert)
|
||||
function save()
|
||||
{
|
||||
if ($this->reCache->save())
|
||||
{
|
||||
sql_slave_exclude();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function requireLogPW()
|
||||
{
|
||||
return $this->reCache->getValue('logpw') != '';
|
||||
}
|
||||
|
||||
// TODO: use prepared one way hash
|
||||
function validateLogPW($nLogType, $sLogPW)
|
||||
{
|
||||
if ($sLogPW == '')
|
||||
return true;
|
||||
|
||||
if (sql_value("SELECT `require_password` FROM `log_types` WHERE `id`='&1'", 0, $nLogType) == 0)
|
||||
return true;
|
||||
|
||||
return ($sLogPW == $this->reCache->getValue('logpw'));
|
||||
}
|
||||
|
||||
static function visitCounter($nVisitUserId, $sRemoteAddr, $nCacheId)
|
||||
{
|
||||
// delete cache_visits older 1 day 60*60*24 = 86400
|
||||
sql("DELETE FROM `cache_visits` WHERE `cache_id`='&1' AND `user_id_ip`!='0' AND NOW()-`last_modified`>86400", $nCacheId);
|
||||
|
||||
if ($nVisitUserId==0)
|
||||
$sIdentifier = $sRemoteAddr;
|
||||
else
|
||||
$sIdentifier = $nVisitUserId;
|
||||
|
||||
// note the visit of this user
|
||||
sql("INSERT INTO `cache_visits` (`cache_id`, `user_id_ip`, `count`) VALUES (&1, '&2', 1)
|
||||
ON DUPLICATE KEY UPDATE `count`=`count`+1", $nCacheId, $sIdentifier);
|
||||
|
||||
// if the previous statement does an INSERT, it was the first visit for this user
|
||||
if (sql_affected_rows() == 1)
|
||||
{
|
||||
if ($nVisitUserId != sql_value("SELECT `user_id` FROM `caches` WHERE `cache_id`='&1'", 0, $nCacheId))
|
||||
{
|
||||
// increment the counter for this cache
|
||||
sql("INSERT INTO `cache_visits` (`cache_id`, `user_id_ip`, `count`) VALUES (&1, '0', 1)
|
||||
ON DUPLICATE KEY UPDATE `count`=`count`+1", $nCacheId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static function getLogsCount($cacheid)
|
||||
{
|
||||
//prepare the logs
|
||||
$rsLogs = sql("SELECT COUNT(*) FROM `cache_logs` WHERE `cache_id`='&1'", $cacheid);
|
||||
$rLog = sql_fetch_assoc($rsLogs);
|
||||
sql_free_result($rsLogs);
|
||||
|
||||
return $rLog;
|
||||
}
|
||||
|
||||
|
||||
static function getLogsArray($cacheid, $start, $count)
|
||||
{
|
||||
//prepare the logs
|
||||
$rsLogs = sql("
|
||||
SELECT `cache_logs`.`user_id` AS `userid`,
|
||||
`cache_logs`.`id` AS `id`,
|
||||
`cache_logs`.`uuid` AS `uuid`,
|
||||
`cache_logs`.`date` AS `date`,
|
||||
`cache_logs`.`type` AS `type`,
|
||||
`cache_logs`.`text` AS `text`,
|
||||
`cache_logs`.`text_html` AS `texthtml`,
|
||||
`cache_logs`.`picture`,
|
||||
`user`.`username` AS `username`,
|
||||
IF(ISNULL(`cache_rating`.`cache_id`), 0, `cache_logs`.`type` IN (1,7)) AS `recommended`
|
||||
FROM `cache_logs`
|
||||
INNER JOIN `user` ON `user`.`user_id` = `cache_logs`.`user_id`
|
||||
LEFT JOIN `cache_rating` ON `cache_logs`.`cache_id`=`cache_rating`.`cache_id` AND `cache_logs`.`user_id`=`cache_rating`.`user_id`
|
||||
WHERE `cache_logs`.`cache_id`='&1'
|
||||
ORDER BY `cache_logs`.`date` DESC, `cache_logs`.`Id` DESC LIMIT &2, &3", $cacheid, $start+0, $count+0);
|
||||
|
||||
$logs = array();
|
||||
while ($rLog = sql_fetch_assoc($rsLogs))
|
||||
{
|
||||
$pictures = array();
|
||||
$rsPictures = sql("SELECT `url`, `title`, `uuid` FROM `pictures` WHERE `object_id`='&1' AND `object_type`=1", $rLog['id']);
|
||||
while ($rPicture = sql_fetch_assoc($rsPictures))
|
||||
$pictures[] = $rPicture;
|
||||
sql_free_result($rsPictures);
|
||||
$rLog['pictures'] = $pictures;
|
||||
|
||||
$logs[] = $rLog;
|
||||
}
|
||||
sql_free_result($rsLogs);
|
||||
|
||||
return $logs;
|
||||
}
|
||||
|
||||
function report($userid, $reportreason, $reportnote)
|
||||
{
|
||||
sql("INSERT INTO cache_reports (`cacheid`, `userid`, `reason`, `note`)
|
||||
VALUES(&1, &2, &3, '&4')",
|
||||
$this->nCacheId, $userid, $reportreason, $reportnote);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function addAdoption($userid)
|
||||
{
|
||||
if ($this->allowEdit() == false)
|
||||
return false;
|
||||
|
||||
if (sql_value("SELECT COUNT(*) FROM `user` WHERE `user_id`='&1' AND `is_active_flag`=1", 0, $userid) == 0)
|
||||
return false;
|
||||
|
||||
// same user?
|
||||
if ($this->getUserId() == $userid)
|
||||
return false;
|
||||
|
||||
sql("INSERT IGNORE INTO `cache_adoption` (`cache_id`, `user_id`) VALUES ('&1', '&2')", $this->nCacheId, $userid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function cancelAdoption($userid)
|
||||
{
|
||||
global $login;
|
||||
|
||||
if ($this->allowEdit() == false && $login->userid != $userid)
|
||||
return false;
|
||||
|
||||
sql("DELETE FROM `cache_adoption` WHERE `user_id`='&1' AND `cache_id`='&2'", $userid, $this->nCacheId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function commitAdoption($userid)
|
||||
{
|
||||
global $login;
|
||||
|
||||
// cache_adoption exists?
|
||||
if (sql_value("SELECT COUNT(*) FROM `cache_adoption` WHERE `cache_id`='&1' AND `user_id`='&2'", 0, $this->nCacheId, $userid) == 0)
|
||||
return false;
|
||||
|
||||
// new user active?
|
||||
if (sql_value("SELECT `is_active_flag` FROM `user` WHERE `user_id`='&1'", 0, $userid) != 1)
|
||||
return false;
|
||||
|
||||
sql("INSERT INTO `logentries` (`module`, `eventid`, `userid`, `objectid1`, `objectid2`, `logtext`)
|
||||
VALUES ('cache', 5, '&1', '&2', '&3', '&4')",
|
||||
$login->userid, $this->nCacheId, 0,
|
||||
'Cache ' . sql_escape($this->nCacheId) . ' has changed the owner from userid ' . sql_escape($this->getUserId()) . ' to ' . sql_escape($userid) . ' by ' . sql_escape($login->userid));
|
||||
sql("UPDATE `caches` SET `user_id`='&1' WHERE `cache_id`='&2'", $userid, $this->nCacheId);
|
||||
sql("DELETE FROM `cache_adoption` WHERE `cache_id`='&1'", $this->nCacheId);
|
||||
|
||||
$this->reCache->setValue('user_id', $userid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// true if anyone can view the cache
|
||||
function isPublic()
|
||||
{
|
||||
return (sql_value("SELECT `allow_user_view` FROM `cache_status` WHERE `id`='&1'", 0, $this->getStatus()) == 1);
|
||||
}
|
||||
function allowView()
|
||||
{
|
||||
global $login;
|
||||
|
||||
if ($this->isPublic())
|
||||
return true;
|
||||
|
||||
$login->verify();
|
||||
|
||||
if (($login->admin & ADMIN_USER) == ADMIN_USER)
|
||||
return true;
|
||||
else if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
function allowEdit()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
function allowLog()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return (sql_value("SELECT `allow_user_log` FROM `cache_status` WHERE `id`='&1'", 0, $this->getStatus()) == 1);
|
||||
}
|
||||
|
||||
function isRecommendedByUser($nUserId)
|
||||
{
|
||||
return (sql_value("SELECT COUNT(*) FROM `cache_rating` WHERE `cache_id`='&1' AND `user_id`='&2'", 0, $this->nCacheId, $nUserId) > 0);
|
||||
}
|
||||
function addRecommendation($nUserId)
|
||||
{
|
||||
// rating_date will be set to NOW() by Insert-trigger
|
||||
sql("INSERT IGNORE INTO `cache_rating` (`cache_id`, `user_id`) VALUES ('&1', '&2')", $this->nCacheId, $nUserId);
|
||||
}
|
||||
function removeRecommendation($nUserId)
|
||||
{
|
||||
sql("DELETE FROM `cache_rating` WHERE `cache_id`='&1' AND `user_id`='&2'", $this->nCacheId, $nUserId);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,121 +1,121 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* get/set has to be commited with save
|
||||
* add/remove etc. is executed instantly
|
||||
***************************************************************************/
|
||||
|
||||
require_once($opt['rootpath'] . 'lib2/logic/rowEditor.class.php');
|
||||
|
||||
class user
|
||||
{
|
||||
var $nCacheDescId = 0;
|
||||
var $reCacheDesc;
|
||||
|
||||
function __construct($nNewCacheDescId=ID_NEW)
|
||||
{
|
||||
$this->reUser = new rowEditor('cache_desc');
|
||||
$this->reUser->addPKInt('id', null, false, RE_INSERT_AUTOINCREMENT);
|
||||
$this->reUser->addString('uuid', '', false, RE_INSERT_OVERWRITE|RE_INSERT_UUID);
|
||||
$this->reUser->addInt('node', 0, false);
|
||||
$this->reUser->addDate('date_created', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reUser->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reUser->addInt('cache_id', 0, false);
|
||||
$this->reUser->addString('language', '', false);
|
||||
$this->reUser->addString('desc', '', false);
|
||||
$this->reUser->addInt('desc_html', 0, false);
|
||||
$this->reUser->addInt('desc_htmledit', 0, false);
|
||||
$this->reUser->addString('hint', '', false);
|
||||
$this->reUser->addString('short_desc', '', false);
|
||||
|
||||
$this->nCacheDescId = $nNewCacheDescId+0;
|
||||
|
||||
if ($nNewCacheDescId == ID_NEW)
|
||||
{
|
||||
$this->reCacheDesc->addNew(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->reCacheDesc->load($this->nCacheDescId);
|
||||
}
|
||||
}
|
||||
|
||||
function exist()
|
||||
{
|
||||
return $this->reCacheDesc->exist();
|
||||
}
|
||||
|
||||
function getId()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('id');
|
||||
}
|
||||
function getUUID()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('uuid');
|
||||
}
|
||||
function getNode()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('node');
|
||||
}
|
||||
function setNode($value)
|
||||
{
|
||||
return $this->reCacheDesc->setValue('node', $value);
|
||||
}
|
||||
function getDateCreated()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('date_created');
|
||||
}
|
||||
function getLastModified()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('last_modified');
|
||||
}
|
||||
function getCacheId()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('cache_id');
|
||||
}
|
||||
function getLanguage()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('language');
|
||||
}
|
||||
function getDescAsHtml()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('desc');
|
||||
}
|
||||
function getIsDescHtml()
|
||||
{
|
||||
return ($this->reCacheDesc->getValue('desc_html')!=0);
|
||||
}
|
||||
function getDescHtmlEdit()
|
||||
{
|
||||
return ($this->reCacheDesc->getValue('desc_htmledit')!=0);
|
||||
}
|
||||
function getHint()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('hint');
|
||||
}
|
||||
function getShortDesc()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('short_desc');
|
||||
}
|
||||
|
||||
function getAnyChanged()
|
||||
{
|
||||
return $this->reCacheDesc->getAnyChanged();
|
||||
}
|
||||
|
||||
// return if successfull (with insert)
|
||||
function save()
|
||||
{
|
||||
sql_slave_exclude();
|
||||
return $this->reCacheDesc->save();
|
||||
}
|
||||
|
||||
function reload()
|
||||
{
|
||||
$this->reCacheDesc->reload();
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* get/set has to be commited with save
|
||||
* add/remove etc. is executed instantly
|
||||
***************************************************************************/
|
||||
|
||||
require_once($opt['rootpath'] . 'lib2/logic/rowEditor.class.php');
|
||||
|
||||
class user
|
||||
{
|
||||
var $nCacheDescId = 0;
|
||||
var $reCacheDesc;
|
||||
|
||||
function __construct($nNewCacheDescId=ID_NEW)
|
||||
{
|
||||
$this->reUser = new rowEditor('cache_desc');
|
||||
$this->reUser->addPKInt('id', null, false, RE_INSERT_AUTOINCREMENT);
|
||||
$this->reUser->addString('uuid', '', false, RE_INSERT_AUTOUUID);
|
||||
$this->reUser->addInt('node', 0, false);
|
||||
$this->reUser->addDate('date_created', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reUser->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reUser->addInt('cache_id', 0, false);
|
||||
$this->reUser->addString('language', '', false);
|
||||
$this->reUser->addString('desc', '', false);
|
||||
$this->reUser->addInt('desc_html', 0, false);
|
||||
$this->reUser->addInt('desc_htmledit', 0, false);
|
||||
$this->reUser->addString('hint', '', false);
|
||||
$this->reUser->addString('short_desc', '', false);
|
||||
|
||||
$this->nCacheDescId = $nNewCacheDescId+0;
|
||||
|
||||
if ($nNewCacheDescId == ID_NEW)
|
||||
{
|
||||
$this->reCacheDesc->addNew(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->reCacheDesc->load($this->nCacheDescId);
|
||||
}
|
||||
}
|
||||
|
||||
function exist()
|
||||
{
|
||||
return $this->reCacheDesc->exist();
|
||||
}
|
||||
|
||||
function getId()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('id');
|
||||
}
|
||||
function getUUID()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('uuid');
|
||||
}
|
||||
function getNode()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('node');
|
||||
}
|
||||
function setNode($value)
|
||||
{
|
||||
return $this->reCacheDesc->setValue('node', $value);
|
||||
}
|
||||
function getDateCreated()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('date_created');
|
||||
}
|
||||
function getLastModified()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('last_modified');
|
||||
}
|
||||
function getCacheId()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('cache_id');
|
||||
}
|
||||
function getLanguage()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('language');
|
||||
}
|
||||
function getDescAsHtml()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('desc');
|
||||
}
|
||||
function getIsDescHtml()
|
||||
{
|
||||
return ($this->reCacheDesc->getValue('desc_html')!=0);
|
||||
}
|
||||
function getDescHtmlEdit()
|
||||
{
|
||||
return ($this->reCacheDesc->getValue('desc_htmledit')!=0);
|
||||
}
|
||||
function getHint()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('hint');
|
||||
}
|
||||
function getShortDesc()
|
||||
{
|
||||
return $this->reCacheDesc->getValue('short_desc');
|
||||
}
|
||||
|
||||
function getAnyChanged()
|
||||
{
|
||||
return $this->reCacheDesc->getAnyChanged();
|
||||
}
|
||||
|
||||
// return if successfull (with insert)
|
||||
function save()
|
||||
{
|
||||
sql_slave_exclude();
|
||||
return $this->reCacheDesc->save();
|
||||
}
|
||||
|
||||
function reload()
|
||||
{
|
||||
$this->reCacheDesc->reload();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,225 +1,225 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* get/set has to be commited with save
|
||||
* add/remove etc. is executed instantly
|
||||
***************************************************************************/
|
||||
|
||||
require_once($opt['rootpath'] . 'lib2/logic/rowEditor.class.php');
|
||||
require_once($opt['rootpath'] . 'lib2/logic/cache.class.php');
|
||||
|
||||
class cachelog
|
||||
{
|
||||
var $nLogId = 0;
|
||||
|
||||
var $reCacheLog;
|
||||
|
||||
static function logIdFromUUID($uuid)
|
||||
{
|
||||
$cacheid = sql_value("SELECT `id` FROM `cache_logs` WHERE `uuid`='&1'", 0, $uuid);
|
||||
return $cacheid;
|
||||
}
|
||||
|
||||
static function fromUUID($uuid)
|
||||
{
|
||||
$logid = cachelog::logIdFromUUID($uuid);
|
||||
if ($logid == 0)
|
||||
return null;
|
||||
|
||||
return new cachelog($logid);
|
||||
}
|
||||
|
||||
static function createNew($nCacheId, $nUserId)
|
||||
{
|
||||
// check if user is allowed to log this cache!
|
||||
$cache = new cache($nCacheId);
|
||||
if ($cache->exist() == false)
|
||||
return false;
|
||||
if ($cache->allowLog() == false)
|
||||
return false;
|
||||
|
||||
$oCacheLog = new cachelog(ID_NEW);
|
||||
$oCacheLog->setUserId($nUserId);
|
||||
$oCacheLog->setCacheId($nCacheId);
|
||||
return $oCacheLog;
|
||||
}
|
||||
|
||||
function __construct($nNewLogId=ID_NEW)
|
||||
{
|
||||
$this->reCacheLog = new rowEditor('cache_logs');
|
||||
$this->reCacheLog->addPKInt('id', null, false, RE_INSERT_AUTOINCREMENT);
|
||||
$this->reCacheLog->addString('uuid', '', false, RE_INSERT_OVERWRITE|RE_INSERT_UUID);
|
||||
$this->reCacheLog->addInt('node', 0, false);
|
||||
$this->reCacheLog->addDate('date_created', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reCacheLog->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reCacheLog->addInt('cache_id', 0, false);
|
||||
$this->reCacheLog->addInt('user_id', 0, false);
|
||||
$this->reCacheLog->addInt('type', 0, false);
|
||||
$this->reCacheLog->addDate('date', time(), false);
|
||||
$this->reCacheLog->addString('text', '', false);
|
||||
$this->reCacheLog->addInt('text_html', 0, false);
|
||||
$this->reCacheLog->addInt('text_htmledit', 0, false);
|
||||
$this->reCacheLog->addInt('owner_notified', 0, false);
|
||||
$this->reCacheLog->addInt('picture', 0, false);
|
||||
|
||||
$this->nLogId = $nNewLogId+0;
|
||||
|
||||
if ($nNewLogId == ID_NEW)
|
||||
{
|
||||
$this->reCacheLog->addNew(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->reCacheLog->load($this->nLogId);
|
||||
}
|
||||
}
|
||||
|
||||
function exist()
|
||||
{
|
||||
return $this->reCacheLog->exist();
|
||||
}
|
||||
|
||||
function getLogId()
|
||||
{
|
||||
return $this->nLogId;
|
||||
}
|
||||
function getUserId()
|
||||
{
|
||||
return $this->reCacheLog->getValue('user_id');
|
||||
}
|
||||
function setUserId($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('user_id', $value);
|
||||
}
|
||||
function getCacheId()
|
||||
{
|
||||
return $this->reCacheLog->getValue('cache_id');
|
||||
}
|
||||
function setCacheId($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('cache_id', $value);
|
||||
}
|
||||
function getType()
|
||||
{
|
||||
return $this->reCacheLog->getValue('type');
|
||||
}
|
||||
function setType($value)
|
||||
{
|
||||
$nValidLogTypes = $this->getValidLogTypes();
|
||||
if (array_search($value, $nValidLogTypes) === false)
|
||||
return false;
|
||||
|
||||
return $this->reCacheLog->setValue('type', $value);
|
||||
}
|
||||
function getDate()
|
||||
{
|
||||
return $this->reCacheLog->getValue('date');
|
||||
}
|
||||
function setDate($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('date', $value);
|
||||
}
|
||||
function getText()
|
||||
{
|
||||
return $this->reCacheLog->getValue('text');
|
||||
}
|
||||
function setText($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('text', $value);
|
||||
}
|
||||
function getTextHtml()
|
||||
{
|
||||
return $this->reCacheLog->getValue('text_html');
|
||||
}
|
||||
function setTextHtml($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('text_html', $value);
|
||||
}
|
||||
function getTextHtmlEdit()
|
||||
{
|
||||
return $this->reCacheLog->getValue('text_html');
|
||||
}
|
||||
function setTextHtmlEdit($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('text_htmledit', $value);
|
||||
}
|
||||
|
||||
function getUUID()
|
||||
{
|
||||
return $this->reCacheLog->getValue('uuid');
|
||||
}
|
||||
function getLastModified()
|
||||
{
|
||||
return $this->reCacheLog->getValue('last_modified');
|
||||
}
|
||||
function getDateCreated()
|
||||
{
|
||||
return $this->reCacheLog->getValue('date_created');
|
||||
}
|
||||
function getNode()
|
||||
{
|
||||
return $this->reCacheLog->getValue('node');
|
||||
}
|
||||
function setNode($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('node', $value);
|
||||
}
|
||||
|
||||
function getAnyChanged()
|
||||
{
|
||||
return $this->reCacheLog->getAnyChanged();
|
||||
}
|
||||
|
||||
// return if successfull (with insert)
|
||||
function save()
|
||||
{
|
||||
sql_slave_exclude();
|
||||
return $this->reCacheLog->save();
|
||||
}
|
||||
|
||||
function allowView()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
if (sql_value("SELECT `cache_status`.`allow_user_view` FROM `caches` INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id` WHERE `caches`.`cache_id`='&1'", 0, $this->getCacheId()) == 1)
|
||||
return true;
|
||||
else if ($login->userid == sql_value("SELECT `user_id` FROM `caches` WHERE `cache_id`='&1'", 0, $this->getCacheId()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function allowEdit()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* will depend on userid in future e.g. maintainance-logs etc. */
|
||||
function getValidLogTypes()
|
||||
{
|
||||
$cache = new cache($this->getCacheId());
|
||||
if ($cache->exist() == false)
|
||||
return array();
|
||||
if ($cache->allowLog() == false)
|
||||
return array();
|
||||
|
||||
$nTypes = array();
|
||||
$rs = sql("SELECT `log_type_id` FROM `cache_logtype` WHERE `cache_type_id`='&1'", $cache->getType());
|
||||
while ($r = sql_fetch_assoc($rs))
|
||||
$nTypes[] = $r['log_type_id'];
|
||||
sql_free_result($rs);
|
||||
|
||||
return $nTypes;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* get/set has to be commited with save
|
||||
* add/remove etc. is executed instantly
|
||||
***************************************************************************/
|
||||
|
||||
require_once($opt['rootpath'] . 'lib2/logic/rowEditor.class.php');
|
||||
require_once($opt['rootpath'] . 'lib2/logic/cache.class.php');
|
||||
|
||||
class cachelog
|
||||
{
|
||||
var $nLogId = 0;
|
||||
|
||||
var $reCacheLog;
|
||||
|
||||
static function logIdFromUUID($uuid)
|
||||
{
|
||||
$cacheid = sql_value("SELECT `id` FROM `cache_logs` WHERE `uuid`='&1'", 0, $uuid);
|
||||
return $cacheid;
|
||||
}
|
||||
|
||||
static function fromUUID($uuid)
|
||||
{
|
||||
$logid = cachelog::logIdFromUUID($uuid);
|
||||
if ($logid == 0)
|
||||
return null;
|
||||
|
||||
return new cachelog($logid);
|
||||
}
|
||||
|
||||
static function createNew($nCacheId, $nUserId)
|
||||
{
|
||||
// check if user is allowed to log this cache!
|
||||
$cache = new cache($nCacheId);
|
||||
if ($cache->exist() == false)
|
||||
return false;
|
||||
if ($cache->allowLog() == false)
|
||||
return false;
|
||||
|
||||
$oCacheLog = new cachelog(ID_NEW);
|
||||
$oCacheLog->setUserId($nUserId);
|
||||
$oCacheLog->setCacheId($nCacheId);
|
||||
return $oCacheLog;
|
||||
}
|
||||
|
||||
function __construct($nNewLogId=ID_NEW)
|
||||
{
|
||||
$this->reCacheLog = new rowEditor('cache_logs');
|
||||
$this->reCacheLog->addPKInt('id', null, false, RE_INSERT_AUTOINCREMENT);
|
||||
$this->reCacheLog->addString('uuid', '', false, RE_INSERT_AUTOUUID);
|
||||
$this->reCacheLog->addInt('node', 0, false);
|
||||
$this->reCacheLog->addDate('date_created', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reCacheLog->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
|
||||
$this->reCacheLog->addInt('cache_id', 0, false);
|
||||
$this->reCacheLog->addInt('user_id', 0, false);
|
||||
$this->reCacheLog->addInt('type', 0, false);
|
||||
$this->reCacheLog->addDate('date', time(), false);
|
||||
$this->reCacheLog->addString('text', '', false);
|
||||
$this->reCacheLog->addInt('text_html', 0, false);
|
||||
$this->reCacheLog->addInt('text_htmledit', 0, false);
|
||||
$this->reCacheLog->addInt('owner_notified', 0, false);
|
||||
$this->reCacheLog->addInt('picture', 0, false);
|
||||
|
||||
$this->nLogId = $nNewLogId+0;
|
||||
|
||||
if ($nNewLogId == ID_NEW)
|
||||
{
|
||||
$this->reCacheLog->addNew(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->reCacheLog->load($this->nLogId);
|
||||
}
|
||||
}
|
||||
|
||||
function exist()
|
||||
{
|
||||
return $this->reCacheLog->exist();
|
||||
}
|
||||
|
||||
function getLogId()
|
||||
{
|
||||
return $this->nLogId;
|
||||
}
|
||||
function getUserId()
|
||||
{
|
||||
return $this->reCacheLog->getValue('user_id');
|
||||
}
|
||||
function setUserId($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('user_id', $value);
|
||||
}
|
||||
function getCacheId()
|
||||
{
|
||||
return $this->reCacheLog->getValue('cache_id');
|
||||
}
|
||||
function setCacheId($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('cache_id', $value);
|
||||
}
|
||||
function getType()
|
||||
{
|
||||
return $this->reCacheLog->getValue('type');
|
||||
}
|
||||
function setType($value)
|
||||
{
|
||||
$nValidLogTypes = $this->getValidLogTypes();
|
||||
if (array_search($value, $nValidLogTypes) === false)
|
||||
return false;
|
||||
|
||||
return $this->reCacheLog->setValue('type', $value);
|
||||
}
|
||||
function getDate()
|
||||
{
|
||||
return $this->reCacheLog->getValue('date');
|
||||
}
|
||||
function setDate($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('date', $value);
|
||||
}
|
||||
function getText()
|
||||
{
|
||||
return $this->reCacheLog->getValue('text');
|
||||
}
|
||||
function setText($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('text', $value);
|
||||
}
|
||||
function getTextHtml()
|
||||
{
|
||||
return $this->reCacheLog->getValue('text_html');
|
||||
}
|
||||
function setTextHtml($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('text_html', $value);
|
||||
}
|
||||
function getTextHtmlEdit()
|
||||
{
|
||||
return $this->reCacheLog->getValue('text_html');
|
||||
}
|
||||
function setTextHtmlEdit($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('text_htmledit', $value);
|
||||
}
|
||||
|
||||
function getUUID()
|
||||
{
|
||||
return $this->reCacheLog->getValue('uuid');
|
||||
}
|
||||
function getLastModified()
|
||||
{
|
||||
return $this->reCacheLog->getValue('last_modified');
|
||||
}
|
||||
function getDateCreated()
|
||||
{
|
||||
return $this->reCacheLog->getValue('date_created');
|
||||
}
|
||||
function getNode()
|
||||
{
|
||||
return $this->reCacheLog->getValue('node');
|
||||
}
|
||||
function setNode($value)
|
||||
{
|
||||
return $this->reCacheLog->setValue('node', $value);
|
||||
}
|
||||
|
||||
function getAnyChanged()
|
||||
{
|
||||
return $this->reCacheLog->getAnyChanged();
|
||||
}
|
||||
|
||||
// return if successfull (with insert)
|
||||
function save()
|
||||
{
|
||||
sql_slave_exclude();
|
||||
return $this->reCacheLog->save();
|
||||
}
|
||||
|
||||
function allowView()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
if (sql_value("SELECT `cache_status`.`allow_user_view` FROM `caches` INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id` WHERE `caches`.`cache_id`='&1'", 0, $this->getCacheId()) == 1)
|
||||
return true;
|
||||
else if ($login->userid == sql_value("SELECT `user_id` FROM `caches` WHERE `cache_id`='&1'", 0, $this->getCacheId()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function allowEdit()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* will depend on userid in future e.g. maintainance-logs etc. */
|
||||
function getValidLogTypes()
|
||||
{
|
||||
$cache = new cache($this->getCacheId());
|
||||
if ($cache->exist() == false)
|
||||
return array();
|
||||
if ($cache->allowLog() == false)
|
||||
return array();
|
||||
|
||||
$nTypes = array();
|
||||
$rs = sql("SELECT `log_type_id` FROM `cache_logtype` WHERE `cache_type_id`='&1'", $cache->getType());
|
||||
while ($r = sql_fetch_assoc($rs))
|
||||
$nTypes[] = $r['log_type_id'];
|
||||
sql_free_result($rs);
|
||||
|
||||
return $nTypes;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,49 +1,49 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* Business layer constant definitions
|
||||
***************************************************************************/
|
||||
|
||||
define('ID_NEW', -1);
|
||||
|
||||
define('RE_TYPE_INT', 1);
|
||||
define('RE_TYPE_STRING', 2);
|
||||
define('RE_TYPE_BOOLEAN', 3);
|
||||
define('RE_TYPE_DATE', 4);
|
||||
define('RE_TYPE_FLOAT', 5);
|
||||
define('RE_TYPE_DOUBLE', 6);
|
||||
|
||||
define('RE_INSERT_NOTHING', 0); //
|
||||
define('RE_INSERT_OVERWRITE', 1); // ignore given values and use function
|
||||
define('RE_INSERT_IGNORE', 2); // dont use this column on insert
|
||||
define('RE_INSERT_AUTOINCREMENT', 4); // column is an auto increment column
|
||||
define('RE_INSERT_UUID', 8); // UUID()
|
||||
define('RE_INSERT_NOW', 16); // NOW()
|
||||
|
||||
define('REGEX_USERNAME', '^[a-zA-Z0-9\.\-_@äüöÄÜÖ=)(\/\\\&*+~#][a-zA-Z0-9\.\-_ @äüöÄÜÖ=)(\/\\\&*+~#]{1,58}[a-zA-Z0-9\.\-_@äüöÄÜÖ=)(\/\\\&*+~#]$'); // min. 4 -> 3 chars -- following 2012-8-6
|
||||
define('REGEX_PASSWORD', '^[a-zA-Z0-9\.\-_ @äüöÄÜÖ=)(\/\\\&*+~#]{3,60}$');
|
||||
define('REGEX_LAST_NAME', '^[a-zA-Z][a-zA-Z0-9\.\- äüöÄÜÖ]{1,59}$');
|
||||
define('REGEX_FIRST_NAME', '^[a-zA-Z][a-zA-Z0-9\.\- äüöÄÜÖ]{1,59}$');
|
||||
define('REGEX_STATPIC_TEXT', '^[a-zA-Z0-9\.\-_ @äüöÄÜÖß=)(\/\\\&*\$+~#!§%;,-?:\[\]{}¹²³\'\"`\|µ°\%]{0,30}$');
|
||||
|
||||
define('ADMIN_TRANSLATE', 1); // edit translation
|
||||
define('ADMIN_MAINTAINANCE', 2); // check table etc.
|
||||
define('ADMIN_USER', 4); // drop users, caches etc.
|
||||
define('ADMIN_NEWS', 8); // approve news entries
|
||||
define('ADMIN_ROOT', 128 | 127); // root + all previous rights
|
||||
|
||||
define('ATTRIB_SELECTED', 1);
|
||||
define('ATTRIB_UNSELECTED', 2);
|
||||
define('ATTRIB_UNDEF', 3);
|
||||
|
||||
define('OBJECT_CACHELOG', 1);
|
||||
define('OBJECT_CACHE', 2);
|
||||
define('OBJECT_CACHEDESC', 3);
|
||||
define('OBJECT_USER', 4);
|
||||
define('OBJECT_TRAVELER', 5);
|
||||
define('OBJECT_PICTURE', 6);
|
||||
define('OBJECT_REMOVEDOBJECT', 7);
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* Business layer constant definitions
|
||||
***************************************************************************/
|
||||
|
||||
define('ID_NEW', -1);
|
||||
|
||||
define('RE_TYPE_INT', 1);
|
||||
define('RE_TYPE_STRING', 2);
|
||||
define('RE_TYPE_BOOLEAN', 3);
|
||||
define('RE_TYPE_DATE', 4);
|
||||
define('RE_TYPE_FLOAT', 5);
|
||||
define('RE_TYPE_DOUBLE', 6);
|
||||
|
||||
define('RE_INSERT_NOTHING', 0); //
|
||||
define('RE_INSERT_OVERWRITE', 1); // ignore given values and use function
|
||||
define('RE_INSERT_IGNORE', 2); // dont use this column on insert
|
||||
define('RE_INSERT_AUTOINCREMENT', 4); // column is an auto increment column
|
||||
define('RE_INSERT_AUTOUUID', 8); // if empty, UUID is generated by before insert trigger (not supported for primary key fields)
|
||||
define('RE_INSERT_NOW', 16); // NOW()
|
||||
|
||||
define('REGEX_USERNAME', '^[a-zA-Z0-9\.\-_@äüöÄÜÖ=)(\/\\\&*+~#][a-zA-Z0-9\.\-_ @äüöÄÜÖ=)(\/\\\&*+~#]{1,58}[a-zA-Z0-9\.\-_@äüöÄÜÖ=)(\/\\\&*+~#]$'); // min. 4 -> 3 chars -- following 2012-8-6
|
||||
define('REGEX_PASSWORD', '^[a-zA-Z0-9\.\-_ @äüöÄÜÖ=)(\/\\\&*+~#]{3,60}$');
|
||||
define('REGEX_LAST_NAME', '^[a-zA-Z][a-zA-Z0-9\.\- äüöÄÜÖ]{1,59}$');
|
||||
define('REGEX_FIRST_NAME', '^[a-zA-Z][a-zA-Z0-9\.\- äüöÄÜÖ]{1,59}$');
|
||||
define('REGEX_STATPIC_TEXT', '^[a-zA-Z0-9\.\-_ @äüöÄÜÖß=)(\/\\\&*\$+~#!§%;,-?:\[\]{}¹²³\'\"`\|µ°\%]{0,30}$');
|
||||
|
||||
define('ADMIN_TRANSLATE', 1); // edit translation
|
||||
define('ADMIN_MAINTAINANCE', 2); // check table etc.
|
||||
define('ADMIN_USER', 4); // drop users, caches etc.
|
||||
define('ADMIN_NEWS', 8); // approve news entries
|
||||
define('ADMIN_ROOT', 128 | 127); // root + all previous rights
|
||||
|
||||
define('ATTRIB_SELECTED', 1);
|
||||
define('ATTRIB_UNSELECTED', 2);
|
||||
define('ATTRIB_UNDEF', 3);
|
||||
|
||||
define('OBJECT_CACHELOG', 1);
|
||||
define('OBJECT_CACHE', 2);
|
||||
define('OBJECT_CACHEDESC', 3);
|
||||
define('OBJECT_USER', 4);
|
||||
define('OBJECT_TRAVELER', 5);
|
||||
define('OBJECT_PICTURE', 6);
|
||||
define('OBJECT_REMOVEDOBJECT', 7);
|
||||
?>
|
||||
+314
-314
@@ -1,315 +1,315 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* get/set has to be commited with save
|
||||
* add/remove etc. is executed instantly
|
||||
***************************************************************************/
|
||||
|
||||
require_once($opt['rootpath'] . 'lib2/logic/rowEditor.class.php');
|
||||
require_once($opt['rootpath'] . 'lib2/logic/const.inc.php');
|
||||
|
||||
class picture
|
||||
{
|
||||
var $nPictureId = 0;
|
||||
var $rePicture;
|
||||
var $sFileExtension = '';
|
||||
var $bFilenamesSet = false;
|
||||
|
||||
static function pictureIdFromUUID($uuid)
|
||||
{
|
||||
$pictureid = sql_value("SELECT `id` FROM `pictures` WHERE `uuid`='&1'", 0, $uuid);
|
||||
return $pictureid;
|
||||
}
|
||||
|
||||
static function fromUUID($uuid)
|
||||
{
|
||||
$pictureid = picture::pictureIdFromUUID($uuid);
|
||||
if ($pictureid == 0)
|
||||
return null;
|
||||
|
||||
return new picture($pictureid);
|
||||
}
|
||||
|
||||
function __construct($nNewPictureId=ID_NEW)
|
||||
{
|
||||
global $opt;
|
||||
|
||||
$this->rePicture = new rowEditor('pictures');
|
||||
$this->rePicture->addPKInt('id', null, false, RE_INSERT_AUTOINCREMENT);
|
||||
$this->rePicture->addString('uuid', '', false);
|
||||
$this->rePicture->addInt('node', 0, false);
|
||||
$this->rePicture->addDate('date_created', time(), true, RE_INSERT_IGNORE);
|
||||
$this->rePicture->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
|
||||
$this->rePicture->addString('url', '', false);
|
||||
$this->rePicture->addString('title', '', false);
|
||||
$this->rePicture->addDate('last_url_check', 0, true);
|
||||
$this->rePicture->addInt('object_id', null, false);
|
||||
$this->rePicture->addInt('object_type', null, false);
|
||||
$this->rePicture->addString('thumb_url', '', false);
|
||||
$this->rePicture->addDate('thumb_last_generated', 0, false);
|
||||
$this->rePicture->addInt('spoiler', 0, false);
|
||||
$this->rePicture->addInt('local', 0, false);
|
||||
$this->rePicture->addInt('unknown_format', 0, false);
|
||||
$this->rePicture->addInt('display', 1, false);
|
||||
|
||||
$this->nPictureId = $nNewPictureId+0;
|
||||
|
||||
if ($nNewPictureId == ID_NEW)
|
||||
{
|
||||
$this->rePicture->addNew(null);
|
||||
|
||||
$sUUID = mb_strtoupper(sql_value("SELECT UUID()", ''));
|
||||
$this->rePicture->setValue('uuid', $sUUID);
|
||||
$this->rePicture->setValue('node', $opt['logic']['node']['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->rePicture->load($this->nPictureId);
|
||||
|
||||
$sFilename = $this->getFilename();
|
||||
$fna = mb_split('\\.', $sFilename);
|
||||
$this->sFileExtension = mb_strtolower($fna[count($fna) - 1]);
|
||||
|
||||
$this->bFilenamesSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
function exist()
|
||||
{
|
||||
return $this->rePicture->exist();
|
||||
}
|
||||
|
||||
static function allowedExtension($sFilename)
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if (strpos($sFilename, ';') !== false)
|
||||
return false;
|
||||
if (strpos($sFilename, '.') === false)
|
||||
return false;
|
||||
|
||||
$sExtension = mb_strtolower(substr($sFilename, strrpos($sFilename, '.') + 1));
|
||||
|
||||
if (strpos(';' . $opt['logic']['pictures']['extensions'] . ';', ';' . $sExtension . ';') !== false)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function setFilenames($sFilename)
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if ($this->bFilenamesSet == true)
|
||||
return;
|
||||
if (strpos($sFilename, '.') === false)
|
||||
return;
|
||||
$sExtension = mb_strtolower(substr($sFilename, strrpos($sFilename, '.') + 1));
|
||||
|
||||
$sUUID = $this->getUUID();
|
||||
|
||||
$this->sFileExtension = $sExtension;
|
||||
$this->setUrl($opt['logic']['pictures']['url'] . $sUUID . '.' . $sExtension);
|
||||
//$this->setThumbUrl($opt['logic']['pictures']['thumb_url'] . substr($sUUID, 0, 1) . '/' . substr($sUUID, 1, 1) . '/' . $sUUID . '.' . $sExtension);
|
||||
$this->bFilenamesSet = true;
|
||||
}
|
||||
|
||||
function getPictureId()
|
||||
{
|
||||
return $this->nPictureId;
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
global $opt;
|
||||
|
||||
// delete record, image and thumb
|
||||
@unlink($this->getFilename());
|
||||
@unlink($this->getThumbFilename());
|
||||
|
||||
sql("DELETE FROM `pictures` WHERE `id`='&1'", $this->nPictureId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getUrl()
|
||||
{
|
||||
return $this->rePicture->getValue('url');
|
||||
}
|
||||
function setUrl($value)
|
||||
{
|
||||
return $this->rePicture->setValue('url', $value);
|
||||
}
|
||||
function getThumbUrl()
|
||||
{
|
||||
return $this->rePicture->getValue('thumb_url');
|
||||
}
|
||||
function setThumbUrl($value)
|
||||
{
|
||||
return $this->rePicture->setValue('thumb_url', $value);
|
||||
}
|
||||
function getTitle()
|
||||
{
|
||||
return $this->rePicture->getValue('title');
|
||||
}
|
||||
function setTitle($value)
|
||||
{
|
||||
if ($value != '')
|
||||
return $this->rePicture->setValue('title', $value);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
function getSpoiler()
|
||||
{
|
||||
return $this->rePicture->getValue('spoiler')!=0;
|
||||
}
|
||||
function setSpoiler($value)
|
||||
{
|
||||
return $this->rePicture->setValue('spoiler', $value ? 1 : 0);
|
||||
}
|
||||
function getLocal()
|
||||
{
|
||||
return $this->rePicture->getValue('local')!=0;
|
||||
}
|
||||
function setLocal($value)
|
||||
{
|
||||
return $this->rePicture->setValue('local', $value ? 1 : 0);
|
||||
}
|
||||
function getDisplay()
|
||||
{
|
||||
return $this->rePicture->getValue('display')!=0;
|
||||
}
|
||||
function setDisplay($value)
|
||||
{
|
||||
return $this->rePicture->setValue('display', $value ? 1 : 0);
|
||||
}
|
||||
function getFilename()
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if (mb_substr($opt['logic']['pictures']['dir'], -1, 1) != '/')
|
||||
$opt['logic']['pictures']['dir'] .= '/';
|
||||
|
||||
$uuid = $this->getUUID();
|
||||
$url = $this->getUrl();
|
||||
$fna = mb_split('\\.', $url);
|
||||
$extension = mb_strtolower($fna[count($fna) - 1]);
|
||||
|
||||
return $opt['logic']['pictures']['dir'] . $uuid . '.' . $extension;
|
||||
}
|
||||
function getThumbFilename()
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if (mb_substr($opt['logic']['pictures']['thumb_dir'], -1, 1) != '/')
|
||||
$opt['logic']['pictures']['thumb_dir'] .= '/';
|
||||
|
||||
$uuid = $this->getUUID();
|
||||
$url = $this->getUrl();
|
||||
$fna = mb_split('\\.', $url);
|
||||
$extension = mb_strtolower($fna[count($fna) - 1]);
|
||||
|
||||
$dir1 = mb_strtoupper(mb_substr($uuid, 0, 1));
|
||||
$dir2 = mb_strtoupper(mb_substr($uuid, 1, 1));
|
||||
|
||||
return $opt['logic']['pictures']['thumb_dir'] . $dir1 . '/' . $dir2 . '/' . $uuid . '.' . $extension;
|
||||
}
|
||||
function getLogId()
|
||||
{
|
||||
if ($this->getObjectType() == OBJECT_CACHELOG)
|
||||
return $this->getObjectId();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
function getCacheId()
|
||||
{
|
||||
if ($this->getObjectType() == OBJECT_CACHELOG)
|
||||
return sql_value("SELECT `cache_id` FROM `cache_logs` WHERE `id`='&1'", false, $this->getObjectId());
|
||||
else if ($this->getObjectType() == OBJECT_CACHE)
|
||||
return $this->getObjectId();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
function getObjectId()
|
||||
{
|
||||
return $this->rePicture->getValue('object_id');
|
||||
}
|
||||
function setObjectId($value)
|
||||
{
|
||||
return $this->rePicture->setValue('object_id', $value+0);
|
||||
}
|
||||
function getObjectType()
|
||||
{
|
||||
return $this->rePicture->getValue('object_type');
|
||||
}
|
||||
function setObjectType($value)
|
||||
{
|
||||
return $this->rePicture->setValue('object_type', $value+0);
|
||||
}
|
||||
function getUserId()
|
||||
{
|
||||
if ($this->getObjectType() == OBJECT_CACHE)
|
||||
return sql_value("SELECT `caches`.`user_id` FROM `caches` WHERE `caches`.`cache_id`='&1'", false, $this->getObjectId());
|
||||
else if ($this->getObjectType() == OBJECT_CACHELOG)
|
||||
return sql_value("SELECT `cache_logs`.`user_id` FROM `cache_logs` WHERE `cache_logs`.`id`='&1'", false, $this->getObjectId());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function getNode()
|
||||
{
|
||||
return $this->rePicture->getValue('node');
|
||||
}
|
||||
function setNode($value)
|
||||
{
|
||||
return $this->rePicture->setValue('node', $value);
|
||||
}
|
||||
function getUUID()
|
||||
{
|
||||
return $this->rePicture->getValue('uuid');
|
||||
}
|
||||
function getLastModified()
|
||||
{
|
||||
return $this->rePicture->getValue('last_modified');
|
||||
}
|
||||
function getDateCreated()
|
||||
{
|
||||
return $this->rePicture->getValue('date_created');
|
||||
}
|
||||
function getAnyChanged()
|
||||
{
|
||||
return $this->rePicture->getAnyChanged();
|
||||
}
|
||||
|
||||
// return if successfull (with insert)
|
||||
function save()
|
||||
{
|
||||
if ($this->bFilenamesSet == false)
|
||||
return false;
|
||||
|
||||
$bRetVal = $this->rePicture->save();
|
||||
|
||||
if ($bRetVal)
|
||||
sql_slave_exclude();
|
||||
|
||||
return $bRetVal;
|
||||
}
|
||||
|
||||
function allowEdit()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
|
||||
if (sql_value("SELECT COUNT(*) FROM `caches` INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id` WHERE (`cache_status`.`allow_user_view`=1 OR `caches`.`user_id`='&1') AND `caches`.`cache_id`='&2'", 0, $login->userid, $this->getCacheId()) == 0)
|
||||
return false;
|
||||
else if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* get/set has to be commited with save
|
||||
* add/remove etc. is executed instantly
|
||||
***************************************************************************/
|
||||
|
||||
require_once($opt['rootpath'] . 'lib2/logic/rowEditor.class.php');
|
||||
require_once($opt['rootpath'] . 'lib2/logic/const.inc.php');
|
||||
|
||||
class picture
|
||||
{
|
||||
var $nPictureId = 0;
|
||||
var $rePicture;
|
||||
var $sFileExtension = '';
|
||||
var $bFilenamesSet = false;
|
||||
|
||||
static function pictureIdFromUUID($uuid)
|
||||
{
|
||||
$pictureid = sql_value("SELECT `id` FROM `pictures` WHERE `uuid`='&1'", 0, $uuid);
|
||||
return $pictureid;
|
||||
}
|
||||
|
||||
static function fromUUID($uuid)
|
||||
{
|
||||
$pictureid = picture::pictureIdFromUUID($uuid);
|
||||
if ($pictureid == 0)
|
||||
return null;
|
||||
|
||||
return new picture($pictureid);
|
||||
}
|
||||
|
||||
function __construct($nNewPictureId=ID_NEW)
|
||||
{
|
||||
global $opt;
|
||||
|
||||
$this->rePicture = new rowEditor('pictures');
|
||||
$this->rePicture->addPKInt('id', null, false, RE_INSERT_AUTOINCREMENT);
|
||||
$this->rePicture->addString('uuid', '', false, RE_INSERT_AUTOUUID);
|
||||
$this->rePicture->addInt('node', 0, false);
|
||||
$this->rePicture->addDate('date_created', time(), true, RE_INSERT_IGNORE);
|
||||
$this->rePicture->addDate('last_modified', time(), true, RE_INSERT_IGNORE);
|
||||
$this->rePicture->addString('url', '', false);
|
||||
$this->rePicture->addString('title', '', false);
|
||||
$this->rePicture->addDate('last_url_check', 0, true);
|
||||
$this->rePicture->addInt('object_id', null, false);
|
||||
$this->rePicture->addInt('object_type', null, false);
|
||||
$this->rePicture->addString('thumb_url', '', false);
|
||||
$this->rePicture->addDate('thumb_last_generated', 0, false);
|
||||
$this->rePicture->addInt('spoiler', 0, false);
|
||||
$this->rePicture->addInt('local', 0, false);
|
||||
$this->rePicture->addInt('unknown_format', 0, false);
|
||||
$this->rePicture->addInt('display', 1, false);
|
||||
|
||||
$this->nPictureId = $nNewPictureId+0;
|
||||
|
||||
if ($nNewPictureId == ID_NEW)
|
||||
{
|
||||
$this->rePicture->addNew(null);
|
||||
|
||||
$sUUID = mb_strtoupper(sql_value("SELECT UUID()", ''));
|
||||
$this->rePicture->setValue('uuid', $sUUID);
|
||||
$this->rePicture->setValue('node', $opt['logic']['node']['id']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->rePicture->load($this->nPictureId);
|
||||
|
||||
$sFilename = $this->getFilename();
|
||||
$fna = mb_split('\\.', $sFilename);
|
||||
$this->sFileExtension = mb_strtolower($fna[count($fna) - 1]);
|
||||
|
||||
$this->bFilenamesSet = true;
|
||||
}
|
||||
}
|
||||
|
||||
function exist()
|
||||
{
|
||||
return $this->rePicture->exist();
|
||||
}
|
||||
|
||||
static function allowedExtension($sFilename)
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if (strpos($sFilename, ';') !== false)
|
||||
return false;
|
||||
if (strpos($sFilename, '.') === false)
|
||||
return false;
|
||||
|
||||
$sExtension = mb_strtolower(substr($sFilename, strrpos($sFilename, '.') + 1));
|
||||
|
||||
if (strpos(';' . $opt['logic']['pictures']['extensions'] . ';', ';' . $sExtension . ';') !== false)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function setFilenames($sFilename)
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if ($this->bFilenamesSet == true)
|
||||
return;
|
||||
if (strpos($sFilename, '.') === false)
|
||||
return;
|
||||
$sExtension = mb_strtolower(substr($sFilename, strrpos($sFilename, '.') + 1));
|
||||
|
||||
$sUUID = $this->getUUID();
|
||||
|
||||
$this->sFileExtension = $sExtension;
|
||||
$this->setUrl($opt['logic']['pictures']['url'] . $sUUID . '.' . $sExtension);
|
||||
//$this->setThumbUrl($opt['logic']['pictures']['thumb_url'] . substr($sUUID, 0, 1) . '/' . substr($sUUID, 1, 1) . '/' . $sUUID . '.' . $sExtension);
|
||||
$this->bFilenamesSet = true;
|
||||
}
|
||||
|
||||
function getPictureId()
|
||||
{
|
||||
return $this->nPictureId;
|
||||
}
|
||||
|
||||
function delete()
|
||||
{
|
||||
global $opt;
|
||||
|
||||
// delete record, image and thumb
|
||||
@unlink($this->getFilename());
|
||||
@unlink($this->getThumbFilename());
|
||||
|
||||
sql("DELETE FROM `pictures` WHERE `id`='&1'", $this->nPictureId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getUrl()
|
||||
{
|
||||
return $this->rePicture->getValue('url');
|
||||
}
|
||||
function setUrl($value)
|
||||
{
|
||||
return $this->rePicture->setValue('url', $value);
|
||||
}
|
||||
function getThumbUrl()
|
||||
{
|
||||
return $this->rePicture->getValue('thumb_url');
|
||||
}
|
||||
function setThumbUrl($value)
|
||||
{
|
||||
return $this->rePicture->setValue('thumb_url', $value);
|
||||
}
|
||||
function getTitle()
|
||||
{
|
||||
return $this->rePicture->getValue('title');
|
||||
}
|
||||
function setTitle($value)
|
||||
{
|
||||
if ($value != '')
|
||||
return $this->rePicture->setValue('title', $value);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
function getSpoiler()
|
||||
{
|
||||
return $this->rePicture->getValue('spoiler')!=0;
|
||||
}
|
||||
function setSpoiler($value)
|
||||
{
|
||||
return $this->rePicture->setValue('spoiler', $value ? 1 : 0);
|
||||
}
|
||||
function getLocal()
|
||||
{
|
||||
return $this->rePicture->getValue('local')!=0;
|
||||
}
|
||||
function setLocal($value)
|
||||
{
|
||||
return $this->rePicture->setValue('local', $value ? 1 : 0);
|
||||
}
|
||||
function getDisplay()
|
||||
{
|
||||
return $this->rePicture->getValue('display')!=0;
|
||||
}
|
||||
function setDisplay($value)
|
||||
{
|
||||
return $this->rePicture->setValue('display', $value ? 1 : 0);
|
||||
}
|
||||
function getFilename()
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if (mb_substr($opt['logic']['pictures']['dir'], -1, 1) != '/')
|
||||
$opt['logic']['pictures']['dir'] .= '/';
|
||||
|
||||
$uuid = $this->getUUID();
|
||||
$url = $this->getUrl();
|
||||
$fna = mb_split('\\.', $url);
|
||||
$extension = mb_strtolower($fna[count($fna) - 1]);
|
||||
|
||||
return $opt['logic']['pictures']['dir'] . $uuid . '.' . $extension;
|
||||
}
|
||||
function getThumbFilename()
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if (mb_substr($opt['logic']['pictures']['thumb_dir'], -1, 1) != '/')
|
||||
$opt['logic']['pictures']['thumb_dir'] .= '/';
|
||||
|
||||
$uuid = $this->getUUID();
|
||||
$url = $this->getUrl();
|
||||
$fna = mb_split('\\.', $url);
|
||||
$extension = mb_strtolower($fna[count($fna) - 1]);
|
||||
|
||||
$dir1 = mb_strtoupper(mb_substr($uuid, 0, 1));
|
||||
$dir2 = mb_strtoupper(mb_substr($uuid, 1, 1));
|
||||
|
||||
return $opt['logic']['pictures']['thumb_dir'] . $dir1 . '/' . $dir2 . '/' . $uuid . '.' . $extension;
|
||||
}
|
||||
function getLogId()
|
||||
{
|
||||
if ($this->getObjectType() == OBJECT_CACHELOG)
|
||||
return $this->getObjectId();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
function getCacheId()
|
||||
{
|
||||
if ($this->getObjectType() == OBJECT_CACHELOG)
|
||||
return sql_value("SELECT `cache_id` FROM `cache_logs` WHERE `id`='&1'", false, $this->getObjectId());
|
||||
else if ($this->getObjectType() == OBJECT_CACHE)
|
||||
return $this->getObjectId();
|
||||
else
|
||||
return false;
|
||||
}
|
||||
function getObjectId()
|
||||
{
|
||||
return $this->rePicture->getValue('object_id');
|
||||
}
|
||||
function setObjectId($value)
|
||||
{
|
||||
return $this->rePicture->setValue('object_id', $value+0);
|
||||
}
|
||||
function getObjectType()
|
||||
{
|
||||
return $this->rePicture->getValue('object_type');
|
||||
}
|
||||
function setObjectType($value)
|
||||
{
|
||||
return $this->rePicture->setValue('object_type', $value+0);
|
||||
}
|
||||
function getUserId()
|
||||
{
|
||||
if ($this->getObjectType() == OBJECT_CACHE)
|
||||
return sql_value("SELECT `caches`.`user_id` FROM `caches` WHERE `caches`.`cache_id`='&1'", false, $this->getObjectId());
|
||||
else if ($this->getObjectType() == OBJECT_CACHELOG)
|
||||
return sql_value("SELECT `cache_logs`.`user_id` FROM `cache_logs` WHERE `cache_logs`.`id`='&1'", false, $this->getObjectId());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function getNode()
|
||||
{
|
||||
return $this->rePicture->getValue('node');
|
||||
}
|
||||
function setNode($value)
|
||||
{
|
||||
return $this->rePicture->setValue('node', $value);
|
||||
}
|
||||
function getUUID()
|
||||
{
|
||||
return $this->rePicture->getValue('uuid');
|
||||
}
|
||||
function getLastModified()
|
||||
{
|
||||
return $this->rePicture->getValue('last_modified');
|
||||
}
|
||||
function getDateCreated()
|
||||
{
|
||||
return $this->rePicture->getValue('date_created');
|
||||
}
|
||||
function getAnyChanged()
|
||||
{
|
||||
return $this->rePicture->getAnyChanged();
|
||||
}
|
||||
|
||||
// return if successfull (with insert)
|
||||
function save()
|
||||
{
|
||||
if ($this->bFilenamesSet == false)
|
||||
return false;
|
||||
|
||||
$bRetVal = $this->rePicture->save();
|
||||
|
||||
if ($bRetVal)
|
||||
sql_slave_exclude();
|
||||
|
||||
return $bRetVal;
|
||||
}
|
||||
|
||||
function allowEdit()
|
||||
{
|
||||
global $login;
|
||||
|
||||
$login->verify();
|
||||
|
||||
if (sql_value("SELECT COUNT(*) FROM `caches` INNER JOIN `cache_status` ON `caches`.`status`=`cache_status`.`id` WHERE (`cache_status`.`allow_user_view`=1 OR `caches`.`user_id`='&1') AND `caches`.`cache_id`='&2'", 0, $login->userid, $this->getCacheId()) == 0)
|
||||
return false;
|
||||
else if ($this->getUserId() == $login->userid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -58,6 +58,9 @@ class rowEditor
|
||||
|
||||
function addPKString($sField, $sDefault, $bNullable, $nInsertFunction=RE_INSERT_NOTHING)
|
||||
{
|
||||
if (($nInsertFunction & RE_INSERT_AUTOUUID) == RE_INSERT_AUTOUUID)
|
||||
die('rowEditor: RE_INSERT_AUTOUUID not supported for primary key fields');
|
||||
|
||||
$this->pk[$sField] = array('type' => RE_TYPE_STRING,
|
||||
'default' => $sDefault,
|
||||
'nullable' => $bNullable,
|
||||
@@ -390,6 +393,9 @@ class rowEditor
|
||||
$this->fields[$this->sAutoIncrementField]['value'] = $nInsertId;
|
||||
}
|
||||
|
||||
/* reload the record to get the actual stored values
|
||||
* (inserted values maybe truncated by mysql or trigger could modify values)
|
||||
*/
|
||||
$pkv = array();
|
||||
foreach ($this->pk AS $k => $v)
|
||||
{
|
||||
@@ -454,9 +460,7 @@ class rowEditor
|
||||
|
||||
if ((($field['insertfunction'] & RE_INSERT_OVERWRITE) == RE_INSERT_OVERWRITE) || (($field['changed'] == false) && ($field['insertfunction'] != RE_INSERT_NOTHING)))
|
||||
{
|
||||
if (($field['insertfunction'] & RE_INSERT_UUID) == RE_INSERT_UUID)
|
||||
$sValues[] = 'UUID()';
|
||||
else if (($field['insertfunction'] & RE_INSERT_NOW) == RE_INSERT_NOW)
|
||||
if (($field['insertfunction'] & RE_INSERT_NOW) == RE_INSERT_NOW)
|
||||
$sValues[] = 'NOW()';
|
||||
else
|
||||
$sValues[] = 'NULL';
|
||||
@@ -479,9 +483,7 @@ class rowEditor
|
||||
|
||||
if ((($field['insertfunction'] & RE_INSERT_OVERWRITE) == RE_INSERT_OVERWRITE) || (($field['changed'] == false) && ($field['insertfunction'] != RE_INSERT_NOTHING)))
|
||||
{
|
||||
if (($field['insertfunction'] & RE_INSERT_UUID) == RE_INSERT_UUID)
|
||||
$sValues[] = 'UUID()';
|
||||
else if (($field['insertfunction'] & RE_INSERT_NOW) == RE_INSERT_NOW)
|
||||
if (($field['insertfunction'] & RE_INSERT_NOW) == RE_INSERT_NOW)
|
||||
$sValues[] = 'NOW()';
|
||||
else
|
||||
$sValues[] = 'NULL';
|
||||
|
||||
+781
-781
File diff suppressed because it is too large
Load Diff
+324
-313
@@ -1,313 +1,324 @@
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* This class provides access to the login user data. Informations are
|
||||
* stored in a cookie.
|
||||
*
|
||||
* Methods:
|
||||
* verify() validate the login-session (automatically invoked)
|
||||
* try_login() try to login with the given user/password
|
||||
* logout() logout the user
|
||||
*
|
||||
* Properties:
|
||||
* userid Integer 0 if no login, userid otherwise
|
||||
* username String username or ''
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
define('LOGIN_UNKNOWN_ERROR', -1); // unkown error occured
|
||||
define('LOGIN_OK', 0); // login succeeded
|
||||
define('LOGIN_BADUSERPW', 1); // bad username or password
|
||||
define('LOGIN_TOOMUCHLOGINS', 2); // too many logins in short time
|
||||
define('LOGIN_USERNOTACTIVE', 3); // the useraccount locked
|
||||
define('LOGIN_EMPTY_USERPASSWORD', 4); // given username/password was empty
|
||||
define('LOGIN_LOGOUT_OK', 5); // logout was successfull
|
||||
|
||||
// login times in seconds
|
||||
define('LOGIN_TIME', 60*60);
|
||||
define('LOGIN_TIME_PERMANENT', 90*24*60*60);
|
||||
|
||||
$login = new login();
|
||||
|
||||
class login
|
||||
{
|
||||
var $userid = 0;
|
||||
var $username = '';
|
||||
var $lastlogin = 0;
|
||||
var $permanent = false;
|
||||
var $sessionid = '';
|
||||
var $verified = false;
|
||||
var $admin = 0;
|
||||
|
||||
function login()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
if ($cookie->is_set('userid') && $cookie->is_set('username'))
|
||||
{
|
||||
$this->userid = $cookie->get('userid')+0;
|
||||
$this->username = $cookie->get('username');
|
||||
$this->permanent = (($cookie->get('permanent')+0) == 1);
|
||||
$this->lastlogin = $cookie->get('lastlogin');
|
||||
$this->sessionid = $cookie->get('sessionid');
|
||||
$this->admin = $cookie->get('admin')+0;
|
||||
$this->verified = false;
|
||||
|
||||
$this->verify();
|
||||
}
|
||||
else
|
||||
$this->pClear();
|
||||
}
|
||||
|
||||
// return true on success
|
||||
function restoreSession($sid)
|
||||
{
|
||||
$min_lastlogin = date('Y-m-d H:i:s', time() - LOGIN_TIME);
|
||||
|
||||
if ($this->checkLoginsCount() == false)
|
||||
{
|
||||
$this->pClear();
|
||||
return false;
|
||||
}
|
||||
|
||||
$rs = sqlf("SELECT `sys_sessions`.`uuid` `sid`, `user`.`user_id`, `sys_sessions`.`last_login`, `user`.`admin`, `user`.`username` FROM &db.`sys_sessions`, &db.`user` WHERE `sys_sessions`.`user_id`=`user`.`user_id` AND `user`.`is_active_flag`=1 AND `sys_sessions`.`uuid`='&1' AND `sys_sessions`.`permanent`=0 AND `sys_sessions`.`last_login`>'&2'", $sid, $min_lastlogin);
|
||||
$r = sql_fetch_assoc($rs);
|
||||
sql_free_result($rs);
|
||||
|
||||
if ($r)
|
||||
{
|
||||
sqlf("UPDATE `sys_sessions` SET `sys_sessions`.`last_login`=NOW() WHERE `sys_sessions`.`uuid`='&1' AND `sys_sessions`.`user_id`='&2'", $r['sid'], $r['user_id']);
|
||||
sqlf("UPDATE `user` SET `user`.`last_login`=NOW() WHERE `user`.`user_id`='&1'", $r['user_id']);
|
||||
|
||||
$this->userid = $r['user_id'];
|
||||
$this->username = $r['username'];
|
||||
$this->permanent = false;
|
||||
$this->lastlogin = $r['last_login'];
|
||||
$this->sessionid = $r['sid'];
|
||||
$this->admin = $r['admin'];
|
||||
$this->verified = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// prevent bruteforce
|
||||
sql("INSERT INTO `sys_logins` (`remote_addr`, `success`) VALUES ('&1', 0)", $_SERVER['REMOTE_ADDR']);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function pClear()
|
||||
{
|
||||
// set to no valid login
|
||||
$this->userid = 0;
|
||||
$this->username = '';
|
||||
$this->permanent = false;
|
||||
$this->lastlogin = '';
|
||||
$this->sessionid = '';
|
||||
$this->admin = 0;
|
||||
$this->verified = true;
|
||||
|
||||
$this->pStoreCookie();
|
||||
}
|
||||
|
||||
function pStoreCookie()
|
||||
{
|
||||
global $cookie;
|
||||
$cookie->set('userid', $this->userid);
|
||||
$cookie->set('username', $this->username);
|
||||
$cookie->set('permanent', ($this->permanent==true ? 1 : 0));
|
||||
$cookie->set('lastlogin', $this->lastlogin);
|
||||
$cookie->set('sessionid', $this->sessionid);
|
||||
$cookie->set('admin', $this->admin);
|
||||
}
|
||||
|
||||
function verify()
|
||||
{
|
||||
if ($this->verified == true)
|
||||
return;
|
||||
|
||||
if ($this->userid == 0)
|
||||
{
|
||||
$this->pClear();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->checkLoginsCount() == false)
|
||||
{
|
||||
$this->pClear();
|
||||
return;
|
||||
}
|
||||
|
||||
$min_lastlogin = date('Y-m-d H:i:s', time() - LOGIN_TIME);
|
||||
$min_lastlogin_permanent = date('Y-m-d H:i:s', time() - LOGIN_TIME_PERMANENT);
|
||||
|
||||
$rs = sqlf("SELECT `sys_sessions`.`last_login`, `user`.`admin`, `user`.`username` FROM &db.`sys_sessions`, &db.`user` WHERE `sys_sessions`.`user_id`=`user`.`user_id` AND `user`.`is_active_flag`=1 AND `sys_sessions`.`uuid`='&1' AND `sys_sessions`.`user_id`='&2' AND ((`sys_sessions`.`permanent`=1 AND `sys_sessions`.`last_login`>'&3') OR (`sys_sessions`.`permanent`=0 AND `sys_sessions`.`last_login`>'&4'))", $this->sessionid, $this->userid, $min_lastlogin_permanent, $min_lastlogin);
|
||||
if ($rUser = sql_fetch_assoc($rs))
|
||||
{
|
||||
if ((($this->permanent == true) && (strtotime($rUser['last_login']) + LOGIN_TIME/2 < time())) ||
|
||||
(($this->permanent == false) && (strtotime($rUser['last_login']) + LOGIN_TIME_PERMANENT/2 < time())))
|
||||
{
|
||||
sqlf("UPDATE `sys_sessions` SET `sys_sessions`.`last_login`=NOW() WHERE `sys_sessions`.`uuid`='&1' AND `sys_sessions`.`user_id`='&2'", $this->sessionid, $this->userid);
|
||||
$rUser['last_login'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
// user.last_login is used for statics, so we keep it up2date
|
||||
sqlf("UPDATE `user` SET `user`.`last_login`=NOW() WHERE `user`.`user_id`='&1'", $this->userid);
|
||||
|
||||
$this->lastlogin = $rUser['last_login'];
|
||||
$this->username = $rUser['username'];
|
||||
$this->admin = $rUser['admin'];
|
||||
$this->verified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// prevent bruteforce
|
||||
sql("INSERT INTO `sys_logins` (`remote_addr`, `success`) VALUES ('&1', 0)", $_SERVER['REMOTE_ADDR']);
|
||||
|
||||
$this->pClear();
|
||||
}
|
||||
sql_free_result($rs);
|
||||
|
||||
$this->pStoreCookie();
|
||||
return;
|
||||
}
|
||||
|
||||
function try_login($user, $password, $permanent)
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if ($password == '')
|
||||
return LOGIN_EMPTY_USERPASSWORD;
|
||||
|
||||
$pwmd5 = md5($password);
|
||||
if ($opt['logic']['password_hash'])
|
||||
$pwmd5 = hash('sha512', $pwmd5);
|
||||
|
||||
return $this->try_login_md5($user, $pwmd5, $permanent);
|
||||
}
|
||||
|
||||
function checkLoginsCount()
|
||||
{
|
||||
global $opt;
|
||||
|
||||
// cleanup old entries
|
||||
// (execute only every 50 search calls)
|
||||
if (rand(1, 50) == 1)
|
||||
sqlf("DELETE FROM `sys_logins` WHERE `date_created`<'&1'", date('Y-m-d H:i:s', time() - 3600));
|
||||
|
||||
// check the number of logins in the last hour ...
|
||||
$logins_count = sqlf_value("SELECT COUNT(*) `count` FROM `sys_logins` WHERE `remote_addr`='&1' AND `date_created`>'&2'", 0, $_SERVER['REMOTE_ADDR'], date('Y-m-d H:i:s', time() - 3600));
|
||||
if ($logins_count > $opt['page']['max_logins_per_hour'])
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
function try_login_md5($user, $pwmd5, $permanent)
|
||||
{
|
||||
global $opt;
|
||||
$this->pClear();
|
||||
|
||||
if ($user == '' || $pwmd5 == '')
|
||||
return LOGIN_EMPTY_USERPASSWORD;
|
||||
|
||||
if ($this->checkLoginsCount() == false)
|
||||
return LOGIN_TOOMUCHLOGINS;
|
||||
|
||||
// delete old sessions
|
||||
$min_lastlogin_permanent = date('Y-m-d H:i:s', time() - LOGIN_TIME_PERMANENT);
|
||||
sqlf("DELETE FROM `sys_sessions` WHERE `last_login`<'&1'", $min_lastlogin_permanent);
|
||||
|
||||
// compare $user with email and username, if both matches use email
|
||||
$rsUser = sqlf("SELECT `user_id`, `username`, 2 AS `prio`, `is_active_flag`, `permanent_login_flag`, `admin` FROM `user` WHERE `username`='&1' AND `password`='&2' UNION
|
||||
SELECT `user_id`, `username`, 1 AS `prio`, `is_active_flag`, `permanent_login_flag`, `admin` FROM `user` WHERE `email`='&1' AND `password`='&2' ORDER BY `prio` ASC LIMIT 1", $user, $pwmd5);
|
||||
$rUser = sql_fetch_assoc($rsUser);
|
||||
sql_free_result($rsUser);
|
||||
|
||||
if ($permanent == null)
|
||||
$permanent = ($rUser['permanent_login_flag'] == 1);
|
||||
|
||||
if ($rUser)
|
||||
{
|
||||
// ok, there is a valid login
|
||||
if ($rUser['is_active_flag'] != 0)
|
||||
{
|
||||
// begin session
|
||||
$uuid = sqlf_value('SELECT UUID()', '');
|
||||
sqlf("INSERT INTO `sys_sessions` (`uuid`, `user_id`, `permanent`, `last_login`) VALUES ('&1', '&2', '&3', NOW())", $uuid, $rUser['user_id'], ($permanent!=false ? 1 : 0));
|
||||
$this->userid = $rUser['user_id'];
|
||||
$this->username = $rUser['username'];
|
||||
$this->permanent = $permanent;
|
||||
$this->lastlogin = date('Y-m-d H:i:s');
|
||||
$this->sessionid = $uuid;
|
||||
$this->admin = $rUser['admin'];
|
||||
$this->verified = true;
|
||||
|
||||
$retval = LOGIN_OK;
|
||||
}
|
||||
else
|
||||
$retval = LOGIN_USERNOTACTIVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// sorry, bad login
|
||||
$retval = LOGIN_BADUSERPW;
|
||||
}
|
||||
|
||||
sqlf("INSERT INTO `sys_logins` (`remote_addr`, `success`) VALUES ('&1', '&2')", $_SERVER['REMOTE_ADDR'], ($rUser===false ? 0 : 1));
|
||||
|
||||
// store to cookie
|
||||
$this->pStoreCookie();
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
function getUserCountry()
|
||||
{
|
||||
global $opt, $cookie;
|
||||
|
||||
// language specified in cookie?
|
||||
if ($cookie->is_set('usercountry'))
|
||||
{
|
||||
$sCountry = $cookie->get('usercountry', null);
|
||||
if ($sCountry != null)
|
||||
return $sCountry;
|
||||
}
|
||||
|
||||
// user specified a language?
|
||||
if ($this->userid != 0)
|
||||
{
|
||||
$sCountry = sql_value("SELECT `country` FROM `user` WHERE `user_id`='&1'", null, $this->userid);
|
||||
if ($sCountry != null)
|
||||
return $sCountry;
|
||||
}
|
||||
|
||||
// default country of this language
|
||||
if (isset($opt['locale'][$opt['template']['locale']]['country']))
|
||||
return $opt['locale'][$opt['template']['locale']]['country'];
|
||||
|
||||
// default country of installation (or domain)
|
||||
return $opt['template']['default']['country'];
|
||||
}
|
||||
|
||||
function logout()
|
||||
{
|
||||
if ($this->userid != 0)
|
||||
sqlf("DELETE FROM `sys_sessions` WHERE `uuid`='&1' AND `user_id`='&2'", $this->sessionid, $this->userid);
|
||||
|
||||
$this->pClear();
|
||||
}
|
||||
|
||||
public function hasAdminPriv($privilege = false)
|
||||
{
|
||||
if ($privilege === false)
|
||||
return $this->admin != 0;
|
||||
|
||||
return ($this->admin & $privilege) == $privilege;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
/***************************************************************************
|
||||
* For license information see doc/license.txt
|
||||
*
|
||||
* Unicode Reminder メモ
|
||||
*
|
||||
* This class provides access to the login user data. Informations are
|
||||
* stored in a cookie.
|
||||
*
|
||||
* Methods:
|
||||
* verify() validate the login-session (automatically invoked)
|
||||
* try_login() try to login with the given user/password
|
||||
* logout() logout the user
|
||||
*
|
||||
* Properties:
|
||||
* userid Integer 0 if no login, userid otherwise
|
||||
* username String username or ''
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
define('LOGIN_UNKNOWN_ERROR', -1); // unkown error occured
|
||||
define('LOGIN_OK', 0); // login succeeded
|
||||
define('LOGIN_BADUSERPW', 1); // bad username or password
|
||||
define('LOGIN_TOOMUCHLOGINS', 2); // too many logins in short time
|
||||
define('LOGIN_USERNOTACTIVE', 3); // the useraccount locked
|
||||
define('LOGIN_EMPTY_USERPASSWORD', 4); // given username/password was empty
|
||||
define('LOGIN_LOGOUT_OK', 5); // logout was successfull
|
||||
|
||||
// login times in seconds
|
||||
define('LOGIN_TIME', 60*60);
|
||||
define('LOGIN_TIME_PERMANENT', 90*24*60*60);
|
||||
|
||||
$login = new login();
|
||||
|
||||
class login
|
||||
{
|
||||
var $userid = 0;
|
||||
var $username = '';
|
||||
var $lastlogin = 0;
|
||||
var $permanent = false;
|
||||
var $sessionid = '';
|
||||
var $verified = false;
|
||||
var $admin = 0;
|
||||
|
||||
function login()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
if ($cookie->is_set('userid') && $cookie->is_set('username'))
|
||||
{
|
||||
$this->userid = $cookie->get('userid')+0;
|
||||
$this->username = $cookie->get('username');
|
||||
$this->permanent = (($cookie->get('permanent')+0) == 1);
|
||||
$this->lastlogin = $cookie->get('lastlogin');
|
||||
$this->sessionid = $cookie->get('sessionid');
|
||||
$this->admin = $cookie->get('admin')+0;
|
||||
$this->verified = false;
|
||||
|
||||
$this->verify();
|
||||
}
|
||||
else
|
||||
$this->pClear();
|
||||
}
|
||||
|
||||
// return true on success
|
||||
function restoreSession($sid)
|
||||
{
|
||||
$min_lastlogin = date('Y-m-d H:i:s', time() - LOGIN_TIME);
|
||||
|
||||
if ($this->checkLoginsCount() == false)
|
||||
{
|
||||
$this->pClear();
|
||||
return false;
|
||||
}
|
||||
|
||||
$rs = sqlf("SELECT `sys_sessions`.`uuid` `sid`, `user`.`user_id`, `sys_sessions`.`last_login`, `user`.`admin`, `user`.`username` FROM &db.`sys_sessions`, &db.`user` WHERE `sys_sessions`.`user_id`=`user`.`user_id` AND `user`.`is_active_flag`=1 AND `sys_sessions`.`uuid`='&1' AND `sys_sessions`.`permanent`=0 AND `sys_sessions`.`last_login`>'&2'", $sid, $min_lastlogin);
|
||||
$r = sql_fetch_assoc($rs);
|
||||
sql_free_result($rs);
|
||||
|
||||
if ($r)
|
||||
{
|
||||
sqlf("UPDATE `sys_sessions` SET `sys_sessions`.`last_login`=NOW() WHERE `sys_sessions`.`uuid`='&1' AND `sys_sessions`.`user_id`='&2'", $r['sid'], $r['user_id']);
|
||||
sqlf("UPDATE `user` SET `user`.`last_login`=NOW() WHERE `user`.`user_id`='&1'", $r['user_id']);
|
||||
|
||||
$this->userid = $r['user_id'];
|
||||
$this->username = $r['username'];
|
||||
$this->permanent = false;
|
||||
$this->lastlogin = $r['last_login'];
|
||||
$this->sessionid = $r['sid'];
|
||||
$this->admin = $r['admin'];
|
||||
$this->verified = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// prevent bruteforce
|
||||
sql("INSERT INTO `sys_logins` (`remote_addr`, `success`) VALUES ('&1', 0)", $_SERVER['REMOTE_ADDR']);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function pClear()
|
||||
{
|
||||
// set to no valid login
|
||||
$this->userid = 0;
|
||||
$this->username = '';
|
||||
$this->permanent = false;
|
||||
$this->lastlogin = '';
|
||||
$this->sessionid = '';
|
||||
$this->admin = 0;
|
||||
$this->verified = true;
|
||||
|
||||
$this->pStoreCookie();
|
||||
}
|
||||
|
||||
function pStoreCookie()
|
||||
{
|
||||
global $cookie;
|
||||
$cookie->set('userid', $this->userid);
|
||||
$cookie->set('username', $this->username);
|
||||
$cookie->set('permanent', ($this->permanent==true ? 1 : 0));
|
||||
$cookie->set('lastlogin', $this->lastlogin);
|
||||
$cookie->set('sessionid', $this->sessionid);
|
||||
$cookie->set('admin', $this->admin);
|
||||
}
|
||||
|
||||
function verify()
|
||||
{
|
||||
if ($this->verified == true)
|
||||
return;
|
||||
|
||||
if ($this->userid == 0)
|
||||
{
|
||||
$this->pClear();
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->checkLoginsCount() == false)
|
||||
{
|
||||
$this->pClear();
|
||||
return;
|
||||
}
|
||||
|
||||
$min_lastlogin = date('Y-m-d H:i:s', time() - LOGIN_TIME);
|
||||
$min_lastlogin_permanent = date('Y-m-d H:i:s', time() - LOGIN_TIME_PERMANENT);
|
||||
|
||||
$rs = sqlf("SELECT `sys_sessions`.`last_login`, `user`.`admin`, `user`.`username` FROM &db.`sys_sessions`, &db.`user` WHERE `sys_sessions`.`user_id`=`user`.`user_id` AND `user`.`is_active_flag`=1 AND `sys_sessions`.`uuid`='&1' AND `sys_sessions`.`user_id`='&2' AND ((`sys_sessions`.`permanent`=1 AND `sys_sessions`.`last_login`>'&3') OR (`sys_sessions`.`permanent`=0 AND `sys_sessions`.`last_login`>'&4'))", $this->sessionid, $this->userid, $min_lastlogin_permanent, $min_lastlogin);
|
||||
if ($rUser = sql_fetch_assoc($rs))
|
||||
{
|
||||
if ((($this->permanent == true) && (strtotime($rUser['last_login']) + LOGIN_TIME/2 < time())) ||
|
||||
(($this->permanent == false) && (strtotime($rUser['last_login']) + LOGIN_TIME_PERMANENT/2 < time())))
|
||||
{
|
||||
sqlf("UPDATE `sys_sessions` SET `sys_sessions`.`last_login`=NOW() WHERE `sys_sessions`.`uuid`='&1' AND `sys_sessions`.`user_id`='&2'", $this->sessionid, $this->userid);
|
||||
$rUser['last_login'] = date('Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
// user.last_login is used for statics, so we keep it up2date
|
||||
sqlf("UPDATE `user` SET `user`.`last_login`=NOW() WHERE `user`.`user_id`='&1'", $this->userid);
|
||||
|
||||
$this->lastlogin = $rUser['last_login'];
|
||||
$this->username = $rUser['username'];
|
||||
$this->admin = $rUser['admin'];
|
||||
$this->verified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// prevent bruteforce
|
||||
sql("INSERT INTO `sys_logins` (`remote_addr`, `success`) VALUES ('&1', 0)", $_SERVER['REMOTE_ADDR']);
|
||||
|
||||
$this->pClear();
|
||||
}
|
||||
sql_free_result($rs);
|
||||
|
||||
$this->pStoreCookie();
|
||||
return;
|
||||
}
|
||||
|
||||
function try_login($user, $password, $permanent)
|
||||
{
|
||||
global $opt;
|
||||
|
||||
if ($password == '')
|
||||
return LOGIN_EMPTY_USERPASSWORD;
|
||||
|
||||
$pwmd5 = md5($password);
|
||||
if ($opt['logic']['password_hash'])
|
||||
$pwmd5 = hash('sha512', $pwmd5);
|
||||
|
||||
return $this->try_login_md5($user, $pwmd5, $permanent);
|
||||
}
|
||||
|
||||
function checkLoginsCount()
|
||||
{
|
||||
global $opt;
|
||||
|
||||
// cleanup old entries
|
||||
// (execute only every 50 search calls)
|
||||
if (rand(1, 50) == 1)
|
||||
sqlf("DELETE FROM `sys_logins` WHERE `date_created`<'&1'", date('Y-m-d H:i:s', time() - 3600));
|
||||
|
||||
// check the number of logins in the last hour ...
|
||||
$logins_count = sqlf_value("SELECT COUNT(*) `count` FROM `sys_logins` WHERE `remote_addr`='&1' AND `date_created`>'&2'", 0, $_SERVER['REMOTE_ADDR'], date('Y-m-d H:i:s', time() - 3600));
|
||||
if ($logins_count > $opt['page']['max_logins_per_hour'])
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
function try_login_md5($user, $pwmd5, $permanent)
|
||||
{
|
||||
global $opt;
|
||||
$this->pClear();
|
||||
|
||||
if ($user == '' || $pwmd5 == '')
|
||||
return LOGIN_EMPTY_USERPASSWORD;
|
||||
|
||||
if ($this->checkLoginsCount() == false)
|
||||
return LOGIN_TOOMUCHLOGINS;
|
||||
|
||||
// delete old sessions
|
||||
$min_lastlogin_permanent = date('Y-m-d H:i:s', time() - LOGIN_TIME_PERMANENT);
|
||||
sqlf("DELETE FROM `sys_sessions` WHERE `last_login`<'&1'", $min_lastlogin_permanent);
|
||||
|
||||
// compare $user with email and username, if both matches use email
|
||||
$rsUser = sqlf("SELECT `user_id`, `username`, 2 AS `prio`, `is_active_flag`, `permanent_login_flag`, `admin` FROM `user` WHERE `username`='&1' AND `password`='&2' UNION
|
||||
SELECT `user_id`, `username`, 1 AS `prio`, `is_active_flag`, `permanent_login_flag`, `admin` FROM `user` WHERE `email`='&1' AND `password`='&2' ORDER BY `prio` ASC LIMIT 1", $user, $pwmd5);
|
||||
$rUser = sql_fetch_assoc($rsUser);
|
||||
sql_free_result($rsUser);
|
||||
|
||||
if ($permanent == null)
|
||||
$permanent = ($rUser['permanent_login_flag'] == 1);
|
||||
|
||||
if ($rUser)
|
||||
{
|
||||
// ok, there is a valid login
|
||||
if ($rUser['is_active_flag'] != 0)
|
||||
{
|
||||
// begin session
|
||||
$uuid = self::create_sessionid();
|
||||
sqlf("INSERT INTO `sys_sessions` (`uuid`, `user_id`, `permanent`) VALUES ('&1', '&2', '&3')", $uuid, $rUser['user_id'], ($permanent!=false ? 1 : 0));
|
||||
$this->userid = $rUser['user_id'];
|
||||
$this->username = $rUser['username'];
|
||||
$this->permanent = $permanent;
|
||||
$this->lastlogin = date('Y-m-d H:i:s');
|
||||
$this->sessionid = $uuid;
|
||||
$this->admin = $rUser['admin'];
|
||||
$this->verified = true;
|
||||
|
||||
$retval = LOGIN_OK;
|
||||
}
|
||||
else
|
||||
$retval = LOGIN_USERNOTACTIVE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// sorry, bad login
|
||||
$retval = LOGIN_BADUSERPW;
|
||||
}
|
||||
|
||||
sqlf("INSERT INTO `sys_logins` (`remote_addr`, `success`) VALUES ('&1', '&2')", $_SERVER['REMOTE_ADDR'], ($rUser===false ? 0 : 1));
|
||||
|
||||
// store to cookie
|
||||
$this->pStoreCookie();
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
private static function create_sessionid()
|
||||
{
|
||||
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff),
|
||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||
);
|
||||
}
|
||||
|
||||
function getUserCountry()
|
||||
{
|
||||
global $opt, $cookie;
|
||||
|
||||
// language specified in cookie?
|
||||
if ($cookie->is_set('usercountry'))
|
||||
{
|
||||
$sCountry = $cookie->get('usercountry', null);
|
||||
if ($sCountry != null)
|
||||
return $sCountry;
|
||||
}
|
||||
|
||||
// user specified a language?
|
||||
if ($this->userid != 0)
|
||||
{
|
||||
$sCountry = sql_value("SELECT `country` FROM `user` WHERE `user_id`='&1'", null, $this->userid);
|
||||
if ($sCountry != null)
|
||||
return $sCountry;
|
||||
}
|
||||
|
||||
// default country of this language
|
||||
if (isset($opt['locale'][$opt['template']['locale']]['country']))
|
||||
return $opt['locale'][$opt['template']['locale']]['country'];
|
||||
|
||||
// default country of installation (or domain)
|
||||
return $opt['template']['default']['country'];
|
||||
}
|
||||
|
||||
function logout()
|
||||
{
|
||||
if ($this->userid != 0)
|
||||
sqlf("DELETE FROM `sys_sessions` WHERE `uuid`='&1' AND `user_id`='&2'", $this->sessionid, $this->userid);
|
||||
|
||||
$this->pClear();
|
||||
}
|
||||
|
||||
public function hasAdminPriv($privilege = false)
|
||||
{
|
||||
if ($privilege === false)
|
||||
return $this->admin != 0;
|
||||
|
||||
return ($this->admin & $privilege) == $privilege;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user