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);
57 <title><?php printf(
"%s", $Title); ?></title>
58 <meta http-equiv=
"refresh" content=
"0; URL=<?php print($NewUrl); ?>">
60 <body bgcolor=
"white">
68 if (($Number > 10) && ($Number < 20))
74 $Digit = $Number % 10;
98 return $Number.GetOrdinalSuffix($Number);
117 return $MonthNames[$MonthNumber];
121 $SelectedValue = NULL,
122 $SubmitOnChange =
"",
124 $PrintEvenIfEmpty = 1,
125 $MultipleAllowed =
false,
126 $OnChangeAction = NULL,
128 $DisabledOptions = NULL)
130 if ((count(
$Items) > 0) || $PrintEvenIfEmpty)
132 # determine forced display width for option list (if needed) 136 if (is_numeric($Width))
138 $ForcedWidthAttrib =
" style=\"width: ".$Width.
"px;\"";
141 # width given with type specifier (%, px, etc) 144 $ForcedWidthAttrib =
" style=\"width: ".$Width.
";\"";
151 $MatchingCharThreshold = 11;
152 $MaxMatchingChars = $MatchingCharThreshold;
153 foreach ($Labels as $Label)
155 if (isset($PreviousLabel))
157 $Len = ($MaxMatchingChars + 1);
158 while (substr($Label, 0, $Len) ==
159 substr($PreviousLabel, 0, $Len)
160 && ($Len < strlen($Label)))
162 $MaxMatchingChars = $Len;
166 $PreviousLabel = $Label;
168 if ($MaxMatchingChars > $MatchingCharThreshold)
170 $ExtraCharsToDisplayBeyondMatch = 6;
171 $ForcedWidth = $MaxMatchingChars + $ExtraCharsToDisplayBeyondMatch;;
172 $ForcedWidthAttrib =
" style=\"width: ".$ForcedWidth.
"ex;\"";
176 $ForcedWidthAttrib =
" style=\"width: auto;\"";
180 # print option list begin 181 print(
"<select name=\"".$ResultVar.
"\"" 182 .
" size=\"".$Size.
"\"" 183 .
" id=\"".$ResultVar.
"\"" 184 .($SubmitOnChange ?
" onChange=\"submit()\"" :
"")
185 .($OnChangeAction ?
" onChange=\"".$OnChangeAction.
"\"" :
"")
186 .($MultipleAllowed ?
" multiple" :
"")
190 # for each element in list 192 while (list($Value, $Label) = each(
$Items))
194 # print option list item 195 printf(
" <option value=\"%s\"", htmlspecialchars($Value));
196 if ((is_array($SelectedValue) && in_array($Value, $SelectedValue))
197 || ($Value == $SelectedValue)) { printf(
" selected"); }
198 if ( !is_null($DisabledOptions)
199 && isset($DisabledOptions[$Label]))
206 # print option list end 207 printf(
"</select>\n");
213 # if no date passed in 214 if (($Year == -1) && ($AllowNullDate))
216 # if null date allowed 233 # if date string passed in 234 if ((strlen($Year) > 4) && ($Month == -1))
236 # split into component parts 237 list($Year, $Month, $Day) = split(
"[-/]", $Year);
240 # print option list for months if month value supplied 244 print(
"\n <select name=\"".$FieldPrefix.
"Month\"" 245 .
" id=\"".$FieldPrefix.
"Month\"" 246 .($SubmitOnChange ?
" onChange='submit()'" :
"")
250 print(
"<option value='0'>--</option>\n");
254 if ($Index == $Month)
256 printf(
" <option value='%s' selected>%s</option>\n", $Index,
GetMonthName($Index));
260 printf(
" <option value='%s'>%s</option>\n", $Index,
GetMonthName($Index));
264 printf(
" </select>\n");
267 # print option list for days if day value supplied 271 print(
"\n <select name=\"".$FieldPrefix.
"Day\"" 272 .
" id=\"".$FieldPrefix.
"Day\"" 273 .($SubmitOnChange ?
" onChange='submit()'" :
"")
277 print(
"<option value='0'>--</option>\n");
283 printf(
" <option value='%s' selected>%s</option>\n", $Index,
GetOrdinalNumber($Index));
287 printf(
" <option value='%s'>%s</option>\n", $Index,
GetOrdinalNumber($Index));
291 printf(
" </select>\n");
294 # print option list for years 295 $Index = date(
"Y") - 45;
296 $EndIndex = $Index + 45;
297 print(
"\n <select name=\"".$FieldPrefix.
"Year\"" 298 .
" id=\"".$FieldPrefix.
"Year\"" 299 .($SubmitOnChange ?
" onChange='submit()'" :
"")
303 print(
"<option value='0'>--</option>\n");
305 while ($Index <= $EndIndex)
309 printf(
" <option value=\"%s\" selected>%s</option>\n", $Index, $Index);
313 printf(
" <option value=\"%s\">%s</option>\n", $Index, $Index);
317 printf(
" </select>\n");
322 # use current date if no date passed in 329 # print option list for hours if hour value supplied 331 print(
"\n <select name=\"".$FieldPrefix.
"Hour\" id=\"".$FieldPrefix.
"Hour\">\n");
336 printf(
" <option value='%s' selected>%d</option>\n", $Index, $Index);
340 printf(
" <option value='%s'>%d</option>\n", $Index, $Index);
344 printf(
" </select>\n");
346 # print option list for minutes if minute value supplied 350 print(
"\n <select name=\"".$FieldPrefix.
"Minute\" id=\"".$FieldPrefix.
"Minute\">\n");
353 if ($Index == $Minute)
355 printf(
" <option value='%s' selected>%02d</option>\n", $Index, $Index);
359 printf(
" <option value='%s'>%02d</option>\n", $Index, $Index);
363 printf(
" </select>\n");
369 # split string on newlines 370 $Pieces = explode(
"\n", $String);
372 # for each line in string 374 for ($Index = 0; $Index < count($Pieces); $Index++)
376 # save length if longer than current max 377 if (strlen($Pieces[$Index]) > $MaxLen)
379 $MaxLen = strlen($Pieces[$Index]);
383 # return length of longest segment to caller 387 function PrintOptionListFromDB($DB, $Table, $Condition, $SortBy, $ResultVar, $ValueQuery, $LabelQuery, $SelectedValue, $Size = 1, $SubmitOnChange =
"", $PrintEvenIfEmpty = 0)
389 # set up condition and sorting parameters 390 if ($Condition !=
"") { $Condition =
"WHERE ".$Condition; }
391 if ($SortBy !=
"") { $SortBy =
"ORDER BY ".$SortBy; }
393 # grab records to be listed from database 394 $QueryString = sprintf(
"SELECT * FROM %s %s %s",
395 $Table, $Condition, $SortBy);
396 $DB->Query($QueryString);
398 # if records were found 399 if ($DB->NumRowsSelected() > 0)
401 # build array of items 402 while ($Row = $DB->FetchRow())
404 $Items[$Row[$ValueQuery]] = $Row[$LabelQuery];
407 # sort array if not already sorted 408 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)