* @author coma ag * @author *105 - Multimediabüro * @version 1.0 * @since PHP 4.x */ class Table { /** * Target template to wich the table will be parsed. [Default: PAGE] * @type string */ var $parsetarget; /** * HTMLTable. Apply format changes to this object. * @type Object * @access public */ var $table; /** * SQL statement to fill table content. Altrnatively use CreateTableFromArray(). * @type string * @access private */ var $sql; /** * Data array to fill table content. Altrnatively use CreateTableFromSQL(). * @type string * @access private */ var $contentArr; /** * Indicates whether data is gathered from SQL statement od provided array * @type bool * @access private */ var $fromSQL = true; var $searchform=false; // normally true var $sortheading=true; var $html; var $menu; var $rowlimit=0; /** * Constructor method * * @param $app Default application class * * @return Generated object ($this) * @access public */ function __construct($app) { $this->app = $app; $this->app->Tpl->Set('TABLEHEADER', ""); $this->app->Tpl->Set('TABLEFOOTER', ""); } // end of constructor /** * Standard method to create a table. The data is gathered * from provided sql statement and formatted, finally printed * to screen. * *

* NOTE: Method is deprecated. Use CreateTableFromArray() or * CreateTableFromSQL() instead! * * * @param $sql SQL stemenet (Select) to fill the table content * @param $parsetarget Target template to where the content is parsed [Default: PAGE] * * @access public */ function CreateTable($sql, $parsetarget='PAGE',$size="") { $this->CreateTableFromSQL($sql, $parsetarget,$size); } // end of function /** * Standard method to create a table: The data is gathered * from provided sql statement and formatted, finally printed * to screen. * * @param $sql SQL stemenet (Select) to fill the table content * @param $parsetarget Target template to where the content is parsed [Default: PAGE] * * @access public */ function CreateTableFromSQL($sql, $parsetarget='PAGE', $size="") { $order=$this->app->Secure->GetGET("order"); if($order!="") $sql = $sql." ORDER By $order"; $this->parsetarget = $parsetarget; $this->sql = $sql; $this->contentArr = $this->app->DB->SelectArr($this->sql); $this->html = ""; $this->fromSQL = true; $this->InitTable($size); } // end of function /** * Alternative method to create a table: The data is gathered * from provided data array, then formatted and finally printed * to screen. * * @param $contentArr SQL stemenet (Select) to fill the table content * @param $parsetarget Target template to where the content is parsed [Default: PAGE] * * @access public */ function CreateTableFromArray($contentArr, $parsetarget=PAGE, $size="") { /* echo "
";
	print_r($contentArr[0]);
  	echo "
"; */ $order=$this->app->Secure->GetGET("order"); if($order!="") $contentArr = $this->SortTableArray($contentArr,$order); $this->parsetarget = $parsetarget; $this->contentArr = $contentArr; $this->fromSQL = false; $this->InitTable($size); } // end of function function SortTableArray($data,$order) { // to be sure, that we have a numeric array for ($i=0; $i$value) { $numarr[$i][]=$value; } } $data = $numarr; // Obtain a list of columns // We have an array of rows, but array_multisort() requires an array of columns, // so we use the below code to obtain the columns, then perform the sorting. if(count($data)>0) foreach ($data as $key => $row) { for($i=0;$itable = new HTMLTable("0",$size,"","0","0"); $this->table->SetTDClass("divider"); $this->table->ChangingRowColors('#F5F5F5', ''); $this->Generate(); } // end of function /** * Use Array $contentArr to fill table with data * * @access private */ function Generate($fromSQL=true) { // Check for empty array if (count($this->contentArr) < 1) return; // Build table while (list($key, $row) = @each($this->contentArr)) { $this->table->NewRow(); while (list($col, $val) = @each($row)) { if(count($this->cols)==0) { $this->table->AddCol($val); } else { if(isset($this->cols[$col])) $this->table->AddCol($val); } // end of if } // end of inner while } // end of outer while } // end of function function DeleteAsk($colnumber,$msg,$module,$action){ $link = " loeschen"; $this->table->ReplaceCol($colnumber,$link); } // end of function function ReplaceCol($colnumber,$link) { $this->table->ReplaceCol($colnumber,$link); } // end of function function RowMenu($col, $menu) { $this->menu = $menu; switch($menu) { case 'special': // $this->RowMenuSpecial($col, "personenform"); break; case 'personen': $this->RowMenuGeneric($col, "personenform", true, true); break; case 'formel': $this->RowMenuGeneric($col, "formelform", false, true); break; case 'produkt': $this->RowMenuGeneric($col, "produktform", true, true); break; case 'hut': $this->RowMenuHut($col, "hutform", true, true); break; case 'statistikauswertung_ordner': $this->RowMenuAuswertung($col, "statistikauswerten"); break; case 'statistikverwaltung_ordner': $this->RowMenuVerwaltungOrdner($col, "statistikverwalten"); break; case 'statistikverwaltung_formeln': $this->RowMenuVerwaltungFormeln($col, "statistikverwaltenformel"); break; default: $this->RowMenuGeneric($col, $menu."form", true); } // end of switch } // end of function /* spalten nummer ( von 1 gezaehlt), dann der if wert also wenn value gleich dem aktuellen Wert in der Zelle ist, dann wird der text in der Zeile durch replacestring ersetzt. Im replacestring muss sich %value% befinden, an der Stelle wird der alte Wert eingefuegt. Falls bestimmte Spalten nicht ersetzt werden sollen, koennen diese im array dontreplacecols angegeben werden. */ function FormatCondition($col, $value, $replacestring, $dontreplacecols=array()) { $rows = count($this->table->Table); for($i=0;$i<$rows;$i++) { // check ob der wert in der spalte mit dem $value uebereinstimmt // wenn ja ersetze jede zeile auser die aus dem array dontreplacecols if($this->table->Table[$i][$col-1]==$value) { // ersetze spalten auser die in dontreplacecols $cols = count($this->table->Table[$i]); for($j=0;$j<$cols;$j++) { if(!in_array($j+1,$dontreplacecols)) { $content = $this->table->Table[$i][$j]; $this->table->Table[$i][$j] = str_replace("%value%", $content, $replacestring); } // end of if } // end of for } // end of if } // end of for } // end of function /** * Formats a table coolumn with SIP specific format options. * Available options are listed below: *
    *
  • numeric: aligns right
  • *
* * @param Int $col Column number for menu * @param String $sipStyle use options from available list (see above) * * @access public */ function FormatColumn($col, $sipStyle) { switch ($sipStyle){ case "numeric": $cssStyle = "divider alignRight"; break; case "currency": $cssStyle = "divider alignRight number"; break; default: $cssStyle = "divider"; } // end of switch $this->table->FormatCol($col, $cssStyle); } // end of function /** * Creates a generic menu for each table row. * Presets for this generic menu are: *
    *
  • the menu column contains the data records id (primary key)
  • *
  • 1st column contains the same id as above
  • *
  • 2nd column contains 0 or 1 as relevant value for activate and deactivate (zustand / active) if param $showActivate is set to true
  • *
  • 3rd column contains 0 or 1 as relevant value for delete (deletable or not) if param $showDelete is set to true
  • *
* * @param Int $col Column number for menu * @param String $module Modulename used to build links (e.g. personenform, hutform, etc.) * @param Bool $showActivate Show active/deactivate buttons depending on value in 2nd column * @param Bool $showDelete Show delete button if value indicates that (value in 3rd column) * * @access public */ function RowMenuGeneric($col, $module, $showActivate=true, $showDelete=false) { $rows = count($this->table->Table); for($i=0;$i<$rows;$i++) { $cols = count($this->table->Table[$i]); for($j=0;$j<$cols;$j++) { if($j==($col-1)){ $id = $this->table->Table[$i][$j]; $menu = ""; //historie $menu .= ""; $menu .= "\"Historie\""; $menu .= " "; // bearbeiten wenn aktiv if ($this->table->Table[$i][1] != 0) { $menu .= ""; $menu .= "\"bearbeiten\""; $menu .= " "; } // end of if // aktivieren wenn inaktiv, sonst deaktivieren if (($this->table->Table[$i][1] == 0) && ($showActivate)){ $menu .= ""; $menu .= "\"reaktivieren\""; $menu .= " "; } else { if($showActivate) { $menu .= ""; $menu .= "\"deaktivieren\""; $menu .= " "; } // end of if } // end of if - anzeige von deaktivieren ODER aktivieren // l�sch button einblenden wenn delete kriterium 1 if ($showDelete) { // print_r($this->table->Table); if ($this->table->Table[$i][2] == 1) { $menu .= ""; $menu .= "\"löschen\""; $menu .= " "; } // end of if - anzeige des l�schen buttons oder nicht nach wert } // end of if - anzeige von l�schen oder nicht nach funktionsparmeter // wenn noch nicht verlinkt $this->table->Table[$i][$j] = $menu; } // end of outer if } // end of inner for } // end pof outer for } // end of function /** * Creates a specific form for Hut * * @param Int $col Column number for menu * @param String $module Modulename used to build links (e.g. personenform, hutform, etc.) * * @access public */ function RowMenuHut($col, $module, $showActivate=true, $showDelete=false) { $rows = count($this->table->Table); for($i=0;$i<$rows;$i++) { $cols = count($this->table->Table[$i]); for($j=0;$j<$cols;$j++) { if($j==($col-1)){ $id = $this->table->Table[$i][$j]; $menu = ""; //historie $menu .= ""; $menu .= "\"Historie\""; $menu .= " "; // bearbeiten wenn aktiv if ($this->table->Table[$i][1] != 0) { $menu .= ""; $menu .= "\"bearbeiten\""; $menu .= " "; } // end of if // aktivieren wenn inaktiv, sonst deaktivieren if (($this->table->Table[$i][1] == 0) && ($showActivate)){ $menu .= ""; $menu .= "\"reaktivieren\""; $menu .= " "; } else { if($showActivate) { if (strlen($this->table->Table[$i][8]) == 51) { $menu .= ""; $menu .= "\"deaktivieren\""; $menu .= " "; } // end of if } // end of if } // end of if - anzeige von deaktivieren ODER aktivieren // l�sch button einblenden wenn delete kriterium 1 if ($showDelete) { // print_r($this->table->Table); if ($this->table->Table[$i][2] == 1) { $menu .= ""; $menu .= "\"löschen\""; $menu .= " "; } // end of if - anzeige des l�schen buttons oder nicht nach wert } // end of if - anzeige von l�schen oder nicht nach funktionsparmeter // wenn noch nicht verlinkt $this->table->Table[$i][$j] = $menu; } // end of outer if } // end of inner for } // end pof outer for } // end of function /** * Creates a specific form for OIC Module Statistik Auswertung / Ordner�bersicht * * @param Int $col Column number for menu * @param String $module Modulename used to build links (e.g. personenform, hutform, etc.) * * @access public */ function RowMenuAuswertung($col, $module) { $rows = count($this->table->Table); for($i=0;$i<$rows;$i++) { $cols = count($this->table->Table[$i]); for($j=0;$j<$cols;$j++) { if($j==($col-1)){ $id = $this->table->Table[$i][$j]; $menu = ""; if ($this->table->Table[$i][3] != 0) { // Detailansicht $menu .= ""; $menu .= "\"Detailansicht\""; $menu .= " "; // Graph $menu .= ""; $menu .= "\"Graph\""; $menu .= " "; } else { $menu .= "keine Formeln vorhanden"; } // end of if - nicht anzeigen wenn keine Formeln im Ordner sind // wenn noch nicht verlinkt $this->table->Table[$i][$j] = $menu; } // end of outer if } // end of inner for } // end pof outer for } // end of function /** * Creates a specific form for OIC Module Statistik Verwaltung / Ordner�bersicht * * @param Int $col Column number for menu * @param String $module Modulename used to build links (e.g. personenform, hutform, etc.) * * @access public */ function RowMenuVerwaltungOrdner($col, $module) { $rows = count($this->table->Table); for($i=0; $i<$rows; $i++) { $cols = count($this->table->Table[$i]); for($j=0; $j<$cols; $j++) { if($j==($col-1)){ $id = $this->table->Table[$i][$j]; $menu = ""; // Edit $menu .= ""; $menu .= "\"Ordner"; $menu .= " "; // Formeln bearbeiten $menu .= ""; $menu .= "\"Formeln"; $menu .= " "; // Nach unten (wenn nicht letztes in Liste) if ($i != $rows-1) { $menu .= ""; $menu .= "\"Nach"; $menu .= " "; } // end of if // Nach oben (wenn nicht erstes in Liste) if ($i != 0) { $menu .= ""; $menu .= "\"Nach"; $menu .= " "; } // end of if // Delete - Wenn in Spalte 3 eine 0 steht (keine Formeln mehr im Ordner) if ($this->table->Table[$i][3] == 0) { $menu .= ""; $menu .= "\"löschen\""; $menu .= " "; } // end of if - anzeige des l�schen buttons oder nicht nach wert // wenn noch nicht verlinkt $this->table->Table[$i][$j] = $menu; } // end of outer if } // end of inner for } // end pof outer for } // end of function /** * Creates a specific form for OIC Module Statistik Verwaltung / Formel�bersicht innerhalb eines Ordners * * @param Int $col Column number for menu * @param String $module Modulename used to build links (e.g. personenform, hutform, etc.) * * @access public */ function RowMenuVerwaltungFormeln($col, $module) { $rows = count($this->table->Table); if ($rows == 0) { $this->table->Table[] = Array("", "", "", "Bisher existiert kein Eintrag in dieser Liste.", "", "", "", "-1"); $rows = count($this->table->Table); } // end of if for($i=0; $i<$rows; $i++) { $cols = count($this->table->Table[$i]); for($j=0; $j<$cols; $j++) { if($j==($col-1)){ $id = $this->table->Table[$i][$j]; $menu = ""; // Ansicht (1 oder 1/4) if ($this->table->Table[$i][1] == 4 && $id != -1) { $menu .= ""; $menu .= "\"Ansicht"; $menu .= " "; } else if ($this->table->Table[$i][0] != "") { $menu .= ""; $menu .= "\"Ansicht"; $menu .= " "; } // end of if - Ansicht 1 oder 1/4 // Delete - Wenn in Spalte 3 eine 0 steht (keine Formeln mehr im Ordner) //echo $this->table->Table[$i][1]."
"; //if ($this->table->Table[$i][1] == 0 && $id != -1) { if ($id != -1) { $menu .= ""; $menu .= "\"löschen\""; $menu .= " "; } // end of if - anzeige des l�schen buttons oder nicht nach wert // Formeln hinzuf�gen if ($id != -1) { $menu .= ""; $menu .= "\"Nach"; $menu .= " "; } else { $menu .= ""; $menu .= "\"Formel"; $menu .= " "; } // end of if // Nach unten (wenn nicht letztes in Liste) if ($i != $rows-1 && $id != -1) { $menu .= ""; $menu .= "\"Nach"; $menu .= " "; } // end of if // Nach oben (wenn nicht erstes in Liste) if ($i != 0 && $id != -1) { $menu .= ""; $menu .= "\"Nach"; $menu .= " "; } // end of if // wenn noch nicht verlinkt $this->table->Table[$i][$j] = $menu; } // end of outer if } // end of inner for } // end pof outer for /* 1 Abgeschlossene Verträge F3 Pkt/Stk 1 Ansicht 1/4 löschen nach dieser hinzufügen nach unten */ } // end of function /** * Shows the siptable * * @access public */ function Show() { $this->html = ""; if($this->searchform) $this->html .= $this->SortAndSearchForm(); //$this->html .= $this->table->Get(" ",""); $this->html .= $this->table->Get(" ",$this->headingtop); $this->app->Tpl->Add($this->parsetarget, $this->html); } // end of function function RowLimit($number) { $this->rowlimit=$number; } function Cols($fields) { $this->cols=array_flip($fields); } function HideCol($number) { $this->table->HideCol($number); } function HeadingTop($value) { $this->headingtop=$value; } function Headings($descriptions) { $this->table->AddRowAsHeading($descriptions); $this->descriptions=$descriptions; } function SetSortAndSearchForm($bool) { $this->searchform=$bool; } function SetSortHeading($bool) { $this->sortheading=$bool; } function SortAndSearchForm() { $select = new HTMLSelect("sort",1); if(count($this->cols)==0) { } else { while (list($col, $val) = @each($this->cols)) { if($this->descriptions[$col]!="") $select->AddOption("Nach {$this->descriptions[$col]} Sortieren",$col); else $select->AddOption("Nach $col Sortieren",$col); } } $html = $select->Get(); $search = new HTMLInput("search","text","",20); $html .= $search->Get(); $html .=""; $html .="
"; $alphabet = range('A', 'Z'); $html .=""; foreach ($alphabet as $letter) $html .= ""; $html .="
$letter
"; return $html; } } // end of class ?>