Commit 7141afe8 by Frederick d. Maus

files ... vllt auch welche die noch gar keinen sinn ergeben

1 parent f3898423
<?php
class mcMessageReport {
private static $Messages = array();
public static function addMessage($param_subject, $param_Message='') {
mcMessageReport::$Messages[] = array('subject' => $param_subject, 'text' => $param_Message);
}
public static function printMessages() {
echo '<p class="message">';
foreach(mcMessageReport::$Messages as $message) {
echo '<br />' . $message['subject'].': '.$message['text'];
}
echo '</p>';
mcMessageReport::$Messages = array();
}
private static $Errors = array();
public static function addError($param_subject, $param_Message='') {
mcMessageReport::$Errors[] = array('subject' => $param_subject, 'text' => $param_Message);
}
public static function printErrors() {
echo '<p class="meld">';
foreach(mcMessageReport::$Errors as $error) {
echo '<br />' . $error['subject'].' ('.$error['text'].')';
}
echo '</p>';
mcMessageReport::$Errors = array();
}
}
?>
<?php
/**
* noch nicht wirklich entwickelt... eher als notiz zu verstehen
* @since 20110801 @author n@mensch.coop
*/
class mcHeader {
// header('Content-Type: text/html; charset=utf-8');
public function password() {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Text, der gesendet wird, falls der Benutzer auf Abbrechen drückt';
exit;
} else {
echo "<p>Hallo {$_SERVER['PHP_AUTH_USER']}.</p>";
echo "<p>Sie gaben {$_SERVER['PHP_AUTH_PW']} als Passwort ein.</p>";
}
}
}
?>
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class mcInputHandler {
public static $ARRAY_PATTERN = '_#_';
private static $action = false;
private static $POST = array();
private static $GET ;
public static function handleGET(array $param_GET) {
if(array_key_exists('action', $param_GET)) {
mcInputHandler::$action = $param_GET['action'];
}
mcInputHandler::$GET = $param_GET;
}
public static function handlePOST(array &$param_POST) {
mcArray::transformArrayWithStringKeyToNormalKey($param_POST, mcInputHandler::$ARRAY_PATTERN);
mcInputHandler::$POST = &$param_POST;
}
public static function &getPOST() {
return mcInputHandler::$POST;
}
public static function getGET() {
return mcInputHandler::$GET;
}
public static function getAction() {
return mcInputHandler::$action;
}
public static function getActionID() {
if(array_key_exists('ID', mcInputHandler::$GET)) {
return mcInputHandler::$GET['ID'];
}
}
public static function getActionMenuLink($param_action, $param_ID=''){
if($param_ID) {
$ID = '&ID='.$param_ID;
} else {
$ID = '';
}
return '?action='.$param_action.$ID;
}
/**
*
* @param type $param_label
* @param type $param_action
* @param type $param_ID
* @return type
*/
public static function getHrefActionMenuLink($param_label, $param_action, $param_ID=''){
return '<a href="'.self::getActionMenuLink($param_action, $param_ID).'">'.$param_label.'</a>';
}
}
?>
<?php
class mcSort {
public static function sortObjs(array $param_objs, $param_column) {
$objs = $param_objs;
$RelationObjcts_count = count($objs);
if(is_array($objs) && !empty($objs)) {
$tmp_sort_short = array();
foreach($objs as $key => $Relation) {
$tmp_sort_short[$key] = $Relation->$param_column;
}
asort($tmp_sort_short);
$tmp_sort_objects = array();
foreach($tmp_sort_short as $key => $column_value) {
$tmp_sort_objects[] = $objs[$key];
}
$param_objs = $tmp_sort_objects;
if($RelationObjcts_count == count($param_objs)) {
return $param_objs;
} else {
D::li('weniger als vorher '.$param_column);
return false;
}
} else {
D::li('no Relation exists with this name '.$param_column);
return false;
}
}
}
?>
/home/dev/arphp
\ No newline at end of file
<?php
class mcActiveRecord extends ActiveRecord {
public static function PDO_query($param_query, array $param_bindValueArray=null) {
$pdo = ActiveDB::getConnection();
try {
$stmt = $pdo->prepare($param_query);
if(!$stmt) {
D::backtrace('PDO SQL ERROR');
D::ulli("PDO_query(".$param_query.")");
D::show($pdo->errorInfo(), $pdo->errorCode());
D::show(PDO::getAvailableDrivers ( void ), 'PDO::getAvailableDrivers ( void )');
// handle($param_errno, $param_errstr, $param_errfile, $param_errline, $param_errcontext)
mcErrorEvent::handle('PDOSql', "error(".$pdo->errorCode().")", null, null, $param_query);
return false;
}
if($param_bindValueArray!==null) {
foreach($param_bindValueArray as $key => $value) {
$stmt->bindValue($key,$value);
}
}
$stmt->execute();
} catch (PDOException $e) {
D::backtrace();
D::printPDOQuery($param_query, $param_bindValueArray);
mcException::handleException($e);
}
if($stmt->errorCode() == "42000") {
D::backtrace('PDO SQL ERROR');
D::ulli("PDO_query(".$param_query.")");
D::show($stmt->errorInfo(), $stmt->errorCode());
mcErrorEvent::handle($param_typ='PDOSql', "error(".$stmt->errorCode().")", null, null, $param_query);
return false;
}
return $stmt;
}
public static function PDO_fetchAll(PDOStatement $param_stmt) {
try {
$var_result = $param_stmt->fetchAll(PDO::FETCH_ASSOC);
$param_stmt->closeCursor();
return $var_result;
} catch (PDOException $e) {
mcException::handleException($e);
}
}
/**
* fnc sort relations
*
* @todo überprüfen ob sort alg stabil ist
*
*
* @since 20120125 @author neumann@netz.coop
*
* @arphp -- fnc zum commiten
*
* @param type $param_RelationName
* @param type $param_column
* @return boolean
*/
public function sortManyRel($param_RelationName, $param_column) {
$relationobjs = mcSort::sortObjs($this->$param_RelationName, $param_column);
if(is_array($relationobjs)) {
$this->$param_RelationName = $relationobjs;
return true;
} else {
return false;
}
}
public function existColumn($varName){
//D::li($varName,1,1);
if(array_key_exists($varName,$this->dbFields)){
return true;
}
if(array_key_exists($varName,$this->hasOneObjects)){
return true;
}
//1:n beziehungen werden erst beim 1.aufruf geladen
if(array_key_exists($varName,$this->hasManyObjects)){
return true;
}
//n:m beziehungen werden erst beim 1.aufruf geladen
if(array_key_exists($varName,$this->hasManyBelongsToObjects)){
return true;
}
return false;
}
/**
* show ActiveRecord Array in html table
*
* @param array $praram_ActiveRecords
* @param array $param_ShowColumns -- array(
* 'col1'=>null,
* 'col2'=>array('link' => array(action=>'do',ID=1),
* 'col3'=>array('type'=>'date||euro'),
* 'col4'=>array('hasOneRel' => 'activerecortclassname'),
* )
* @param string $param_subject
* @param array $param_headrow=null
* @param type $param_SortColumn
* @param array $param_marked
* @param
*/
public static function showArray(array $praram_ActiveRecords, array $param_ShowColumns, $param_subject="", array $param_headrow=null, $param_SortColumn=null, array $param_marked=null, array $param_summaryline=null ) {
if(count($praram_ActiveRecords) && count($param_ShowColumns)) {
$Display_sortRealtions = array();
if(!is_null($param_headrow)) {
$Display_sortRealtions[] = $param_headrow;
}
if(!is_null($param_SortColumn)) {
$praram_ActiveRecords= mcSort::sortObjs($praram_ActiveRecords, $param_SortColumn);
}
if(is_array($param_summaryline) && count($praram_ActiveRecords)>1) {
$summaryline = array();
$lastline = array();
}
foreach($praram_ActiveRecords as $relationobj) {
if(!is_null($param_marked)) {
$m_bool =array();
foreach($param_marked as $mkey => $mvalue) {
if($relationobj->$mkey == $mvalue) {
$m_bool[$mkey] = $mvalue;
}
}
if($m_bool == $param_marked) {
$b1 = '<u>';
$b2 = '</u>';
} else {
$b1 = $b2 = '';
}
}
$Display_Line = array();
foreach($param_ShowColumns as $columnname => $columnoptions) {
// D::li($columnname,1,1);
if(is_array($columnoptions)) {
if(array_key_exists('hasOneRel', $columnoptions) && $columnoptions['hasOneRel']) {
if($relationobj->$columnoptions['hasOneRel']->existColumn($columnname)) {
$Display_value = $relationobj->$columnoptions['hasOneRel']->$columnname;
} else if(array_key_exists('valueIsFnc', $columnoptions) && $columnoptions['valueIsFnc']) {
$return = $relationobj->$columnoptions['hasOneRel']->$columnname();
if(is_array($return) && array_key_exists('returnKey', $columnoptions['valueIsFnc'])) {
$Display_value = $return[$columnoptions['valueIsFnc']['returnKey']];
} else if(!is_array($return)) {
$Display_value = $return;
} else {
D::li('config Error');
}
} else {
$Display_value = mcLanguage::getWord($columnname);
}
} else {
if($relationobj->existColumn($columnname)) {
$Display_value = $relationobj->$columnname;
} else if(array_key_exists('valueIsFnc', $columnoptions) && $columnoptions['valueIsFnc']) {
$return = $relationobj->$columnname();
if(is_array($return) && array_key_exists('returnKey', $columnoptions['valueIsFnc'])) {
$Display_value = $return[$columnoptions['valueIsFnc']['returnKey']];
} else if(!is_array($return)) {
$Display_value = $return;
} else {
D::li('config Error');
}
} else {
$Display_value = mcLanguage::getWord($columnname);
}
}
} else {
if($relationobj->existColumn($columnname)) {
$Display_value = $relationobj->$columnname;
} else {
$Display_value = mcLanguage::getWord($columnname);
}
}
if(is_array($param_summaryline) && array_key_exists($columnname, $param_summaryline)) {
if($param_summaryline[$columnname] == 'summation') {
$summaryline[$columnname] += $Display_value;
}
}
if(empty($columnoptions)) {
$Line = $b1.$Display_value.$b2;
} else if($columnoptions['type']=='euro') {
$Line = $b1.mcNumber::form2($Display_value).' €'.$b2;
} else if($columnoptions['type']=='date') {
$Line = $b1.mcDate::format8601Date($Display_value).''.$b2;
} else {
$Line = $b1.$Display_value.$b2;
}
if(!empty($columnoptions) && array_key_exists('link', $columnoptions) && is_array($columnoptions['link'])) {
if(array_key_exists('hasOneRel', $columnoptions) && $columnoptions['hasOneRel']) {
$Display_Line[] = mcInputHandler::getHrefActionMenuLink($Line, $columnoptions['link']['action'], $relationobj->$columnoptions['hasOneRel']->$columnoptions['link']['ID']);
} else {
$Display_Line[] = mcInputHandler::getHrefActionMenuLink($Line, $columnoptions['link']['action'], $relationobj->$columnoptions['link']['ID']);
}
} else {
$Display_Line[] = $Line;
}
}
$Display_sortRealtions[] = $Display_Line;
}
if(is_array($lastline)) {
foreach($param_ShowColumns as $columnname => $columnoptions) {
if(array_key_exists($columnname, $summaryline)) {
if(empty($columnoptions)) {
$lastline[] = $summaryline[$columnname];
} else if($columnoptions['type']=='euro') {
$lastline[] = mcNumber::form2($summaryline[$columnname]).' €';
} else if($columnoptions['type']=='date') {
$lastline[] = mcDate::format8601Date($summaryline[$columnname]).'';
} else {
$lastline[] = $summaryline[$columnname];
}
} else {
$lastline[] = '';
}
}
$Display_sortRealtions[] = $lastline;
}
mcTableHtml::showTable($Display_sortRealtions, $param_subject);
}
if(is_array($summaryline)) {
return $summaryline;
}
}
}
?>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!