fixed mentioned bugs, updates #206

This commit is contained in:
Nils Bohrs 2013-06-20 20:02:46 +02:00 committed by following
parent 2fb28300ee
commit c6fa97b794
6 changed files with 52 additions and 42 deletions

View File

@ -545,6 +545,11 @@
$opt['map']['min_maxrecords'] = 100;
$opt['map']['max_maxrecords'] = 4000;
/*
* html purifier
*/
$opt['html_purifier']['cache_path'] = dirname(__FILE__).'/../cache2/html_purifier/';
/* Opencaching Node Daemon
*
*/

View File

@ -553,22 +553,18 @@ class cache
}
function logTypeAllowed($logType)
function logTypeAllowed($logType, $oldLogType = 0)
{
// check if given logType is valid for this cache type
return (sql_value(" SELECT COUNT(*)
FROM cache_logtype
WHERE cache_type_id='&1'
AND log_type_id='&2'",
0,
$this->getType(), $logType) > 0);
return logtype_ok($this->getCacheId(), $logType, $oldLogType);
}
function updateCacheStatus($logType)
{
// get cache status
$cacheStatus = sql_value(" SELECT `cache_status`
$cacheStatus = sql_value("
SELECT `cache_status`
FROM `log_types`
WHERE `id`='&1'",
0,
@ -579,7 +575,7 @@ class cache
}
function getUserLogTypes($userId, $userLogType)
function getUserLogTypes($userLogType, $oldLogType = 0)
{
global $translate, $login;
@ -588,7 +584,7 @@ class cache
$logtypeNames = get_logtype_names();
$allowedLogtypes = get_cache_log_types($this->getCacheId(), 0);
$defaultLogType = $userLogType;
if (!logtype_ok($this->getCacheId(), $defaultLogType, 0))
if (!logtype_ok($this->getCacheId(), $defaultLogType, $oldLogType))
$defaultLogType = $allowedLogtypes[0];
// prepare array
@ -605,10 +601,10 @@ class cache
return $logTypes;
}
function teamcommentAllowed($logType)
function teamcommentAllowed($logType, $oldTeamComment = false)
{
// checks if teamcomment is allowed
return teamcomment_allowed($this->getCacheId(),$logType);
return teamcomment_allowed($this->getCacheId(), $logType, $oldTeamComment);
}
}
?>
?>

View File

@ -64,6 +64,8 @@ class cachelog
static function createNewFromCache($oCache, $nUserId)
{
global $opt;
// check if user is allowed to log this cache!
if ($oCache->exist() == false)
return false;
@ -73,6 +75,7 @@ class cachelog
$oCacheLog = new cachelog(ID_NEW);
$oCacheLog->setUserId($nUserId);
$oCacheLog->setCacheId($oCache->getCacheId());
$oCacheLog->setNode($opt['logic']['node']['id']);
return $oCacheLog;
}
@ -278,7 +281,8 @@ class cachelog
static function isDuplicate($cacheId, $userId, $logType, $logDate, $logText)
{
// get info if exact the same values are already in database
return (sql_value(" SELECT COUNT(`id`)
return (sql_value("
SELECT COUNT(`id`)
FROM `cache_logs`
WHERE `cache_id`='&1'
AND `user_id`='&2'

View File

@ -1254,7 +1254,8 @@ class user
function getGivenRatings()
{
// get number of cache ratings for this user
return sql_value(" SELECT COUNT(`user_id`)
return sql_value("
SELECT COUNT(`user_id`)
FROM `cache_rating`
WHERE `user_id`='&1'",
0,

View File

@ -40,20 +40,22 @@
$useradmin = ($login->hasAdminPriv()) ? 1 : 0;
// prepare array to indicate errors in template
$error = array();
$validate = array();
// proceed loggable, if valid cache_id
$error['logAllowed'] = true;
$validate['logAllowed'] = true;
if ($cacheId != 0)
{
// get cache object
$cache = new cache($cacheId);
// check log allowed (owner, admin, already published)
$error['logAllowed'] = ($cache->allowLog() || $useradmin || $cache->getStatus() != 5);
// check log allowed (owner, admin, already published, not disabled)
$validate['logAllowed'] = ($cache->allowLog() || $useradmin || ($cache->getStatus() != 5 && $cache->getStatus() != 6 && $cache->getStatus() != 7));
// get user object
$user = new user($login->userid);
// is user cache owner
$isOwner = ($user->getUserId() == $cache->getUserId());
// assing ratings to template
$tpl->assign('ratingallowed', $user->allowRatings());
@ -61,6 +63,7 @@
$tpl->assign('maxratings', $user->getMaxRatings());
$tpl->assign('israted', $cache->isRecommendedByUser($user->getUserId()));
$tpl->assign('foundsuntilnextrating', $user->foundsUntilNextRating());
$tpl->assign('isowner', $isOwner);
// check and prepare form values
$logText = (isset($_POST['logtext'])) ? ($_POST['logtext']) : '';
@ -113,14 +116,14 @@
&& ($logTimeHour . $logTimeMinute == "" || is_numeric($logTimeHour))
&& ($logTimeMinute == "" || is_numeric($logTimeMinute)))
{
$error['dateOk'] = checkdate( $logDateMonth, $logDateDay, $logDateYear)
$validate['dateOk'] = checkdate( $logDateMonth, $logDateDay, $logDateYear)
&& ($logDateYear >= 2000)
&& ($logTimeHour>=0)
&& ($logTimeHour<=23)
&& ($logTimeMinute>=0)
&& ($logTimeMinute<=59);
if ($error['dateOk'] && isset($_POST['submitform']))
$error['dateOk'] = (mktime( $logTimeHour+0,
if ($validate['dateOk'] && isset($_POST['submitform']))
$validate['dateOk'] = (mktime( $logTimeHour+0,
$logTimeMinute+0,
0,
$logDateMonth,
@ -128,19 +131,19 @@
$logDateYear) < time());
}
else
$error['dateOk'] = false;
$validate['dateOk'] = false;
// check log type
$error['logType'] = $cache->logTypeAllowed($logType);
$validate['logType'] = $cache->logTypeAllowed($logType);
// check log password
$error['logPw'] = true;
$validate['logPw'] = true;
if (isset($_POST['submitform']) && $cache->requireLogPW())
$error['logPw'] = $cache->validateLogPW($logType, $_POST['log_pw']);
$validate['logPw'] = $cache->validateLogPW($logType, $_POST['log_pw']);
// check error
$loggable = true;
foreach ($error as $test)
foreach ($validate as $test)
{
$loggable &= $test;
@ -150,7 +153,7 @@
}
// prepare duplicate log error
$error['duplicateLog'] = true;
$validate['duplicateLog'] = true;
// all checks done, no error => log
if (isset($_POST['submitform']) && $loggable)
@ -185,7 +188,6 @@
$cacheLog->setText($logText);
$cacheLog->setTextHtml((($descMode != 1) ? 1 : 0));
$cacheLog->setTextHtmlEdit((($descMode == 3) ? 1 : 0));
$cacheLog->setNode($opt['logic']['node']['id']);
// save log values
$cacheLog->save();
@ -193,8 +195,8 @@
// update cache status
$cache->updateCacheStatus($logType);
// update rating
if ($rateOption)
// update rating (if correct logtype, user has ratings to give and is not owner)
if ($rateOption && $user->allowRatings() && !$isOwner)
if ($rateCache)
$cache->addRecommendation($user->getUserId());
else
@ -212,13 +214,13 @@
}
else
{
$error['duplicateLog'] = false;
$validate['duplicateLog'] = false;
}
}
// assign values to template
// error
$tpl->assign('error', $error);
$tpl->assign('validate', $validate);
// user info
$tpl->assign('userFound', $user->getStatFound());
// cache infos
@ -236,21 +238,21 @@
// text, <html> or editor
$tpl->assign('descMode', $descMode);
// logtypes
$tpl->assign('logtypes', $cache->getUserLogTypes($user->getUserId(),$logType));
$tpl->assign('logtypes', $cache->getUserLogTypes($logType));
// teamcomment
$tpl->assign('octeamcommentallowed', $cache->teamcommentAllowed(3));
$tpl->assign('octeamcomment', ($ocTeamComment || ($cache->allowLog() && $useradmin)) ? true : false);
$tpl->assign('octeamcommentclass', ($cache->allowLog() && $useradmin) ? 'redtext' : '');
$tpl->assign('octeamcomment', ($ocTeamComment || (!$cache->allowLog() && $useradmin)) ? true : false);
$tpl->assign('octeamcommentclass', (!$cache->allowLog() && $useradmin) ? 'redtext' : '');
}
else
{
// not loggable
$error['logAllowed'] = false;
$validate['logAllowed'] = false;
}
// prepare template and display
$tpl->assign('error', $error);
$tpl->assign('validate', $validate);
$tpl->display();
?>

View File

@ -66,7 +66,7 @@ function _chkFound () {
<td colspan="2" style="text-align: right;"><b>{t 1=$userFound}You found %1 caches until now.{/t}</b></td>
</tr>
<tr><td class="spacer" colspan="2"></td></tr>
{if $error.duplicateLog==false}
{if $validate.duplicateLog==false}
<tr>
<td colspan="2"><span class="errormsg">{t}This log has already been saved, you maybe send it twice!{/t}</span></td>
</tr>
@ -96,7 +96,7 @@ function _chkFound () {
&nbsp;&nbsp;&nbsp;
<input class="input20" type="text" name="loghour" maxlength="2" value="{$loghour}" /> :
<input class="input20" type="text" name="logminute" maxlength="2" value="{$logminute}" />
&nbsp;&nbsp;{if $error.dateOk==false}<span class="errormsg">{t}date or time is invalid{/t}</span>{/if}
&nbsp;&nbsp;{if $validate.dateOk==false}<span class="errormsg">{t}date or time is invalid{/t}</span>{/if}
</td>
</tr>
<tr>
@ -107,6 +107,7 @@ function _chkFound () {
</td>
</tr>
<tr><td class="spacer" colspan="2"></td></tr>
{if $isowner==false}
<tr>
<td valign="top">{t}Recommendations:{/t}</td>
<td valign="top">
@ -114,12 +115,13 @@ function _chkFound () {
{t 1=$givenratings 2=$maxratings}You have given %1 of %2 possible recommendations.{/t}
{else}
{t 1=$foundsuntilnextrating}You need additional %1 finds, to make another recommendation.{/t}
{if ($givenratings==$maxratings && $israted==false)}<br />{t}Alternatively, you can withdraw a <a href="mytop5.php">existing recommendation</a>.{/t}{/if}
{if ($givenratings > 0 && $givenratings==$maxratings && $israted==false)}<br />{t}Alternatively, you can withdraw a <a href="mytop5.php">existing recommendation</a>.{/t}{/if}
{/if}
<noscript><br />{t}A recommendation can only be made within a "found"-log!{/t}</noscript>
</td>
</tr>
<tr><td class="spacer" colspan="2"></td></tr>
{/if}
</table>
<table class="table">
@ -167,7 +169,7 @@ function _chkFound () {
{if $logpw}
<tr>
<td colspan="2">{t}passwort to log:{/t}
<input class="input100" type="text" name="log_pw" maxlength="20" value="" /> {if $error.pwOk==false}<span class="errormsg">{t}Invalid password!{/t}</span>{else}({if $cachetype==6}{t}only for attended-logs{/t}{else}{t}only for found-logs{/t}{/if}){/if}
<input class="input100" type="text" name="log_pw" maxlength="20" value="" /> {if $validate.pwOk==false}<span class="errormsg">{t}Invalid password!{/t}</span>{else}({if $cachetype==6}{t}only for attended-logs{/t}{else}{t}only for found-logs{/t}{/if}){/if}
</td>
</tr>
<tr><td class="spacer" colspan="2"></td></tr>