+++ /dev/null
-<?php
-
-class AJAXBackend extends AJAXBackendBase {
- public function salesText()
- {
- $sales = new Sales($_POST['id']);
- $sales->setDescription($_POST['text']);
- }
-}
-
+++ /dev/null
-<?php
-
-class AJAXBackendBase {
- protected $db;
- protected $relativeRootPath;
-
- public function __construct()
- {
- global $db;
- $this->db = $db;
-
- $path = substr($_SERVER['HTTP_REFERER'], strpos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME'])+strlen($_SERVER['SERVER_NAME'])+1);
-
- $pos = 0;
- $this->relativeRootPath = '';
- while (($pos = strpos($path, '/', $pos)) !== false) {
- $this->relativeRootPath .= '../';
- $pos++;
- }
- }
-
- public function relativeRootPath()
- {
- return $this->relativeRootPath;
- }
-
-}
return $this->modify('paid', 0);
}
- public function setDescription($text)
+ public function ajaxText(Array $data)
{
- return $this->modify('description', $text);
+ return $this->modify('description', $data['text']);
}
}
-?>
public function distinctYears()
{
- $sql = "SELECT DISTINCT EXTRACT(YEAR from date) AS year FROM sprit_log ORDER BY year DESC";
+ $sql = "SELECT EXTRACT(YEAR from date) AS year,sum(price) AS sum,sum(km) AS km FROM sprit_log GROUP BY year ORDER BY year DESC";
return $this->db->fetchObjectList($sql);
}
}
if (strlen($out)) {
- $out = '<table class="smallfont" width="100%">' .
+ $out = '<table class="smallfont spritlog" width="100%">' .
'<thead><tr>' .
'<th width="70">Datum</th><th width="130" class="left">Ort</th><th class="left">Tankstelle</th>' .
'<th width="40">EUR/l</th><th width="40">l</th><th width="40">EUR</th><th width="40">km</th><th width="40">gesamt</th>' .
'</tr></thead>' .
- $out .
+ '<tbody>' . $out . '</tbody>' .
'<tfoot><tr>' .
'<th colspan="4" class="left">Summe</th>' .
sprintf('<th class="right">%.2f</th><th class="right">%.2f</th><th class="right">%d</th><th> </th>',
return $out;
}
-}
+ public function ajaxList(Array $data)
+ {
+ return array('html' => array('list_'.$data['year'] => $this->formatYear($data['year'])));
+ }
+
+ public function ajaxAdd(Array $data)
+ {
+ $data = array('machine' => intval($data['machine']),
+ 'date' => assert_iso_date($data['date']),
+ 'city' => $data['city'],
+ 'tankstelle' => $data['tankstelle'],
+ 'price_liter' => str_replace(',','.',$data['price_liter']),
+ 'liter' => str_replace(',','.',$data['liter']),
+ 'price' => str_replace(',','.',$data['price']),
+ 'km' => intval($data['km']),
+ 'km_total' => intval($data['km_total']),
+ 'sys_edit' => 'now()',
+ 'sys_user' => $_SERVER['REMOTE_USER']);
+
+ foreach ($data as $k => $v)
+ if (empty($v))
+ return ajax_error(sprintf('Field %s must not be empty', $k));
+ if (empty($data['id'])) {
+ $ok = $this->db->insertInto('sprit_log', $data);
+ } else {
+ $ok = $this->db->update('sprit_log', $data, 'id = ' . intval($data['id']));
+ }
+
+ $d = explode('-', $data['date']);
+ return array('status' => $ok, 'year' => $d[0]);
+
+ }
+}
--- /dev/null
+<?php
+
+class SpritMachine extends DatabaseTable {
+
+ public function __construct($id=false)
+ {
+ parent::__construct('sprit_machine', $id);
+ }
+
+ public function ajaxList(Array $data)
+ {
+ $out = '';
+ $sql = "SELECT id,name FROM sprit_machine WHERE active = 1 ORDER BY name";
+ foreach ($this->fetchObjectList($sql) as $row) {
+ $out .= sprintf('<li>%s ', $row->name);
+ $out .= '<form action="list.php" method="POST" style="display:inline;">';
+ $out .= sprintf('<input type="hidden" name="machine" value="%d">', $row->id);
+ $out .= sprintf('<img src="%spix/arrowrightmonth.gif" onclick="machine_list(this);" style="margin-bottom:-4px;" title="Liste zeigen">',
+ $this->rootPath);
+ $out .= '</form>';
+ $out .= '</li>';
+ }
+
+ return array('html' => array('machines' => $out));
+ }
+
+ public function ajaxSave(Array $data)
+ {
+ if ($this->id) {
+ $sql = sprintf("UPDATE sprit_machine SET name=%s,sys_edit=now(),sys_user=%s WHERE id = %d",
+ $this->quote(utf8_decode($data['name'])),
+ $this->quote($_SERVER['REMOTE_USER']),
+ $this->id);
+ } else {
+ $sql = sprintf("INSERT INTO sprit_machine (name,active,sys_user,sys_edit) " .
+ "VALUES (%s,1,%s,now())",
+ $this->quote(utf8_decode($data['name'])),
+ $this->quote($_SERVER['REMOTE_USER']));
+ }
+
+ return $this->execute($sql);
+ }
+
+}
+
function load_machines()
{
- ajax_request('machines', null,
- function(data){
- $('#machines').html(data.list);
- });
+ $.invoke('SpritMachine/List');
}
function machine_new()
function machine_new_save()
{
- ajax_request('savemachine', $('#details input').serialize(),
- function(data){
- load_machines();
- $('#details').hide();
- });
+ $.invoke('SpritMachine/Save', $('#details input').serialize(), function(data){
+ load_machines();
+ $('#details').hide();
+ });
+
return false;
}
div#details {
width: 270px;
}
+div.bar {
+ background-color: #98c5e5;
+ border-bottom: 1px solid #AAA;
+ font-size: 14px;
+ font-weight: bold;
+}
+div.year {
+ float: left;
+}
+table.spritlog tbody td {
+ border-bottom: 1px solid #CCC;
+}
+table.spritlog thead th {
+ border-bottom: 1px solid #AAA;
+}
+table.spritlog tfoot th {
+ border-top: 1px solid #AAA;
+}
+table.spritlog tbody tr:hover {
+ background-color: yellow;
+}
</style>
<div id="details" class="popup" style="margin-top: 5px;display:none;">
<input type="submit" onclick="$('#details').hide();return false" value="Abbrechen">
</div>
-</div>
+ </div>
</div>
<?php
$log = new SpritLog();
$list = $log->distinctYears();
foreach ($list as $row) {
- printf('<h3 year="%d" class="bar year">%d</h3>', $row->year, $row->year);
- printf('<div id="list_%d"></div>', $row->year);
+ echo '<div class="bar">';
+ printf('<div year="%d" class="year">%d</div>', $row->year, $row->year);
+ printf('<div style="float:right;">€ %.2f %d km</div>', $row->sum, $row->km);
+ echo '<div style="clear:both;"></div></div>';
+ printf('<div id="list_%d" style="display:none;"></div>', $row->year);
}
if (count($list)) {
$out = <<<EOT
<script type="text/javascript">
$(function(){
load_year({$list[0]->year});
- $('h3.year').click(function(e){
- var year = \$(this).attr('year');
- load_year(year);
- });
+ $('div.bar').click(toggle_year);
});
</script>
EOT;
echo $out;
}
?>
-
+<div style="height:10px;"></div>
</page>
<protect><script text="text/javascript">
var sprit_machine = <?=intval($_POST['machine'])?>;
function log_save()
{
- ajax_request('savelog', $('#details input').serialize(),
- function(data){
- load_year(data.year);
- $('#details').hide();
- });
+ $.invoke('SpritLog/Add', $('#details input').serialize(), function(data){
+ load_year(data.year);
+ $('#details').hide();
+ });
+
return false;
}
+function toggle_year(event)
+{
+ var year = $(this).find('div.year').attr('year');
+
+ if ($('div#list_'+year).is(':visible'))
+ $('div#list_'+year).hide();
+ else
+ load_year(year);
+}
+
function load_year(year)
{
- ajax_request('loadyear', {year: year},
- function(data){
- var div = $('div#list_'+data.year);
- if (div.length)
- div.html(data.list);
- else
- window.location.reload();
- });
+ $('div#list_'+year).show();
+ $.invoke('SpritLog/List', {year: year});
}
</script></protect>
+++ /dev/null
-<?php
-
-class ModuleAJAXBackend extends AJAXBackendBase {
-
- public function ajax_machines()
- {
- $out = '';
- $sql = "SELECT id,name FROM sprit_machine WHERE active = 1 ORDER BY name";
- foreach ($this->db->fetchObjectList($sql) as $row) {
- $out .= sprintf('<li>%s ', $row->name);
- $out .= '<form action="list.php" method="POST" style="display:inline;">';
- $out .= sprintf('<input type="hidden" name="machine" value="%d">', $row->id);
- $out .= sprintf('<img src="%spix/arrowrightmonth.gif" onclick="machine_list(this);" style="margin-bottom:-4px;" title="Liste zeigen">',
- $this->relativeRootPath());;
- $out .= '</form>';
- $out .= '</li>';
- }
- return array('status' => true, 'list' => $out);;
- }
-
- public function ajax_savemachine()
- {
- if (empty($_POST['id'])) {
- $sql = sprintf("INSERT INTO sprit_machine (name,active,sys_user,sys_edit) " .
- "VALUES (%s,1,%s,now())",
- $this->db->quote(utf8_decode($_POST['name'])),
- $this->db->quote($_SERVER['REMOTE_USER']));
- } else {
- $sql = sprintf("UPDATE sprit_machine SET name=%s,sys_edit=now(),sys_user=%s WHERE id = %d",
- $this->db->quote(utf8_decode($_POST['name'])),
- $this->db->quote($_SERVER['REMOTE_USER']),
- $_POST['id']);
- }
- return array('status' => $this->db->execute($sql));
- }
-
- public function ajax_savelog()
- {
- $data = array('machine' => intval($_POST['machine']),
- 'date' => assert_iso_date($_POST['date']),
- 'city' => $_POST['city'],
- 'tankstelle' => $_POST['tankstelle'],
- 'price_liter' => str_replace(',','.',$_POST['price_liter']),
- 'liter' => str_replace(',','.',$_POST['liter']),
- 'price' => str_replace(',','.',$_POST['price']),
- 'km' => intval($_POST['km']),
- 'km_total' => intval($_POST['km_total']),
- 'sys_edit' => 'now()',
- 'sys_user' => $_SERVER['REMOTE_USER']);
-
- foreach ($data as $k => $v)
- if (empty($v))
- json_error(sprintf('Field %s must not be empty', $k));
-
- if (empty($_POST['id'])) {
- $ok = $this->db->insertInto('sprit_log', $data);
- } else {
- $ok = $this->db->update('sprit_log', $data, 'id = ' . intval($_POST['id']));
- }
-
- $d = explode('-', $data['date']);
- return array('status' => $ok, 'year' => $d[0]);
- }
-
- public function ajax_loadyear()
- {
- $log = new SpritLog();
- return array('status' => true,
- 'list' => $log->formatYear($_POST['year']),
- 'year' => $_POST['year']);
- }
-
-}
task_oid = obj.parentNode.children[0].children[0].value;
var input = $('<input>');
-<protect>
input.val(obj.innerHTML.replace('>', '>').replace('<', '<').replace('&', '&'));
-</protect>
input.css('fontSize', '100%').css('width', '100%').css('background', 'yellow');
obj.innerHTML = '';
$(obj).append(input);
if (!task_parent) return;
if (task_parent.children[0].value != task_title)
- ajax_request('save','oid='+task_oid+'&task='+encodeURIComponent(task_parent.children[0].value));
+ $.invoke('Sales/Text', {id: task_oid, text: task_parent.children[0].value});
task_parent.innerHTML = task_parent.children[0].value;
task_parent = null;