#include <infocon.style>
#include <phptools.inc>
#include "account.inc"

<?php
function filter_account()
{
    if ((strlen($_POST['currency']) > 0) && ($_POST['currency'] == "dm")) {
	$account = new AccountingDM();
    } else {
	$account = new Accounting();
    }

    return $account->filterTable($_POST);
}

if (!empty($_POST['ajax']) && $_POST['ajax'] == 1) {
    echo utf8_encode(filter_account());
    exit;
}

?>

<page func=InfoCon title="Kontoführung">

<calendar_init -5>
<account_heading>

<style type="text/css">
div#filter_popup {
    background: white;
    border: 1px solid #CCC;
    height:auto;
    width:340px;
    position:absolute;
}
div#filter_title {
    width: 100%;
    cursor: move;
    background: #EEE;
    margin-bottom: 5px;
    font-weight: bold;
}
</style>
<table class="border smallfont yellow-hover" width=100% border=0 cellpadding=0 cellspacing=1>
<thead>
<tr class=head>
  <th width=10%>Datum</th>
  <th width=10%>Kategorie</th>
  <th width=70%>Verwendungszweck</th>
  <th width=10%>Betrag</th>
</tr>
</thead>
<tbody>
<?=(count($_GET)?'':filter_account())?>
</tbody>
</table><p>

<protect><script type="text/javascript">
$(function(){
    $('table.border tr').not('.head').click(function(){
	$(this).toggleClass('highlight');
	if ($(this).hasClass('highlight'))
	    $(this).css('backgroundColor','#add8e6');
	else
	    $(this).css('backgroundColor','');
    });
    $('body').append('<script type="text/javascript" src="../../jquery.udraggable.js"><\/script>');
    $('body').append('<script type="text/javascript" src="../../jquery.event.ue.js"><\/script>');
    $('body').append('<script type="text/javascript" src="../../jquery.editable.js"><\/script>');
});

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/geral/utf-8 [rev. #1]

UTF8 = {
        encode: function(s){
                for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
                        s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
                );
                return s.join("");
        },
        decode: function(s){
                for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
                        ((a = s[i][c](0)) & 0x80) &&
                        (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
                        o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
                );
                return s.join("");
        }
};

function filter_popup()
{
    if (!$('#filter_popup form input').length) {
	$.get('query.php',
	      window.location.search.substr(1)+'&ajax=1',
	      function(data) {
		  var text = '<style type="text/css">';
		  text += '#fc { z-index: 10; }';
		  $(data).find('style').each(function(i,e){
		      text += $(this).html();
		  });
		  text += '</style>';
		  text += $(data).find('form').html();
		  $('#filter_popup form').html(text);

		  $('#filter_popup').udraggable({
		      'handle': 'div#filter_title'
		  }).css('top', '70px').css('left', '103px');

		  $('#filter_popup form input,#filter_popup form select').not('input.button').change(function(e){
		      $.invoke('Accounting/Filter',
			       $('#filter_popup form').serialize(),
			     function(data){
				 $('table.border tbody').html(data.table);
				 make_editable('table.smallfont tr span');
			     });
		      return false;
		  });

		  $('#filter_popup form input.button[type="submit"]').click(function(e){
		      $.invoke('Accounting/Filter',
			       $('#filter_popup form').serialize(),
			     function(data){
				 $('table.border tbody').html(data.table);
				 $('#filter_popup').hide();
				 make_editable('table.smallfont tr span');
			     });
		      return false;
		  });
	  });
    }

    if ($('#filter_popup:visible').length)
        $('#filter_popup').hide();
    else
        $('#filter_popup').show();

    return false;
}

</script></protect>
<div id="filter_popup" style="display:none;">
<div id="filter_title">Filter setzen</div>
<div style="padding:5px;">
<form id="filter_form"></form>
</div>
</div>
</page>

# Local variables:
# mode: text
# mode: auto-fill
# end:
