From 11972639df8315753123ebccdadee1f596807ad0 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Tue, 16 Sep 2014 08:03:29 +0000 Subject: Integrated new EasyGiant Library --- .../Application/Controllers/BaseController.php | 3 +- h-source/Library/Array/Validate/Base.php | 106 +++- h-source/Library/Array/Validate/Soft.php | 91 +--- h-source/Library/Array/Validate/Strong.php | 91 ++-- 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 | 179 ++++++- h-source/Library/Db/Mysqli.php | 265 +++++++++- 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 | 2 +- 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 | 49 +- 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 | 114 ++++- 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 | 243 ++++++++- h-source/Library/Helper/Menu.php | 40 +- h-source/Library/Helper/Pages.php | 15 +- h-source/Library/Helper/Popup.php | 44 +- h-source/Library/Hooks.php | 2 +- h-source/Library/Html/Form.php | 29 +- h-source/Library/Image/Gd/Captcha.php | 2 +- h-source/Library/Image/Gd/Thumbnail.php | 247 ++++++--- 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 | 4 +- 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 | 520 +++++++++++++++++-- h-source/Library/Model/Map.php | 2 +- h-source/Library/Model/Tree.php | 560 +++++++++++++++++---- h-source/Library/Params.php | 71 ++- 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 | 39 +- h-source/Library/Url.php | 23 +- h-source/Library/Users/CheckAdmin.php | 7 +- h-source/tables.sql | 2 + 71 files changed, 2929 insertions(+), 645 deletions(-) create mode 100644 h-source/Library/Array/Validate/Values.php create mode 100644 h-source/Library/Lang/En/Formats/Fields.php create mode 100644 h-source/Library/Lang/En/Formats/From/Mysql.php create mode 100755 h-source/Library/Lang/En/Formats/From/index.html create mode 100644 h-source/Library/Lang/En/Formats/To/Mysql.php create mode 100755 h-source/Library/Lang/En/Formats/To/index.html create mode 100755 h-source/Library/Lang/En/Formats/index.html (limited to 'h-source') diff --git a/h-source/Application/Controllers/BaseController.php b/h-source/Application/Controllers/BaseController.php index 4644fc1..5c5a197 100644 --- a/h-source/Application/Controllers/BaseController.php +++ b/h-source/Application/Controllers/BaseController.php @@ -119,7 +119,7 @@ class BaseController extends Controller //check ft they are updating the website $updating = $this->m['ParamsModel']->select('updating')->where(array('id_par'=>1))->toList('updating')->send(); - + $data['updating_flag'] = 'no'; if (count($updating)>0) { @@ -152,7 +152,6 @@ class BaseController extends Controller } } - //elements of the top menu from the config.xml file //help link $mod = new BoxParser($this->getBox(array("top_menu","help_page_link"))); diff --git a/h-source/Library/Array/Validate/Base.php b/h-source/Library/Array/Validate/Base.php index fb4a66c..f1a242e 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -26,6 +26,7 @@ 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 @@ -44,7 +45,40 @@ 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) { @@ -116,6 +150,13 @@ 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') @@ -123,6 +164,12 @@ 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 @@ -139,7 +186,7 @@ class Array_Validate_Base { if (array_key_exists($keyArray[$i],$associativeArray)) { - if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $strength === 'strong') + if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $this->strength === 'strong') { if (!call_user_func($func,$associativeArray[$keyArray[$i]])) { @@ -217,7 +264,7 @@ class Array_Validate_Base { if (array_key_exists($keyArray[$i],$associativeArray)) { - if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $strength === 'strong') + if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $this->strength === 'strong') { if (!in_array($associativeArray[$keyArray[$i]],$stringsArray)) { @@ -234,25 +281,50 @@ 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++) + $errorString = null; + $keyArray = explode(',',$keyString); + $numb = 0; + for ($i = 0; $i < count($keyArray); $i++) + { + if (array_key_exists($keyArray[$i],$associativeArray)) { - 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 (!preg_match($regExp,$associativeArray[$keyArray[$i]])) { - if (!preg_match($regExp,$associativeArray[$keyArray[$i]])) - { - $numb++; - $errorString .= $this->_resultString->getDoesntMatchResultString($keyArray[$i],$regExp); - } + $numb++; + $errorString .= $this->_resultString->getDoesntMatchResultString($keyArray[$i],$regExp); } } } - $this->errorString = $errorString; - return $numb === 0 ? true : false; + } + $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)) + { + if (strcmp($associativeArray[$keyArray[$i]],'') !== 0 or $this->strength === 'strong') + { + if (!checkDecimal($associativeArray[$keyArray[$i]],$format)) + { + $numb++; + $errorString .= $this->_resultString->getNotDecimalResultString($keyArray[$i],$format); + } + } + } + } + $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 d0c7646..d790652 100644 --- a/h-source/Library/Array/Validate/Soft.php +++ b/h-source/Library/Array/Validate/Soft.php @@ -1,7 +1,24 @@ . if (!defined('EG')) die('Direct access not allowed!'); @@ -9,77 +26,11 @@ if (!defined('EG')) die('Direct access not allowed!'); class Array_Validate_Soft extends Array_Validate_Base { - public function __construct($lang = 'Eng') + public function __construct($lang = 'En') { parent::__construct($lang); - } - - - //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,$strength = 'soft') - { - 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,$strength = 'soft') - { - 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,$strength = 'soft') - { - 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,$strength = 'soft') - { - 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,$strength = 'soft') - { - 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 = '',$strength = 'soft') - { - 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 = '/./',$strength = 'soft') - { - return parent::checkMatch($associativeArray,$keyString,$regExp,'soft'); + + $this->strength = "soft"; } } diff --git a/h-source/Library/Array/Validate/Strong.php b/h-source/Library/Array/Validate/Strong.php index d105319..d907d1d 100644 --- a/h-source/Library/Array/Validate/Strong.php +++ b/h-source/Library/Array/Validate/Strong.php @@ -1,46 +1,38 @@ . if (!defined('EG')) die('Direct access not allowed!'); -//class to manage arrays +//class to validate associative arrays class Array_Validate_Strong extends Array_Validate_Base { - public function __construct($lang = 'Eng') + public function __construct($lang = 'En') { 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) { @@ -110,6 +102,19 @@ 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') { @@ -123,6 +128,18 @@ 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) @@ -177,4 +194,18 @@ 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; + } + } } diff --git a/h-source/Library/Array/Validate/Values.php b/h-source/Library/Array/Validate/Values.php new file mode 100644 index 0000000..9355949 --- /dev/null +++ b/h-source/Library/Array/Validate/Values.php @@ -0,0 +1,36 @@ +. + +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 2b02c9e..d4300b4 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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)) { + if (array_key_exists($temp[0],$associativeArray) and !is_array($associativeArray[$temp[0]])) { $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 5d7a12f..aa32041 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 0e7e03f..302439a 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 c75508b..7f80841 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -35,19 +35,40 @@ function sanitizeSuperGlobal() $_SERVER = stripslashesDeep($_SERVER); } - - -function checkPostLength() +function checkPostLength($checkArray = null) { + $a = isset($checkArray) ? $checkArray : $_POST; + if (MAX_POST_LENGTH !== 0) { - foreach ($_POST as $key => $value) + foreach ($a as $key => $value) { - if (strlen($value) > MAX_POST_LENGTH) die('the length of some of the $_POST values is too large'); + 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'); + } } } } +//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) @@ -61,20 +82,108 @@ function checkRegisterGlobals() if (ini_get('register_globals')) die('register globals is on: easyGiant works only with register globals off'); } -function callHook() +//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) { - $url = isset($_GET['url']) ? $_GET['url'] : DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION; + 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; + } } else { - $url = (strcmp(getQueryString(),"") !== 0) ? getQueryString() : DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION; + if (strcmp(getQueryString(),"") !== 0) + { + if (!languageInUrl(getQueryString())) + { + $url = getQueryString(); + } + else + { + $url = languageInUrl(getQueryString()) . DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION; + } + } + else + { + $url = 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') { @@ -85,12 +194,19 @@ 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; @@ -108,10 +224,30 @@ function callHook() $errorAction = ERROR_ACTION !== false ? ERROR_ACTION : DEFAULT_ACTION; /* - VERIFY THE ACTION NAME + 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(); @@ -122,6 +258,7 @@ function callHook() */ if (!ctype_alnum($controller) or (strcmp($controller,'') === 0)) { + Params::$currentApplication = null; $controller = $errorController; $action = $errorAction; $urlArray = array(); @@ -129,8 +266,10 @@ 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')) + // 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')) { + Params::$currentApplication = null; $controller = $errorController; $action = $errorAction; $urlArray = array(); @@ -139,6 +278,7 @@ 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(); @@ -147,40 +287,28 @@ 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 - $application = $controller; + $controllerName = $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,$application,$queryString); + $dispatch = new $controller($model,$controllerName,$queryString, getApplicationName()); //pass the action to the controller object $dispatch->action = $action; @@ -196,7 +324,7 @@ function callHook() $templateFlag= true; - if (method_exists($controller, $action)) + if (method_exists($dispatch, $action)) { //pass the action to the theme object $dispatch->theme->action = $action; @@ -235,7 +363,10 @@ function rewrite($url) $oldKey = $key; $key = str_replace('\/','/',$key); $key = str_replace('/','\/',$key); - if (preg_match('/^'.$key.'/',$url)) + + $regExpr = Params::$exactUrlMatchRewrite ? '/^'.$key.'$/' : '/^'.$key.'/'; + + if (preg_match($regExpr,$url)) { $nurl = preg_replace('/^'.$key.'/',$address,$url); return array($nurl,$oldKey); @@ -272,10 +403,18 @@ 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'); @@ -284,6 +423,10 @@ 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'); @@ -293,6 +436,9 @@ 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 b0eef53..bc1c229 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -31,6 +31,8 @@ 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 @@ -57,17 +59,21 @@ class Controller { protected $scaffold = null; //the reference to the scaffold object - function __construct($model, $controller, $queryString = array()) { + function __construct($model, $controller, $queryString = array(), $application = null) + { + $this->application = $application; $this->controller = $controller; $this->modelName = $model; $this->_queryString = $queryString; - $this->theme = new Theme($controller); + $this->theme = new Theme($application, $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 @@ -136,8 +142,8 @@ class Controller { { if (class_exists($controller)) { $model = str_replace('Controller',null,$controller).'Model'; - $application = strtolower(str_replace('Controller',null,$controller)); - $this->c[$controller] = new $controller($model,$application,array()); + $application = $this->controller; + $this->c[$controller] = new $controller($model,$application,$this->_queryString); $this->c[$controller]->theme = $this->theme; } } @@ -234,7 +240,7 @@ class Controller { } $this->viewArgs[$this->argKeys[$i]] = $this->_queryString[$i]; } - $this->viewStatus = Url::createUrl(array_values($this->viewArgs)); + $this->viewStatus = Url::createUrl($this->viewArgs); $this->updateHelpers(); //update the theme @@ -282,7 +288,7 @@ class Controller { //create the viewStatus property final public function buildStatus() { - $this->viewStatus = Url::createUrl(array_values($this->viewArgs)); + $this->viewStatus = Url::createUrl($this->viewArgs); //update the theme $this->theme->viewStatus = $this->viewStatus; $this->theme->viewArgs = $this->viewArgs; @@ -295,9 +301,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->controller,$this->m[$this->modelName],$this->viewArgs,$params); + $this->scaffold = new Scaffold($type,$this->application,$this->controller,$this->m[$this->modelName],$this->viewArgs,$params); - $this->helper('Menu',$this->controller,$this->scaffold->params['panelController']); + $this->helper('Menu',$this->applicationUrl.$this->controller,$this->scaffold->params['panelController']); $this->scaffold->mainMenu = $this->h['Menu']; $this->m[$this->modelName]->popupBuild(); @@ -305,7 +311,8 @@ class Controller { if ($type === 'main') { - $here = $this->controller.'/'.$this->scaffold->params['mainAction']; + $here = $this->applicationUrl.$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 d19d24a..e0dcfe0 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -24,16 +24,34 @@ if (!defined('EG')) die('Direct access not allowed!'); //class to manage the database //singleton! -class Db_Mysql { +class Db_Mysql +{ + + 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 $dblink; - private $fieldsType = array('tinyint','smallint','int','mediumint','bigint','float','double'); + + 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(); /** *connect to the database @@ -51,7 +69,8 @@ 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) { @@ -78,7 +97,46 @@ 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() { @@ -163,16 +221,29 @@ class Db_Mysql { public function get_num_rows($table,$where=null,$group_by=null,$on=array(),$using=array(),$join=array()) { - $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using,$join); + $select = isset($group_by) ? "*" : 'count(*) as number'; + + $query = $this->createSelectQuery($table,$select,$where,$group_by,null,null,$on,$using,$join); $this->query=$query; + $this->queries[] = $query; $ris = mysql_query($query); if ($ris) { - $num_rows = mysql_num_rows($ris); - return $num_rows; + + if (isset($group_by)) + { + $num_rows = mysql_num_rows($ris); + } + else + { + $row = mysql_fetch_array($ris); + $num_rows = $row['number']; + } + + return (int)$num_rows; } else { - return false; + return 0; } } @@ -182,6 +253,8 @@ 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) { @@ -223,6 +296,8 @@ 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); } @@ -259,32 +334,73 @@ class Db_Mysql { } else { - return false; + return array(); } } - //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) - public function getTypes($table, $fields) + + private function getFieldsFeature($feature, $table, $fields, $full = false, $associative = false) { $query = "DESCRIBE $table;"; $result = mysql_query($query); $temp = array(); while ($row = mysql_fetch_assoc($result)) { - $e = explode('(',$row['Type']); - $temp[$row['Field']] = reset($e); + if ($full) + { + $temp[$row['Field']] = $row[$feature]; + } + else + { + $e = explode('(',$row[$feature]); + $temp[$row['Field']] = strcmp($feature,"Type") === 0 ? strtolower(reset($e)) : reset($e); + } } + $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; - $types[] = $temp[$fields[$i]]; + + if ($associative) + { + $types[$fields[$i]] = $temp[$fields[$i]]; + } + else + { + $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 @@ -312,6 +428,8 @@ 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 @@ -320,12 +438,34 @@ 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() { @@ -367,6 +507,8 @@ 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 @@ -375,6 +517,7 @@ class Db_Mysql { } else { return false; } + } else { return false; } @@ -390,6 +533,8 @@ class Db_Mysql { // } $query="DELETE FROM $table $where;"; $this->query=$query; + $this->queries[] = $query; + $ris = mysql_query($query); #check the result @@ -423,6 +568,8 @@ 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 b65f470..bd3ce1c 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -27,14 +27,31 @@ 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 $fieldsType = array('tinyint','smallint','int','mediumint','bigint','float','double'); + + 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(); //PHP-Mysql charset translation table private $charsetTranslationTable = array( @@ -53,7 +70,8 @@ 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()) @@ -85,7 +103,46 @@ 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() { @@ -170,16 +227,30 @@ class Db_Mysqli public function get_num_rows($table,$where=null,$group_by=null,$on=array(),$using=array(),$join=array()) { - $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using,$join); + $select = isset($group_by) ? "*" : 'count(*) as number'; + + $query = $this->createSelectQuery($table,$select,$where,$group_by,null,null,$on,$using,$join); $this->query = $query; + $this->queries[] = $query; + $ris = $this->db->query($query); if ($ris) { - $num_rows = $ris->num_rows; + + if (isset($group_by)) + { + $num_rows = $ris->num_rows; + } + else + { + $row = $ris->fetch_array(); + $num_rows = $row['number']; + } + $ris->close(); - return $num_rows; + return (int)$num_rows; } else { - return false; + return 0; } } @@ -188,6 +259,8 @@ 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) { @@ -230,6 +303,8 @@ 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); } @@ -262,45 +337,85 @@ class Db_Mysqli $result->close(); return $data; } else { - return false; + return array(); } } - //return an array containing all the types of the fields (indicated in $fields) of a table (indicated in $table) - public function getTypes($table, $fields) + private function getFieldsFeature($feature, $table, $fields, $full = false, $associative = false ) { $query = "DESCRIBE $table;"; $result = $this->db->query($query); $temp = array(); while ($row = $result->fetch_assoc()) { - $e = explode('(',$row['Type']); - $temp[$row['Field']] = reset($e); + if ($full) + { + $temp[$row['Field']] = $row[$feature]; + } + else + { + $e = explode('(',$row[$feature]); + $temp[$row['Field']] = strcmp($feature,"Type") === 0 ? strtolower(reset($e)) : reset($e); + } } $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; - $types[] = $temp[$fields[$i]]; + + if ($associative) + { + $types[$fields[$i]] = $temp[$fields[$i]]; + } + else + { + $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)) @@ -316,21 +431,103 @@ class Db_Mysqli $values = implode(',',$values); $query="INSERT INTO $table ($fields) VALUES ($values);"; $this->query=$query; + $this->queries[] = $query; - $ris = $this->db->query($query); + if ($this->autocommit) + { + $ris = $this->db->query($query); - #check the result - if ($ris) { + #check the result + if ($ris) { + return true; + } else { + return false; + } + } + else + { + $this->transactionBatch[] = $query; 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() { @@ -372,13 +569,23 @@ class Db_Mysqli $str=implode(',',$str); $query="UPDATE $table SET $str $where;"; $this->query=$query; - $ris = $this->db->query($query); + $this->queries[] = $query; + + if ($this->autocommit) + { + $ris = $this->db->query($query); - #check the result - if ($ris) { + #check the result + if ($ris) { + return true; + } else { + return false; + } + } + else + { + $this->transactionBatch[] = $query; return true; - } else { - return false; } } else { return false; @@ -395,6 +602,8 @@ class Db_Mysqli // } $query="DELETE FROM $table $where;"; $this->query=$query; + $this->queries[] = $query; + $ris = $this->db->query($query); #check the result @@ -429,6 +638,8 @@ 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 9d2ff19..369af20 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 2cb8aed..ab66091 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 32a82c1..17afa1a 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 3e766bd..8917590 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 7eda7b7..a060ba3 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 00a0afe..19b5fd1 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant diff --git a/h-source/Library/Form/Checkbox.php b/h-source/Library/Form/Checkbox.php index 497c097..91191a9 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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); + $returnString .= Html_Form::checkbox($this->entryName, $value, $this->options, $this->className,$this->idName,$this->attributes); $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 6f45557..fa3b84f 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -33,6 +33,7 @@ abstract class Form_Entry { public $labelClass = null; //the class of the tag of the label public $options = array(); //options (if the entry is a "; + } + } + $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; @@ -353,16 +482,32 @@ class Helper_List extends Helper_Html { $this->_recordNumber = count($queryResult); $htmlList = null; //create the HTML of the head of the record list - $htmlList .= $this->wrapRow($this->createHead(),'listHead'); + $htmlList .= "\n".$this->wrapRow($this->createHead(),'listHead')."\n"; //create the HTML of the filters - $htmlList .= $this->wrapRow($this->createFilters(),'listFilters'); + $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'); + } + } + for ($i = 0; $i < count($queryResult); $i++) { $this->ifInBoundaries($i); $temp = $this->getRowList($queryResult[$i]); $htmlList .= $this->wrapRow($temp,'listRow'); } - return $this->wrapList($htmlList); + return $this->wrapList($htmlList."\n"); } public function generalForm($itemArray, $submitName, $submitValue) @@ -459,8 +604,20 @@ 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) + public function filterForm($viewArgsName, $filterString = null, $filterValues = null) { $cleanName = str_replace('n!',null,$viewArgsName); $cleanName = str_replace('-',null,$cleanName); @@ -475,8 +632,11 @@ class Helper_List extends Helper_Html { if (Params::$nullQueryValue) { $this->viewArgs[$viewArgsName] = Params::$nullQueryValue; - $viewStatus = Url::createUrl(array_values($this->viewArgs)); - if (strcmp($value,Params::$nullQueryValue) === 0) $value = ''; + $viewStatus = Url::createUrl($this->viewArgs); + if (strcmp($value,Params::$nullQueryValue) === 0 and !isset($filterValues)) + { + $value = ''; + } } else { @@ -489,11 +649,42 @@ class Helper_List extends Helper_Html { $title = $this->strings->gtext('filter'); $clearLinkTitle = $this->strings->gtext('clear the filter'); - $html = "
\n"; - $html .= ""; - $html .= ""; - $html .= "\n"; - $html .= "
\n"; + $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"; + } return $html; } diff --git a/h-source/Library/Helper/Menu.php b/h-source/Library/Helper/Menu.php index 8fd4bf4..4b33261 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,7 +25,8 @@ 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; @@ -49,6 +50,7 @@ class Helper_Menu extends Helper_Html 'text' => $this->strings->gtext('Back'), 'url' => 'main', 'icon' => $baseUrl."left.png", + 'queryString' => null, ), 'add' => array( @@ -57,6 +59,7 @@ class Helper_Menu extends Helper_Html 'text' => $this->strings->gtext('Add'), 'url' => 'form/insert', 'icon' => $baseUrl."add.png", + 'queryString' => null, ), 'panel' => array( @@ -65,9 +68,25 @@ 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) @@ -89,8 +108,11 @@ 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) @@ -98,8 +120,18 @@ 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']; - $menu .= "
$icon $text
\n"; + $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"; } } } diff --git a/h-source/Library/Helper/Pages.php b/h-source/Library/Helper/Pages.php index d8ac856..3826469 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -109,9 +109,16 @@ class Helper_Pages extends Helper_Html public function html($pageNumber,$string = null) { if (isset($string)) { $strNumber = $string; - $strClass = "class='itemListPage'"; + if (strcmp($pageNumber,"1") === 0) + { + $strClass = "class='itemListPage previous_page'"; + } + else + { + $strClass = "class='itemListPage next_page'"; + } } else { - if ($pageNumber === $this->_currentPage) + if (strcmp($pageNumber,$this->_currentPage) === 0) { $strNumber = $pageNumber; $strClass = "class='currentPage'"; @@ -123,7 +130,7 @@ class Helper_Pages extends Helper_Html } } $this->viewArgs[$this->_variableArg] = $pageNumber; - $viewStatus = Url::createUrl(array_values($this->viewArgs)); + $viewStatus = Url::createUrl($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 4f67a5c..f3e6058 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,6 +25,15 @@ 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 @@ -85,9 +94,17 @@ 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 = null; + $returnString = self::$popupHtml["before_loop"]; if ($this->checkViewArgs()) { if (isset($this->viewArgs[$this->pageArg])) @@ -104,11 +121,12 @@ class Helper_Popup extends Helper_Html { $tempArg = $this->viewArgs[$field]; $this->legend[$field] = $tempArg; - $returnString .= "\n"; + $returnString .= self::$popupHtml["middle"]; $this->viewArgs[$field] = $tempArg; - } - if ($this->printLegend) - { - $returnString .= "\n"; - } - if (count($this->popupArray)>0) { - $returnString .= "\n"; + + $returnString .= self::$popupHtml["bottom"]; } } + $returnString .= self::$popupHtml["after_loop"]; return $returnString; } diff --git a/h-source/Library/Hooks.php b/h-source/Library/Hooks.php index b16b6d5..de46da8 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 64c501f..91b2aa0 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -70,10 +70,10 @@ class Html_Form { $a = $optionValue; } - if (strcmp($b,'optgroupOpen') === 0) + if (strcmp($optionValue,'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 .= "\n"; + $returnString .= ""; return $returnString; } @@ -97,7 +97,7 @@ class Html_Form { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - $returnString ="\n"; + $returnString =""; return $returnString; } @@ -110,7 +110,7 @@ class Html_Form { $strClass = isset($className) ? "class='".$className."'" : null; $idStr = isset($idName) ? "id='".$idName."'" : null; - $returnString ="\n"; + $returnString =""; return $returnString; } @@ -126,7 +126,7 @@ class Html_Form { $idStr = isset($idName) ? "id='".$idName."'" : null; $str = (strcmp($value,$option) === 0) ? "checked = 'checked'" : null; - return "\n"; + return ""; } //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 "\n"; + return ""; } //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 "\n"; + return ""; } //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 "\n"; + return ""; } //return the HTML of a radio button @@ -202,7 +202,7 @@ class Html_Form { } $str= (strcmp($value,$optionValue) === 0) ? "checked='checked'" : null; - $returnString .= "$before$after\n"; + $returnString .= "$before$after"; } return $returnString; @@ -222,12 +222,13 @@ class Html_Form { if (isset($image)) { - $returnString = "\n"; - $returnString .= "\n"; + $returnString = ""; + $returnString .= ""; } else { - $returnString ="\n"; + $returnString = ''; + $returnString .= ""; } return $returnString; diff --git a/h-source/Library/Image/Gd/Captcha.php b/h-source/Library/Image/Gd/Captcha.php index 1e8d706..d4285c2 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 1fd7796..bb69891 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -47,9 +47,10 @@ class Image_Gd_Thumbnail 'resample' => 'yes', 'function' => 'none', 'outputFormat' => 'jpeg', + 'backgroundColor' => null, //must be hex color ); - //set the $this->scaffold->params array + //set the $this->params array if (is_array($params)) { foreach ($params as $key => $value) @@ -60,6 +61,46 @@ 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 @@ -112,92 +153,172 @@ class Image_Gd_Thumbnail $scale = max($this->params['imgWidth']/$width, $this->params['imgHeight']/$height); } - if ($scale < 1) { - - $xSrc = 0; - $ySrc = 0; - - if ($this->params['cropImage'] === 'no') + $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) { - $newWidth = floor($scale*$width); - $newHeight = floor($scale*$height); + $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 if ($this->params['cropImage'] === 'yes') + else { - - $newWidth = $this->params['imgWidth']; - $newHeight = $this->params['imgHeight']; + $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 ($this->params['cropImage'] === 'yes') + { + if ($scale < 1) + { + $newWidth = $backWidth = $this->params['imgWidth']; + $newHeight = $backHeight = $this->params['imgHeight']; $oldWidth = $width; $oldHeight = $height; $width = floor($newWidth/$scale); $height = floor($newHeight/$scale); - switch ($this->params['horizAlign']) + $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']) { - 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']; + $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); + } + } - - switch ($this->params['vertAlign']) + else if ($width <= $this->params['imgWidth']) { - 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']; + $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); + } + + } + else if ($height <= $this->params['imgHeight']) + { + $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); + } + } - } + } - //temp image - $tmpImg = imagecreatetruecolor($newWidth, $newHeight); - - if(strcmp($type,'png') === 0 or strcmp($type,'gif') === 0){ - imagealphablending($tmpImg, false); - imagesavealpha($tmpImg, true); - } - - if ($this->params['resample'] === 'yes') + //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) { - //copy and resample - imagecopyresampled($tmpImg, $img, 0, 0, $xSrc, $ySrc,$newWidth, $newHeight, $width, $height); + $rgbColor = hex2rgb($this->params['backgroundColor']); + + $backgroundC = imagecolorallocate($tmpImg,$rgbColor[0],$rgbColor[1],$rgbColor[2]); } else { - //copy and resize - imagecopyresized($tmpImg, $img, 0, 0, $xSrc, $ySrc,$newWidth, $newHeight, $width, $height); + $backgroundC = imagecolortransparent($tmpImg); } - imagedestroy($img); - $img = $tmpImg; - - if (!function_exists($this->params['function'])) { - throw new Exception('Error in '.__METHOD__.': function '.$this->params['function']. ' does not exist'); + + imagefill($tmpImg, 0, 0, $backgroundC); + } + + if(strcmp($type,'png') === 0 or strcmp($type,'gif') === 0){ + + if ($this->params['backgroundColor']) + { + imagealphablending($tmpImg, true); + } + else + { + imagealphablending($tmpImg, false); } + + imagesavealpha($tmpImg, true); + } - $img = call_user_func($this->params['function'],$img); + if ($this->params['resample'] === 'yes') + { + //copy and resample + imagecopyresampled($tmpImg, $img, $xDst, $yDst, $xSrc, $ySrc,$newWidth, $newHeight, $width, $height); } else { - if(strcmp($type,'png') === 0 or strcmp($type,'gif') === 0){ - imagealphablending($img, false); - imagesavealpha($img, true); - } + //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'); + } + + $img = call_user_func($this->params['function'],$img); } if (!$img) diff --git a/h-source/Library/Lang/En/DbCondStrings.php b/h-source/Library/Lang/En/DbCondStrings.php index bfc5867..0c72d95 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 { +class Lang_En_DbCondStrings extends Lang_En_ValCondStrings { //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 ". $field ." is already present. Please choose a different value.
\n"; + return "
The value of ". getFieldLabel($field) ." is already present. Please choose a different value.
\n".$this->getHiddenAlertElement($field); } } diff --git a/h-source/Library/Lang/En/Formats/Fields.php b/h-source/Library/Lang/En/Formats/Fields.php new file mode 100644 index 0000000..c91a1f0 --- /dev/null +++ b/h-source/Library/Lang/En/Formats/Fields.php @@ -0,0 +1,46 @@ +. + +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 new file mode 100644 index 0000000..5e4ea07 --- /dev/null +++ b/h-source/Library/Lang/En/Formats/From/Mysql.php @@ -0,0 +1,64 @@ +. + +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 new file mode 100755 index 0000000..8d1c8b6 --- /dev/null +++ b/h-source/Library/Lang/En/Formats/From/index.html @@ -0,0 +1 @@ + diff --git a/h-source/Library/Lang/En/Formats/To/Mysql.php b/h-source/Library/Lang/En/Formats/To/Mysql.php new file mode 100644 index 0000000..31daab8 --- /dev/null +++ b/h-source/Library/Lang/En/Formats/To/Mysql.php @@ -0,0 +1,62 @@ +. + +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 new file mode 100755 index 0000000..8d1c8b6 --- /dev/null +++ b/h-source/Library/Lang/En/Formats/To/index.html @@ -0,0 +1 @@ + diff --git a/h-source/Library/Lang/En/Formats/index.html b/h-source/Library/Lang/En/Formats/index.html new file mode 100755 index 0000000..8d1c8b6 --- /dev/null +++ b/h-source/Library/Lang/En/Formats/index.html @@ -0,0 +1 @@ + diff --git a/h-source/Library/Lang/En/Generic.php b/h-source/Library/Lang/En/Generic.php index c940949..8df27a9 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -50,6 +50,8 @@ class Lang_En_Generic '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 cf26b8f..266b1d2 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -24,13 +24,19 @@ if (!defined('EG')) die('Direct access not allowed!'); class Lang_En_ModelStrings extends Lang_ResultStrings { - 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
" - ); + 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", + ); + + } } diff --git a/h-source/Library/Lang/En/UploadStrings.php b/h-source/Library/Lang/En/UploadStrings.php index 61bc0c5..572f7bb 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 7f4e7ea..8742c23 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -24,70 +24,106 @@ 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 "
". $element ." not defined!
\n"; + return "
Please fill the field ". getFieldLabel($element) .".
\n".$this->getHiddenAlertElement($element); } //if the elements are not equal public function getNotEqualResultString($element) { - return "
Different values: $element
\n"; + return "
Please check that the fields ".getFieldLabel($element)." are equal
\n".$this->getHiddenAlertElement($element); } //if the element is not alphabetic public function getNotAlphabeticResultString($element) { - return "
".$element." has to be alphabetic
\n"; + return "
Please check that the field ".getFieldLabel($element)." is alphabetic
\n".$this->getHiddenAlertElement($element); } //if the element is not alphanumeric public function getNotAlphanumericResultString($element) { - return "
".$element." has to be alphanumeric
\n"; + return "
Please check that the field ".getFieldLabel($element)." has to be alphanumeric
\n".$this->getHiddenAlertElement($element); } //if the element is not a decimal digit public function getNotDecimalDigitResultString($element) { - return "
".$element." has to be a decimal digit
\n"; + return "
Please check that the field ".getFieldLabel($element)." is a decimal digit
\n".$this->getHiddenAlertElement($element); } - - //if the element has the mail format + + //if the element hasn't the mail format public function getNotMailFormatResultString($element) { - return "
".$element." doesn't seem an e-mail address
\n"; + return "
Please check that the field ".getFieldLabel($element)." is an e-mail address
\n".$this->getHiddenAlertElement($element); } - //if the element is numeric + //if the element is not numeric public function getNotNumericResultString($element) { - return "
".$element." has to be a numeric
\n"; + 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); } //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 "
Please check that the field ".getFieldLabel($element)." does not exceed the value of $maxLength characters
\n".$this->getHiddenAlertElement($element); } //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 "
Please check that the field ".getFieldLabel($element)." is not one of the following strings: $stringList
\n".$this->getHiddenAlertElement($element); } //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 "
Please check that the field ".getFieldLabel($element)." is one of the following strings: $stringList
\n".$this->getHiddenAlertElement($element); } - //if the element is not one of the strings indicated by $stringList (a comma-separated list of strings) + //if the element does not match the reg expr indicated by $regExp public function getDoesntMatchResultString($element,$regExp) { - return "
".$element." has to match the following regular expression: $regExp
\n"; + 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); } } diff --git a/h-source/Library/Lang/Eng/DbCondStrings.php b/h-source/Library/Lang/Eng/DbCondStrings.php index e4196b6..cd625af 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 bb0ab99..29947fd 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -33,6 +33,25 @@ 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 fa741a2..20b8173 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -30,7 +30,8 @@ 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
" + "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", ); } diff --git a/h-source/Library/Lang/Eng/UploadStrings.php b/h-source/Library/Lang/Eng/UploadStrings.php index 2ae4c9b..ca0332b 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 42e70d8..f5d40a2 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -27,67 +27,89 @@ 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 has the mail format + //if the element hasn't 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 numeric + //if the element is not numeric public function getNotNumericResultString($element) { - return "
".$element." has to be a numeric
\n"; + 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"; } //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 is not one of the strings indicated by $stringList (a comma-separated list of strings) + //if the element does not match the reg expr indicated by $regExp public function getDoesntMatchResultString($element,$regExp) { - return "
".$element." has to match the following regular expression: $regExp
\n"; + 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"; } } diff --git a/h-source/Library/Lang/ResultStrings.php b/h-source/Library/Lang/ResultStrings.php index 2181b90..6f84090 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 f576c10..de4f68f 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 index cdd1843..67bd91c 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,10 +25,12 @@ 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 = null; //the form structure + public $formStruct = array("entries" => array()); //the form structure public $submitName = null; //the current submitName (from the form) public $identifierName = 'identifier'; @@ -37,15 +39,18 @@ 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 have to be satisfied before applying the query - //Ex: 'update'=>'checkEmpty:titolo,autore','submitName'=>'conditions' + //conditions that the $_POST array has to satisfy (strong) 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 + //conditions that the $_POST array has to satisfy (soft) 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' @@ -57,13 +62,17 @@ 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 @@ -104,6 +113,9 @@ abstract class Model_Base 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 @@ -121,6 +133,7 @@ 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 @@ -138,6 +151,7 @@ abstract class Model_Base //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]; @@ -157,6 +171,24 @@ 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); @@ -173,12 +205,22 @@ abstract class Model_Base } //sanitize all the $values property - public function sanitize() + public function sanitize($function = "sanitizeDb") { + 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,'sanitizeDb'); + $this->values = $this->arrayExt->subset($this->values,$keys,$function); } + //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) { @@ -326,7 +368,129 @@ 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 = $this->arrayExt->subset($recordArray,$this->fields,$funcDb); $values[$idName] = $ident; @@ -408,8 +569,16 @@ 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); - $tempArray = is_array($defaultValues) ? $defaultValues : array(); + if (is_array($defaultValues)) + { + foreach ($defaultValues as $field => $value) + { + $tempArray[$field] = $value; + } + } $values = $this->arrayExt->subset($tempArray,$this->fields,$funcPost); @@ -528,6 +697,8 @@ 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.'); @@ -535,50 +706,70 @@ abstract class Model_Base $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 (count($this->values) > 0) { - if (isset($id)) + if (isset($whereClause)) { - $where = $this->_idFieldsArray[0].'='.(int)($id); - $result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$where); + $result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$whereClause); $this->setNotice($result); return $result; } else { - $this->notice = $this->_resultString->getString('no-id'); - $this->result = false; - $this->identifierValue = null; - return false; + 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; + } } } + 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 (isset($this->_idOrder)) + if (count($this->values) > 0) { - $maxValue = $this->db->getMax($this->_tablesArray[0],$this->_idOrder); - $this->supplInsertValues[$this->_idOrder] = (int)$maxValue + 1; - } - - $el = $this->setSupplValues('insert'); + 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; + $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; + } } //method to call the delete query (overriding of the base_db del method) @@ -600,7 +791,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; @@ -627,6 +818,8 @@ abstract class Model_Base //where clause public function move($id,$par = 'up') { + $this->notice = null; + $this->queryResult = false; if (isset($id)) { @@ -662,7 +855,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; @@ -672,11 +865,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; } @@ -797,40 +990,108 @@ abstract class Model_Base } } + //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 strongCondition array + //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' or 'soft' + //$strength: strong,soft,values 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)) @@ -856,7 +1117,7 @@ abstract class Model_Base $values = $temp[0]; } - $baseArgs = array($_POST,$values); + $baseArgs = array($arrayToCheck,$values); if (strstr($key,'|')) { @@ -889,7 +1150,6 @@ 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 @@ -1046,6 +1306,13 @@ 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) { @@ -1104,6 +1371,12 @@ 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) { @@ -1138,6 +1411,7 @@ abstract class Model_Base { $this->select = null; $this->where = array(); + $this->sWhere = null; $this->groupBy = null; $this->orderBy = null; $this->limit = null; @@ -1146,9 +1420,84 @@ 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) { @@ -1162,6 +1511,67 @@ 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 7a093e1..e6d9f6b 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 f7f95ea..849fd7d 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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; - } - } - - //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 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 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,32 +84,51 @@ 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)) +// $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)) { - $on = array(); - - if (isset($where) and isset($wherePlus)) + if (isset($this->sWhere)) { - $where .= ' AND ' . $wherePlus; - } - else if (!isset($where) and isset($wherePlus)) - { - $where .= $wherePlus; + $where .= " AND " . $this->sWhere; } } else { - $on = $where; - $where = $wherePlus; + $where = $this->sWhere; } + + $tables = isset($this->from) ? $this->from : $tableName; + + $fields = $tableName.".*"; + $on = $this->on; return array('tables' => $tables,'where' => $where,'fields'=>$fields,'on'=>$on); } @@ -127,10 +146,37 @@ 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; - return $row = $this->db->select($elements['tables'],$queryFields,$elements['where'],$this->groupBy,$this->orderBy,$this->limit,$elements['on'],$this->using,$this->join); + $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]); + } + + } + } + } + + return $row; } public function send() @@ -160,8 +206,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) { - $tempWhere = $this->where; - $this->setWhereQueryClause(array($this->_idFieldsArray[0] => (int)$id)); + + $this->save()->clear()->setWhereQueryClause(array($this->_idFieldsArray[0] => (int)$id)); $this->using = null; @@ -174,7 +220,7 @@ class Model_Tree extends Model_Base { $values = $this->getAll('other'); } - $this->where = $tempWhere; + $this->restore(); return (count($values) > 0) ? $values[0][$this->_tablesArray[0]] : array(); @@ -218,49 +264,373 @@ class Model_Tree extends Model_Base { return $this->db->recordExists($elements['tables'],$field,$value,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join); } -// //get the number of records of the table $this->_tablesArray[0] -// public function rowNumber() { -// return $this->recordNumber($this->_tablesArray[0]); -// } - - //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) + //check referential integrity during delete + public function checkOnDeleteIntegrity($id = null, $whereClause = null) { - $this->queryResult = false; + $this->save(); - if (isset($whereClause)) + $result = true; + + if (count($this->foreignKeys) > 0) { - return parent::del(null,$whereClause); + 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; + } + } + } + + } + } } - else + + return $result; + } + + //check referential integrity during insert or update + public function checkOnUpdateIntegrity($queryType) + { + $result = true; + + if (count($this->foreignKeys) > 0) { - if ($this->_onDelete === 'check' and isset($this->_reference)) + foreach ($this->foreignKeys as $f) { - if (isset($this->_reference[0]) and isset($this->_reference[1])) + if (preg_match('/^(.*?)\s(child of)\s(.*?)\((.*?)\)(\s(on update)\s(restrict)\s\((.*?)\))?$/i',$f,$matches)) { - if ($this->db->recordExists($this->_reference[0],$this->_reference[1],(int)$id)) + $childKey = $matches[1]; + $ParentModel = $matches[3]; + $ParentField = $matches[4]; + + $notice = isset($matches[8]) ? "
".$matches[8]."
" : ""; + + if (array_key_exists($childKey,$this->values)) { - $this->notice = $this->_resultString->getString('associate'); - $this->identifierValue = null; + $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; } - else + } + } + } + + 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) + { + $res = $this->save()->select($fieldName)->send(); + $this->restore(); + + if (count($res) > 0 and isset($res[0][$this->_tables][$fieldName])) + { + return $res[0][$this->_tables][$fieldName]; + } + 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) + { + if (!$types) + { + $this->notice .= $this->_resultString->getString('not-existing-fields'); + $this->result = false; + return false; + } + else + { + $this->saveConditions("values"); + $this->saveConditions("database"); + + if (Params::$setValuesConditionsFromDbTableStruct) + { + 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) { - return parent::del((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]); + } + } } } - else + + foreach (Params::$valuesConditionsFromFormatsOfFieldsNames as $regExpr => $function) { - throw new Exception('you have forgotten to set \'$this->_reference\' or you have forgotten to set $this->_onDelete = \'nocheck\''); + foreach ($fields as $f) + { + if (preg_match($regExpr,$f,$matches)) + { + $this->addValuesCondition($queryType,$function,$f); + } + } + } } - else + } + +// 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)) { - return parent::del((int)$id); + $types = $this->getTypes(); + + if ($types) + { + $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]]); + } + } + } } } + } + + 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")) + { + 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 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 diff --git a/h-source/Library/Params.php b/h-source/Library/Params.php index 433a952..e22c1bf 100644 --- a/h-source/Library/Params.php +++ b/h-source/Library/Params.php @@ -1,7 +1,24 @@ . if (!defined('EG')) die('Direct access not allowed!'); @@ -18,9 +35,15 @@ class Params //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'; @@ -37,7 +60,51 @@ class Params //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 + //global website language used by the models and by the helpers for reporting 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 186e4b3..d2d51a7 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 d99585d..8ad9226 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 4c5b46c..a418b7c 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -32,6 +32,9 @@ 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. @@ -54,30 +57,37 @@ class Scaffold //instance of Lang_{language}_Generic public $strings = null; - public function __construct($type,$controller,$model,$viewArgs,$params = 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) { $this->_type = $type; - $this->_controller = $controller; + $this->application = $application; + $this->controller = $controller; $this->model = $model; $this->viewArgs = $viewArgs; //get the generic language class $this->strings = Factory_Strings::generic(Params::$language); - $autoParams = array( - 'mainAction' => 'main', - 'modifyAction' => 'form/update', - 'associateAction' => 'associate', - 'panelController' => 'panel', - 'pageList' => true, - 'pageVariable' => 'page', - 'recordPerPage' => 10, - 'mainMenu' => 'panel,add', - 'formMenu' => 'panel,back', - 'postSubmitValue' => $this->strings->gtext('Save'), - 'popup' => false, - 'popupType' => 'exclusive' - ); + $autoParams = self::$autoParams; + + if (!array_key_exists("postSubmitValue",$autoParams)) + { + $autoParams['postSubmitValue'] = $this->strings->gtext('Save'); + } //set the $this->scaffold->params array if (is_array($params)) { @@ -87,6 +97,7 @@ class Scaffold } $this->params = $autoParams; + $this->applicationUrl = isset($application) ? $application . "/" : null; } //ad some clauses to the select query @@ -109,11 +120,35 @@ class Scaffold { $this->_primaryKey = $primaryKey; - if (strcmp($recordList,'') !== 0) + if (is_array($recordList) or strcmp($recordList,'') !== 0) { - $recordListArray = explode(',',$recordList); + $recordListArray = is_array($recordList) ? $recordList : explode(',',$recordList); + foreach ($recordListArray as $record) { - $this->itemList->addItem("simpleText",";$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;"); + } } } @@ -123,26 +158,33 @@ class Scaffold { foreach ($themeArray as $el) { - switch ($el) + if (preg_match('/ledit\|(.*)/',$el,$matches)) { - 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['modifyAction'].'/;'.$primaryKey.';','Edit','Edit'); - break; + $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; + } } } } @@ -157,7 +199,8 @@ class Scaffold $this->queryType = $queryType; $submitName = $this->model->getSubmitName($queryType); $value = $this->params['postSubmitValue']; - $viewStatus = Url::createUrl(array_values($this->viewArgs)); + $viewStatus = Url::createUrl($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 1ee17af..c63d165 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // 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 a001631..1ddec92 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -34,13 +34,21 @@ 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($controller) { + function __construct($application, $controller) { + $this->controller = $controller; - $this->baseUrl = MOD_REWRITE_MODULE === true ? 'http://' . DOMAIN_NAME : 'http://' . DOMAIN_NAME . '/index.php'; - $this->baseUrlSrc = 'http://' . DOMAIN_NAME; + $this->application = $application; + + $langUrl = isset(Params::$lang) ? "/".Params::$lang : null; + $protocol = Params::$useHttps ? "https" : "http"; + + $this->baseUrl = MOD_REWRITE_MODULE === true ? "$protocol://" . DOMAIN_NAME . $langUrl : "$protocol://" . DOMAIN_NAME . '/index.php' . $langUrl; + + $this->baseUrlSrc = "$protocol://" . DOMAIN_NAME; } @@ -71,15 +79,22 @@ 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 (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $file . '.php')) { + 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')) { 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'); @@ -87,7 +102,15 @@ class Theme { } if (isset($this->_lastView)) { - if (file_exists(ROOT . DS . APPLICATION_PATH . DS . 'Views' . DS .$subfolder. ucwords($this->controller) . DS . $this->_lastView . '.php')) { + 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')) { 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 da312b1..26ff3df 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -26,28 +26,35 @@ class Url { //get the url starting from the root folder public static function getRoot($pathFromRootFolder = null) { - $url = MOD_REWRITE_MODULE === true ? 'http://' . DOMAIN_NAME . '/' . $pathFromRootFolder : 'http://' . DOMAIN_NAME . '/index.php/' . $pathFromRootFolder; + + $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; 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 (in this case '1,2,4') - public static function createUrl($valuesArray,$numericString = null) { + //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) { $elementsArray = explode(',',$numericString); - $valuesArray = array_values($valuesArray); + $valuesArray = array_values($variablesArray); + $keysArray = array_keys($variablesArray); $urlString = null; for ($i = 0; $i < count($valuesArray); $i++) { if (isset($numericString)) { if (isset($valuesArray[$i]) and in_array($i,$elementsArray)) { - $urlString .= "/".$valuesArray[$i]; + $urlString .= (Params::$rewriteStatusVariables or $forceRewrite) ? "/".$valuesArray[$i] : "&".$keysArray[$i]."=".$valuesArray[$i]; } } else { if (isset($valuesArray[$i])) { - $urlString .= "/".$valuesArray[$i]; + $urlString .= (Params::$rewriteStatusVariables or $forceRewrite) ? "/".$valuesArray[$i] : "&".$keysArray[$i]."=".$valuesArray[$i]; } } } - return $urlString; + return (Params::$rewriteStatusVariables or $forceRewrite) ? $urlString : "?".ltrim($urlString,"&"); } } diff --git a/h-source/Library/Users/CheckAdmin.php b/h-source/Library/Users/CheckAdmin.php index 701b47e..aa4e33f 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 - 2011 Antonio Gallo +// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -65,6 +65,11 @@ class Users_CheckAdmin { $this->_params[$key] = $value; } + public function getUid() + { + return $this->uid; + } + private function cleanSessions() { #cancello le sessioni scadute diff --git a/h-source/tables.sql b/h-source/tables.sql index 3c11b38..5943806 100644 --- a/h-source/tables.sql +++ b/h-source/tables.sql @@ -270,6 +270,8 @@ CREATE TABLE IF NOT EXISTS `params` ( PRIMARY KEY (`id_par`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; +insert into params (updating) values ('no'); + -- -------------------------------------------------------- -- -- cgit v1.2.3