improve exploding
[infodrom.org/service.infodrom.org] / src / InfoCon / account / list.wml
1 #include <infocon.style>
2 #include <phptools.inc>
3 #include "account.inc"
4
5 <?php
6 function filter_account()
7 {
8   global $db;
9   $out = '';
10   $table = "account";
11   $value = "value_eur";
12   $add = '';
13   if ((strlen($_POST['currency']) > 0) && ($_POST['currency'] == "dm")) {
14     $table = "account_dm";
15     $value = "value_dm";
16     $add = "&cur=dm";
17   }
18
19   $where[] = sprintf("blz_kto = '%s'", $_POST['blzkto']);
20   if (strlen($_POST['year'])) {
21     $where[] = sprintf ("datum >= '%04d-01-01'", $_POST['year']);
22     $year++;
23     $where[] = sprintf ("datum < '%04d-01-01'", $_POST['year']+1);
24   }
25
26   if (strlen($_POST['deadline']) && strlen(trim($_POST['deadline']))) {
27     $date = form_to_yyyymmdd ($_POST['deadline']);
28     $where[] = sprintf ("datum < '%s'", $date);
29   }
30
31   if (strlen($_POST['statement']) && strlen(trim($_POST['statement']))) {
32     $where[] = sprintf("statement = '%s'", $_POST['statement']);
33   }
34
35   if (strlen($_POST['category']) && strlen(trim($_POST['category']))) {
36     if (!empty($_POST['ajax'])) $_POST['category'] = utf8_decode($_POST['category']);
37     $where[] = sprintf("category = '%s'", $_POST['category']);
38   }
39
40   if (strlen($_POST['keyword']) && strlen(trim($_POST['keyword']))) {
41     if (!empty($_POST['ajax'])) $_POST['keyword'] = utf8_decode($_POST['keyword']);
42     $where[] = sprintf("descr ~* '%s'", $_POST['keyword']);
43   }
44
45   if (strlen($_POST['from_to']) && strlen(trim($_POST['from_to']))) {
46     if (!empty($_POST['ajax'])) $_POST['from_to'] = utf8_decode($_POST['from_to']);
47     $where[] = sprintf("from_to = '%s'", $_POST['from_to']);
48   }
49
50   if ($_POST['input'] && !$_POST['output']) {
51     $where[] = "$value > 0.0";
52   } elseif ($_POST['output'] && !$_POST['input']) {
53     $where[] = "$value < 0.0";
54   }
55
56   $query = "SELECT datum,id,category,descr,$value FROM $table WHERE "
57          . implode ($where, " AND ")
58          . " ORDER BY datum,id";
59
60   $sum = 0.0;
61   $sum_in = 0.0;
62   $sum_out = 0.0;
63   $color = 0;
64   foreach ($db->fetchAssocList($query) as $row) {
65     $descr = explode ("\n", $row['descr']);
66     $date = explode (" ", $row['datum']);
67     $date = explode ("-", $date[0]);
68     $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
69
70     $out .= sprintf ("<tr class=\"t%d\">", $color);
71     $out .= sprintf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
72     $out .= sprintf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
73     $out .= sprintf ("<td width=\"70%%\"><a href=\"edit.php?id=%d%s\">%s</a></td>",
74             $row['id'], $add, $descr[0]);
75     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\">%5.2f</td>",
76       $row[$value]>0?"in":"out", $row[$value]);
77     $sum += $row[$value];
78     if ($row[$value] > 0) {
79       $sum_in += $row[$value];
80     } else {
81       $sum_out += $row[$value];
82     }
83     $out .= "</tr>";
84     $color = !$color;
85   }
86   if (strlen($_POST['statement'])) {
87     $out .= sprintf ("<tr class=\"t%d\">", $color);
88     $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Einnahmen</strong></td>";
89     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"in\">%5.2f</td>",$sum_in);
90     $out .= "</tr>";
91     $out .= sprintf ("<tr class=\"t%d\">", $color);
92     $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Ausgaben</strong></td>";
93     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"out\">%5.2f</td>", $sum_out*-1);
94     $out .= "</tr>";
95   }
96   $out .= sprintf ("<tr class=\"t%d\">", $color);
97   $out .= "<td width=\"90%\" colspan=\"3\" align=\"left\"><strong>Summe</strong></td>";
98   $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\"><strong>%5.2f</strong></td>",
99     $sum>0?"in":"out", $sum);
100   $out .= "</tr>";
101
102   return $out;
103 }
104
105 if (!empty($_POST['ajax']) && $_POST['ajax'] == 1) {
106     echo utf8_encode(filter_account());
107     exit;
108 }
109
110 ?>
111
112 <page func=InfoCon title="Kontoführung">
113
114 <calendar_init -5>
115 <account_heading>
116 <form_to_yyyymmdd>
117
118 <style type="text/css">
119 div#filter_popup {
120     background: white;
121     border: 1px solid #CCC;
122     height:auto;
123     width:340px;
124     position:absolute;
125 }
126 div#filter_title {
127     width: 100%;
128     cursor: move;
129     background: #EEE;
130     margin-bottom: 5px;
131     font-weight: bold;
132 }
133 </style>
134 <table class="border smallfont" width=100% border=0 cellpadding=0 cellspacing=1>
135 <thead>
136 <tr class=head>
137   <th width=10%>Datum</th>
138   <th width=10%>Kategorie</th>
139   <th width=70%>Verwendungszweck</th>
140   <th width=10%>Betrag</th>
141 </tr>
142 </thead>
143 <tbody>
144 <?=(count($_GET)?'':filter_account())?>
145 </tbody>
146 </table><p>
147
148 <protect><script type="text/javascript">
149 $(function(){
150     $('table.border tr').not('.head').click(function(){
151         $(this).toggleClass('highlight');
152         if ($(this).hasClass('highlight'))
153             $(this).css('backgroundColor','#add8e6');
154         else
155             $(this).css('backgroundColor','');
156     });
157     $('body').append('<script type="text/javascript" src="../../jquery.udraggable.js"><\/script>');
158     $('body').append('<script type="text/javascript" src="../../jquery.event.ue.js"><\/script>');
159 });
160
161 //+ Jonas Raoni Soares Silva
162 //@ http://jsfromhell.com/geral/utf-8 [rev. #1]
163
164 UTF8 = {
165         encode: function(s){
166                 for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
167                         s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
168                 );
169                 return s.join("");
170         },
171         decode: function(s){
172                 for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
173                         ((a = s[i][c](0)) & 0x80) &&
174                         (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
175                         o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
176                 );
177                 return s.join("");
178         }
179 };
180
181 function filter_popup()
182 {
183     if (!$('#filter_popup form input').length) {
184         $.get('query.php',
185               window.location.search.substr(1)+'&ajax=1',
186               function(data) {
187                   var text = '<style type="text/css">';
188                   text += '#fc { z-index: 10; }';
189                   $(data).find('style').each(function(i,e){
190                       text += $(this).html();
191                   });
192                   text += '</style>';
193                   text += $(data).find('form').html();
194                   $('#filter_popup form').html(text);
195
196                   $('#filter_popup').udraggable({
197                       'handle': 'div#filter_title'
198                   }).css('top', '70px').css('left', '103px');
199
200                   $('#filter_popup form input,#filter_popup form select').not('input.button').change(function(e){
201                       $.post('list.php',
202                              'ajax=1&'+$('#filter_popup form').serialize(),
203                              function(data){
204                                  $('table.border tbody').html(UTF8.decode(data));
205                              });
206                       return false;
207                   });
208
209                   $('#filter_popup form input.button[type="submit"]').click(function(e){
210                       $.post('list.php',
211                              'ajax=1&'+$('#filter_popup form').serialize(),
212                              function(data){
213                                  $('table.border tbody').html(UTF8.decode(data));
214                                  $('#filter_popup').hide();
215                              });
216                       return false;
217                   });
218           });
219     }
220
221     if ($('#filter_popup:visible').length)
222         $('#filter_popup').hide();
223     else
224         $('#filter_popup').show();
225
226     return false;
227 }
228
229 </script></protect>
230 <div id="filter_popup" style="display:none;">
231 <div id="filter_title">Filter setzen</div>
232 <div style="padding:5px;">
233 <form id="filter_form"></form>
234 </div>
235 </div>
236 </page>
237
238 # Local variables:
239 # mode: text
240 # mode: auto-fill
241 # end: