This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/contrib/blotter/theme.php

191 lines
5.6 KiB
PHP
Raw Normal View History

2010-02-18 14:12:52 +00:00
<?php
2010-02-16 00:37:00 +00:00
class BlotterTheme extends Themelet {
public function display_editor($entries) {
global $page;
$html = $this->get_html_for_blotter_editor($entries);
$page->set_title("Blotter Editor");
$page->set_heading("Blotter Editor");
2010-02-18 14:12:52 +00:00
$page->add_block(new Block("Welcome to the Blotter Editor!", $html, "main", 10));
$page->add_block(new Block("Navigation", "<a href='".make_link()."'>Index</a>", "left", 0));
2010-02-16 00:37:00 +00:00
}
2010-02-18 14:12:52 +00:00
2010-02-16 00:37:00 +00:00
public function display_blotter_page($entries) {
global $page;
$html = $this->get_html_for_blotter_page($entries);
$page->set_mode("data");
$page->set_data($html);
}
2010-02-18 14:12:52 +00:00
2010-02-16 00:37:00 +00:00
public function display_blotter($entries) {
global $page, $config;
$html = $this->get_html_for_blotter($entries);
$position = $config->get_string("blotter_position", "subheading");
$page->add_block(new Block(null, $html, $position, 20));
}
2010-02-18 14:12:52 +00:00
2010-02-16 00:37:00 +00:00
private function is_odd($number) {
2010-02-18 14:12:52 +00:00
return $number & 1; // 0 = even, 1 = odd
2010-02-16 00:37:00 +00:00
}
2010-02-18 14:12:52 +00:00
2010-02-16 00:37:00 +00:00
private function get_html_for_blotter_editor($entries) {
2010-05-28 13:26:46 +00:00
global $user;
2010-02-16 00:37:00 +00:00
/**
* Long function name, but at least I won't confuse it with something else ^_^
*/
$html = "";
2010-02-18 14:12:52 +00:00
// Add_new stuff goes here.
$table_header = "
<tr>
<th>Date</th>
<th>Message</th>
<th>Important?</th>
<th>Action</th>
</tr>";
$add_new = "
<tr class='even'>
<form action='".make_link("blotter/add")."' method='POST'>
2010-05-28 13:26:46 +00:00
".$user->get_auth_html()."
2010-02-18 14:12:52 +00:00
<td colspan='2'><textarea style='text-align:left;' name='entry_text' rows='2' /></textarea></td>
<td><input type='checkbox' name='important' /></td>
<td><input type='submit' value='Add'></td>
</form>
</tr>";
2010-02-16 00:37:00 +00:00
// Now, time for entries list.
$table_rows = "";
2010-02-18 14:12:52 +00:00
for ($i = 0 ; $i < count($entries) ; $i++)
{
/**
* Add table rows
*/
2010-02-16 00:37:00 +00:00
$id = $entries[$i]['id'];
$entry_date = $entries[$i]['entry_date'];
$entry_text = $entries[$i]['entry_text'];
if($entries[$i]['important'] == 'Y') { $important = 'Y'; } else { $important = 'N'; }
if(!$this->is_odd($i)) {$tr_class = "odd";}
if($this->is_odd($i)) {$tr_class = "even";}
// Add the new table row(s)
$table_rows .=
2010-02-18 14:23:56 +00:00
"<tr class='{$tr_class}'>
2010-02-18 14:12:52 +00:00
<td>$entry_date</td>
<td>$entry_text</td>
<td>$important</td>
<td><form name='remove$id' method='post' action='".make_link("blotter/remove")."'>
2010-05-28 13:26:46 +00:00
".$user->get_auth_html()."
2010-02-18 14:12:52 +00:00
<input type='hidden' name='id' value='$id' />
<input type='submit' style='width: 100%;' value='Remove' />
</form>
</td>
2010-02-16 00:37:00 +00:00
</tr>";
}
$html = "
<table id='blotter_entries' class='zebra'>
2010-02-18 14:12:52 +00:00
<thead>$table_header</thead>
<tbody>$add_new</tbody>
<tfoot>$table_rows</tfoot>
2010-02-16 00:37:00 +00:00
</table>
<br />
<b>Help:</b><br />
<blockquote>Add entries to the blotter, and they will be displayed.</blockquote>";
2010-02-18 14:12:52 +00:00
2010-02-16 00:37:00 +00:00
return $html;
}
2010-02-18 14:12:52 +00:00
2010-02-16 00:37:00 +00:00
private function get_html_for_blotter_page($entries) {
/**
* This one displays a list of all blotter entries.
*/
global $config;
$i_color = $config->get_string("blotter_color","#FF0000");
$html = "";
$html .= "<html><head><title>Blotter</title></head>
2010-02-18 14:12:52 +00:00
<body><pre>";
2010-02-16 00:37:00 +00:00
2010-02-18 14:12:52 +00:00
for ($i = 0 ; $i < count($entries) ; $i++)
{
/**
* Blotter entries
*/
// Reset variables:
2010-02-16 00:37:00 +00:00
$i_open = "";
$i_close = "";
$id = $entries[$i]['id'];
$messy_date = $entries[$i]['entry_date'];
$clean_date = date("m/d/y",strtotime($messy_date));
$entry_text = $entries[$i]['entry_text'];
if($entries[$i]['important'] == 'Y') { $i_open = "<font color='#{$i_color}'>"; $i_close="</font>"; }
$html .= "{$i_open}{$clean_date} - {$entry_text}{$i_close}<br /><br />";
}
$html .= "</pre></body></html>";
return $html;
}
2010-02-18 14:12:52 +00:00
2010-02-16 00:37:00 +00:00
private function get_html_for_blotter($entries) {
/**
* Show the blotter widget
* Although I am starting to learn PHP, I got no idea how to do javascript... to the tutorials!
*/
global $config;
$i_color = $config->get_string("blotter_color","#FF0000");
$position = $config->get_string("blotter_position", "subheading");
$html = "<style type='text/css'>
2010-02-18 14:12:52 +00:00
#blotter1 {font-size: 80%; position: relative;}
#blotter2 {font-size: 80%;}
</style>";
2010-02-16 00:37:00 +00:00
$html .= "<script><!--
2010-02-18 14:12:52 +00:00
$(document).ready(function() {
$(\"#blotter2-toggle\").click(function() {
$(\"#blotter2\").slideToggle(\"slow\", function() {
if($(\"#blotter2\").is(\":hidden\")) {
$.cookie(\"blotter2-hidden\", 'true', {path: '/'});
}
else {
$.cookie(\"blotter2-hidden\", 'false', {path: '/'});
}
});
});
if($.cookie(\"blotter2-hidden\") == 'true') {
$(\"#blotter2\").hide();
}
});
//--></script>";
2010-02-16 00:37:00 +00:00
$entries_list = "";
2010-02-18 14:12:52 +00:00
for ($i = 0 ; $i < count($entries) ; $i++)
{
/**
* Blotter entries
*/
// Reset variables:
2010-02-16 00:37:00 +00:00
$i_open = "";
$i_close = "";
$id = $entries[$i]['id'];
$messy_date = $entries[$i]['entry_date'];
$clean_date = date("m/d/y",strtotime($messy_date));
$entry_text = $entries[$i]['entry_text'];
if($entries[$i]['important'] == 'Y') { $i_open = "<font color='#{$i_color}'>"; $i_close="</font>"; }
$entries_list .= "<li>{$i_open}{$clean_date} - {$entry_text}{$i_close}</li>";
}
$out_text = "";
$in_text = "";
$pos_break = "";
$pos_align = "text-align: right; position: absolute; right: 0px;";
if($position == "left") { $pos_break = "<br />"; $pos_align = ""; }
2010-02-18 14:12:52 +00:00
if(count($entries) == 0) { $out_text = "No blotter entries yet."; $in_text = "Empty.";}
2010-02-16 00:37:00 +00:00
else { $clean_date = date("m/d/y",strtotime($entries[0]['entry_date']));
2010-02-18 14:12:52 +00:00
$out_text = "Blotter updated: {$clean_date}";
$in_text = "<ul>$entries_list</ul>";
2010-02-16 00:37:00 +00:00
}
$html .= "<div id='blotter1'><span>$out_text</span>{$pos_break}<span style='{$pos_align}'><a href='#' id='blotter2-toggle'>Show/Hide</a> <a href='".make_link("blotter")."'>Show All</a></span></div>";
$html .= "<div id='blotter2'>$in_text</div>";
return $html;
}
}
2010-02-18 14:12:52 +00:00
?>