<?php
/* SVN FILE: $Id$ */
/**
 * Pluginクラス
 *
 * PHP versions 5
 *
 *      hitSuji : Social Network Service <http://rakuto.net/rktSNS/>
 *      Copyright (c) 2007 Yujiro Takahashi
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @category        hitSuji
 * @package         hitSuji
 * @copyright       Copyright (c) 2007 Yujiro Takahashi
 * @link            http://rakuto.net/
 * @author          Yujiro Takahashi <yujiro@rakuto.net>
 * @version         $Revision$
 * @modifiedby      $LastChangedBy$
 * @lastmodified    $Date$
 * @license         http://opensource.org/licenses/mit-license.php The MIT License
 */

$page = 0;
$ref_account = RKT_account::exec()->getAccountID();
$condition = array(
    'ref_account' => $ref_account
);
$max  = RKT_DB::getRow('sum_poll', $condition, 'count(*) as ct');
if (!empty($max['ct'])){
    $page = ceil($max['ct'] / LIMIT_ROWS);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="content-type" content='text/html; charset="utf-8"' />
<link rel="stylesheet" href="<?php e(BASE_URL); ?>resource/css/common.css" type="text/css" />
<script type="text/javascript" src="<?php e(BASE_URL); ?>resource/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="<?php e(BASE_URL); ?>resource/yui/json/json-min.js"></script>
<script type="text/javascript" src="<?php e(BASE_URL); ?>resource/yui/container/container-min.js"></script>
<script type="text/javascript" src="<?php e(BASE_URL); ?>resource/yui/connection/connection-min.js"></script>
<script type="text/javascript" src="<?php e(BASE_URL); ?>resource/js/feed.js"></script>
<style type="text/css">
<!--
BODY	{
    margin: 0;
    padding: 0;
}
A {
	text-decoration:none;
}
-->
</style>
<script language="javascript" type="text/javascript">

var insertPoll = function(e, obj) {
	var node = YAHOO.util.Event.getTarget(e);
	var id   = node.getAttribute('id');
	var body = '<img id="'+ id +'" src="<?php echo BASE_URL; ?>resource/img/common/blankpoll.gif">';

	parent.myEditor.execCommand('inserthtml', body);
	parent.YAHOO.util.Dom.setStyle('insertPoll', "visibility", "hidden");
};

var viewPolls = function() {
	this.fOffset = 1;
	this.fPage = YAHOO.util.Dom.get('viewPollsPage');
	this.nextPolls = function (){
		this.fOffset += 1;
		if (this.fOffset > <?php e($page); ?>){
			this.fOffset = 1;
		}
		this.setPolls();
		this.fPage.innerHTML = this.fOffset + '/' + <?php e($page); ?>;
	}
	this.prevPolls = function (){
		this.fOffset -= 1;
		if (this.fOffset <= 0){
			this.fOffset = <?php e($page); ?>;
		}
		this.setPolls();
		this.fPage.innerHTML = this.fOffset + '/' + <?php e($page); ?>;
	}
	this.setPolls = function (){
		var callback =
		{
			success: function(o) {
				var Polls = YAHOO.lang.JSON.parse (o.responseText);

				var ul  = YAHOO.util.Dom.get('pollList');
				var li  = null;
				var anc = null;
				var img = null;
				var br  = null;

				while (ul.lastChild){
					ul.removeChild(ul.lastChild); 
				}

				for (row=0; row<Polls.length; row++){
					li  = document.createElement('li');
					img = document.createElement('img');

					img.src = '<?php e(BASE_URL); ?>resource/img/icons/chart_pie.gif';
					img.setAttribute('align', 'absmiddle');
					img.style.marginLeft  = '4px';
					img.style.marginRight = '4px';

					li.appendChild(img);
					li.appendChild(document.createTextNode(Polls[row].title));
					YAHOO.util.Event.addListener(li, 'click', insertPoll);

					li.setAttribute('class', 'cHand');
					li.setAttribute('className', 'cHand');
					li.setAttribute('id', Polls[row].id);

					ul.appendChild(li);
				}
			},
			failure: function(o) {
			},
			argument: []
		}
		YAHOO.util.Connect.initHeader('Cookie', document.cookie);
		YAHOO.util.Connect.asyncRequest('GET',  '<?php e(HTTP_ACTION); ?>member/poll/list/<?php e($ref_account); ?>/json/<?php e(US); ?>page=' + this.fOffset, callback);
	}
}

YAHOO.util.Event.onContentReady("pollList", function () {
	myViewPolls = new viewPolls();
	myViewPolls.setPolls();
});
</script>
</head>
<body>
		<ul class="horizontal" style="background-color:blue;">
			<li style="width:50px; text-align:center;"><a href="javascript:myViewPolls.prevPolls();"><img src="<?php e(BASE_URL); ?>resource/img/icons/resultset_previous.gif" width="16" height="16" alt="<<" align="top" /></a></li>
			<li id="viewPollsPage" style="width:80px; text-align:center;"><?php e(1 .'/'. $page); ?></li>
			<li style="width:50px; text-align:center;"><a href="javascript:myViewPolls.nextPolls();"><img src="<?php e(BASE_URL); ?>resource/img/icons/resultset_next.gif" width="16" height="16" alt=">>" align="top" /></a></li>
		</ul><br />
		<ul id="pollList"></ul>
</body>
<html>

