mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Import from DCARF SVN
This commit is contained in:
170
functions/functions.xhtml.php
Normal file
170
functions/functions.xhtml.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?
|
||||
/**
|
||||
* Functions related to XHTML code generation
|
||||
*
|
||||
*
|
||||
* This file is part of queXS
|
||||
*
|
||||
* queXS is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* queXS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with queXS; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*
|
||||
* @author Adam Zammit <adam.zammit@deakin.edu.au>
|
||||
* @copyright Deakin University 2007,2008
|
||||
* @package queXS
|
||||
* @subpackage functions
|
||||
* @link http://www.deakin.edu.au/dcarf/ queXS was writen for DCARF - Deakin Computer Assisted Research Facility
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL) Version 2
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Display a valid XHTML Strict header
|
||||
*
|
||||
* @param string $title HTML title
|
||||
* @param bool $body True if to display the end of the head/body
|
||||
* @param bool|array $css False for no CSS otherwise array of CSS include files
|
||||
* @param bool|array $javascript False for no Javascript otherwise array of Javascript include files
|
||||
* @param string $bodytext Space in the body element: good for onload='top.close()' to close validly
|
||||
* @param bool|int $refresh False or 0 for no refresh otherwise the number of seconds to refresh
|
||||
*
|
||||
* @see xhtml_foot()
|
||||
*/
|
||||
function xhtml_head($title="",$body=true,$css=false,$javascript=false,$bodytext=false,$refresh=false)
|
||||
{
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
||||
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head><title><? if (empty($title)) print "queXS"; else print "queXS: $title"; ?></title>
|
||||
<?
|
||||
if ($css)
|
||||
foreach ($css as $c) print "<link rel='stylesheet' href='$c' type='text/css'></link>";
|
||||
if ($javascript)
|
||||
foreach ($javascript as $j) print "<script type='text/javascript' src='$j'></script>";
|
||||
if ($refresh)
|
||||
print " <!--Set to refresh every $refresh seconds-->
|
||||
<meta http-equiv='Cache-Control' content='no-cache'/>
|
||||
<meta http-equiv='refresh' content='$refresh'/>";
|
||||
if (!$body) return;
|
||||
?>
|
||||
</head>
|
||||
<?
|
||||
if ($bodytext) print "<body $bodytext>"; else print "<body>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a valid XHTML Strict footer
|
||||
*
|
||||
* @see xhtml_head()
|
||||
*/
|
||||
|
||||
function xhtml_foot()
|
||||
{
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a valid XHTML Strict table
|
||||
*
|
||||
* @param array $content Content from database usually an array of arrays
|
||||
* @param array $fields The names of fields to display
|
||||
* @param bool|array $head False if no header otherwise array of header titles
|
||||
* @param string $class Table CSS class
|
||||
* @param bool|array $highlight False if nothing to highlight else an array containing the field to highlight
|
||||
*
|
||||
*/
|
||||
function xhtml_table($content,$fields,$head = false,$class = "tclass",$highlight=false)
|
||||
{
|
||||
print "<table class='$class'>";
|
||||
if ($head)
|
||||
{
|
||||
print "<tr>";
|
||||
foreach ($head as $e)
|
||||
print"<th>$e</th>";
|
||||
print "</tr>";
|
||||
}
|
||||
foreach($content as $row)
|
||||
{
|
||||
if ($highlight && isset($row[key($highlight)]) && $row[key($highlight)] == current($highlight))
|
||||
print "<tr class='highlight'>";
|
||||
else
|
||||
print "<tr>";
|
||||
|
||||
foreach ($fields as $e)
|
||||
print "<td>{$row[$e]}</td>";
|
||||
|
||||
print "</tr>";
|
||||
}
|
||||
print "</table>";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display a drop down list based on a given array
|
||||
*
|
||||
* Example SQL:
|
||||
* SELECT questionnaire_id as value,description, CASE WHEN questionnaire_id = '$questionnaire_id' THEN 'selected=\'selected\'' ELSE '' END AS selected
|
||||
* FROM questionnaire
|
||||
*
|
||||
*
|
||||
* @param array $elements An array of arrays containing a value and a description and if selected (3 elements)
|
||||
* @param string $selectid The ID of the element
|
||||
* @param string $var The var name of the return string
|
||||
* @param bool $useblank Add a blank element to the start of the list
|
||||
* @param string|bool $pass Anything to pass along in the return string (remember to separate with &)
|
||||
* @param bool $js Whether to use JS or not
|
||||
*
|
||||
*/
|
||||
function display_chooser($elements, $selectid, $var, $useblank = true, $pass = false, $js = true)
|
||||
{
|
||||
print "<div><select id='$selectid' name='$selectid' ";
|
||||
if ($js) print "onchange=\"LinkUp('$selectid')\"";
|
||||
print ">";
|
||||
if ($useblank)
|
||||
{
|
||||
print "<option value='";
|
||||
if ($js) print "?";
|
||||
if ($pass != false)
|
||||
print $pass;
|
||||
print "'></option>";
|
||||
}
|
||||
foreach($elements as $e)
|
||||
{
|
||||
if ($js)
|
||||
{
|
||||
print "<option value='?$var={$e['value']}";
|
||||
if ($pass != false)
|
||||
print "&$pass";
|
||||
print "' ";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<option value='{$e['value']}' ";
|
||||
}
|
||||
if (isset($e['selected'])) print $e['selected'];
|
||||
print ">".$e['description']."</option>";
|
||||
}
|
||||
print "</select></div>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user