Odyssey
stmnt_reports.prg
1 <?php
2  $monLibrary= dirname(__FILE__) . "/../library";
3  $sharedLibrary= dirname(__FILE__) . "/../../shared/library";
4  require_once("$monLibrary/cu_top.i");
5  require_once("$monLibrary/ck_hticket.i");
6  require_once("$sharedLibrary/cu_flagconst.i");
7 
8  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
9  // ** Permissions failed
10  // ** redirect to new page
11  header("Location: /hcuadm/hcu_noperm.prg");
12  exit;
13  }
14 
15 $dms_ok=array('report'=>'digits','csv'=>'string','pos'=>'digits','cdate'=>'string','ctime'=>'string',
16  's0'=>'digits','s1'=>'digits','s2'=>'digits','s3'=>'digits','s4'=>'digits','s5'=>'digits','s6'=>'digits', 's7'=>'digits');
17 dms_import($dms_ok);
18 
19 $report = (isset($report) ? $report : 0);
20 $cdate = isset($cdate) ? $cdate : "NONE";
21 $ctime = isset($ctime) ? $ctime : "NONE";
22 $s0 = isset($s0) ? $s0 : 0;
23 $s1 = isset($s1) ? $s1 : 0;
24 $s2 = isset($s2) ? $s2 : 0;
25 $s3 = isset($s3) ? $s3 : 0;
26 $s4 = isset($s4) ? $s4 : 0;
27 $s5 = isset($s5) ? $s5 : 0;
28 $s6 = isset($s6) ? $s6 : 0;
29 $s7 = isset($s7) ? $s7 : 0;
30 $csv = isset($csv) ? $csv : "";
31 
32 $self = $_SERVER['PHP_SELF'];
33 
34 if ($report == 2) {$cdate='NONE';$ctime='NONE';}
35 if ($report == 3) {$ctime='NONE';}
36 #
37 $msg='';
38 if ($cdate && $cdate != 'NONE' && !(preg_match("/^\d{8}$/",$cdate))) {
39  $msg .= "Please use 'YYYYMMDD' format for cutoff date<br>";
40  unset ($cdate);
41 }
42 if ($cdate && $cdate <= '20030101') {
43  $msg .= "Please provide a cutoff date after 20030101<br>";
44  unset ($cdate);
45 }
46 if ($s0 && $s0 != 1 && $s0 != 0) {
47  $msg .= "Invalid setting for 'Summary Only'<br>";
48  unset ($s0);
49 }
50 if ($ctime && $ctime != 'NONE' && !(preg_match("/^\d{2}:\d{2}:\d{2}$/",$ctime))) {
51  $msg .= "Please use 'HH:MM:SS' format for cutoff time<br>";
52  unset ($ctime);
53 }
54 #
55 if ($report && $cdate && $ctime) {
56  switch ($report) {
57  case 1:
58  $rptname='stmntcount';
59  break;
60  case 2:
61  $rptname='stmntfrags';
62  break;
63  case 3:
64  $rptname='stmntstatus';
65  break;
66  }
67 
68  $q="cdate=$cdate&ctime=$ctime";
69  if ($s0 == 1) {$q .= "&s0=1";}
70  $servers=array();
71  if ($s1 == 1) {array_push($servers,"www");$q .= "&s1=1";}
72  if ($s3 == 1) {array_push($servers,"www3");$q .= "&s3=1";}
73  if ($s5 == 1) {array_push($servers,"www5");$q .= "&s5=1";}
74  if ($s6 == 1) {array_push($servers,"www6");$q .= "&s6=1";}
75  if ($s7 == 1) {array_push($servers,"my");$q .= "&s7=1";} // For Odyssey
76  if (sizeof($servers) == 0) {
77  $servers=array('www3','www5','www6','my'); // Add 'my' to this list when able
78  }
79  $culist = array();
80  foreach ($servers as $ask) {
81 // ** New method -- make a system call --
82  // * the system call will actually be a curl call that will
83  // * send the cookie so it can be processed as normal with all
84  // * validation
85  // ** Be sure the cookie value on the command line is URL Encoded --mws 11/28/2006
86  $cmd = "";
87  if ($ask == "my") {
88  $cmd = "https://$ask.homecu.net/monitor/cgi-bin/$rptname.mp?csv=raw&$q";
89  } else {
90  $cmd = "https://$ask.homecu.net/hcuadm/$rptname.pl?csv=raw&$q";
91  }
92 $ch=curl_init($cmd);
93 $curlcookies = "";
94 $curlcookies .= "HCUTicket=" . urlencode($_COOKIE['HCUTicket']);
95 
96 
97 if ($ask == "my") {
98  $curlcookies .= ";homecu_dev_oauth2_proxy={$_COOKIE['homecu_dev_oauth2_proxy']}";
99 }
100 
101 curl_setopt($ch,CURLOPT_COOKIE,$curlcookies);
102 curl_setopt($ch,CURLOPT_USERPWD,"nobody:no1home");
103 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); # get response as string
104 $rawresp=curl_exec($ch);
105 curl_close($ch);
106 $response=array();
107 if ($rawresp) {
108  foreach(explode("\r\n",$rawresp) as $get_line) {
109  if (trim($get_line) != "") {
110  $response[] = $get_line;
111  }
112  }
113 }
114 
115 # $cmd = "https://nobody:no1home@$ask.homecu.net/hcuadm/{$rptname}.pl?csv=raw&$q";
116 #
117 # $cmd = "/usr/bin/curl " . escapeshellarg("-b HCUTicket=" . urlencode($_COOKIE['HCUTicket'])) . " " . escapeshellarg("$cmd");
118 # // ** Now pass the command to the command line
119 # $response = Array(); // Reset the array
120 # // ** Take the command -- open a pipe -- then retrieve the information -- stuff into an array
121 # if ($handle = popen($cmd, 'r')) {
122 # while (!feof ($handle)) {
123 # $get_line = fgets($handle, 4096);
124 # if (trim($get_line) != "") {
125 # $response[] = $get_line;
126 # }
127 # }
128 #
129 # // ** Be sure to close the handle
130 # pclose($handle);
131 # }
132 
133  if (sizeof($response)) {
134  $titles = explode("\t",rtrim(array_shift($response),"\r\n"));
135  $ftypes = explode("\t",rtrim(array_shift($response),"\r\n"));
136  array_walk($response, 'save_server', "$ask");
137  array_walk($response, 'sort_by', key($servers));
138  array_push($titles,"Server");
139  array_push($ftypes,"char");
140  $culist = array_merge($culist, $response);
141  }
142  }
143 
144 #
145  $culist = array_unique($culist);
146  sort($culist);
147  $title = array_shift($titles);
148  $num_fields = sizeof($titles);
149  $num_rows = sizeof($culist);
150 
151 if (($csv == 'csv') && sizeof($culist)) {
152  unset($csv);
153  $ostring = "";
154  $osep = "";
155 
156 #
157 # First record has the field names
158 #
159  for ($i_field = 0; $i_field < $num_fields; $i_field++) {
160  $field_name = $titles[$i_field];
161  $ostring .= "$osep\"$field_name\"";
162  $osep = ",";
163  }
164  $ostring .= "\r\n";
165 
166 #
167 # Now the data
168 #
169  foreach ($culist as $cu) {
170  $cu = rtrim($cu);
171  $osep="";
172  $row = explode("\t",$cu);
173 
174  # throw away the sort column
175  array_shift($row);
176 
177  $hdrdtl=array_shift($row);
178 
179  for ($i_field = 0; $i_field < $num_fields; $i_field++) {
180  $field_type = $ftypes[$i_field];
181  if (preg_match("/(int|numeric)/i", $field_type)) {
182  $ostring .= "${osep}${row[$i_field]}";
183  } elseif (preg_match("/(text|char)/i", $field_type)) {
184  $ostring .= "${osep}\"${row[$i_field]}\"";
185  } elseif ($field_type == "bool") {
186  $ostring .= "${osep}\"${row[$i_field]}\"";
187  } else {
188  $ostring .= "${osep}\"${row[$i_field]}\"";
189  }
190  $osep=",";
191  }
192  $ostring .= "\r\n";
193 
194  }
195 
196  header("Content-length: " . strlen( $ostring ) );
197  header("Content-type: application/octetstream");
198  header("Content-disposition: inline; filename=\"${Cu}report${report}.csv\"");
199  print ( $ostring );
200  exit;
201 }
202 #
203 $cfgShowBlob = false;
204 $cfgQuotes="\"";
205 $cfgBorder=1;
206 $cfgMaxRows=99999;
207 $cfgMaxPages=5;
208 $cfgMaxText=255;
209 $strShowingRecords = "Showing records ";
210 $strTotal = "total";
211 $strPrevious = "Previous";
212 $strNext = "Next";
213 $strPos1 = "Begin";
214 $strEnd = "End";
215 $strMore = "More";
216 $strEmptySet = "No records found";
217 
218  if (!isset($pos))
219  $pos = 0;
220 
221  $pos_next = $pos + $cfgMaxRows;
222  $pos_prev = $pos - $cfgMaxRows;
223 
224  $num_rows = sizeof($culist);
225 
226  $num_fields = sizeof($ftypes);
227 
228  $iNumRows = $num_rows;
229  if ($num_rows < $pos_next) {
230  $pos_next = $num_rows;
231  }
232 
233  $strNavigation = "";
234  $strNavigation .= "<table border=0 width='100%' cellspacing=0 cellpadding=2><tr>\n";
235  $strNavigation .= "<td align=left class='dtl'>";
236  if ($pos >= $cfgMaxRows) {
237  //doj added link to beginning of results
238  $strNavigation .= "<a href=\"$self?report=$report&title=$title&sql_order=" . urlencode($sql_order) . "&pos=0$q\">&lt;&lt; $strPos1 </a> | ";
239 
240  $strNavigation .= " <a href=\"$self?report=$report&title=$title&sql_order=" . urlencode($sql_order) . "&pos=$pos_prev$q\">&lt; $strPrevious </a> | ";
241  } else {
242  $strNavigation .= "&nbsp;";
243  }
244  $strNavigation .= "</td>\n";
245 
246  $strNavigation .= "<td align=center class='dtl'>\n";
247 
248  //doj now only the previous and next $cfgMaxPages pages will be shown
249  if (empty($cfgMaxPages)) {
250  $cfgMaxPages = 5;
251  }
252 
253  $iCount = $pos - ($cfgMaxRows * $cfgMaxPages);
254  if ($iCount < 0)
255  $iCount = 0;
256 
257  $iPageCnt = (int)($iCount / $cfgMaxRows);
258  $iPageStop = $pos + ($cfgMaxRows * ($cfgMaxPages + 1));
259 
260  $strPages = "";
261  for (; $iCount < $iNumRows && $iCount < $iPageStop; $iCount += $cfgMaxRows) {
262  //doj until here
263  $iPageCnt++;
264  if ($iCount != $pos) {
265  $strPages .= "<a href=\"$self?report=$report&title=".urlencode($title)."&sql_order=".urlencode($sql_order)."&pos=$iCount$q\">$iPageCnt</a> | ";
266  } else {
267  if ($iNumRows > $cfgMaxRows) {
268  $strPages .= "$iPageCnt | ";
269  }
270  }
271  }
272  $strNavigation .= preg_replace("/ \| $/", "", $strPages);
273 
274  $strNavigation .= "</td>\n";
275 
276  $strNavigation .= "<td align=right class='dtl'>";
277  if ($pos_next < $num_rows) {
278  $strNavigation .= " | <a href=\"$self?report=$report&title=".urlencode($title)."&sql_order=".urlencode($sql_order)."&pos=$pos_next$q\"> $strNext &gt;</a>";
279 
280  //doj link to end of results
281  $pos_end = $num_rows - $cfgMaxRows;
282  $strNavigation .= " | <a href=\"$self?report=$report&title=".urlencode($title)."&sql_order=".urlencode($sql_order)."&pos=$pos_end$q\"> $strEnd &gt;&gt;</a>";
283  } else {
284  $strNavigation .= "&nbsp;";
285  }
286  $strNavigation .= "</td>\n";
287  $strNavigation .= "</tr></table>\n";
288 
289 header("Expires: Sat 20 May 1995 03:32:38 GMT");
290 header("Pragma: no-cache");
291 header("Cache-Control: no-cache, must-revalidate");
292 cu_header("$title");
293  echo "<table border=0 align=center width='90%' class='dmsbg' cellpadding=3 cellspacing=0><tr><td>";
294  echo "<table border=0 align=center width='100%' bgcolor=white cellpadding=2 cellspacing=0>";
295  echo "<tr><td class='dtl' align='left'>";
296  echo "<a href='$produrl/hcuadm/cuilist.prg'>Credit Union List</a>&nbsp;&nbsp;&nbsp;
297  <a href='$self?report=0'>Report Menu</a>&nbsp;&nbsp;&nbsp;
298  <A HREF='$self?csv=csv&report=$report&$q'>Download CSV</a></td><td class='dtl' align='right'>&nbsp; ";
299  if ($num_rows > 1) {
300  echo "$strShowingRecords $pos - $pos_next ($num_rows $strTotal)";
301  }
302  echo "</td></tr></table>";
303 
304  echo $strNavigation;
305  echo "<table cellspacing=0 border=$cfgBorder align=center width='100%'>";
306  echo "<tr><td class='hdr' colspan='$num_fields' align='center'>$title</td></tr><tr>";
307 
308  for ($i_field = 0; $i_field < $num_fields; $i_field++) {
309  $field_name = $titles[$i_field];
310  echo "<th class='hdr'>$field_name</th>";
311  }
312  echo "</tr>\n";
313  if ((sizeof($culist)) < 1) {
314  echo "<tr class='odd'><td class='dtl' colspan='$num_fields'>$strEmptySet</td></tr>";
315  } else {
316 
317  for ($i_row = $pos; $i_row < $pos_next; $i_row++) {
318  $row = explode("\t",rtrim($culist[$i_row],"\r\n"));
319 
320  # throw away the sort column
321  array_shift($row);
322 
323 
324  $hdrdtl=array_shift($row);
325 
326  $rbg=($hdrdtl == 's' ? 'dtl' : 'odd_small');
327 
328  echo "<tr class=$rbg>";
329  for ($i_field = 0; $i_field < sizeof($row); $i_field++) {
330  if (!isset($row[$i_field]))
331  unset($row[$i_field]);
332  $field_type = $ftypes[$i_field];
333  $field_name = $titles[$i_field];
334  if (preg_match("/(int|numeric)/i", $field_type)) {
335 
336  echo "<td class='$rbg' align=right valign=top>&nbsp;$row[$i_field]&nbsp;</td>\n";
337  } elseif ($cfgShowBlob == false && preg_match("/BLOB/i", $field_type)) {
338  echo "<td class='$rbg' align=right valign=top>&nbsp;[BLOB]&nbsp;</td>\n";
339  } elseif (preg_match("/(text|char)/i", $field_type)) {
340  // If the text is longer than $cfgMaxText characters, let's cut it short
341  if (strlen($row[$i_field]) > $cfgMaxText && !empty($cfgMaxText)) {
342  $strLgText = nl2br(htmlspecialchars(substr($row[$i_field], 0, $cfgMaxText))) . " <br><b>... $strMore ...</b>";
343  } else {
344  $strLgText = nl2br(htmlspecialchars($row[$i_field]));
345  }
346  echo "<td class='$rbg' valign=top>&nbsp;$strLgText</td>\n";
347  } elseif ($field_type == "bool") {
348  echo "<td class='$rbg' valign=top>&nbsp;", bool_YesNo($row[$i_field]), "&nbsp;</td>\n";
349  } else {
350  echo "<td class='$rbg' valign=top>&nbsp;", nl2br(htmlspecialchars($row[$i_field])), "&nbsp;</td>\n";
351  }
352  }
353  echo "</tr>";
354 
355  }
356 }
357 
358  echo "</table>\n";
359  echo $strNavigation;
360 
361  echo "</td></tr></table>";
362 
363 
364 } else {
365  # show list of selections
366 header("Expires: Sat 20 May 1995 03:32:38 GMT");
367 header("Pragma: no-cache");
368 header("Cache-Control: no-cache, must-revalidate");
369 cu_header("Select Report");
370 print <<<EOF
371  <form action='$self' method='GET'>
372  <table width='500' border='0' align='center' cellpadding=3 cellspacing=0 class='dmsbg'><tr><td>
373  <table width='100%' border='0' align='center' bgcolor=white cellpadding2 cellspacing=0>
374  <tr class='barb'><td align='center'><font size=+1>Please Select Report</font></td></tr>
375  <tr><td><a href="$produrl/hcuadm/cuilist.prg" target="parent">Credit Union List</a></td></tr>
376  <tr class='hdr'><td>E-Statement Reports</td></tr>
377  <tr class='msg'><td>$msg</td></tr>
378  <tr class='odd_small'><td>&nbsp;&nbsp;&nbsp;<input type='radio' name='report' value='1'>&nbsp;E-Statement Count</td></tr>
379  <tr class='even_small'><td>&nbsp;&nbsp;&nbsp;<input type='radio' name='report' value='2'>&nbsp;Missing Fragments</td></tr>
380  <tr class='odd_small'><td>&nbsp;&nbsp;&nbsp;<input type='radio' name='report' value='3'>&nbsp;Last Status</td></tr>
381  <tr class='hdr'><td>&nbsp;</td></tr>
382  <tr class='odd_small'><td>
383  <table align='center'><tr><td class='odd_small'>&nbsp;Cutoff Date (YYYYMMDD)</td><td>&nbsp;<input type='text' size='10' maxlength='8' name='cdate'></td></tr>
384  <tr><td class='odd_small'>&nbsp;Cutoff Time (HH:MM:SS)</td><td>&nbsp;<input type='text' name='ctime' value='00:00:00' size='10' maxlength='8'></td></tr>
385  <tr><td colspan=2 class='odd_small'><input type='checkbox' name='s0' value='1'>&nbsp;Summary Only&nbsp;</td></tr></table>
386 </td></tr>
387  <tr class='hdr'><td>&nbsp;</td></tr>
388  <tr class='odd_small'><td>&nbsp; Include Data from <br>
389 <!--&nbsp;&nbsp;<input type='checkbox' name='s1' value='1'>&nbsp;www
390 &nbsp;&nbsp;<input type='checkbox' name='s2' value='1'>&nbsp;www2
391 &nbsp;&nbsp;<input type='checkbox' name='s4' value='1'>&nbsp;www4-->
392 &nbsp;&nbsp;<input type='checkbox' name='s3' value='1'>&nbsp;www3
393 &nbsp;&nbsp;<input type='checkbox' name='s5' value='1'>&nbsp;www5
394 &nbsp;&nbsp;<input type='checkbox' name='s6' value='1'>&nbsp;www6
395 &nbsp;&nbsp;<input type='checkbox' name='s7' value='1'>&nbsp;Odyssey
396 </td></tr>
397  <tr class='hdr'><td>&nbsp;</td></tr>
398  <tr class='hdrc'><td><input type='submit' value='Go'></td></tr>
399 </table>
400 </td></tr></table>
401 EOF;
402  exit;
403 
404  }
405 function save_server(&$response, $key, $server)
406 {
407  $row = explode("\t",$response);
408  if ($row[0]=='s' || $row[0]=='T') {
409  $response = rtrim($response,"\r\n") . "\t$server\r\n";
410  } else {
411  $response = rtrim($response,"\r\n") . "\t\r\n";
412  }
413 }
414 
415 function sort_by(&$response, $key, $server)
416 {
417  $row = explode("\t",$response);
418  if ($row[0]=='T') {
419  $response = "zzzzzzzz" . $row[1] . $server . sprintf('%05d',$key) . "\t$response";
420  } else {
421  $response = $row[1] . $server . sprintf('%05d',$key) . "\t$response";
422  }
423 }
424 
425 ?>