Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
merged branch 168-cachelists
  • Loading branch information
following5 committed Jun 25, 2015
2 parents 9e1ffa2 + 288b823 commit 5afc1f8
Show file tree
Hide file tree
Showing 52 changed files with 2,557 additions and 213 deletions.
95 changes: 95 additions & 0 deletions bin/dbsv-update.php
Expand Up @@ -373,6 +373,101 @@ function dbv_122() // add user profile flag for default setting of send-my-email
}
}

function dbv_123() // add tables, fields and procs for cache lists and list watches
{
if (!sql_table_exists('cache_lists'))
{
sql("
CREATE TABLE `cache_lists` (
`id` int(10) NOT NULL auto_increment,
`uuid` varchar(36) NOT NULL,
`user_id` int(10) NOT NULL,
`date_created` datetime NOT NULL,
`last_modified` datetime NOT NULL,
`last_added` datetime default NULL,
`name` varchar(80) NOT NULL,
`is_public` tinyint(1) NOT NULL default '0',
`entries` int(6) NOT NULL default '0' COMMENT 'via trigger in cache_list_items',
`watchers` int(10) NOT NULL default '0' COMMENT 'via trigger in cache_list_watches',
PRIMARY KEY (`id`),
UNIQUE KEY `uuid` (`uuid`),
KEY `name` (`name`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
}
if (!sql_table_exists('cache_list_items'))
{
sql("
CREATE TABLE `cache_list_items` (
`cache_list_id` int(10) NOT NULL,
`cache_id` int(10) NOT NULL,
UNIQUE KEY `cache_list_id` (`cache_list_id`,`cache_id`),
KEY `cache_id` (`cache_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
}
if (!sql_table_exists('cache_list_watches'))
{
sql("
CREATE TABLE `cache_list_watches` (
`cache_list_id` int(10) NOT NULL,
`user_id` int(10) NOT NULL,
UNIQUE KEY `cache_list_id` (`cache_list_id`,`user_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
}

if (!sql_field_exists('caches','show_cachelists'))
{
sql("ALTER TABLE `caches` ADD COLUMN `show_cachelists` tinyint(1) NOT NULL default '1'");
}
if (sql_field_exists('cache_watches','last_executed')) // obsolete pre-OC3 field
{
sql("ALTER TABLE `cache_watches` DROP COLUMN `last_executed`");
}

update_triggers(); // runs maintain-123.inc.php
}

function dbv_124() // update cache lists implementation
{
if (!sql_table_exists('stat_cache_lists'))
{
sql("
CREATE TABLE `stat_cache_lists` (
`cache_list_id` int(10) NOT NULL,
`entries` int(6) NOT NULL default '0' COMMENT 'via trigger in cache_list_items',
`watchers` int(6) NOT NULL default '0' COMMENT 'via trigger in cache_list_watches',
PRIMARY KEY (`cache_list_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
SELECT `id` `cache_list_id`, `entries`, `watchers` FROM `cache_lists`");
}
if (sql_field_exists('cache_lists','entries'))
sql("ALTER TABLE `cache_lists` DROP COLUMN `entries`");
if (sql_field_exists('cache_lists','watchers'))
sql("ALTER TABLE `cache_lists` DROP COLUMN `watchers`");
if (!sql_field_exists('cache_lists','description'))
sql("ALTER TABLE `cache_lists` ADD COLUMN `description` mediumtext NOT NULL");
if (!sql_field_exists('cache_lists','desc_htmledit'))
sql("ALTER TABLE `cache_lists` ADD COLUMN `desc_htmledit` tinyint(1) unsigned NOT NULL default '1'");

update_triggers(); // runs maintain-124.inc.php
}

function dbv_125() // update cache lists implementation; preparation of XML interface export
{
global $opt;

if (!sql_field_exists('cache_lists','node'))
{
sql("ALTER TABLE `cache_lists` ADD COLUMN `node` tinyint(3) unsigned NOT NULL default '0' AFTER `uuid`");
sql("UPDATE `cache_lists` SET `node`='&1'", $opt['logic']['node']['id']);
}
if (!sql_field_exists('cache_lists','last_state_change'))
sql("ALTER TABLE `cache_lists` ADD COLUMN `last_state_change` datetime default NULL AFTER `last_added`");

update_triggers(); // runs maintain-125.inc.php
}


// When adding new mutations, take care that they behave well if run multiple
// times. This improves robustness of database versioning.
Expand Down
2 changes: 1 addition & 1 deletion doc/license.txt
Expand Up @@ -184,7 +184,7 @@ Icons
License : Creative Commons BY-SA 3.0
Author : Oxygen

4. 16x16 Icons 'flag-checker', 'footprints', 'clock select', lock
4. 16x16 Icons 'flag-checker', 'footprints', 'clock select', lock, list
Path : htdocs/resource2/ocstyle/images/misc/
htdocs/resource2/ocstyle/images/map/caches2/
htdocs/resource2/ocstyle/images/cachestatus/
Expand Down
66 changes: 66 additions & 0 deletions htdocs/addtolist.php
@@ -0,0 +1,66 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* Unicode Reminder メモ
***************************************************************************/

require('./lib2/web.inc.php');
require_once('./lib2/logic/cachelist.class.php');
$tpl->name = 'addtolist';
$tpl->menuitem = MNU_CACHES_ADDTOLIST;

$login->verify();
if ($login->userid == 0)
$tpl->redirect_login();

$cacheid = isset($_REQUEST['cacheid']) ? $_REQUEST['cacheid'] + 0 : 0;
if (!$cacheid)
$tpl->redirect('index.php');
$tpl->assign('cacheid', $cacheid);

if (isset($_REQUEST['cancel']))
$tpl->redirect('viewcache.php?cacheid=' . $cacheid);

$newlist_name = isset($_REQUEST['newlist_name']) ? trim($_REQUEST['newlist_name']) : false;
$newlist_public = isset($_REQUEST['newlist_public']);
$newlist_watch = isset($_REQUEST['newlist_watch']);

if (isset($_REQUEST['save']) && isset($_REQUEST['listid']))
{
$listid = $_REQUEST['listid'] + 0;
if ($listid == 0)
{
$cachelist = new cachelist(ID_NEW, $login->userid);
if (!$cachelist->setName($newlist_name))
$tpl->assign('name_error', true);
else
{
$cachelist->setPublic($newlist_public);
if ($cachelist->save())
{
$cachelist->addCacheByID($cacheid);
if ($newlist_watch)
$cachelist->watch(true);
}
$tpl->redirect('viewcache.php?cacheid=' . $cacheid);
}
}
else
{
$cachelist = new cachelist($listid);
if ($cachelist->exist())
$cachelist->addCacheByID($cacheid);
$tpl->redirect('viewcache.php?cacheid=' . $cacheid);
}
}

$tpl->assign('cachename', sql_value("SELECT `name` FROM `caches` WHERE `cache_id`='&1'", '', $cacheid));
$tpl->assign('cachelists', cachelist::getMyLists());
$tpl->assign('default_list', cachelist::getMyLastAddedToListId());
$tpl->assign('newlist_name', $newlist_name);
$tpl->assign('newlist_public', $newlist_public);
$tpl->assign('newlist_watch', $newlist_watch);
$tpl->display();

?>
29 changes: 29 additions & 0 deletions htdocs/cachelist.php
@@ -0,0 +1,29 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* Unicode Reminder メモ
*
* Shortcut for cachelist search
***************************************************************************/

require('./lib2/web.inc.php');

$id = isset($_REQUEST['id']) ? $_REQUEST['id'] + 0 : 0;
$watch = isset($_REQUEST['watch']);
$dontwatch = isset($_REQUEST['dontwatch']);

if ($id)
{
if ($watch || $dontwatch)
{
$list = new cachelist($id);
if ($list->exist())
$list->watch($watch);
}
$tpl->redirect("search.php?searchto=searchbylist&listid=" . $id . "&showresult=1&f_disabled=0&f_inactive=0&f_ignored=1&sort=byname");
}
else
$tpl->redirect("cachelists.php");

?>
51 changes: 51 additions & 0 deletions htdocs/cachelists.php
@@ -0,0 +1,51 @@
<?php
/***************************************************************************
* For license information see doc/license.txt
*
* Unicode Reminder メモ
***************************************************************************/

require('./lib2/web.inc.php');
require_once('./lib2/logic/cachelist.class.php');
require_once('./lib2/pager.class.php');

$login->verify();

$tpl->name = 'cachelists';
$tpl->menuitem = MNU_CACHES_LISTS;

if (isset($_REQUEST['watchlist']))
{
$list = new cachelist($_REQUEST['watchlist'] + 0);
if ($list->exist())
$list->watch(true);
}
else if (isset($_REQUEST['dontwatchlist']))
{
$list = new cachelist($_REQUEST['dontwatchlist'] + 0);
if ($list->exist())
$list->watch(false);
}

$MAXITEMS = 30;
$startat = isset($_REQUEST['startat']) ? $_REQUEST['startat']+0 : 0;
$name_filter = isset($_REQUEST['name']) ? $_REQUEST['name'] : '';
$by_filter = isset($_REQUEST['by']) ? $_REQUEST['by'] : '';
$listcount = cachelist::getPublicListCount($name_filter, $by_filter);

$tpl->assign('name_filter', $name_filter);
$tpl->assign('by_filter', $by_filter);
$tpl->assign('cachelists', cachelist::getPublicLists($startat, $MAXITEMS, $name_filter, $by_filter));
$tpl->assign('show_status', false);
$tpl->assign('show_user', true);
// Do not show watchers because this would allow conclusions on what the list owner watches.
$tpl->assign('show_watchers', false);
$tpl->assign('show_edit', false);
$tpl->assign('togglewatch', 'cachelists.php');

$pager = new pager("cachelists.php?startat={offset}");
$pager->make_from_offset($startat, $listcount, $MAXITEMS);

$tpl->display();

?>
3 changes: 3 additions & 0 deletions htdocs/dbmaintain.php
Expand Up @@ -28,6 +28,7 @@
$procedures[] = 'sp_updateall_cache_listingdates';
$procedures[] = 'sp_updateall_cachelog_logdates';
$procedures[] = 'sp_updateall_rating_dates';
$procedures[] = 'sp_updateall_cachelist_counts';

$tpl->assign('procedures', $procedures);

Expand Down Expand Up @@ -61,6 +62,8 @@
sql("CALL sp_updateall_cachelog_logdates(@c)");
else if ($proc == 'sp_updateall_rating_dates')
sql("CALL sp_updateall_rating_dates(@c)");
else if ($proc == 'sp_updateall_cachelist_counts')
sql("CALL sp_updateall_cachelist_counts(@c)");
else
{
$bError = true;
Expand Down

0 comments on commit 5afc1f8

Please sign in to comment.