Odyssey
hcucontact_rpt.prg
1 <?php
2 
3 $monLibrary = dirname(__FILE__) . "/../library";
4 $sharedLibrary = dirname(__FILE__) . "/../../shared/library";
5 require_once("$monLibrary/cu_top.i");
6 require_once("$monLibrary/ck_hticket.i");
7 require_once("$sharedLibrary/cu_flagconst.i");
8 
9 $dms_ok=array('report'=>'digits','ob'=>'digits','csv'=>'string',
10  'pos'=>'digits','d'=>'digits','jval'=>'string','pm'=>'digits');
11 dms_import($dms_ok);
12 
13 $report = (isset($report) ? $report : 2);
14 
15 switch ($report) {
16 
17  case 1:
18  $sql_query = "select trim(upper(user_name)) as cu,
19  trim(www_server) as www_server, system_options
20  from cuinfo
21  where system_options & 3::bigint > 0
22  and system_options & 64::bigint = 0
23  and date_live is not null
24  and user_name not in ('miki', 'demo', 'dmstest') ";
25  if (!isset($ob) || (intval($ob) < 1 || intval($ob) > 3)) {
26  $sql_order = " ORDER BY 1";
27  $ob = 1; // Set the order by to 1 if it isn't set
28  } else {
29  $sql_order = " ORDER BY " . intval($ob);
30  }
31 
32  $title = "HCU Contacts Cuinfo List";
33  break;
34 
35  case 2:
36  $sql_query = "select trim(m.cu) as cu,
37  case when n.notify is null then trim(m.master)
38  else trim(n.notify) end as email
39  from (select a.cu, u.email as master from cuadmin a
40  join cuadminusers u on a.cu = u.cu where u.realname = 'CU Master') as m
41  left join (select cu, email as notify from cuadmnotify
42  where role = 'hcunotice') as n on m.cu = n.cu ";
43  if (!isset($ob) || (intval($ob) < 1 || intval($ob) > 2)) {
44  $sql_order = " ORDER BY 1";
45  $ob = 1; // Set the order by to 1 if it isn't set
46  } else {
47  $sql_order = " ORDER BY " . intval($ob);
48  }
49  $title = "HCU Contact Email List";
50  break;
51 
52  case 3:
53  $sql_query = "select m.cu as \"CU\", n.notify as \"HCU Notice\",
54  m.master as \"CU Master\"
55  from (select a.cu, u.email as master from cuadmin a
56  join cuadminusers u on a.cu=u.cu where u.realname = 'CU Master')
57  as m left join (select cu, email as notify from cuadmnotify
58  where role = 'hcunotice') as n on m.cu = n.cu ";
59  if (!isset($ob) || (intval($ob) < 1 || intval($ob) > 3)) {
60  $sql_order = " ORDER BY 1";
61  $ob = 1; // Set the order by to 1 if it isn't set
62  } else {
63  $sql_order = " ORDER BY " . intval($ob);
64  }
65  $title = "HCU Notice and Master Email List";
66  break;
67 
68  case 4:
69  $sql_query = "select trim(cu) as cu,
70  trim(email) as email
71  from cuadmnotify where role = 'hcunotice' ";
72  if (!isset($ob) || (intval($ob) < 1 || intval($ob) > 2)) {
73  $sql_order = " ORDER BY 1";
74  $ob = 1; // Set the order by to 1 if it isn't set
75  } else {
76  $sql_order = " ORDER BY " . intval($ob);
77  }
78  $title = "HCU Notice Email List";
79  break;
80 
81  case 5:
82  $sql_query = "select trim(cu) as cu,
83  trim(email) as email
84  from cuadmnotify where role = 'esload' ";
85  if (!isset($ob) || (intval($ob) < 1 || intval($ob) > 2)) {
86  $sql_order = " ORDER BY 1";
87  $ob = 1; // Set the order by to 1 if it isn't set
88  } else {
89  $sql_order = " ORDER BY " . intval($ob);
90  }
91  $title = "HCU ESLoad Email List";
92  break;
93 }
94 
95 $sql_query = stripslashes($sql_query);
96 $sql_order = stripslashes($sql_order);
97 $title = stripslashes($title);
98 
99 $d = isset($d) ? $d : null;
100 if ($d == 1) {
101  $sql_order .= " desc";
102 }
103 
104 $sql_order = isset($sql_order) ? trim($sql_order) : "";
105 if (!$result = db_query($sql_query . $sql_order, $dbh)) {
106  pg_die(pg_errormessage($dbh), $sql_query . $sqlorder, __FILE__, __LINE__);
107 }
108 $num_rows = db_num_rows($result);
109 $num_fields = @pg_numfields($result);
110 
111 if (isset($csv) && $csv == 'raw') {
112  unset($csv);
113  $ostring = "";
114  $osep = "\t";
115 
116  if ($num_rows > 0) {
117 
118  #
119  # First record has the field names
120  #
121  $ostring = $title;
122  for ($i_field = 0; $i_field < $num_fields; $i_field++) {
123  $field_name = pg_fieldname($result, $i_field);
124  $ostring .= "${osep}${field_name}";
125  }
126  $ostring .= "\r\n";
127 
128  #
129  # Second record has the field types
130  #
131  $osep = "";
132  for ($i_field = 0; $i_field < $num_fields; $i_field++) {
133  $field_type = pg_fieldtype($result, $i_field);
134  $ostring .= "${osep}${field_type}";
135  $osep = "\t";
136  }
137  $ostring .= "\r\n";
138 
139  #
140  # Now the data
141  #
142  for ($i_row = 0; $i_row < $num_rows; $i_row++) {
143  $osep = "";
144  $row = pg_fetch_row($result, $i_row);
145  for ($i_field = 0; $i_field < $num_fields; $i_field++) {
146  $ostring .= "${osep}${row[$i_field]}";
147  $osep = "\t";
148  }
149  $ostring .= "\r\n";
150  }
151  }
152 
153  $Cu = $Cu ?? "";
154 
155  header("Content-length: " . strlen( $ostring ) );
156  header("Content-type: application/octetstream");
157  header("Content-disposition: inline; filename=\"${Cu}report${report}.csv\"");
158  print ( $ostring );
159  exit;
160 }
161 
162 
163 $query = display_table($result);
164 
165 function display_table ($dt_result) {
166  global $pos, $dbh, $sql_query, $sql_order, $report, $self, $title, $ob, $d, $jval, $pm;
167 
168  $cfgQuotes = "\"";
169  $cfgBorder = 0;
170  $cfgMaxRows = 30;
171  $cfgMaxPages = 5;
172  $cfgMaxText = 255;
173  $cfgOrder = "DESC";
174  $strShowingRecords = "Showing records ";
175  $strTotal = "total";
176  $strPrevious = "Previous";
177  $strNext = "Next";
178  $strPos1 = "Begin";
179  $strEnd = "End";
180  $strMore = "More";
181  $strEmptySet = "No records found";
182 
183  #
184  # if jval is set, search through the ob field until we find a match
185  # set $pos so record is on the page
186  #
187 
188  if (!isset($pos)) {
189  $pos = 0;
190  }
191  if (!isset($d)) {
192  $d = 0;
193  }
194 
195  $num_rows = @pg_numrows($dt_result);
196 
197  $num_fields = @pg_numfields($dt_result);
198 
199  if (isset($jval) && trim($jval) > '') {
200  $nomatch = 1;
201  $jval = trim(stripslashes(preg_replace("/[\"\`;\\\]/","",$jval)));
202  if ($pm) $clen = strlen($jval);
203  for ( $rowptr = 0; $rowptr < $num_rows; $rowptr++ ) {
204  $colval = pg_fetch_result($dt_result, $rowptr, $ob - 1);
205  $coloff = (strpos(strtolower($colval), strtolower($jval)) === false ? 0 : strpos(strtolower($colval), strtolower($jval)));
206  if ($pm == 2) {
207  $colval = substr($colval, $coloff, $clen);
208  }
209  if ($pm == 1) {
210  $colval = substr($colval, 0, $clen);
211  }
212  if (strtolower(trim($colval)) == strtolower($jval)) {
213  $pos = $cfgMaxRows * floor($rowptr / $cfgMaxRows);
214  $nomatch = 0;
215  break;
216  }
217  }
218 
219  }
220 
221  $pos_next = $pos + $cfgMaxRows;
222  $pos_prev = $pos - $cfgMaxRows;
223 
224 
225  $iNumRows = $num_rows;
226  if ($num_rows < $pos_next) {
227  $pos_next = $num_rows;
228  }
229 
230  if (!isset($strNavigation)) {
231  $strNavigation = "";
232  }
233  $strNavigation .= "<table border=0 cellpadding=2 cellspacing=0><tr>\n";
234  $strNavigation .= "<td align=left>";
235  if ($pos >= $cfgMaxRows) {
236  //doj added link to beginning of results
237  $strNavigation .= "<a href=\"$self?report=$report&ob=$ob&d=$d&pos=0\">&lt;&lt; $strPos1 </a> | ";
238 
239  $strNavigation .= " <a href=\"$self?report=$report&ob=$ob&d=$d&pos=$pos_prev\">&lt; $strPrevious </a> | ";
240  } else {
241  $strNavigation .= "&nbsp;";
242  }
243  $strNavigation .= "</td>\n";
244 
245  $strNavigation .= "<td align=center>\n";
246 
247  //doj now only the previous and next $cfgMaxPages pages will be shown
248  if (empty($cfgMaxPages)) {
249  $cfgMaxPages = 5;
250  }
251 
252  $iCount = $pos - ($cfgMaxRows * $cfgMaxPages);
253  if ($iCount < 0)
254  $iCount = 0;
255 
256  $iPageCnt = (int)($iCount / $cfgMaxRows);
257  $iPageStop = $pos + ($cfgMaxRows * ($cfgMaxPages + 1));
258 
259  if (!isset($strPages)) {
260  $strPages = "";
261  }
262  for (; $iCount < $iNumRows && $iCount < $iPageStop; $iCount += $cfgMaxRows) {
263  //doj until here
264  $iPageCnt++;
265  if ($iCount != $pos) {
266  $strPages .= "<a href=\"$self?report=$report&ob=$ob&d=$d&pos=$iCount\">$iPageCnt</a> | ";
267  } else {
268  if ($iNumRows > $cfgMaxRows) {
269  $strPages .= "$iPageCnt | ";
270  }
271  }
272  }
273  $strNavigation .= preg_replace('/ \| $/i', "", $strPages);
274 
275  $strNavigation .= "</td>\n";
276 
277  $strNavigation .= "<td align=right>";
278  if ($pos_next < $num_rows) {
279  $strNavigation .= " | <a href=\"$self?report=$report&ob=$ob&d=$d&pos=$pos_next\"> $strNext &gt;</a>";
280 
281  //doj link to end of results
282  $pos_end = $num_rows - $cfgMaxRows;
283  $strNavigation .= " | <a href=\"$self?report=$report&ob=$ob&d=$d&pos=$pos_end\"> $strEnd &gt;&gt;</a>";
284  } else {
285  $strNavigation .= "&nbsp;";
286  }
287  $strNavigation .= "</td>\n";
288  $strNavigation .= "</tr></table>\n";
289 
290  header("Expires: Sat 20 May 1995 03:32:38 GMT");
291  header("Pragma: no-cache");
292  header("Cache-Control: no-cache, must-revalidate");
293 
294  if (!isset($q)) {
295  $q = "";
296  }
297  print <<<EOF
298  <script language='javascript'>
299  function jumpto()
300  {
301  var strJval=document.jumpform.jval.value;
302  var strPm=0;
303  for (i=document.jumpform.pm.length-1; i > -1; i--) {
304  if (document.jumpform.pm[i].checked) {
305  strPm = document.jumpform.pm[i].value; i = -1;
306  }
307  }
308  document.location='$self?report=$report&ob=$ob&d=$d&pos=0&jval=' + strJval + '&pm=' + strPm + '$q';
309  }
310  </script>
311 EOF;
312 
313  cu_header("$title");
314  echo "<table border=$cfgBorder align=center width='100%' bgcolor=white cellpadding=2 cellspacing=0>";
315  echo "<tr><td class='dtl' align='left'>";
316  echo "<a href='cuilist.prg'>Credit Union List</a>&nbsp;&nbsp;&nbsp;
317  <A HREF='$self?csv=csv&report=$report&ob=$ob&d=$d'>Download CSV</a></td><td class='dtl' align='right'>&nbsp;";
318  if ($num_rows > 1) {
319  echo "$strShowingRecords $pos - $pos_next ($num_rows $strTotal)";
320  }
321  echo "</td></tr></table>";
322 
323  echo $strNavigation;
324  if ($iNumRows > $cfgMaxRows) {
325  # show a 'Jump to this value' link for the sorted field only
326  print "<form name='jumpform' onSubmit='jumpto();return false;'>
327  <table border=$cfgBorder align=center width='90%'>
328  <tr><td class='msg'><hr>
329  Click column heading to change sort order and jump value<br>&nbsp;</td></tr>
330  <tr><td>Jump to " .
331  pg_fieldname($dt_result, $ob-1) . ": &nbsp;
332  <input type='text' name='jval' value='$jval' size='10'>
333  &nbsp;&nbsp;
334  <input type='radio' name='pm' value='1'>&nbsp;Partial Match
335  &nbsp;&nbsp;
336  <input type='radio' name='pm' value='2'>&nbsp;Wildcard&nbsp;&nbsp;
337  <input type='button' value='Go' onClick='jumpto();return false;'>";
338  if ($nomatch == 1 ) print "<br><font color='red' align='center'>No Match Found</font>";
339  print "</td></tr></table></form>";
340  }
341  echo "<table border=$cfgBorder align=center width='100%' bgcolor=white cellpadding=2 cellspacing=0>";
342  echo "<tr><td class='hdr' colspan='$num_fields' align='center'>$title</td></tr><tr>";
343  echo "<tr>";
344 
345  for ($i_field = 0; $i_field < $num_fields; $i_field++) {
346  $field_name = pg_fieldname($dt_result, $i_field);
347  if (@pg_numrows($dt_result) > 1) {
348 
349  if (($i_field + 1) == intval($ob) && $d != 1) {
350  $desc_ord = "&d=1"; // Descending order??
351  } else {
352  $desc_ord = "&d=0";
353  }
354 
355  $sort_order = ($i_field + 1);
356  echo "<th class='small' align='left'><A HREF=\"$self?report=$report&pos=$pos&ob={$sort_order}{$desc_ord}\">$field_name</a></th>\n";
357  } else {
358  echo "<th class='small' align='left'>$field_name</th>";
359  }
360  }
361  echo "</tr>\n";
362  if ((@pg_numrows($dt_result)) < 1) {
363  echo "<tr class='odd'><td colspan='$num_fields'>$strEmptySet</td>";
364  } else {
365 
366  if (!isset($cfgShowBlob)) {
367  $cfgShowBlob = "";
368  }
369 
370  for ($i_row = $pos; $i_row < $pos_next; $i_row++) {
371  $row = pg_fetch_row($dt_result, $i_row);
372  $i_row % 2 ? $rbg = "odd_small" : $rbg = "even_small";
373  echo "<tr class=$rbg>";
374  for ($i_field = 0; $i_field < pg_numfields($dt_result); $i_field++) {
375  if (!isset($row[$i_field])) {
376  unset($row[$i_field]);
377  }
378  $field_type = pg_fieldtype($dt_result, $i_field);
379  $field_name = pg_fieldname($dt_result, $i_field);
380  if (preg_match('/int|numeric/i', $field_type)) {
381 
382  echo "<td align=right valign=top>&nbsp;$row[$i_field]&nbsp;</td>\n";
383  } elseif ($cfgShowBlob == false && preg_match('/blob/i', $field_type)) {
384  echo "<td align=right valign=top>&nbsp;[BLOB]&nbsp;</td>\n";
385  } elseif (preg_match('/text|char/i', $field_type)) {
386  // If the text is longer than $cfgMaxText characters, let's cut it short
387  if (strlen($row[$i_field]) > $cfgMaxText && !empty($cfgMaxText)) {
388  $strLgText = nl2br(htmlspecialchars(substr($row[$i_field], 0, $cfgMaxText))) . " <br><b>... $strMore ...</b>";
389  } else {
390  $strLgText = nl2br(htmlspecialchars($row[$i_field]));
391  }
392  echo "<td valign=top>&nbsp;$strLgText</td>\n";
393  } elseif ($field_type == "bool") {
394  echo "<td valign=top>&nbsp;", bool_YesNo($row[$i_field]), "&nbsp;</td>\n";
395  } else {
396  echo "<td valign=top>&nbsp;", nl2br(htmlspecialchars($row[$i_field])), "&nbsp;</td>\n";
397  }
398  }
399 
400  }
401  }
402 
403  if (!isset($query)) {
404  $query = "";
405  }
406 
407  echo "</tr></table>\n";
408  echo $strNavigation;
409  return $query;
410 }
411 
412 // Function: pg_die($error, $query)
413 // Params: $error -- The displayable error text. Usually passed as pg_errormessage()
414 // $query -- The query which was attempted
415 function pg_die($error = "", $query = "", $err_file = __FILE__, $err_line = __LINE__) {
416  global $strError,$strMySQLSaid, $strBack, $sql_query, $link, $db, $table, $cfgDebug, $server;
417 
418  echo "<b><font face=\"arial,helvetican,sans-serif\" color=\"red\">$strError - $err_file -- Line: $err_line</font></b><p>";
419  if (empty($error)) {
420  $error = @pg_errormessage();
421  }
422  echo "<font face=\"arial,helvetican,sans-serif\" color=\"red\">", $strMySQLSaid . $error;
423  if (empty($query)) {
424  $query = $sql_query;
425  }
426  if (!empty($query)) {
427  echo "<br>Your query: <br><b>", nl2br(htmlentities($query)), "</b>";
428  }
429  echo "<br><a href=\"javascript:history.back()\">$strBack</a></font>";
430 
431  if ($cfgDebug) {
432  echo "<br>Link: $link<br>DB: $db<br>Table: $table<br>Server: $server";
433  }
434 
435  echo "<p>";
436  exit;
437 }
438 ?>