Odyssey
monitorFunctions.i
1 <?php
2 /**
3  * This function will return the master list of available languages that HomeCU
4  * may use.
5  *
6  * @return array
7  */
8 function returnMasterLanguageList() {
9  $retVal = Array('en_US' => 'English', 'es_US' => 'Spanish', 'pl_US' => 'Polish');
10  return $retVal;
11 }
12 
13 function cu_footer() {
14  echo '</body></html>';
15 }
16 
17 function cu_header($title, $focus="") {
18 
19  global $cu;
20  global $chome;
21  global $Flite;
22  global $CU2_FRAMEFREE;
23  global $Fset2;
24 
25  echo '<!DOCTYPE html>
26 <head>
27 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />';
28 
29  if ("$chome" != "") {
30  if ($Flite == "1") {
31  $mstyle=(is_readable("/home/${chome}/public_html/lindex.css")
32  ? "/lindex.css"
33  : "/mindex.css");
34  } elseif (($Fset2 & $CU2_FRAMEFREE) == $CU2_FRAMEFREE ) {
35  $mstyle=(is_readable("/home/${chome}/public_html/findex.css")
36  ? "/findex.css"
37  : "/mindex.css");
38  } else { $mstyle = "/mindex.css"; }
39  echo '<link rel=stylesheet href="/~' . $chome . $mstyle . '"
40  type="text/css">';
41  } else {
42  echo '<link rel=stylesheet href="/monitor/css/monitor.css" type="text/css">';
43  }
44  echo "<title>$title</title>
45  <meta name = 'format-detection' content = 'telephone=no'>
46  </head>";
47  if ("$focus" == "") {
48  echo "<body>";
49  } else {
50  echo "<body onLoad=\"self.focus();document.$focus.focus()\">";
51  }
52  }
53 
54 function cu_message($msg) {
55  echo '<table>';
56  echo '<tr><td>';
57  echo "$msg";
58  echo '</tr></td>';
59  echo '</table>';
60  }
61 
62 
63  // This will display fields to be shown, but will escape all html tags
64 function dms_disphtml($text,$charset='ISO-8859-1') {
65  return htmlspecialchars(trim($text),ENT_COMPAT,$charset);
66 }
67 
68 function disp_i18n($msg,$mode=ENT_COMPAT) {
69  # Polish characters are passed as numeric entity codes
70  # be sure any existing codes in the text are passed unchanged
71  # translate the htmlspecial character
72  $msg=htmlspecialchars(trim($msg),$mode);
73  # and then put back the numeric entity codes
74  $msg=str_replace('&amp;#','&#',$msg);
75  return $msg;
76  }
77 
78  // This will take a date in any format and verify it is a valid date
79  function isdate($pDate) {
80  /*
81  // This code was replaced -- it was prone to errors in the differences of date values
82 
83  $m_val = date("m", strtotime($pDate));
84  $d_val = date("d", strtotime($pDate));
85  $y_val = date("Y", strtotime($pDate));
86  return checkdate($m_val, $d_val, $y_val);
87  */
88  // This is now limited to the date format MM/DD/YYYY
89  if (preg_match("#^([0-9]{1,2})[/.-]{1}([0-9]{1,2})[/.-]{1}([0-9]{2,4})$#", $pDate, $regs)) {
90  $m_val = $regs[1];
91  $d_val = $regs[2];
92  $y_val = $regs[3];
93  return checkdate($m_val, $d_val, $y_val);
94  } else {
95  return false;
96  }
97  }
98 
99 /*
100  Purpose: This function will do double duty. It will validate
101  a date that is passed in one variable such as MM/DD/YYYY
102  AND it should also be able to accept the date in pieces in
103  three separte parameters
104 */
105 // function dms_checkdate($month, $day=false, $year=false) {
106 function dms_checkdate() {
107 
108  $retval = true; // START THE FUNCTION TO RETURN TRUE
109 
110  // ** FIRST -- Determine if we are assuming 3 pieces or 1 full date piece
111  if (func_num_args() == 1) {
112  $date_arg = func_get_arg(0);
113  // ** EXPECT THE DATE TO BE ONE FULL DATE in the month variable MM/DD/YYYY -- separator may be [/-.]
114  // ** BREAK THE PIECES APART
115  if (preg_match("#^([0-9]{1,2})[/-]{1}([0-9]{1,2})[/-]{1}([0-9]{2,4})$#", $date_arg, $regs)) {
116  $m_val = $regs[1];
117  $d_val = $regs[2];
118  $y_val = $regs[3];
119  } else {
120  $retval = false;
121  }
122  } elseif (func_num_args() == 3) {
123  $arg_date = func_get_args();
124  // ** Expect the date to be parsed into the 3 different parameters -- verify the pieces match and contain no string
125  if ((strval(intval($arg_date[0])) != strval($arg_date[0])) || (strval(intval($arg_date[1])) != strval($arg_date[1])) || (strval(intval($arg_date[2])) != strval($arg_date[2]))) {
126  $retval = false;
127  } else {
128  $m_val = $arg_date[0];
129  $d_val = $arg_date[1];
130  $y_val = $arg_date[2];
131  }
132  } else {
133  // ALL OTHER CASES -- RETURN FALSE
134  $retval = false;
135  }
136  // ** If the return value is true then we have the values we want, now check the date
137  if ($retval) {
138  // Seemed to pass the first exercise, now test to see if the actual checkdate is correct
139  $retval = checkdate(intval($m_val), intval($d_val), intval($y_val));
140  }
141 
142  return $retval;
143 }
144 
145