aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xh-source/Library/Call.php4
-rwxr-xr-xh-source/Library/Db/Mysql.php85
-rw-r--r--h-source/Library/Db/Mysqli.php87
-rwxr-xr-xh-source/Library/Files/Upload.php104
-rwxr-xr-xh-source/Library/Form/Checkbox.php12
-rwxr-xr-xh-source/Library/Form/Entry.php10
-rw-r--r--h-source/Library/Form/File.php47
-rwxr-xr-xh-source/Library/Form/Form.php9
-rwxr-xr-xh-source/Library/Form/InputText.php12
-rw-r--r--h-source/Library/Form/Password.php12
-rwxr-xr-xh-source/Library/Form/Radio.php12
-rwxr-xr-xh-source/Library/Form/Select.php12
-rw-r--r--h-source/Library/Html/Form.php13
-rwxr-xr-xh-source/Library/Model/Base.php97
-rwxr-xr-xh-source/Library/Model/Map.php35
-rwxr-xr-xh-source/Library/Model/Tree.php25
-rwxr-xr-xh-source/Library/Scaffold.php4
17 files changed, 438 insertions, 142 deletions
diff --git a/h-source/Library/Call.php b/h-source/Library/Call.php
index a2c7e68..092e59b 100755
--- a/h-source/Library/Call.php
+++ b/h-source/Library/Call.php
@@ -71,7 +71,7 @@ function callHook()
$url = (strcmp(getQueryString(),"") !== 0) ? getQueryString() : DEFAULT_CONTROLLER . '/' . DEFAULT_ACTION;
}
- //rewrite the URL
+// rewrite the URL
if (Route::$rewrite === 'yes')
{
$url = rewrite($url);
@@ -217,6 +217,8 @@ function rewrite($url)
{
foreach (Route::$map as $key => $address)
{
+ $key = str_replace('\/','/',$key);
+ $key = str_replace('/','\/',$key);
if (preg_match('/^'.$key.'/',$url))
{
return preg_replace('/^'.$key.'/',$address,$url);
diff --git a/h-source/Library/Db/Mysql.php b/h-source/Library/Db/Mysql.php
index 3f8d3ef..4545ea6 100755
--- a/h-source/Library/Db/Mysql.php
+++ b/h-source/Library/Db/Mysql.php
@@ -95,20 +95,55 @@ class Db_Mysql {
return mysql_errno($this->dblink);
}
- public function createSelectQuery($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=null,$using=null)
+ public function getJoinString($string)
{
- if (isset($where))
+ if (strstr($string,':'))
{
- $where='WHERE '.$where;
+ $tArray = explode(':',$string);
+ switch($tArray[0])
+ {
+ case 'i':
+ $jString = ' INNER JOIN ' . $tArray[1];
+ break;
+ case 'l':
+ $jString = ' LEFT JOIN ' . $tArray[1];
+ break;
+ case 'r':
+ $jString = ' RIGHT JOIN ' . $tArray[1];
+ break;
+ default:
+ $jString = ' INNER JOIN ' . $tArray[1];
+ break;
+ }
+ return $jString;
}
- if (isset($using))
+ else
+ {
+ return ' INNER JOIN '.$string;
+ }
+ }
+
+ public function createSelectQuery($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=array(),$using=array(),$join=array())
+ {
+ $maxValue = max(count($on),count($using),count($join));
+
+ $joinString = null;
+ for ($i=0; $i < $maxValue; $i++)
{
- $using ='USING ('.$using.')';
- $on = null;
+ $joinString .= isset($join[$i]) ? $this->getJoinString($join[$i]) : null;
+ if (isset($using[$i]))
+ {
+ $joinString .= ' USING ('.$using[$i].')';
+ }
+ else if (isset($on[$i]))
+ {
+ $joinString .= ' ON '.$on[$i];
+ }
}
- if (isset($on) and !isset($using))
+
+ if (isset($where))
{
- $on='ON '.$on;
+ $where='WHERE '.$where;
}
if (isset($order_by)) {
$order_by='ORDER BY '.$order_by;
@@ -120,13 +155,13 @@ class Db_Mysql {
$limit='LIMIT '.$limit;
}
- $query="SELECT $fields FROM $table $on $using $where $group_by $order_by $limit;";
+ $query="SELECT $fields FROM $table $joinString $where $group_by $order_by $limit;";
return $query;
}
- public function get_num_rows($table,$where=null,$group_by=null,$on=null,$using=null) {
+ 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);
+ $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using,$join);
$this->query=$query;
@@ -140,9 +175,9 @@ class Db_Mysql {
}
//get the maximum value of the field $field of the table $table having the $where conditions
- public function getMath($func,$table,$field,$where=null,$group_by = null, $on=null,$using=null)
+ public function getMath($func,$table,$field,$where=null,$group_by = null, $on=array(),$using=array(),$join=array())
{
- $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using);
+ $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using,$join);
$this->query = $query;
$result = mysql_query($query);
@@ -158,32 +193,32 @@ class Db_Mysql {
}
//get the maximum value of the field $field of the table $table having the $where conditions
- public function getMax($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getMax($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('MAX',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('MAX',$table,$field,$where,$group_by,$on,$using,$join);
}
//get the minimum value of the field $field of the table $table having the $where conditions
- public function getMin($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getMin($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('MIN',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('MIN',$table,$field,$where,$group_by,$on,$using,$join);
}
//get the sum of the fields
- public function getSum($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getSum($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('SUM',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('SUM',$table,$field,$where,$group_by,$on,$using,$join);
}
//get the average of the fields
- public function getAvg($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getAvg($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('AVG',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('AVG',$table,$field,$where,$group_by,$on,$using,$join);
}
- public function select($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=null,$using=null)
+ public function select($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=array(),$using=array(),$join=array())
{
- $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using);
+ $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using,$join);
$this->query = $query;
$result = mysql_query($query);
@@ -364,7 +399,7 @@ class Db_Mysql {
}
// function to check if exist the record having the field $id_name=$id_value
- public function recordExists($table,$fieldName,$fieldValue,$where = null,$groupBy=null,$on=null,$using=null)
+ public function recordExists($table,$fieldName,$fieldValue,$where = null,$groupBy=null,$on=array(),$using=array(),$join=array())
{
if (isset($where))
{
@@ -373,7 +408,7 @@ class Db_Mysql {
$fieldValue = '"'.$fieldValue.'"';
- $num=$this->get_num_rows($table,$fieldName.'='.$fieldValue.$where,$groupBy,$on,$using);
+ $num=$this->get_num_rows($table,$fieldName.'='.$fieldValue.$where,$groupBy,$on,$using,$join);
$res=($num>0) ? true : false;
return $res;
diff --git a/h-source/Library/Db/Mysqli.php b/h-source/Library/Db/Mysqli.php
index 09bb017..e6fdb15 100644
--- a/h-source/Library/Db/Mysqli.php
+++ b/h-source/Library/Db/Mysqli.php
@@ -101,21 +101,56 @@ class Db_Mysqli
{
return $this->db->errno;
}
-
- public function createSelectQuery($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=null,$using=null)
+
+ public function getJoinString($string)
{
- if (isset($where))
+ if (strstr($string,':'))
{
- $where='WHERE '.$where;
+ $tArray = explode(':',$string);
+ switch($tArray[0])
+ {
+ case 'i':
+ $jString = ' INNER JOIN ' . $tArray[1];
+ break;
+ case 'l':
+ $jString = ' LEFT JOIN ' . $tArray[1];
+ break;
+ case 'r':
+ $jString = ' RIGHT JOIN ' . $tArray[1];
+ break;
+ default:
+ $jString = ' INNER JOIN ' . $tArray[1];
+ break;
+ }
+ return $jString;
}
- if (isset($using))
+ else
+ {
+ return ' INNER JOIN '.$string;
+ }
+ }
+
+ public function createSelectQuery($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=array(),$using=array(),$join=array())
+ {
+ $maxValue = max(count($on),count($using),count($join));
+
+ $joinString = null;
+ for ($i=0; $i < $maxValue; $i++)
{
- $using ='USING ('.$using.')';
- $on = null;
+ $joinString .= isset($join[$i]) ? $this->getJoinString($join[$i]) : null;
+ if (isset($using[$i]))
+ {
+ $joinString .= ' USING ('.$using[$i].')';
+ }
+ else if (isset($on[$i]))
+ {
+ $joinString .= ' ON '.$on[$i];
+ }
}
- if (isset($on) and !isset($using))
+
+ if (isset($where))
{
- $on='ON '.$on;
+ $where='WHERE '.$where;
}
if (isset($order_by)) {
$order_by='ORDER BY '.$order_by;
@@ -127,13 +162,13 @@ class Db_Mysqli
$limit='LIMIT '.$limit;
}
- $query="SELECT $fields FROM $table $on $using $where $group_by $order_by $limit;";
+ $query="SELECT $fields FROM $table $joinString $where $group_by $order_by $limit;";
return $query;
}
- public function get_num_rows($table,$where=null,$group_by=null,$on=null,$using=null) {
+ 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);
+ $query = $this->createSelectQuery($table,'*',$where,$group_by,null,null,$on,$using,$join);
$this->query = $query;
$ris = $this->db->query($query);
@@ -146,9 +181,9 @@ class Db_Mysqli
}
}
- public function getMath($func,$table,$field,$where=null,$group_by = null, $on=null,$using=null)
+ public function getMath($func,$table,$field,$where=null,$group_by = null, $on=array(),$using=array(),$join=array())
{
- $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using);
+ $query = $this->createSelectQuery($table,"$func($field) AS m",$where,$group_by,null,null,$on,$using,$join);
$this->query = $query;
$result = $this->db->query($query);
@@ -165,32 +200,32 @@ class Db_Mysqli
}
//get the maximum value of the field $field of the table $table having the $where conditions
- public function getMax($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getMax($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('MAX',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('MAX',$table,$field,$where,$group_by,$on,$using,$join);
}
//get the minimum value of the field $field of the table $table having the $where conditions
- public function getMin($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getMin($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('MIN',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('MIN',$table,$field,$where,$group_by,$on,$using,$join);
}
//get the sum of the fields
- public function getSum($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getSum($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('SUM',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('SUM',$table,$field,$where,$group_by,$on,$using,$join);
}
//get the average of the fields
- public function getAvg($table,$field,$where=null,$group_by = null,$on=null,$using=null)
+ public function getAvg($table,$field,$where=null,$group_by = null,$on=array(),$using=array(),$join=array())
{
- return $this->getMath('AVG',$table,$field,$where,$group_by,$on,$using);
+ return $this->getMath('AVG',$table,$field,$where,$group_by,$on,$using,$join);
}
- public function select($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=null,$using=null)
+ public function select($table,$fields='*',$where=null,$group_by=null,$order_by=null,$limit=null,$on=array(),$using=array(),$join=array())
{
- $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using);
+ $query = $this->createSelectQuery($table,$fields,$where,$group_by,$order_by,$limit,$on,$using,$join);
$this->query = $query;
$result = $this->db->query($query);
@@ -370,7 +405,7 @@ class Db_Mysqli
//function to check if exist the record having the field $id_name=$id_value
- public function recordExists($table,$fieldName,$fieldValue,$where = null,$groupBy=null,$on=null,$using=null)
+ public function recordExists($table,$fieldName,$fieldValue,$where = null,$groupBy=null,$on=array(),$using=array(),$join=array())
{
if (isset($where))
{
@@ -379,7 +414,7 @@ class Db_Mysqli
$fieldValue = '"'.$fieldValue.'"';
- $num = $this->get_num_rows($table,$fieldName.'='.$fieldValue.$where,$groupBy,$on,$using);
+ $num = $this->get_num_rows($table,$fieldName.'='.$fieldValue.$where,$groupBy,$on,$using,$join);
$res=($num>0) ? true : false;
return $res;
diff --git a/h-source/Library/Files/Upload.php b/h-source/Library/Files/Upload.php
index 466582c..0c459ff 100755
--- a/h-source/Library/Files/Upload.php
+++ b/h-source/Library/Files/Upload.php
@@ -50,15 +50,18 @@ class Files_Upload
$this->pattern = "/^(".$tmp.")/";
$defaultParams = array(
- 'filesPermission'=>0777,
- 'delFolderAction'=>'delFolderAction',
- 'delFileAction'=>'delFileAction',
- 'createFolderAction'=>'createFolderAction',
- 'uploadFileAction'=>'uploadFileAction',
- 'maxFileSize' => 3000000,
- 'language' => 'Eng',
- 'allowedExtensions'=>'jpg,jpeg,png,gif,txt',
- 'fileUploadKey' => 'userfile'
+ 'filesPermission' => 0777,
+ 'delFolderAction' => 'delFolderAction',
+ 'delFileAction' => 'delFileAction',
+ 'createFolderAction' => 'createFolderAction',
+ 'uploadFileAction' => 'uploadFileAction',
+ 'maxFileSize' => 3000000,
+ 'language' => 'Eng',
+ 'allowedExtensions' => 'jpg,jpeg,png,gif,txt',
+ 'fileUploadKey' => 'userfile',
+ 'fileUploadBehaviour' => 'add_token', //can be none or add_token
+ 'fileUploadBeforeTokenChar' => '_',
+ 'functionUponFileNane' => 'none',
);
//set the $this->scaffold->params array
@@ -83,6 +86,15 @@ class Files_Upload
}
+ //set a new value for one element of the $params array
+ public function setParam($key,$value)
+ {
+ if (array_key_exists($key,$this->params))
+ {
+ $this->params[$key] = $value;
+ }
+ }
+
//change a resulting string
public function setString($key,$value)
{
@@ -206,6 +218,32 @@ class Files_Upload
return strtolower(end(explode('.', $file)));
}
+ //get the file name without the extension
+ protected function getNameWithoutFileExtension($file)
+ {
+ $copy = explode('.', $file);
+ array_pop($copy);
+ return implode('.',$copy);
+ }
+
+ //get a not existing file name if the one retrieved from the upload process already exists in the current directory
+ protected function getUniqueName($file,$int = 0)
+ {
+ $fileNameWithoutExt = $this->getNameWithoutFileExtension($file);
+ $extension = $this->getFileExtension($file);
+ $token = $int === 0 ? null : $this->params['fileUploadBeforeTokenChar'].$int;
+ $newName = $fileNameWithoutExt.$token.".$extension";
+ if (!file_exists($this->base.$this->directory.$newName))
+ {
+ return $newName;
+ }
+ else
+ {
+ return $this->getUniqueName($file,$int+1);
+ }
+
+ }
+
protected function parentDir() { #individuo la cartella madre
$folders = explode(self::DS,$this->directory);
@@ -389,17 +427,53 @@ class Files_Upload
return false;
}
+ //remove all the files that are not inside the $list argument
+ public function removeFilesNotInTheList($list = array())
+ {
+ $this->listFiles();
+ $files = $this->getFiles();
+ foreach ($files as $file)
+ {
+ if (!in_array($file,$list))
+ {
+ $this->removeFile($file);
+ }
+ }
+ }
+
//upload a file in the current directory
//$fileName: name of the file
- public function uploadFile($fileName = null) {
+ public function uploadFile($fileName = null)
+ {
$userfile = $this->params['fileUploadKey'];
- $ext = $this->getFileExtension($_FILES[$userfile]["name"]);
- $fileName = isset($fileName) ? $fileName.".$ext" : basename($_FILES[$userfile]["name"]);
-
- $this->fileName = $fileName;
if(strcmp(trim($_FILES[$userfile]["name"]),"") !== 0)
{
+ $nameFromUpload = basename($_FILES[$userfile]["name"]);
+
+ $ext = $this->getFileExtension($nameFromUpload);
+ $nameWithoutExtension = $this->getNameWithoutFileExtension($nameFromUpload);
+
+ if (!function_exists($this->params['functionUponFileNane'])) {
+ throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$this->params['functionUponFileNane']. '</b> does not exist');
+ }
+
+ $nameWithoutExtension = call_user_func($this->params['functionUponFileNane'],$nameWithoutExtension);
+
+ $fileName = isset($fileName) ? $fileName.".$ext" : $nameWithoutExtension.".$ext";
+
+ $this->fileName = $fileName;
+
+ switch($this->params['fileUploadBehaviour'])
+ {
+ case 'none':
+ break;
+ case 'add_token':
+ $this->fileName = $this->getUniqueName($this->fileName);
+ $fileName = $this->fileName;
+ break;
+ }
+
if(@is_uploaded_file($_FILES[$userfile]["tmp_name"])) {
if ($_FILES[$userfile]["size"] <= $this->params['maxFileSize'])
{
@@ -408,7 +482,7 @@ class Files_Upload
if (in_array($ext,$AllowedExtensionsArray))
{
- //check if the file doesn't exists
+ //check if the file doesn't exist
if (!file_exists($this->base.$this->directory.$fileName))
{
if (@move_uploaded_file($_FILES[$userfile]["tmp_name"],$this->base.$this->directory.$fileName))
diff --git a/h-source/Library/Form/Checkbox.php b/h-source/Library/Form/Checkbox.php
index a606e76..4074210 100755
--- a/h-source/Library/Form/Checkbox.php
+++ b/h-source/Library/Form/Checkbox.php
@@ -31,14 +31,16 @@ class Form_Checkbox extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::checkbox($this->entryName, $value, $this->options, $this->className,$this->idName);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::checkbox($this->entryName, $value, $this->options, $this->className,$this->idName);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}
diff --git a/h-source/Library/Form/Entry.php b/h-source/Library/Form/Entry.php
index 2582557..440ee2d 100755
--- a/h-source/Library/Form/Entry.php
+++ b/h-source/Library/Form/Entry.php
@@ -47,11 +47,19 @@ abstract class Form_Entry {
return isset($this->entryClass) ? $this->entryClass : 'formEntry';
}
- public function getWrapElements()
+ public function getWrapElements($value = null)
{
+ //replace the ;;value;; variable
+ for ($i = 0; $i < count($this->wrap); $i++)
+ {
+ $this->wrap[$i] = str_replace(';;value;;',$value,$this->wrap[$i]);
+ }
+
$wrap[0] = isset($this->wrap[0]) ? $this->wrap[0] : null;
$wrap[1] = isset($this->wrap[1]) ? $this->wrap[1] : null;
$wrap[2] = isset($this->wrap[2]) ? $this->wrap[2] : null;
+ $wrap[3] = isset($this->wrap[3]) ? $this->wrap[3] : null;
+ $wrap[4] = isset($this->wrap[4]) ? $this->wrap[4] : null;
return $wrap;
}
diff --git a/h-source/Library/Form/File.php b/h-source/Library/Form/File.php
new file mode 100644
index 0000000..48030f7
--- /dev/null
+++ b/h-source/Library/Form/File.php
@@ -0,0 +1,47 @@
+<?php
+
+// EasyGiant, a web software to build a community of people that want to share their hardware information.
+// Copyright (C) 2009 - 2010 Antonio Gallo (h-source-copyright.txt)
+//
+// This file is part of EasyGiant
+//
+// EasyGiant is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// EasyGiant is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with EasyGiant. If not, see <http://www.gnu.org/licenses/>.
+
+if (!defined('EG')) die('Direct access not allowed!');
+
+//create the HTML of a file upload entry
+class Form_File extends Form_Entry
+{
+
+ public function __construct($entryName = null)
+ {
+ $this->entryName = $entryName;
+ }
+
+ public function render($value = null)
+ {
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
+ $returnString .= $wrap[1];
+ $returnString .= $this->getLabelTag();
+ $returnString .= $wrap[2];
+ $returnString .= Html_Form::fileUpload($this->entryName, $value, $this->className, $this->idName);
+ $returnString .= $wrap[3];
+ $returnString .="</div>\n";
+ $returnString .= $wrap[4];
+ return $returnString;
+ }
+
+}
diff --git a/h-source/Library/Form/Form.php b/h-source/Library/Form/Form.php
index 9705666..9aba086 100755
--- a/h-source/Library/Form/Form.php
+++ b/h-source/Library/Form/Form.php
@@ -31,12 +31,14 @@ class Form_Form {
public $id = null;
public $submit = array(); //the submit entries array('name'=>'value')
public $method = 'POST'; //the transmission method: POST/GET
+ public $enctype = null; //enctype attribute of the form
- public function __construct($action,$submit = array('generalAction'=>'save'),$method = 'POST')
+ public function __construct($action,$submit = array('generalAction'=>'save'),$method = 'POST',$enctype = null)
{
$this->action = $action; //action of the form: controller/action
$this->submit = $submit;
$this->method = $method;
+ $this->enctype = $enctype;
}
//method to manage the $this->entry associative array
@@ -76,7 +78,7 @@ class Form_Form {
$labelClass = array_key_exists('labelClass',$entry) ? $entry['labelClass'] : null;
$defaultValue = array_key_exists('defaultValue',$entry) ? $entry['defaultValue'] : null;
$wrap = array_key_exists('wrap',$entry) ? $entry['wrap'] : array();
-
+
$this->entry[$name]->entryClass = $entryClass;
$this->entry[$name]->labelString = $labelString;
$this->entry[$name]->idName = $idName;
@@ -105,7 +107,8 @@ class Form_Form {
$fid = isset($this->id) ? "id='".$this->id."'" : null;
$fname = isset($this->name) ? "name='".$this->name."'" : null;
$fclass = isset($this->className) ? "class='".$this->className."'" : null;
- $htmlForm = "<form $fname $fclass $fid action='".Url::getRoot($this->action)."' method='".$this->method."'>\n";
+ $fenctype = isset($this->enctype) ? " enctype=".$this->enctype." " : null;
+ $htmlForm = "<form $fname $fclass $fid action='".Url::getRoot($this->action)."' method='".$this->method."' $fenctype>\n";
$subset = (isset($subset)) ? explode(',',$subset) : array_keys($values);
diff --git a/h-source/Library/Form/InputText.php b/h-source/Library/Form/InputText.php
index 02315a6..5943fb9 100755
--- a/h-source/Library/Form/InputText.php
+++ b/h-source/Library/Form/InputText.php
@@ -31,14 +31,16 @@ class Form_InputText extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::input($this->entryName, $value, $this->className, $this->idName);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::input($this->entryName, $value, $this->className, $this->idName);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}
diff --git a/h-source/Library/Form/Password.php b/h-source/Library/Form/Password.php
index 02500af..1ac4492 100644
--- a/h-source/Library/Form/Password.php
+++ b/h-source/Library/Form/Password.php
@@ -31,14 +31,16 @@ class Form_Password extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::password($this->entryName, null, $this->className);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::password($this->entryName, null, $this->className);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}
diff --git a/h-source/Library/Form/Radio.php b/h-source/Library/Form/Radio.php
index 49137c0..a10726a 100755
--- a/h-source/Library/Form/Radio.php
+++ b/h-source/Library/Form/Radio.php
@@ -31,14 +31,16 @@ class Form_Radio extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::radio($this->entryName,$value,$this->options,$this->className, 'after', $this->idName);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::radio($this->entryName,$value,$this->options,$this->className, 'after', $this->idName);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}
diff --git a/h-source/Library/Form/Select.php b/h-source/Library/Form/Select.php
index db88124..884b0b2 100755
--- a/h-source/Library/Form/Select.php
+++ b/h-source/Library/Form/Select.php
@@ -31,14 +31,16 @@ class Form_Select extends Form_Entry
public function render($value = null)
{
- $wrap = $this->getWrapElements();
- $returnString = "<div class='".$this->getEntryClass()."'>\n\t";
- $returnString .= $wrap[0];
- $returnString .= $this->getLabelTag();
+ $wrap = $this->getWrapElements($value);
+ $returnString = $wrap[0];
+ $returnString .= "<div class='".$this->getEntryClass()."'>\n\t";
$returnString .= $wrap[1];
- $returnString .= Html_Form::select($this->entryName,$value,$this->options,$this->className, $this->idName);
+ $returnString .= $this->getLabelTag();
$returnString .= $wrap[2];
+ $returnString .= Html_Form::select($this->entryName,$value,$this->options,$this->className, $this->idName);
+ $returnString .= $wrap[3];
$returnString .="</div>\n";
+ $returnString .= $wrap[4];
return $returnString;
}
diff --git a/h-source/Library/Html/Form.php b/h-source/Library/Html/Form.php
index e3148cd..501e2a2 100644
--- a/h-source/Library/Html/Form.php
+++ b/h-source/Library/Html/Form.php
@@ -89,6 +89,19 @@ class Html_Form {
return $returnString;
}
+ //return the HTML of an <input type='file' ...>
+ //$name: the name of the input
+ //$className: the class name of the input
+ //$idName: name of the id
+ static public function fileUpload($name, $value, $className = null, $idName = null)
+ {
+ $strClass = isset($className) ? "class='".$className."'" : null;
+ $idStr = isset($idName) ? "id='".$idName."'" : null;
+
+ $returnString ="<input ".$idStr." $strClass type='file' name='" .$name. "'>\n";
+ return $returnString;
+ }
+
//return the HTML of a checkBox
//$name: name of the checkBox (string)
//$value: the value of the checkBox (string or number)
diff --git a/h-source/Library/Model/Base.php b/h-source/Library/Model/Base.php
index 4f2e783..753d93c 100755
--- a/h-source/Library/Model/Base.php
+++ b/h-source/Library/Model/Base.php
@@ -63,14 +63,17 @@ abstract class Model_Base
public $limit = null;
public $from = null; //from clause of the select queries
- public $on = null; //join part of the where clause of the select queries
- public $using = null; //using clause
+ public $on = array(); //on array
+ public $using = array(); //using array
+ public $join = array(); //join array
public $toList = false; //if the result have to be given in a list format
public $listArray = array(); //array containing the $key and the $value to be used to extract a list from a resultSet
//logic operator between statements in the where clause of select queries
public $logicalOperators = array('AND');
+
+ public $files = null; //reference to the Files_Upload class
protected $_tables='itemTable,boxTable,item_boxTable';
protected $_idFields='id_item,id_box';
@@ -149,9 +152,20 @@ abstract class Model_Base
//instantiate the database class
$this->db = Factory_Db::getInstance(DATABASE_TYPE);
+
+ //instantiate the Files_Upload class
+ $params = array(
+ 'filesPermission' => 0777,
+ 'language' => $this->_lang,
+ 'allowedExtensions' => 'png,jpg,jpeg,gif',
+ 'maxFileSize' => 20000000,
+ 'fileUploadKey' => 'userfile'
+ );
+
+ $this->files = new Files_Upload(ROOT."/media/",$params);
}
- //sanitize all the $values proprierty
+ //sanitize all the $values property
public function sanitize()
{
$this->values = $this->arrayExt->subset($this->values,null,'sanitizeDb');
@@ -331,13 +345,25 @@ abstract class Model_Base
if (array_key_exists($entry,$values))
{
if (!function_exists($funcUponEntry)) {
- throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$funcUponEntry. '</b> does not exists');
+ throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$funcUponEntry. '</b> does not exist');
}
$values[$entry] = call_user_func($funcUponEntry,$values[$entry]);
}
}
-
+
+ //set values of $_SESSION array
+ foreach ($values as $k => $v)
+ {
+ if (isset($this->formStruct['entries'][$k]['type']))
+ {
+ if ($this->formStruct['entries'][$k]['type'] === 'File')
+ {
+ session_start();
+ $_SESSION['form_'.$k] = $v;
+ }
+ }
+ }
}
}
else if ($queryType === 'insert')
@@ -356,6 +382,24 @@ abstract class Model_Base
if ($queryType === 'update')
{
$values[$idName] = $ident;
+
+ //take values from $_SESSION array
+ $tempFieldArray = explode(',',$this->fields);
+
+ for ($i = 0; $i < count($tempFieldArray); $i++)
+ {
+ if (isset($this->formStruct['entries'][$tempFieldArray[$i]]['type']))
+ {
+ if ($this->formStruct['entries'][$tempFieldArray[$i]]['type'] === 'File')
+ {
+ session_start();
+ if (isset($_SESSION['form_'.$tempFieldArray[$i]]))
+ {
+ $values[$tempFieldArray[$i]] = $_SESSION['form_'.$tempFieldArray[$i]];
+ }
+ }
+ }
+ }
}
}
}
@@ -886,7 +930,7 @@ abstract class Model_Base
{
if (!function_exists($this->_popupFunctions[$field]))
{
- throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$this->_popupFunctions[$field]. '</b> does not exists');
+ throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$this->_popupFunctions[$field]. '</b> does not exist');
}
$tempName = call_user_func($this->_popupFunctions[$field],$row[$itemNameTable][$itemNameClean]);
@@ -945,17 +989,40 @@ abstract class Model_Base
return $this;
}
- //set the $on property and return the current object
+ //set the on property and return the current object
public function on($joinClause = '-')
{
- $this->on = $joinClause;
+ $this->on[] = $joinClause;
+ $this->using[] = null;
return $this;
}
//set the $using property and return the current object
public function using($using = null)
{
- $this->using = $using;
+ $this->using[] = $using;
+ $this->on[] = null;
+ return $this;
+ }
+
+ //set the $join property and return the current object
+ public function left($string = null)
+ {
+ $this->join[] = "l:$string";
+ return $this;
+ }
+
+ //set the $join property and return the current object
+ public function right($string = null)
+ {
+ $this->join[] = "r:$string";
+ return $this;
+ }
+
+ //set the $join property and return the current object
+ public function inner($string = null)
+ {
+ $this->join[] = "i:$string";
return $this;
}
@@ -1011,14 +1078,15 @@ abstract class Model_Base
$this->orderBy = null;
$this->limit = null;
$this->from = null;
- $this->on = null;
- $this->using = null;
+ $this->on = array();
+ $this->using = array();
+ $this->join = array();
$this->toList = false;
return $this;
}
//initialize and populate the ::form property (reference to a Form_Form object)
- public function setForm($defAction = null, $defSubmit = array(), $defMethod = 'POST')
+ public function setForm($defAction = null, $defSubmit = array(), $defMethod = 'POST', $defEnctype = null)
{
if (isset($this->formStruct))
{
@@ -1026,8 +1094,9 @@ abstract class Model_Base
$submit = array_key_exists('submit',$this->formStruct) ? $this->formStruct['submit'] : $defSubmit;
$entries = array_key_exists('entries',$this->formStruct) ? $this->formStruct['entries'] : null;
$method = array_key_exists('post',$this->formStruct) ? $this->formStruct['post'] : $defMethod;
+ $enctype = array_key_exists('enctype',$this->formStruct) ? $this->formStruct['enctype'] : $defEnctype;
- $this->form = new Form_Form($action,$submit,$method);
+ $this->form = new Form_Form($action,$submit,$method,$enctype);
if (isset($entries))
{
@@ -1082,7 +1151,7 @@ abstract class Model_Base
}
else
{
- $this->form = new Form_Form($defAction,$defSubmit,$defMethod);
+ $this->form = new Form_Form($defAction,$defSubmit,$defMethod,$defEnctype);
}
}
diff --git a/h-source/Library/Model/Map.php b/h-source/Library/Model/Map.php
index 4fe562d..10166db 100755
--- a/h-source/Library/Model/Map.php
+++ b/h-source/Library/Model/Map.php
@@ -42,25 +42,18 @@ class Model_Map extends Model_Base {
public function createMapWhere($choice)
{ //create the where join clause
//$choice=(first,last,all)
- if (isset($this->on))
- {
- return $this->on;
- }
- else
- {
- $first = $this->_tablesArray[0].'.'.$this->_idFieldsArray[0].'='.$this->_tablesArray[2].'.'.$this->_idFieldsArray[0];
- $last = $this->_tablesArray[1].'.'.$this->_idFieldsArray[1].'='.$this->_tablesArray[2].'.'.$this->_idFieldsArray[1];
- switch ($choice) {
- case 'first':
- return $first;
- break;
- case 'last':
- return $last;
- break;
- case 'all':
- return $first. ' and '.$last;
- break;
- }
+ $first = $this->_tablesArray[0].'.'.$this->_idFieldsArray[0].'='.$this->_tablesArray[2].'.'.$this->_idFieldsArray[0];
+ $last = $this->_tablesArray[1].'.'.$this->_idFieldsArray[1].'='.$this->_tablesArray[2].'.'.$this->_idFieldsArray[1];
+ switch ($choice) {
+ case 'first':
+ return $first;
+ break;
+ case 'last':
+ return $last;
+ break;
+ case 'all':
+ return $first. ' and '.$last;
+ break;
}
}
@@ -168,6 +161,8 @@ class Model_Map extends Model_Base {
public function selectId($id,$fields = null)
{
$id = (int)$id;
+
+ $tempWhere = $this->where;
$this->setWhereQueryClause(array($this->_idFieldsArray[0] => $id));
if (isset($fields))
@@ -178,6 +173,8 @@ class Model_Map extends Model_Base {
{
$values = $this->getAll('Items');
}
+
+ $this->where = $tempWhere;
return (count($values) > 0) ? $values[0][$this->_tablesArray[0]] : array();
}
diff --git a/h-source/Library/Model/Tree.php b/h-source/Library/Model/Tree.php
index 4dcac8f..56a5db3 100755
--- a/h-source/Library/Model/Tree.php
+++ b/h-source/Library/Model/Tree.php
@@ -29,7 +29,7 @@ class Model_Tree extends Model_Base {
//method to create the first part of where clause
//$index: the index of $this->_tablesArray
public function createTreeWhere($index) {
- if (isset($this->on))
+ if (!empty($this->on))
{
return $this->on;
}
@@ -90,9 +90,9 @@ class Model_Tree extends Model_Base {
$wherePlus = $this->createWhereClause();
- if (!isset($this->on))
+ if (empty($this->on))
{
- $on = null;
+ $on = array();
if (isset($where) and isset($wherePlus))
{
@@ -105,7 +105,7 @@ class Model_Tree extends Model_Base {
}
else
{
- $on = (strcmp($where,'-') !== 0) ? $where : null;
+ $on = (isset($where[0]) and strcmp($where[0],'-') !== 0) ? $where : array();
$where = $wherePlus;
}
@@ -128,7 +128,7 @@ class Model_Tree extends Model_Base {
$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);
+ return $row = $this->db->select($elements['tables'],$queryFields,$elements['where'],$this->groupBy,$this->orderBy,$this->limit,$elements['on'],$this->using,$this->join);
}
public function send()
@@ -158,6 +158,7 @@ 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->using = null;
@@ -170,6 +171,8 @@ class Model_Tree extends Model_Base {
{
$values = $this->getAll('other');
}
+
+ $this->where = $tempWhere;
return (count($values) > 0) ? $values[0][$this->_tablesArray[0]] : array();
@@ -179,38 +182,38 @@ class Model_Tree extends Model_Base {
//the number of records of the table $tableName is returned
public function rowNumber() {
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->get_num_rows($elements['tables'],$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->get_num_rows($elements['tables'],$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
public function getMax($field)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->getMax($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->getMax($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
public function getMin($field)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->getMin($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->getMin($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
public function getSum($field)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->getSum($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->getSum($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
public function getAvg($field)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->getAvg($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->getAvg($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
//check if the table has the field $field equal to $value
public function has($field,$value)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->recordExists($elements['tables'],$field,$value,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ 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]
diff --git a/h-source/Library/Scaffold.php b/h-source/Library/Scaffold.php
index 7ee655d..aa20a4b 100755
--- a/h-source/Library/Scaffold.php
+++ b/h-source/Library/Scaffold.php
@@ -135,13 +135,13 @@ class Scaffold
//initialize the form
//$queryType = insert/update
//$action: the action of the form (controller/action/queryString)
- public function loadForm($queryType,$action)
+ public function loadForm($queryType,$action,$method = 'POST',$enctype = null)
{
$this->queryType = $queryType;
$submitName = $this->model->getSubmitName($queryType);
$value = $this->params['postSubmitValue'];
$viewStatus = Url::createUrl(array_values($this->viewArgs));
- $this->model->setForm($action.$viewStatus,array($submitName => $value),'POST');
+ $this->model->setForm($action.$viewStatus,array($submitName => $value),$method,$enctype);
$this->form = $this->model->form;
}