Odyssey
SetFlag.prg
1 <?php
2 
3 $dms_ok=array('action'=>'string','reset_bit'=>'array', 'reset_doc'=>'array');
4 dms_import_v2($SYSENV, "SETFLAG", $dms_ok);
5 
6 $SYSENV["SETFLAG"]["helpicon"]="<img src='/IMAGES/q1.gif' border=0 alt='View Help' align='top'>";
7 $SYSENV["SETFLAG"]["helpicon2"]="<img src='/IMAGES/q2.gif' border=0 alt='View Help' align='top'>";
8 $SYSENV["SETFLAG"]["helpdoc"]="SetFlagHelp.html";
9 $SYSENV["SETFLAG"]["self"] = "$menu_link?ft=24";
10 extract($SYSENV["SETFLAG"]);
11 extract($SYSENV["TOP"]);
12 
13 $main = basename($_SERVER['SCRIPT_NAME']);
14  // Determine if we are updating flags, saving suppression list, or displaying the form
15  switch ($act) {
16  case "U2":
17  case "S":
18  case "E":
19  break;
20  default:
21  $act = "E";
22  }
23 
24  if ($act == "E"):
25  $CU = strtoupper( $Cu );
26  // get a list of any CMS popups that the member might have said not to show again;
27  // only get the ones set up for the CU and with responseon not null
28  $sql = "select docs.docsid, docs.docsname, docs.docstitle, docs.docsdesc, docs.docsresponsetype
29  from cucmsdocs docs
30  join cucmsfrags frags on frags.docsid = docs.docsid
31  and frags.cu = '{$CU}'
32  where docs.docsresponsetype in ('D', 'A', 'E', 'P')";
33  $sth = db_query($sql, $dbh);
34 
35  // save the list
36  $upgradeList = array();
37  $row = 0;
38  while ( $popRow = db_fetch_array($sth, $row++) ) {
39  $upgradeList[] = $popRow;
40  }
41 ?>
42 <script language="JAVASCRIPT">
43 <!--
44  function show_help(marker)
45 {
46 helpwin=window.open(marker,"_Help","toolbar=1,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=500,height=340");
47 helpwin.focus();
48  }
49 // -->
50  </script>
51 
52 <?php
53  if ( count( $upgradeList ) > 0 ) {
54  // separate out into list of member dismissible and CU dismissible; only the persistent ones are CU dismissible
55  $memberDismissibleList = array();
56  $cuDismissibleList = array();
57  for ( $i = 0; $i < count( $upgradeList ); $i++ ) {
58  if ( $upgradeList[$i]["docsresponsetype"] == "P" )
59  $cuDismissibleList[] = $upgradeList[$i];
60  else
61  $memberDismissibleList[] = $upgradeList[$i];
62  }
63 ?>
64  <form action="<?php echo $self ?>&act=U2" method="post">
65  <br>
66  <br>
67  <div align="center">
68  <table width="100%" border=0 cellpadding=4 cellspacing=1>
69 <?php
70  // show the member-dismissible list
71  if ( count( $memberDismissibleList ) ) {
72 ?>
73  <tr><td class="bar" colspan="2" align="center">Reset Member Pop-Ups and Promos <a href='javascript:show_help("<?php echo $helpdoc ?>#overview");'><?php echo $helpicon ?></a></td></tr>
74  <tr><td class="msg" colspan="2" align="left">
75  By default, Pop-up messages and Member-Dismissible Login Promos are shown to all members. Members may dismiss the message or promo by specifying "Don't Tell Me Again". <br><br>When you reset these flags, all members will see the related message or promo again, even if they previously checked "Don't Tell Me Again".
76  </td></tr>
77 <?php
78  for ( $i = 0; $i < count( $memberDismissibleList ); $i++ ) {
79  // get a count of the members affected
80  $sql = "SELECT count(*) FROM cucmsresponse WHERE docsid = {$memberDismissibleList[$i]["docsid"]} AND cu = '$Cu' AND responseon IS NOT NULL";
81  $rs = db_query($sql, $dbh);
82  $row = db_fetch_array($rs,0);
83  if ( $row[0] > 0 )
84  $affectedStr = "(<span style='font-style:italic;'>{$row[0]} member(s)</span>)";
85  else
86  $affectedStr = "";
87 
88  print <<< table_row
89  <tr><td class="dtl" align="left" width="70%">{$memberDismissibleList[$i]["docsdesc"]} $affectedStr</td>
90  <td class="dtll" width="30%" >
91  <input type="checkbox" name="reset_doc[]" value="{$memberDismissibleList[$i]["docsid"]}">Reset Flag
92  </td>
93  </tr>
94 table_row;
95  }
96  }
97 ?>
98 
99 <?php
100  // Show this if both lists exist
101  if ( count( $memberDismissibleList ) && count( $cuDismissibleList ) ) {
102 ?>
103  <tr><td class="msg" colspan="2">&nbsp;</td></tr>
104 <?php
105  }
106 
107  // show the CU-dismissible list
108  if ( count( $cuDismissibleList ) ) {
109 ?>
110  <tr><td class="msg" colspan="2" align="left">
111  By default, the CU-Dismissible Promos are shown to all members. It is possible for the credit union to exclude members from the CU-Dismissible Login Promo by marking their accounts (see below).<br><br>When you reset this flag, all members will see any active CU-Dismissible Promo.
112  </td></tr>
113 <?php
114  for ( $i = 0; $i < count( $cuDismissibleList ); $i++ ) {
115  $sql = "SELECT count(*) FROM cucmsresponse WHERE docsid = {$cuDismissibleList[$i]["docsid"]} AND cu = '$Cu' AND responseon IS NOT NULL";
116  $rs = db_query($sql, $dbh);
117  $row = db_fetch_array($rs,0);
118  if ( $row[0] > 0 )
119  $affectedStr = "(<span style='font-style:italic;'>{$row[0]} member(s)</span>)";
120  else
121  $affectedStr = "";
122 
123  print <<< table_row
124  <tr><td class="dtl" width="70%">{$cuDismissibleList[$i]["docsdesc"]} $affectedStr</td>
125  <td class="dtll" width="30%" >
126  <input type="checkbox" name="reset_doc[]" value="{$cuDismissibleList[$i]["docsid"]}">Reset Flag
127  </td>
128  </tr>
129 table_row;
130  }
131  }
132 ?>
133  <tr><td align="center" colspan='2' class='dtl'><input type="submit" value="Reset Selected Flags" name="submit_settings"></td></tr>
134 
135  </table>
136  </div>
137  </form>
138 <?php
139  }
140 ?>
141  <form action="<?php echo $self ?>&act=S" method="post">
142  <br>
143  <br>
144  <div align="center">
145  <table width="100%" border=0 cellpadding=4 cellspacing=1>
146  <tr><td class="bar" align="center">Exclude From CU-Dismissible Login Promo<a href='javascript:show_help("<?php echo $helpdoc ?>#NDTpromo");'><?php echo $helpicon ?></a></td></tr>
147  <?php if (is_readable("$home_path/admin/CU-Dismissible.html")): ?>
148  <tr><td class="dtlr"><a href="<?php echo $main ?>/admin/CU-Dismissible.html?ft=82" target="get_file" class="link2">View Results of Last Post </a></td></tr>
149  <?php endif; ?>
150 
151  <tr><td class="msg" align="left">
152  By default, the CU-Dismissible Login Promo is shown to all members. If you wish to exclude certain members from this promo, use the box below to enter their accounts.
153 <br><br>Insert the account numbers into this entry field, separated by a space or new line. <br>
154 If the record does not exist or cannot be updated, an error will be displayed.
155  </td></tr>
156  <tr><td valign="top" class="dtl" align="center">
157  <textarea name="accts" cols="35" rows="15"></textarea>
158  </td></tr>
159  <tr>
160  <td align="center" class="dtl"><input type="submit" value="Set Flags" name="btnEval"></td>
161  </tr>
162 
163  </table>
164  </div>
165  </form>
166 <?php
167  elseif ($act == "U2"):
168 
169  $errorList = array();
170  for ( $i = 0; $i < count($reset_doc); $i++ ) {
171  $docID = $reset_doc[$i];
172 
173  // set up the query to reset the members that have responsded to this notice
174  $sql = "UPDATE cucmsresponse SET responseon = NULL
175  WHERE docsid = $docID AND cu = '$Cu'";
176 
177  // run the query
178  $rs = db_query($sql, $dbh);
179 
180  // check the result
181  if ( !$rs ) {
182  // get the document name
183  $sql = "SELECT docsname FROM cucmsdocs WHERE docsid = $docID";
184  $rs = db_query($sql, $dbh);
185  if ( !$rs ) {
186  $errorList[] = "Error reading doc id: $docID";
187  } else {
188  $row = db_fetch_array($rs,0);
189  $errorList[] = "Error reading doc: {$row["docsname"]}";
190  }
191  }
192  }
193 
194  if ( count( $errorList ) > 0 ):
195  // reset failed, display message
196 ?>
197  <form>
198  <div align="center">
199  <table border=0 cellpadding=4 cellspacing=0>
200  <tr><td class="bar">Credit Union Message Settings</td></tr>
201  <tr><td class="dtl">Failed to reset notice settings</td></tr>
202 <?php
203  for ( $i = 0; $i < count( $errorList ); $i++ ) {
204  print "<tr><td class='dtl'>{$errorList[$i]}</td></tr>";
205  }
206 ?>
207  </table>
208  </div>
209  </form>
210 
211 <?php
212  else:
213  // Save completed, report save successful
214 ?>
215  <form>
216  <div align="center">
217  <table border=0 cellpadding=4 cellspacing=0>
218  <tr><td class="bar">Credit Union Popups and Promos Settings</td></tr>
219  <tr><td class="dtl">Settings Saved Successfully</td></tr>
220  </table>
221  </div>
222  </form>
223 <?php
224  endif;
225 
226  elseif ($act == "S"):
227  /*
228  * Get a list of any cu-Dismissible promos
229  */
230 
231  $save_msg = '';
232  $prt_msg = '';
233  $CU = strtoupper($Cu);
234  $sql = "select docs.docsid from cucmsdocs docs
235  join cucmsfrags frags on frags.docsid = docs.docsid
236  and frags.cu = '{$CU}'
237  where docs.docsresponsetype = 'P'";
238  $sth = db_query($sql, $dbh);
239 
240  if (!($sth) || db_num_rows($sth) != 1) {
241  # error - no persistent promo
242  $save_msg .= "No persistent promo found. Can't update.";
243  $prt_msg .= "No persistent promo found. Can't update.";
244  } else {
245  list($docID) = db_fetch_array($sth, 0);
246  }
247 
248  // SAVE OPTION
249  // Replace common delimiter characters with a space,
250  // Separate each of the accounts into an array, then
251  // loop through the array and build the sql
252 
253  $form_accts = array();
254  $delims = array("\r\n", "\t", ";", ",");
255  $form_accts = explode(" ", str_replace($delims, " ", $_POST['accts']));
256 
257  for ($idx = 0; $idx < count($form_accts); $idx++) {
258 
259  $member = $form_accts[$idx];
260  if (trim($member) <> '') {
261  if (strlen(trim($member)) > 0 && preg_match("/^\d\d*$/", $member)) {
262 
263  /* * *********
264  // NOTE: This is not yet implemented. The logic will need to know which document is being referenced for
265  // exclusion and then loop through cucmsresponse to set the current date on any members requested.
266  // If the member isn't in the table already for the document id, credit union, they will need to be added.
267  *
268  */
269  # first see if the cuuser record exists -
270  $upd_sql = "SELECT user_name from cuusers WHERE cu='" . prep_save($CU) . "'
271  and user_name = '" . prep_save($member) . "'; ";
272  $updateRs = db_query($upd_sql, $dbh);
273 
274  if (db_num_rows($updateRs) === 0) {
275  $save_msg .= "Invalid member $member (no Digital Banking record)<br>\n";
276  $prt_msg .= "Invalid member $member (no Digital Banking record)<br>\n";
277  } else {
278 
279  # call update-notice to set "response" for this member.
280  // ** NO RECORD exists in cucmsresponse
281  $upd_sql = "INSERT INTO cucmsresponse (docsid, cu, accountnumber, responseon)
282  (SELECT " . intval($docID) . ", '" . prep_save($CU) . "',
283  '" . prep_save($member) . "', current_date
284  WHERE NOT EXISTS (SELECT (docsid, cu, accountnumber)
285  FROM cucmsresponse as cur
286  WHERE cur.docsid = " . intval($docID) . "
287  AND cur.cu = '" . prep_save($CU) . "'
288  AND cur.accountnumber = '" . prep_save($member) . "' ) ); ";
289 
290  $updateRs = db_query($upd_sql, $dbh);
291  if (db_affected_rows($updateRs) === 0) {
292  // ** NO Rows affected -- NO INSERT -- SO UPDATE INSTEAD
293  // ** UPDATE
294  // ** If the cucmsresponse record exist, but the responsedate is NULL, then I need
295  $upd_sql = "UPDATE cucmsresponse
296  SET responseon = current_date
297  WHERE docsid = " . intval($docID) . "
298  AND cu = '" . prep_save($CU) . "'
299  AND accountnumber = '" . prep_save($member) . "' ";
300  $updateRs = db_query($upd_sql, $dbh);
301 
302  if (!updateRs) {
303  $save_msg .= "Update FAILED Member $member <br>\n";
304  $prt_msg .= "Update FAILED Member $member <br>\n";
305  }
306  }
307  $prt_msg .= "Member $member updated<br>\n";
308  }
309  } else {
310  $save_msg .= "Invalid member $member (empty or non-numeric)<br>\n";
311  $prt_msg .= "Invalid member $member (empty or non-numeric)<br>\n";
312  }
313  }
314  }
315 # create file to save $prt_msg
316 
317  $tabfile = "$home_path/admin/CU-Dismissible.html";
318  $tabhdr = "<HTML><HEAD>
319  <TITLE>Last CU-Dismissible Promo Exclusions</TITLE></HEAD>
320  <BODY>Posted by $Cn " . date("r") . "<BR><BR>";
321  $tabtrl = "</BODY></HTML>";
322 
323 
324  $STATFILE = fopen("$tabfile", "w");
325 
326 
327  fwrite($STATFILE, "$tabhdr");
328  fwrite($STATFILE, "$prt_msg");
329  fwrite($STATFILE, "$tabtrl");
330  fclose($STATFILE);
331 
332  print "<div align='center'><table border=0 cellpadding=4 cellspacing=0>
333  <tr>
334  <td class='bar'>Credit Union Popups and Promos Settings</td>
335  </tr>
336 <tr><td class='dtlr'><a href='$main/admin/CU-Dismissible.html?ft=82' target='get_file' class='link2'>View Full Results </a></td></tr>";
337  if (trim($save_msg) == '') {
338  print "<tr><td class='dtl'>Settings Saved Successfully</td></tr>";
339  } else {
340  print "<tr><td class='dtl'>$save_msg</td></tr>";
341  }
342  print "</table></div>";
343 
344 endif;
345 
346 
347 ?>