Switch to UTF8 when in JS/AJAX mode
[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 ("
66 ", $row['descr']);
67     $date = explode (" ", $row['datum']);
68     $date = explode ("-", $date[0]);
69     $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
70
71     $out .= sprintf ("<tr class=\"t%d\">", $color);
72     $out .= sprintf ("<td width=\"10%%\" align=\"right\">%s</td>", $date);
73     $out .= sprintf ("<td width=\"10%%\" align=\"center\">%s</td>", $row['category']);
74     $out .= sprintf ("<td width=\"70%%\"><a href=\"edit.php?id=%d%s\">%s</a></td>",
75             $row['id'], $add, $descr[0]);
76     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\">%5.2f</td>",
77       $row[$value]>0?"in":"out", $row[$value]);
78     $sum += $row[$value];
79     if ($row[$value] > 0) {
80       $sum_in += $row[$value];
81     } else {
82       $sum_out += $row[$value];
83     }
84     $out .= "</tr>";
85     $color = !$color;
86   }
87   if (strlen($statement)) {
88     $out .= sprintf ("<tr class=\"t%d\">", $color);
89     $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Einnahmen</strong></td>";
90     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"in\">%5.2f</td>",$sum_in);
91     $out .= "</tr>";
92     $out .= sprintf ("<tr class=\"t%d\">", $color);
93     $out .= "<td width=\"90%\" colspan=\"3\"><strong>Summe Ausgaben</strong></td>";
94     $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"out\">%5.2f</td>", $sum_out*-1);
95     $out .= "</tr>";
96   }
97   $out .= sprintf ("<tr class=\"t%d\">", $color);
98   $out .= "<td width=\"90%\" colspan=\"3\" align=\"left\"><strong>Summe</strong></td>";
99   $out .= sprintf ("<td width=\"10%%\" align=\"right\" class=\"%s\"><strong>%5.2f</strong></td>",
100     $sum>0?"in":"out", $sum);
101   $out .= "</tr>";
102
103   return $out;
104 }
105
106 if (!empty($_POST['ajax']) && $_POST['ajax'] == 1) {
107     echo utf8_encode(filter_account());
108     exit;
109 }
110
111 ?>
112
113 <page func=InfoCon title="Kontoführung">
114
115 <calendar_init -5>
116 <account_heading>
117 <form_to_yyyymmdd>
118
119 <style type="text/css">
120 div#filter_popup {
121     background: white;
122     border: 1px solid #CCC;
123     height:auto;
124     width:340px;
125     position:absolute;
126 }
127 div#filter_title {
128     width: 100%;
129     cursor: move;
130     background: #EEE;
131     margin-bottom: 5px;
132     font-weight: bold;
133 }
134 </style>
135 <table class="border smallfont" width=100% border=0 cellpadding=0 cellspacing=1>
136 <thead>
137 <tr class=head>
138   <th width=10%>Datum</th>
139   <th width=10%>Kategorie</th>
140   <th width=70%>Verwendungszweck</th>
141   <th width=10%>Betrag</th>
142 </tr>
143 </thead>
144 <tbody>
145 <?=(count($_GET)?'':filter_account())?>
146 </tbody>
147 </table><p>
148
149 <protect><script type="text/javascript">
150 $(function(){
151     $('table.border tr').not('.head').click(function(){
152         $(this).toggleClass('highlight');
153         if ($(this).hasClass('highlight'))
154             $(this).css('backgroundColor','#add8e6');
155         else
156             $(this).css('backgroundColor','');
157     });
158     $('body').append('<script type="text/javascript" src="../../jquery.udraggable.js"><\/script>');
159     $('body').append('<script type="text/javascript" src="../../jquery.event.ue.js"><\/script>');
160 });
161
162 function filter_popup()
163 {
164     if (!$('#filter_popup form input').length) {
165         $.get('query.php',
166               window.location.search.substr(1)+'&ajax=1',
167               function(data) {
168                   var text = '<style type="text/css">';
169                   text += '#fc { z-index: 10; }';
170                   $(data).find('style').each(function(i,e){
171                       text += $(this).html();
172                   });
173                   text += '</style>';
174                   text += $(data).find('form').html();
175                   $('#filter_popup form').html(text);
176
177                   $('#filter_popup').udraggable({
178                       'handle': 'div#filter_title'
179                   }).css('top', '70px').css('left', '103px');
180
181                   $('#filter_popup form input.button[type="submit"]').click(function(e){
182                       $.post('list.php',
183                              'ajax=1&'+$('#filter_popup form').serialize(),
184                              function(data){
185                                  $('table.border tbody').html(data);
186                                  $('#filter_popup').hide();
187                              });
188                       return false;
189                   });
190           });
191     }
192
193     if ($('#filter_popup:visible').length)
194         $('#filter_popup').hide();
195     else
196         $('#filter_popup').show();
197
198     return false;
199 }
200
201 </script></protect>
202 <div id="filter_popup" style="display:none;">
203 <div id="filter_title">Filter setzen</div>
204 <div style="padding:5px;">
205 <form id="filter_form"></form>
206 </div>
207 </div>
208 </page>
209
210 # Local variables:
211 # mode: text
212 # mode: auto-fill
213 # end: