. */ include("./include/Appl.php"); include("./include/Persons.php"); class ListView { private $title; private $sort; private $showButtons; private $sqlwhere; private $urlargs; private $maxlist; private $printable; private $fields; public function __construct($title, $defaultsort="", $showButtons=true, $sqlwhere="", $sqlwhereuseselection=true, $urlargs="", $maxlist=0, $printable=false) { global $setup; $this->title = $title; if( isset($_GET['sort']) AND preg_match("/^[a-zA-Z0-9_]+$/", $_GET['sort']) ) { $this->sort = $_GET['sort']; }elseif( preg_match("/^[a-zA-Z0-9_]+$/", $defaultsort) ) { $this->sort = $defaultsort; }else { debug("Invalid or no default sort provided"); $this->sort = ""; } $this->showButtons = $showButtons; if( strlen($sqlwhere)==0 ) { if( $sqlwhereuseselection ) $this->sqlwhere = $_SESSION['sess_sel']; else $this->sqlwhere = "1"; }else { if( $sqlwhereuseselection ) $this->sqlwhere = $_SESSION['sess_sel'] . " AND " . $sqlwhere; else $this->sqlwhere = $sqlwhere; } if( strlen($urlargs)>0 ) $this->urlargs = $urlargs."&"; else $this->urlargs = ""; if( $maxlist>0 ) $this->maxlist = $maxlist; else $this->maxlist = $setup['MaxList']; $this->printable = $printable; $this->fields = array(); } public function __destruct() { } public function addfield($name) { if( preg_match("/^[a-zA-Z0-9_]+$/", $name) ) { $class = ""; if( substr($name, 0, 14) == "ExtraQuestion_" ) { $extraQuestionId = substr($name, 14); $filename = "ExtraQuestion"; }else { $filename = $name; } if( $file = glob( dirname($_SERVER["SCRIPT_FILENAME"])."/include/PersonsFields/???".$filename.".php" ) AND count($file)==1 AND is_readable($file[0]) ) { $class = "Persons".$filename; }elseif( $file = glob( dirname($_SERVER["SCRIPT_FILENAME"])."/include/ApplFields/???".$filename.".php" ) AND count($file)==1 AND is_readable($file[0]) ) { $class = "Appl".$filename; }else { debug("Didn't add ".$name.", cannot find related file"); return false; } if( $class!="" ) { include_once( $file[0] ); if( $filename == "ExtraQuestion" ) { $query = "SELECT `question`, `maxlength` FROM `appl_extraquestions` WHERE `id` = " . $extraQuestionId; if( @mysql_num_rows( $res=doquery($query) )>0 ) { $row = mysql_fetch_assoc($res); $classref = new ApplExtraQuestion(0, $extraQuestionId, $row['question'], $row['maxlength']); } }else { $classref = new $class(0); } if( $classref->get_access(false)!=Appl::ACCESS_NO ) { $this->fields[$name]['class'] = $class; $this->fields[$name]['classref'] = $classref; $this->fields[$name]['printname'] = $classref->get_print_name(); $this->fields[$name]['printnameshort'] = $classref->get_print_name_short(); $this->fields[$name]['sql_columnname'] = $classref->sql_columnname(); return true; }else { debug("Didn't add ".$name.", access denied"); return false; } } }else { // invalid name debug("Didn't add ".$name.", invalid name"); return false; } } public function display() { if( !isset($_GET['start']) ) { $_GET['start'] = 0; $_REQUEST['start'] = 0; } $title = $this->title; if( array_key_exists($this->sort, $this->fields) ) $title .= " ordered by ".$this->fields[$this->sort]['printname']; echoln("
Failed selecting row count.
"); }else { $row = mysql_fetch_array($res); $tot_rows = $row['tot_rows']; if( $tot_rows>$this->maxlist AND !$this->printable ) { // There are more entries to show than fit on one page, split in pages $page_text = "Page"; for($i=0; $i<($tot_rows/$this->maxlist); $i++) { if( $_GET['start']==($i*$this->maxlist) ) { $page_text .= " ".($i+1).""; }else { $page_text .= " urlargs.($this->sort=="" ? "" : "sort=".$this->sort."&")."start=".($i*$this->maxlist)."\">".($i+1).""; } } if( $_REQUEST['start']==-1 ) { $page_text .= " all rows"; }else { $page_text.=" urlargs.($this->sort=="" ? "" : "sort=".$this->sort."&")."start=-1\">all rows"; } echoln("".$page_text."
"); } if( $_GET['start']==-1 OR $this->printable ) { $sqllimit = "0"; if( $tot_rows>0 ) echoln("Showing all rows (".$tot_rows." total).
"); }else { $start = get_int("start"); if( $start<0 ) $start = false; if( $start>=$tot_rows ) $start = max(0, $tot_rows - $this->maxlist); $sqllimit = $start . ", " . $this->maxlist; if( $tot_rows>0 ) echoln("Showing rows ".($start+1)." - ".min( ($start+$this->maxlist), $tot_rows )." (".$tot_rows." total).
"); } $fields = array_keys($this->fields); $joins = ""; $query = "SELECT `applications`.`id`, `applications`.`BodyCode`"; for( $i=0; $iEmpty selection, no matching entries found.
"); }else { echoln("| "); for( $i=0; $i | |
|---|---|
");
echoln(" ");
if( in_array("application_register", $_SESSION['sess_functions']) )
echoln(" ");
if( in_array("application_edit", $_SESSION['sess_functions']) )
echoln(" edit");
echoln(" | ");
}
for( $i=0; $ifields[ $fields[$i] ]['classref']->displayoptions($row['id']) . $title .">".($this->printable ? $this->fields[ $fields[$i] ]['classref']->displaytext($row[ $fields[$i] ], $row['id'], $row) : $this->fields[ $fields[$i] ]['classref']->display($row[ $fields[$i] ], $row['id'], $row))." | "); } echoln("
".$page_text."
"); } } } } } ?>