예제 #1
0
 public function fill(array $contents)
 {
     $this->loadAttributes();
     #$this->object->loadMeOrEmpty();
     $allowed = PMReflector::getAttributesArrayAnyObject($this->attributes);
     foreach ($allowed as $v) {
         if (isset($contents[$v])) {
             $this->sA($v, $contents[$v]);
         }
     }
 }
예제 #2
0
 public static function getAttributesArray($className)
 {
     if (is_object($className)) {
         return PMReflector::getAttributesArrayAnyObject($className);
     }
     /*$a = array();
     	    $class = new ReflectionClass("$className");
     		$props = $class->getProperties();
     		for($i = 0;$i < count($props);$i++)
     			$a[] = $props[$i]->getName();
     		return $a;*/
     return PMReflector::getAttributesArrayAnyObject(new $className());
 }
예제 #3
0
 public function __construct($formID, $fields, $title = null, $virtualFields = array())
 {
     $this->id = $formID;
     if (is_array($fields)) {
         $this->fields = $fields;
     }
     if ($fields instanceof PersistentObject) {
         $fields->loadMeOrEmpty();
         $this->fields = PMReflector::getAttributesArrayAnyObject($fields->getA());
     }
     $this->virtualFields = $virtualFields;
     $this->types = array();
     $this->labels = array();
     $this->options = array();
     $this->values = array();
     $this->endLV = array();
     $this->spaces = array();
     $this->spaceLines = array();
     $this->table = new HTMLTable(2, $title);
     $this->table->setColClass(1, "backgroundColor3");
     $this->table->setColClass(2, "backgroundColor2");
     $this->title = $title;
     $this->saveMode = null;
     #$this->onSubmit = null;
     $this->buttons = array();
 }
예제 #4
0
 public function getEditHTML()
 {
     if (BPS::getProperty($this->className . "GUI", "edit") == "ok") {
         return $this->getEditTableHTML();
     }
     ################################################################################
     if ($this->name == null) {
         $this->name = $this->className;
     }
     if ($this->attributes == null) {
         $this->attributes = PMReflector::getAttributesArrayAnyObject($this->object->getA());
     }
     $widths = Aspect::joinPoint("changeWidths", $this, __METHOD__);
     if ($widths == null) {
         $widths = array(700, 132, 218);
     }
     $tab = new HTMLTable(2);
     $tab->setTableStyle("width:{$widths['0']}px;margin-left:10px;");
     $tab->setColWidth(1, "50%");
     $tab->setColWidth(2, "50%");
     $A = $this->object->getA();
     $TSub = new HTMLTable(2);
     $TSub->setColWidth(1, 120);
     $TSub->setColClass(1, "");
     $TSub->setColClass(2, "");
     $TC = clone $TSub;
     $row = array();
     foreach ($this->attributes as $k => $v) {
         if (isset($this->types[$v]) and $this->types[$v] == "hidden") {
             continue;
         }
         if (isset($this->parsers[$v])) {
             $A->{$v} = $this->invokeParser($this->parsers[$v], $A->{$v}, $this->object);
         }
         if (isset($this->types[$v]) and $this->types[$v] == "select") {
             if (isset($this->options[$v]) and isset($this->options[$v][$A->{$v}])) {
                 $A->{$v} = $this->options[$v][$A->{$v}];
             }
         }
         if (isset($this->spaces[$v]) and $this->spaces[$v] != "") {
             if ($k > 0) {
                 $row[] = $TC;
             }
             if ($this->forceNewRow[$v]) {
                 $row[] = "";
                 $tab->addRow($row);
                 $tab->addRowClass("backgroundColor0");
                 $tab->addRowStyle("vertical-align:top;");
                 $row = array();
             }
             if (count($row) == 2) {
                 $tab->addRow($row);
                 $tab->addRowClass("backgroundColor0");
                 $tab->addRowStyle("vertical-align:top;");
                 $row = array();
             }
             $TC = clone $TSub;
             if (trim($this->spaces[$v]) != "") {
                 $TC->addRow(array($this->spaces[$v]));
                 $TC->addRowClass("backgroundColor2");
                 $TC->addRowColspan(1, 2);
             }
         }
         if ($A->{$v} != "") {
             $B = "";
             if (isset($this->fieldButtons[$v])) {
                 $B = $this->fieldButtons[$v];
                 $B->style("float:right;");
             }
             $TC->addLV($this->labels($v) . ":", $B . nl2br($A->{$v}));
             $TC->addRowStyle("vertical-align:top;");
         }
         /*
         			$label = isset($this->labels[$v]) ? $this->labels[$v] : $v;
         
         			$row[] = "<label>".($label != "" ? ucfirst($label).":" : "")."</label>";
         
         
         
         			$row[] = nl2br($A->$v);*/
         /*if(count($row) == 4){
         			$tab->addRow($row);
         			$row = array();
         		}*/
     }
     $row[] = $TC;
     if (count($row) == 1) {
         $row[] = "";
     }
     if (count($row) == 2) {
         $tab->addRow($row);
         $tab->addRowClass("backgroundColor0");
         $tab->addRowStyle("vertical-align:top;");
     }
     $BE = new Button("Eintrag\nbearbeiten", "edit");
     $BE->onclick(str_replace(array("%CLASSNAME", "%CLASSID"), array($this->className, $this->object->getID()), $this->functionEdit));
     $BE->style("float:left;margin-left:10px;");
     $BD = new Button("Eintrag\nlöschen", "trash");
     $BD->onclick(str_replace(array("%CLASSNAME", "%CLASSID"), array($this->className, $this->object->getID()), $this->functionDelete));
     $BD->style("float:left;margin-left:10px;");
     $options = "<div style=\"width:{$widths['0']}px;\">" . $BE . $BD . implode("", $this->topButtons) . "</div><div style=\"clear:left;height:10px;width:{$widths['0']}px;\"></div>";
     $appended = "";
     if (count($this->appended) > 0) {
         foreach ($this->appended as $k => $v) {
             $appended .= $v->getHTML();
         }
     }
     $prepended = "";
     if (count($this->prepended) > 0) {
         foreach ($this->prepended as $k => $v) {
             $prepended .= $v->getHTML();
         }
     }
     /*
     		if(count($this->CRMGUIappendedElements) > 0)
     			foreach($this->CRMGUIappendedElements as $k => $v)
     				$appended .= $v->getHTML();*/
     return $options . $prepended . $tab . $appended;
 }
예제 #5
0
 function loadSingle2($table, $id, $typsicher = false)
 {
     /*$db = @sqlite_open($this->file) or die ("SQLite-DB konnte nicht geöffnet werden. DB-Datei: ".$this->file.(is_file($this->file) ? " existiert" : " existiert nicht" ));
     		$sql = "SELECT ".implode(", ",$fields)." FROM $table WHERE $keyName = '$id'";
     		$_SESSION["messages"]->addMessage("executing SQLite: $sql");
     		$q = sqlite_query($db,$sql);
     
     		$t = sqlite_fetch_array($q);
     		if(sqlite_num_rows($q) == 0) throw new ZeroRowsException();
     		sqlite_close($db);
     		
     		return $t;*/
     if ($this->c == null) {
         $this->renewConnection();
     }
     $sql = "SELECT * FROM {$table} WHERE " . $table . "ID = '{$id}'";
     $q = $this->c->query($sql);
     $_SESSION["messages"]->addMessage("executing SQLite: {$sql}");
     #echo sqlite_error_string($this->c->lastError());
     if ($this->c->lastError() === 1) {
         throw new TableDoesNotExistException();
     }
     /*if($this->c->error AND $this->c->errno == 1146) throw new TableDoesNotExistException();
     		if($this->c->error AND ($this->c->errno == 1045 OR $this->c->errno == 2002)) throw new NoDBUserDataException();
     		if($this->c->error AND $this->c->errno == 1054) {
     			ereg("[a-zA-Z0-9 ]*\'([a-zA-Z0-9\.]*)\'[a-zA-Z ]*\'([a-zA-Z ]*)\'.*", $this->c->error(), $regs);
     			throw new FieldDoesNotExistException($regs[1],$regs[2]);
     		}
     		if($this->c->error AND $this->c->errno == 1046) throw new DatabaseNotSelectedException();*/
     #echo $this->c->error;
     $t = $q->fetchObject();
     $fields = PMReflector::getAttributesArrayAnyObject($t);
     #foreach($fields AS $key => $value)
     #	$t->$value = $this->fixUtf8(stripslashes($t->$value));
     return $t;
 }
예제 #6
0
 function getBrowserHTML($lineWithId = -1, $useBPS = true)
 {
     T::load(Util::getRootPath() . "libraries");
     $canDelete = mUserdata::isDisallowedTo("cantDelete" . $this->className);
     #$canEdit = mUserdata::isDisallowedTo("cantEdit".$this->className);
     if (!$canDelete) {
         $this->showTrash = false;
     }
     #if(!$canEdit) //KILLS SEARCH-FIELD!!
     #	$this->showEdit = false;
     $bps = BPS::getAllProperties("m" . $this->className . "GUI");
     if (!$useBPS) {
         $bps = false;
     }
     $GUIF = $this->GUIFactory;
     $GUIF->setMultiPageDetails($this->multiPageDetails);
     $GUIF->setTableMode($this->displayMode);
     $GUIF->options($this->showTrash, $this->showEdit, $this->showNew);
     if ($this->blacklists != null) {
         $GUIF->blacklists($this->blacklists);
     }
     if (isset($bps["selectionMode"])) {
         $GUIF->selection($bps["selectionMode"]);
     }
     #$GUIF->features($this->features);
     #$this->multiPageDetails["target"] = $this->frame;#"contentRight";
     #$GUIF->setMultiPageDetails($this->multiPageDetails);
     if ($this->targetFrame != null) {
         $GUIF->targetFrame($this->targetFrame);
     }
     $E = $this->object->getNextEntry();
     if ($this->attributes == null and $E != null) {
         $this->attributes = PMReflector::getAttributesArrayAnyObject($E->getA());
     }
     #if($E == null) //To fix display error when no entry
     #	$this->attributes = array("");
     if ($this->caption == null and $this->caption !== false) {
         $this->caption($this->displayMode == "BrowserLeft" ? $this->name == null ? $this->className : $this->name : "");
     }
     #"Bitte ".($this->name == null ? $this->className : $this->name)." auswählen:");
     $Tab = $GUIF->getTable($E == null ? array("") : $this->attributes, $this->colStyle, $this->caption);
     if ($this->tableWeight) {
         $Tab->weight($this->tableWeight);
     }
     $Tab->setTableID("Browserm{$this->className}");
     $Tab->addTableClass("contentBrowser");
     if ($this->useScreenHeight) {
         $Tab->useScreenHeight();
     }
     if ($this->header != null and $this->object->numLoaded() > 0) {
         $Tab->addHeaderRow($this->header);
     }
     if ($lineWithId == -1) {
         if ($this->showQuicksearch) {
             $GUIF->buildQuickSearchLine();
         }
         #if($this->multiPageDetails["total"] > $this->multiPageDetails["perPage"])
         if ($this->showPageFlip) {
             $GUIF->buildFlipPageLine("top");
         }
         if ($this->object->isFiltered()) {
             $GUIF->buildFilteredWarningLine($this->object->isFilteredLabel());
         }
         $GUIF->buildNewEntryLine(($this->name == null ? $this->className : $this->name) . " neu anlegen");
     }
     $this->object->resetPointer();
     $DisplayGroup = null;
     while ($E = $this->object->getNextEntry()) {
         /**
          * DisplayGroup
          */
         if ($lineWithId == -1 and $this->displayGroup != null and $DisplayGroup != $E->A($this->displayGroup[0])) {
             if ($this->displayGroup[1] != null) {
                 $DGP = explode("::", $this->displayGroup[1]);
                 $GUIF->buildGroupLine(Util::invokeStaticMethod($DGP[0], $DGP[1], array($E->A($this->displayGroup[0]), $E)));
             } else {
                 $GUIF->buildGroupLine($E->A($this->displayGroup[0]));
             }
         }
         $Line = array();
         foreach ($this->attributes as $attributeName) {
             $LineContent = $E->A($attributeName);
             if (isset($this->parsers[$attributeName])) {
                 $LineContent = $this->invokeParser($this->parsers[$attributeName], $LineContent, $E);
             } else {
                 $LineContent = htmlspecialchars($LineContent);
             }
             $Line[] = $LineContent;
         }
         $GUIF->buildLine($E->getID(), $Line);
         if ($this->displayGroup != null) {
             $DisplayGroup = $E->A($this->displayGroup[0]);
         }
     }
     if ($lineWithId == -1) {
         if ($this->object->isFiltered()) {
             $GUIF->buildFilteredWarningLine($this->object->isFilteredLabel());
         }
         if ($this->multiPageDetails["total"] > $this->multiPageDetails["perPage"] and $this->showPageFlip) {
             $GUIF->buildFlipPageLine("bottom");
         }
         if ($this->object->numLoaded() == 0) {
             $GUIF->buildNoEntriesLine();
         }
     } else {
         return $Tab->getHTMLForUpdate();
     }
     $prepend = "";
     foreach ($this->prepended as $PE) {
         $prepend .= $PE;
     }
     $appended = "";
     foreach ($this->appended as $PE) {
         $appended .= $PE;
     }
     return "<div class=\"browserContainer contentBrowser\">" . $prepend . $this->sideButtons($bps) . $GUIF->getContainer($Tab, $this->caption, $appended, $this->topButtons($bps)) . "</div>" . str_replace("%CLASSNAME", $this->className, $this->sortable) . $this->tip;
 }
예제 #7
0
 function loadMultipleV4(SelectStatement $statement, $typsicher = false)
 {
     #file_put_contents(Util::getRootPath()."debug.txt", print_r(debug_backtrace(), true));
     $where = "(";
     $lastKey = "";
     $closeBrackets = "";
     foreach ($statement->whereFields as $key => $value) {
         $addOpenBracket = false;
         if ($where != "(" and $statement->whereBracketGroup[$lastKey] != $statement->whereBracketGroup[$key]) {
             $addOpenBracket = true;
             $where .= ")";
         }
         $currentWhereValue = $statement->whereValues[$key];
         if ($currentWhereValue != "NULL" and $currentWhereValue != "NOT NULL" and substr($currentWhereValue, 0, 3) != "t1.") {
             $currentWhereValue = "'" . $this->c->real_escape_string($currentWhereValue) . "'";
         }
         $where .= ($where != "(" ? " " . $statement->whereLogOp[$key] . " " . ($addOpenBracket ? "(" : "") : "") . "" . $statement->whereFields[$key] . " " . $statement->whereOperators[$key] . " " . $currentWhereValue . "";
         $lastKey = $key;
     }
     $where .= ")";
     $order = "";
     foreach ($statement->order as $key => $value) {
         $order .= ($order != "" ? ", " : "") . $statement->order[$key] . " " . $statement->orderAscDesc[$key];
     }
     $tables = array();
     for ($i = 0; $i < count($statement->joinTables); $i++) {
         if (!isset($tables[$statement->joinTables[$i]])) {
             $tables[$statement->joinTables[$i]] = array();
         }
         $tables[$statement->joinTables[$i]][] = array($statement->joinConditions[$i][0], $statement->joinConditionOperators[$i], $statement->joinConditions[$i][1], $statement->joinTypes[$i]);
     }
     $t = 2;
     $joinAdd = "";
     foreach ($tables as $table => $conditions) {
         $type = "LEFT";
         $ons = "";
         for ($i = 0; $i < count($conditions); $i++) {
             if ($i == 0) {
                 $ons .= ((!strpos($conditions[$i][0], ".") and $conditions[$i][0][0] != " ") ? "t1." : "") . "" . $conditions[$i][0] . " " . $conditions[$i][1] . " t{$t}." . $conditions[$i][2];
             } else {
                 if ($conditions[$i][2] != "NOT NULL" and $conditions[$i][2] != "NULL") {
                     $conditions[$i][2] = "'" . $conditions[$i][2] . "'";
                 }
                 $ons .= " AND t{$t}." . $conditions[$i][0] . " " . $conditions[$i][1] . " " . $conditions[$i][2] . "";
             }
             if (isset($conditions[$i][3]) and $conditions[$i][3] != "") {
                 $type = $conditions[$i][3];
             }
         }
         $joinAdd .= "\n {$type} JOIN " . $table . " t{$t} ON({$ons})";
         $t++;
     }
     if ($this->affectedRowsOnly and count($statement->group) === 0) {
         $tempFields = $statement->fields;
         $statement->fields = array("COUNT(*) AS anzahlTotal");
         $order = "";
     }
     $sql = "SELECT\n " . implode(",\n ", $statement->fields) . "\n FROM `" . $statement->table[0] . "` t1{$joinAdd} " . ($where != "()" ? "\n WHERE {$where}" : "") . (count($statement->group) > 0 ? "\n GROUP BY " . implode(", ", $statement->group) : "") . ($order != "" ? "\n ORDER BY {$order}" : "") . (count($statement->limit) > 0 ? "\n LIMIT " . implode(", ", $statement->limit) : "");
     $collector = array();
     if ($statement->table[0] != "Userdata") {
         $_SESSION["messages"]->startMessage("executing MySQL: {$sql}");
     }
     #echo nl2br($sql)."<br /><br />";
     $q = $this->c->query($sql);
     DBStorage::$queryCounter++;
     if ($this->c->error and ($this->c->errno == 1045 or $this->c->errno == 2002)) {
         throw new NoDBUserDataException();
     }
     if ($this->c->error and $this->c->errno == 1146) {
         throw new TableDoesNotExistException($statement->table[0]);
     }
     if ($this->c->error and $this->c->errno == 1046) {
         throw new DatabaseNotSelectedException();
     }
     if ($this->c->error and $this->c->errno == 1054) {
         preg_match("/[a-zA-Z0-9 ]*\\'([a-zA-Z0-9\\.]*)\\'[a-zA-Z ]*\\'([a-zA-Z ]*)\\'.*/", $this->c->error, $regs);
         throw new FieldDoesNotExistException($regs[1], $regs[2]);
     }
     #if($this->c->error AND $this->c->errno == 1028) //aborted query
     #	die($sql);
     if ($this->c->error) {
         echo "MySQL-Fehler: " . $this->c->error . "<br />Fehlernummer: " . $this->c->errno;
     }
     #echo $sql."<br /><br />";
     if ($statement->table[0] != "Userdata") {
         $_SESSION["messages"]->endMessage(": " . $this->c->affected_rows . " " . $statement->table[0] . " geladen");
     }
     if ($this->affectedRowsOnly) {
         $this->affectedRowsOnly = false;
         if (count($statement->group) === 0) {
             $statement->fields = $tempFields;
             $t = $q->fetch_object();
             return $t->anzahlTotal;
         }
         return $this->c->affected_rows;
     }
     /*if($typsicher){
     			$types = array();
     			$qc = $this->c->query("SHOW COLUMNS FROM ".$statement->table[0]);
     			DBStorage::$queryCounter++;
     			while($tc = $qc->fetch_object())
     				$types[$tc->Field] = $this->mysql2Object($tc->Type);
     				
     			foreach($statement->joinTables AS $kc => $vc){
     				$qc = $this->c->query("SHOW COLUMNS FROM ".$vc);
     				DBStorage::$queryCounter++;
     				while($tc = $qc->fetch_object())
     					$types[$tc->Field] = $this->mysql2Object($tc->Type);
     			}
     			
     			foreach($statement->dataTypes AS $kc => $vc)
     				$types = array_merge($types, $vc);
     		}*/
     $fields = null;
     $cName = $statement->table[0];
     if ($statement->className != "") {
         $cName = $statement->className[0];
     }
     while ($t = $q->fetch_object()) {
         $A = new Attributes();
         if ($fields == null) {
             $fields = PMReflector::getAttributesArrayAnyObject($t);
         }
         foreach ($fields as $key => $value) {
             $A->{$value} = $this->fixUtf8(stripslashes($t->{$value}));
             /*if($typsicher){
             			if(isset($types[$value])) $typObj = $types[$value];
             			else throw new DataTypeNotDefinedException($value);
             			
             			$A->$value = new $typObj($A->$value);
             			#echo "<pre>";
             			#print_r($A);
             			#echo "</pre>";
             		}*/
         }
         if (count($this->parsers) > 0) {
             foreach ($this->parsers as $key => $value) {
                 if (isset($A->{$key})) {
                     eval("\$A->\$key = " . $value . "(\"" . $A->{$key} . "\",\"load\", \$A);");
                 }
             }
         }
         $oID = $statement->table[0] . "ID";
         #$cName = $statement->table[0];
         #if(isset($_SESSION["CurrentAppPlugins"]) AND $_SESSION["CurrentAppPlugins"]->isPluginGeneric($cName))
         #	$cName = "Generic";
         $newCOfClass = new $cName($t->{$oID});
         $newCOfClass->setA($A);
         $collector[] = $newCOfClass;
     }
     return $collector;
 }
예제 #8
0
 function loadSingle2($table, $id)
 {
     $sql = "SELECT * FROM {$table} WHERE " . $table . "ID = '{$id}'";
     $q = $this->c->query($sql);
     DBStorage::$queryCounter++;
     $_SESSION["messages"]->addMessage("executing MySQL: {$sql}");
     if ($this->c->error and $this->c->errno == 1146) {
         throw new TableDoesNotExistException($table);
     }
     if ($this->c->error and ($this->c->errno == 1045 or $this->c->errno == 2002)) {
         throw new NoDBUserDataException();
     }
     if ($this->c->error and $this->c->errno == 1054) {
         preg_match("/[a-zA-Z0-9 ]*\\'([a-zA-Z0-9\\.]*)\\'[a-zA-Z ]*\\'([a-zA-Z ]*)\\'.*/", $this->c->error(), $regs);
         throw new FieldDoesNotExistException($regs[1], $regs[2]);
     }
     if ($this->c->error and $this->c->errno == 1046) {
         throw new DatabaseNotSelectedException();
     }
     echo $this->c->error;
     if ($this->c->error and PHYNX_USE_SYSLOG) {
         syslog(LOG_ERR, "MySQL: " . $this->c->error . "(" . $this->c->errno . ") in {$sql}");
     }
     $t = $q->fetch_object();
     $fields = PMReflector::getAttributesArrayAnyObject($t);
     /*if($typsicher){
     			$types = array();
     			$qc = $this->c->query("SHOW COLUMNS FROM $table");
     			DBStorage::$queryCounter++;
     			while($tc = $qc->fetch_object())
     				$types[$tc->Field] = $this->mysql2Object($tc->Type);
     		}*/
     foreach ($fields as $key => $value) {
         $t->{$value} = $this->fixUtf8(stripslashes($t->{$value}));
         /*if($typsicher){
         			if(isset($types[$value])) $typObj = $types[$value];
         			else throw new DataTypeNotDefinedException($value);
         			
         			$t->$value = new $typObj($t->$value);
         		}*/
     }
     return $t;
 }
예제 #9
0
 function loadMultipleV4(SelectStatement $statement, $typsicher = false)
 {
     #echo array_search("t1.".$statement->table[0], $statement->fields);
     unset($statement->fields[array_search("t1." . $statement->table[0] . "ID", $statement->fields)]);
     if (array_search("t1." . $statement->table[0] . "ID AS currentObjectID", $statement->fields) === false) {
         $statement->fields[] = "t1." . $statement->table[0] . "ID AS currentObjectID";
     }
     #print_r($statement->fields);
     #return ;
     if (count($statement->order) == 0) {
         $statement->order[] = "currentObjectID";
         $statement->orderAscDesc[] = "ASC";
     }
     $where = "(";
     $lastKey = "";
     $closeBrackets = "";
     foreach ($statement->whereFields as $key => $value) {
         $addOpenBracket = false;
         if ($where != "(" and $statement->whereBracketGroup[$lastKey] != $statement->whereBracketGroup[$key]) {
             $addOpenBracket = true;
             $where .= ")";
         }
         $currentWhereValue = $statement->whereValues[$key];
         if ($currentWhereValue != "NULL" and $currentWhereValue != "NOT NULL") {
             $currentWhereValue = "'" . mssql_real_escape_string($currentWhereValue) . "'";
         }
         $where .= ($where != "(" ? " " . $statement->whereLogOp[$key] . " " . ($addOpenBracket ? "(" : "") : "") . "[" . $statement->whereFields[$key] . "] " . $statement->whereOperators[$key] . " " . $currentWhereValue . "";
         $lastKey = $key;
     }
     $where .= ")";
     $order = "";
     foreach ($statement->order as $key => $value) {
         $order .= ($order != "" ? ", " : "") . "[" . $statement->order[$key] . "] " . $statement->orderAscDesc[$key];
     }
     $tables = array();
     for ($i = 0; $i < count($statement->joinTables); $i++) {
         if (!isset($tables[$statement->joinTables[$i]])) {
             $tables[$statement->joinTables[$i]] = array();
         }
         $tables[$statement->joinTables[$i]][] = array($statement->joinConditions[$i][0], $statement->joinConditionOperators[$i], $statement->joinConditions[$i][1]);
     }
     $t = 2;
     $joinAdd = "";
     foreach ($tables as $table => $conditions) {
         $ons = "";
         for ($i = 0; $i < count($conditions); $i++) {
             if ($i == 0) {
                 $ons .= ((!strpos($conditions[$i][0], ".") and $conditions[$i][0][0] != " ") ? "t1." : "") . "" . $conditions[$i][0] . " " . $conditions[$i][1] . " t{$t}." . $conditions[$i][2];
             } else {
                 if ($conditions[$i][2] != "NOT NULL" and $conditions[$i][2] != "NULL") {
                     $conditions[$i][2] = "'" . $conditions[$i][2] . "'";
                 }
                 $ons .= " AND t{$t}." . $conditions[$i][0] . " " . $conditions[$i][1] . " " . $conditions[$i][2] . "";
             }
         }
         $joinAdd .= "\n LEFT JOIN [" . $table . "] t{$t} ON({$ons})";
         $t++;
     }
     $sql = "WITH MSOrdered AS (\nSELECT\n (ROW_NUMBER() OVER(ORDER BY {$order})) - 1 AS MSZeilennummer, " . implode(",\n ", $statement->fields) . "\n FROM [" . $statement->table[0] . "] t1{$joinAdd} " . ($where != "()" ? "\n WHERE {$where}" : "") . (count($statement->group) > 0 ? "\n GROUP BY " . implode(", ", $statement->group) : "") . "\n)\n";
     #.(count($statement->limit) > 0 ? "\n LIMIT ".implode(", ",$statement->limit) : "")
     $sql .= "SELECT * FROM MSOrdered";
     $limit = array();
     if (isset($statement->limit[0])) {
         $limit = explode(",", $statement->limit[0]);
     }
     if (count($limit) == 1) {
         $sql .= " WHERE MSZeilennummer < " . $limit[0];
     }
     if (count($limit) == 2) {
         $sql .= " WHERE MSZeilennummer BETWEEN " . $limit[0] . " AND " . $limit[1];
     }
     $sql .= $order != "" ? "\n ORDER BY {$order}" : "";
     $collector = array();
     #if($statement->table[0] != "Userdata")
     $_SESSION["messages"]->startMessage("executing MSSQL: {$sql}");
     #echo nl2br($sql)."<br /><br />";
     $q = mssql_query($sql);
     #echo mssql_get_last_message().": ".(mssql_errno() == 208)."<br />";
     #if(mysql_error() AND (mysql_errno() == 1045 OR mysql_errno() == 2002)) throw new NoDBUserDataException();
     if (mssql_get_last_message() and mssql_errno() == 208) {
         throw new TableDoesNotExistException();
     }
     #if(mysql_error() AND mysql_errno() == 1046) throw new DatabaseNotSelectedException();
     #if(mysql_error() AND mysql_errno() == 1054) {
     #	preg_match("/[a-zA-Z0-9 ]*\'([a-zA-Z0-9\.]*)\'[a-zA-Z ]*\'([a-zA-Z ]*)\'.*/", mysql_error(), $regs);
     #	throw new FieldDoesNotExistException($regs[1],$regs[2]);
     #}
     #if(mysql_error()) echo "MySQL-Fehler: ".mysql_error()."<br />Fehlernummer: ".mysql_errno();
     if ($statement->table[0] != "Userdata") {
         $_SESSION["messages"]->endMessage(": " . mssql_rows_affected($this->connection) . " " . $statement->table[0] . " geladen");
     }
     if ($this->affectedRowsOnly) {
         $this->affectedRowsOnly = false;
         return mssql_rows_affected($this->connection);
     }
     if ($typsicher) {
         $types = array();
         $qc = mssql_query("SHOW COLUMNS FROM " . $statement->table[0]);
         while ($tc = mssql_fetch_object($qc)) {
             $types[$tc->Field] = $this->mysql2Object($tc->Type);
         }
         foreach ($statement->joinTables as $kc => $vc) {
             $qc = mssql_query("SHOW COLUMNS FROM " . $vc);
             while ($tc = mssql_fetch_object($qc)) {
                 $types[$tc->Field] = $this->mysql2Object($tc->Type);
             }
         }
         foreach ($statement->dataTypes as $kc => $vc) {
             $types = array_merge($types, $vc);
         }
     }
     $fields = null;
     while (@($t = mssql_fetch_object($q))) {
         $A = new Attributes();
         if ($fields == null) {
             $fields = PMReflector::getAttributesArrayAnyObject($t);
         }
         foreach ($fields as $key => $value) {
             $A->{$value} = $this->fixUtf8(stripslashes($t->{$value}));
             if ($typsicher) {
                 if (isset($types[$value])) {
                     $typObj = $types[$value];
                 } else {
                     throw new DataTypeNotDefinedException($value);
                 }
                 $A->{$value} = new $typObj($A->{$value});
                 #echo "<pre>";
                 #print_r($A);
                 #echo "</pre>";
             }
         }
         if (count($this->parsers) > 0) {
             foreach ($this->parsers as $key => $value) {
                 if (isset($A->{$key})) {
                     eval("\$A->\$key = " . $value . "(\"" . $A->{$key} . "\",\"load\");");
                 }
             }
         }
         $oID = "currentObjectID";
         $cName = $statement->table[0];
         $newCOfClass = new $cName($t->{$oID});
         $newCOfClass->setA($A);
         $collector[] = $newCOfClass;
     }
     return $collector;
 }
예제 #10
0
 function getBrowserHTML($lineWithId = -1, $useBPS = true)
 {
     $bps = BPS::getAllProperties("m" . $this->className . "GUI");
     if (!$useBPS) {
         $bps = false;
     }
     $GUIF = $this->GUIFactory;
     $GUIF->setMultiPageDetails($this->multiPageDetails);
     $GUIF->setTableMode($this->displayMode);
     $GUIF->options($this->showTrash, $this->showEdit, $this->showNew);
     if ($this->blacklists != null) {
         $GUIF->blacklists($this->blacklists);
     }
     if (isset($bps["selectionMode"])) {
         $GUIF->selection($bps["selectionMode"]);
     }
     #$GUIF->features($this->features);
     #$this->multiPageDetails["target"] = $this->frame;#"contentRight";
     #$GUIF->setMultiPageDetails($this->multiPageDetails);
     $E = $this->object->getNextEntry();
     if ($this->attributes == null and $E != null) {
         $this->attributes = PMReflector::getAttributesArrayAnyObject($E->getA());
     }
     if ($E == null) {
         //To fix display error when no entry
         $this->attributes = array("");
     }
     if ($this->caption == null) {
         $this->caption("Bitte " . ($this->name == null ? $this->className : $this->name) . " auswählen:");
     }
     $Tab = $GUIF->getTable($this->attributes, $this->colStyle, $this->caption);
     $Tab->setTableID("Browserm{$this->className}");
     if ($this->header != null) {
         $Tab->addHeaderRow($this->header);
     }
     if ($lineWithId == -1) {
         if ($this->showQuicksearch) {
             $GUIF->buildQuickSearchLine();
         }
         if ($this->multiPageDetails["total"] > $this->multiPageDetails["perPage"]) {
             $GUIF->buildFlipPageLine("top");
         }
         $GUIF->buildNewEntryLine(($this->name == null ? $this->className : $this->name) . " neu anlegen");
         if ($this->object->isFiltered()) {
             $GUIF->buildFilteredWarningLine();
         }
     }
     $this->object->resetPointer();
     $DisplayGroup = null;
     while ($E = $this->object->getNextEntry()) {
         /**
          * DisplayGroup
          */
         if ($lineWithId == -1 and $this->displayGroup != null and $DisplayGroup != $E->A($this->displayGroup[0])) {
             if ($this->displayGroup[1] != null) {
                 $DGP = explode("::", $this->displayGroup[1]);
                 $GUIF->buildGroupLine(Util::invokeStaticMethod($DGP[0], $DGP[1], array($E->A($this->displayGroup[0]), $E)));
             } else {
                 $GUIF->buildGroupLine($E->A($this->displayGroup[0]));
             }
         }
         $Line = array();
         foreach ($this->attributes as $attributeName) {
             $LineContent = $E->A($attributeName);
             if (isset($this->parsers[$attributeName])) {
                 $LineContent = $this->invokeParser($this->parsers[$attributeName], $LineContent, $E);
             } else {
                 $LineContent = htmlspecialchars($LineContent);
             }
             $Line[] = $LineContent;
         }
         $GUIF->buildLine($E->getID(), $Line);
         if ($this->displayGroup != null) {
             $DisplayGroup = $E->A($this->displayGroup[0]);
         }
     }
     if ($lineWithId == -1) {
         if ($this->object->isFiltered()) {
             $GUIF->buildFilteredWarningLine();
         }
         if ($this->multiPageDetails["total"] > $this->multiPageDetails["perPage"]) {
             $GUIF->buildFlipPageLine("bottom");
         }
     } else {
         return $Tab->getHTMLForUpdate();
     }
     return $this->topButtons($bps) . $this->sideButtons($bps) . $GUIF->getContainer($Tab, $this->caption) . str_replace("%CLASSNAME", $this->className, $this->sortable) . $this->tip;
 }
예제 #11
0
 function loadMultipleV4(SelectStatement $statement, $typsicher = false)
 {
     #file_put_contents(Util::getRootPath()."debug.txt", print_r(debug_backtrace(), true));
     $where = "(";
     $lastKey = "";
     $closeBrackets = "";
     foreach ($statement->whereFields as $key => $value) {
         $addOpenBracket = false;
         if ($where != "(" and $statement->whereBracketGroup[$lastKey] != $statement->whereBracketGroup[$key]) {
             $addOpenBracket = true;
             $where .= ")";
         }
         $currentWhereValue = $statement->whereValues[$key];
         if ($currentWhereValue != "NULL" and $currentWhereValue != "NOT NULL" and substr($currentWhereValue, 0, 3) != "t1." and substr($currentWhereValue, 0, 3) != "t2.") {
             $currentWhereValue = "" . $this->c->quote($currentWhereValue) . "";
         }
         $where .= ($where != "(" ? " " . $statement->whereLogOp[$key] . " " . ($addOpenBracket ? "(" : "") : "") . "" . $statement->whereFields[$key] . " " . $statement->whereOperators[$key] . " " . $currentWhereValue . "";
         $lastKey = $key;
     }
     $where .= ")";
     $order = "";
     foreach ($statement->order as $key => $value) {
         $order .= ($order != "" ? ", " : "") . $statement->order[$key] . " " . $statement->orderAscDesc[$key];
     }
     $tables = array();
     for ($i = 0; $i < count($statement->joinTables); $i++) {
         if (!isset($tables[$statement->joinTables[$i]])) {
             $tables[$statement->joinTables[$i]] = array();
         }
         $tables[$statement->joinTables[$i]][] = array($statement->joinConditions[$i][0], $statement->joinConditionOperators[$i], $statement->joinConditions[$i][1], $statement->joinTypes[$i]);
     }
     $t = 2;
     $joinAdd = "";
     foreach ($tables as $table => $conditions) {
         $type = "LEFT";
         $ons = "";
         for ($i = 0; $i < count($conditions); $i++) {
             if ($i == 0) {
                 $ons .= ((!strpos($conditions[$i][0], ".") and $conditions[$i][0][0] != " ") ? "t1." : "") . "" . $conditions[$i][0] . " " . $conditions[$i][1] . " t{$t}." . $conditions[$i][2];
             } else {
                 if ($conditions[$i][2] != "NOT NULL" and $conditions[$i][2] != "NULL") {
                     $conditions[$i][2] = "'" . $conditions[$i][2] . "'";
                 }
                 $ons .= " AND t{$t}." . $conditions[$i][0] . " " . $conditions[$i][1] . " " . $conditions[$i][2] . "";
             }
             if (isset($conditions[$i][3]) and $conditions[$i][3] != "") {
                 $type = $conditions[$i][3];
             }
         }
         $joinAdd .= "\n {$type} JOIN " . $table . " t{$t} ON({$ons})";
         $t++;
     }
     if ($this->affectedRowsOnly and count($statement->group) === 0) {
         $tempFields = $statement->fields;
         $statement->fields = array("COUNT(*) AS \"anzahlTotal\"");
         $order = "";
     }
     if (count($statement->limit) > 0 and strpos($statement->limit[0], ",") > 0) {
         $statement->limit = explode(",", $statement->limit[0]);
     }
     foreach ($statement->fields as $k => $field) {
         if ($field == "t1." . $statement->table[0] . "ID") {
             $statement->fields[$k] = "t1." . $statement->table[0] . "ID AS \"" . $statement->table[0] . "ID\"";
             if (count($statement->group) > 0) {
                 $statement->fields[$k] = "MAX(t1." . $statement->table[0] . "ID) AS \"" . $statement->table[0] . "ID\"";
             }
             break;
         }
     }
     $sql = "SELECT\n " . implode(",\n ", $statement->fields) . "\n FROM " . $statement->table[0] . " t1{$joinAdd} " . ($where != "()" ? "\n WHERE {$where}" : "") . (count($statement->group) > 0 ? "\n GROUP BY " . implode(", ", $statement->group) : "") . ($order != "" ? "\n ORDER BY {$order}" : "") . (count($statement->limit) == 1 ? "\n LIMIT " . $statement->limit[0] : "") . (count($statement->limit) > 1 ? "\n LIMIT " . $statement->limit[1] . " OFFSET " . $statement->limit[0] : "");
     #echo $sql;
     $collector = array();
     if ($statement->table[0] != "Userdata") {
         $_SESSION["messages"]->startMessage("executing PDO: {$sql}");
     }
     #echo nl2br($sql)."<br /><br />";
     #$q = $this->c->query($sql);
     $q = $this->c->prepare($sql);
     #echo $sql;
     #echo "\n";
     #var_dump($q);
     Timer::now("sql start", __FILE__, __LINE__);
     $q->execute();
     Timer::now("sql end", __FILE__, __LINE__);
     #print_r($this->c->errorInfo());
     DBPDOStorage::$queryCounter++;
     #if($this->c->error AND ($this->c->errno == 1045 OR $this->c->errno == 2002)) throw new NoDBUserDataException();
     #if($this->c->error AND $this->c->errno == 1146) throw new TableDoesNotExistException($statement->table[0]);
     #if($this->c->error AND $this->c->errno == 1046) throw new DatabaseNotSelectedException();
     #if($this->c->error AND $this->c->errno == 1054) {
     #	preg_match("/[a-zA-Z0-9 ]*\'([a-zA-Z0-9\.]*)\'[a-zA-Z ]*\'([a-zA-Z ]*)\'.*/", $this->c->error, $regs);
     #	throw new FieldDoesNotExistException($regs[1],$regs[2]);
     #}
     #if($this->c->error) echo "MySQL-Fehler: ".$this->c->error."<br />Fehlernummer: ".$this->c->errno;
     #echo $sql."<br /><br />";
     #if($statement->table[0] != "Userdata") $_SESSION["messages"]->endMessage(": ".$this->c->affected_rows." ".$statement->table[0]." geladen");
     if ($this->affectedRowsOnly) {
         $this->affectedRowsOnly = false;
         if (count($statement->group) === 0) {
             $statement->fields = $tempFields;
             $t = $q->fetch(PDO::FETCH_OBJ);
             return $t->anzahlTotal;
         }
         return $s->rowCount();
     }
     $fields = null;
     $cName = $statement->table[0];
     if ($statement->className != "") {
         $cName = $statement->className[0];
     }
     while ($t = $q->fetch(PDO::FETCH_OBJ)) {
         $A = new Attributes();
         if ($fields == null) {
             $fields = PMReflector::getAttributesArrayAnyObject($t);
         }
         foreach ($fields as $key => $value) {
             $A->{$value} = stripslashes($t->{$value});
         }
         if (count($this->parsers) > 0) {
             foreach ($this->parsers as $key => $value) {
                 if (isset($A->{$key})) {
                     eval("\$A->\$key = " . $value . "(\"" . $A->{$key} . "\",\"load\", \$A);");
                 }
             }
         }
         $oID = $statement->table[0] . "ID";
         $newCOfClass = new $cName($t->{$oID});
         $newCOfClass->setA($A);
         $collector[] = $newCOfClass;
     }
     return $collector;
 }