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']['min_maxrecords'] = 100;
$opt['map']['max_maxrecords'] = 4000; $opt['map']['max_maxrecords'] = 4000;
/*
* html purifier
*/
$opt['html_purifier']['cache_path'] = dirname(__FILE__).'/../cache2/html_purifier/';
/* Opencaching Node Daemon /* 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 // check if given logType is valid for this cache type
return (sql_value(" SELECT COUNT(*) return logtype_ok($this->getCacheId(), $logType, $oldLogType);
FROM cache_logtype
WHERE cache_type_id='&1'
AND log_type_id='&2'",
0,
$this->getType(), $logType) > 0);
} }
function updateCacheStatus($logType) function updateCacheStatus($logType)
{ {
// get cache status // get cache status
$cacheStatus = sql_value(" SELECT `cache_status` $cacheStatus = sql_value("
SELECT `cache_status`
FROM `log_types` FROM `log_types`
WHERE `id`='&1'", WHERE `id`='&1'",
0, 0,
@ -579,7 +575,7 @@ class cache
} }
function getUserLogTypes($userId, $userLogType) function getUserLogTypes($userLogType, $oldLogType = 0)
{ {
global $translate, $login; global $translate, $login;
@ -588,7 +584,7 @@ class cache
$logtypeNames = get_logtype_names(); $logtypeNames = get_logtype_names();
$allowedLogtypes = get_cache_log_types($this->getCacheId(), 0); $allowedLogtypes = get_cache_log_types($this->getCacheId(), 0);
$defaultLogType = $userLogType; $defaultLogType = $userLogType;
if (!logtype_ok($this->getCacheId(), $defaultLogType, 0)) if (!logtype_ok($this->getCacheId(), $defaultLogType, $oldLogType))
$defaultLogType = $allowedLogtypes[0]; $defaultLogType = $allowedLogtypes[0];
// prepare array // prepare array
@ -605,10 +601,10 @@ class cache
return $logTypes; return $logTypes;
} }
function teamcommentAllowed($logType) function teamcommentAllowed($logType, $oldTeamComment = false)
{ {
// checks if teamcomment is allowed // 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) static function createNewFromCache($oCache, $nUserId)
{ {
global $opt;
// check if user is allowed to log this cache! // check if user is allowed to log this cache!
if ($oCache->exist() == false) if ($oCache->exist() == false)
return false; return false;
@ -73,6 +75,7 @@ class cachelog
$oCacheLog = new cachelog(ID_NEW); $oCacheLog = new cachelog(ID_NEW);
$oCacheLog->setUserId($nUserId); $oCacheLog->setUserId($nUserId);
$oCacheLog->setCacheId($oCache->getCacheId()); $oCacheLog->setCacheId($oCache->getCacheId());
$oCacheLog->setNode($opt['logic']['node']['id']);
return $oCacheLog; return $oCacheLog;
} }
@ -278,7 +281,8 @@ class cachelog
static function isDuplicate($cacheId, $userId, $logType, $logDate, $logText) static function isDuplicate($cacheId, $userId, $logType, $logDate, $logText)
{ {
// get info if exact the same values are already in database // 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` FROM `cache_logs`
WHERE `cache_id`='&1' WHERE `cache_id`='&1'
AND `user_id`='&2' AND `user_id`='&2'

View File

@ -1254,7 +1254,8 @@ class user
function getGivenRatings() function getGivenRatings()
{ {
// get number of cache ratings for this user // 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` FROM `cache_rating`
WHERE `user_id`='&1'", WHERE `user_id`='&1'",
0, 0,

View File

@ -40,20 +40,22 @@
$useradmin = ($login->hasAdminPriv()) ? 1 : 0; $useradmin = ($login->hasAdminPriv()) ? 1 : 0;
// prepare array to indicate errors in template // prepare array to indicate errors in template
$error = array(); $validate = array();
// proceed loggable, if valid cache_id // proceed loggable, if valid cache_id
$error['logAllowed'] = true; $validate['logAllowed'] = true;
if ($cacheId != 0) if ($cacheId != 0)
{ {
// get cache object // get cache object
$cache = new cache($cacheId); $cache = new cache($cacheId);
// check log allowed (owner, admin, already published) // check log allowed (owner, admin, already published, not disabled)
$error['logAllowed'] = ($cache->allowLog() || $useradmin || $cache->getStatus() != 5); $validate['logAllowed'] = ($cache->allowLog() || $useradmin || ($cache->getStatus() != 5 && $cache->getStatus() != 6 && $cache->getStatus() != 7));
// get user object // get user object
$user = new user($login->userid); $user = new user($login->userid);
// is user cache owner
$isOwner = ($user->getUserId() == $cache->getUserId());
// assing ratings to template // assing ratings to template
$tpl->assign('ratingallowed', $user->allowRatings()); $tpl->assign('ratingallowed', $user->allowRatings());
@ -61,6 +63,7 @@
$tpl->assign('maxratings', $user->getMaxRatings()); $tpl->assign('maxratings', $user->getMaxRatings());
$tpl->assign('israted', $cache->isRecommendedByUser($user->getUserId())); $tpl->assign('israted', $cache->isRecommendedByUser($user->getUserId()));
$tpl->assign('foundsuntilnextrating', $user->foundsUntilNextRating()); $tpl->assign('foundsuntilnextrating', $user->foundsUntilNextRating());
$tpl->assign('isowner', $isOwner);
// check and prepare form values // check and prepare form values
$logText = (isset($_POST['logtext'])) ? ($_POST['logtext']) : ''; $logText = (isset($_POST['logtext'])) ? ($_POST['logtext']) : '';
@ -113,14 +116,14 @@
&& ($logTimeHour . $logTimeMinute == "" || is_numeric($logTimeHour)) && ($logTimeHour . $logTimeMinute == "" || is_numeric($logTimeHour))
&& ($logTimeMinute == "" || is_numeric($logTimeMinute))) && ($logTimeMinute == "" || is_numeric($logTimeMinute)))
{ {
$error['dateOk'] = checkdate( $logDateMonth, $logDateDay, $logDateYear) $validate['dateOk'] = checkdate( $logDateMonth, $logDateDay, $logDateYear)
&& ($logDateYear >= 2000) && ($logDateYear >= 2000)
&& ($logTimeHour>=0) && ($logTimeHour>=0)
&& ($logTimeHour<=23) && ($logTimeHour<=23)
&& ($logTimeMinute>=0) && ($logTimeMinute>=0)
&& ($logTimeMinute<=59); && ($logTimeMinute<=59);
if ($error['dateOk'] && isset($_POST['submitform'])) if ($validate['dateOk'] && isset($_POST['submitform']))
$error['dateOk'] = (mktime( $logTimeHour+0, $validate['dateOk'] = (mktime( $logTimeHour+0,
$logTimeMinute+0, $logTimeMinute+0,
0, 0,
$logDateMonth, $logDateMonth,
@ -128,19 +131,19 @@
$logDateYear) < time()); $logDateYear) < time());
} }
else else
$error['dateOk'] = false; $validate['dateOk'] = false;
// check log type // check log type
$error['logType'] = $cache->logTypeAllowed($logType); $validate['logType'] = $cache->logTypeAllowed($logType);
// check log password // check log password
$error['logPw'] = true; $validate['logPw'] = true;
if (isset($_POST['submitform']) && $cache->requireLogPW()) if (isset($_POST['submitform']) && $cache->requireLogPW())
$error['logPw'] = $cache->validateLogPW($logType, $_POST['log_pw']); $validate['logPw'] = $cache->validateLogPW($logType, $_POST['log_pw']);
// check error // check error
$loggable = true; $loggable = true;
foreach ($error as $test) foreach ($validate as $test)
{ {
$loggable &= $test; $loggable &= $test;
@ -150,7 +153,7 @@
} }
// prepare duplicate log error // prepare duplicate log error
$error['duplicateLog'] = true; $validate['duplicateLog'] = true;
// all checks done, no error => log // all checks done, no error => log
if (isset($_POST['submitform']) && $loggable) if (isset($_POST['submitform']) && $loggable)
@ -185,7 +188,6 @@
$cacheLog->setText($logText); $cacheLog->setText($logText);
$cacheLog->setTextHtml((($descMode != 1) ? 1 : 0)); $cacheLog->setTextHtml((($descMode != 1) ? 1 : 0));
$cacheLog->setTextHtmlEdit((($descMode == 3) ? 1 : 0)); $cacheLog->setTextHtmlEdit((($descMode == 3) ? 1 : 0));
$cacheLog->setNode($opt['logic']['node']['id']);
// save log values // save log values
$cacheLog->save(); $cacheLog->save();
@ -193,8 +195,8 @@
// update cache status // update cache status
$cache->updateCacheStatus($logType); $cache->updateCacheStatus($logType);
// update rating // update rating (if correct logtype, user has ratings to give and is not owner)
if ($rateOption) if ($rateOption && $user->allowRatings() && !$isOwner)
if ($rateCache) if ($rateCache)
$cache->addRecommendation($user->getUserId()); $cache->addRecommendation($user->getUserId());
else else
@ -212,13 +214,13 @@
} }
else else
{ {
$error['duplicateLog'] = false; $validate['duplicateLog'] = false;
} }
} }
// assign values to template // assign values to template
// error // error
$tpl->assign('error', $error); $tpl->assign('validate', $validate);
// user info // user info
$tpl->assign('userFound', $user->getStatFound()); $tpl->assign('userFound', $user->getStatFound());
// cache infos // cache infos
@ -236,21 +238,21 @@
// text, <html> or editor // text, <html> or editor
$tpl->assign('descMode', $descMode); $tpl->assign('descMode', $descMode);
// logtypes // logtypes
$tpl->assign('logtypes', $cache->getUserLogTypes($user->getUserId(),$logType)); $tpl->assign('logtypes', $cache->getUserLogTypes($logType));
// teamcomment // teamcomment
$tpl->assign('octeamcommentallowed', $cache->teamcommentAllowed(3)); $tpl->assign('octeamcommentallowed', $cache->teamcommentAllowed(3));
$tpl->assign('octeamcomment', ($ocTeamComment || ($cache->allowLog() && $useradmin)) ? true : false); $tpl->assign('octeamcomment', ($ocTeamComment || (!$cache->allowLog() && $useradmin)) ? true : false);
$tpl->assign('octeamcommentclass', ($cache->allowLog() && $useradmin) ? 'redtext' : ''); $tpl->assign('octeamcommentclass', (!$cache->allowLog() && $useradmin) ? 'redtext' : '');
} }
else else
{ {
// not loggable // not loggable
$error['logAllowed'] = false; $validate['logAllowed'] = false;
} }
// prepare template and display // prepare template and display
$tpl->assign('error', $error); $tpl->assign('validate', $validate);
$tpl->display(); $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> <td colspan="2" style="text-align: right;"><b>{t 1=$userFound}You found %1 caches until now.{/t}</b></td>
</tr> </tr>
<tr><td class="spacer" colspan="2"></td></tr> <tr><td class="spacer" colspan="2"></td></tr>
{if $error.duplicateLog==false} {if $validate.duplicateLog==false}
<tr> <tr>
<td colspan="2"><span class="errormsg">{t}This log has already been saved, you maybe send it twice!{/t}</span></td> <td colspan="2"><span class="errormsg">{t}This log has already been saved, you maybe send it twice!{/t}</span></td>
</tr> </tr>
@ -96,7 +96,7 @@ function _chkFound () {
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<input class="input20" type="text" name="loghour" maxlength="2" value="{$loghour}" /> : <input class="input20" type="text" name="loghour" maxlength="2" value="{$loghour}" /> :
<input class="input20" type="text" name="logminute" maxlength="2" value="{$logminute}" /> <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> </td>
</tr> </tr>
<tr> <tr>
@ -107,6 +107,7 @@ function _chkFound () {
</td> </td>
</tr> </tr>
<tr><td class="spacer" colspan="2"></td></tr> <tr><td class="spacer" colspan="2"></td></tr>
{if $isowner==false}
<tr> <tr>
<td valign="top">{t}Recommendations:{/t}</td> <td valign="top">{t}Recommendations:{/t}</td>
<td valign="top"> <td valign="top">
@ -114,12 +115,13 @@ function _chkFound () {
{t 1=$givenratings 2=$maxratings}You have given %1 of %2 possible recommendations.{/t} {t 1=$givenratings 2=$maxratings}You have given %1 of %2 possible recommendations.{/t}
{else} {else}
{t 1=$foundsuntilnextrating}You need additional %1 finds, to make another recommendation.{/t} {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} {/if}
<noscript><br />{t}A recommendation can only be made within a "found"-log!{/t}</noscript> <noscript><br />{t}A recommendation can only be made within a "found"-log!{/t}</noscript>
</td> </td>
</tr> </tr>
<tr><td class="spacer" colspan="2"></td></tr> <tr><td class="spacer" colspan="2"></td></tr>
{/if}
</table> </table>
<table class="table"> <table class="table">
@ -167,7 +169,7 @@ function _chkFound () {
{if $logpw} {if $logpw}
<tr> <tr>
<td colspan="2">{t}passwort to log:{/t} <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> </td>
</tr> </tr>
<tr><td class="spacer" colspan="2"></td></tr> <tr><td class="spacer" colspan="2"></td></tr>