Skip to content

Commit

Permalink
generate status-change logs for Ocprop actions and account-disabling; f…
Browse files Browse the repository at this point in the history
…ixes #207
  • Loading branch information
following5 committed Jun 5, 2013
1 parent 4408abe commit 0eeb9c1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 9 deletions.
24 changes: 23 additions & 1 deletion htdocs/editcache.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -474,10 +474,32 @@ function getWaypoints($cacheid)
} }


// save to DB // save to DB
// status update will trigger touching the last_modified date of all depending records // Status update will trigger touching the last_modified date of all depending records.
// Status change via editcache.php is no longer available via the user interface,
// but still used by Ocprop and maybe other tools.
sql("SET @STATUS_CHANGE_USER_ID='&1'", $usr['userid']); sql("SET @STATUS_CHANGE_USER_ID='&1'", $usr['userid']);
sql("UPDATE `caches` SET `name`='&1', `longitude`='&2', `latitude`='&3', `type`='&4', `date_hidden`='&5', `country`='&6', `size`='&7', `difficulty`='&8', `terrain`='&9', `status`='&10', `search_time`='&11', `way_length`='&12', `logpw`='&13', `wp_gc`='&14', `wp_nc`='&15', `date_activate` = $activation_date WHERE `cache_id`='&16'", $cache_name, $cache_lon, $cache_lat, $cache_type, date('Y-m-d', mktime(0, 0, 0, $cache_hidden_month, $cache_hidden_day, $cache_hidden_year)), $cache_country, $sel_size, $cache_difficulty, $cache_terrain, $status, $search_time, $way_length, $log_pw, $wp_gc, $wp_nc, $cache_id); sql("UPDATE `caches` SET `name`='&1', `longitude`='&2', `latitude`='&3', `type`='&4', `date_hidden`='&5', `country`='&6', `size`='&7', `difficulty`='&8', `terrain`='&9', `status`='&10', `search_time`='&11', `way_length`='&12', `logpw`='&13', `wp_gc`='&14', `wp_nc`='&15', `date_activate` = $activation_date WHERE `cache_id`='&16'", $cache_name, $cache_lon, $cache_lat, $cache_type, date('Y-m-d', mktime(0, 0, 0, $cache_hidden_month, $cache_hidden_day, $cache_hidden_year)), $cache_country, $sel_size, $cache_difficulty, $cache_terrain, $status, $search_time, $way_length, $log_pw, $wp_gc, $wp_nc, $cache_id);


// generate status-change log
if ($status != $status_old && $status_old != 5)
{
switch ($status)
{
case 1: $logtype = 10; break;
case 2: $logtype = 11; break;
case 3: $logtype = 9; break;
case 6: $logtype = 13; break;
default: $logtype = 0; // ???
}
if ($logtype > 0)
{
sql("INSERT INTO `cache_logs` (`node`, `cache_id`, `user_id`, `type`, `date`)
VALUES ('&1','&2','&3','&4','&5')",
$oc_nodeid, $cache_id, $usr['userid'], $logtype, date('Y-m-d'));
// notifications will be automatically generated
}
}

// do not use slave server for the next time ... // do not use slave server for the next time ...
db_slave_exclude(); db_slave_exclude();


Expand Down
2 changes: 1 addition & 1 deletion htdocs/lib2/logic/cache.class.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ function allowLog()
global $login; global $login;


$login->verify(); $login->verify();
if ($this->getUserId() == $login->userid) if ($this->getUserId() == $login->userid || $login->hasAdminPriv(ADMIN_USER))
return true; return true;


return (sql_value("SELECT `allow_user_log` FROM `cache_status` WHERE `id`='&1'", 0, $this->getStatus()) == 1); return (sql_value("SELECT `allow_user_log` FROM `cache_status` WHERE `id`='&1'", 0, $this->getStatus()) == 1);
Expand Down
4 changes: 2 additions & 2 deletions htdocs/lib2/logic/cachelog.class.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ function getTextHtml()
} }
function setTextHtml($value) function setTextHtml($value)
{ {
return $this->reCacheLog->setValue('text_html', $value); return $this->reCacheLog->setValue('text_html', $value ? 1 : 0);
} }
function getTextHtmlEdit() function getTextHtmlEdit()
{ {
return $this->reCacheLog->getValue('text_html'); return $this->reCacheLog->getValue('text_html');
} }
function setTextHtmlEdit($value) function setTextHtmlEdit($value)
{ {
return $this->reCacheLog->setValue('text_htmledit', $value); return $this->reCacheLog->setValue('text_htmledit', $value ? 1 : 0);
} }
function getUUID() function getUUID()
{ {
Expand Down
33 changes: 29 additions & 4 deletions htdocs/lib2/logic/user.class.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require_once($opt['rootpath'] . 'lib2/logic/statpic.class.php'); require_once($opt['rootpath'] . 'lib2/logic/statpic.class.php');
require_once($opt['rootpath'] . 'lib2/logic/countriesList.class.php'); require_once($opt['rootpath'] . 'lib2/logic/countriesList.class.php');
require_once($opt['rootpath'] . 'lib2/logic/picture.class.php'); require_once($opt['rootpath'] . 'lib2/logic/picture.class.php');
require_once($opt['rootpath'] . 'lib2/logic/cache.class.php');
require_once($opt['rootpath'] . 'lib2/logic/cracklib.inc.php'); require_once($opt['rootpath'] . 'lib2/logic/cracklib.inc.php');
require_once($opt['rootpath'] . 'lib2/translate.class.php'); require_once($opt['rootpath'] . 'lib2/translate.class.php');


Expand Down Expand Up @@ -696,7 +697,7 @@ function canDisable()


function disable() function disable()
{ {
global $login; global $login, $translate;


if ($this->canDisable() == false) if ($this->canDisable() == false)
return false; return false;
Expand All @@ -714,8 +715,7 @@ function disable()
'User ' . sql_escape($this->getUsername()) . ' disabled', 'User ' . sql_escape($this->getUsername()) . ' disabled',
serialize($backup)); serialize($backup));


sql("SET @STATUS_CHANGE_USER_ID='&1'", $login->userid); // delete private data
sql("UPDATE `caches` SET `status`=6 WHERE `user_id`='&1' AND `status` IN (1, 2, 3)", $this->nUserId);
sql("UPDATE `user` SET `password`=NULL, `email`=NULL, sql("UPDATE `user` SET `password`=NULL, `email`=NULL,
`is_active_flag`=0, `is_active_flag`=0,
`latitude`=0, `longitude`=0, `latitude`=0, `longitude`=0,
Expand All @@ -729,7 +729,32 @@ function disable()
sql("DELETE FROM `user_options` WHERE `user_id`='&1'", $this->nUserId); sql("DELETE FROM `user_options` WHERE `user_id`='&1'", $this->nUserId);
$this->reload(); $this->reload();


return true; // lock the user's caches
$error = false;
$rs = sql("SELECT `cache_id` FROM `caches` WHERE `user_id`='&1' AND `status` IN (1,2,3)", $this->nUserId);
while (($rCache = sql_fetch_assoc($rs)) && !$error)
{
$error = true;
$cache = new cache($rCache['cache_id']);
if ($cache->setStatus(6) && $cache->save())
{
$log = cachelog::createNew($rCache['cache_id'],$login->userid,true);
if ($log !== false)
{
$log->setType(cachelog::LOGTYPE_LOCKED);
$log->setOcTeamComment(true);
$log->setDate(date('Y-m-d'));
$log->setText($translate->t('The user account has been disabled.', '','',0,'',1, $cache->getDefaultDescLanguage()));
$log->setTextHtml(false);
if ($log->save())
$error = false;
}
}
echo "\n";
}
sql_free_result($rs);

return !$error;
} }




Expand Down
2 changes: 1 addition & 1 deletion htdocs/util2/cron/modules/cache_autoarchive.class.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function archive_cache($cache_id, $comment)
global $opt, $login, $translate; global $opt, $login, $translate;


$log = cachelog::createNew($cache_id,$login->userid); $log = cachelog::createNew($cache_id,$login->userid);
if (!$log) if ($log === false)
echo $this->name . ": cannot create log for cache $cache_id\n"; echo $this->name . ": cannot create log for cache $cache_id\n";
else else
{ {
Expand Down

0 comments on commit 0eeb9c1

Please sign in to comment.