From 3ff03dc4f0a72432b34c00da620272cf011e4ddd Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 29 Jul 2021 14:17:20 +1000 Subject: Publishing h-node.org code. - this is the h-node.org code, except - removed a js file (3x copies at three different locations) without license / copyright headers - /Js/linkToForm.js - /Public/Js/linkToForm.js - /admin/Public/Js/linkToForm.js - removed config files containing credentials - /Application/Include/params.php - /Config/Config.php - /admin/Application/Include/params.php - /admin/Config/Config.php - added license and copyright header to one php file - /admin/Library/ErrorReporting.php (almost identical to /Library/ErrorReporting.php which has the headers) --- h-source/Library/Array/Validate/Base.php | 106 +- h-source/Library/Array/Validate/Soft.php | 76 +- h-source/Library/Array/Validate/Strong.php | 90 +- h-source/Library/Array/Validate/Values.php | 36 - h-source/Library/ArrayExt.php | 4 +- h-source/Library/Bootstrap.php | 2 +- h-source/Library/BoxParser.php | 2 +- h-source/Library/Call.php | 208 +--- h-source/Library/Controller.php | 29 +- h-source/Library/Db/Mysql.php | 178 +-- h-source/Library/Db/Mysqli.php | 264 +---- h-source/Library/Email.php | 2 +- h-source/Library/ErrorReporting.php | 2 +- h-source/Library/Factory/Db.php | 2 +- h-source/Library/Factory/Strings.php | 2 +- h-source/Library/Files/Log.php | 2 +- h-source/Library/Files/Upload.php | 24 +- h-source/Library/Form/Checkbox.php | 4 +- h-source/Library/Form/Entry.php | 3 +- h-source/Library/Form/File.php | 4 +- h-source/Library/Form/Form.php | 120 +- h-source/Library/Form/Hidden.php | 4 +- h-source/Library/Form/Html.php | 2 +- h-source/Library/Form/InputText.php | 4 +- h-source/Library/Form/Password.php | 4 +- h-source/Library/Form/Radio.php | 4 +- h-source/Library/Form/Select.php | 4 +- h-source/Library/Form/Textarea.php | 4 +- h-source/Library/Functions.php | 186 +--- h-source/Library/HeaderObj.php | 2 +- h-source/Library/Helper/Array.php | 2 +- h-source/Library/Helper/Html.php | 2 +- h-source/Library/Helper/List.php | 288 +---- h-source/Library/Helper/Menu.php | 40 +- h-source/Library/Helper/Pages.php | 15 +- h-source/Library/Helper/Popup.php | 46 +- h-source/Library/Hooks.php | 2 +- h-source/Library/Html/Form.php | 48 +- h-source/Library/Image/Gd/Captcha.php | 2 +- h-source/Library/Image/Gd/Thumbnail.php | 246 +---- h-source/Library/Lang/En/DbCondStrings.php | 6 +- h-source/Library/Lang/En/Formats/Fields.php | 46 - h-source/Library/Lang/En/Formats/From/Mysql.php | 64 -- h-source/Library/Lang/En/Formats/From/index.html | 1 - h-source/Library/Lang/En/Formats/To/Mysql.php | 62 -- h-source/Library/Lang/En/Formats/To/index.html | 1 - h-source/Library/Lang/En/Formats/index.html | 1 - h-source/Library/Lang/En/Generic.php | 5 +- h-source/Library/Lang/En/ModelStrings.php | 24 +- h-source/Library/Lang/En/UploadStrings.php | 2 +- h-source/Library/Lang/En/ValCondStrings.php | 68 +- h-source/Library/Lang/Eng/DbCondStrings.php | 2 +- h-source/Library/Lang/Eng/Generic.php | 21 +- h-source/Library/Lang/Eng/ModelStrings.php | 5 +- h-source/Library/Lang/Eng/UploadStrings.php | 2 +- h-source/Library/Lang/Eng/ValCondStrings.php | 52 +- h-source/Library/Lang/ResultStrings.php | 2 +- h-source/Library/ModAbstract.php | 2 +- h-source/Library/Model/#Base.php# | 1273 ++++++++++++++++++++++ h-source/Library/Model/Base.php | 607 ++--------- h-source/Library/Model/Map.php | 2 +- h-source/Library/Model/Tree.php | 560 ++-------- h-source/Library/Params.php | 68 +- h-source/Library/Popup.php | 2 +- h-source/Library/Request.php | 2 +- h-source/Library/Scaffold.php | 123 +-- h-source/Library/Strings/Functions.php | 2 +- h-source/Library/Theme.php | 40 +- h-source/Library/Url.php | 24 +- h-source/Library/Users/CheckAdmin.php | 12 +- 70 files changed, 1988 insertions(+), 3158 deletions(-) delete mode 100644 h-source/Library/Array/Validate/Values.php delete mode 100644 h-source/Library/Lang/En/Formats/Fields.php delete mode 100644 h-source/Library/Lang/En/Formats/From/Mysql.php delete mode 100755 h-source/Library/Lang/En/Formats/From/index.html delete mode 100644 h-source/Library/Lang/En/Formats/To/Mysql.php delete mode 100755 h-source/Library/Lang/En/Formats/To/index.html delete mode 100755 h-source/Library/Lang/En/Formats/index.html create mode 100755 h-source/Library/Model/#Base.php# (limited to 'h-source/Library') diff --git a/h-source/Library/Array/Validate/Base.php b/h-source/Library/Array/Validate/Base.php index f1a242e..fb4a66c 100644 --- a/h-source/Library/Array/Validate/Base.php +++ b/h-source/Library/Array/Validate/Base.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -26,7 +26,6 @@ if (!defined('EG')) die('Direct access not allowed!'); class Array_Validate_Base { - public $strength; public $errorString = null; //string containing the list fields not found public $errorsNumb = null; //numbers of errors @@ -45,40 +44,7 @@ class Array_Validate_Base $this->_resultString = new $stringClass(); } - public function checkNotEmpty($associativeArray,$keyString) - { - $errorString = null; - $keyArray = explode(',',$keyString); - $numb = 0; - for ($i = 0; $i < count($keyArray); $i++) - { - if (array_key_exists($keyArray[$i],$associativeArray)) - { - if (is_array($associativeArray[$keyArray[$i]])) - { - $errorString .= $this->_resultString->getNotDefinedResultString($keyArray[$i]); - $numb++; - } - else - { - if (strcmp(trim($associativeArray[$keyArray[$i]]),'') === 0) - { - $errorString .= $this->_resultString->getNotDefinedResultString($keyArray[$i]); - $numb++; - } - } - } - else - { - $errorString .= $this->_resultString->getNotDefinedResultString($keyArray[$i]); - $numb++; - } - } - $this->errorString = $errorString; - $this->errorNumb = $numb; - return $numb === 0 ? true : false; - } - + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are not '' and are equal (===) to each other public function checkEqual($associativeArray,$keyString) { @@ -150,13 +116,6 @@ class Array_Validate_Base } - //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are integer strings - //$strength: hard or soft. If $strength is set equal to soft than non check is made upon array values equalt to '' or null - public function checkInteger($associativeArray,$keyString,$strength = 'strong') - { - return $this->checkGeneric($associativeArray,$keyString,$strength,'checkInteger','getNotIntegerFormatResultString'); - } - //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) is a number (integer or number). It makes use of the is_numeric PHP built-in function //$strength: hard or soft. If $strength is set equal to soft than non check is made upon array values equalt to '' or null public function checkNumeric($associativeArray,$keyString,$strength = 'strong') @@ -164,12 +123,6 @@ class Array_Validate_Base return $this->checkGeneric($associativeArray,$keyString,$strength,'is_numeric','getNotNumericResultString'); } - //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are an ISO date. - //$strength: hard or soft. If $strength is set equal to soft than non check is made upon array values equalt to '' or null - public function checkIsoDate($associativeArray,$keyString,$strength = 'strong') - { - return $this->checkGeneric($associativeArray,$keyString,$strength,'checkIsoDate','getNotDateResultString'); - } //apply a generic check function //$strength: hard or soft. If $strength is set equal to soft than non check is made upon array values equalt to '' or null @@ -186,7 +139,7 @@ class Array_Validate_Base { if (array_key_exists($keyArray[$i],$associativeArray)) { - if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $this->strength === 'strong') + if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $strength === 'strong') { if (!call_user_func($func,$associativeArray[$keyArray[$i]])) { @@ -264,7 +217,7 @@ class Array_Validate_Base { if (array_key_exists($keyArray[$i],$associativeArray)) { - if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $this->strength === 'strong') + if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $strength === 'strong') { if (!in_array($associativeArray[$keyArray[$i]],$stringsArray)) { @@ -281,50 +234,25 @@ class Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) match the regular expression $regExp public function checkMatch($associativeArray,$keyString,$regExp = '/./',$strength = 'strong') { - $errorString = null; - $keyArray = explode(',',$keyString); - $numb = 0; - for ($i = 0; $i < count($keyArray); $i++) - { - if (array_key_exists($keyArray[$i],$associativeArray)) - { - if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $this->strength === 'strong') - { - if (!preg_match($regExp,$associativeArray[$keyArray[$i]])) - { - $numb++; - $errorString .= $this->_resultString->getDoesntMatchResultString($keyArray[$i],$regExp); - } - } - } - } - $this->errorString = $errorString; - return $numb === 0 ? true : false; - } - - //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are decimal with the format indicated in $format - //$format: M,D M is the maximum number of digits, D is the number of digits to the right of the decimal point - public function checkDecimal($associativeArray,$keyString,$format = '10,2') - { - $errorString = null; - $keyArray = explode(',',$keyString); - $numb = 0; - for ($i = 0; $i < count($keyArray); $i++) - { - if (array_key_exists($keyArray[$i],$associativeArray)) + $errorString = null; + $keyArray = explode(',',$keyString); + $numb = 0; + for ($i = 0; $i < count($keyArray); $i++) { - if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $this->strength === 'strong') + if (array_key_exists($keyArray[$i],$associativeArray)) { - if (!checkDecimal($associativeArray[$keyArray[$i]],$format)) + if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $strength === 'strong') { - $numb++; - $errorString .= $this->_resultString->getNotDecimalResultString($keyArray[$i],$format); + if (!preg_match($regExp,$associativeArray[$keyArray[$i]])) + { + $numb++; + $errorString .= $this->_resultString->getDoesntMatchResultString($keyArray[$i],$regExp); + } } } } - } - $this->errorString = $errorString; - return $numb === 0 ? true : false; + $this->errorString = $errorString; + return $numb === 0 ? true : false; } } \ No newline at end of file diff --git a/h-source/Library/Array/Validate/Soft.php b/h-source/Library/Array/Validate/Soft.php index d790652..b348bdc 100644 --- a/h-source/Library/Array/Validate/Soft.php +++ b/h-source/Library/Array/Validate/Soft.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -26,11 +26,77 @@ if (!defined('EG')) die('Direct access not allowed!'); class Array_Validate_Soft extends Array_Validate_Base { - public function __construct($lang = 'En') + public function __construct($lang = 'Eng') { parent::__construct($lang); - - $this->strength = "soft"; + } + + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are not '' and are equal (===) to each other + public function checkEqual($associativeArray,$keyString) + { + return parent::checkEqual($associativeArray,$keyString); + } + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are alphabetic values + public function checkAlpha($associativeArray,$keyString) + { + return parent::checkAlpha($associativeArray,$keyString,'soft'); + } + + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are alphanumeric values + public function checkAlphaNum($associativeArray,$keyString) + { + return parent::checkAlphaNum($associativeArray,$keyString,'soft'); + } + + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are decimal digits + public function checkDigit($associativeArray,$keyString) + { + return parent::checkDigit($associativeArray,$keyString,'soft'); + } + + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) have mail format + public function checkMail($associativeArray,$keyString) + { + return parent::checkMail($associativeArray,$keyString,'soft'); + } + + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) is a number (integer or number). It makes use of the is_numeric PHP built-in function + public function checkNumeric($associativeArray,$keyString) + { + return parent::checkNumeric($associativeArray,$keyString,'soft'); + } + + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) have a number of chars smaller than $maxLenght + public function checkLength($associativeArray,$keyString,$maxLength = 10) + { + return parent::checkLength($associativeArray,$keyString,$maxLength); + } + + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are different from the values indicated in the argument $strings (a comma-separated list of words) + public function checkIsNotStrings($associativeArray,$keyString,$strings = '') + { + return parent::checkIsNotStrings($associativeArray,$keyString,$strings); + } + + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are one of the values indicated in the argument $strings (a comma-separated list of words) + public function checkIsStrings($associativeArray,$keyString,$strings = '') + { + return parent::checkIsStrings($associativeArray,$keyString,$strings,'soft'); + } + + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) match the regular expression $regExp + public function checkMatch($associativeArray,$keyString,$regExp = '/./') + { + return parent::checkMatch($associativeArray,$keyString,$regExp,'soft'); } -} +} \ No newline at end of file diff --git a/h-source/Library/Array/Validate/Strong.php b/h-source/Library/Array/Validate/Strong.php index d907d1d..ccdce74 100644 --- a/h-source/Library/Array/Validate/Strong.php +++ b/h-source/Library/Array/Validate/Strong.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -22,17 +22,42 @@ if (!defined('EG')) die('Direct access not allowed!'); -//class to validate associative arrays +//class to manage arrays class Array_Validate_Strong extends Array_Validate_Base { - public function __construct($lang = 'En') + public function __construct($lang = 'Eng') { parent::__construct($lang); - - $this->strength = "strong"; } + + public function checkNotEmpty($associativeArray,$keyString) + { + $errorString = null; + $keyArray = explode(',',$keyString); + $numb = 0; + for ($i = 0; $i < count($keyArray); $i++) + { + if (array_key_exists($keyArray[$i],$associativeArray)) + { + if (strcmp(trim($associativeArray[$keyArray[$i]]),'') === 0) + { + $errorString .= $this->_resultString->getNotDefinedResultString($keyArray[$i]); + $numb++; + } + } + else + { + $errorString .= $this->_resultString->getNotDefinedResultString($keyArray[$i]); + $numb++; + } + } + $this->errorString = $errorString; + $this->errorNumb = $numb; + return $numb === 0 ? true : false; + } + //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are not '' and are equal (===) to each other public function checkEqual($associativeArray,$keyString) { @@ -47,7 +72,7 @@ class Array_Validate_Strong extends Array_Validate_Base } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are alphabetic values - public function checkAlpha($associativeArray,$keyString,$strength = 'strong') + public function checkAlpha($associativeArray,$keyString) { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -61,7 +86,7 @@ class Array_Validate_Strong extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are alphanumeric values - public function checkAlphaNum($associativeArray,$keyString,$strength = 'strong') + public function checkAlphaNum($associativeArray,$keyString) { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -75,7 +100,7 @@ class Array_Validate_Strong extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are decimal digits - public function checkDigit($associativeArray,$keyString,$strength = 'strong') + public function checkDigit($associativeArray,$keyString) { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -89,7 +114,7 @@ class Array_Validate_Strong extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) have mail format - public function checkMail($associativeArray,$keyString,$strength = 'strong') + public function checkMail($associativeArray,$keyString) { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -102,21 +127,8 @@ class Array_Validate_Strong extends Array_Validate_Base } - //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are an ISO date. - public function checkIsoDate($associativeArray,$keyString,$strength = 'strong') - { - if ($this->checkNotEmpty($associativeArray,$keyString)) - { - - return parent::checkIsoDate($associativeArray,$keyString,'strong'); - - } else { - return false; - } - } - //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) is a number (integer or number). It makes use of the is_numeric PHP built-in function - public function checkNumeric($associativeArray,$keyString,$strength = 'strong') + public function checkNumeric($associativeArray,$keyString) { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -128,18 +140,6 @@ class Array_Validate_Strong extends Array_Validate_Base } } - //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) is an integer string. - public function checkInteger($associativeArray,$keyString,$strength = 'strong') - { - if ($this->checkNotEmpty($associativeArray,$keyString)) - { - - return parent::checkInteger($associativeArray,$keyString,'strong'); - - } else { - return false; - } - } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) have a number of chars smaller than $maxLenght public function checkLength($associativeArray,$keyString,$maxLength = 10) @@ -170,7 +170,7 @@ class Array_Validate_Strong extends Array_Validate_Base //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are one of the values indicated in the argument $strings (a comma-separated list of words) - public function checkIsStrings($associativeArray,$keyString,$strings = '',$strength = 'strong') + public function checkIsStrings($associativeArray,$keyString,$strings = '') { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -183,7 +183,7 @@ class Array_Validate_Strong extends Array_Validate_Base } //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) match the regular expression $regExp - public function checkMatch($associativeArray,$keyString,$regExp = '/./',$strength = 'strong') + public function checkMatch($associativeArray,$keyString,$regExp = '/./') { if ($this->checkNotEmpty($associativeArray,$keyString)) { @@ -194,18 +194,4 @@ class Array_Validate_Strong extends Array_Validate_Base return false; } } - - //verify that the values of the associative array ($associativeArray) indicated by the key string ($keyString) are decimal with the format indicated in $format - //$format: M,D M is the maximum number of digits, D is the number of digits to the right of the decimal point - public function checkDecimal($associativeArray,$keyString,$format = '10,2') - { - if ($this->checkNotEmpty($associativeArray,$keyString)) - { - - return parent::checkDecimal($associativeArray,$keyString,$format); - - } else { - return false; - } - } -} +} \ No newline at end of file diff --git a/h-source/Library/Array/Validate/Values.php b/h-source/Library/Array/Validate/Values.php deleted file mode 100644 index 9355949..0000000 --- a/h-source/Library/Array/Validate/Values.php +++ /dev/null @@ -1,36 +0,0 @@ -. - -if (!defined('EG')) die('Direct access not allowed!'); - -//class to validate associative arrays -class Array_Validate_Values extends Array_Validate_Soft -{ - - public function __construct($lang = 'En') - { - parent::__construct($lang); - - $this->strength = "strong"; - } - -} diff --git a/h-source/Library/ArrayExt.php b/h-source/Library/ArrayExt.php index d4300b4..2b02c9e 100755 --- a/h-source/Library/ArrayExt.php +++ b/h-source/Library/ArrayExt.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -50,7 +50,7 @@ class ArrayExt { if (!in_array($temp[1],explode(',',Params::$allowedSanitizeFunc))) { throw new Exception('"'.$temp[1]. '" function not allowed'); } - if (array_key_exists($temp[0],$associativeArray) and !is_array($associativeArray[$temp[0]])) { + if (array_key_exists($temp[0],$associativeArray)) { $tempArray[$temp[0]] = call_user_func($temp[1],$associativeArray[$temp[0]]); } else { $tempArray[$temp[0]] = ''; diff --git a/h-source/Library/Bootstrap.php b/h-source/Library/Bootstrap.php index aa32041..5d7a12f 100755 --- a/h-source/Library/Bootstrap.php +++ b/h-source/Library/Bootstrap.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/BoxParser.php b/h-source/Library/BoxParser.php index 302439a..0e7e03f 100644 --- a/h-source/Library/BoxParser.php +++ b/h-source/Library/BoxParser.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Call.php b/h-source/Library/Call.php index 7f80841..c75508b 100755 --- a/h-source/Library/Call.php +++ b/h-source/Library/Call.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -35,40 +35,19 @@ function sanitizeSuperGlobal() $_SERVER = stripslashesDeep($_SERVER); } -function checkPostLength($checkArray = null) + + +function checkPostLength() { - $a = isset($checkArray) ? $checkArray : $_POST; - if (MAX_POST_LENGTH !== 0) { - foreach ($a as $key => $value) + foreach ($_POST as $key => $value) { - if (is_array($value)) - { - checkPostLength($value); - } - else - { - if (strlen($value) > MAX_POST_LENGTH) die('the length of some of the $_POST values is too large'); - } + if (strlen($value) > MAX_POST_LENGTH) die('the length of some of the $_POST values is too large'); } } } -//remove elements that are arrays -//applied to $_POST and $_GET -function fixArray($array) -{ - $temp = array(); - - foreach ($array as $key => $value) - { - $temp[$key] = is_array($value) ? "" : $value; - } - - return $temp; -} - function checkRequestUriLength() { if (MAX_REQUEST_URI_LENGTH !== 0) @@ -82,108 +61,20 @@ function checkRegisterGlobals() if (ini_get('register_globals')) die('register globals is on: easyGiant works only with register globals off'); } -//geth the name of the current application used -function getApplicationName() -{ - if (isset(Params::$currentApplication)) - { - return Params::$currentApplication; - } - return null; -} - -//geth the path of the current application used -//add the trailing slash to the application name -function getApplicationPath() -{ - if (isset(Params::$currentApplication)) - { - return "Apps".DS.ucfirst(Params::$currentApplication).DS; - } - return null; -} - -function languageInUrl($url) -{ - $url = trim($url,"/"); - - if (in_array($url,Params::$frontEndLanguages)) - { - return $url."/"; - } - return false; -} - function callHook() { - + $currentUrl = null; if (MOD_REWRITE_MODULE === true) { - if (isset($_GET['url'])) - { - if (!languageInUrl($_GET['url'])) - { - $url = $_GET['url']; - } - else - { - $url = languageInUrl($_GET['url']) . DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION; - } - } - else - { - $url = DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION; - } + $url = isset($_GET['url']) ? $_GET['url'] : DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION; } else { - if (strcmp(getQueryString(),"") !== 0) - { - if (!languageInUrl(getQueryString())) - { - $url = getQueryString(); - } - else - { - $url = languageInUrl(getQueryString()) . DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION; - } - } - else - { - $url = DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION; - } + $url = (strcmp(getQueryString(),"") !== 0) ? getQueryString() : DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION; } - $arriveUrl = $url; - - $urlArray = array(); - $urlArray = explode("/",$url); - - //get the language - if (count(Params::$frontEndLanguages) > 0) - { - if (in_array($urlArray[0],Params::$frontEndLanguages)) - { - Params::$lang = sanitizeAll($urlArray[0]); - array_shift($urlArray); - } - else - { - Params::$lang = Params::$defaultFrontEndLanguage; -/* - if (isset($_GET['url']) and Params::$redirectToDefaultLanguage) - { - $h = new HeaderObj(DOMAIN_NAME); - - $h->redirect($arriveUrl); - }*/ - } - } - - $url = implode("/",$urlArray); - // rewrite the URL if (Route::$rewrite === 'yes') { @@ -194,19 +85,12 @@ function callHook() // echo $url; + $urlArray = array(); $urlArray = explode("/",$url); + $controller = DEFAULT_CONTROLLER; $action = DEFAULT_ACTION; - - //check if an application name is found in the URL - if (isset(Params::$installed) and isset($urlArray[0]) and strcmp($urlArray[0],'') !== 0 and in_array($urlArray[0],Params::$installed)) - { - Params::$currentApplication = strtolower(trim($urlArray[0])); - - array_shift($urlArray); - } - if (isset($urlArray[0])) { $controller = (strcmp($urlArray[0],'') !== 0) ? strtolower(trim($urlArray[0])) : DEFAULT_CONTROLLER; @@ -223,31 +107,11 @@ function callHook() $errorController = ERROR_CONTROLLER !== false ? ERROR_CONTROLLER : DEFAULT_CONTROLLER; $errorAction = ERROR_ACTION !== false ? ERROR_ACTION : DEFAULT_ACTION; - /* - CHECK COUPLES CONTROLLER,ACTION - */ - if (!in_array('all',Route::$allowed)) - { - $couple = "$controller,$action"; - if (getApplicationName() !== null) - { - $couple = getApplicationName().",".$couple; - } - if (!in_array($couple,Route::$allowed)) - { - Params::$currentApplication = null; - $controller = $errorController; - $action = $errorAction; - $urlArray = array(); - } - } - /* VERIFY THE ACTION NAME - */ + */ if (method_exists('Controller', $action) or !ctype_alnum($action) or (strcmp($action,'') === 0)) { - Params::$currentApplication = null; $controller = $errorController; $action = $errorAction; $urlArray = array(); @@ -258,7 +122,6 @@ function callHook() */ if (!ctype_alnum($controller) or (strcmp($controller,'') === 0)) { - Params::$currentApplication = null; $controller = $errorController; $action = $errorAction; $urlArray = array(); @@ -266,10 +129,8 @@ function callHook() //check that the controller class belongs to the application/controllers folder //otherwise set the controller to the default controller - // if (!file_exists(ROOT.DS.APPLICATION_PATH.DS.'Controllers'.DS.ucwords($controller).'Controller.php') and !file_exists(ROOT.DS.APPLICATION_PATH.DS.getApplicationPath().'Controllers'.DS.ucwords($controller).'Controller.php')) - if (!file_exists(ROOT.DS.APPLICATION_PATH.DS.getApplicationPath().'Controllers'.DS.ucwords($controller).'Controller.php')) + if (!file_exists(ROOT.DS.APPLICATION_PATH.DS.'Controllers'.DS.ucwords($controller).'Controller.php')) { - Params::$currentApplication = null; $controller = $errorController; $action = $errorAction; $urlArray = array(); @@ -278,7 +139,6 @@ function callHook() //set the controller class to DEFAULT_CONTROLLER if it doesn't exists if (!class_exists(ucwords($controller).'Controller')) { - Params::$currentApplication = null; $controller = $errorController; $action = $errorAction; $urlArray = array(); @@ -287,28 +147,40 @@ function callHook() //set the action to DEFAULT_ACTION if it doesn't exists if (!method_exists(ucwords($controller).'Controller', $action)) { - Params::$currentApplication = null; $controller = $errorController; $action = $errorAction; $urlArray = array(); } + + /* + CHECK COUPLES CONTROLLER,ACTION + */ + if (!in_array('all',Route::$allowed)) + { + $couple = "$controller,$action"; + if (!in_array($couple,Route::$allowed)) + { + $controller = $errorController; + $action = $errorAction; + $urlArray = array(); + } + } array_shift($urlArray); $queryString = $urlArray; //set the name of the application - $controllerName = $controller; + $application = $controller; $controller = ucwords($controller); $model = $controller; $controller .= 'Controller'; $model .= 'Model'; -// echo $controller."-".$action; //include the file containing the set of actions to carry out before the initialization of the controller class Hooks::load(ROOT . DS . APPLICATION_PATH . DS . 'Hooks' . DS . 'BeforeInitialization.php'); if (class_exists($controller)) { - $dispatch = new $controller($model,$controllerName,$queryString, getApplicationName()); + $dispatch = new $controller($model,$application,$queryString); //pass the action to the controller object $dispatch->action = $action; @@ -324,7 +196,7 @@ function callHook() $templateFlag= true; - if (method_exists($dispatch, $action)) + if (method_exists($controller, $action)) { //pass the action to the theme object $dispatch->theme->action = $action; @@ -363,10 +235,7 @@ function rewrite($url) $oldKey = $key; $key = str_replace('\/','/',$key); $key = str_replace('/','\/',$key); - - $regExpr = Params::$exactUrlMatchRewrite ? '/^'.$key.'$/' : '/^'.$key.'/'; - - if (preg_match($regExpr,$url)) + if (preg_match('/^'.$key.'/',$url)) { $nurl = preg_replace('/^'.$key.'/',$address,$url); return array($nurl,$oldKey); @@ -403,18 +272,10 @@ function __autoload($className) { require_once(ROOT . DS . 'Library' . DS . $className . '.php'); } - else if (getApplicationName() and file_exists(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Controllers' . DS . $backupName . '.php')) - { - require_once(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Controllers' . DS . $backupName . '.php'); - } else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Controllers' . DS . $backupName . '.php')) { require_once(ROOT . DS . APPLICATION_PATH . DS . 'Controllers' . DS . $backupName . '.php'); } - else if (getApplicationName() and file_exists(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Models' . DS . $backupName . '.php')) - { - require_once(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Models' . DS . $backupName . '.php'); - } else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Models' . DS . $backupName . '.php')) { require_once(ROOT . DS . APPLICATION_PATH . DS . 'Models' . DS . $backupName . '.php'); @@ -423,10 +284,6 @@ function __autoload($className) { require_once(ROOT . DS . APPLICATION_PATH . DS . 'Modules' . DS . $backupName . '.php'); } - else if (getApplicationName() and file_exists(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Strings' . DS . $backupName . '.php')) - { - require_once(ROOT . DS . APPLICATION_PATH . DS . getApplicationPath() . 'Strings' . DS . $backupName . '.php'); - } else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Strings' . DS . $className . '.php')) { require_once(ROOT . DS . APPLICATION_PATH . DS . 'Strings' . DS . $className . '.php'); @@ -436,9 +293,6 @@ function __autoload($className) try { - $_POST = fixArray($_POST); - $_GET = fixArray($_GET); - //check the length of the $_POST values checkPostLength(); diff --git a/h-source/Library/Controller.php b/h-source/Library/Controller.php index bc1c229..b0eef53 100755 --- a/h-source/Library/Controller.php +++ b/h-source/Library/Controller.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -31,8 +31,6 @@ class Controller { protected $_queryString = array(); //the array of args coming from the url - public $application = null; - public $applicationUrl = null; //the url of the application public $controller; public $action; public $currPage; //the URL of the current page @@ -59,21 +57,17 @@ class Controller { protected $scaffold = null; //the reference to the scaffold object - function __construct($model, $controller, $queryString = array(), $application = null) - { - $this->application = $application; + function __construct($model, $controller, $queryString = array()) { $this->controller = $controller; $this->modelName = $model; $this->_queryString = $queryString; - $this->theme = new Theme($application, $controller); + $this->theme = new Theme($controller); $this->baseUrl = $this->theme->baseUrl; $this->baseUrlSrc = $this->theme->baseUrlSrc; - + $this->headerObj = new HeaderObj(DOMAIN_NAME); $this->request = new Request(); - - $this->applicationUrl = isset($application) ? $application . "/" : null; } //redirect to $path after the time $time @@ -142,8 +136,8 @@ class Controller { { if (class_exists($controller)) { $model = str_replace('Controller',null,$controller).'Model'; - $application = $this->controller; - $this->c[$controller] = new $controller($model,$application,$this->_queryString); + $application = strtolower(str_replace('Controller',null,$controller)); + $this->c[$controller] = new $controller($model,$application,array()); $this->c[$controller]->theme = $this->theme; } } @@ -240,7 +234,7 @@ class Controller { } $this->viewArgs[$this->argKeys[$i]] = $this->_queryString[$i]; } - $this->viewStatus = Url::createUrl($this->viewArgs); + $this->viewStatus = Url::createUrl(array_values($this->viewArgs)); $this->updateHelpers(); //update the theme @@ -288,7 +282,7 @@ class Controller { //create the viewStatus property final public function buildStatus() { - $this->viewStatus = Url::createUrl($this->viewArgs); + $this->viewStatus = Url::createUrl(array_values($this->viewArgs)); //update the theme $this->theme->viewStatus = $this->viewStatus; $this->theme->viewArgs = $this->viewArgs; @@ -301,9 +295,9 @@ class Controller { if (!in_array($type,$typeArray)) { throw new Exception("the type '$type' is not allowed in ".__METHOD__); } - $this->scaffold = new Scaffold($type,$this->application,$this->controller,$this->m[$this->modelName],$this->viewArgs,$params); + $this->scaffold = new Scaffold($type,$this->controller,$this->m[$this->modelName],$this->viewArgs,$params); - $this->helper('Menu',$this->applicationUrl.$this->controller,$this->scaffold->params['panelController']); + $this->helper('Menu',$this->controller,$this->scaffold->params['panelController']); $this->scaffold->mainMenu = $this->h['Menu']; $this->m[$this->modelName]->popupBuild(); @@ -311,8 +305,7 @@ class Controller { if ($type === 'main') { - $here = $this->applicationUrl.$this->controller.'/'.$this->scaffold->params['mainAction']; - + $here = $this->controller.'/'.$this->scaffold->params['mainAction']; $this->helper('Pages',$here,$this->scaffold->params['pageVariable']); $this->helper('List',$this->m[$this->modelName]->identifierName,$here,$this->scaffold->params['pageVariable']); diff --git a/h-source/Library/Db/Mysql.php b/h-source/Library/Db/Mysql.php index e0dcfe0..4561a1b 100755 --- a/h-source/Library/Db/Mysql.php +++ b/h-source/Library/Db/Mysql.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -24,34 +24,16 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to manage the database //singleton! -class Db_Mysql -{ - - private $autocommit = true; - private $transactionBatchSize = 100; - - public $transactionBatch = array(); +class Db_Mysql { public $query = null; //the last query executed - public $queries = array(); //array containing all the queries executed - public $charsetError = true; //true: non eccor occurred during the modification of the connection charset, false: one error occurred public $charset = null; //the charset of the client connection private static $instance = null; //instance of this class private $dblink; - - private $charTypes = array('varchar','char'); - private $textTypes = array('tinytext','text','mediumtext','longtext'); - private $integerTypes = array('tinyint','smallint','int','mediumint','bigint'); - private $floatTypes = array('real','float','double'); - private $dateTypes = array('date'); - private $enumTypes = array('enum'); - private $decimalTypes = array('decimal'); - private $uniqueIndexStrings = array('UNI'); - - private $fieldsType = array(); + private $fieldsType = array('tinyint','smallint','int','mediumint','bigint','float','double'); /** *connect to the database @@ -69,8 +51,7 @@ class Db_Mysql private function __construct($host,$user,$pwd,$db_name) { - $this->fieldsType = array_merge($this->integerTypes, $this->floatTypes); - + $this->dblink = mysql_connect($host,$user,$pwd); if ($this->dblink === FALSE) { @@ -97,46 +78,7 @@ class Db_Mysql return self::$instance; } - public function getUniqueIndexStrings() - { - return $this->uniqueIndexStrings; - } - - public function getTextTypes() - { - return $this->textTypes; - } - - public function getDecimalTypes() - { - return $this->decimalTypes; - } - - public function getEnumTypes() - { - return $this->enumTypes; - } - - public function getCharTypes() - { - return $this->charTypes; - } - - public function getIntegerTypes() - { - return $this->integerTypes; - } - - public function getFloatTypes() - { - return $this->floatTypes; - } - - public function getDateTypes() - { - return $this->dateTypes; - } - + //close the connection public function disconnect() { @@ -221,29 +163,16 @@ class Db_Mysql public function get_num_rows($table,$where=null,$group_by=null,$on=array(),$using=array(),$join=array()) { - $select = isset($group_by) ? "*" : 'count(*) as number'; - - $query = $this->createSelectQuery($table,$select,$where,$group_by,null,null,$on,$using,$join); + $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using,$join); $this->query=$query; - $this->queries[] = $query; $ris = mysql_query($query); if ($ris) { - - if (isset($group_by)) - { - $num_rows = mysql_num_rows($ris); - } - else - { - $row = mysql_fetch_array($ris); - $num_rows = $row['number']; - } - - return (int)$num_rows; + $num_rows = mysql_num_rows($ris); + return $num_rows; } else { - return 0; + return false; } } @@ -253,8 +182,6 @@ class Db_Mysql $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $result = mysql_query($query); if ($result) { @@ -296,8 +223,6 @@ class Db_Mysql $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $result = mysql_query($query); return $this->getData($result); } @@ -334,73 +259,31 @@ class Db_Mysql } else { - return array(); + return false; } } - - private function getFieldsFeature($feature, $table, $fields, $full = false, $associative = false) + //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) + public function getTypes($table, $fields) { $query = "DESCRIBE $table;"; $result = mysql_query($query); $temp = array(); while ($row = mysql_fetch_assoc($result)) { - if ($full) - { - $temp[$row['Field']] = $row[$feature]; - } - else - { - $e = explode('(',$row[$feature]); - $temp[$row['Field']] = strcmp($feature,"Type") === 0 ? strtolower(reset($e)) : reset($e); - } + $temp[$row['Field']] = reset(explode('(',$row['Type'])); } - $this->queries[] = $query; - - //return all fields types - if ($fields === "*") - { - $fields = implode(",",array_keys($temp)); - } - $types = array(); $fields = explode(',',$fields); for ($i = 0; $i < count($fields); $i++) { if (!array_key_exists($fields[$i],$temp)) return false; - - if ($associative) - { - $types[$fields[$i]] = $temp[$fields[$i]]; - } - else - { - $types[] = $temp[$fields[$i]]; - } + $types[] = $temp[$fields[$i]]; } return $types; } - //return an array containing all the keys of the fields (indicated in $fields) of a table (indicated in $table) - public function getKeys($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Key', $table, $fields, $full, $associative); - } - - //return an array containing all the default values of the fields (indicated in $fields) of a table (indicated in $table) - public function getDefaultValues($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Default', $table, $fields, $full, $associative); - } - - //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) - public function getTypes($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Type', $table, $fields, $full, $associative); - } - public function insert($table,$fields,$values) { #$table is a string @@ -428,8 +311,6 @@ class Db_Mysql $values = implode(',',$values); $query="INSERT INTO $table ($fields) VALUES ($values);"; $this->query = $query; - $this->queries[] = $query; - $ris = mysql_query($query); #check the result @@ -438,34 +319,12 @@ class Db_Mysql } else { return false; } - + } else { return false; } } - //set the autocommit attribute - public function setAutocommit($value) - { - } - - //set the transactionBatchSize attribute - public function setTransactionBatchSize($size) - { - } - - //commit a batch of queries - //$batch: array of queries - public function commitBatch($batch) - { - } - - //commit the transaction - public function commitTransaction() - { - return false; - } - // Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). public function lastId() { @@ -507,8 +366,6 @@ class Db_Mysql $str=implode(',',$str); $query="UPDATE $table SET $str $where;"; $this->query=$query; - $this->queries[] = $query; - $ris = mysql_query($query); #check the result @@ -517,7 +374,6 @@ class Db_Mysql } else { return false; } - } else { return false; } @@ -533,8 +389,6 @@ class Db_Mysql // } $query="DELETE FROM $table $where;"; $this->query=$query; - $this->queries[] = $query; - $ris = mysql_query($query); #check the result @@ -568,8 +422,6 @@ class Db_Mysql public function query($query) { $this->query = $query; - $this->queries[] = $query; - $result = mysql_query($query); if ($result === false) { diff --git a/h-source/Library/Db/Mysqli.php b/h-source/Library/Db/Mysqli.php index bd3ce1c..df57a54 100644 --- a/h-source/Library/Db/Mysqli.php +++ b/h-source/Library/Db/Mysqli.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -27,31 +27,14 @@ if (!defined('EG')) die('Direct access not allowed!'); class Db_Mysqli { - private $autocommit = true; - private $transactionBatchSize = 100; - - public $transactionBatch = array(); - public $query = null; //the last query executed - public $queries = array(); //array containing all the queries executed - public $charsetError = true; //true: non eccor occurred during the modification of the connection charset, false: one error occurred public $charset = null; //the charset of the client connection private static $instance = null; //instance of this class private $db; - - private $charTypes = array('varchar','char'); - private $textTypes = array('tinytext','text','mediumtext','longtext'); - private $integerTypes = array('tinyint','smallint','int','mediumint','bigint'); - private $floatTypes = array('real','float','double'); - private $dateTypes = array('date'); - private $enumTypes = array('enum'); - private $decimalTypes = array('decimal'); - private $uniqueIndexStrings = array('UNI'); - - private $fieldsType = array(); + private $fieldsType = array('tinyint','smallint','int','mediumint','bigint','float','double'); //PHP-Mysql charset translation table private $charsetTranslationTable = array( @@ -70,8 +53,7 @@ class Db_Mysqli private function __construct($host,$user,$pwd,$db_name) { - $this->fieldsType = array_merge($this->integerTypes, $this->floatTypes); - + $this->db = new mysqli($host,$user,$pwd,$db_name); if (mysqli_connect_error()) @@ -103,46 +85,7 @@ class Db_Mysqli return self::$instance; } - public function getUniqueIndexStrings() - { - return $this->uniqueIndexStrings; - } - - public function getTextTypes() - { - return $this->textTypes; - } - - public function getDecimalTypes() - { - return $this->decimalTypes; - } - - public function getEnumTypes() - { - return $this->enumTypes; - } - - public function getCharTypes() - { - return $this->charTypes; - } - - public function getIntegerTypes() - { - return $this->integerTypes; - } - - public function getFloatTypes() - { - return $this->floatTypes; - } - - public function getDateTypes() - { - return $this->dateTypes; - } - + //close the connection public function disconnect() { @@ -227,30 +170,16 @@ class Db_Mysqli public function get_num_rows($table,$where=null,$group_by=null,$on=array(),$using=array(),$join=array()) { - $select = isset($group_by) ? "*" : 'count(*) as number'; - - $query = $this->createSelectQuery($table,$select,$where,$group_by,null,null,$on,$using,$join); + $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $ris = $this->db->query($query); if ($ris) { - - if (isset($group_by)) - { - $num_rows = $ris->num_rows; - } - else - { - $row = $ris->fetch_array(); - $num_rows = $row['number']; - } - + $num_rows = $ris->num_rows; $ris->close(); - return (int)$num_rows; + return $num_rows; } else { - return 0; + return false; } } @@ -259,8 +188,6 @@ class Db_Mysqli $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $result = $this->db->query($query); if ($result) { @@ -303,8 +230,6 @@ class Db_Mysqli $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using,$join); $this->query = $query; - $this->queries[] = $query; - $result = $this->db->query($query); return $this->getData($result); } @@ -337,85 +262,44 @@ class Db_Mysqli $result->close(); return $data; } else { - return array(); + return false; } } - private function getFieldsFeature($feature, $table, $fields, $full = false, $associative = false ) + //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) + public function getTypes($table, $fields) { $query = "DESCRIBE $table;"; $result = $this->db->query($query); $temp = array(); while ($row = $result->fetch_assoc()) { - if ($full) - { - $temp[$row['Field']] = $row[$feature]; - } - else - { - $e = explode('(',$row[$feature]); - $temp[$row['Field']] = strcmp($feature,"Type") === 0 ? strtolower(reset($e)) : reset($e); - } + $temp[$row['Field']] = reset(explode('(',$row['Type'])); } $result->close(); - $this->queries[] = $query; - - //return all fields types - if ($fields === "*") - { - $fields = implode(",",array_keys($temp)); - } - $types = array(); $fields = explode(',',$fields); for ($i = 0; $i < count($fields); $i++) { if (!array_key_exists($fields[$i],$temp)) return false; - - if ($associative) - { - $types[$fields[$i]] = $temp[$fields[$i]]; - } - else - { - $types[] = $temp[$fields[$i]]; - } + $types[] = $temp[$fields[$i]]; } return $types; } - //return an array containing all the keys of the fields (indicated in $fields) of a table (indicated in $table) - public function getKeys($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Key', $table, $fields, $full, $associative); - } - - //return an array containing all the default values of the fields (indicated in $fields) of a table (indicated in $table) - public function getDefaultValues($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Default', $table, $fields, $full, $associative); - } - - //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) - public function getTypes($table, $fields, $full = false, $associative = false) - { - return $this->getFieldsFeature('Type', $table, $fields, $full, $associative); - } - public function insert($table,$fields,$values) { + #$table is a string #$fields has to be a string with comma as separator: name1,name2,... #$values has to be an array - $values = array_values($values); if (strcmp($fields,'') !== 0) { //get the type of the fields $types = $this->getTypes($table,$fields); if (!$types) return false; - + for($i = 0; $i < count($values); $i++) { if (!in_array($types[$i],$this->fieldsType)) @@ -431,103 +315,21 @@ class Db_Mysqli $values = implode(',',$values); $query="INSERT INTO $table ($fields) VALUES ($values);"; $this->query=$query; - $this->queries[] = $query; - if ($this->autocommit) - { - $ris = $this->db->query($query); + $ris = $this->db->query($query); - #check the result - if ($ris) { - return true; - } else { - return false; - } - } - else - { - $this->transactionBatch[] = $query; + #check the result + if ($ris) { return true; + } else { + return false; } + } else { return false; } } - //set the autocommit attribute - public function setAutocommit($value) - { - if ($value === true or $value === false) - { - $this->autocommit = $value; - $this->db->autocommit($value); - } - else - { - $this->autocommit = true; - $this->db->autocommit(true); - } - } - - //set the transactionBatchSize attribute - public function setTransactionBatchSize($size) - { - $this->transactionBatchSize = abs($size); - } - - //commit a batch of queries - //$batch: array of queries - public function commitBatch($batch) - { - foreach ($batch as $sql) - { - $this->db->query($sql); - } - - if (!$this->autocommit and $this->db->commit()) - { - return true; - } - else - { - return false; - } - } - - //commit the transaction - public function commitTransaction() - { - $returnArray = array(); - - if (!$this->autocommit) - { - if (count($this->transactionBatch) > 0) - { - if ($this->transactionBatchSize === 0) - { - $returnArray[] = $this->commitBatch($this->transactionBatch); - } - else - { - $batchArray = array_chunk($this->transactionBatch, $this->transactionBatchSize); - - foreach ($batchArray as $batch) - { - $returnArray[] = $this->commitBatch($batch); - } - } - } - } - - if (count(array_filter($returnArray)) === count($returnArray)) - { - $this->transactionBatch = array(); - return true; - } - - return false; - } - // Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). public function lastId() { @@ -569,23 +371,13 @@ class Db_Mysqli $str=implode(',',$str); $query="UPDATE $table SET $str $where;"; $this->query=$query; - $this->queries[] = $query; - - if ($this->autocommit) - { - $ris = $this->db->query($query); + $ris = $this->db->query($query); - #check the result - if ($ris) { - return true; - } else { - return false; - } - } - else - { - $this->transactionBatch[] = $query; + #check the result + if ($ris) { return true; + } else { + return false; } } else { return false; @@ -602,8 +394,6 @@ class Db_Mysqli // } $query="DELETE FROM $table $where;"; $this->query=$query; - $this->queries[] = $query; - $ris = $this->db->query($query); #check the result @@ -638,8 +428,6 @@ class Db_Mysqli public function query($query) { $this->query = $query; - $this->queries[] = $query; - $result = $this->db->query($query); if ($result === true) { diff --git a/h-source/Library/Email.php b/h-source/Library/Email.php index 369af20..9d2ff19 100644 --- a/h-source/Library/Email.php +++ b/h-source/Library/Email.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/ErrorReporting.php b/h-source/Library/ErrorReporting.php index ab66091..2cb8aed 100644 --- a/h-source/Library/ErrorReporting.php +++ b/h-source/Library/ErrorReporting.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Factory/Db.php b/h-source/Library/Factory/Db.php index 17afa1a..32a82c1 100755 --- a/h-source/Library/Factory/Db.php +++ b/h-source/Library/Factory/Db.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Factory/Strings.php b/h-source/Library/Factory/Strings.php index 8917590..3e766bd 100644 --- a/h-source/Library/Factory/Strings.php +++ b/h-source/Library/Factory/Strings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Files/Log.php b/h-source/Library/Files/Log.php index a060ba3..7eda7b7 100644 --- a/h-source/Library/Files/Log.php +++ b/h-source/Library/Files/Log.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Files/Upload.php b/h-source/Library/Files/Upload.php index 19b5fd1..7dbc7d1 100755 --- a/h-source/Library/Files/Upload.php +++ b/h-source/Library/Files/Upload.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -230,8 +230,7 @@ class Files_Upload { if (strstr($file,'.')) { - $extArray = explode('.', $file); - return strtolower(end($extArray)); + return strtolower(end(explode('.', $file))); } return ''; } @@ -269,23 +268,6 @@ class Files_Upload } - //get a not existing folder name - public function getUniqueFolderName($folder,$int = 0) - { - $token = $int === 0 ? null : $this->params['fileUploadBeforeTokenChar'].$int; - - $newName = $folder.$token; - if (!is_dir($this->base.$this->directory.$newName)) - { - return $newName; - } - else - { - return $this->getUniqueFolderName($folder,$int+1); - } - - } - protected function parentDir() { #individuo la cartella madre $folders = explode(self::DS,$this->directory); @@ -351,7 +333,7 @@ class Files_Upload } //check if the $name folder is empty or not - public function isEmpty($name) + protected function isEmpty($name) { $items = scandir($name); foreach( $items as $this_file ) { diff --git a/h-source/Library/Form/Checkbox.php b/h-source/Library/Form/Checkbox.php index 91191a9..497c097 100755 --- a/h-source/Library/Form/Checkbox.php +++ b/h-source/Library/Form/Checkbox.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Checkbox extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::checkbox($this->entryName, $value, $this->options, $this->className,$this->idName,$this->attributes); + $returnString .= Html_Form::checkbox($this->entryName, $value, $this->options, $this->className,$this->idName); $returnString .= $wrap[3]; $returnString .="\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Entry.php b/h-source/Library/Form/Entry.php index fa3b84f..6f45557 100755 --- a/h-source/Library/Form/Entry.php +++ b/h-source/Library/Form/Entry.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -33,7 +33,6 @@ abstract class Form_Entry { public $labelClass = null; //the class of the tag of the label public $options = array(); //options (if the entry is a \n\n"; } - $htmlForm .= ""; $htmlForm .= "\n"; - - if (isset(self::$defaultEntryAttributes["formWrap"]) and is_array(self::$defaultEntryAttributes["formWrap"]) and count(self::$defaultEntryAttributes["formWrap"]) === 2) - { - return self::$defaultEntryAttributes["formWrap"][0] . $htmlForm . self::$defaultEntryAttributes["formWrap"][1]; - } return $htmlForm; } diff --git a/h-source/Library/Form/Hidden.php b/h-source/Library/Form/Hidden.php index c2185b9..c589662 100755 --- a/h-source/Library/Form/Hidden.php +++ b/h-source/Library/Form/Hidden.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -33,7 +33,7 @@ class Form_Hidden extends Form_Entry public function render($value = null) { - $returnString = Html_Form::hidden($this->entryName, $value, $this->className, $this->idName, $this->attributes); + $returnString = Html_Form::hidden($this->entryName, $value); return $returnString; } diff --git a/h-source/Library/Form/Html.php b/h-source/Library/Form/Html.php index a7181cc..e5c9989 100644 --- a/h-source/Library/Form/Html.php +++ b/h-source/Library/Form/Html.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Form/InputText.php b/h-source/Library/Form/InputText.php index 086c0a1..344264e 100755 --- a/h-source/Library/Form/InputText.php +++ b/h-source/Library/Form/InputText.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_InputText extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::input($this->entryName, $value, $this->className, $this->idName, $this->attributes); + $returnString .= Html_Form::input($this->entryName, $value, $this->className, $this->idName); $returnString .= $wrap[3]; $returnString .="\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Password.php b/h-source/Library/Form/Password.php index 41fbc8e..9bfc68b 100644 --- a/h-source/Library/Form/Password.php +++ b/h-source/Library/Form/Password.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Password extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::password($this->entryName, null, $this->className, $this->idName, $this->attributes); + $returnString .= Html_Form::password($this->entryName, null, $this->className); $returnString .= $wrap[3]; $returnString .="\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Radio.php b/h-source/Library/Form/Radio.php index 10154be..4f596ed 100755 --- a/h-source/Library/Form/Radio.php +++ b/h-source/Library/Form/Radio.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Radio extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::radio($this->entryName,$value,$this->options,$this->className, 'after', $this->idName, $this->attributes); + $returnString .= Html_Form::radio($this->entryName,$value,$this->options,$this->className, 'after', $this->idName); $returnString .= $wrap[3]; $returnString .="\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Select.php b/h-source/Library/Form/Select.php index 8b2a634..53d7632 100755 --- a/h-source/Library/Form/Select.php +++ b/h-source/Library/Form/Select.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Select extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::select($this->entryName,$value,$this->options,$this->className, $this->idName, $this->reverse, $this->attributes); + $returnString .= Html_Form::select($this->entryName,$value,$this->options,$this->className, $this->idName, $this->reverse); $returnString .= $wrap[3]; $returnString .="\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Form/Textarea.php b/h-source/Library/Form/Textarea.php index f294b0a..aaaf19e 100755 --- a/h-source/Library/Form/Textarea.php +++ b/h-source/Library/Form/Textarea.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -39,7 +39,7 @@ class Form_Textarea extends Form_Entry $returnString .= $wrap[1]; $returnString .= $this->getLabelTag(); $returnString .= $wrap[2]; - $returnString .= Html_Form::textarea($this->entryName, $value, $this->className, $this->idName, $this->attributes); + $returnString .= Html_Form::textarea($this->entryName, $value, $this->className, $this->idName); $returnString .= $wrap[3]; $returnString .="\n"; $returnString .= $wrap[4]; diff --git a/h-source/Library/Functions.php b/h-source/Library/Functions.php index ef86812..1477680 100755 --- a/h-source/Library/Functions.php +++ b/h-source/Library/Functions.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -108,24 +108,12 @@ SANITIZE DEEP function stripslashesDeep($value) { if(get_magic_quotes_gpc()) {#if stripslashes - return array_map_recursive('stripslashes', $value); + return array_map('stripslashes', $value); } return $value; } -//from http://www.php.net/array_map#112857 -function array_map_recursive($callback, $array) { - foreach ($array as $key => $value) { - if (is_array($array[$key])) { - $array[$key] = array_map_recursive($callback, $array[$key]); - } - else { - $array[$key] = call_user_func($callback, $array[$key]); - } - } - return $array; -} - + function sanitizeHtmlDeep($value) { return array_map('sanitizeHtml', $value); } @@ -175,9 +163,7 @@ function sha1Deep($value) return array_map('sha1', $value); } -function strip_tagsDeep($value) { - return array_map('strip_tags', $value); -} + @@ -242,75 +228,6 @@ function wrap($string,$tag_class) {#wrap the string with the tag and its class return $str_front.$string.$str_rear; } -//check that $date is a ISO date (YYYY-MM-DD) -function checkIsoDate($date) -{ - if (preg_match('/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/',$date)) - { - $dateArray = explode('-',$date); - if ((int)$dateArray[1] <= 12 and (int)$dateArray[1] >= 1 ) - { - if ((int)$dateArray[2] >= 1 and (int)$dateArray[2] <= 31) - { - return checkdate((int)$dateArray[1],(int)$dateArray[2],(int)$dateArray[0]); - } - } - } - return false; -} - -//check if $string is an integer string -function checkInteger($string) -{ - if (preg_match('/^\-?[0-9]{1,}$/',$string)) - { - return true; - } - return false; -} - -//check if $string is decimal with the format indicated in $format -//$format: M,D M is the maximum number of digits, D is the number of digits to the right of the decimal point -function checkDecimal($string, $format) -{ - $t = explode(",",$format); - $M = (int)$t[0]; - $D = (int)$t[1]; - $I = $M - $D; - - if (preg_match("/^[0-9]{1,$I}(\.[0-9]{1,$D})?$/",$string)) - { - return true; - } - return false; -} - -//get label name from field name -function getFieldLabel($fieldName) -{ - if (class_exists("Lang_".Params::$language."_Formats_Fields")) - { - return call_user_func(array("Lang_".Params::$language."_Formats_Fields", "getLabel"), $fieldName); - } - - return call_user_func(array("Lang_En_Formats_Fields", "getLabel"), $fieldName); - -// if (strstr($fieldName,",")) -// { -// $temp = explode(",",$fieldName); -// for ($i=0; $i< count($temp); $i++) -// { -// $temp[$i] = getFieldLabel($temp[$i]); -// } -// return implode (" and ",$temp); -// } -// else -// { -// $fieldName = str_replace("_"," ", $fieldName); -// return ucfirst($fieldName); -// } -} - //generate a random password //$start: start number of mt_rand //$end: end number of mt_rand @@ -349,7 +266,7 @@ function getIp() $ip = sanitizeIp($_SERVER["HTTP_X_FORWARDED_FOR"]); } else if (!empty($_SERVER["HTTP_CLIENT_IP"])) { $ip = sanitizeIp($_SERVER["HTTP_CLIENT_IP"]); - } else if (!empty($_SERVER["REMOTE_ADDR"])) { + } else { $ip = sanitizeIp($_SERVER["REMOTE_ADDR"]); } } else { @@ -357,7 +274,7 @@ function getIp() $ip = sanitizeIp(getenv( 'HTTP_X_FORWARDED_FOR' )); } else if ( getenv( 'HTTP_CLIENT_IP' ) !== false ) { $ip = sanitizeIp(getenv( 'HTTP_CLIENT_IP' )); - } else if ( getenv( 'REMOTE_ADDR' ) !== false ) { + } else { $ip = sanitizeIp(getenv( 'REMOTE_ADDR' )); } } @@ -377,76 +294,6 @@ function getUserAgent() { } } -//encode a string to drop ugly characters -function encode($url) -{ - $url = utf8_decode(html_entity_decode($url,ENT_QUOTES,'UTF-8')); - - $temp = null; - - for ($i=0;$i"; - if (strcmp(substr($url,$i,1),' ') === 0) - { - $temp .= '_'; - } - else if (strcmp(substr($url,$i,1),"'") === 0) - { - $temp .= ''; - } - else - { - if (preg_match('/^[a-zA-Z\_0-9]$/',substr($url,$i,1))) - { - $temp .= substr($url,$i,1); - } - else - { - $temp .= '_'; - } - } - } - - $temp = urlencode($temp); - return $temp; -} - -function callFunction($function, $string, $caller = "CallFunction") -{ - if (strstr($function,'::')) //static method - { - $temp = explode('::',$function); - - if (!method_exists($temp[0],$temp[1])) - { - throw new Exception('Error in '.$caller.': method '.$temp[1].' of class '.$temp[0].' does not exists.'); - } - - return call_user_func(array($temp[0], $temp[1]),$string); - } - else if (strstr($function,'.')) //method - { - $temp = explode('.',$function); - - $obj = new $temp[0]; //new instance of the object - - if (!method_exists($obj,$temp[1])) - { - throw new Exception('Error in '.$caller.': method '.$temp[1].' of class '.$temp[0].' does not exists.'); - } - - return call_user_func(array($obj, $temp[1]),$string); - } - else //function - { - if (!function_exists($function)) { - throw new Exception('Error in '.$caller.': function '.$function.' does not exists.'); - } - //apply the function - return call_user_func($function,$string); - } -} function xml_encode($string) { @@ -457,23 +304,4 @@ function xml_encode($string) } return strtr($string, $trans); -} - -//Convert Hex Color to RGB -//http://bavotasan.com/2011/convert-hex-color-to-rgb-using-php/ -function hex2rgb($hex) { - $hex = str_replace("#", "", $hex); - - if(strlen($hex) == 3) { - $r = hexdec(substr($hex,0,1).substr($hex,0,1)); - $g = hexdec(substr($hex,1,1).substr($hex,1,1)); - $b = hexdec(substr($hex,2,1).substr($hex,2,1)); - } else { - $r = hexdec(substr($hex,0,2)); - $g = hexdec(substr($hex,2,2)); - $b = hexdec(substr($hex,4,2)); - } - $rgb = array($r, $g, $b); - //return implode(",", $rgb); // returns the rgb values separated by commas - return $rgb; // returns an array with the rgb values -} +} \ No newline at end of file diff --git a/h-source/Library/HeaderObj.php b/h-source/Library/HeaderObj.php index 2d52e1d..994eb16 100644 --- a/h-source/Library/HeaderObj.php +++ b/h-source/Library/HeaderObj.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Helper/Array.php b/h-source/Library/Helper/Array.php index dbdda4f..329463f 100755 --- a/h-source/Library/Helper/Array.php +++ b/h-source/Library/Helper/Array.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Helper/Html.php b/h-source/Library/Helper/Html.php index 9e25bb4..81a9bdd 100755 --- a/h-source/Library/Helper/Html.php +++ b/h-source/Library/Helper/Html.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Helper/List.php b/h-source/Library/Helper/List.php index 81b5345..ba59643 100755 --- a/h-source/Library/Helper/List.php +++ b/h-source/Library/Helper/List.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,9 +25,6 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to create the HTML of a list of records class Helper_List extends Helper_Html { - //table attributes - static public $tableAttributes = array('class'=>'listTable','cellspacing'=>'0'); - private $__rowArray = array(); //the current associative array representing the database record protected $_itemsList = array(); //2-dimensional associative array containing the list items @@ -37,7 +34,7 @@ class Helper_List extends Helper_Html { protected $_recordNumber = null; //number of records from the table - protected $_allowedItems = array('simpleLink','simpleText','delForm','editForm','associateForm','moveupForm','movedownForm','Form','ledit','link','text','checkbox','input'); //type of items allowed + protected $_allowedItems = array('simpleLink','simpleText','delForm','editForm','associateForm','moveupForm','movedownForm','Form','ledit','link','text'); //type of items allowed //it can be: both, top, bottom, none protected $_boundaries = 'none'; @@ -45,12 +42,6 @@ class Helper_List extends Helper_Html { //array of filters protected $_filters = array(); - //array of bulk actions - protected $_bulkActions = array(); - - //set to false if you don't want that the filters are created inside the table - public $showFilters = true; - //set if the submit buttons have to be images or not (it can be yse or not) public $submitImageType = 'yes'; @@ -63,6 +54,9 @@ class Helper_List extends Helper_Html { //properties of columns public $colProperties = array(); + //table attributes + public $tableAttributes = array('class'=>'listTable','cellspacing'=>'0'); + //$position: array. First element: page number, second element: number of pages public $position = array(); @@ -74,15 +68,12 @@ class Helper_List extends Helper_Html { public $pageArg = null; //the key of the viewArgs array representing the page number. $this->viewArgs[$this->pageArg] is set to 1 if $this->pageArg !== null - //if the filter forms have to be aggregated in a unique form or if they have to be left separated - public $aggregateFilters = false; - public function __construct() { //get the generic language class $this->strings = Factory_Strings::generic(Params::$language); - $baseUrl = Url::getRoot().'Public/Img/Icons/elementary_2_5/'; + $baseUrl = 'http://'.DOMAIN_NAME.'/Public/Img/Icons/elementary_2_5/'; //set the files of the images $this->submitImages = array( @@ -156,39 +147,17 @@ class Helper_List extends Helper_Html { //set the filters //$filters: array whose elements are the viewArgs to be used for the filters forms - //or null public function setFilters($filters) { $this->_filters = $filters; } - - //set $this->aggregateFilters equal to true - public function aggregateFilters() - { - $this->aggregateFilters = true; - } - - //set the bulk actions - //$bulkActions: associative array. - //key: class of the inputs whose elements have to be selected and serialized by javascript in the following way: data-primary-key:value_attribute|data-primary-key:value_attribute|data-primary-key:value_attribute|... - //value: array with two elements whose first element is the bulk action to be sent as a key of $_POST, second element is the human readable name of the action, third element can be the string "confirm" (if the user has to confirm the action) or undefined - //example: - // $bulkActions = array( - // "input_category_id_order" => array("sortAction","Sort elements"), - // "checkbox_category_id" => array("deleteAction","Delete elements","confirm"), - // ); - public function setBulkActions($bulkActions) - { - $this->_bulkActions = $bulkActions; - } //check that the ViewArgs array is complete public function checkViewArgs() { foreach ($this->_filters as $field) { - $key = !is_array($field) ? $field : $field[0]; - if (!array_key_exists($key,$this->viewArgs) and strcmp($key,null) !== 0) return false; + if (!array_key_exists($field,$this->viewArgs) and strcmp($field,null) !== 0) return false; } return true; } @@ -203,48 +172,47 @@ class Helper_List extends Helper_Html { public function replaceFields($string,$rowArray) { $this->__rowArray = $rowArray; //used by the replaceField method - $string = preg_replace_callback('/(\;)(.*?)(\;)/', array($this, 'replaceField') ,$string); + $string = preg_replace_callback('/(\;)(.*?)(\;)/', 'Helper_List::replaceField' ,$string); return $string; } - //get : or . as char used to separate table and field - public function getChar($string) - { - return strstr($string,':') ? ':' : '.'; - } - //replace a single string wrapped by ; with its correspondent value taken by the $recordArray associative array (a row of the select query) public function replaceField($match) { $string = $match[2]; - //check if a function has been indicated - if (strstr($string,'|')) - { - //get the function - $firstArray = explode('|',$string); - if (strstr($firstArray[1],':') or strstr($firstArray[1],'.')) + if (strstr($string,':') or strstr($string,'.')) { + if (strstr($string,':')) + { + $char = ':'; + } + else { + $char = '.'; + } + //check if a function has been indicated + if (strstr($string,'|')) + { + //get the function + $firstArray = explode('|',$string); $func = $firstArray[0]; //replace the fields - $char = $this->getChar($firstArray[1]); $temp = explode($char,$firstArray[1]); $string = $this->__rowArray[$temp[0]][$temp[1]]; - $string = callFunction($func,$string,__METHOD__); + if (!function_exists($func)) { + throw new Exception('Error in '.__METHOD__.': function '.$func.' does not exists..'); + } + //apply the function + $string = call_user_func($func,$string); } - } - else - { - if (strstr($string,':') or strstr($string,'.')) + else { - $char = $this->getChar($string); $temp = explode($char,$string); $string = $this->__rowArray[$temp[0]][$temp[1]]; } } - return $string; } @@ -259,8 +227,8 @@ class Helper_List extends Helper_Html { } //wrap the column with the tag td - public function wrapColumn($string, $className = null, $tag = "td") { - return wrap($string,array($tag=>$className)); + public function wrapColumn($string, $className = null) { + return wrap($string,array('td'=>$className)); } //wrap the row with the tag tr @@ -269,7 +237,7 @@ class Helper_List extends Helper_Html { } public function wrapList($string) { - return wrap($string,array('table'=>self::$tableAttributes)); + return wrap($string,array('table'=>$this->tableAttributes)); } //method to create the HTML of the head of the table @@ -280,18 +248,13 @@ class Helper_List extends Helper_Html { foreach ($this->_head as $item) { $temp = $item['action']; - if (preg_match('/\[\[bulkselect:(.*?)\]\]/',$temp,$matches)) - { - $temp = Html_Form::checkbox("bulkselect_".$matches[1],"","BS","bulk_select_checkbox",null,"data-class='".$matches[1]."'"); - } - $prop = $item['type']; if (isset($this->colProperties[$count])) { $prop = $this->colProperties[$count]; } - $htmlHead .= $this->wrapColumn($temp, $prop, "th"); + $htmlHead .= $this->wrapColumn($temp,$prop); $count++; } @@ -299,27 +262,7 @@ class Helper_List extends Helper_Html { return $htmlHead; } - //return an array with all the filters in a 1-dimensional array - public function getFiltersList() - { - $filterList = array(); - - foreach ($this->_filters as $f) - { - if (is_array($f)) - { - $filterList[] = $f[0]; - } - else - { - $filterList[] = $f; - } - } - - return $filterList; - } - - //method to create the HTML of the filters input + //method to create the HTML of the head of the table public function createFilters() { $htmlFilters = null; @@ -339,91 +282,18 @@ class Helper_List extends Helper_Html { $html = ' '; if (isset($this->_filters[$count])) { - if (!is_array($this->_filters[$count])) - { - $html = $this->filterForm($this->_filters[$count]); - } - else - { - $html = call_user_func_array(array($this,"filterForm"),$this->_filters[$count]); -// $html = $this->filterForm($this->_filters[$count][0],$this->_filters[$count][1]); - } - } - - //wrap single cell if filters doesn't have to be aggregate - if (!$this->aggregateFilters) - { - $htmlFilters .= !$this->showFilters ? $html : $this->wrapColumn($html,$prop); + $html = $this->filterForm($this->_filters[$count]); } - else - { - $htmlFilters .= $html; - } - + $htmlFilters .= $this->wrapColumn($html,$prop); + $count++; } - - //wrap an aggregate cell if filters have to be aggregate - if ($this->aggregateFilters) - { - $colspan = count($this->_itemsList); - $formTop = "
\n"; - $imgSrc = Url::getRoot('Public/Img/Icons/elementary_2_5/find.png'); - - $formBottom = ""; - $emptyFilterStatusArray = array(); - $filtersList = $this->getFiltersList(); - foreach ($this->viewArgs as $k => $v) - { - if (!in_array($k,$filtersList)) - { - $emptyFilterStatusArray[] = "$k=$v"; - $formBottom .= ""; - } - } - $emptyFilterStatus = implode("&",$emptyFilterStatusArray); - - $formBottom .= ""; - - $formBottom .= "\n"; - - $formBottom .= "
"; - - $htmlFilters = !$this->showFilters ? $formTop.$htmlFilters.$formBottom : $this->wrapColumn($formTop.$htmlFilters.$formBottom,array("class"=>"aggregate_filters_td","colspan"=>$colspan)); - - } } } return $htmlFilters; } - //create the HTML of the select of the bulk actions - public function createBulkActionsSelect() - { - $htmlBulkSelect = null; - $colspan = count($this->_itemsList); - - if (count($this->_bulkActions) > 0) - { - $htmlBulkSelect .= "".$this->strings->gtext('Actions').": "; - $htmlBulkSelect = $this->wrapColumn($htmlBulkSelect,array("class"=>"bulk_actions_td","colspan"=>$colspan)); - } - - return $htmlBulkSelect; - } - //create the HTML of a single row (values taken from the associative array $rowArray) public function getRowList($rowArray) { $htmlList = null; @@ -482,32 +352,16 @@ class Helper_List extends Helper_Html { $this->_recordNumber = count($queryResult); $htmlList = null; //create the HTML of the head of the record list - $htmlList .= "\n".$this->wrapRow($this->createHead(),'listHead')."\n"; + $htmlList .= $this->wrapRow($this->createHead(),'listHead'); //create the HTML of the filters - $htmlList .= "\n"; - - $bulkActionsHtml = $this->createBulkActionsSelect(); - if (isset($bulkActionsHtml)) - { - $htmlList .= $this->wrapRow($bulkActionsHtml,'bulk_actions_tr'); - } - - if ($this->showFilters) - { - $filtersHtml = $this->createFilters(); - if (isset($filtersHtml)) - { - $htmlList .= $this->wrapRow($filtersHtml,'listFilters'); - } - } - + $htmlList .= $this->wrapRow($this->createFilters(),'listFilters'); for ($i = 0; $i < count($queryResult); $i++) { $this->ifInBoundaries($i); $temp = $this->getRowList($queryResult[$i]); $htmlList .= $this->wrapRow($temp,'listRow'); } - return $this->wrapList($htmlList."\n"); + return $this->wrapList($htmlList); } public function generalForm($itemArray, $submitName, $submitValue) @@ -604,20 +458,8 @@ class Helper_List extends Helper_Html { return $string; } - //create the HTML of a checkbox - public function checkbox($itemArray) - { - return Html_Form::checkbox($itemArray['action'],$itemArray['field'],$itemArray['name'],"checkbox_".encode($itemArray['action']),null,"data-primary-key='".$itemArray['value']."'"); - } - - //create the HTML of an input text - public function input($itemArray) - { - return Html_Form::input($itemArray['action'],$itemArray['field'],"input_".encode($itemArray['action']),null,"data-primary-key='".$itemArray['name']."'"); - } - //create the HTML of the filter - public function filterForm($viewArgsName, $filterString = null, $filterValues = null) + public function filterForm($viewArgsName) { $cleanName = str_replace('n!',null,$viewArgsName); $cleanName = str_replace('-',null,$cleanName); @@ -632,15 +474,8 @@ class Helper_List extends Helper_Html { if (Params::$nullQueryValue) { $this->viewArgs[$viewArgsName] = Params::$nullQueryValue; - $viewStatus = Url::createUrl($this->viewArgs); - if (strcmp($value,Params::$nullQueryValue) === 0 and !isset($filterValues)) - { - $value = ''; - } - } - else - { - $viewStatus = $this->viewStatus; + $viewStatus = Url::createUrl(array_values($this->viewArgs)); + if (strcmp($value,Params::$nullQueryValue) === 0) $value = ''; } $this->viewArgs[$viewArgsName] = $temp; @@ -649,42 +484,11 @@ class Helper_List extends Helper_Html { $title = $this->strings->gtext('filter'); $clearLinkTitle = $this->strings->gtext('clear the filter'); - $html = null; - - if (!$this->aggregateFilters) - { - $html .= "
\n"; - } - - $html .= isset($filterString) ? " ".$filterString." " : null; - - if (!isset($filterValues)) - { - $html .= ""; - } - else - { - $filterValues = array_merge(array(Params::$nullQueryValue => $this->strings->gtext('All')),$filterValues); - $html .= Html_Form::select($viewArgsName,$value,$filterValues,"list_filter_input list_filter_input_$cleanName",null,"yes"); - } - - if (!$this->aggregateFilters) - { - $html .= ""; - $html .= "\n"; - - if (!Params::$rewriteStatusVariables) - { - foreach ($this->viewArgs as $k => $v) - { - if (strcmp($k,"$viewArgsName") !== 0) - { - $html .= ""; - } - } - } - $html .= "
\n"; - } + $html = "
\n"; + $html .= ""; + $html .= ""; + $html .= "\n"; + $html .= "
\n"; return $html; } diff --git a/h-source/Library/Helper/Menu.php b/h-source/Library/Helper/Menu.php index 4b33261..8fd4bf4 100755 --- a/h-source/Library/Helper/Menu.php +++ b/h-source/Library/Helper/Menu.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,8 +25,7 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to write the top menù of the view files class Helper_Menu extends Helper_Html { - public static $htmlLinks = array(); - + public $panelController; //panel controller public $controller; @@ -50,7 +49,6 @@ class Helper_Menu extends Helper_Html 'text' => $this->strings->gtext('Back'), 'url' => 'main', 'icon' => $baseUrl."left.png", - 'queryString' => null, ), 'add' => array( @@ -59,7 +57,6 @@ class Helper_Menu extends Helper_Html 'text' => $this->strings->gtext('Add'), 'url' => 'form/insert', 'icon' => $baseUrl."add.png", - 'queryString' => null, ), 'panel' => array( @@ -68,25 +65,9 @@ class Helper_Menu extends Helper_Html 'text' => $this->strings->gtext('Panel'), 'url' => 'main', 'icon' => $baseUrl."panel.png", - 'queryString' => null, ) ); - - foreach (self::$htmlLinks as $k => $v) - { - if (!array_key_exists($k, $this->links)) - { - $this->links[$k] = $v; - } - else - { - foreach ($v as $subK => $subV) - { - $this->links[$k][$subK] = $subV; - } - } - } } public function build($controller = null, $panelController = null) @@ -108,11 +89,8 @@ class Helper_Menu extends Helper_Html //check that the text and the ure are defined if (isset($this->links[$linkName]['text']) and isset($this->links[$linkName]['url'])) { - $title = isset($this->links[$linkName]['title']) ? "title=\"".$this->links[$linkName]['title']."\"" : null; - + $title = isset($this->links[$linkName]['title']) ? "title='".$this->links[$linkName]['title']."'" : null; $class = isset($this->links[$linkName]['class']) ? "class='".$this->links[$linkName]['class']."'" : null; - $class = isset(self::$htmlLinks[$linkName]["class"]) ? "class='".self::$htmlLinks[$linkName]["class"]."'" : $class; - $icon = isset($this->links[$linkName]['icon']) ? " " : null; //choose the controller (current or panel) @@ -120,18 +98,8 @@ class Helper_Menu extends Helper_Html $viewStatus = (strcmp($linkName,'panel') === 0) ? null : $this->viewStatus; $href = Url::getRoot($controller.$this->links[$linkName]['url'].$viewStatus); - - if (isset($this->links[$linkName]['queryString'])) - { - $href .= $this->links[$linkName]['queryString']; - } - $text = $this->links[$linkName]['text']; - $htmlBefore = isset($this->links[$linkName]["htmlBefore"]) ? $this->links[$linkName]["htmlBefore"] : "
$icon "; - $htmlAfter = isset($this->links[$linkName]["htmlAfter"]) ? $this->links[$linkName]["htmlAfter"] : "
"; - $attributes = isset($this->links[$linkName]["attributes"]) ? $this->links[$linkName]["attributes"] : null; - - $menu .= "$htmlBefore$text$htmlAfter\n"; + $menu .= "
$icon $text
\n"; } } } diff --git a/h-source/Library/Helper/Pages.php b/h-source/Library/Helper/Pages.php index 3826469..d8ac856 100755 --- a/h-source/Library/Helper/Pages.php +++ b/h-source/Library/Helper/Pages.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -109,16 +109,9 @@ class Helper_Pages extends Helper_Html public function html($pageNumber,$string = null) { if (isset($string)) { $strNumber = $string; - if (strcmp($pageNumber,"1") === 0) - { - $strClass = "class='itemListPage previous_page'"; - } - else - { - $strClass = "class='itemListPage next_page'"; - } + $strClass = "class='itemListPage'"; } else { - if (strcmp($pageNumber,$this->_currentPage) === 0) + if ($pageNumber === $this->_currentPage) { $strNumber = $pageNumber; $strClass = "class='currentPage'"; @@ -130,7 +123,7 @@ class Helper_Pages extends Helper_Html } } $this->viewArgs[$this->_variableArg] = $pageNumber; - $viewStatus = Url::createUrl($this->viewArgs); + $viewStatus = Url::createUrl(array_values($this->viewArgs)); $href= Url::getRoot(null) . $this->_urlViewAction .$viewStatus; return $this->getATag($href,$strNumber,$strClass); } diff --git a/h-source/Library/Helper/Popup.php b/h-source/Library/Helper/Popup.php index f3e6058..18bb00d 100755 --- a/h-source/Library/Helper/Popup.php +++ b/h-source/Library/Helper/Popup.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,15 +25,6 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to create the popup menu class Helper_Popup extends Helper_Html { - //the HTML of the popup - public static $popupHtml = array( - "before_loop" => "", - "top" => "
\n", - "bottom" => "
", - "after_loop" => "", - ); - public $popupArray = array(); //array of popup objects (see popup.php) public $url = null; //the url (controller/action) to link by means of the popup menù // public $fieldArg = null; //the key of the viewArgs array to set to the field in the where clause @@ -94,17 +85,9 @@ class Helper_Popup extends Helper_Html { } } - public function replacePlaceholders($string, $field, $name) - { - $string = str_replace("[[field]]",$field,$string); - $string = str_replace("[[name]]",$name,$string); - - return $string; - } - //create the HTML of the popup public function render() { - $returnString = self::$popupHtml["before_loop"]; + $returnString = null; if ($this->checkViewArgs()) { if (isset($this->viewArgs[$this->pageArg])) @@ -121,12 +104,11 @@ class Helper_Popup extends Helper_Html { $tempArg = $this->viewArgs[$field]; $this->legend[$field] = $tempArg; - $returnString .= $this->replacePlaceholders(self::$popupHtml["top"],$field,$popup->name); - + $returnString .= "\n"; $this->viewArgs[$field] = $tempArg; - - if ($this->printLegend) + } + if ($this->printLegend) + { + $returnString .= "\n"; + } + if (count($this->popupArray)>0) { + $returnString .= "\n"; } } - $returnString .= self::$popupHtml["after_loop"]; return $returnString; } diff --git a/h-source/Library/Hooks.php b/h-source/Library/Hooks.php index de46da8..b16b6d5 100644 --- a/h-source/Library/Hooks.php +++ b/h-source/Library/Hooks.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Html/Form.php b/h-source/Library/Html/Form.php index 91b2aa0..ec81cfb 100644 --- a/h-source/Library/Html/Form.php +++ b/h-source/Library/Html/Form.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -70,10 +70,10 @@ class Html_Form { $a = $optionValue; } - if (strcmp($optionValue,'optgroupOpen') === 0) + if (strcmp($b,'optgroupOpen') === 0) { if ($flag === 1) $returnString .= "\n"; - $returnString .= "\n"; + $returnString .= "\n"; $flag = 1; } else @@ -83,7 +83,7 @@ class Html_Form { } } if ($flag === 1) $returnString .= "\n"; - $returnString .= ""; + $returnString .= "\n"; return $returnString; } @@ -97,7 +97,7 @@ class Html_Form { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - $returnString =""; + $returnString ="\n"; return $returnString; } @@ -110,7 +110,7 @@ class Html_Form { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - $returnString =""; + $returnString ="\n"; return $returnString; } @@ -126,7 +126,7 @@ class Html_Form { $idStr = isset($idName) ? "id='".$idName."'" : null; $str = (strcmp($value,$option) === 0) ? "checked = 'checked'" : null; - return ""; + return "\n"; } //return the HTML of a hidden entry @@ -137,7 +137,7 @@ class Html_Form { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - return ""; + return "\n"; } //return the HTML of a password entry @@ -149,7 +149,7 @@ class Html_Form { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - return ""; + return "\n"; } //return the HTML of a textarea @@ -161,7 +161,7 @@ class Html_Form { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - return ""; + return "\n"; } //return the HTML of a radio button @@ -202,33 +202,7 @@ class Html_Form { } $str= (strcmp($value,$optionValue) === 0) ? "checked='checked'" : null; - $returnString .= "$before$after"; - } - - return $returnString; - } - - //return the HTML of an - //$name: the name of the input - //$value: the value of the input - //$className: the class name of the input - //$idName: name of the id - //$image: url of the image (if it is an image button) - //$attributes: list of attributes - static public function submit($name, $value, $className = null, $idName = null, $image = null, $attributes = null) - { - $strClass = isset($className) ? "class='".$className."'" : null; - $idStr = isset($idName) ? "id='".$idName."'" : null; - - if (isset($image)) - { - $returnString = ""; - $returnString .= ""; - } - else - { - $returnString = ''; - $returnString .= ""; + $returnString .= "$before$after\n"; } return $returnString; diff --git a/h-source/Library/Image/Gd/Captcha.php b/h-source/Library/Image/Gd/Captcha.php index d4285c2..1e8d706 100644 --- a/h-source/Library/Image/Gd/Captcha.php +++ b/h-source/Library/Image/Gd/Captcha.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Image/Gd/Thumbnail.php b/h-source/Library/Image/Gd/Thumbnail.php index bb69891..22e501e 100644 --- a/h-source/Library/Image/Gd/Thumbnail.php +++ b/h-source/Library/Image/Gd/Thumbnail.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -47,10 +47,9 @@ class Image_Gd_Thumbnail 'resample' => 'yes', 'function' => 'none', 'outputFormat' => 'jpeg', - 'backgroundColor' => null, //must be hex color ); - //set the $this->params array + //set the $this->scaffold->params array if (is_array($params)) { foreach ($params as $key => $value) @@ -61,46 +60,6 @@ class Image_Gd_Thumbnail $this->params = $defaultParams; } - public function getSourceCoordinates($direction, $oldDim, $dim) - { - if ($direction === "x") - { - switch ($this->params['horizAlign']) - { - case 'left': - $coordSrc = 0; - break; - case 'right': - $coordSrc = floor(($oldDim-$dim)); - break; - case 'center': - $coordSrc = floor(($oldDim-$dim)/2); - break; - default: - $coordSrc = $this->params['horizAlign']; - } - } - else - { - switch ($this->params['vertAlign']) - { - case 'top': - $coordSrc = 0; - break; - case 'bottom': - $coordSrc = floor(($oldDim-$dim)); - break; - case 'center': - $coordSrc = floor(($oldDim-$dim)/2); - break; - default: - $coordSrc = $this->params['vertAlign']; - } - } - - return $coordSrc; - } - //create the thumbnail //$imageName: the name of the file inside $this->basePath //$outputFile: the name of the output file @@ -116,8 +75,7 @@ class Image_Gd_Thumbnail if (file_exists($imagePath)) { - $extArray = explode('.', $imagePath); - $ext = strtolower(end($extArray)); + $ext = strtolower(end(explode('.', $imagePath))); if (strcmp($ext,'jpg') === 0 or strcmp($ext,'jpeg') === 0) { $img = @imagecreatefromjpeg($imagePath); @@ -153,172 +111,81 @@ class Image_Gd_Thumbnail $scale = max($this->params['imgWidth']/$width, $this->params['imgHeight']/$height); } - $xSrc = 0; //x coordinate of source image - $ySrc = 0; //y coordinate of source image - - $xDst = 0; //x coordinate of destination image - $yDst = 0; //y coordinate of destination image - - if ($this->params['cropImage'] === 'no') - { - if ($scale <= 1) + if ($scale < 1) { + + $xSrc = 0; + $ySrc = 0; + + if ($this->params['cropImage'] === 'no') { - $newWidth = $backWidth = floor($scale*$width); - $newHeight = $backHeight = floor($scale*$height); - - if ($this->params['backgroundColor']) - { - $backWidth = $this->params['imgWidth']; - $backHeight = $this->params['imgHeight']; - - if ($backWidth > $newWidth) - { - $xDst = floor(($backWidth-$newWidth)/2); - } - else if ($backHeight > $newHeight) - { - $yDst = floor(($backHeight-$newHeight)/2); - } - } - } - else - { - $newWidth = $backWidth = $width; - $newHeight = $backHeight = $height; - - if ($this->params['backgroundColor']) - { - $backWidth = $this->params['imgWidth']; - $backHeight = $this->params['imgHeight']; - - $xDst = floor(($backWidth-$newWidth)/2); - $yDst = floor(($backHeight-$newHeight)/2); - } + $newWidth = floor($scale*$width); + $newHeight = floor($scale*$height); } - } - else if ($this->params['cropImage'] === 'yes') - { - if ($scale < 1) + else if ($this->params['cropImage'] === 'yes') { - $newWidth = $backWidth = $this->params['imgWidth']; - $newHeight = $backHeight = $this->params['imgHeight']; + + $newWidth = $this->params['imgWidth']; + $newHeight = $this->params['imgHeight']; $oldWidth = $width; $oldHeight = $height; $width = floor($newWidth/$scale); $height = floor($newHeight/$scale); - $xSrc = $this->getSourceCoordinates("x",$oldWidth,$width); - $ySrc = $this->getSourceCoordinates("y",$oldHeight,$height); - - } - else - { - $oldWidth = $width; - $oldHeight = $height; - - if ($width <= $this->params['imgWidth'] and $height <= $this->params['imgHeight']) + switch ($this->params['horizAlign']) { - $newWidth = $backWidth = $width; - $newHeight = $backHeight = $height; - - if ($this->params['backgroundColor']) - { - $backWidth = $this->params['imgWidth']; - $backHeight = $this->params['imgHeight']; - - $xDst = floor(($backWidth-$newWidth)/2); - $yDst = floor(($backHeight-$newHeight)/2); - } - - } - else if ($width <= $this->params['imgWidth']) - { - $newWidth = $backWidth = $width; - $newHeight = $backHeight = $height = $this->params['imgHeight']; - - $ySrc = $this->getSourceCoordinates("y",$oldHeight,$height); - - if ($this->params['backgroundColor']) - { - $backWidth = $this->params['imgWidth']; - $backHeight = $this->params['imgHeight']; - - $xDst = floor(($backWidth-$newWidth)/2); - } - + case 'left': + $xSrc = 0; + break; + case 'right': + $xSrc = floor(($oldWidth-$width)); + break; + case 'center': + $xSrc = floor(($oldWidth-$width)/2); + break; + default: + $xSrc = $this->params['horizAlign']; } - else if ($height <= $this->params['imgHeight']) + + switch ($this->params['vertAlign']) { - $newHeight = $backHeight = $height; - $newWidth = $backWidth = $width = $this->params['imgWidth']; - - $xSrc = $this->getSourceCoordinates("x",$oldWidth,$width); - - if ($this->params['backgroundColor']) - { - $backWidth = $this->params['imgWidth']; - $backHeight = $this->params['imgHeight']; - - $yDst = floor(($backHeight-$newHeight)/2); - } - + case 'top': + $ySrc = 0; + break; + case 'bottom': + $ySrc = floor(($oldHeight-$height)); + break; + case 'center': + $ySrc = floor(($oldHeight-$height)/2); + break; + default: + $ySrc = $this->params['vertAlign']; } - } - } - //temp image - $tmpImg = imagecreatetruecolor($backWidth, $backHeight); - - //set background color if backgroundColor param is not null (hex value) - if ($this->params['backgroundColor']) - { - if (strcmp($this->params['backgroundColor'],"transparent") !== 0) - { - $rgbColor = hex2rgb($this->params['backgroundColor']); - - $backgroundC = imagecolorallocate($tmpImg,$rgbColor[0],$rgbColor[1],$rgbColor[2]); - } - else - { - $backgroundC = imagecolortransparent($tmpImg); } - - imagefill($tmpImg, 0, 0, $backgroundC); - } - - if(strcmp($type,'png') === 0 or strcmp($type,'gif') === 0){ - - if ($this->params['backgroundColor']) + + //temp image + $tmpImg = imagecreatetruecolor($newWidth, $newHeight); + + if ($this->params['resample'] === 'yes') { - imagealphablending($tmpImg, true); + //copy and resample + imagecopyresampled($tmpImg, $img, 0, 0, $xSrc, $ySrc,$newWidth, $newHeight, $width, $height); } else { - imagealphablending($tmpImg, false); + //copy and resize + imagecopyresized($tmpImg, $img, 0, 0, $xSrc, $ySrc,$newWidth, $newHeight, $width, $height); } - - imagesavealpha($tmpImg, true); - } + imagedestroy($img); + $img = $tmpImg; - if ($this->params['resample'] === 'yes') - { - //copy and resample - imagecopyresampled($tmpImg, $img, $xDst, $yDst, $xSrc, $ySrc,$newWidth, $newHeight, $width, $height); - } - else - { - //copy and resize - imagecopyresized($tmpImg, $img, $xDst, $yDst, $xSrc, $ySrc,$newWidth, $newHeight, $width, $height); - } - imagedestroy($img); - $img = $tmpImg; + if (!function_exists($this->params['function'])) { + throw new Exception('Error in '.__METHOD__.': function '.$this->params['function']. ' does not exist'); + } - if (!function_exists($this->params['function'])) - { - throw new Exception('Error in '.__METHOD__.': function '.$this->params['function']. ' does not exist'); + $img = call_user_func($this->params['function'],$img); } - - $img = call_user_func($this->params['function'],$img); + } if (!$img) @@ -328,7 +195,6 @@ class Image_Gd_Thumbnail $img = imagecreate($imgWidth, $imgHeight); imagecolorallocate($img,200,200,200); - } //print the image diff --git a/h-source/Library/Lang/En/DbCondStrings.php b/h-source/Library/Lang/En/DbCondStrings.php index 0c72d95..bfc5867 100644 --- a/h-source/Library/Lang/En/DbCondStrings.php +++ b/h-source/Library/Lang/En/DbCondStrings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -23,12 +23,12 @@ if (!defined('EG')) die('Direct access not allowed!'); //error strings in the case database conditions are not satisfied -class Lang_En_DbCondStrings extends Lang_En_ValCondStrings { +class Lang_En_DbCondStrings { //get the error string in the case that the value of the field $field is already present in the table $table public function getNotUniqueString($field) { - return "
The value of ". getFieldLabel($field) ." is already present. Please choose a different value.
\n".$this->getHiddenAlertElement($field); + return "
The value of ". $field ." is already present. Please choose a different value.
\n"; } } diff --git a/h-source/Library/Lang/En/Formats/Fields.php b/h-source/Library/Lang/En/Formats/Fields.php deleted file mode 100644 index c91a1f0..0000000 --- a/h-source/Library/Lang/En/Formats/Fields.php +++ /dev/null @@ -1,46 +0,0 @@ -. - -if (!defined('EG')) die('Direct access not allowed!'); - -class Lang_En_Formats_Fields -{ - - public static function getLabel($fieldName) - { - if (strstr($fieldName,",")) - { - $temp = explode(",",$fieldName); - for ($i=0; $i< count($temp); $i++) - { - $temp[$i] = self::getLabel($temp[$i]); - } - return implode (" and ",$temp); - } - else - { - $fieldName = str_replace("_"," ", $fieldName); - return ucfirst($fieldName); - } - } - -} diff --git a/h-source/Library/Lang/En/Formats/From/Mysql.php b/h-source/Library/Lang/En/Formats/From/Mysql.php deleted file mode 100644 index 5e4ea07..0000000 --- a/h-source/Library/Lang/En/Formats/From/Mysql.php +++ /dev/null @@ -1,64 +0,0 @@ -. - -if (!defined('EG')) die('Direct access not allowed!'); - -class Lang_En_Formats_From_Mysql -{ - - //convert the string from MySQL decimal format to En decimal format - public function decimal($string) - { - return $string; - } - - //convert the string from MySQL float format to En float format - public function float($string) - { - return $string; - } - - //convert the string from MySQL double format to En double format - public function double($string) - { - return $string; - } - - - //convert the string from MySQL date format to En date format - public function date($date) - { - if (preg_match('/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/',$date)) - { - $dateArray = explode('-',$date); - return $dateArray[1]."-".$dateArray[2]."-".$dateArray[0]; - } - return $date; - } - - //convert the string from MySQL enum format to En enum format - public function enum($string) - { - return $string; - } - -} \ No newline at end of file diff --git a/h-source/Library/Lang/En/Formats/From/index.html b/h-source/Library/Lang/En/Formats/From/index.html deleted file mode 100755 index 8d1c8b6..0000000 --- a/h-source/Library/Lang/En/Formats/From/index.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/h-source/Library/Lang/En/Formats/To/Mysql.php b/h-source/Library/Lang/En/Formats/To/Mysql.php deleted file mode 100644 index 31daab8..0000000 --- a/h-source/Library/Lang/En/Formats/To/Mysql.php +++ /dev/null @@ -1,62 +0,0 @@ -. - -if (!defined('EG')) die('Direct access not allowed!'); - -class Lang_En_Formats_To_Mysql -{ - - //convert the string from En decimal format to MySQL decimal format - public function decimal($string) - { - return $string; - } - - //convert the string from En float format to MySQL float format - public function float($string) - { - return $string; - } - - //convert the string from En double format to MySQL double format - public function double($string) - { - return $string; - } - - //convert the string from En date format to MySQL date format - public function date($date) - { - if (preg_match('/^[0-9]{2}\-[0-9]{2}\-[0-9]{4}$/',$date)) - { - $dateArray = explode('-',$date); - return $dateArray[2]."-".$dateArray[0]."-".$dateArray[1]; - } - return $date; - } - - //convert the string from En enum format to MySQL enum format - public function enum($string) - { - return $string; - } -} \ No newline at end of file diff --git a/h-source/Library/Lang/En/Formats/To/index.html b/h-source/Library/Lang/En/Formats/To/index.html deleted file mode 100755 index 8d1c8b6..0000000 --- a/h-source/Library/Lang/En/Formats/To/index.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/h-source/Library/Lang/En/Formats/index.html b/h-source/Library/Lang/En/Formats/index.html deleted file mode 100755 index 8d1c8b6..0000000 --- a/h-source/Library/Lang/En/Formats/index.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/h-source/Library/Lang/En/Generic.php b/h-source/Library/Lang/En/Generic.php index 8df27a9..3268270 100644 --- a/h-source/Library/Lang/En/Generic.php +++ b/h-source/Library/Lang/En/Generic.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -49,9 +49,6 @@ class Lang_En_Generic 'pages' => 'pages', 'filter' => 'filter', 'clear the filter' => 'clear the filter', - 'Save' => 'Save', - 'Actions' => 'Actions', - '-- Select bulk action --' => '-- Select bulk action --', ); public function gtext($string) diff --git a/h-source/Library/Lang/En/ModelStrings.php b/h-source/Library/Lang/En/ModelStrings.php index 266b1d2..cf26b8f 100644 --- a/h-source/Library/Lang/En/ModelStrings.php +++ b/h-source/Library/Lang/En/ModelStrings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -24,19 +24,13 @@ if (!defined('EG')) die('Direct access not allowed!'); class Lang_En_ModelStrings extends Lang_ResultStrings { - public function __construct() { - - $this->string = array( - "error" => "
Query error: Contact the administrator!
\n", - "executed" => "
Operation executed!
\n", - "associate" => "
Referential integrity problem: record associated to some other record in a child table. Break the association before.
\n", - "no-id" => "
Alert: record identifier not defined!
\n", - "not-linked" => "
The Item is not associated : you can't dissociate it
", - "linked" => "
The Item is already associated: you can't associate it another time
", - "not-existing-fields" => "
Some fields in the query do not exist
\n", - "no-fields" => "
There are no values in the insert/update query
\n", - ); - - } + public $string = array( + "error" => "
Query error: Contact the administrator!
\n", + "executed" => "
Operation executed!
\n", + "associate" => "
Referential integrity problem: record associated to some other record in a child table. Break the association before.
\n", + "no-id" => "
Alert: record identifier not defined!
\n", + "not-linked" => "
The Item is not associated : you can't dissociate it
", + "linked" => "
The Item is already associated: you can't associate it another time
" + ); } diff --git a/h-source/Library/Lang/En/UploadStrings.php b/h-source/Library/Lang/En/UploadStrings.php index 572f7bb..61bc0c5 100644 --- a/h-source/Library/Lang/En/UploadStrings.php +++ b/h-source/Library/Lang/En/UploadStrings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Lang/En/ValCondStrings.php b/h-source/Library/Lang/En/ValCondStrings.php index 8742c23..7f4e7ea 100644 --- a/h-source/Library/Lang/En/ValCondStrings.php +++ b/h-source/Library/Lang/En/ValCondStrings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -24,106 +24,70 @@ if (!defined('EG')) die('Direct access not allowed!'); class Lang_En_ValCondStrings { - //get the HTMl of the hidden alert notices - public function getHiddenAlertElement($element) - { - $html = ""; - $t = explode(",",$element); - - foreach ($t as $el) - { - $html .= "
$el
"; - } - - return $html; - } - //if the element is not defined public function getNotDefinedResultString($element) { - return "
Please fill the field ". getFieldLabel($element) .".
\n".$this->getHiddenAlertElement($element); + return "
". $element ." not defined!
\n"; } //if the elements are not equal public function getNotEqualResultString($element) { - return "
Please check that the fields ".getFieldLabel($element)." are equal
\n".$this->getHiddenAlertElement($element); + return "
Different values: $element
\n"; } //if the element is not alphabetic public function getNotAlphabeticResultString($element) { - return "
Please check that the field ".getFieldLabel($element)." is alphabetic
\n".$this->getHiddenAlertElement($element); + return "
".$element." has to be alphabetic
\n"; } //if the element is not alphanumeric public function getNotAlphanumericResultString($element) { - return "
Please check that the field ".getFieldLabel($element)." has to be alphanumeric
\n".$this->getHiddenAlertElement($element); + return "
".$element." has to be alphanumeric
\n"; } //if the element is not a decimal digit public function getNotDecimalDigitResultString($element) { - return "
Please check that the field ".getFieldLabel($element)." is a decimal digit
\n".$this->getHiddenAlertElement($element); + return "
".$element." has to be a decimal digit
\n"; } - - //if the element hasn't the mail format + + //if the element has the mail format public function getNotMailFormatResultString($element) { - return "
Please check that the field ".getFieldLabel($element)." is an e-mail address
\n".$this->getHiddenAlertElement($element); + return "
".$element." doesn't seem an e-mail address
\n"; } - //if the element is not numeric + //if the element is numeric public function getNotNumericResultString($element) { - return "
Please check that the field ".getFieldLabel($element)." is numeric
\n".$this->getHiddenAlertElement($element); - } - - //if the element is not an integer - public function getNotIntegerFormatResultString($element) - { - return "
Please check that the field ".getFieldLabel($element)." is an integer number
\n".$this->getHiddenAlertElement($element); - } - - //if the element is not a real date - public function getNotDateResultString($element) - { - return "
Please check that the field ".getFieldLabel($element)." is a real date
\n".$this->getHiddenAlertElement($element); + return "
".$element." has to be a numeric
\n"; } //if the element (string) length exceeds the value of characters (defined by $maxLength) public function getLengthExceedsResultString($element,$maxLength) { - return "
Please check that the field ".getFieldLabel($element)." does not exceed the value of $maxLength characters
\n".$this->getHiddenAlertElement($element); + return "
".$element." exceeds the value of $maxLength characters
\n"; } //if the element is one of the strings indicated by $stringList (a comma-separated list of strings) public function getIsForbiddenStringResultString($element,$stringList) { - return "
Please check that the field ".getFieldLabel($element)." is not one of the following strings: $stringList
\n".$this->getHiddenAlertElement($element); + return "
".$element." can't be one of the following strings: $stringList
\n"; } //if the element is not one of the strings indicated by $stringList (a comma-separated list of strings) public function getIsNotStringResultString($element,$stringList) { - return "
Please check that the field ".getFieldLabel($element)." is one of the following strings: $stringList
\n".$this->getHiddenAlertElement($element); + return "
".$element." has to be one of the following strings: $stringList
\n"; } - //if the element does not match the reg expr indicated by $regExp + //if the element is not one of the strings indicated by $stringList (a comma-separated list of strings) public function getDoesntMatchResultString($element,$regExp) { - return "
Please check that the field ".getFieldLabel($element)." matchs the following regular expression: $regExp
\n".$this->getHiddenAlertElement($element); - } - - //if the element is not decimal - public function getNotDecimalResultString($element, $format) - { - $t = explode(",",$format); - $M = (int)$t[0]; - $D = (int)$t[1]; - $I = $M - $D; - return "
Please check that the field ".getFieldLabel($element)." is a decimal number (maximum number of integer digits:$I, maximum number of decimal digits: $D)
\n".$this->getHiddenAlertElement($element); + return "
".$element." has to match the following regular expression: $regExp
\n"; } } diff --git a/h-source/Library/Lang/Eng/DbCondStrings.php b/h-source/Library/Lang/Eng/DbCondStrings.php index cd625af..e4196b6 100644 --- a/h-source/Library/Lang/Eng/DbCondStrings.php +++ b/h-source/Library/Lang/Eng/DbCondStrings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Lang/Eng/Generic.php b/h-source/Library/Lang/Eng/Generic.php index 29947fd..bb0ab99 100644 --- a/h-source/Library/Lang/Eng/Generic.php +++ b/h-source/Library/Lang/Eng/Generic.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -33,25 +33,6 @@ class Lang_Eng_Generic 'move up' => 'move up', 'move down' => 'move down', 'associate' => 'associate', - 'up' => 'su', - 'down' => 'down', - 'link' => 'link', - 'del' => 'del', - 'back' => 'back', - 'Back' => 'Back', - 'add a new record' => 'add a new record', - 'Add' => 'Add', - 'back to the Panel' => 'back to the Panel', - 'Panel' => 'Panel', - 'previous' => 'previous', - 'next' => 'next', - 'All' => 'All', - 'pages' => 'pages', - 'filter' => 'filter', - 'clear the filter' => 'clear the filter', - 'Save' => 'Save', - 'Actions' => 'Actions', - '-- Select bulk action --' => '-- Select bulk action --', ); public function gtext($string) diff --git a/h-source/Library/Lang/Eng/ModelStrings.php b/h-source/Library/Lang/Eng/ModelStrings.php index 20b8173..fa741a2 100644 --- a/h-source/Library/Lang/Eng/ModelStrings.php +++ b/h-source/Library/Lang/Eng/ModelStrings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -30,8 +30,7 @@ class Lang_Eng_ModelStrings extends Lang_ResultStrings { "associate" => "
Referential integrity problem: record associated to some other record in a child table. Break the association before.
\n", "no-id" => "
Alert: record identifier not defined!
\n", "not-linked" => "
The Item is not associated : you can't dissociate it
", - "linked" => "
The Item is already associated: you can't associate it another time
", - "not-existing-fields" => "
Some fields in the query do not exist
\n", + "linked" => "
The Item is already associated: you can't associate it another time
" ); } diff --git a/h-source/Library/Lang/Eng/UploadStrings.php b/h-source/Library/Lang/Eng/UploadStrings.php index ca0332b..2ae4c9b 100644 --- a/h-source/Library/Lang/Eng/UploadStrings.php +++ b/h-source/Library/Lang/Eng/UploadStrings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Lang/Eng/ValCondStrings.php b/h-source/Library/Lang/Eng/ValCondStrings.php index f5d40a2..42e70d8 100644 --- a/h-source/Library/Lang/Eng/ValCondStrings.php +++ b/h-source/Library/Lang/Eng/ValCondStrings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -27,89 +27,67 @@ class Lang_Eng_ValCondStrings { //if the element is not defined public function getNotDefinedResultString($element) { - return "
". $element ." not defined!
\n"; + return "
". $element ." not defined!
\n"; } //if the elements are not equal public function getNotEqualResultString($element) { - return "
Different values: $element
\n"; + return "
Different values: $element
\n"; } //if the element is not alphabetic public function getNotAlphabeticResultString($element) { - return "
".$element." has to be alphabetic
\n"; + return "
".$element." has to be alphabetic
\n"; } //if the element is not alphanumeric public function getNotAlphanumericResultString($element) { - return "
".$element." has to be alphanumeric
\n"; + return "
".$element." has to be alphanumeric
\n"; } //if the element is not a decimal digit public function getNotDecimalDigitResultString($element) { - return "
".$element." has to be a decimal digit
\n"; + return "
".$element." has to be a decimal digit
\n"; } - //if the element hasn't the mail format + //if the element has the mail format public function getNotMailFormatResultString($element) { - return "
".$element." doesn't seem an e-mail address
\n"; + return "
".$element." doesn't seem an e-mail address
\n"; } - //if the element is not numeric + //if the element is numeric public function getNotNumericResultString($element) { - return "
".$element." has to be a numeric
\n"; - } - - //if the element is not an integer - public function getNotIntegerFormatResultString($element) - { - return "
".$element." has to be an integer
\n"; - } - - //if the element is not a real date - public function getNotDateResultString($element) - { - return "
".$element." has to be a real date (YYYY-MM-DD)
\n"; + return "
".$element." has to be a numeric
\n"; } //if the element (string) length exceeds the value of characters (defined by $maxLength) public function getLengthExceedsResultString($element,$maxLength) { - return "
".$element." exceeds the value of $maxLength characters
\n"; + return "
".$element." exceeds the value of $maxLength characters
\n"; } //if the element is one of the strings indicated by $stringList (a comma-separated list of strings) public function getIsForbiddenStringResultString($element,$stringList) { - return "
".$element." can't be one of the following strings: $stringList
\n"; + return "
".$element." can't be one of the following strings: $stringList
\n"; } //if the element is not one of the strings indicated by $stringList (a comma-separated list of strings) public function getIsNotStringResultString($element,$stringList) { - return "
".$element." has to be one of the following strings: $stringList
\n"; + return "
".$element." has to be one of the following strings: $stringList
\n"; } - //if the element does not match the reg expr indicated by $regExp + //if the element is not one of the strings indicated by $stringList (a comma-separated list of strings) public function getDoesntMatchResultString($element,$regExp) { - return "
".$element." has to match the following regular expression: $regExp
\n"; - } - - //if the element is not decimal - public function getNotDecimalResultString($element, $format) - { - $t = explode(",",$format); - $M = (int)$t[0]; - $D = (int)$t[1]; - $I = $M - $D; - return "
".$element." has to be a decimal number (maximum number of integer digits:$I, maximum number of decimal digits: $D)
\n"; + return "
".$element." has to match the following regular expression: $regExp
\n"; } } diff --git a/h-source/Library/Lang/ResultStrings.php b/h-source/Library/Lang/ResultStrings.php index 6f84090..2181b90 100644 --- a/h-source/Library/Lang/ResultStrings.php +++ b/h-source/Library/Lang/ResultStrings.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/ModAbstract.php b/h-source/Library/ModAbstract.php index de4f68f..f576c10 100644 --- a/h-source/Library/ModAbstract.php +++ b/h-source/Library/ModAbstract.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Model/#Base.php# b/h-source/Library/Model/#Base.php# new file mode 100755 index 0000000..4162a56 --- /dev/null +++ b/h-source/Library/Model/#Base.php# @@ -0,0 +1,1273 @@ +. + +if (!defined('EG')) die('Direct access not allowed!'); + +abstract class Model_Base +{ + + public $fields = ''; //the fields that have to be manipulated by the update and insert query + public $values = array(); //the values that corresponding to the $this->fields fields + public $form = null; //reference to a Form_Form object + public $formStruct = null; //the form structure + + public $submitName = null; //the current submitName (from the form) + public $identifierName = 'identifier'; + + public $notice = null; //a string explaining the result of the query applied (or not if an error occured): executed, error, etc + public $result = true; //the result of validate conditions, database conditions and query. It can be 'true' or 'false' + public $queryResult = false; //the result of the query + + //conditions that have to be satisfied before applying the query + //Ex: 'update'=>'checkEmpty:titolo,autore','submitName'=>'conditions' + public $strongConditions = array(); + + //conditions that have to be satisfied before applying the query + //Ex: 'update'=>'checkEmpty:titolo,autore','submitName'=>'conditions' + //do not return error if a value is equal to '' or null + public $softConditions = array(); + + //conditions that have to be satisfied before applying the query + //check that the new values inserted satisfy some conditions + //Ex: 'update'=>'checkUniqueCompl:titolo,autore;checkUnique:titolo','insert'=>'checkUnique:titolo' + public $databaseConditions = array(); + + public $popupArray = array(); //array of popup objects (see popup.php) + + public $supplInsertValues = array(); //associative array defining supplementary values to be inserted on each insert query. It has to have the following form: array(field1 => value1,field2 => value2, ...) + + public $supplUpdateValues = array(); //associative array defining supplementary values to be inserted on each update query. It has to have the following form: array(field1 => value1,field2 => value2, ...) + + public $select = null; //fields that have to be selected in select queries + public $where = array(); //associative array containing all the where clauses ($field => $value) + //group by, order by and limit clauses + public $groupBy = null; + public $orderBy = null; + public $limit = null; + + public $from = null; //from clause of the select queries + public $on = array(); //on array + public $using = array(); //using array + public $join = array(); //join array + + public $toList = false; //if the result have to be given in a list format + public $listArray = array(); //array containing the $key and the $value to be used to extract a list from a resultSet + + //logic operator between statements in the where clause of select queries + public $logicalOperators = array('AND'); + + public $files = null; //reference to the Files_Upload class + + protected $_tables='itemTable,boxTable,item_boxTable'; + protected $_idFields='id_item,id_box'; + protected $_tablesArray=array(); + protected $_idFieldsArray=array(); + protected $_where = array(); + + //the name of the field that has to be used to order the rows of the main table of the model + protected $_idOrder = null; + + protected $_onDelete = 'check'; //can be 'nocheck' or 'check'. check: referential integrity check. nocheck: no referential integrity check + protected $_reference = null; //array containing the child table that have a reference to this table and the foreign key of the child table-> array($childTable,$foreignKey) + + protected $_popupItemNames = array(); //the fields to be used as names in the popupArray elements. Associative array ($itemNameField1 => $itemNameValue1, ...) + + //the labels of the pop-up menus + protected $_popupLabels = array(); + + //functions that have to be applied upon the label fields of the popup menu + protected $_popupFunctions = array(); + + protected $_popupWhere = array(); //where clause for the pupup menu + + protected $_resultString; //reference to the class containing all the result strings of the db queries + protected $_dbCondString; //reference to the class containing all the result strings of the database conditions + + protected $_backupFields = ''; //field saved after the delFields method has been applied + protected $_backupValues = array(); //values saved after the delFields method has been applied + protected $_allowedDbMethods = array('update','insert','del','moveup','movedown'); //methods that can be called by the updateTable method + + protected $submitNames = array( + 'update' => 'updateAction', + 'insert' => 'insertAction', + 'del' =>'delAction', + 'moveup' =>'moveupAction', + 'movedown' =>'movedownAction' + ); + + protected $identifierValue = null; //the value of the identifier ($_POST[$this->identifier]) + protected $arrayExt; //arrayExt object (see library/arrayExt.php) + + protected $_arrayStrongCheck; //Array_Validate_Strong object + protected $_arraySoftCheck; //Array_Validate_Soft object + + public $db; //reference to the database layer class + protected $_lang = null; //language of notices + + + public function __construct() { + $this->_tablesArray = explode(',',$this->_tables); + $this->_idFieldsArray = explode(',',$this->_idFields); + $this->_where[$this->_idFieldsArray[0]] = $this->_tablesArray[0]; + $this->arrayExt = new ArrayExt(); + + //initialize the validate objects + $this->_arrayStrongCheck = new Array_Validate_Strong($this->_lang); + $this->_arraySoftCheck = new Array_Validate_Soft($this->_lang); + + $this->identifierName = $this->_idFieldsArray[0]; + + //set the language of notices + $this->_lang = Params::$language; + + //create the $_resultString object (result strings of the db queries) + $modelStringClass = 'Lang_'.$this->_lang.'_ModelStrings'; + if (!class_exists($modelStringClass)) + { + $modelStringClass = 'Lang_En_ModelStrings'; + } + $this->_resultString = new $modelStringClass(); + + //create the $_dbCondString object (result strings of the database conditions) + $dbCondStringClass = 'Lang_'.$this->_lang.'_DbCondStrings'; + if (!class_exists($dbCondStringClass)) + { + $dbCondStringClass = 'Lang_En_DbCondStrings'; + } + $this->_dbCondString = new $dbCondStringClass(); + + //instantiate the database class + $this->db = Factory_Db::getInstance(DATABASE_TYPE); + + //instantiate the Files_Upload class + $params = array( + 'filesPermission' => 0777, + 'language' => $this->_lang, + 'allowedExtensions' => 'png,jpg,jpeg,gif', + 'maxFileSize' => 20000000, + 'fileUploadKey' => 'userfile' + ); + + $this->files = new Files_Upload(ROOT."/media/",$params); + } + + //sanitize all the $values property + public function sanitize() + { + $keys = implode(',',array_keys($this->values)); + $this->values = $this->arrayExt->subset($this->values,$keys,'sanitizeDb'); + } + + //change a resulting string from a db query + public function setString($key,$value) + { + $this->_resultString->string[$key] = $value; + } + + //set the submitNames property (array) + //$methodName : the method name, $submitName: the submit name of the submit action of the form + public function setSubmitNames($methodName,$submitName) + { + if (!in_array($methodName,$this->_allowedDbMethods)) + { + throw new Exception('query type "'.$methodName. '" not allowed in '. __METHOD__); + } + $this->submitNames[$methodName] = $submitName; + } + + //get the last query executed + public function getQuery() + { + return $this->db->query; + } + + //get the where clause of the select query + public function getWhereQueryClause() + { + return $this->where; + } + + //set the where clause of the select query + //whereArray = array ($table_field => $value) + public function setWhereQueryClause($whereArray) + { + $this->where = $whereArray; + } + + //append the whereArray clause to $this_->whereClause + //whereArray = array ($table_field => $value) + public function appendWhereQueryClause($whereArray) + { + $this->where = array_merge($this->where,$whereArray); + } + + //drop the char $char from the beginning of the string $string + public function dropStartChar($string,$char) + { + while(strcmp($string[0],$char) === 0) + { + $string = substr($string,1); + } + return $string; + } + + //get the table name from $this->_where. If the table is not present then return $this->_tablesArray[0] + public function getTableName($field) + { + return isset($this->_where[$field]) ? $this->_where[$field] : $this->_tablesArray[0]; + } + + //method to create the where clause of the select query from the $this->where array + //$level: level of the ricorsion + //$whereClauseLevel: array containing the field=>value statements of the where clause. If $whereClause = null than $this->where is considered + public function createWhereClause($level = 0, $whereClauseLevel = null, $operator = null) + { + $whereClause = null; + $whereClauseArray = array(); + + $whereClause = isset($whereClauseLevel) ? $whereClauseLevel : $this->where; + + foreach ($whereClause as $field => $value) + { + if (is_array($value)) + { + if (strstr($field,"OR")) + { + $op = " OR "; + } + else if (strstr($field,"AND")) + { + $op = " AND "; + } + else + { + $op = null; + } + $newValue = $this->createWhereClause($level+1, $value, $op); + if (isset($newValue)) $whereClauseArray[] = $newValue; + } + else + { + $flag = 0; //equal where clause + if (isset($field)) + { + //drop the 'n:' and '-' chars from $field + $fieldClean = str_replace('n!',null,$field); + $fieldClean = $this->dropStartChar($fieldClean,'-'); + if (strcmp($value,Params::$nullQueryValue) !== 0 or (Params::$nullQueryValue === false)) + { + foreach (params::$whereClauseSymbolArray as $symbol) + { + if (strstr($value,$symbol)) + { + //check if write or not the table name + $tableName = strstr($field,'n!') ? null : $this->getTableName($field).'.'; + $whereClauseArray[] = $tableName.$fieldClean.' '.$value; + $flag = 1; //not equal where clause + break; + } + } + if ($flag === 0) + { + $value = '"'.$value.'"'; + //check if write or not the table name + $tableName = strstr($field,'n!') ? null : $this->getTableName($field).'.'; + $whereClauseArray[] = $tableName.$fieldClean.'='.$value; + } + } + } + } + } + //get the logic operator at the current level + if (isset($operator)) + { + $logicOper = $operator; + } + else + { + $logicOper = isset($this->logicalOperators[$level]) ? ' '.$this->logicalOperators[$level].' ' : ' AND '; + } + $whereClause = !empty($whereClauseArray) ? implode($logicOper,$whereClauseArray) : null; + $whereClause = (isset($whereClause) and $level>0) ? '('.$whereClause.')' : $whereClause; + return $whereClause; + } + + + //get the submitName having its key (the method name) + public function getSubmitName($key) + { + if (!array_key_exists($key,$this->submitNames)) + { + return 'generalAction'; +// throw new Exception('query type "'.$key. '" not allowed in '.__METHOD__); + } + return $this->submitNames[$key]; + + } + + + //return the values, taken from the $_POST array, to be inserted inside the forms + //$queryType: insert or update + //$func: sanitize function to apply upon each value + //$id: if $queryType='update' that the values are taken from the record (of the main table of this model) having the primary key equal to $id + //$defaultValues = associative array of the form: array($entry=>$defaultValue) + //$functionsIfFromDb = associative array of the form: array($entry=>$function_to_be_applied) + public function getFormValues($queryType = 'insert', $func = 'sanitizeHtml',$id = null,$defaultValues = array(),$functionsIfFromDb = array()) + { + @session_start(); + if (is_array($func)) + { + $funcPost = $func[0]; + $funcDb = $func[1]; + } + else + { + $funcPost = $func; + $funcDb = 'none'; + } + + $arrayType = array('update','insert'); + $values = array(); + $idName = $this->identifierName; + if (in_array($queryType,$arrayType)) + { + $ident = null; + if (isset($id)) + { + $ident = (int)$id; + } + else if (isset($_POST[$idName])) + { + $ident = (int)$_POST[$idName]; + } + if ($this->result) + { + if ($queryType === 'update') + { + if (isset($ident)) + { + $recordArray = $this->selectId($ident); + + $fieldsArray = explode(',',$this->fields); + + $values = $this->arrayExt->subset($recordArray,$this->fields,$funcDb); + +// foreach ($fieldsArray as $field) +// { +// $values[$field] = array_key_exists($field,$recordArray) ? $recordArray[$field] : ''; +// } + + $values[$idName] = $ident; + + //apply the functions upon entries + foreach ($functionsIfFromDb as $entry => $funcUponEntry) + { + if (array_key_exists($entry,$values)) + { + if (!function_exists($funcUponEntry)) { + throw new Exception('Error in '.__METHOD__.': function '.$funcUponEntry. ' does not exist'); + } + + $values[$entry] = call_user_func($funcUponEntry,$values[$entry]); + } + } + + //set values of $_SESSION array + foreach ($values as $k => $v) + { + if (isset($this->formStruct['entries'][$k]['type'])) + { + if ($this->formStruct['entries'][$k]['type'] === 'File') + { + $_SESSION['form_'.$k] = $v; + } + } + } + } + } + else if ($queryType === 'insert') + { + + $tempArray = is_array($defaultValues) ? $defaultValues : array(); + + $values = $this->arrayExt->subset($tempArray,$this->fields,$funcPost); + + } + } + else + { + $values = $this->arrayExt->subset($_POST,$this->fields,$funcPost); + + if ($queryType === 'update') + { + $values[$idName] = $ident; + + //take values from $_SESSION array + $tempFieldArray = explode(',',$this->fields); + + for ($i = 0; $i < count($tempFieldArray); $i++) + { + if (isset($this->formStruct['entries'][$tempFieldArray[$i]]['type'])) + { + if ($this->formStruct['entries'][$tempFieldArray[$i]]['type'] === 'File') + { + if (isset($_SESSION['form_'.$tempFieldArray[$i]])) + { + $values[$tempFieldArray[$i]] = $_SESSION['form_'.$tempFieldArray[$i]]; + } + } + } + } + } + } + } + return $values; + } + + + //method to set the properties $this->fields and $this->values + public function setFields($fields,$func = 'sanitizeAll') + { + $this->values = $this->arrayExt->subset($_POST,$fields,$func); + $this->fields = $this->extractFields($fields); + + //set the backup variables + $this->_backupFields = $this->fields; + $this->_backupValues = $this->values; + } + + + //clear the fields list + public function clearFields() + { + $this->_backupFields = $this->fields; + $this->_backupValues = $this->values; + $this->fields = ''; + $this->values = array(); + } + + //del the fields written in the $list argument. The $list argument has to be of the type: field1,field2,... + public function delFields($list) + { + $this->_backupFields = $this->fields; + $this->_backupValues = $this->values; + $this->values = $this->arrayExt->subsetComplementary($this->values,$list); +// $this->fields = implode(',',array_keys($this->values)); + } + + //restore the fields and values saved in $_backupFields and $_backupValues + public function restoreFields() + { + $this->fields = $this->_backupFields; + $this->values = $this->_backupValues; + } + + //method to clean the $fields string deleting the colons (and the word after the colon) + public function extractFields($fields) { + $fieldsArray = explode(',',$fields); + $resultString = array(); + foreach ($fieldsArray as $field) { + if (strstr($field,':')) { + $temp = explode(':',$field); + $resultString[] = $temp[0]; + } else { + $resultString[] = $field; + } + } + return implode(',',$resultString); + } + + //add the supplementary value on insert and update queries + //$queryType: insert or update + public function setSupplValues($queryType) + { + if ($queryType === 'insert') + { + $supplValues = $this->supplInsertValues; + } + else if ($queryType === 'update') + { + $supplValues = $this->supplUpdateValues; + } + + $baseFields = implode(',',array_keys($this->values)); + + $supplFields = implode(',',array_keys($supplValues)); + $supplFields = (strcmp($supplFields,'') === 0) ? $supplFields : ',' . $supplFields; + + $fields = $baseFields . $supplFields; + $values = array_merge(array_values($this->values),array_values($supplValues)); + + return array($fields,$values); + } + + + //method to call the update query (overriding of the base_db del method) + //update the record with the primary key equal to $id (default) + //if $whereClause is set then use $whereClause as where clause of the update query + public function update($id = null, $whereClause = null) + { + if (!is_array($this->supplUpdateValues)) + { + throw new Exception('error in ' . __METHOD__ . ': the supplUpdateValues property has to be an array.'); + } + $el = $this->setSupplValues('update'); + $this->queryResult = false; + + if (isset($whereClause)) + { + $result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$whereClause); + $this->setNotice($result); + return $result; + } + else + { + if (isset($id)) + { + $where = $this->_idFieldsArray[0].'='.(int)($id); + $result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$where); + $this->setNotice($result); + return $result; + } + else + { + $this->notice = $this->_resultString->getString('no-id'); + $this->result = false; + $this->identifierValue = null; + return false; + } + } + } + + //method to call the insert query (overriding of the base_db del method) + public function insert() { + + $this->queryResult = false; + if (!is_array($this->supplInsertValues)) { + throw new Exception('error in ' . __METHOD__ . ': the supplInsertValues property has to be an array.'); + } + + if (isset($this->_idOrder)) + { + $maxValue = $this->db->getMax($this->_tablesArray[0],$this->_idOrder); + $this->supplInsertValues[$this->_idOrder] = (int)$maxValue + 1; + } + + $el = $this->setSupplValues('insert'); + + $result = $this->db->insert($this->_tablesArray[0],$el[0],$el[1]); + $this->setNotice($result); + return $result; + } + + //method to call the delete query (overriding of the base_db del method) + public function del($id = null, $whereClause = null) { + + $this->queryResult = false; + + if (isset($whereClause)) + { + $result = $this->db->del($this->_tablesArray[0],$whereClause); + $this->setNotice($result); + return $result; + } + else + { + if (isset($id)) { + $where = $this->_idFieldsArray[0].'='.(int)$id; + $result = $this->db->del($this->_tablesArray[0],$where); + $this->setNotice($result); + return $result; + } else { + $this->notice = $this->_resultString->getString('no-id'); + $this->result = false; + $this->identifierValue = null; + return false; + } + } + } + + //move to the top the record having $this->_idOrder = $id + //where clause + public function moveup($id) + { + return $this->move($id,'up'); + } + + //move to the top the record having $this->_idOrder = $id + //where clause + public function movedown($id) + { + return $this->move($id,'down'); + } + + //move the record having $this->_tablesArray[0] = $id + //$par: 'up' or 'down' + //where clause + public function move($id,$par = 'up') + { + $this->queryResult = false; + if (isset($id)) + { + $increm = ($par === 'up') ? 1 : -1; + + $backupLimit = $this->limit; + $this->limit = null; + + $data = $this->getFields($this->_tablesArray[0].'.'.$this->_idFieldsArray[0].','.$this->_tablesArray[0].'.'.$this->_idOrder); + + for($i = 0; $i < count($data); $i++) + { + if (strcmp($data[$i][$this->_tablesArray[0]][$this->_idFieldsArray[0]],$id) === 0) + { + if (($par === 'up' and $i !== 0) or ($par === 'down' and $i !== (count($data)-1))) + { + $prevOrder = $data[$i-$increm][$this->_tablesArray[0]][$this->_idOrder]; + $prevId = $data[$i-$increm][$this->_tablesArray[0]][$this->_idFieldsArray[0]]; + $currentOrder = $data[$i][$this->_tablesArray[0]][$this->_idOrder]; + $currentId = $data[$i][$this->_tablesArray[0]][$this->_idFieldsArray[0]]; + + //exchange the id_order of the two record + $res1 = $this->db->update($this->_tablesArray[0],$this->_idOrder,array($prevOrder),$this->_idFieldsArray[0]."='$currentId'"); + $res2 = $this->db->update($this->_tablesArray[0],$this->_idOrder,array($currentOrder),$this->_idFieldsArray[0]."='$prevId'"); + $result = ($res1 and $res2); + $this->setNotice($result); + return $result; + } + } + } + + $this->limit = $backupLimit; + } + else + { + $this->notice = $this->_resultString->getString('no-id'); + $this->result = false; + $this->identifierValue = null; + return false; + } + return false; + } + + public function setNotice($result) { + if ($result) { + $this->notice = $this->_resultString->getString('executed'); + $this->result = true; + $this->queryResult = true; + } else { + $this->notice = $this->_resultString->getString('error'); + $this->result = false; + $this->queryResult = false; + } + } + + //method used to verify that the value of a field is not duplicated + //$fieldsList: list of fields to check. Ex: field1,field2,... + //$where: the where clause + public function checkUnique($fieldsList,$where = null) + { + $errorString = null; + $numb = 0; + $fieldsArray = explode(',',$fieldsList); + $queryFieldsArray = explode(',',$this->fields); + foreach ($fieldsArray as $field) + { + if (in_array($field,$queryFieldsArray)) + { + if ($this->db->recordExists($this->_tablesArray[0],$field,$this->values[$field],$where)) + { + $errorString .= $this->_dbCondString->getNotUniqueString($field); + $numb++; + } + } + } + $this->notice = $errorString; + return $numb === 0 ? true : false; + } + + //like checkUnique: check all the records of the table apart from the record that has to be modified + public function checkUniqueCompl($fieldsList,$id = null) + { + if (isset($id)) + { + $where = $this->_idFieldsArray[0].'!='.(int)($id); + return $this->checkUnique($fieldsList,$where); + } else { + $this->notice = $this->_resultString->getString('no-id'); + return false; + } + } + + //method to apply the database conditions listed in the $this->databaseConditions associative array + //$queryType: indicates what set of validate conditions has to be considered (it's the key of the associative array) + public function applyDatabaseConditions($queryType,$id = null) + { + if (array_key_exists($queryType,$this->databaseConditions)) + { + if (!is_array($this->databaseConditions[$queryType])) + { + throw new Exception('error in method '.__METHOD__.' : databaseConditions['.$queryType.'] has to be an associative array'); + } + + foreach ($this->databaseConditions[$queryType] as $key => $values) + { + + //personalized error string + $altErrorString = null; + + //delete all the '+' chars + $key = $this->dropStartChar($key,'+'); + + if (strcmp($values,'all') === 0 or strstr($values,'all|')) + { + if (strstr($values,'all|')) + { + $values = str_replace('all|',$this->fields.'|',$values); + } + else + { + $values = $this->fields; + } + } + + if (strstr($values,'|')) + { + $temp = explode('|',$values); + $altErrorString = "
".$temp[1]."
\n"; + $values = $temp[0]; + } + + $allowedMethod = array('checkUnique','checkUniqueCompl'); + if (!in_array($key,$allowedMethod)) + { + throw new Exception('error in method '.__METHOD__.' : method "'.$key. '" not allowed in the property named databaseConditions'); + } + if (!call_user_func_array(array($this,$key),array($values,$id))) + { + if (isset($altErrorString)) $this->notice = $altErrorString; + $this->result = false; + $this->queryResult = false; + return false; + } + } + return true; + } else { + return true; + } + } + + + //method to apply the validate conditions listed in the $this->strongConditions associative array + //$queryType: indicates what set of validate conditions has to be considered (it's the key of the associative array) + //$strength: 'strong' or 'soft' + public function applyValidateConditions($queryType,$strength = 'strong') + { + if ($strength === 'strong') + { + $validateObj = $this->_arrayStrongCheck; + $conditions = $this->strongConditions; + $errString = 'strongConditions'; + } + else + { + $validateObj = $this->_arraySoftCheck; + $conditions = $this->softConditions; + $errString = 'softConditions'; + + if (Params::$nullQueryValue !== false) + { + $conditions['insert']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; + $conditions['update']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; + } + } + + if (array_key_exists($queryType,$conditions)) + { + if (!is_array($conditions[$queryType])) + { + throw new Exception('error in method '.__METHOD__.' : '.$errString.'['.$queryType.'] has to be an associative array'); + } + + foreach ($conditions[$queryType] as $key => $values) + { + + //personalized error string + $altErrorString = null; + + //delete all the '+' chars + $key = $this->dropStartChar($key,'+'); + + if (strcmp($values,'all') === 0 or strstr($values,'all|')) + { + if (strstr($values,'all|')) + { + $values = str_replace('all|',$this->fields.'|',$values); + } + else + { + $values = $this->fields; + } + } + + if (strstr($values,'|')) + { + $temp = explode('|',$values); + $altErrorString = "
".$temp[1]."
\n"; + $values = $temp[0]; + } + + $baseArgs = array($_POST,$values); + + if (strstr($key,'|')) + { + $funcArray = explode('|',$key); + $funcName = $funcArray[0]; + array_shift($funcArray); + $funcArgs = array_merge($baseArgs,$funcArray); + } + else + { + $funcName = $key; + $funcArgs = $baseArgs; + } + + if (!method_exists($validateObj,$funcName) or $funcName === 'checkGeneric') + { + throw new Exception('error in method '.__METHOD__.' :method "'.$funcName. '" not allowed in '.$errString); + } + if (!call_user_func_array(array($validateObj,$funcName),$funcArgs)) + { + $this->notice .= (isset($altErrorString)) ? $altErrorString : $validateObj->errorString; + $this->result = false; + $this->queryResult = false; + return false; + } + } + return true; + } else { + return true; + } + } + + + //apply, in sequence, the strong,soft and database conditions + //$methodName: insert,update + //$id: the id of the record. It is necessary for database conditions + public function checkConditions($methodName,$id = null) + { + if ($this->applyValidateConditions($methodName,'strong')) + { + if ($this->applyValidateConditions($methodName,'soft')) + { + if ($this->applyDatabaseConditions($methodName,$id)) + { + return true; + } + } + } + return false; + } + + //method that calls the function indicated in $this->submitNames. Ex: if $_POST['delAction'] is found, then the "del" method is called. + public function updateTable($methodsList = '',$id = null) { + + $allowedMethodsArray = explode(',',$methodsList); + $resultArray = array(); + $this->identifierValue = null; + if (isset($id)) + { + $this->identifierValue = (int)$id; + } + else if (isset($_POST[$this->identifierName])) + { + $this->identifierValue = (int)$_POST[$this->identifierName]; + } + foreach ($this->submitNames as $methodName => $submitName) + { + if (array_key_exists($submitName,$_POST)) + { + $this->submitName = $submitName; + if (method_exists($this,$methodName)) + { + //if the method is allowed + if (in_array($methodName,$allowedMethodsArray)) + { + if ($this->checkConditions($methodName,$this->identifierValue)) + { + $this->notice = null; + call_user_func_array(array($this,$methodName),array($this->identifierValue)); + } + } + } + else + { + throw new Exception('method '.$methodName.' not defined in class '.__CLASS__.'; error in method '.__METHOD__.''); + } + return; //only one cycle! + } + } + } + + //method to build the array of popup objects + public function popupBuild() + { + foreach ($this->_popupItemNames as $field => $itemName) + { +// if (array_key_exists($field,$this->_where)) +// { + $fieldClean = str_replace('n!',null,$field); + $itemNameClean = str_replace('n!',null,$itemName); + $fieldClean = $this->dropStartChar($fieldClean,'-'); + $itemNameClean = $this->dropStartChar($itemNameClean,'-'); + + //fields that have to be extracted + $queryFields = ($fieldClean === $itemNameClean) ? $fieldClean : $fieldClean.','.$itemNameClean; + + $table = $this->getTableName($field); + $this->popupArray[$field] = new Popup(); + + $popupWhereClause = array_key_exists($field,$this->_popupWhere) ? $this->_popupWhere[$field] : null; + + $result = $this->db->select($table,$queryFields,$popupWhereClause,$fieldClean); + + if ($result and $result !== false) + { + //get the label of the popup menu + $label = array_key_exists($field,$this->_popupLabels) ? $this->_popupLabels[$field] : $table.' : '.$itemNameClean; + $this->popupArray[$field]->name = $label; + + //get the table name + $fieldTable = isset($result[0][$table][$fieldClean]) ? $table : Params::$aggregateKey; + $itemNameTable = isset($result[0][$table][$itemNameClean]) ? $table : Params::$aggregateKey; + + foreach ($result as $row) + { + $this->popupArray[$field]->itemsValue[] = $row[$fieldTable][$fieldClean]; + + if (array_key_exists($field,$this->_popupFunctions)) + { + if (!function_exists($this->_popupFunctions[$field])) + { + throw new Exception('Error in '.__METHOD__.': function '.$this->_popupFunctions[$field]. ' does not exist'); + } + + $tempName = call_user_func($this->_popupFunctions[$field],$row[$itemNameTable][$itemNameClean]); + } + else + { + $tempName = $row[$itemNameTable][$itemNameClean]; + } + + $this->popupArray[$field]->itemsName[] = $tempName; + } + } +// } + } + } + + + //get the element before and after the current one + //$key: the key of the self::$where array that indicates the field to be used in order to find out the records before and after + //$fields: the fields that have to be extracted + public function getNeighbours($key,$fields = '') + { + //backup of the values + $tempWhere = $this->where; + $tempLimit = $this->limit; + $tempOrderBy = $this->orderBy; + $this->limit = 1; + //before + $this->where[$key] = '<'.$tempWhere[$key]; + $this->orderBy = $this->getTableName($key).'.'.$key.' DESC'; + $dataAfter = $this->getFields($fields); + //after + $this->where[$key] = '>'.$tempWhere[$key]; + $this->orderBy = $this->getTableName($key).'.'.$key; + $dataBefore = $this->getFields($fields); + //restore the previous values + $this->where = $tempWhere; + $this->limit = $tempLimit; + $this->orderBy = $tempOrderBy; + $result[0] = isset($dataBefore[0]) ? $dataBefore[0] : null; + $result[1] = isset($dataAfter[0]) ? $dataAfter[0] : null; + return $result; + } + + //set the $select property and return the current object + public function select($fields = null) + { + $this->select = $fields; + return $this; + } + + //set the $from property and return the current object + public function from($tables = null) + { + $this->from = isset($tables) ? $tables : $this->_tables; + return $this; + } + + //set the on property and return the current object + public function on($joinClause = '-') + { + $this->on[] = $joinClause; + $this->using[] = null; + return $this; + } + + //set the $using property and return the current object + public function using($using = null) + { + $this->using[] = $using; + $this->on[] = null; + return $this; + } + + //set the $join property and return the current object + public function left($string = null) + { + $this->join[] = "l:$string"; + return $this; + } + + //set the $join property and return the current object + public function right($string = null) + { + $this->join[] = "r:$string"; + return $this; + } + + //set the $join property and return the current object + public function inner($string = null) + { + $this->join[] = "i:$string"; + return $this; + } + + //set the $where property and return the current object + public function where($where = array()) + { + $this->where = $where; + return $this; + } + + //append the $where array to the ::where property and return the current object + public function aWhere($where = array()) + { + $this->appendWhereQueryClause($where); + return $this; + } + + //set the $groupBy property and return the current object + public function groupBy($groupBy = null) + { + $this->groupBy = $groupBy; + return $this; + } + + //set the $orderBy property and return the current object + public function orderBy($orderBy = null) + { + $this->orderBy = $orderBy; + return $this; + } + + //set the $limit property and return the current object + public function limit($limit = null) + { + $this->limit = $limit; + return $this; + } + + //set the $listArray property + public function toList($key, $value = null) + { + $this->listArray = array($key,$value); + $this->toList = true; + return $this; + } + + //reset all the clauses of the select query + public function clear() + { + $this->select = null; + $this->where = array(); + $this->groupBy = null; + $this->orderBy = null; + $this->limit = null; + $this->from = null; + $this->on = array(); + $this->using = array(); + $this->join = array(); + $this->toList = false; + return $this; + } + + //initialize and populate the ::form property (reference to a Form_Form object) + public function setForm($defAction = null, $defSubmit = array(), $defMethod = 'POST', $defEnctype = null) + { + if (isset($this->formStruct)) + { + $action = array_key_exists('action',$this->formStruct) ? $this->formStruct['action'] : $defAction; + $submit = array_key_exists('submit',$this->formStruct) ? $this->formStruct['submit'] : $defSubmit; + $entries = array_key_exists('entries',$this->formStruct) ? $this->formStruct['entries'] : null; + $method = array_key_exists('post',$this->formStruct) ? $this->formStruct['post'] : $defMethod; + $enctype = array_key_exists('enctype',$this->formStruct) ? $this->formStruct['enctype'] : $defEnctype; + + $this->form = new Form_Form($action,$submit,$method,$enctype); + + if (isset($entries)) + { + $this->form->setEntries($entries); + } + + $copy = $this->form->entry; + + foreach ($copy as $name => $entry) + { + if (strcmp($entry->type,'Select') === 0 and isset($entry->options)) + { + if (!is_array($entry->options)) + { + if (strstr($entry->options,'foreign::')) + { + $elements = explode('::',$entry->options); + + for ($i = 0; $i < count($elements); $i++) + { + if (strcmp($elements[$i],'--') === 0) $elements[$i] = null; + } + //send the query + array_shift($elements); + $resultSet = call_user_func_array(array($this->db,'select'),$elements); + + $single = true; + + if (strstr($elements[1],',')) + { + $args = explode(',',$elements[1]); + //add the table name + $args[0] = $elements[0].'.'.$args[0]; + $args[1] = $elements[0].'.'.$args[1]; + //associative array + $single = false; + } + else + { + $args[0] = $elements[0].'.'.$elements[1]; + $args[1] = null; + } + + $list = $this->getList($resultSet,$args[0],$args[1]); + + $this->form->entry[$name]->options = ($single) ? implode(',',array_values($list)) : $list; + } + } + } + } + + } + else + { + $this->form = new Form_Form($defAction,$defSubmit,$defMethod,$defEnctype); + } + } + + //get a list from a result set + //$resultSet: the result set coming from a select query + public function getList($resultSet, $key, $value = null) + { + $list = array(); + + if (strstr($key,'.')) + { + $arr = explode('.',$key); + $keyTable = $arr[0]; + $keyField = $arr[1]; + } + else + { + $keyTable = $this->_tablesArray[0]; + $keyField = $key; + } + + if (!isset($value)) + { + foreach ($resultSet as $row) + { + $list[] = $row[$keyTable][$keyField]; + } + } + else + { + if (strstr($value,'.')) + { + $arr = explode('.',$value); + $valueTable = $arr[0]; + $valueField = $arr[1]; + } + else + { + $valueTable = $this->_tablesArray[0]; + $valueField = $value; + } + + foreach ($resultSet as $row) + { + $list[$row[$keyTable][$keyField]] = $row[$valueTable][$valueField]; + } + + } + return $list; + } + + // Retrieves the ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT). + public function lastId() + { + return $this->db->lastId(); + } + + //send a free query + public function query($query) + { + return $this->db->query($query); + } + + //the text of the error message from previous MySQL operation + public function getError() + { + return $this->db->getError(); + } + + //the numerical value of the error message from previous MySQL operation + public function getErrno() + { + return $this->db->getErrno(); + } + + //define the abstract method to get the value of the record $id of the main table + abstract public function selectId($id); + + //define the abstract method to get the fields from the tables + abstract public function getFields(); + +} \ No newline at end of file diff --git a/h-source/Library/Model/Base.php b/h-source/Library/Model/Base.php index 67bd91c..4162a56 100755 --- a/h-source/Library/Model/Base.php +++ b/h-source/Library/Model/Base.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,12 +25,10 @@ if (!defined('EG')) die('Direct access not allowed!'); abstract class Model_Base { - public $foreignKeys = array(); //list of foreign keys - public $fields = ''; //the fields that have to be manipulated by the update and insert query public $values = array(); //the values that corresponding to the $this->fields fields public $form = null; //reference to a Form_Form object - public $formStruct = array("entries" => array()); //the form structure + public $formStruct = null; //the form structure public $submitName = null; //the current submitName (from the form) public $identifierName = 'identifier'; @@ -39,18 +37,15 @@ abstract class Model_Base public $result = true; //the result of validate conditions, database conditions and query. It can be 'true' or 'false' public $queryResult = false; //the result of the query - //conditions that the $_POST array has to satisfy (strong) + //conditions that have to be satisfied before applying the query + //Ex: 'update'=>'checkEmpty:titolo,autore','submitName'=>'conditions' public $strongConditions = array(); - //conditions that the $_POST array has to satisfy (soft) + //conditions that have to be satisfied before applying the query + //Ex: 'update'=>'checkEmpty:titolo,autore','submitName'=>'conditions' + //do not return error if a value is equal to '' or null public $softConditions = array(); - //conditions that $this->values has to satisfy (strong) - public $valuesConditions = array(); - - //array where the conditions are temporary saved when the saveConditions is called - public $backupConditions = array(); - //conditions that have to be satisfied before applying the query //check that the new values inserted satisfy some conditions //Ex: 'update'=>'checkUniqueCompl:titolo,autore;checkUnique:titolo','insert'=>'checkUnique:titolo' @@ -62,17 +57,13 @@ abstract class Model_Base public $supplUpdateValues = array(); //associative array defining supplementary values to be inserted on each update query. It has to have the following form: array(field1 => value1,field2 => value2, ...) - public $backupSelect = array(); //where the status of the where clause is stored when the save() method is called public $select = null; //fields that have to be selected in select queries - public $sWhere = null; //string: free where clause public $where = array(); //associative array containing all the where clauses ($field => $value) //group by, order by and limit clauses public $groupBy = null; public $orderBy = null; public $limit = null; - public $convert = false; //It can be tru or false. If true the extracted values are converted from MySQL format to $_lang format - public $from = null; //from clause of the select queries public $on = array(); //on array public $using = array(); //using array @@ -108,14 +99,9 @@ abstract class Model_Base protected $_popupWhere = array(); //where clause for the pupup menu - protected $_popupOrderBy = array(); //order by clause for the pupup menu - protected $_resultString; //reference to the class containing all the result strings of the db queries protected $_dbCondString; //reference to the class containing all the result strings of the database conditions - protected $_conversionToDbObject = null; //reference to the class to convert the values from current lang formats to MySQL formats - protected $_conversionFromDbObject = null; //reference to the class to convert the values from MySQL formats to current lang formats - protected $_backupFields = ''; //field saved after the delFields method has been applied protected $_backupValues = array(); //values saved after the delFields method has been applied protected $_allowedDbMethods = array('update','insert','del','moveup','movedown'); //methods that can be called by the updateTable method @@ -133,7 +119,6 @@ abstract class Model_Base protected $_arrayStrongCheck; //Array_Validate_Strong object protected $_arraySoftCheck; //Array_Validate_Soft object - protected $_arrayValuesCheck; //Array_Validate_Values object public $db; //reference to the database layer class protected $_lang = null; //language of notices @@ -145,16 +130,15 @@ abstract class Model_Base $this->_where[$this->_idFieldsArray[0]] = $this->_tablesArray[0]; $this->arrayExt = new ArrayExt(); - //set the language of notices - $this->_lang = Params::$language; - //initialize the validate objects $this->_arrayStrongCheck = new Array_Validate_Strong($this->_lang); $this->_arraySoftCheck = new Array_Validate_Soft($this->_lang); - $this->_arrayValuesCheck = new Array_Validate_Values($this->_lang); $this->identifierName = $this->_idFieldsArray[0]; + //set the language of notices + $this->_lang = Params::$language; + //create the $_resultString object (result strings of the db queries) $modelStringClass = 'Lang_'.$this->_lang.'_ModelStrings'; if (!class_exists($modelStringClass)) @@ -171,24 +155,6 @@ abstract class Model_Base } $this->_dbCondString = new $dbCondStringClass(); - //create the references of the classes to convert to e from MySQL formats - if (DATABASE_TYPE === "Mysqli" or DATABASE_TYPE === "Mysql") - { - $_conversionToDbObject = 'Lang_'.$this->_lang.'_Formats_To_Mysql'; - if (!class_exists($_conversionToDbObject)) - { - $_conversionToDbObject = 'Lang_En_Formats_To_Mysql'; - } - $this->_conversionToDbObject = new $_conversionToDbObject(); - - $_conversionFromDbObject = 'Lang_'.$this->_lang.'_Formats_From_Mysql'; - if (!class_exists($_conversionFromDbObject)) - { - $_conversionFromDbObject = 'Lang_En_Formats_From_Mysql'; - } - $this->_conversionFromDbObject = new $_conversionFromDbObject(); - } - //instantiate the database class $this->db = Factory_Db::getInstance(DATABASE_TYPE); @@ -205,22 +171,12 @@ abstract class Model_Base } //sanitize all the $values property - public function sanitize($function = "sanitizeDb") + public function sanitize() { - if (!function_exists($function)) { - throw new Exception('Error in '.__METHOD__.': function '.$function.' does not exists.'); - } - $keys = implode(',',array_keys($this->values)); - $this->values = $this->arrayExt->subset($this->values,$keys,$function); + $this->values = $this->arrayExt->subset($this->values,$keys,'sanitizeDb'); } - //return the name of the primary key - public function getPrimaryKey() - { - return $this->_idFields; - } - //change a resulting string from a db query public function setString($key,$value) { @@ -321,11 +277,11 @@ abstract class Model_Base { foreach (params::$whereClauseSymbolArray as $symbol) { - if (stristr($value,$symbol)) + if (strstr($value,$symbol)) { //check if write or not the table name $tableName = strstr($field,'n!') ? null : $this->getTableName($field).'.'; - $whereClauseArray[] = strstr($field,'n!n!') ? $value : $tableName.$fieldClean.' '.$value; + $whereClauseArray[] = $tableName.$fieldClean.' '.$value; $flag = 1; //not equal where clause break; } @@ -335,7 +291,7 @@ abstract class Model_Base $value = '"'.$value.'"'; //check if write or not the table name $tableName = strstr($field,'n!') ? null : $this->getTableName($field).'.'; - $whereClauseArray[] = strstr($field,'n!n!') ? $value : $tableName.$fieldClean.'='.$value; + $whereClauseArray[] = $tableName.$fieldClean.'='.$value; } } } @@ -368,129 +324,7 @@ abstract class Model_Base } - //converts values from MySQl to $_lang format when filling the form with values coming from the DB - public function convertFromMysql($values) - { - if (Params::$automaticConversionFromDbFormat) - { - if (isset($this->_conversionFromDbObject)) - { - //get all types as associative array - $types = $this->db->getTypes($this->_tables, "*", false, true); - - if ($types) - { - $values = $this->convertFromMysqlT($types, $values, $this->db->getEnumTypes()); - } - } - } - - return $values; - } - - //convert an array associaive from MySQL format to $_lang format - //$values: array associative to convert - //$types: types of the elements of the associative array - //$excludeTypes: array of type whose conversion has to be avoided - public function convertFromMysqlT($types, $values, $excludeTypes = array()) - { - foreach ($values as $field => $value) - { - if (array_key_exists($field, $types)) - { - if (!in_array(strtolower($types[$field]),$excludeTypes)) - { - if (method_exists($this->_conversionFromDbObject,strtolower($types[$field]))) - { - $values[$field] = call_user_func(array($this->_conversionFromDbObject, strtolower($types[$field])), $values[$field]); - } - } - } - } - return $values; - } - - //set the default values taking it from DB or from type definition - public function setDefaultFormValues($fields) - { - $returnDefaultValues = array(); - - if (Params::$automaticallySetFormDefaultValues) - { - if (isset($this->_conversionFromDbObject)) - { - //get all types as associative array - $types = $this->db->getTypes($this->_tables, "*", true, true); - - //get all default values as associative array - $defaultValues = $this->db->getDefaultValues($this->_tables, "*", false, true); - - $fieldsArray = explode(",",$fields); - - foreach ($fieldsArray as $field) - { - if (array_key_exists($field,$defaultValues)) - { - if (preg_match('/^('.implode("|",$this->db->getCharTypes()).')/i',$types[$field],$matches) or preg_match('/^('.implode("|",$this->db->getTextTypes()).')/i',$types[$field],$matches)) - { - if (strcmp($defaultValues[$field],"") !== 0) - { - $returnDefaultValues[$field] = $defaultValues[$field]; - } - } - else if (preg_match('/^('.implode("|",$this->db->getIntegerTypes()).')/i',$types[$field],$matches) or preg_match('/^('.implode("|",$this->db->getFloatTypes()).')$/i',$types[$field],$matches) or preg_match('/^('.implode("|",$this->db->getDecimalTypes()).')/i',$types[$field],$matches)) - { - if (strcmp($defaultValues[$field],"") !== 0) - { - $returnDefaultValues[$field] = method_exists($this->_conversionFromDbObject,strtolower($matches[1])) ? call_user_func(array($this->_conversionFromDbObject, strtolower($matches[1])), $defaultValues[$field]) : $defaultValues[$field]; - } - else - { - $returnDefaultValues[$field] = 0; - } - } - else if (preg_match('/^('.implode("|",$this->db->getDateTypes()).')$/i',$types[$field],$matches)) - { - $defDate = Params::$useCurrentDateAsDefaultDate ? date("Y-m-d") : ""; - if (strcmp($defaultValues[$field],"") !== 0) - { - $defDate = $defaultValues[$field]; - } - - if (method_exists($this->_conversionFromDbObject,strtolower($types[$field]))) - { - $returnDefaultValues[$field] = call_user_func(array($this->_conversionFromDbObject, strtolower($types[$field])), $defDate); - } - else - { - $returnDefaultValues[$field] = $defDate; - } - } - else if (preg_match('/^('.implode("|",$this->db->getEnumTypes()).')\((.*?)\)$/i',$types[$field],$matches)) - { - if (strcmp($defaultValues[$field],"") !== 0) - { - $returnDefaultValues[$field] = $defaultValues[$field]; - } - else - { - $temp = array(); - $strings = explode(",",$matches[2]); - for ($i=0;$iselectId($ident); - $recordArray = $this->convertFromMysql($recordArray); - $fieldsArray = explode(',',$this->fields); - + $values = $this->arrayExt->subset($recordArray,$this->fields,$funcDb); +// foreach ($fieldsArray as $field) +// { +// $values[$field] = array_key_exists($field,$recordArray) ? $recordArray[$field] : ''; +// } + $values[$idName] = $ident; //apply the functions upon entries @@ -569,16 +406,8 @@ abstract class Model_Base } else if ($queryType === 'insert') { - //set the default values taking it from DB or from type definition - $tempArray = $this->setDefaultFormValues($this->fields); - if (is_array($defaultValues)) - { - foreach ($defaultValues as $field => $value) - { - $tempArray[$field] = $value; - } - } + $tempArray = is_array($defaultValues) ? $defaultValues : array(); $values = $this->arrayExt->subset($tempArray,$this->fields,$funcPost); @@ -697,8 +526,6 @@ abstract class Model_Base //if $whereClause is set then use $whereClause as where clause of the update query public function update($id = null, $whereClause = null) { - $this->notice = null; - if (!is_array($this->supplUpdateValues)) { throw new Exception('error in ' . __METHOD__ . ': the supplUpdateValues property has to be an array.'); @@ -706,70 +533,50 @@ abstract class Model_Base $el = $this->setSupplValues('update'); $this->queryResult = false; - if (count($this->values) > 0) + if (isset($whereClause)) + { + $result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$whereClause); + $this->setNotice($result); + return $result; + } + else { - if (isset($whereClause)) + if (isset($id)) { - $result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$whereClause); + $where = $this->_idFieldsArray[0].'='.(int)($id); + $result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$where); $this->setNotice($result); return $result; } else { - if (isset($id)) - { - $where = $this->_idFieldsArray[0].'='.(int)($id); - $result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$where); - $this->setNotice($result); - return $result; - } - else - { - $this->notice .= $this->_resultString->getString('no-id'); - $this->result = false; - $this->identifierValue = null; - return false; - } + $this->notice = $this->_resultString->getString('no-id'); + $this->result = false; + $this->identifierValue = null; + return false; } } - else - { - $this->notice .= $this->_resultString->getString('no-fields'); - $this->result = true; - $this->queryResult = true; - return false; - } } //method to call the insert query (overriding of the base_db del method) public function insert() { - $this->notice = null; + $this->queryResult = false; if (!is_array($this->supplInsertValues)) { throw new Exception('error in ' . __METHOD__ . ': the supplInsertValues property has to be an array.'); } - if (count($this->values) > 0) + if (isset($this->_idOrder)) { - if (isset($this->_idOrder)) - { - $maxValue = $this->db->getMax($this->_tablesArray[0],$this->_idOrder); - $this->supplInsertValues[$this->_idOrder] = (int)$maxValue + 1; - } - - $el = $this->setSupplValues('insert'); - - $result = $this->db->insert($this->_tablesArray[0],$el[0],$el[1]); - $this->setNotice($result); - return $result; - } - else - { - $this->notice .= $this->_resultString->getString('no-fields'); - $this->result = true; - $this->queryResult = true; - return false; + $maxValue = $this->db->getMax($this->_tablesArray[0],$this->_idOrder); + $this->supplInsertValues[$this->_idOrder] = (int)$maxValue + 1; } + + $el = $this->setSupplValues('insert'); + + $result = $this->db->insert($this->_tablesArray[0],$el[0],$el[1]); + $this->setNotice($result); + return $result; } //method to call the delete query (overriding of the base_db del method) @@ -791,7 +598,7 @@ abstract class Model_Base $this->setNotice($result); return $result; } else { - $this->notice .= $this->_resultString->getString('no-id'); + $this->notice = $this->_resultString->getString('no-id'); $this->result = false; $this->identifierValue = null; return false; @@ -818,8 +625,6 @@ abstract class Model_Base //where clause public function move($id,$par = 'up') { - $this->notice = null; - $this->queryResult = false; if (isset($id)) { @@ -855,7 +660,7 @@ abstract class Model_Base } else { - $this->notice .= $this->_resultString->getString('no-id'); + $this->notice = $this->_resultString->getString('no-id'); $this->result = false; $this->identifierValue = null; return false; @@ -865,11 +670,11 @@ abstract class Model_Base public function setNotice($result) { if ($result) { - $this->notice .= $this->_resultString->getString('executed'); + $this->notice = $this->_resultString->getString('executed'); $this->result = true; $this->queryResult = true; } else { - $this->notice .= $this->_resultString->getString('error'); + $this->notice = $this->_resultString->getString('error'); $this->result = false; $this->queryResult = false; } @@ -932,6 +737,18 @@ abstract class Model_Base //delete all the '+' chars $key = $this->dropStartChar($key,'+'); + if (strcmp($values,'all') === 0 or strstr($values,'all|')) + { + if (strstr($values,'all|')) + { + $values = str_replace('all|',$this->fields.'|',$values); + } + else + { + $values = $this->fields; + } + } + if (strstr($values,'|')) { $temp = explode('|',$values); @@ -958,140 +775,29 @@ abstract class Model_Base } } - //add a condition - //$condArray: it can be $this->strongConditions, $this->softConditions or $this->databaseConditions - //$queryType: insert, update - //$condition: the condition - //$field: comma separated list of fields - private function addCondition(&$condArray,$queryType,$condition,$field) - { - if (isset($condArray[$queryType]) and array_key_exists($condition,$condArray[$queryType])) - { - $condition = "+".$condition; - $this->addCondition($condArray,$queryType,$condition,$field); - } - else - { - $condArray[$queryType][$condition] = $field; - } - } - - //choose if to apply insert, update or both conditions - private function addChooseCondition(&$condArray,$queryType,$condition,$field) - { - if ($queryType === "both") - { - $this->addCondition($condArray,"insert",$condition,$field); - $this->addCondition($condArray,"update",$condition,$field); - } - else - { - $this->addCondition($condArray,$queryType,$condition,$field); - } - } - - //add a condition to the strongCondition array - public function addDatabaseCondition($queryType,$condition,$field) - { - if ($queryType === "both") - { - $this->addChooseCondition($this->databaseConditions,"insert",$condition,$field); - $this->addChooseCondition($this->databaseConditions,"update",$condition."Compl",$field); - } - else - { - $this->addChooseCondition($this->databaseConditions,$queryType,$condition,$field); - } - } - - //add a condition to the strongCondition array - public function addStrongCondition($queryType,$condition,$field) - { - $this->addChooseCondition($this->strongConditions,$queryType,$condition,$field); - } - - //add a condition to the softCondition array - public function addSoftCondition($queryType,$condition,$field) - { - $this->addChooseCondition($this->softConditions,$queryType,$condition,$field); - } - - //add a condition to the valuesCondition array - public function addValuesCondition($queryType,$condition,$field) - { - $this->addChooseCondition($this->valuesConditions,$queryType,$condition,$field); - } - - //return the correct conditions array - //$strength: strong,soft,values - public function &getConditions($strength) - { - if ($strength === 'strong') - { - return $this->strongConditions; - } - else if ($strength === 'values') - { - return $this->valuesConditions; - } - else if ($strength === 'database') - { - return $this->databaseConditions; - } - - return $this->softConditions; - } - - //save the conditions - //$strength: strong,soft,values - public function saveConditions($strength) - { - $this->backupConditions[$strength] = $this->getConditions($strength); - } - - //restore the conditions taking them from $this->backupConditions - public function restoreConditions($strength) - { - $c = &$this->getConditions($strength); - - if (isset($this->backupConditions[$strength])) - { - $c = $this->backupConditions[$strength]; - } - } - - //clear the conditions - //$strength: strong,soft,values - public function clearConditions($strength) - { - $c = &$this->getConditions($strength); - $c = array(); - } //method to apply the validate conditions listed in the $this->strongConditions associative array //$queryType: indicates what set of validate conditions has to be considered (it's the key of the associative array) - //$strength: strong,soft,values + //$strength: 'strong' or 'soft' public function applyValidateConditions($queryType,$strength = 'strong') { - $arrayToCheck = $_POST; if ($strength === 'strong') { $validateObj = $this->_arrayStrongCheck; $conditions = $this->strongConditions; $errString = 'strongConditions'; } - else if ($strength === 'values') - { - $validateObj = $this->_arrayValuesCheck; - $conditions = $this->valuesConditions; - $errString = 'valuesConditions'; - $arrayToCheck = $this->values; - } else { $validateObj = $this->_arraySoftCheck; $conditions = $this->softConditions; $errString = 'softConditions'; + + if (Params::$nullQueryValue !== false) + { + $conditions['insert']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; + $conditions['update']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; + } } if (array_key_exists($queryType,$conditions)) @@ -1109,6 +815,18 @@ abstract class Model_Base //delete all the '+' chars $key = $this->dropStartChar($key,'+'); + + if (strcmp($values,'all') === 0 or strstr($values,'all|')) + { + if (strstr($values,'all|')) + { + $values = str_replace('all|',$this->fields.'|',$values); + } + else + { + $values = $this->fields; + } + } if (strstr($values,'|')) { @@ -1117,7 +835,7 @@ abstract class Model_Base $values = $temp[0]; } - $baseArgs = array($arrayToCheck,$values); + $baseArgs = array($_POST,$values); if (strstr($key,'|')) { @@ -1150,6 +868,7 @@ abstract class Model_Base } } + //apply, in sequence, the strong,soft and database conditions //$methodName: insert,update //$id: the id of the record. It is necessary for database conditions @@ -1189,10 +908,6 @@ abstract class Model_Base $this->submitName = $submitName; if (method_exists($this,$methodName)) { - if (strcmp($methodName,"insert") === 0) - { - $this->identifierValue = null; - } //if the method is allowed if (in_array($methodName,$allowedMethodsArray)) { @@ -1232,9 +947,7 @@ abstract class Model_Base $popupWhereClause = array_key_exists($field,$this->_popupWhere) ? $this->_popupWhere[$field] : null; - $popupOrderBy = array_key_exists($field,$this->_popupOrderBy) ? $this->_popupOrderBy[$field] : null; - - $result = $this->db->select($table,$queryFields,$popupWhereClause,$fieldClean,$popupOrderBy); + $result = $this->db->select($table,$queryFields,$popupWhereClause,$fieldClean); if ($result and $result !== false) { @@ -1306,13 +1019,6 @@ abstract class Model_Base return $this; } - //set the $convert property and return the current object - public function convert($convert = true) - { - $this->convert = $convert; - return $this; - } - //set the $from property and return the current object public function from($tables = null) { @@ -1371,12 +1077,6 @@ abstract class Model_Base return $this; } - public function sWhere($sWhere) - { - $this->sWhere = $sWhere; - return $this; - } - //set the $groupBy property and return the current object public function groupBy($groupBy = null) { @@ -1411,7 +1111,6 @@ abstract class Model_Base { $this->select = null; $this->where = array(); - $this->sWhere = null; $this->groupBy = null; $this->orderBy = null; $this->limit = null; @@ -1420,84 +1119,9 @@ abstract class Model_Base $this->using = array(); $this->join = array(); $this->toList = false; - $this->convert = false; return $this; } - //save all the clauses of the select query - public function save() - { - $this->backupSelect["select"] = $this->select; - $this->backupSelect["where"] = $this->where; - $this->backupSelect["sWhere"] = $this->sWhere; - $this->backupSelect["groupBy"] = $this->groupBy; - $this->backupSelect["orderBy"] = $this->orderBy; - $this->backupSelect["limit"] = $this->limit; - $this->backupSelect["from"] = $this->from; - $this->backupSelect["on"] = $this->on; - $this->backupSelect["using"] = $this->using; - $this->backupSelect["join"] = $this->join; - $this->backupSelect["toList"] = $this->toList; - $this->backupSelect["convert"] = $this->convert; - return $this; - } - - //restored all the saved clauses of the select query - public function restore() - { - if (count($this->backupSelect) > 0) - { - $this->select = $this->backupSelect["select"]; - $this->where = $this->backupSelect["where"]; - $this->sWhere = $this->backupSelect["sWhere"]; - $this->groupBy = $this->backupSelect["groupBy"]; - $this->orderBy = $this->backupSelect["orderBy"]; - $this->limit = $this->backupSelect["limit"]; - $this->from = $this->backupSelect["from"]; - $this->on = $this->backupSelect["on"]; - $this->using = $this->backupSelect["using"]; - $this->join = $this->backupSelect["join"]; - $this->toList = $this->backupSelect["toList"]; - $this->convert = $this->backupSelect["convert"]; - } - return $this; - } - - public function getSelectArrayFromEnumField($fieldName) - { - $types = $this->db->getTypes($this->_tables, $fieldName, true, true); - - if ($types) - { - if (preg_match('/^('.implode("|",$this->db->getEnumTypes()).')\((.*?)\)/i',$types[$fieldName],$matches)) - { - return $this->getSelectArrayFromEnumValues($matches[1], $matches[2]); - } - } - } - - public function getSelectArrayFromEnumValues($enumFunc, $enumValues) - { - $enumFunc = strtolower($enumFunc); - - $temp = array(); - $strings = explode(",",$enumValues); - for ($i=0;$i_conversionFromDbObject) and method_exists($this->_conversionFromDbObject, $enumFunc)) - { - $temp[$val] = call_user_func(array($this->_conversionFromDbObject, $enumFunc), $val); - } - else - { - $temp[$val] = $val; - } - } - return $temp; - } - //initialize and populate the ::form property (reference to a Form_Form object) public function setForm($defAction = null, $defSubmit = array(), $defMethod = 'POST', $defEnctype = null) { @@ -1511,67 +1135,6 @@ abstract class Model_Base $this->form = new Form_Form($action,$submit,$method,$enctype); - //get the entries from DB definition - $types = $this->db->getTypes($this->_tables, "*", true, true); - - foreach ($types as $field => $type) - { - $entryType = "InputText"; - $classType = "varchar_input"; - $options = null; - - if (strcmp($field, $this->_idFieldsArray[0]) === 0) - { - $entryType = "Hidden"; - } - else if (preg_match('/^('.implode("|",$this->db->getTextTypes()).')/i',$type,$matches)) - { - $entryType = "Textarea"; - $classType = "text_input"; - } - else if (preg_match('/^('.implode("|",$this->db->getDateTypes()).')/i',$type,$matches)) - { - $classType = "date_input"; - } - else if (preg_match('/^('.implode("|",$this->db->getEnumTypes()).')\((.*?)\)/i',$type,$matches)) - { - $entryType = "Select"; - $classType = "select_input"; - $options = $this->getSelectArrayFromEnumValues($matches[1], $matches[2]); - } - - if (array_key_exists($field,$entries)) - { - if (!array_key_exists("type",$entries[$field])) - { - $entries[$field]["type"] = $entryType; - } - - if ($entryType === "Select" and !array_key_exists("options",$entries[$field])) - { - $entries[$field]["options"] = $options; - $entries[$field]["reverse"] = "yes"; - } - - if (!array_key_exists("className",$entries[$field])) - { - $entries[$field]["className"] = $classType." ".Form_Form::$defaultEntryAttributes['className']; - } - } - else - { - $entries[$field]["type"] = $entryType; - - if ($entryType === "Select") - { - $entries[$field]["options"] = $options; - $entries[$field]["reverse"] = "yes"; - } - - $entries[$field]["className"] = $classType." ".Form_Form::$defaultEntryAttributes['className']; - } - } - if (isset($entries)) { $this->form->setEntries($entries); diff --git a/h-source/Library/Model/Map.php b/h-source/Library/Model/Map.php index e6d9f6b..7a093e1 100755 --- a/h-source/Library/Model/Map.php +++ b/h-source/Library/Model/Map.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Model/Tree.php b/h-source/Library/Model/Tree.php index 849fd7d..f7f95ea 100755 --- a/h-source/Library/Model/Tree.php +++ b/h-source/Library/Model/Tree.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -28,54 +28,54 @@ class Model_Tree extends Model_Base { parent::__construct(); } -// //method to create the first part of where clause -// //$index: the index of $this->_tablesArray -// public function createTreeWhere($index) { -// if (!empty($this->on)) -// { -// return $this->on; -// } -// else -// { -// $whereArray = array(); -// for ($i = $index; $i < (count($this->_tablesArray)-1); $i++) -// { -// $whereArray[] = $this->_tablesArray[$i].'.'.$this->_idFieldsArray[$i+1].'='.$this->_tablesArray[$i+1].'.'.$this->_idFieldsArray[$i+1]; -// } -// $whereString = !empty($whereArray) ? implode(' and ',$whereArray) : null; -// return $whereString; -// } -// } + //method to create the first part of where clause + //$index: the index of $this->_tablesArray + public function createTreeWhere($index) { + if (!empty($this->on)) + { + return $this->on; + } + else + { + $whereArray = array(); + for ($i = $index; $i < (count($this->_tablesArray)-1); $i++) + { + $whereArray[] = $this->_tablesArray[$i].'.'.$this->_idFieldsArray[$i+1].'='.$this->_tablesArray[$i+1].'.'.$this->_idFieldsArray[$i+1]; + } + $whereString = !empty($whereArray) ? implode(' and ',$whereArray) : null; + return $whereString; + } + } -// //create the list of tables of the select query -// //$index: the index of $this->_tablesArray -// public function createTablesList($index) { -// if (isset($this->from)) -// { -// return $this->from; -// } -// else -// { -// $tablesString = null; -// for ($i = $index; $i < (count($this->_tablesArray)-1); $i++) -// { -// $tablesString .= $this->_tablesArray[$i] . ','; -// } -// $tablesString .= $this->_tablesArray[count($this->_tablesArray)-1]; -// return $tablesString; -// } -// } -// -// //method to create the list of fields of the select query -// public function createFieldsList($index) { -// $fieldsString = null; -// for ($i = $index; $i < (count($this->_tablesArray)-1); $i++) -// { -// $fieldsString .= $this->_tablesArray[$i] . '.*,'; -// } -// $fieldsString .= $this->_tablesArray[count($this->_tablesArray)-1].'.*'; -// return $fieldsString; -// } + //create the list of tables of the select query + //$index: the index of $this->_tablesArray + public function createTablesList($index) { + if (isset($this->from)) + { + return $this->from; + } + else + { + $tablesString = null; + for ($i = $index; $i < (count($this->_tablesArray)-1); $i++) + { + $tablesString .= $this->_tablesArray[$i] . ','; + } + $tablesString .= $this->_tablesArray[count($this->_tablesArray)-1]; + return $tablesString; + } + } + + //method to create the list of fields of the select query + public function createFieldsList($index) { + $fieldsString = null; + for ($i = $index; $i < (count($this->_tablesArray)-1); $i++) + { + $fieldsString .= $this->_tablesArray[$i] . '.*,'; + } + $fieldsString .= $this->_tablesArray[count($this->_tablesArray)-1].'.*'; + return $fieldsString; + } //method to create the where clause and the list of tables and fields of the select query @@ -84,51 +84,32 @@ class Model_Tree extends Model_Base { //return: $elements = array('tables'=>$tables,'where'=>$where,'fields'=>$fields) public function treeQueryElements($tableName,$choice = 'all') { -// $index = array_search($tableName,$this->_tablesArray); -// $subArray = ($choice === 'all') ? array_slice($this->_tablesArray,$index) : array($tableName); //this array is necessary to verify that the where clause makes sense -// $tables = ($choice === 'all') ? $this->createTablesList($index) : $tableName; -// $where = ($choice === 'all') ? $this->createTreeWhere($index) : null; -// $fields = ($choice === 'all') ? $this->createFieldsList($index) : $tableName.'.*'; -// -// $wherePlus = $this->createWhereClause(); -// -// if (empty($this->on)) -// { -// $on = array(); -// -// if (isset($where) and isset($wherePlus)) -// { -// $where .= ' AND ' . $wherePlus; -// } -// else if (!isset($where) and isset($wherePlus)) -// { -// $where .= $wherePlus; -// } -// } -// else -// { -// $on = $where; -// $where = $wherePlus; -// } - - $where = $this->createWhereClause(); - - if (isset($where)) + $index = array_search($tableName,$this->_tablesArray); + $subArray = ($choice === 'all') ? array_slice($this->_tablesArray,$index) : array($tableName); //this array is necessary to verify that the where clause makes sense + $tables = ($choice === 'all') ? $this->createTablesList($index) : $tableName; + $where = ($choice === 'all') ? $this->createTreeWhere($index) : null; + $fields = ($choice === 'all') ? $this->createFieldsList($index) : $tableName.'.*'; + + $wherePlus = $this->createWhereClause(); + + if (empty($this->on)) { - if (isset($this->sWhere)) + $on = array(); + + if (isset($where) and isset($wherePlus)) { - $where .= " AND " . $this->sWhere; + $where .= ' AND ' . $wherePlus; + } + else if (!isset($where) and isset($wherePlus)) + { + $where .= $wherePlus; } } else { - $where = $this->sWhere; + $on = $where; + $where = $wherePlus; } - - $tables = isset($this->from) ? $this->from : $tableName; - - $fields = $tableName.".*"; - $on = $this->on; return array('tables' => $tables,'where' => $where,'fields'=>$fields,'on'=>$on); } @@ -146,37 +127,10 @@ class Model_Tree extends Model_Base { public function getFields($fields = '',$choice = 'all') { $elements = $this->treeQueryElements($this->_tablesArray[0],$choice); - - $queryFields = (strcmp($fields,'') === 0) ? $elements['fields'] : $fields; - $row = $this->db->select($elements['tables'],$queryFields,$elements['where'],$this->groupBy,$this->orderBy,$this->limit,$elements['on'],$this->using,$this->join); - - //convert from MySQL values - if ($this->convert) - { - if (count($row) > 0) - { - $types = array(); - - $tablesList = array_keys($row[0]); - - foreach ($tablesList as $table) - { - $types[$table] = $this->db->getTypes($table, "*", false, true); - } - - for ($i=0;$i< count ($row); $i++) - { - foreach ($tablesList as $table) - { - $row[$i][$table] = $this->convertFromMysqlT($types[$table], $row[$i][$table]); - } - - } - } - } + $queryFields = (strcmp($fields,'') === 0) ? $elements['fields'] : $fields; - return $row; + return $row = $this->db->select($elements['tables'],$queryFields,$elements['where'],$this->groupBy,$this->orderBy,$this->limit,$elements['on'],$this->using,$this->join); } public function send() @@ -206,8 +160,8 @@ class Model_Tree extends Model_Base { //$id: the id (primary key) of the record //$fields: the comma separated list of fields that have to be extracted public function selectId($id,$fields = null) { - - $this->save()->clear()->setWhereQueryClause(array($this->_idFieldsArray[0] => (int)$id)); + $tempWhere = $this->where; + $this->setWhereQueryClause(array($this->_idFieldsArray[0] => (int)$id)); $this->using = null; @@ -220,7 +174,7 @@ class Model_Tree extends Model_Base { $values = $this->getAll('other'); } - $this->restore(); + $this->where = $tempWhere; return (count($values) > 0) ? $values[0][$this->_tablesArray[0]] : array(); @@ -264,374 +218,50 @@ class Model_Tree extends Model_Base { return $this->db->recordExists($elements['tables'],$field,$value,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join); } - //check referential integrity during delete - public function checkOnDeleteIntegrity($id = null, $whereClause = null) - { - $this->save(); - - $result = true; - - if (count($this->foreignKeys) > 0) - { - foreach ($this->foreignKeys as $f) - { - if (preg_match('/^(.*?)\s(parent of)\s(.*?)\((.*?)\)(\s(on delete)\s(cascade|restrict)\s\((.*?)\))?$/i',$f,$matches)) - { - $parentKey = $matches[1]; - $childModel = $matches[3]; - $childField = $matches[4]; - - if (isset($whereClause)) - { - $this->clear()->sWhere($whereClause); - } - else - { - $this->clear()->where(array($this->_idFields=>(int)$id)); - } - - $keys = sanitizeDbDeep($this->toList($parentKey)->send()); - $this->restore(); - - if (count($keys) > 0) - { - $child = new $childModel(); - $childrenIds = $child->clear()->where(array($childField=>"in('".implode("','",$keys)."')"))->toList($child->getPrimaryKey())->send(); - - if (count($childrenIds) > 0) - { - if (isset($matches[7]) and strcmp($matches[7],"cascade") === 0) - { - foreach ($childrenIds as $childId) - { - $child->del((int)$childId); - } - - if (strcmp($matches[8],"") !== 0) - { - $this->notice .= "
".$matches[8]."
"; - } - } - else - { - $this->notice .= isset($matches[8]) ? "
".$matches[8]."
" : $this->_resultString->getString('associate'); - $result = false; - } - } - } +// //get the number of records of the table $this->_tablesArray[0] +// public function rowNumber() { +// return $this->recordNumber($this->_tablesArray[0]); +// } - } - } - } - - return $result; - } - - //check referential integrity during insert or update - public function checkOnUpdateIntegrity($queryType) - { - $result = true; - - if (count($this->foreignKeys) > 0) - { - foreach ($this->foreignKeys as $f) - { - if (preg_match('/^(.*?)\s(child of)\s(.*?)\((.*?)\)(\s(on update)\s(restrict)\s\((.*?)\))?$/i',$f,$matches)) - { - $childKey = $matches[1]; - $ParentModel = $matches[3]; - $ParentField = $matches[4]; - - $notice = isset($matches[8]) ? "
".$matches[8]."
" : ""; - - if (array_key_exists($childKey,$this->values)) - { - $parent = new $ParentModel(); - $res = $parent->clear()->where(array($ParentField=>sanitizeDb($this->values[$childKey])))->send(); - - if (count($res) === 0) - { - $this->notice .= $notice; - $this->result = false; - $result = false; - } - } - else if ($queryType === "insert") - { - $this->notice .= $notice; - $this->result = false; - $result = false; - } - } - } - } - - return $result; - } - - //get the first extracted full record - public function record() - { - $res = $this->getFields($this->select); - - if (count($res) > 0) - { - return $res[0][$this->_tables]; - } - return array(); - } - - //get a single field from the first extracted record - public function field($fieldName) + //method to call the delete query (overriding of the del method of Model.php) + //check the referential integrity + public function del($id = null, $whereClause = null) { - $res = $this->save()->select($fieldName)->send(); - $this->restore(); + $this->queryResult = false; - if (count($res) > 0 and isset($res[0][$this->_tables][$fieldName])) + if (isset($whereClause)) { - return $res[0][$this->_tables][$fieldName]; + return parent::del(null,$whereClause); } - return ""; - } - - //get the types of the fields in $this->values - public function getTypes($full = false) - { - return $types = $this->db->getTypes($this->_tables,implode(",",array_keys($this->values)),$full); - } - - //automatically set the values conditions - public function setValuesConditionsFromDbFields($queryType) - { - $fields = array_keys($this->values); - $fieldsAsString = implode(",",$fields); - - $types = $this->getTypes(true); - $fieldKeys = $this->db->getKeys($this->_tables,$fieldsAsString,true,false); - - if (count($this->values) > 0) + else { - if (!$types) + if ($this->_onDelete === 'check' and isset($this->_reference)) { - $this->notice .= $this->_resultString->getString('not-existing-fields'); - $this->result = false; - return false; - } - else - { - $this->saveConditions("values"); - $this->saveConditions("database"); - - if (Params::$setValuesConditionsFromDbTableStruct) + if (isset($this->_reference[0]) and isset($this->_reference[1])) { - foreach ($types as $index => $t) - { - if (preg_match('/^('.implode("|",$this->db->getCharTypes()).')\(([0-9]*?)\)$/i',$t,$matches)) - { - $this->addValuesCondition($queryType,'checkLength|'.$matches[2],$fields[$index]); - } - else if (preg_match('/^('.implode("|",$this->db->getIntegerTypes()).')/i',$t,$matches)) - { - $this->addValuesCondition($queryType,'checkInteger',$fields[$index]); - } - else if (preg_match('/^('.implode("|",$this->db->getFloatTypes()).')$/i',$t,$matches)) - { - $this->addValuesCondition($queryType,'checkNumeric',$fields[$index]); - } - else if (preg_match('/^('.implode("|",$this->db->getDateTypes()).')$/i',$t,$matches)) - { - $this->addValuesCondition($queryType,'checkIsoDate',$fields[$index]); - } - else if (preg_match('/^('.implode("|",$this->db->getEnumTypes()).')\((.*?)\)$/i',$t,$matches)) - { - $temp = array(); - $strings = explode(",",$matches[2]); - for ($i=0;$iaddValuesCondition($queryType,'checkIsStrings|'.implode(",",$temp),$fields[$index]); - } - else if (preg_match('/^('.implode("|",$this->db->getDecimalTypes()).')\((.*?)\)$/i',$t,$matches)) - { - $this->addValuesCondition($queryType,'checkDecimal|'.$matches[2],$fields[$index]); - } - } - - //set unique conditions - foreach ($fieldKeys as $index => $fk) + if ($this->db->recordExists($this->_reference[0],$this->_reference[1],(int)$id)) { - if (preg_match('/^('.implode("|",$this->db->getUniqueIndexStrings()).')$/i',$fk,$matches)) - { - if ($queryType === "insert") - { - $this->addDatabaseCondition($queryType,'checkUnique',$fields[$index]); - } - else - { - $this->addDatabaseCondition($queryType,'checkUniqueCompl',$fields[$index]); - } - } + $this->notice = $this->_resultString->getString('associate'); + $this->identifierValue = null; + $this->result = false; } - } - - foreach (Params::$valuesConditionsFromFormatsOfFieldsNames as $regExpr => $function) - { - foreach ($fields as $f) + else { - if (preg_match($regExpr,$f,$matches)) - { - $this->addValuesCondition($queryType,$function,$f); - } + return parent::del((int)$id); } - } - } - } - -// print_r($fields); -// print_r($types); - - return true; - } - - //convert values of the $this->values to MySQL formats - public function convertValuesToDb() - { - if (Params::$automaticConversionToDbFormat) - { - if (isset($this->_conversionToDbObject)) - { - $types = $this->getTypes(); - - if ($types) + else { - $fields = array_keys($this->values); - - foreach ($types as $index => $t) - { - if (method_exists($this->_conversionToDbObject,strtolower($t))) - { - $this->values[$fields[$index]] = call_user_func(array($this->_conversionToDbObject, strtolower($t)), $this->values[$fields[$index]]); - } - } + throw new Exception('you have forgotten to set \'$this->_reference\' or you have forgotten to set $this->_onDelete = \'nocheck\''); } } - } - } - - public function insert() - { - $this->db->setAutocommit(true); - - $this->notice = null; - $this->queryResult = false; - - $this->convertValuesToDb(); - - if ($this->checkOnUpdateIntegrity("insert")) - { - //set the values conditions from the table description - if ($this->setValuesConditionsFromDbFields("insert")) - { - if ($this->applyDatabaseConditions("insert",null)) - { - $this->restoreConditions("database"); - if ($this->applyValidateConditions("insert",'values')) - { - $this->restoreConditions("values"); - return parent::insert(); - } - $this->restoreConditions("values"); - } - $this->restoreConditions("database"); - } - } - - return false; - - } - - public function update($id = null, $whereClause = null) - { - $this->db->setAutocommit(true); - - $this->notice = null; - $this->queryResult = false; - - $this->convertValuesToDb(); - - if ($this->checkOnUpdateIntegrity("update")) - { - //set the values conditions from the table description - if ($this->setValuesConditionsFromDbFields("update")) + else { - if (!isset($id) or $this->applyDatabaseConditions("update",(int)$id)) - { - $this->restoreConditions("database"); - //check the values conditions - if ($this->applyValidateConditions("update",'values')) - { - $this->restoreConditions("values"); - return parent::update($id, $whereClause); - } - $this->restoreConditions("values"); - } - $this->restoreConditions("database"); + return parent::del((int)$id); } } - return false; } - - //method to call the delete query (overriding of the del method of Model.php) - //check the referential integrity - public function del($id = null, $whereClause = null) - { - $this->notice = null; - $this->queryResult = false; - - if ($this->checkOnDeleteIntegrity($id, $whereClause)) - { - return parent::del($id, $whereClause); - } - else - { - return false; - } -// if (isset($whereClause)) -// { -// return parent::del(null,$whereClause); -// } -// else -// { -// if ($this->_onDelete === 'check' and isset($this->_reference)) -// { -// if (isset($this->_reference[0]) and isset($this->_reference[1])) -// { -// if ($this->db->recordExists($this->_reference[0],$this->_reference[1],(int)$id)) -// { -// $this->notice = $this->_resultString->getString('associate'); -// $this->identifierValue = null; -// $this->result = false; -// } -// else -// { -// return parent::del((int)$id); -// } -// } -// else -// { -// throw new Exception('you have forgotten to set \'$this->_reference\' or you have forgotten to set $this->_onDelete = \'nocheck\''); -// } -// } -// else -// { -// return parent::del((int)$id); -// } -// } -// return false; - } //method to obtain one columns from the tables $this->_tablesArray as an associative array //$valueField: the column that have to be extracted (array_values of the resulting associative array), $keyField: the column that have to play the role of array_keys diff --git a/h-source/Library/Params.php b/h-source/Library/Params.php index e22c1bf..e5f5ab7 100644 --- a/h-source/Library/Params.php +++ b/h-source/Library/Params.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -26,24 +26,24 @@ if (!defined('EG')) die('Direct access not allowed!'); class Params { - public static $allowedDb = array('Mysql','Mysqli','None'); //allowed database type + //allowed database type + public static $allowedDb = array('Mysql','Mysqli','None'); - public static $allowedSanitizeFunc = 'sanitizeAll,sanitizeDb,sanitizeHtml,forceInt,forceNat,none,md5,sha1,strip_tags'; //allowed sanitize functions + //allowed sanitize functions + public static $allowedSanitizeFunc = 'sanitizeAll,sanitizeDb,sanitizeHtml,forceInt,forceNat,none,md5,sha1'; - public static $allowedHashFunc = array('md5','sha1'); //allowed hash functions + //allowed hash functions + public static $allowedHashFunc = array('md5','sha1'); //conventional null value for the value of the field in the createWhereClause method of the Model class public static $nullQueryValue = false; //use HTTPS for links or not public static $useHttps = false; - + //class name of the div that contains the error strings public static $errorStringClassName = 'alert'; - //class name of the div that contains the error strings - public static $infoStringClassName = 'executed'; - //table name in the returning structure of the select queries in the case of an aggregate function. Ex count(*),sum(*) public static $aggregateKey = 'aggregate'; @@ -52,59 +52,15 @@ class Params public static $htmlentititiesCharset = DEFAULT_CHARSET; //list of symbols used in the statements of the where clause of the select queries - public static $whereClauseSymbolArray = array('<','>','!=','<=','>=','in(','not in(','like','between'); + public static $whereClauseSymbolArray = array('<','>','!=','<=','>=','in(','not in(','like'); //is the mbstring extension enabled? public static $mbStringLoaded = false; - + //subfolder of the View folder where to look for view files public static $viewSubfolder = null; - //global website language used by the models and by the helpers for reporting + //global website language used by the models and by the helpers public static $language = 'It'; - - //array of languages allowed for the website front-end - public static $frontEndLanguages = array(); - - //default front-end language - public static $defaultFrontEndLanguage = "it"; - - //current front-end language - public static $lang = null; - - //if true, it redirect to current language if language is expected ($frontEndLanguages not empty) but not present - public static $redirectToDefaultLanguage = false; - - //if the URL status variables have to be rewritten or left in the standard query string form - public static $rewriteStatusVariables = true; - - //if the URL has to be rewritten only if an exact match has been found (true) or if a match has been found starting from the beginning (false) - public static $exactUrlMatchRewrite = false; - - //list of installed applications - //the name of the applications has to match a subfolder of tha Apps folder - public static $installed = array(); - - //the application called - public static $currentApplication = null; - - //if true, automatically set the values conditions from the table types - public static $setValuesConditionsFromDbTableStruct = false; - - //if true, automatically convert values to MySQL format during insert and update queries (using types taken from table definition) - public static $automaticConversionToDbFormat = false; - - //if true, convert values from MySQl to $_lang format when filling the form with values coming from the DB - public static $automaticConversionFromDbFormat = false; - - //if true, set the default value for each field when filling the form - //default values are taken from DB where present or from type definition - public static $automaticallySetFormDefaultValues = false; - - //if true, set date("Y-m-d") as default date when setting the default values of the form or of the $this->values array - public static $useCurrentDateAsDefaultDate = true; - - //definition of values conditions from the formats of the fields names - public static $valuesConditionsFromFormatsOfFieldsNames = array(); -} \ No newline at end of file +} diff --git a/h-source/Library/Popup.php b/h-source/Library/Popup.php index d2d51a7..186e4b3 100755 --- a/h-source/Library/Popup.php +++ b/h-source/Library/Popup.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Request.php b/h-source/Library/Request.php index 8ad9226..d99585d 100644 --- a/h-source/Library/Request.php +++ b/h-source/Library/Request.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Scaffold.php b/h-source/Library/Scaffold.php index a418b7c..7e43134 100755 --- a/h-source/Library/Scaffold.php +++ b/h-source/Library/Scaffold.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -32,9 +32,6 @@ class Scaffold protected $_primaryKey = null; //the primary key of the table protected $_controller = null; //the name of the controller - public $application = null; //the name of the application - public $applicationUrl = null; //the url of the application - public $controller = null; //the name of the controller public $model = null; //the reference to the model associated with the controller public $viewArgs = array(); //the associative array representing the status args of the main action of the controller. @@ -57,37 +54,30 @@ class Scaffold //instance of Lang_{language}_Generic public $strings = null; - public static $autoParams = array( - 'mainAction' => 'main', - 'modifyAction' => 'form/update', - 'associateAction' => 'associate', - 'panelController' => 'panel', - 'pageList' => true, - 'pageVariable' => 'page', - 'recordPerPage' => 20, - 'mainMenu' => 'panel,add', - 'formMenu' => 'panel,back', - 'popup' => false, - 'popupType' => 'exclusive' - ); - - public function __construct($type,$application, $controller,$model,$viewArgs,$params = null) { + public function __construct($type,$controller,$model,$viewArgs,$params = null) { $this->_type = $type; - $this->application = $application; - $this->controller = $controller; + $this->_controller = $controller; $this->model = $model; $this->viewArgs = $viewArgs; //get the generic language class $this->strings = Factory_Strings::generic(Params::$language); - $autoParams = self::$autoParams; - - if (!array_key_exists("postSubmitValue",$autoParams)) - { - $autoParams['postSubmitValue'] = $this->strings->gtext('Save'); - } + $autoParams = array( + 'mainAction' => 'main', + 'modifyAction' => 'form/update', + 'associateAction' => 'associate', + 'panelController' => 'panel', + 'pageList' => true, + 'pageVariable' => 'page', + 'recordPerPage' => 10, + 'mainMenu' => 'panel,add', + 'formMenu' => 'panel,back', + 'postSubmitValue' => 'Save', + 'popup' => false, + 'popupType' => 'exclusive' + ); //set the $this->scaffold->params array if (is_array($params)) { @@ -97,7 +87,6 @@ class Scaffold } $this->params = $autoParams; - $this->applicationUrl = isset($application) ? $application . "/" : null; } //ad some clauses to the select query @@ -120,35 +109,11 @@ class Scaffold { $this->_primaryKey = $primaryKey; - if (is_array($recordList) or strcmp($recordList,'') !== 0) + if (strcmp($recordList,'') !== 0) { - $recordListArray = is_array($recordList) ? $recordList : explode(',',$recordList); - + $recordListArray = explode(',',$recordList); foreach ($recordListArray as $record) { - if (preg_match('/\[\[checkbox\]\](\;)(.*?)(\;)/',$record,$matches)) - { - $this->itemList->addItem("checkbox",encode($matches[2]),";".$matches[2].";","",";".$primaryKey.";"); - } - else if (preg_match('/\[\[checkbox\:(.*?)\]\](\;)(.*?)(\;)/',$record,$matches)) - { - $this->itemList->addItem("checkbox",encode($matches[3]),";".$matches[3].";",$matches[1],";".$primaryKey.";"); - } - else if (preg_match('/\[\[input\]\](\;)(.*?)(\;)/',$record,$matches)) - { - $this->itemList->addItem("input",encode($matches[2]),";".$matches[2].";",";".$primaryKey.";"); - } - else if (preg_match('/\[\[ledit\]\](\;)(.*?)(\;)/',$record,$matches)) - { - $this->itemList->addItem("link",$this->applicationUrl . $this->controller.'/'.$this->params['modifyAction']."/;$primaryKey;","",";".$matches[2].";"); - } - else if (strstr($record, ';')) - { - $this->itemList->addItem("simpleText","$record"); - } - else - { - $this->itemList->addItem("simpleText",";$record;"); - } + $this->itemList->addItem("simpleText",";$record;"); } } @@ -158,33 +123,26 @@ class Scaffold { foreach ($themeArray as $el) { - if (preg_match('/ledit\|(.*)/',$el,$matches)) + switch ($el) { - $this->itemList->addItem('ledit',$matches[1],'Edit','Edit'); - } - else - { - switch ($el) - { - case 'moveup': - $this->itemList->addItem('moveupForm',$this->applicationUrl . $this->controller.'/'.$this->params['mainAction'],";".$primaryKey.";"); - break; - case 'movedown': - $this->itemList->addItem('movedownForm',$this->applicationUrl . $this->controller.'/'.$this->params['mainAction'],";".$primaryKey.";"); - break; - case 'link': - $this->itemList->addItem('associateForm',$this->applicationUrl . $this->controller.'/'.$this->params['associateAction'],";".$primaryKey.";"); - break; - case 'edit': - $this->itemList->addItem('editForm',$this->applicationUrl . $this->controller.'/'.$this->params['modifyAction'],";".$primaryKey.";"); - break; - case 'del': - $this->itemList->addItem('delForm',$this->applicationUrl . $this->controller.'/'.$this->params['mainAction'],";".$primaryKey.";"); - break; - case 'ledit': - $this->itemList->addItem('ledit',$this->applicationUrl . $this->controller.'/'.$this->params['modifyAction'].'/;'.$primaryKey.';','Edit','Edit'); - break; - } + case 'moveup': + $this->itemList->addItem('moveupForm',$this->_controller.'/'.$this->params['mainAction'],";".$primaryKey.";"); + break; + case 'movedown': + $this->itemList->addItem('movedownForm',$this->_controller.'/'.$this->params['mainAction'],";".$primaryKey.";"); + break; + case 'link': + $this->itemList->addItem('associateForm',$this->_controller.'/'.$this->params['associateAction'],";".$primaryKey.";"); + break; + case 'edit': + $this->itemList->addItem('editForm',$this->_controller.'/'.$this->params['modifyAction'],";".$primaryKey.";"); + break; + case 'del': + $this->itemList->addItem('delForm',$this->_controller.'/'.$this->params['mainAction'],";".$primaryKey.";"); + break; + case 'ledit': + $this->itemList->addItem('ledit',$this->_controller.'/'.$this->params['mainAction'].'/;'.$primaryKey.';','Edit','Edit'); + break; } } } @@ -199,8 +157,7 @@ class Scaffold $this->queryType = $queryType; $submitName = $this->model->getSubmitName($queryType); $value = $this->params['postSubmitValue']; - $viewStatus = Url::createUrl($this->viewArgs); - + $viewStatus = Url::createUrl(array_values($this->viewArgs)); $this->model->setForm($action.$viewStatus,array($submitName => $value),$method,$enctype); $this->form = $this->model->form; } diff --git a/h-source/Library/Strings/Functions.php b/h-source/Library/Strings/Functions.php index c63d165..1ee17af 100644 --- a/h-source/Library/Strings/Functions.php +++ b/h-source/Library/Strings/Functions.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Theme.php b/h-source/Library/Theme.php index 1ddec92..10c0fce 100755 --- a/h-source/Library/Theme.php +++ b/h-source/Library/Theme.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -34,20 +34,15 @@ class Theme { public $viewArgs = array(); public $viewStatus = ''; public $controller = 'controller'; - public $application = null; public $action = ''; public $currPage; //the URL of the current page - function __construct($application, $controller) { - - $this->controller = $controller; - $this->application = $application; - - $langUrl = isset(Params::$lang) ? "/".Params::$lang : null; + function __construct($controller) { + $protocol = Params::$useHttps ? "https" : "http"; - - $this->baseUrl = MOD_REWRITE_MODULE === true ? "$protocol://" . DOMAIN_NAME . $langUrl : "$protocol://" . DOMAIN_NAME . '/index.php' . $langUrl; - + + $this->controller = $controller; + $this->baseUrl = MOD_REWRITE_MODULE === true ? "$protocol://" . DOMAIN_NAME : "$protocol://" . DOMAIN_NAME . '/index.php'; $this->baseUrlSrc = "$protocol://" . DOMAIN_NAME; } @@ -79,22 +74,15 @@ class Theme { } } + public function render() { extract($this->_data); - + //find the View subfolder where to look for view files $subfolder = isset(Params::$viewSubfolder) ? Params::$viewSubfolder . DS : null; foreach ($this->_viewFiles as $file) { - if (isset($this->application) and file_exists(ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php')) - { - include (ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS . $subfolder. ucwords($this->controller) . DS . $file . '.php'); - } - else if (isset($this->application) and file_exists(ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS . $subfolder. $file . '.php')) - { - include (ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder. $file . '.php'); - } - else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php')) { + if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php')) { include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php'); } else { include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. $file . '.php'); @@ -102,15 +90,7 @@ class Theme { } if (isset($this->_lastView)) { - if (isset($this->application) and file_exists(ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php')) - { - include (ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php'); - } - else if (isset($this->application) and file_exists(ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS . $subfolder . $this->_lastView . '.php')) - { - include (ROOT . DS . APPLICATION_PATH . DS . "Apps" . DS . ucfirst($this->application). DS . 'Views' . DS .$subfolder . $this->_lastView . '.php'); - } - else if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php')) { + if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php')) { include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php'); } else { include (ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. $this->_lastView . '.php'); diff --git a/h-source/Library/Url.php b/h-source/Library/Url.php index 26ff3df..efb8e6e 100755 --- a/h-source/Library/Url.php +++ b/h-source/Library/Url.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -26,35 +26,31 @@ class Url { //get the url starting from the root folder public static function getRoot($pathFromRootFolder = null) { - - $langUrl = isset(Params::$lang) ? "/".Params::$lang : null; - + $protocol = Params::$useHttps ? "https" : "http"; - - $url = MOD_REWRITE_MODULE === true ? "$protocol://" . DOMAIN_NAME . $langUrl . '/' . $pathFromRootFolder : "$protocol://" . DOMAIN_NAME . '/index.php/' . $langUrl . $pathFromRootFolder; + + $url = MOD_REWRITE_MODULE === true ? "$protocol://" . DOMAIN_NAME . '/' . $pathFromRootFolder : "$protocol://" . DOMAIN_NAME . '/index.php/' . $pathFromRootFolder; return $url; } - //create an url string (element1/element2/element4) from the values of the array $valuesArray considering only the elements indicated in the numeric string $numericString - //$forceRewrite: if true it always rewrite the status variables - public static function createUrl($variablesArray, $numericString = null, $forceRewrite = false) { + //create an url string (element1/element2/element4) from the values of the array $valuesArray considering only the elements indicated in the numeric string $numericString (in this case '1,2,4') + public static function createUrl($valuesArray,$numericString = null) { $elementsArray = explode(',',$numericString); - $valuesArray = array_values($variablesArray); - $keysArray = array_keys($variablesArray); + $valuesArray = array_values($valuesArray); $urlString = null; for ($i = 0; $i < count($valuesArray); $i++) { if (isset($numericString)) { if (isset($valuesArray[$i]) and in_array($i,$elementsArray)) { - $urlString .= (Params::$rewriteStatusVariables or $forceRewrite) ? "/".$valuesArray[$i] : "&".$keysArray[$i]."=".$valuesArray[$i]; + $urlString .= "/".$valuesArray[$i]; } } else { if (isset($valuesArray[$i])) { - $urlString .= (Params::$rewriteStatusVariables or $forceRewrite) ? "/".$valuesArray[$i] : "&".$keysArray[$i]."=".$valuesArray[$i]; + $urlString .= "/".$valuesArray[$i]; } } } - return (Params::$rewriteStatusVariables or $forceRewrite) ? $urlString : "?".ltrim($urlString,"&"); + return $urlString; } } diff --git a/h-source/Library/Users/CheckAdmin.php b/h-source/Library/Users/CheckAdmin.php index aa4e33f..54deb2a 100755 --- a/h-source/Library/Users/CheckAdmin.php +++ b/h-source/Library/Users/CheckAdmin.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -60,16 +60,6 @@ class Users_CheckAdmin { $this->uid = isset($_COOKIE[$this->_params['cookie_name']]) ? sanitizeAlnum($_COOKIE[$this->_params['cookie_name']]) : null; } - public function setParam($key, $value) - { - $this->_params[$key] = $value; - } - - public function getUid() - { - return $this->uid; - } - private function cleanSessions() { #cancello le sessioni scadute -- cgit v1.2.3