4 # Axis--StandardLibrary.php
5 # A Collection of Utility Routines
7 # Copyright 1999-2002 Axis Data
8 # This code is free software that can be used or redistributed under the
9 # terms of Version 2 of the GNU General Public License, as published by the
10 # Free Software Foundation (http://www.fsf.org).
12 # Author: Edward Almasy (almasy@axisdata.com)
14 # Part of the AxisPHP library v1.2.4
15 # For more information see http://www.axisdata.com/AxisPHP/
19 # (accepts a date string in the form YYYY-MM-DD and adds or subtracts days)
23 $Pieces = explode(
"-", $DateString);
25 # convert to value of date in seconds (a la Unix timestamp)
26 $DateInSeconds = mktime(1, 1, 1, $Pieces[1], $Pieces[2], $Pieces[0]);
28 # perform date arithmetic
29 $DateInSeconds = $DateInSeconds + ($DaysToAdd * (60 * 60 * 24));
31 # return YYYY-MM-DD date string to caller
32 return date(
"Y-m-d", $DateInSeconds);
37 return htmlentities($String);
42 $TranslationTable = get_html_translation_table(HTML_ENTITIES);
43 $TranslationTable = array_flip($TranslationTable);
44 return strtr($String, $TranslationTable);
58 <title><?php printf(
"%s", $Title); ?></title>
59 <meta http-equiv=
"refresh" content=
"0; URL=<?php print($NewUrl); ?>">
61 <body bgcolor=
"white">
65 <script language=
"php">
70 if (($Number > 10) && ($Number < 20))
76 $Digit = $Number % 10;
100 return $Number.GetOrdinalSuffix($Number);
119 return $MonthNames[$MonthNumber];
123 $SelectedValue = NULL,
124 $SubmitOnChange =
"",
126 $PrintEvenIfEmpty = 1,
127 $MultipleAllowed =
false,
128 $OnChangeAction = NULL,
130 $DisabledOptions = NULL)
132 if ((count(
$Items) > 0) || $PrintEvenIfEmpty)
134 # determine forced display width for option list (if needed)
138 if (is_numeric($Width))
140 $ForcedWidthAttrib =
" style=\"width: ".$Width.
"px;\"";
143 # width given with type specifier (%, px, etc)
146 $ForcedWidthAttrib =
" style=\"width: ".$Width.
";\"";
153 $MatchingCharThreshold = 11;
154 $MaxMatchingChars = $MatchingCharThreshold;
155 foreach ($Labels as $Label)
157 if (isset($PreviousLabel))
159 $Len = ($MaxMatchingChars + 1);
160 while (substr($Label, 0, $Len) ==
161 substr($PreviousLabel, 0, $Len)
162 && ($Len < strlen($Label)))
164 $MaxMatchingChars = $Len;
168 $PreviousLabel = $Label;
170 if ($MaxMatchingChars > $MatchingCharThreshold)
172 $ExtraCharsToDisplayBeyondMatch = 6;
173 $ForcedWidth = $MaxMatchingChars + $ExtraCharsToDisplayBeyondMatch;;
174 $ForcedWidthAttrib =
" style=\"width: ".$ForcedWidth.
"ex;\"";
178 $ForcedWidthAttrib =
" style=\"width: auto;\"";
182 # print option list begin
183 print(
"<select name=\"".$ResultVar.
"\""
184 .
" size=\"".$Size.
"\""
185 .
" id=\"".$ResultVar.
"\""
186 .($SubmitOnChange ?
" onChange=\"submit()\"" :
"")
187 .($OnChangeAction ?
" onChange=\"".$OnChangeAction.
"\"" :
"")
188 .($MultipleAllowed ?
" multiple" :
"")
192 # for each element in list
194 while (list($Value, $Label) = each(
$Items))
196 # print option list item
197 printf(
" <option value=\"%s\"", htmlspecialchars($Value));
198 if ((is_array($SelectedValue) && in_array($Value, $SelectedValue))
199 || ($Value == $SelectedValue)) { printf(
" selected"); }
200 if ( !is_null($DisabledOptions)
201 && isset($DisabledOptions[$Label]))
208 # print option list end
209 printf(
"</select>\n");
215 # if no date passed in
216 if (($Year == -1) && ($AllowNullDate))
218 # if null date allowed
235 # if date string passed in
236 if ((strlen($Year) > 4) && ($Month == -1))
238 # split into component parts
239 list($Year, $Month, $Day) = split(
"[-/]", $Year);
242 # print option list for months if month value supplied
246 print(
"\n <select name=\"".$FieldPrefix.
"Month\""
247 .
" id=\"".$FieldPrefix.
"Month\""
248 .($SubmitOnChange ?
" onChange='submit()'" :
"")
252 print(
"<option value='0'>--</option>\n");
256 if ($Index == $Month)
258 printf(
" <option value='%s' selected>%s</option>\n", $Index,
GetMonthName($Index));
262 printf(
" <option value='%s'>%s</option>\n", $Index,
GetMonthName($Index));
266 printf(
" </select>\n");
269 # print option list for days if day value supplied
273 print(
"\n <select name=\"".$FieldPrefix.
"Day\""
274 .
" id=\"".$FieldPrefix.
"Day\""
275 .($SubmitOnChange ?
" onChange='submit()'" :
"")
279 print(
"<option value='0'>--</option>\n");
285 printf(
" <option value='%s' selected>%s</option>\n", $Index,
GetOrdinalNumber($Index));
289 printf(
" <option value='%s'>%s</option>\n", $Index,
GetOrdinalNumber($Index));
293 printf(
" </select>\n");
296 # print option list for years
297 $Index = date(
"Y") - 45;
298 $EndIndex = $Index + 45;
299 print(
"\n <select name=\"".$FieldPrefix.
"Year\""
300 .
" id=\"".$FieldPrefix.
"Year\""
301 .($SubmitOnChange ?
" onChange='submit()'" :
"")
305 print(
"<option value='0'>--</option>\n");
307 while ($Index <= $EndIndex)
311 printf(
" <option value=\"%s\" selected>%s</option>\n", $Index, $Index);
315 printf(
" <option value=\"%s\">%s</option>\n", $Index, $Index);
319 printf(
" </select>\n");
324 # use current date if no date passed in
331 # print option list for hours if hour value supplied
333 print(
"\n <select name=\"".$FieldPrefix.
"Hour\" id=\"".$FieldPrefix.
"Hour\">\n");
338 printf(
" <option value='%s' selected>%d</option>\n", $Index, $Index);
342 printf(
" <option value='%s'>%d</option>\n", $Index, $Index);
346 printf(
" </select>\n");
348 # print option list for minutes if minute value supplied
352 print(
"\n <select name=\"".$FieldPrefix.
"Minute\" id=\"".$FieldPrefix.
"Minute\">\n");
355 if ($Index == $Minute)
357 printf(
" <option value='%s' selected>%02d</option>\n", $Index, $Index);
361 printf(
" <option value='%s'>%02d</option>\n", $Index, $Index);
365 printf(
" </select>\n");
371 # split string on newlines
372 $Pieces = explode(
"\n", $String);
374 # for each line in string
376 for ($Index = 0; $Index < count($Pieces); $Index++)
378 # save length if longer than current max
379 if (strlen($Pieces[$Index]) > $MaxLen)
381 $MaxLen = strlen($Pieces[$Index]);
385 # return length of longest segment to caller
389 function PrintOptionListFromDB($DB, $Table, $Condition, $SortBy, $ResultVar, $ValueQuery, $LabelQuery, $SelectedValue, $Size = 1, $SubmitOnChange =
"", $PrintEvenIfEmpty = 0)
391 # set up condition and sorting parameters
392 if ($Condition !=
"") { $Condition =
"WHERE ".$Condition; }
393 if ($SortBy !=
"") { $SortBy =
"ORDER BY ".$SortBy; }
395 # grab records to be listed from database
396 $QueryString = sprintf(
"SELECT * FROM %s %s %s",
397 $Table, $Condition, $SortBy);
398 $DB->Query($QueryString);
400 # if records were found
401 if ($DB->NumRowsSelected() > 0)
403 # build array of items
404 while ($Row = $DB->FetchRow())
406 $Items[$Row[$ValueQuery]] = $Row[$LabelQuery];
409 # sort array if not already sorted
410 if ($SortBy ==
"") { asort(
$Items); }
LongestStringLineLength($String)
PrintOptionListsOfTimeComponents($FieldPrefix, $Hour=-1, $Minute=-1)
GetMonthName($MonthNumber)
PrintOptionListFromDB($DB, $Table, $Condition, $SortBy, $ResultVar, $ValueQuery, $LabelQuery, $SelectedValue, $Size=1, $SubmitOnChange="", $PrintEvenIfEmpty=0)
GetHtmlEscapedString($String)
GetUnHtmlEscapedString($String)
PHP CalcDate($DateString, $DaysToAdd)
GetOrdinalSuffix($Number)
GetOrdinalNumber($Number)
PrintOptionListsOfDateComponents($FieldPrefix, $AllowNullDate=0, $Year=-1, $Month=-1, $Day=-1, $SubmitOnChange="")
PrintAutoRefreshPage($Title, $NewUrl)
PrintOptionList($ResultVar, $Items, $SelectedValue=NULL, $SubmitOnChange="", $Size=1, $PrintEvenIfEmpty=1, $MultipleAllowed=false, $OnChangeAction=NULL, $Width=NULL, $DisabledOptions=NULL)