Odyssey
BannerMntc.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('action'=>'string','AddChange'=>'string', 'msg'=>'string',
16 'sname'=>'string','sstart'=>'string','sstop'=>'string','banner'=>'string',
17 'todelete'=>'string','bannertext'=>'string','rowid'=>'string','stype'=>'digits');
18 dms_import($dms_ok);
19 $cu = strtoupper(prep_save($rowid, 10));
20 
21 $banner = (empty($banner) ? "" : trim($banner));
22 $self = $_SERVER['PHP_SELF'] ;
23 
24 $action = (empty($action) ? "ok" : $action);
25 $action = strtolower($action);
26 $action = trim($action);
27 
28 $msg = (empty($msg) ? "NO MESSAGE" : $msg);
29 
30 $today = date("m/d/Y");
31 $oneyear = date("m/d/Y",mktime (0,0,0,date("m"),date("d"),date("Y")+1));
32 
33 switch ($action) {
34  case "yes":
35  banner_update("delete");
36  break;
37  case "delete":
38  confirm($banner, $action);
39  break;
40  case "add":
41  case "save":
42  banner_update("$action");
43  break;
44  case "no":
45  $banner="";
46  case "ok":
47  getbanner("$msg");
48  break;
49  }
50 
51 //exit;
52 
53 function banner_update($action) {
54  global $banner;
55  global $stype;
56  global $sname;
57  global $sstart;
58  global $sstop;
59  global $bannertext;
60 
61  global $Cn;
62  global $cu;
63  global $rowid;
64  global $self;
65  global $today;
66  global $oneyear;
67  global $link;
68 
69  $msg = "";
70 
71 
72 if ($action == "add" || $action == "save") {
73  $sname = (trim($sname) == "" ? "" : $sname);
74  $sstart = (trim($sstart) == "" ? "$today" : $sstart);
75  $sstop = (trim($sstop) == "" ? "$oneyear" : $sstop);
76  $bannertext = (trim($bannertext) == "" ? "" : $bannertext);
77 
78  # need to check start and stop dates here
79  if (trim($banner) == ""){ $msg .= "Please Select a Banner<br>\n"; }
80  if (trim($bannertext) == ""){ $msg .= "Please Specify Banner Text<br>\n"; }
81  if (preg_match("/^ *$/",$banner)) { $msg .= "Invalid Banner ID<br>\n";}
82  if (($starttime = strtotime($sstart)) === -1) {
83  $msg .= "Invalid Start Date<br>\n";
84  } else {
85  list($mm,$dd,$yyyy) = explode("/",$sstart);
86  if (!dms_checkdate("$mm", "$dd", "$yyyy")) {
87  $msg .= "Invalid Start Date<br>\n";}
88  }
89  if (($stoptime = strtotime($sstop)) === -1) {
90  $msg .= "Invalid Stop Date<br>\n";
91  } else {
92  list($mm,$dd,$yyyy) = explode("/",$sstop);
93  if (!dms_checkdate("$mm", "$dd", "$yyyy")) {
94  $msg .= "Invalid Stop Date<br>\n";}
95  }
96  if ($starttime > $stoptime) {
97  $msg .= "Start Date must be before Stop Date<br>\n";}
98 
99  }
100 
101  // ** MWS - 1 - Replace any " (double) with ' (single) quotes
102  // ** 2 - Test the banner script using eval as is done in ShowBanner.i, in hopes of finding problems.
103 
104  // Banner
105  $bannertext = str_replace('"', "'", $bannertext);
106 
107  // Try to catch a syntax error
108  // ** We need slashes stripped from the bannertext first
109  $testbannertext=stripslashes($bannertext);
110 
111  if (php_syntax_error("\$bannertext=sprintf ('%s',\"$testbannertext\");")) {
112  $msg .= "There is a problem with the syntax of the banner text you entered. Please review the text and look for any double quotes or declaration of php variables that may have caused the problem.<br>";
113  }
114 
115  if ($msg == ""){
116  switch ($action) {
117  case "delete":
118  $what = "Deleted";
119  $sql = "delete from cusurveymaster
120  where surveyid='" . intval($banner) . "' and cu='$cu';";
121  break;
122  case "save":
123  $what = "Updated";
124  $sql= "update cusurveymaster set
125  startdate='$sstart', stopdate='$sstop',
126  surveyname='$sname',
127  question='" . prep_save($bannertext) . "',
128  qstyle='3', runstat=1,
129  employee='Y', inc_balances='Y',
130  surveytype = $stype,
131  dontshow = 'Y'
132  where surveyid='" . intval($banner) . "' and cu='$cu'";
133 
134 
135  break;
136 
137  case "add":
138  $what = "Added";
139  $sql = "insert into cusurveymaster (cu,surveyid, startdate,
140  stopdate, surveyname, question, qstyle,
141  runstat, employee, surveytype, dontshow, inc_balances)
142  values (
143  '$cu',nextval('cusurveymaster_surveyid_seq'),'$sstart',
144  '$sstop','$sname','" . prep_save($bannertext) . "', '3',
145  1, 'Y',$stype,'Y','Y');";
146 #
147  break;
148  }
149 
150  $sth = db_query($sql,$link);
151  $msg = pg_errormessage();
152  if (!$sth) {
153  require("errormail.i");
154  $notify = new ErrorMail;
155  $notify->line=__LINE__;
156  $notify->file=__FILE__;
157  $notify->callingfunction = __FUNCTION__;
158  $notify->error=$msg;
159  $notify->cu="$cu";
160  $notify->banner="$banner";
161  $notify->sql="$sql";
162  $notify->SendErr();
163  }
164  if ($msg == "") { update_success($what);}
165 
166  db_free_result($sth);
167  }
168  if ($msg) {
169  switch ($action) {
170  case "delete":
171  $banner="";
172  case "add":
173  case "save":
174  default:
175  getbanner($msg);
176  break;
177  }
178 }
179 }
180 function getbanner($msg) {
181 
182 global $self;
183 global $Cn;
184 global $cu;
185 global $rowid;
186 global $banner;
187 global $bannertext;
188 global $AddChange;
189 global $today;
190 global $oneyear;
191 global $sname;
192 global $sstart;
193 global $sstop;
194 global $link;
195 
196 header("Expires: Sat 20 May 1995 03:32:38 GMT");
197 header("Pragma: no-cache");
198 header("Cache-Control: no-cache, must-revalidate");
199 
200 cu_header("Banner Maintenance");
201 print <<<EOF
202 <script language="JAVASCRIPT">
203 <!--
204  function show_preview(sform)
205 {
206 var marker="BannerView?cu=$cu";
207 viewwin=window.open("","_Preview","toolbar=1,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=600,height=380");
208 document.viewform.viewtext.value=sform.bannertext.value;
209 document.viewform.submit();
210 viewwin.focus();
211  }
212 
213 function validate(mode,sform)
214 {
215  var strSurvey = sform.banner.value;
216  var strBanner = sform.bannertext.value;
217  var strMessage = "";
218  var patSpaces = /^ *$/;
219 
220  // validate user entries
221 
222  if (strSurvey.length == 0)
223  { strMessage += "Please Select a Banner Number.\\n";}
224  if (strBanner.length == 0)
225  { strMessage += "Please Specify Banner Text.\\n";}
226  if (patSpaces.exec(strSurvey) != null)
227  { strMessage += "Invalid Banner Number.\\n";}
228  if (strSurvey.indexOf("'") != -1 || strSurvey.indexOf('"') != -1)
229  { strMessage += "Invalid Characters in Banner Number.\\n";}
230 
231 
232  if (strMessage.length > 0)
233  {
234  alert(strMessage);
235  return false;
236  } else {
237  sform.action.value=mode;
238  sform.submit();
239 
240  return true;
241  }
242 
243 }
244 // -->
245 </script>
246 EOF;
247 
248  $sql= "select surveyid,
249  to_char(startdate,'mm/dd/yyyy'),
250  to_char(stopdate,'mm/dd/yyyy'),
251  question,
252  surveytype
253  from cusurveymaster
254  where cu='$cu'
255  and surveytype in (2,3)
256  order by surveytype";
257 
258  $sth = db_query($sql,$link);
259 
260 $blist = array();
261 
262  for ($row=0;list($banner,$sstart,$sstop,$bannertext,$stype) = db_fetch_array($sth,$row); $row++) {
263 
264  $blist[$stype][0]=$banner;
265  $blist[$stype][1]=$sstart;
266  $blist[$stype][2]=$sstop;
267  $blist[$stype][3]=$bannertext;
268  }
269  if ("$msg" != "NO MESSAGE") {
270  print <<<EOF
271  <table width=95% cellspacing=1 cellpadding=4 border=0>
272  <tr><td class="ahd" align='center'><img src='/monitor/images/alert.black.gif'>&nbsp;
273 $msg</td></tr></table>
274 EOF;
275  }
276 print <<<EOF
277 <form name='viewform' action='BannerView?cu=$cu&chome=$rowid' method='POST' target='_Preview'>
278 <input type='hidden' name='viewtext' value=''>
279 <input type='hidden' name='cu' value='$cu'>
280 <input type='hidden' name='chome' value='$rowid'>
281 </form>
282 EOF;
283 for ($stype=2;$stype < 3; $stype++) { // Desktop is apparently 2 and mobile is apparently 3 so change the limit from 4 to 3 to remove the mobile banner.
284  list ($banner, $sstart,$sstop,$bannertext) = $blist[$stype];
285  $AddChange = ($blist[$stype][0] == "" ? "Add" : "Save");
286  $banner = ($AddChange == "Add" ? "new" : $banner);
287  $sstart = (trim($sstart) == "" ? "$today" : $sstart);
288  $sstop = (trim($sstop) == "" ? "$oneyear" : $sstop);
289  $sname = ($stype == 2 ? "Desktop" : "Mobile");
290  print <<<EOF
291  <div align=center><br><form name='${sname}form' action='$self'>
292  <table width=95% cellspacing=1 cellpadding=4 border=0>
293  <tr><td class='bar' colspan=2 align=center>$cu $sname Banner</td></tr>
294  <tr><td class='dtll' width='50%'>&nbsp;</td>
295  <td class='dtll'>
296 EOF;
297 if ($banner != "new") {
298  print <<<EOF
299 <a href="$self?rowid=$rowid&banner=$banner&action=delete&sname=$sname">&nbsp;Delete&nbsp;</a>&nbsp;|&nbsp;<a href="javascript:show_preview(document.${sname}form)"> &nbsp;View&nbsp;</a>
300 EOF;
301 } else { print "&nbsp;";}
302  print <<<EOF
303  </td></tr>
304  <tr><td class='dtlc' valign=top colspan='2'>
305  <textarea cols='60' rows='6' wrap='virtual' name='bannertext'>$bannertext</textarea>
306  </td></tr>
307  <tr>
308  <td class='dtlr'>Effective Dates: </td>
309  <td class='dtll'>&nbsp;
310  <input type=text name='sstart' size='10' maxlength='10' value='$sstart'>
311  &nbsp;to&nbsp;
312  <input type=text name='sstop' size='10' maxlength='10' value='$sstop'>
313  </td>
314  </tr>
315  <tr><td class='dtlc' colspan='2'>
316 <input type='hidden' name='stype' value='$stype'>
317 <input type='hidden' name='rowid' value='$rowid'>
318 <input type='hidden' name='banner' value='$banner'>
319 <input type='hidden' name='action' value='$AddChange'>
320 <input type=hidden name='AddChange' value='$AddChange'>
321 <hr width=50%><br>
322  <input type=button value='$AddChange' onClick="validate('$AddChange',this.form);">
323 </td></tr></table></form>
324 EOF;
325 }
326 
327 }
328 
329 function confirm($banner, $action) {
330 global $self;
331 global $Cn;
332 global $cu;
333 global $rowid;
334 global $sname;
335 
336  if (!$banner) {
337  getbanner("You must select a banner type");
338  return;
339  }
340 header("Expires: Sat 20 May 1995 03:32:38 GMT");
341 header("Pragma: no-cache");
342 header("Cache-Control: no-cache, must-revalidate");
343 cu_header("Banner Maintenance");
344  $sname = (trim($sname) == "" ? "" : stripslashes($sname));
345 
346  print <<<EOF
347  <div align=center><br><form name="form1" action="$self">
348  <input type="hidden" name="rowid" value="$rowid">
349  <table width=90% cellspacing=0 cellpadding=4 border=0>
350  <tr><td class="bar" colspan=2 align=center>$cu Banner</td></tr>
351 
352 <tr><td class='ahd' colspan=2 align=center>Warning! This will delete the $sname banner for $cu. Do you wish to continue?</td></tr>
353 
354  <tr><td class="hdr" colspan=2><hr></td>
355  <tr><td class="hdr" align=right>
356  <input type=submit name="action" value="Yes">
357  </td>
358  <td class="hdr" align=left>
359  <input type=submit name="action" value="No">
360  </td>
361  </tr>
362  </table>
363  <input type=hidden name="banner" value="$banner">
364  <input type=hidden name="todelete" value="delete">
365  </form></div>
366 EOF;
367 }
368 
369 function update_success($what) {
370 global $banner;
371 global $rowid;
372 global $self;
373 global $main_url;
374  $msg=urlencode("Banner $what Successfully");
375  header("Location: $main_url?rowid=$rowid&msg=$msg");
376 }
377 function disp_msg($msg,$mode) {
378 # return htmlspecialchars(trim(stripslashes($msg)));
379  switch ($mode) {
380  case 'en':
381  $msg=htmlentities(trim(stripslashes($msg)),ENT_QUOTES);
382  break;
383  case 'sc':
384  default:
385  # translate the htmlspecial character
386  $msg=htmlspecialchars(trim(stripslashes($msg)));
387  break;
388  }
389  # and then put back the numeric entity codes
390  $msg=str_replace('&amp;#','&#',$msg);
391  return $msg;
392 }
393 function error_exit($reason) {
394 global $pg_ttl;
395  print <<<EOF
396  <CENTER><BR>
397  <TABLE BORDER=0 CELLPADDING=6 WIDTH=90%>
398 <tr><td CLASS="bar" align="center">$cu $pg_ttl
399 </td></tr><tr>
400  <td class='hdr' align='center'>
401  Unable to complete your request</td></tr>
402  <tr><td class='dtl' align='center'>
403  ${reason}.
404  </td></tr></table>
405 EOF;
406 exit;
407 }
408 /**
409  * Check the syntax of some PHP code.
410  * @param string $code PHP code to check.
411  * @return boolean|array If false, then check was successful, otherwise an array(message,line) of errors is returned.
412  */
413 function php_syntax_error($code){
414  $braces=0;
415  $inString=0;
416  foreach (token_get_all('<?php ' . $code) as $token) {
417  if (is_array($token)) {
418  switch ($token[0]) {
419  case T_CURLY_OPEN:
420  case T_DOLLAR_OPEN_CURLY_BRACES:
421  case T_START_HEREDOC: ++$inString; break;
422  case T_END_HEREDOC: --$inString; break;
423  }
424  } else if ($inString & 1) {
425  switch ($token) {
426  case '`': case '\'':
427  case '"': --$inString; break;
428  }
429  } else {
430  switch ($token) {
431  case '`': case '\'':
432  case '"': ++$inString; break;
433  case '{': ++$braces; break;
434  case '}':
435  if ($inString) {
436  --$inString;
437  } else {
438  --$braces;
439  if ($braces < 0) break 2;
440  }
441  break;
442  }
443  }
444  }
445  $inString = @ini_set('log_errors', false);
446  $token = @ini_set('display_errors', true);
447  ob_start();
448  $braces || $code = "if(0){{$code}\n}";
449  if (eval($code) === false) {
450  if ($braces) {
451  $braces = PHP_INT_MAX;
452  } else {
453  false !== strpos($code,CR) && $code = strtr(str_replace(CRLF,LF,$code),CR,LF);
454  $braces = substr_count($code,LF);
455  }
456  $code = ob_get_clean();
457  $code = strip_tags($code);
458  if (preg_match("'syntax error, (.+) in .+ on line \d+)$'s", $code, $code)) {
459  $code[2] = (int) $code[2];
460  $code = $code[2] <= $braces
461  ? array($code[1], $code[2])
462  : array('unexpected $end' . substr($code[1], 14), $braces);
463  } else $code = array('syntax error', 0);
464  } else {
465  ob_end_clean();
466  $code = false;
467  }
468  @ini_set('display_errors', $token);
469  @ini_set('log_errors', $inString);
470  return $code;
471 }