Odyssey
AdminProg.prg
1 <?php
2  $monLibrary= dirname(__FILE__) . "/../library";
3  require_once("$monLibrary/cu_top.i");
4  require_once("$monLibrary/ck_hticket.i");
5 
6  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
7  // ** Permissions failed
8  // ** redirect to new page
9  header("Location: /hcuadm/hcu_noperm.prg");
10  exit;
11  }
12 
13 $dms_ok=array('opt'=>'string','pg'=>'string','rowid'=>'string');
14 dms_import($dms_ok);
15 $print_msg = "";
16 $print_err = "";
17 
18  cu_header("Allowed Program List");
19  $msg = "";
20  if (isset($opt) && isset($pg)) {
21  // Here it needs to set the switch for the program
22  // Either delete the record from the cuadminexclude
23  // or add it
24  switch ($opt) {
25  case "on":
26  // Turn this program ON fro the credit union
27  // this is done by DELETING it from the
28  // cuadminexclude table
29  $sql = "DELETE FROM cuadminexclude
30  WHERE trim(program) = '" . pg_escape_string($pg) . "'
31  AND trim(user_name) = '" . pg_escape_string($rowid) . "' ";
32  if ($exc_rs = db_query($sql, $link)) {
33  $print_msg = "Program {$pg} was turned ON for {$rowid}";
34  } else {
35  $print_msg = "Error -- Status not changed for program {$pg}";
36  }
37  db_free_result($exc_rs);
38  break;
39  case "off":
40  // Turn off this program for this credit union
41  // This is done by ADDING the record to the
42  // cuadminexclude table
43 
44  // First -- I have the user_name -- I want to
45  // Guarantee the correct cu value by grabbing
46  // the value from the cuadminusers
47  $sql = "SELECT cu
48  FROM cuadminusers
49  WHERE user_name = '" . pg_escape_string($rowid) . "' ";
50  $cu_rs = db_query($sql, $link);
51  $cu_row = db_fetch_array($cu_rs, 0);
52  db_free_result($cu_rs);
53  $cu = trim($cu_row['cu']);
54  // But make sure we have a cu code -- only insert if we do
55  if ($cu != '') {
56  $sql = "INSERT INTO cuadminexclude
57  (cu, user_name, program)
58  VALUES
59  ('" . pg_escape_string($cu) . "',
60  '" . pg_escape_string($rowid) . "',
61  '" . pg_escape_string($pg) . "' ) ";
62  if ($exc_rs = db_query($sql, $link)) {
63  $print_msg = "Program {$pg} was turned OFF for {$rowid}";
64  } else {
65  $print_msg = "Error -- Status not changed for program {$pg}";
66  }
67  db_free_result($exc_rs);
68  }
69  break;
70  }
71  }
72 
73 
74  $sql = "SELECT programs.program, programs.displaytext,
75  programs.description, programs.def_set, exclude.user_name
76  FROM cuadminprogs as programs
77  LEFT JOIN (
78  SELECT cuadminexclude.program, cuadminexclude.user_name, cuadminexclude.cu
79  FROM cuadminexclude
80  WHERE trim(cuadminexclude.user_name) = '" . pg_escape_string($rowid) . "')
81  as exclude on exclude.program = programs.program
82  ORDER BY programs.sort_order ";
83  $prod_list = db_query($sql, $link);
84 
85  if ($print_msg != '') {
86  $print_err = "<tr><td class='msg' colspan='3' align='center'>$print_msg</td></tr>";
87  }
88  print <<< EOF
89  <form action="{$_SERVER['PHP_SELF']}" method="post">
90  <table cellpadding=3 cellspacing=0 border=0 align=center class='dmsbg' width=700>
91  <tr><td>
92  <table cellpadding=3 cellspacing=0 border=0 align=left bgcolor=white width="100%">
93  <tr><td class='bar' align=center colspan=3>
94  Credit Union's Allowed Program List
95  </td></tr>
96  $print_err
97  <tr><td class='hdr' align=right nowrap width="30%">Program</td>
98  <td class='hdr' align='center' width="5%">Allowed</td>
99  <td class='hdr' width="65%">Description</td></tr>
100 EOF;
101  $cntr = 0;
102  while($prod_row = db_fetch_array($prod_list, $cntr++)) {
103  printf ("<tr>
104  <td class=\"dtlr\" align=right valign=top>%s</td>
105  <td class=\"dtlc\" valign=top><a href=\"{$_SERVER['PHP_SELF']}?pg=%s&opt=%s&rowid=%s\" class='%s'>%s</a></td>
106  <td class=\"dtll\" align=left valign=top>%s</td>
107  </tr>\n", htmlspecialchars(trim($prod_row['displaytext'])),
108  urlencode($prod_row['program']),
109  ($prod_row['user_name'] == "" ? "off" : "on"),
110  urlencode($rowid),
111  ($prod_row['user_name'] == "" ? "" : "error"),
112  ($prod_row['user_name'] == "" ? "On" : "Off"),
113  htmlspecialchars(trim($prod_row['description'])));
114  }
115 
116 ?>
117  </table>
118  </td></tr>
119  </table>
120  </form>
121  </body>
122 </html>