<?php

class opiboardapp extends plugin
{



	/*--- Základné meta informácie o aplikácií ---*/

	protected function load ()
	{
		$this -> title = 'OpiBoard&trade;';
		$this -> version = '1.0';
		$this -> author = 'Tomáš Tatarko';
		$this -> url = 'http://tatarko.info/';
		$this -> description = 'Interná komunikácia medzi redaktormi na Vašej stránke.';
		$this -> modes = array ('application', 'widget');
		$this -> cache = false;
		$this -> redactors = true;
		$this -> values = array ();
		$this -> tables = array (
			'posts' => '`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `author` bigint(20) unsigned NULL DEFAULT 0, `message` text NOT NULL, `time` int(11) unsigned NULL DEFAULT 0, PRIMARY KEY (`id`)',
		);
	}



	/*--- Widget profil pre odoslanie správy ---*/

	protected function widget ()
	{
		$return = '';
		global $_CONFIG, $prefix, $translate;
		$sql = $this -> query ("SELECT * FROM `{prefix}posts` ORDER BY `time` DESC LIMIT 2");
		while ($row = mysql_fetch_assoc ($sql))
		{
			list ($author) = $row['author'] == 0 ? array ($_CONFIG['author']) : @mysql_fetch_row (@mysql_query ("SELECT `name` FROM `{$prefix}_moderators` WHERE `id` = {$row['author']} LIMIT 1")); 
			$return .= '<div class="cofrNew">
 <p>' . $row['message'] . '</p>
 <div class="added">' . $author . ', ' . date ('d.m @H:i', $row['time']) . '</div>
</div>' . "\n";
		}
		if (mysql_num_rows ($sql) == 0) $return .= '<p>' . $translate['nocontent'] . '</p>' . "\n";
		$return .= '<form action="admin.php?app=' . $this -> apphash . '" method="post">
 <input type="text" name="message" />
 <input type="submit" value="' . $translate['add'] . '" />
</form>' . "\n";
		return $return;
	}



	/*--- Modul pre režím plnej aplikácie ---*/

	protected function application ()
	{
		$return = '';
		global $_CONFIG, $prefix, $translate;
		if (isset ($_POST['message']))
		{
			if ($this -> query ("INSERT INTO `{prefix}posts` VALUES (0, " . USER . ", '" . adjust ($_POST['message']) . "', UNIX_TIMESTAMP());"))
			$return .= getIcon ('info', $translate['successadd']);
			else $return .= getIcon ('error', $translate['failureadd']);
		}
		$return .= '<form action="' . _SiteForm . '" method="post">
 <input type="text" name="message" />
 <input type="submit" value="' . $translate['add'] . '" />
</form>' . "\n";
		$sql = $this -> query ("SELECT * FROM `{prefix}posts` ORDER BY `time` DESC");
		while ($row = mysql_fetch_assoc ($sql))
		{
			list ($author) = $row['author'] == 0 ? array ($_CONFIG['author']) : @mysql_fetch_row (@mysql_query ("SELECT `name` FROM `{$prefix}_moderators` WHERE `id` = {$row['author']} LIMIT 1")); 
			$return .= '<div class="cofrNew">
 <p>' . $row['message'] . '</p>
 <div class="added">Pridal ' . $author . ' dňa ' . date ('d.m.Y @H:i', $row['time']) . '</div>
</div>' . "\n";
		}
		if (mysql_num_rows ($sql) == 0) $return .= '<p>' . $translate['nocontent'] . '</p>' . "\n";
		return $return;
	}
};

?>