mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merging changes to trunk:
Revision: [1761] Removing old db_acl.sql Revision: [1759] Removed unneeded calls to uses(). Changed basics.php listClasses() no longer using folder class. Starting corrections in DboPostgres class. Adding missing DboPostgres::query(). Added missing doc blocks to AjaxHelper. Fixed undefined keys in FormHelper::generateFields() Reformatted FormHelper::generateFields() adding open and close brackets where needed Revision: [1758] Fixed typo Revision: [1757] Fixed errors found when using PHP 4. Fixed a scaffold error Revision: [1756] Merging changes to model_php4.php Revision: [1755] Fixed scaffolding for the changes made to the model. Fixed Model::isForeignKey(), replaced array_key_exists with in_array, other function was failing Revision: [1754] Committing changes from bundt model to beta. DataSources will not be in the beta release Revision: [1751] Cleaning up a little more in the code. Removing loading of log.php unless it is really needed. Refactored dispatcher to speed up the stripslashes code if it is called Revision: [1748] removing all references to error_messages and deleting the file Revision: [1747] updated more error messages Revision: [1746] removing all error message defines Revision: [1745] added _() method from 1.0 to basics.php only used to return string right now Revision: [1744] Adding fix for ticket #220 Revision: [1743] More work on ErrorHandler class Revision: [1742] Renaming error view for missing database connection Revision: [1741] More work on ErrorHandler class Revision: [1740] More work on error class Revision: [1739] Replacing all $_SERVER variable check with env() in basics.php Revision: [1738] Adding env() to basic Revision: [1737] Updated session to use env() Revision: [1736] Removing ternary operators from Dispatcher Revision: [1735] Per nates request I am rolling back ACL to [1373] Revision: [1734] Removed the IP in the session class this was not very reliable. Added a time setting that generates current time adding the Security::inactiveMins() to the session Removed code that was added to basics.php to replace gethostbyaddr(). Added CAKE_SESSION_STRING define to core.php which is used in the by the Session class to generate a hashed key. Revision: [1733] Moving errors messages to ErrorHandler class. Updating errors view for use with new class. Updating Scaffold to use new class. Updated Dispatcher to use new class. Removing methods from Object class Revision: [1732] Adding ErrorHandler class Revision: [1731] Adding fix for Ticket #223 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1762 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
93c65557a4
commit
677a39a445
53 changed files with 6568 additions and 2839 deletions
|
@ -9,7 +9,7 @@
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
|
@ -39,8 +39,7 @@
|
||||||
* release/app/.htaccess
|
* release/app/.htaccess
|
||||||
* release/app/webroot/.htaccess
|
* release/app/webroot/.htaccess
|
||||||
*/
|
*/
|
||||||
//define ('BASE_URL', $_SERVER['SCRIPT_NAME']);
|
//define ('BASE_URL', env('SCRIPT_NAME');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set debug level here:
|
* Set debug level here:
|
||||||
|
@ -66,6 +65,12 @@ define('CAKE_SESSION_COOKIE', 'CAKEPHP');
|
||||||
*/
|
*/
|
||||||
define('CAKE_SECURITY', 'high');
|
define('CAKE_SECURITY', 'high');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a random string of used in session.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
define('CAKE_SESSION_STRING', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CakePHP includes 3 types of session saves
|
* CakePHP includes 3 types of session saves
|
||||||
* database or file. Set this to your preffered method.
|
* database or file. Set this to your preffered method.
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
CREATE TABLE `acos` (
|
|
||||||
`id` int(11) NOT NULL auto_increment,
|
|
||||||
`object_id` int(11) default NULL,
|
|
||||||
`alias` varchar(255) NOT NULL default '',
|
|
||||||
`lft` int(11) default NULL,
|
|
||||||
`rght` int(11) default NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE `aros` (
|
|
||||||
`id` int(11) NOT NULL auto_increment,
|
|
||||||
`user_id` int(11) default NULL,
|
|
||||||
`alias` varchar(255) NOT NULL default '',
|
|
||||||
`lft` int(11) default NULL,
|
|
||||||
`rght` int(11) default NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE `aros_acos` (
|
|
||||||
`id` int(11) NOT NULL auto_increment,
|
|
||||||
`aro_id` int(11) default NULL,
|
|
||||||
`aco_id` int(11) default NULL,
|
|
||||||
`create` tinyint(1) NOT NULL default '0',
|
|
||||||
`read` tinyint(1) NOT NULL default '0',
|
|
||||||
`update` tinyint(1) NOT NULL default '0',
|
|
||||||
`delete` tinyint(1) NOT NULL default '0',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE `aco_actions` (
|
|
||||||
`id` int(11) NOT NULL auto_increment,
|
|
||||||
`aros_acos_id` int(11) default NULL,
|
|
||||||
`action` varchar(255) NOT NULL default '',
|
|
||||||
`value` tinyint(1) NOT NULL default '0',
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);
|
|
|
@ -67,7 +67,6 @@ require_once ROOT.'cake'.DS.'basics.php';
|
||||||
require_once ROOT.APP_DIR.DS.'config'.DS.'core.php';
|
require_once ROOT.APP_DIR.DS.'config'.DS.'core.php';
|
||||||
require_once ROOT.'cake'.DS.'config'.DS.'paths.php';
|
require_once ROOT.'cake'.DS.'config'.DS.'paths.php';
|
||||||
require_once LIBS.'object.php';
|
require_once LIBS.'object.php';
|
||||||
require_once LIBS.'log.php';
|
|
||||||
require_once LIBS.'session.php';
|
require_once LIBS.'session.php';
|
||||||
require_once LIBS.'security.php';
|
require_once LIBS.'security.php';
|
||||||
require_once LIBS.'neat_array.php';
|
require_once LIBS.'neat_array.php';
|
||||||
|
@ -121,9 +120,8 @@ if (DEBUG)
|
||||||
|
|
||||||
$TIME_START = getMicrotime();
|
$TIME_START = getMicrotime();
|
||||||
|
|
||||||
uses('folder');
|
|
||||||
require_once CAKE.'dispatcher.php';
|
require_once CAKE.'dispatcher.php';
|
||||||
require_once LIBS.'model'.DS.'dbo'.DS.'dbo_factory.php';
|
require_once LIBS.'model'.DS.'connection_manager.php';
|
||||||
|
|
||||||
config('database');
|
config('database');
|
||||||
|
|
||||||
|
|
567
cake/basics.php
567
cake/basics.php
|
@ -59,7 +59,7 @@ if (!function_exists("ob_get_clean"))
|
||||||
* @uses APP
|
* @uses APP
|
||||||
* @uses MODELS
|
* @uses MODELS
|
||||||
*/
|
*/
|
||||||
function loadModels ()
|
function loadModels()
|
||||||
{
|
{
|
||||||
if(!class_exists('AppModel'))
|
if(!class_exists('AppModel'))
|
||||||
{
|
{
|
||||||
|
@ -71,9 +71,20 @@ function loadModels ()
|
||||||
{
|
{
|
||||||
require_once(CAKE.'app_model.php');
|
require_once(CAKE.'app_model.php');
|
||||||
}
|
}
|
||||||
foreach (listClasses(MODELS) as $model_fn)
|
}
|
||||||
|
|
||||||
|
if (phpversion() < 5 && function_exists("overload"))
|
||||||
|
{
|
||||||
|
overload('AppModel');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (listClasses(MODELS) as $model_fn)
|
||||||
|
{
|
||||||
|
require_once (MODELS.$model_fn);
|
||||||
|
if (phpversion() < 5 && function_exists("overload"))
|
||||||
{
|
{
|
||||||
require_once (MODELS.$model_fn);
|
list($name) = explode('.', $model_fn);
|
||||||
|
overload(Inflector::camelize($name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,6 +113,38 @@ function loadView ($viewClass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a model by CamelCase name.
|
||||||
|
*
|
||||||
|
* @uses listModules()
|
||||||
|
* @uses APP
|
||||||
|
* @uses MODELS
|
||||||
|
*/
|
||||||
|
function loadModel($name)
|
||||||
|
{
|
||||||
|
$name = Inflector::underscore($name);
|
||||||
|
|
||||||
|
// Make sure AppModel is loaded
|
||||||
|
if(!class_exists('AppModel'))
|
||||||
|
{
|
||||||
|
if(file_exists(APP.'app_model.php'))
|
||||||
|
{
|
||||||
|
require_once(APP.'app_model.php');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
require_once(CAKE.'app_model.php');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file_exists(MODELS.$name.'.php'))
|
||||||
|
{
|
||||||
|
require_once (MODELS.$name.'.php');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all controllers.
|
* Loads all controllers.
|
||||||
|
@ -134,11 +177,11 @@ function loadControllers ()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a controller and its helper libraries.
|
* Loads a controller and its helper libraries.
|
||||||
*
|
*
|
||||||
* @param string $name Name of controller
|
* @param string $name Name of controller
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
*/
|
*/
|
||||||
function loadController ($name)
|
function loadController ($name)
|
||||||
{
|
{
|
||||||
if(!class_exists('AppController'))
|
if(!class_exists('AppController'))
|
||||||
|
@ -176,44 +219,58 @@ function loadController ($name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists PHP files in given directory.
|
* Returns an array of filenames of PHP files in given directory.
|
||||||
*
|
*
|
||||||
* @param string $path Path to scan for files
|
* @param string $path Path to scan for files
|
||||||
* @return array List of files in directory
|
* @return array List of files in directory
|
||||||
*/
|
*/
|
||||||
function listClasses($path)
|
function listClasses($path)
|
||||||
{
|
{
|
||||||
$modules = new Folder($path);
|
$dir = opendir($path);
|
||||||
return $modules->find('(.+)\.php');
|
|
||||||
|
while (false !== ($file = readdir($dir)))
|
||||||
|
{
|
||||||
|
if ((substr($file, -3, 3) == 'php'))
|
||||||
|
{
|
||||||
|
$classes[] = $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($dir);
|
||||||
|
return $classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads configuration files
|
* Loads configuration files
|
||||||
*
|
*
|
||||||
* @return boolean Success
|
* @return boolean Success
|
||||||
*/
|
*/
|
||||||
function config ()
|
function config()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$count = count($args);
|
foreach ($args as $arg)
|
||||||
foreach ($args as $arg)
|
{
|
||||||
{
|
if (('database' == $arg) && file_exists(CONFIGS.$arg.'.php'))
|
||||||
if (('database' == $arg) && file_exists(CONFIGS.$arg.'.php'))
|
{
|
||||||
{
|
include_once(CONFIGS.$arg.'.php');
|
||||||
include_once(CONFIGS.$arg.'.php');
|
}
|
||||||
}
|
elseif (file_exists(CONFIGS.$arg.'.php'))
|
||||||
elseif (file_exists(CONFIGS.$arg.'.php'))
|
{
|
||||||
{
|
include_once (CONFIGS.$arg.'.php');
|
||||||
include_once (CONFIGS.$arg.'.php');
|
if (count($args) == 1)
|
||||||
if ($count == 1) return true;
|
{
|
||||||
}
|
return true;
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
if ($count == 1) return false;
|
else
|
||||||
}
|
{
|
||||||
}
|
if (count($args) == 1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -228,11 +285,11 @@ function config ()
|
||||||
*/
|
*/
|
||||||
function uses ()
|
function uses ()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
foreach ($args as $arg)
|
foreach ($args as $arg)
|
||||||
{
|
{
|
||||||
require_once(LIBS.strtolower($arg).'.php');
|
require_once(LIBS.low($arg).'.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,33 +300,39 @@ function uses ()
|
||||||
*/
|
*/
|
||||||
function vendor($name)
|
function vendor($name)
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
foreach ($args as $arg)
|
foreach ($args as $arg)
|
||||||
{
|
{
|
||||||
require_once(VENDORS.$arg.'.php');
|
require_once(VENDORS.$arg.'.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print out debug information about given variable.
|
* Prints out debug information about given variable.
|
||||||
*
|
*
|
||||||
* Only runs if DEBUG level is non-zero.
|
* Only runs if DEBUG level is non-zero.
|
||||||
*
|
*
|
||||||
* @param boolean $var Variable to show debug information for.
|
* @param boolean $var Variable to show debug information for.
|
||||||
* @param boolean $show_html If set to true, the method prints the debug data in a screen-friendly way.
|
* @param boolean $show_html If set to true, the method prints the debug data in a screen-friendly way.
|
||||||
*/
|
*/
|
||||||
function debug($var = false, $show_html = false)
|
function debug($var = false, $showHtml = false)
|
||||||
{
|
{
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
{
|
{
|
||||||
print "\n<pre>\n";
|
print "\n<pre>\n";
|
||||||
if ($show_html) $var = str_replace('<', '<', str_replace('>', '>', $var));
|
ob_start();
|
||||||
print_r($var);
|
print_r($var);
|
||||||
print "\n</pre>\n";
|
$var = ob_get_clean();
|
||||||
|
|
||||||
|
if ($showHtml)
|
||||||
|
{
|
||||||
|
$var = str_replace('<', '<', str_replace('>', '>', $var));
|
||||||
|
}
|
||||||
|
|
||||||
|
print "{$var}\n</pre>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!function_exists('getMicrotime'))
|
if (!function_exists('getMicrotime'))
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -289,71 +352,78 @@ if (!function_exists('sortByKey'))
|
||||||
/**
|
/**
|
||||||
* Sorts given $array by key $sortby.
|
* Sorts given $array by key $sortby.
|
||||||
*
|
*
|
||||||
* @param array $array
|
* @param array $array
|
||||||
* @param string $sortby
|
* @param string $sortby
|
||||||
* @param string $order Sort order asc/desc (ascending or descending).
|
* @param string $order Sort order asc/desc (ascending or descending).
|
||||||
* @param integer $type
|
* @param integer $type
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC)
|
function sortByKey(&$array, $sortby, $order='asc', $type=SORT_NUMERIC)
|
||||||
{
|
|
||||||
if (!is_array($array))
|
|
||||||
{
|
{
|
||||||
return null;
|
if (!is_array($array))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($array as $key => $val)
|
||||||
|
{
|
||||||
|
$sa[$key] = $val[$sortby];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($order == 'asc')
|
||||||
|
{
|
||||||
|
asort($sa, $type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
arsort($sa, $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($sa as $key=>$val)
|
||||||
|
{
|
||||||
|
$out[] = $array[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
}
|
}
|
||||||
foreach ($array as $key => $val)
|
|
||||||
{
|
|
||||||
$sa[$key] = $val[$sortby];
|
|
||||||
}
|
|
||||||
if($order == 'asc')
|
|
||||||
{
|
|
||||||
asort($sa, $type);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
arsort($sa, $type);
|
|
||||||
}
|
|
||||||
foreach ($sa as $key=>$val)
|
|
||||||
{
|
|
||||||
$out[] = $array[$key];
|
|
||||||
}
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!function_exists('array_combine'))
|
if (!function_exists('array_combine'))
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Combines given identical arrays by using the first array's values as keys,
|
* Combines given identical arrays by using the first array's values as keys,
|
||||||
* and the second one's values as values. (Implemented for back-compatibility with PHP4.)
|
* and the second one's values as values. (Implemented for back-compatibility
|
||||||
|
* with PHP4)
|
||||||
*
|
*
|
||||||
* @param array $a1
|
* @param array $a1
|
||||||
* @param array $a2
|
* @param array $a2
|
||||||
* @return mixed Outputs either combined array or false.
|
* @return mixed Outputs either combined array or false.
|
||||||
*/
|
*/
|
||||||
function array_combine($a1, $a2)
|
function array_combine($a1, $a2)
|
||||||
{
|
{
|
||||||
$a1 = array_values($a1);
|
$a1 = array_values($a1);
|
||||||
$a2 = array_values($a2);
|
$a2 = array_values($a2);
|
||||||
$c1 = count($a1);
|
$c1 = count($a1);
|
||||||
$c2 = count($a2);
|
$c2 = count($a2);
|
||||||
|
|
||||||
if ($c1 != $c2)
|
if ($c1 != $c2)
|
||||||
{
|
{
|
||||||
return false; // different lenghts
|
return false; // different lenghts
|
||||||
}
|
}
|
||||||
if ($c1 <= 0)
|
if ($c1 <= 0)
|
||||||
{
|
{
|
||||||
return false; // arrays are the same and both are empty
|
return false; // arrays are the same and both are empty
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = array();
|
$output = array();
|
||||||
for ($i = 0; $i < $c1; $i++)
|
|
||||||
{
|
for ($i = 0; $i < $c1; $i++)
|
||||||
$output[$a1[$i]] = $a2[$i];
|
{
|
||||||
|
$output[$a1[$i]] = $a2[$i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
}
|
}
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -368,7 +438,17 @@ function h($text)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of all the given parameters, making parameter lists shorter to write.
|
* Returns an array of all the given parameters.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* <code>
|
||||||
|
* a('a', 'b')
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* Would return:
|
||||||
|
* <code>
|
||||||
|
* array('a', 'b')
|
||||||
|
* </code>
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
@ -379,28 +459,46 @@ function a()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hierarchical arrays.
|
* Constructs associative array from pairs of arguments.
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* <code>
|
||||||
|
* aa('a','b')
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* Would return:
|
||||||
|
* <code>
|
||||||
|
* array('a'=>'b')
|
||||||
|
* </code>
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @todo Explain this method better.
|
*/
|
||||||
|
function aa()
|
||||||
|
{
|
||||||
|
$args = func_get_args();
|
||||||
|
|
||||||
|
for ($l = 0, $c = count($args); $l < $c; $l++)
|
||||||
|
{
|
||||||
|
if ($l+1 < count($args))
|
||||||
|
{
|
||||||
|
$a[$args[$l]] = $args[$l+1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$a[$args[$l]] = null;
|
||||||
|
}
|
||||||
|
$l++;
|
||||||
|
}
|
||||||
|
return $a;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Renamed to aa(). Version 0.10.
|
||||||
*/
|
*/
|
||||||
function ha()
|
function ha()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$count = count($args);
|
return call_user_func_array('aa', $args);
|
||||||
|
|
||||||
for($i=0 ; $i < $count ; $i++)
|
|
||||||
{
|
|
||||||
if($i+1 < $count)
|
|
||||||
{
|
|
||||||
$a[$args[$i]] = $args[$i+1];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$a[$args[$i]] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -413,12 +511,44 @@ function e($text)
|
||||||
echo $text;
|
echo $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method for strtolower().
|
||||||
|
*
|
||||||
|
* @param string $str String to lowercase
|
||||||
|
*/
|
||||||
|
function low($str)
|
||||||
|
{
|
||||||
|
return strtolower($str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method for strtoupper().
|
||||||
|
*
|
||||||
|
* @param string $str String to uppercase
|
||||||
|
*/
|
||||||
|
function up($str)
|
||||||
|
{
|
||||||
|
return strtoupper($str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method for str_replace().
|
||||||
|
*
|
||||||
|
* @param string $search String to be replaced
|
||||||
|
* @param string $replace String to insert
|
||||||
|
* @param string $subject String to search
|
||||||
|
*/
|
||||||
|
function r($search, $replace, $subject)
|
||||||
|
{
|
||||||
|
return str_replace($search, $replace, $subject);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print_r convenience function, which prints out <PRE> tags around
|
* Print_r convenience function, which prints out <PRE> tags around
|
||||||
* the output of given array. Similar to debug().
|
* the output of given array. Similar to debug().
|
||||||
*
|
*
|
||||||
* @see debug
|
* @see debug()
|
||||||
* @param array $var
|
* @param array $var
|
||||||
*/
|
*/
|
||||||
function pr($var)
|
function pr($var)
|
||||||
{
|
{
|
||||||
|
@ -433,19 +563,18 @@ function pr($var)
|
||||||
/**
|
/**
|
||||||
* Display parameter
|
* Display parameter
|
||||||
*
|
*
|
||||||
* @param mixed $p Parameter as string or array
|
* @param mixed $p Parameter as string or array
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function params($p)
|
function params($p)
|
||||||
{
|
{
|
||||||
|
if (!is_array($p) || count($p) == 0)
|
||||||
if(!is_array($p) || count($p) == 0)
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(is_array($p[0]) && count($p) == 1)
|
if (is_array($p[0]) && count($p) == 1)
|
||||||
{
|
{
|
||||||
return $p[0];
|
return $p[0];
|
||||||
}
|
}
|
||||||
|
@ -458,43 +587,183 @@ function params($p)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the REQUEST_URI from the server environment, or, failing that, constructs
|
* Returns the REQUEST_URI from the server environment, or, failing that,
|
||||||
* a new one, using the PHP_SELF constant and other variables.
|
* constructs a new one, using the PHP_SELF constant and other variables.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string URI
|
||||||
*/
|
*/
|
||||||
function setUri()
|
function setUri()
|
||||||
{
|
{
|
||||||
if (isset($_SERVER['REQUEST_URI']))
|
if (env('REQUEST_URI'))
|
||||||
{
|
{
|
||||||
$uri = $_SERVER['REQUEST_URI'];
|
$uri = env('REQUEST_URI');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (isset($_SERVER['argv']))
|
if (env('argv'))
|
||||||
{
|
{
|
||||||
$uri = $_SERVER['PHP_SELF'] .'/'. $_SERVER['argv'][0];
|
$uri = env('argv');
|
||||||
|
$uri = env('PHP_SELF') .'/'. $uri[0];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$uri = $_SERVER['PHP_SELF'] .'/'. $_SERVER['QUERY_STRING'];
|
$uri = env('PHP_SELF') .'/'. env('QUERY_STRING');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $uri;
|
return $uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
function gethost ($ip)
|
/**
|
||||||
|
* Gets an environment variable from available sources.
|
||||||
|
* Used as a backup if $_SERVER/$_ENV are disabled.
|
||||||
|
*
|
||||||
|
* @param string $key Environment variable name.
|
||||||
|
* @return string Environment variable setting.
|
||||||
|
*/
|
||||||
|
function env($key)
|
||||||
{
|
{
|
||||||
if (stristr(getenv('OS'), 'windows'))
|
if (isset($_SERVER[$key]))
|
||||||
{
|
{
|
||||||
$host = split('Name:',`nslookup $ip`);
|
return $_SERVER[$key];
|
||||||
return ( trim (isset($host[1]) ? str_replace ("\n".'Address: '.$ip, '', $host[1]) : $ip));
|
}
|
||||||
}
|
elseif (isset($_ENV[$key]))
|
||||||
else
|
{
|
||||||
{
|
return $_ENV[$key];
|
||||||
$host = `host $ip`;
|
}
|
||||||
return (($host ? end ( explode (' ', $host)) : $ip));
|
elseif (getenv($key) !== false)
|
||||||
}
|
{
|
||||||
|
return getenv($key);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('file_get_contents'))
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns contents of a file as a string.
|
||||||
|
*
|
||||||
|
* @param string $fileName Name of the file.
|
||||||
|
* @param boolean $useIncludePath Wheter the function should use the
|
||||||
|
* include path or not.
|
||||||
|
* @return mixed Boolean false or contents of required file.
|
||||||
|
*/
|
||||||
|
function file_get_contents($fileName, $useIncludePath = false)
|
||||||
|
{
|
||||||
|
$res = fopen($fileName, 'rb', $useIncludePath);
|
||||||
|
if ($res === false)
|
||||||
|
{
|
||||||
|
trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearstatcache();
|
||||||
|
|
||||||
|
if ($fileSize = @filesize($fileName))
|
||||||
|
{
|
||||||
|
$data = fread($res, $fileSize);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data = '';
|
||||||
|
while (!feof($res))
|
||||||
|
{
|
||||||
|
$data .= fread($res, 8192);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "$data\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('file_put_contents'))
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Writes data into file.
|
||||||
|
*
|
||||||
|
* If file exists, it will be overwritten. If data is an array, it will be
|
||||||
|
* join()ed with an empty string.
|
||||||
|
*
|
||||||
|
* @param string $fileName File name.
|
||||||
|
* @param mixed $data String or array.
|
||||||
|
*/
|
||||||
|
function file_put_contents($fileName, $data)
|
||||||
|
{
|
||||||
|
if (is_array($data))
|
||||||
|
{
|
||||||
|
$data = join('', $data);
|
||||||
|
}
|
||||||
|
$res = @fopen($fileName, 'xb');
|
||||||
|
if ($res)
|
||||||
|
{
|
||||||
|
@fwrite($res, $data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads/writes temporary data to cache files or session.
|
||||||
|
*
|
||||||
|
* @param string $path File path within /tmp to save the file.
|
||||||
|
* @param mixed $data The data to save to the temporary file.
|
||||||
|
* @param mixed $expires A valid strtotime string when the data expires.
|
||||||
|
* @param string $target The target of the cached data; either 'cache' or 'public'.
|
||||||
|
* @return mixed The contents of the temporary file.
|
||||||
|
*/
|
||||||
|
function cache($path, $data = null, $expires = '+1 day', $target = 'cache')
|
||||||
|
{
|
||||||
|
if (is_string($expires))
|
||||||
|
{
|
||||||
|
$expires = strtotime($expires);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (low($target))
|
||||||
|
{
|
||||||
|
case 'cache':
|
||||||
|
$filename = CACHE . $path;
|
||||||
|
break;
|
||||||
|
case 'public':
|
||||||
|
$filename = WWW_ROOT . $path;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$now = time();
|
||||||
|
$timediff = $expires - $now;
|
||||||
|
$filetime = @filemtime($filename);
|
||||||
|
|
||||||
|
if ($data == null)
|
||||||
|
{
|
||||||
|
// Read data from file
|
||||||
|
if (file_exists($filename) && $filetime !== false)
|
||||||
|
{
|
||||||
|
if ($filetime + $timediff < $now)
|
||||||
|
{
|
||||||
|
// File has expired
|
||||||
|
@unlink($filename);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data = file_get_contents($filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file_put_contents($filename, $data);
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a translated string if one is found,
|
||||||
|
* or the submitted message if not found.
|
||||||
|
*
|
||||||
|
* @param unknown_type $msg
|
||||||
|
* @param unknown_type $return
|
||||||
|
* @return unknown
|
||||||
|
* @todo Not implemented in 0.10.x.x
|
||||||
|
*/
|
||||||
|
function __($msg, $return = null)
|
||||||
|
{
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
?>
|
?>
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for file.
|
* Short description for file.
|
||||||
*
|
*
|
||||||
* In this file you set paths to different directories used by Cake.
|
* In this file you set paths to different directories used by Cake.
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -187,15 +187,19 @@ define ('PEAR', VENDORS.'Pear'.DS);
|
||||||
* Full url prefix
|
* Full url prefix
|
||||||
*/
|
*/
|
||||||
$s = null;
|
$s = null;
|
||||||
if ( (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] =='on' ))
|
$https = env('HTTPS');
|
||||||
{
|
if ( (isset($https) && $https =='on' ))
|
||||||
|
{
|
||||||
$s ='s';
|
$s ='s';
|
||||||
}
|
}
|
||||||
if (isset($_SERVER['HTTP_HOST']))
|
unset($https);
|
||||||
{
|
|
||||||
define('FULL_BASE_URL', 'http'.$s.'://'.$_SERVER['HTTP_HOST']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$httpHost = env('HTTP_HOST');
|
||||||
|
if (isset($httpHost))
|
||||||
|
{
|
||||||
|
define('FULL_BASE_URL', 'http'.$s.'://'.$httpHost);
|
||||||
|
}
|
||||||
|
unset($httpHost);
|
||||||
/**
|
/**
|
||||||
* Web path to the public images directory.
|
* Web path to the public images directory.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
/**
|
/**
|
||||||
* List of helpers to include
|
* List of helpers to include
|
||||||
*/
|
*/
|
||||||
uses('error_messages', 'router', DS.'controller'.DS.'controller');
|
uses('router', DS.'controller'.DS.'controller');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatcher translates URLs to controller-action-paramter triads.
|
* Dispatcher translates URLs to controller-action-paramter triads.
|
||||||
|
@ -123,7 +123,8 @@ class Dispatcher extends Object
|
||||||
{
|
{
|
||||||
if(preg_match('/([\\.]+)/',$ctrlName))
|
if(preg_match('/([\\.]+)/',$ctrlName))
|
||||||
{
|
{
|
||||||
$this->error404(strtolower($ctrlName),'Was not found on this server');
|
return $this->cakeError('error404',array(array('url' => strtolower($ctrlName),
|
||||||
|
'message' => 'Was not found on this server')));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -136,17 +137,8 @@ class Dispatcher extends Object
|
||||||
|
|
||||||
if ($missingController)
|
if ($missingController)
|
||||||
{
|
{
|
||||||
$controller =& new Controller();
|
return $this->cakeError('missingController',array(array('className' => Inflector::camelize($params['controller']."Controller"),
|
||||||
$params['action'] = 'missingController';
|
'webroot' => $this->webroot)));
|
||||||
if (empty($params['controller']))
|
|
||||||
{
|
|
||||||
$params['controller'] = "Controller";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$params['controller'] = Inflector::camelize($params['controller']."Controller");
|
|
||||||
}
|
|
||||||
$controller->missingController = $params['controller'];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -195,22 +187,25 @@ class Dispatcher extends Object
|
||||||
if((in_array('scaffold', array_keys($classVars))) && ($missingAction === true))
|
if((in_array('scaffold', array_keys($classVars))) && ($missingAction === true))
|
||||||
{
|
{
|
||||||
uses(DS.'controller'.DS.'scaffold');
|
uses(DS.'controller'.DS.'scaffold');
|
||||||
$scaffolding = new Scaffold($controller, $params);
|
return new Scaffold($controller, $params);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$controller->constructClasses();
|
$controller->constructClasses();
|
||||||
|
|
||||||
if ($missingAction)
|
if ($missingAction)
|
||||||
{
|
{
|
||||||
$controller->missingAction = $params['action'];
|
return $this->cakeError('missingAction',
|
||||||
$params['action'] = 'missingAction';
|
array(array('className' => Inflector::camelize($params['controller']."Controller"),
|
||||||
|
'action' => $params['action'],
|
||||||
|
'webroot' => $this->webroot)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($privateAction)
|
if ($privateAction)
|
||||||
{
|
{
|
||||||
$controller->privateAction = $params['action'];
|
return $this->cakeError('privateAction',
|
||||||
$params['action'] = 'privateAction';
|
array(array('className' => Inflector::camelize($params['controller']."Controller"),
|
||||||
|
'action' => $params['action'],
|
||||||
|
'webroot' => $this->webroot)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_invoke($controller, $params );
|
return $this->_invoke($controller, $params );
|
||||||
|
@ -249,18 +244,47 @@ class Dispatcher extends Object
|
||||||
include CONFIGS.'routes.php';
|
include CONFIGS.'routes.php';
|
||||||
$params = $Route->parse ($from_url);
|
$params = $Route->parse ($from_url);
|
||||||
|
|
||||||
// add submitted form data
|
if (ini_get('magic_quotes_gpc') == 1)
|
||||||
$params['form'] = $_POST;
|
|
||||||
if (isset($_POST['data']))
|
|
||||||
{
|
{
|
||||||
$params['data'] = (ini_get('magic_quotes_gpc') == 1)?
|
if(!empty($_POST))
|
||||||
$this->stripslashes_deep($_POST['data']) : $_POST['data'];
|
{
|
||||||
|
if(is_array($_POST))
|
||||||
|
{
|
||||||
|
$params['form'] = array_map('stripslashes', $_POST);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$params['form'] = stripcslashes($_POST);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$params['form'] = $_POST;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($params['form']['data']))
|
||||||
|
{
|
||||||
|
$params['data'] = $params['form']['data'];
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_GET))
|
if (isset($_GET))
|
||||||
{
|
{
|
||||||
$params['url'] = $this->urldecode_deep($_GET);
|
if (ini_get('magic_quotes_gpc') == 1)
|
||||||
$params['url'] = (ini_get('magic_quotes_gpc') == 1)?
|
{
|
||||||
$this->stripslashes_deep($params['url']) : $params['url'];
|
if(is_array($_GET))
|
||||||
|
{
|
||||||
|
$params['url'] = array_map('stripslashes', $_GET);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$params['url'] = stripcslashes($_GET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$params['url'] = $_GET;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($_FILES as $name => $data)
|
foreach ($_FILES as $name => $data)
|
||||||
|
@ -274,26 +298,6 @@ class Dispatcher extends Object
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively strips slashes from given array.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function stripslashes_deep($val)
|
|
||||||
{
|
|
||||||
return (is_array($val)) ?
|
|
||||||
array_map(array('Dispatcher','stripslashes_deep'), $val) : stripslashes($val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively performs urldecode on given array.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function urldecode_deep($val)
|
|
||||||
{
|
|
||||||
return (is_array($val)) ?
|
|
||||||
array_map(array('Dispatcher','urldecode_deep'), $val) : urldecode($val);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a base URL.
|
* Returns a base URL.
|
||||||
*
|
*
|
||||||
|
@ -309,8 +313,8 @@ class Dispatcher extends Object
|
||||||
$base = BASE_URL.$this->admin;
|
$base = BASE_URL.$this->admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
$docRoot = $_SERVER['DOCUMENT_ROOT'];
|
$docRoot = env('DOCUMENT_ROOT');
|
||||||
$scriptName = $_SERVER['PHP_SELF'];
|
$scriptName = env('PHP_SELF');
|
||||||
|
|
||||||
// If document root ends with 'webroot', it's probably correctly set
|
// If document root ends with 'webroot', it's probably correctly set
|
||||||
$r = null;
|
$r = null;
|
||||||
|
@ -361,36 +365,5 @@ class Dispatcher extends Object
|
||||||
}
|
}
|
||||||
return $base;
|
return $base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Displays an error page (e.g. 404 Not found).
|
|
||||||
*
|
|
||||||
* @param int $code Error code (e.g. 404)
|
|
||||||
* @param string $name Name of the error message (e.g. Not found)
|
|
||||||
* @param string $message
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function error ($code, $name, $message)
|
|
||||||
{
|
|
||||||
$controller =& new Controller ($this);
|
|
||||||
$controller->base = $this->base;
|
|
||||||
$controller->autoLayout = true;
|
|
||||||
$controller->set(array('code'=>$code, 'name'=>$name, 'message'=>$message));
|
|
||||||
$controller->pageTitle = $code.' '. $name;
|
|
||||||
return $controller->render('errors/error404');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience method to display a 404 page.
|
|
||||||
*
|
|
||||||
* @param string $url URL that spawned this message, to be included in the output.
|
|
||||||
* @param string $message Message text for the 404 page.
|
|
||||||
*/
|
|
||||||
function error404 ($url, $message)
|
|
||||||
{
|
|
||||||
header("HTTP/1.0 404 Not Found");
|
|
||||||
$this->error('404', 'Not found', sprintf(ERROR_404, $url, $message));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class collections.
|
* Class collections.
|
||||||
*
|
*
|
||||||
* A repository for class objects, each registered with a key.
|
* A repository for class objects, each registered with a key.
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
/**
|
/**
|
||||||
* Class Collections.
|
* Class Collections.
|
||||||
*
|
*
|
||||||
* A repository for class objects, each registered with a key.
|
* A repository for class objects, each registered with a key.
|
||||||
* If you try to add an object with the same key twice, nothing will come of it.
|
* If you try to add an object with the same key twice, nothing will come of it.
|
||||||
* If you need a second instance of an object, give it another key.
|
* If you need a second instance of an object, give it another key.
|
||||||
*
|
*
|
||||||
|
@ -39,9 +39,9 @@
|
||||||
* @subpackage cake.cake.libs
|
* @subpackage cake.cake.libs
|
||||||
* @since CakePHP v 0.9.2
|
* @since CakePHP v 0.9.2
|
||||||
*/
|
*/
|
||||||
class ClassRegistry
|
class ClassRegistry
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Names of classes with their objects.
|
* Names of classes with their objects.
|
||||||
*
|
*
|
||||||
|
@ -55,32 +55,33 @@
|
||||||
*
|
*
|
||||||
* @return ClassRegistry instance
|
* @return ClassRegistry instance
|
||||||
*/
|
*/
|
||||||
function &getInstance() {
|
function &getInstance()
|
||||||
|
{
|
||||||
static $instance = array();
|
static $instance = array();
|
||||||
if (!$instance)
|
if (!$instance)
|
||||||
{
|
{
|
||||||
$instance[0] =& new ClassRegistry;
|
$instance[0] =& new ClassRegistry;
|
||||||
}
|
}
|
||||||
return $instance[0];
|
return $instance[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add $object to the registry, associating it with the name $key.
|
* Add $object to the registry, associating it with the name $key.
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $object
|
* @param mixed $object
|
||||||
*/
|
*/
|
||||||
function addObject($key, &$object)
|
function addObject($key, &$object)
|
||||||
{
|
{
|
||||||
|
$_this =& ClassRegistry::getInstance();
|
||||||
$key = strtolower($key);
|
$key = strtolower($key);
|
||||||
|
|
||||||
if (array_key_exists($key, $this->_objects) === false)
|
if (array_key_exists($key, $_this->_objects) === false)
|
||||||
{
|
{
|
||||||
$this->_objects[$key] =& $object;
|
$_this->_objects[$key] =& $object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if given key is present in the ClassRegistry.
|
* Returns true if given key is present in the ClassRegistry.
|
||||||
*
|
*
|
||||||
|
@ -89,8 +90,9 @@
|
||||||
*/
|
*/
|
||||||
function isKeySet($key)
|
function isKeySet($key)
|
||||||
{
|
{
|
||||||
|
$_this =& ClassRegistry::getInstance();
|
||||||
$key = strtolower($key);
|
$key = strtolower($key);
|
||||||
return array_key_exists($key, $this->_objects);
|
return array_key_exists($key, $_this->_objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +104,8 @@
|
||||||
function &getObject($key)
|
function &getObject($key)
|
||||||
{
|
{
|
||||||
$key = strtolower($key);
|
$key = strtolower($key);
|
||||||
return $this->_objects[$key];
|
$_this =& ClassRegistry::getInstance();
|
||||||
|
return $_this->_objects[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access Control List factory class.
|
* Access Control List factory class.
|
||||||
*
|
*
|
||||||
* Permissions system.
|
* Permissions system.
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access Control List factory class.
|
* Access Control List factory class.
|
||||||
*
|
*
|
||||||
* Looks for ACL implementation class in core config, and returns an instance of that class.
|
* Looks for ACL implementation class in core config, and returns an instance of that class.
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -58,7 +58,7 @@ class AclComponent extends Object
|
||||||
*
|
*
|
||||||
* @return MyACL
|
* @return MyACL
|
||||||
*/
|
*/
|
||||||
function &getACL()
|
function &getACL()
|
||||||
{
|
{
|
||||||
if($this->_instance == null)
|
if($this->_instance == null)
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ class AclComponent extends Object
|
||||||
*/
|
*/
|
||||||
function _initACL()
|
function _initACL()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,4 +163,4 @@ class AclComponent extends Object
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Access Control List abstract class.
|
* Access Control List abstract class.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -29,14 +29,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Access Control List abstract class. Not to be instantiated.
|
||||||
*
|
|
||||||
* @return AclBase
|
|
||||||
*/
|
|
||||||
uses('error_messages');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Access Control List abstract class. Not to be instantiated.
|
|
||||||
* Subclasses of this class are used by AclComponent to perform ACL checks in Cake.
|
* Subclasses of this class are used by AclComponent to perform ACL checks in Cake.
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -57,7 +50,7 @@ class AclBase
|
||||||
//No instantiations or constructor calls (even statically)
|
//No instantiations or constructor calls (even statically)
|
||||||
if (strcasecmp(get_class($this), "AclBase") == 0 || !is_subclass_of($this, "AclBase"))
|
if (strcasecmp(get_class($this), "AclBase") == 0 || !is_subclass_of($this, "AclBase"))
|
||||||
{
|
{
|
||||||
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
|
trigger_error(__("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration."), E_USER_ERROR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,10 +63,8 @@ class AclBase
|
||||||
* @param unknown_type $aco
|
* @param unknown_type $aco
|
||||||
* @param unknown_type $action
|
* @param unknown_type $action
|
||||||
*/
|
*/
|
||||||
function check($aro, $aco, $action = "*")
|
function check($aro, $aco, $action = "*") {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -2,21 +2,21 @@
|
||||||
/* SVN FILE: $Id$ */
|
/* SVN FILE: $Id$ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is core configuration file.
|
* This is core configuration file.
|
||||||
*
|
*
|
||||||
* Use it to configure core behaviour ofCake.
|
* Use it to configure core behaviour ofCake.
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -43,7 +43,7 @@ uses('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aros_aco');
|
||||||
* @subpackage cake.cake.app.controllers.components.dbacl
|
* @subpackage cake.cake.app.controllers.components.dbacl
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DB_ACL extends AclBase
|
class DB_ACL extends AclBase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,9 +52,9 @@ class DB_ACL extends AclBase
|
||||||
*/
|
*/
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
|
@ -69,7 +69,7 @@ class DB_ACL extends AclBase
|
||||||
$Perms = new ArosAco();
|
$Perms = new ArosAco();
|
||||||
$Aro = new Aro();
|
$Aro = new Aro();
|
||||||
$Aco = new Aco();
|
$Aco = new Aco();
|
||||||
|
|
||||||
if($aro == null || $aco == null)
|
if($aro == null || $aco == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -85,11 +85,6 @@ class DB_ACL extends AclBase
|
||||||
trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()', E_USER_ERROR);
|
trigger_error('ACO permissions key "' . $action . '" does not exist in DB_ACL::check()', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($aroPath == false || $aroPath == null || count($aroPath) == 0 || $tmpAcoPath == false || $tmpAcoPath == null || count($tmpAcoPath) == 0)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($tmpAcoPath as $a)
|
foreach($tmpAcoPath as $a)
|
||||||
{
|
{
|
||||||
$acoPath[] = $a['Aco']['id'];
|
$acoPath[] = $a['Aco']['id'];
|
||||||
|
@ -195,7 +190,7 @@ class DB_ACL extends AclBase
|
||||||
$save['id'] = $perms['link'][0]['aros_acos']['id'];
|
$save['id'] = $perms['link'][0]['aros_acos']['id'];
|
||||||
}
|
}
|
||||||
//return $Perms->save(array('ArosAco' => $save));
|
//return $Perms->save(array('ArosAco' => $save));
|
||||||
|
|
||||||
if(isset($save['id']))
|
if(isset($save['id']))
|
||||||
{
|
{
|
||||||
$q = 'update aros_acos set ';
|
$q = 'update aros_acos set ';
|
||||||
|
@ -213,7 +208,7 @@ class DB_ACL extends AclBase
|
||||||
{
|
{
|
||||||
$q = 'insert into aros_acos (' . implode(', ', array_keys($save)) . ') values (' . implode(', ', $save) . ')';
|
$q = 'insert into aros_acos (' . implode(', ', array_keys($save)) . ') values (' . implode(', ', $save) . ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
$Perms->db->query($q);
|
$Perms->db->query($q);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -309,7 +304,7 @@ class DB_ACL extends AclBase
|
||||||
{
|
{
|
||||||
$Aro = new Aro();
|
$Aro = new Aro();
|
||||||
$Aco = new Aco();
|
$Aco = new Aco();
|
||||||
|
|
||||||
$qAro = (is_string($aro) ? "alias = '" . addslashes($aro) . "'" : "user_id = {$aro}");
|
$qAro = (is_string($aro) ? "alias = '" . addslashes($aro) . "'" : "user_id = {$aro}");
|
||||||
$qAco = (is_string($aco) ? "alias = '" . addslashes($aco) . "'" : "object_id = {$aco}");
|
$qAco = (is_string($aco) ? "alias = '" . addslashes($aco) . "'" : "object_id = {$aco}");
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
CREATE TABLE `acos` (
|
CREATE TABLE `acos` (
|
||||||
`id` int(11) NOT NULL auto_increment,
|
`id` int(11) NOT NULL auto_increment,
|
||||||
`model` varchar(255) NOT NULL default '',
|
`model` varchar(255) NOT NULL default '',
|
||||||
|
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for file.
|
* Short description for file.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -35,7 +35,7 @@ require_once(CAKE . 'app_model.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for file.
|
* Short description for file.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -44,7 +44,7 @@ require_once(CAKE . 'app_model.php');
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class AclNode extends AppModel
|
class AclNode extends AppModel
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -56,36 +56,29 @@ class AclNode extends AppModel
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function __construct($object = null, $parent = null)
|
function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->__setTable();
|
$this->__setTable();
|
||||||
if($object != null)
|
|
||||||
{
|
|
||||||
$this->create($object, $parent);
|
|
||||||
}
|
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $object A new ACL object. This can be a string for alias-based ACL, or a Model for object-based ACL
|
* @param unknown_type $link_id
|
||||||
* @param unknown_type $parent The parent object
|
* @param unknown_type $parent_id
|
||||||
|
* @param unknown_type $alias
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function create($object = null, $parent = null)
|
function create($link_id = 0, $parent_id = null, $alias = '')
|
||||||
{
|
{
|
||||||
if (strtolower(get_class($this)) == "aclnode")
|
|
||||||
{
|
|
||||||
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
parent::create();
|
parent::create();
|
||||||
|
|
||||||
pr($this->__dataVars());
|
if (strtolower(get_class($this)) == "aclnode")
|
||||||
exit();
|
{
|
||||||
|
trigger_error(__("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration."), E_USER_ERROR);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
extract($this->__dataVars());
|
extract($this->__dataVars());
|
||||||
|
|
||||||
if($parent_id == null || $parent_id === 0)
|
if($parent_id == null || $parent_id === 0)
|
||||||
|
@ -134,7 +127,7 @@ class AclNode extends AppModel
|
||||||
{
|
{
|
||||||
if (strtolower(get_class($this)) == "aclnode")
|
if (strtolower(get_class($this)) == "aclnode")
|
||||||
{
|
{
|
||||||
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
|
trigger_error(__("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration."), E_USER_ERROR);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
extract($this->__dataVars());
|
extract($this->__dataVars());
|
||||||
|
@ -213,16 +206,16 @@ class AclNode extends AppModel
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The path to a node as an array, where the first element of the array is at the root of the tree, and the last element is the requested node
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param mixed $id
|
* @param unknown_type $id
|
||||||
* @return array
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function getPath($id)
|
function getPath($id)
|
||||||
{
|
{
|
||||||
if (strtolower(get_class($this)) == "aclnode")
|
if (strtolower(get_class($this)) == "aclnode")
|
||||||
{
|
{
|
||||||
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
|
trigger_error(__("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration."), E_USER_ERROR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
extract($this->__dataVars());
|
extract($this->__dataVars());
|
||||||
|
@ -236,16 +229,16 @@ class AclNode extends AppModel
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the child nodes of a specified element
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param mixed $id
|
* @param unknown_type $id
|
||||||
* @return array
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function getChildren($id)
|
function getChildren($id)
|
||||||
{
|
{
|
||||||
if (strtolower(get_class($this)) == "aclnode")
|
if (strtolower(get_class($this)) == "aclnode")
|
||||||
{
|
{
|
||||||
trigger_error(ERROR_ABSTRACT_CONSTRUCTION, E_USER_ERROR);
|
trigger_error(__("[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration."), E_USER_ERROR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
extract($this->__dataVars());
|
extract($this->__dataVars());
|
||||||
|
@ -255,57 +248,32 @@ class AclNode extends AppModel
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a reference to a node object
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param unknown_type $obj
|
* @param unknown_type $id
|
||||||
* @param unknown_type $fKey
|
* @param unknown_type $fKey
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function _resolveID($obj, $fKey)
|
function _resolveID($id, $fKey)
|
||||||
{
|
{
|
||||||
extract($this->__dataVars());
|
|
||||||
if(is_object($obj))
|
|
||||||
{
|
|
||||||
if(isset($obj->id) && isset($obj->name))
|
|
||||||
{
|
|
||||||
return "model = '{$obj->name}' and {$secondary_id} = {$obj->id}";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else if(is_array($obj))
|
|
||||||
{
|
|
||||||
$keys = array_keys($obj);
|
|
||||||
$key1 = $keys[0];
|
|
||||||
if(is_string($key1) && is_array($obj[$key1]) && isset($obj[$key1]['id']))
|
|
||||||
{
|
|
||||||
return "model = '{$key1}' and {$secondary_id} = {$obj[$key1]['id']}";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else if(is_string($obj))
|
|
||||||
{
|
|
||||||
$path = explode('/', $obj);
|
|
||||||
|
|
||||||
}
|
|
||||||
$key = (is_string($id) ? 'alias' : $fKey);
|
$key = (is_string($id) ? 'alias' : $fKey);
|
||||||
$val = (is_string($id) ? '"' . addslashes($id) . '"' : $id);
|
$val = (is_string($id) ? '"' . addslashes($id) . '"' : $id);
|
||||||
return "{$key} = {$val}";
|
return "{$key} = {$val}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private method: modifies the left and right values of affected nodes in a tree when a node is added or removed
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param string $table aros or acos, depending on the tree to be modified
|
* @param unknown_type $table
|
||||||
* @param int $dir The direction in which to shift the nodes
|
* @param unknown_type $dir
|
||||||
* @param int $lft The left position of the node being added or removed
|
* @param unknown_type $lft
|
||||||
* @param int $rght The right position of the node being added or removed
|
* @param unknown_type $rght
|
||||||
*/
|
*/
|
||||||
function _syncTable($table, $dir, $lft, $rght)
|
function _syncTable($table, $dir, $lft, $rght)
|
||||||
{
|
{
|
||||||
$shift = ($dir == 2 ? 1 : 2);
|
$shift = ($dir == 2 ? 1 : 2);
|
||||||
$table = strtolower($table);
|
$this->db->query("UPDATE $table SET rght = rght " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE rght > " . $rght);
|
||||||
$this->db->query("UPDATE {$table} SET rght = rght " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE rght > " . $rght);
|
$this->db->query("UPDATE $table SET lft = lft " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE lft > " . $lft);
|
||||||
$this->db->query("UPDATE {$table} SET lft = lft " . ($dir > 0 ? "+" : "-") . " {$shift} WHERE lft > " . $lft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for file.
|
* Short description for file.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for file.
|
* Short description for file.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class Aco extends AclNode
|
class Aco extends AclNode
|
||||||
{
|
{
|
||||||
var $name = 'Aco';
|
var $name = 'Aco';
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for file.
|
* Short description for file.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -36,7 +36,7 @@ require_once(CAKE.'app_model.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for file.
|
* Short description for file.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
|
|
|
@ -149,14 +149,6 @@ class Controller extends Object
|
||||||
*/
|
*/
|
||||||
var $autoLayout = true;
|
var $autoLayout = true;
|
||||||
|
|
||||||
/**
|
|
||||||
* Database configuration to use (see /config/database.php)
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $useDbConfig = 'default';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
|
@ -218,9 +210,6 @@ class Controller extends Object
|
||||||
*/
|
*/
|
||||||
function constructClasses()
|
function constructClasses()
|
||||||
{
|
{
|
||||||
$dboFactory = DboFactory::getInstance($this->useDbConfig);
|
|
||||||
$this->db =& $dboFactory;
|
|
||||||
|
|
||||||
if (!empty($this->components))
|
if (!empty($this->components))
|
||||||
{
|
{
|
||||||
$component =& new Component($this);
|
$component =& new Component($this);
|
||||||
|
@ -263,11 +252,6 @@ class Controller extends Object
|
||||||
}
|
}
|
||||||
elseif ($this->uses)
|
elseif ($this->uses)
|
||||||
{
|
{
|
||||||
if (!$this->db)
|
|
||||||
{
|
|
||||||
die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
|
|
||||||
}
|
|
||||||
|
|
||||||
$uses = is_array($this->uses)? $this->uses: array($this->uses);
|
$uses = is_array($this->uses)? $this->uses: array($this->uses);
|
||||||
|
|
||||||
foreach ($uses as $modelClass)
|
foreach ($uses as $modelClass)
|
||||||
|
@ -281,7 +265,8 @@ class Controller extends Object
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
die("Controller::__construct() : ".ucfirst($this->name)." requires missing model {$modelClass}, exiting.");
|
return $this->cakeError('missingTable',array(array('className' => $modelClass,
|
||||||
|
'webroot' => '')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -494,11 +479,10 @@ class Controller extends Object
|
||||||
|
|
||||||
$model = $this->modelClass;
|
$model = $this->modelClass;
|
||||||
$modelKey = $this->modelKey;
|
$modelKey = $this->modelKey;
|
||||||
$table = $this->{$model}->table;
|
$table = $this->{$model}->source;
|
||||||
$association = array_search($table,$this->{$model}->alias);
|
$association = array_search($table,$this->{$model}->alias);
|
||||||
|
|
||||||
$classRegistry =& ClassRegistry::getInstance();
|
$objRegistryModel = ClassRegistry::getObject($modelKey);
|
||||||
$objRegistryModel = $classRegistry->getObject($modelKey);
|
|
||||||
|
|
||||||
foreach ($objRegistryModel->_tableInfo as $tables)
|
foreach ($objRegistryModel->_tableInfo as $tables)
|
||||||
{
|
{
|
||||||
|
@ -506,7 +490,7 @@ class Controller extends Object
|
||||||
{
|
{
|
||||||
$alias = null;
|
$alias = null;
|
||||||
// set up the prompt
|
// set up the prompt
|
||||||
if( $objRegistryModel->isForeignKey($tabl['name']) )
|
if ($objRegistryModel->isForeignKey($tabl['name']))
|
||||||
{
|
{
|
||||||
$niceName = substr( $tabl['name'], 0, strpos( $tabl['name'], "_id" ) );
|
$niceName = substr( $tabl['name'], 0, strpos( $tabl['name'], "_id" ) );
|
||||||
$fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($niceName);
|
$fieldNames[ $tabl['name'] ]['prompt'] = Inflector::humanize($niceName);
|
||||||
|
@ -541,7 +525,7 @@ class Controller extends Object
|
||||||
$fieldNames[ $tabl['name']]['tagName'] = $model.'/'.$tabl['name'];
|
$fieldNames[ $tabl['name']]['tagName'] = $model.'/'.$tabl['name'];
|
||||||
|
|
||||||
// Now, find out if this is a required field.
|
// Now, find out if this is a required field.
|
||||||
//$validationFields = $classRegistry->getObject($table)->validate;
|
//$validationFields = ClassRegistry::getObject($table)->validate;
|
||||||
$validationFields = $objRegistryModel->validate;
|
$validationFields = $objRegistryModel->validate;
|
||||||
if( isset( $validationFields[ $tabl['name'] ] ) )
|
if( isset( $validationFields[ $tabl['name'] ] ) )
|
||||||
{
|
{
|
||||||
|
@ -580,29 +564,28 @@ class Controller extends Object
|
||||||
case "varchar":
|
case "varchar":
|
||||||
case "char":
|
case "char":
|
||||||
{
|
{
|
||||||
if( isset( $fieldNames[ $tabl['name']]['foreignKey'] ) )
|
if (isset($fieldNames[ $tabl['name']]['foreignKey']))
|
||||||
{
|
{
|
||||||
$fieldNames[ $tabl['name']]['type'] = 'select';
|
$fieldNames[ $tabl['name']]['type'] = 'select';
|
||||||
// This is a foreign key select dropdown box. now, we have to add the options.
|
// This is a foreign key select dropdown box. now, we have to add the options.
|
||||||
$fieldNames[ $tabl['name']]['options'] = array();
|
$fieldNames[ $tabl['name']]['options'] = array();
|
||||||
|
|
||||||
// get the list of options from the other model.
|
// get the list of options from the other model.
|
||||||
$registry = ClassRegistry::getInstance();
|
$otherModel = ClassRegistry::getObject(Inflector::underscore($fieldNames[$tabl['name']]['modelKey']));
|
||||||
$otherModel = $registry->getObject(Inflector::underscore($fieldNames[$tabl['name']]['modelKey']));
|
|
||||||
|
|
||||||
if( is_object($otherModel) )
|
if (is_object($otherModel))
|
||||||
{
|
{
|
||||||
if( $doCreateOptions )
|
if ($doCreateOptions)
|
||||||
{
|
{
|
||||||
$otherDisplayField = $otherModel->getDisplayField();
|
$otherDisplayField = $otherModel->getDisplayField();
|
||||||
foreach( $otherModel->findAll() as $pass )
|
foreach ($otherModel->findAll() as $pass)
|
||||||
{
|
{
|
||||||
foreach( $pass as $key=>$value )
|
foreach ($pass as $key => $value)
|
||||||
{
|
{
|
||||||
|
|
||||||
if( $alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value[$otherModel->primaryKey] ) && isset( $value[$otherDisplayField] ) )
|
if($alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value['id'] ) && isset( $value[$otherDisplayField]))
|
||||||
{
|
{
|
||||||
$fieldNames[ $tabl['name']]['options'][$value[$otherModel->primaryKey]] = $value[$otherDisplayField];
|
$fieldNames[ $tabl['name']]['options'][$value['id']] = $value[$otherDisplayField];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -641,7 +624,7 @@ class Controller extends Object
|
||||||
// for foreign key autonumber fields, we'll set the type to 'key' so that it does not display in the input form.
|
// for foreign key autonumber fields, we'll set the type to 'key' so that it does not display in the input form.
|
||||||
|
|
||||||
$charCount = strlen($this->$model->primaryKey);
|
$charCount = strlen($this->$model->primaryKey);
|
||||||
if( 0 == strncmp($tabl['name'], $this->$model->primaryKey, $charCount) )
|
if(0 == strncmp($tabl['name'], $this->$model->primaryKey, $charCount))
|
||||||
{
|
{
|
||||||
$fieldNames[ $tabl['name']]['type'] = 'hidden';
|
$fieldNames[ $tabl['name']]['type'] = 'hidden';
|
||||||
}
|
}
|
||||||
|
@ -652,19 +635,18 @@ class Controller extends Object
|
||||||
$fieldNames[ $tabl['name']]['options'] = array();
|
$fieldNames[ $tabl['name']]['options'] = array();
|
||||||
|
|
||||||
// get the list of options from the other model.
|
// get the list of options from the other model.
|
||||||
$registry = ClassRegistry::getInstance();
|
$otherModel = ClassRegistry::getObject(Inflector::underscore($fieldNames[$tabl['name']]['modelKey']));
|
||||||
$otherModel = $registry->getObject(Inflector::underscore($fieldNames[$tabl['name']]['modelKey']));
|
|
||||||
|
|
||||||
if( is_object($otherModel) )
|
if( is_object($otherModel) )
|
||||||
{
|
{
|
||||||
if( $doCreateOptions )
|
if( $doCreateOptions )
|
||||||
{
|
{
|
||||||
$otherDisplayField = $otherModel->getDisplayField();
|
$otherDisplayField = $otherModel->getDisplayField();
|
||||||
foreach( $otherModel->findAll() as $pass )
|
foreach($otherModel->findAll() as $pass)
|
||||||
{
|
{
|
||||||
foreach( $pass as $key=>$value )
|
foreach($pass as $key => $value)
|
||||||
{
|
{
|
||||||
if( $alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset( $value[$otherModel->primaryKey] ) && isset( $value[$otherDisplayField] ) )
|
if( $alias.$key == $this->{$model}->tableToModel[$fieldNames[ $tabl['name'] ]['table']] && isset($value[$otherModel->primaryKey]) && isset($value[$otherDisplayField]))
|
||||||
{
|
{
|
||||||
$fieldNames[ $tabl['name']]['options'][$value[$otherModel->primaryKey]] = $value[$otherDisplayField];
|
$fieldNames[ $tabl['name']]['options'][$value[$otherModel->primaryKey]] = $value[$otherDisplayField];
|
||||||
}
|
}
|
||||||
|
@ -700,15 +682,17 @@ class Controller extends Object
|
||||||
case "date":
|
case "date":
|
||||||
case "datetime":
|
case "datetime":
|
||||||
{
|
{
|
||||||
if( 0 != strncmp( "created", $tabl['name'], 6 ) && 0 != strncmp("modified",$tabl['name'], 8) )
|
if(0 != strncmp( "created", $tabl['name'], 6 ) && 0 != strncmp("modified",$tabl['name'], 8))
|
||||||
$fieldNames[ $tabl['name']]['type'] = $type;
|
{
|
||||||
|
$fieldNames[ $tabl['name']]['type'] = $type;
|
||||||
|
}
|
||||||
if(isset($data[$model][$tabl['name']]))
|
if(isset($data[$model][$tabl['name']]))
|
||||||
{
|
{
|
||||||
$fieldNames[ $tabl['name']]['selected'] = $data[$model][$tabl['name']];
|
$fieldNames[ $tabl['name']]['selected'] = $data[$model][$tabl['name']];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$fieldNames[ $tabl['name']]['selected'] = null;
|
$ieldNames[ $tabl['name']]['selected'] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -721,14 +705,14 @@ class Controller extends Object
|
||||||
}
|
}
|
||||||
// now, add any necessary hasAndBelongsToMany list boxes
|
// now, add any necessary hasAndBelongsToMany list boxes
|
||||||
// loop through the many to many relations to make a list box.
|
// loop through the many to many relations to make a list box.
|
||||||
foreach( $objRegistryModel->_manyToMany as $relation )
|
foreach($objRegistryModel->hasAndBelongsToMany as $relation => $relData)
|
||||||
{
|
{
|
||||||
//list($modelName) = $relation;
|
$modelName = $relData['className'];
|
||||||
list($manyAssociation, $modelName, $value) = $relation;
|
$manyAssociation = $relation;
|
||||||
$modelKeyM = Inflector::underscore($modelName);
|
$modelKeyM = Inflector::underscore($modelName);
|
||||||
$modelObject = new $modelName();
|
$modelObject = new $modelName();
|
||||||
|
|
||||||
if( $doCreateOptions )
|
if($doCreateOptions)
|
||||||
{
|
{
|
||||||
$otherDisplayField = $modelObject->getDisplayField();
|
$otherDisplayField = $modelObject->getDisplayField();
|
||||||
$fieldNames[$modelKeyM]['model'] = $modelName;
|
$fieldNames[$modelKeyM]['model'] = $modelName;
|
||||||
|
@ -736,11 +720,11 @@ class Controller extends Object
|
||||||
$fieldNames[$modelKeyM]['type'] = "selectMultiple";
|
$fieldNames[$modelKeyM]['type'] = "selectMultiple";
|
||||||
$fieldNames[$modelKeyM]['tagName'] = $manyAssociation.'/'.$manyAssociation;
|
$fieldNames[$modelKeyM]['tagName'] = $manyAssociation.'/'.$manyAssociation;
|
||||||
|
|
||||||
foreach( $modelObject->findAll() as $pass )
|
foreach($modelObject->findAll() as $pass)
|
||||||
{
|
{
|
||||||
foreach( $pass as $key=>$value )
|
foreach($pass as $key=>$value)
|
||||||
{
|
{
|
||||||
if( $key == $modelName && isset( $value[$modelObject->primaryKey] ) && isset( $value[$otherDisplayField] ) )
|
if($key == $modelName && isset($value[$modelObject->primaryKey]) && isset( $value[$otherDisplayField]))
|
||||||
{
|
{
|
||||||
$fieldNames[$modelKeyM]['options'][$value[$modelObject->primaryKey]] = $value[$otherDisplayField];
|
$fieldNames[$modelKeyM]['options'][$value[$modelObject->primaryKey]] = $value[$otherDisplayField];
|
||||||
}
|
}
|
||||||
|
@ -759,6 +743,6 @@ class Controller extends Object
|
||||||
|
|
||||||
return $fieldNames;
|
return $fieldNames;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
?>
|
?>
|
|
@ -356,65 +356,61 @@ class Scaffold extends Object {
|
||||||
$this->controllerClass->helpers[] = 'Form';
|
$this->controllerClass->helpers[] = 'Form';
|
||||||
}
|
}
|
||||||
|
|
||||||
$isDataBaseSet = DboFactory::getInstance($this->controllerClass->useDbConfig);
|
$this->controllerClass->constructClasses();
|
||||||
if(!empty($isDataBaseSet))
|
if(isset($this->controllerClass->{$this->modelKey}->ds))
|
||||||
{
|
{
|
||||||
$this->controllerClass->constructClasses();
|
|
||||||
|
|
||||||
if($params['action'] === 'index' || $params['action'] === 'list' ||
|
if($params['action'] === 'index' || $params['action'] === 'list' ||
|
||||||
$params['action'] === 'show' || $params['action'] === 'add' ||
|
$params['action'] === 'show' || $params['action'] === 'add' ||
|
||||||
$params['action'] === 'create' || $params['action'] === 'edit' ||
|
$params['action'] === 'create' || $params['action'] === 'edit' ||
|
||||||
$params['action'] === 'update' || $params['action'] === 'destroy')
|
$params['action'] === 'update' || $params['action'] === 'destroy')
|
||||||
{
|
{
|
||||||
switch ($params['action'])
|
switch ($params['action'])
|
||||||
{
|
{
|
||||||
case 'index':
|
case 'index':
|
||||||
$this->_scaffoldIndex($params);
|
$this->_scaffoldIndex($params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'show':
|
case 'show':
|
||||||
$this->_scaffoldShow($params);
|
$this->_scaffoldShow($params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'list':
|
case 'list':
|
||||||
$this->_scaffoldList($params);
|
$this->_scaffoldList($params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'add':
|
case 'add':
|
||||||
$this->_scaffoldNew($params);
|
$this->_scaffoldNew($params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'edit':
|
case 'edit':
|
||||||
$this->_scaffoldEdit($params);
|
$this->_scaffoldEdit($params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'create':
|
case 'create':
|
||||||
$this->_scaffoldCreate($params);
|
$this->_scaffoldCreate($params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'update':
|
case 'update':
|
||||||
$this->_scaffoldUpdate($params);
|
$this->_scaffoldUpdate($params);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'destroy':
|
case 'destroy':
|
||||||
$this->_scaffoldDestroy($params);
|
$this->_scaffoldDestroy($params);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->controllerClass->layout = 'default';
|
return $this->cakeError('missingAction',
|
||||||
$this->controllerClass->missingAction = $params['action'];
|
array(array('className' => Inflector::camelize($params['controller']."Controller"),
|
||||||
call_user_func_array(array($this->controllerClass, 'missingAction'), null);
|
'action' => $params['action'],
|
||||||
exit;
|
'webroot' => $this->controllerClass->webroot)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->controllerClass->constructClasses();
|
return $this->cakeError('missingDatabase',
|
||||||
$this->controllerClass->layout = 'default';
|
array(array('webroot' => $this->controllerClass->webroot)));
|
||||||
call_user_func_array(array($this->controllerClass, 'missingDatabase'), null);
|
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
207
cake/libs/error.php
Normal file
207
cake/libs/error.php
Normal file
|
@ -0,0 +1,207 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs
|
||||||
|
* @since CakePHP v 0.10.5.1732
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs
|
||||||
|
* @since CakePHP v 0.10.5.1732
|
||||||
|
*/
|
||||||
|
class ErrorHandler extends Object
|
||||||
|
{
|
||||||
|
var $controller = null;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*/
|
||||||
|
function __construct($method, $messages)
|
||||||
|
{
|
||||||
|
$this->controller =& new Controller();
|
||||||
|
if(DEBUG > 0)
|
||||||
|
{
|
||||||
|
call_user_func_array(array(&$this, $method), $messages);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
call_user_func_array(array(&$this, 'error404'), $messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays an error page (e.g. 404 Not found).
|
||||||
|
*
|
||||||
|
* @param int $code Error code (e.g. 404)
|
||||||
|
* @param string $name Name of the error message (e.g. Not found)
|
||||||
|
* @param string $message
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function error ($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
$this->controller->webroot = $this->_webroot();
|
||||||
|
$this->controller->set(array('code'=>$code,
|
||||||
|
'name'=>$name,
|
||||||
|
'message'=>$message,
|
||||||
|
'title' => $code.' '. $name));
|
||||||
|
$this->controller->render('../errors/error404');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to display a 404 page.
|
||||||
|
*
|
||||||
|
* @param string $url URL that spawned this message, to be included in the output.
|
||||||
|
* @param string $message Message text for the 404 page.
|
||||||
|
*/
|
||||||
|
function error404 ($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
if(!isset($url))
|
||||||
|
{
|
||||||
|
$url = $action;
|
||||||
|
}
|
||||||
|
if(!isset($message))
|
||||||
|
{
|
||||||
|
$message = '';
|
||||||
|
}
|
||||||
|
header("HTTP/1.0 404 Not Found");
|
||||||
|
$this->error(array('code'=>'404',
|
||||||
|
'name'=>'Not found',
|
||||||
|
'message'=>sprintf(__("The requested address %s was not found on this server."), $url, $message)));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the Missing Controller web page.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function missingController($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
$this->controller->webroot = $webroot;
|
||||||
|
$this->controller->set(array('controller' => $className,
|
||||||
|
'title' => 'Missing Controller'));
|
||||||
|
$this->controller->render('../errors/missingController');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the Missing Action web page.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function missingAction($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
$this->controller->webroot = $webroot;
|
||||||
|
$this->controller->set(array('controller' => $className,
|
||||||
|
'action' => $action,
|
||||||
|
'title' => 'Missing Method in Controller'));
|
||||||
|
$this->controller->render('../errors/missingAction');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the Private Action web page.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function privateAction($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
$this->controller->webroot = $webroot;
|
||||||
|
$this->controller->set(array('controller' => $className,
|
||||||
|
'action' => $action,
|
||||||
|
'title' => 'Trying to access private method in class'));
|
||||||
|
$this->controller->render('../errors/privateAction');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the Missing Table web page.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function missingTable($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
$this->controller->webroot = $this->_webroot();
|
||||||
|
$this->controller->set(array('model' => $className,
|
||||||
|
'table' => $table,
|
||||||
|
'title' => 'Missing Database Table'));
|
||||||
|
$this->controller->render('../errors/missingTable');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the Missing Database web page.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function missingDatabase($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
$this->controller->webroot = $webroot;
|
||||||
|
$this->controller->set(array('title' => 'Scaffold Missing Database Connection'));
|
||||||
|
$this->controller->render('../errors/missingScaffolddb');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the Missing View web page.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function missingView($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
$this->controller->webroot = $webroot;
|
||||||
|
$this->controller->set(array('controller' => $className,
|
||||||
|
'action' => $action,
|
||||||
|
'title' => 'Missing View'));
|
||||||
|
$this->controller->render('../errors/missingView');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the Missing Table web page.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function missingConnection($params)
|
||||||
|
{
|
||||||
|
extract($params);
|
||||||
|
$this->controller->webroot = $this->_webroot();
|
||||||
|
$this->controller->set(array('model' => $className,
|
||||||
|
'title' => 'Missing Database Connection'));
|
||||||
|
$this->controller->render('../errors/missingConnection');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function _webroot()
|
||||||
|
{
|
||||||
|
$dispatcher =& new Dispatcher();
|
||||||
|
$dispatcher->baseUrl();
|
||||||
|
return $dispatcher->webroot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -1,117 +0,0 @@
|
||||||
<?php
|
|
||||||
/* SVN FILE: $Id$ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error Messages Defines
|
|
||||||
*
|
|
||||||
* Longer, human-readable error messages for Cake operation errors to be displayed
|
|
||||||
* to end-users.
|
|
||||||
*
|
|
||||||
* PHP versions 4 and 5
|
|
||||||
*
|
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
|
||||||
* Las Vegas, Nevada 89104
|
|
||||||
*
|
|
||||||
* Licensed under The MIT License
|
|
||||||
* Redistributions of files must retain the above copyright notice.
|
|
||||||
*
|
|
||||||
* @filesource
|
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
|
||||||
* @package cake
|
|
||||||
* @subpackage cake.cake.libs
|
|
||||||
* @since CakePHP v 0.2.9
|
|
||||||
* @version $Revision$
|
|
||||||
* @modifiedby $LastChangedBy$
|
|
||||||
* @lastmodified $Date$
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for when the specified database driver can not be found.
|
|
||||||
*/
|
|
||||||
define ('ERROR_UNKNOWN_DATABASE_DRIVER', '[DbFactory] Specified database driver (%s) not found');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for when the dispatcher can not find a default controller.
|
|
||||||
*/
|
|
||||||
define ('ERROR_NO_CONTROLLER_SET', '[Dispatcher] No default controller, can\'t continue, check routes config');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for when the dispatcher can not find a default action.
|
|
||||||
*/
|
|
||||||
define ('ERROR_NO_ACTION_SET', '[Dispatcher] No default action, can\'t continue, check routes config');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for when the dispatcher can not find given controller.
|
|
||||||
*/
|
|
||||||
define ('ERROR_UNKNOWN_CONTROLLER', '[Dispatcher] Specified controller "%s" doesn\'t exist, create it first');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for when the dispatcher can not find expected action in controller.
|
|
||||||
*/
|
|
||||||
define ('ERROR_NO_ACTION', '[Dispatcher] Action "%s" is not defined in the "%s" controller, create it first');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for errors in view.
|
|
||||||
*/
|
|
||||||
define ('ERROR_IN_VIEW', '[Controller] Error in view "%s", got: <blockquote>%s</blockquote>');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for when the controller can not find expected view.
|
|
||||||
*/
|
|
||||||
define ('ERROR_NO_VIEW', '[Controller] No template file for view "%s" (expected "%s"), create it first');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for errors in layout.
|
|
||||||
*/
|
|
||||||
define ('ERROR_IN_LAYOUT', '[Controller] Error in layout "%s", got: <blockquote>"%s"</blockquote>');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for when the controller can not find expected layout.
|
|
||||||
*/
|
|
||||||
define ('ERROR_NO_LAYOUT', '[Controller] Couln\'t find layout "%s" (expected "%s"), create it first');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for database not being able to access the table list.
|
|
||||||
*/
|
|
||||||
define ('ERROR_NO_TABLE_LIST', '[Database] Couldn\'t get table list, check database config');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for no corresponding database table found for model.
|
|
||||||
*/
|
|
||||||
define ('ERROR_NO_MODEL_TABLE', '[Model] No DB table for model "%s" (expected "%s"), create it first');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for Field not present in table.
|
|
||||||
*/
|
|
||||||
define ('ERROR_NO_FIELD_IN_MODEL_DB', '[Model::set()] Field "%s" is not present in table "%s", check database schema');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string short short error message.
|
|
||||||
*/
|
|
||||||
define ('SHORT_ERROR_MESSAGE', '<div class="error_message">%s</div>');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for when original image can not be loaded.
|
|
||||||
*/
|
|
||||||
define ('ERROR_CANT_GET_ORIGINAL_IMAGE', '[Image] Couldn\'t load original image %s (tried from "%s")');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for error 404.
|
|
||||||
*/
|
|
||||||
define ('ERROR_404', "The requested address /%s was not found on this server."); // second %s contains short error message
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for error 500.
|
|
||||||
*/
|
|
||||||
define ('ERROR_500', "Application error, sorry.");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Error string for attempted construction of an abstract class
|
|
||||||
*/
|
|
||||||
define ('ERROR_ABSTRACT_CONSTRUCTION', '[acl_base] The AclBase class constructor has been called, or the class was instantiated. This class must remain abstract. Please refer to the Cake docs for ACL configuration.');
|
|
||||||
|
|
||||||
?>
|
|
145
cake/libs/model/connection_manager.php
Normal file
145
cake/libs/model/connection_manager.php
Normal file
|
@ -0,0 +1,145 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.model
|
||||||
|
* @since CakePHP v 0.10.x.1402
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages loaded instances of DataSource objects
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.model
|
||||||
|
* @since CakePHP v 0.10.x.1402
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
uses('model'.DS.'datasources'.DS.'datasource');
|
||||||
|
class ConnectionManager extends Object
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds a loaded instance of the Connections object
|
||||||
|
*
|
||||||
|
* @var class:Connections
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $config = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds instances DataSource objects
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_dataSources = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
if(class_exists('DATABASE_CONFIG'))
|
||||||
|
{
|
||||||
|
$this->config = new DATABASE_CONFIG();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a reference to the ConnectionManger object instance
|
||||||
|
*
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
function &getInstance()
|
||||||
|
{
|
||||||
|
static $instance = null;
|
||||||
|
if($instance == null)
|
||||||
|
{
|
||||||
|
$instance =& new ConnectionManager();
|
||||||
|
}
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a reference to a DataSource object
|
||||||
|
*
|
||||||
|
* @param string $name The name of the DataSource, as defined in app/config/connections
|
||||||
|
* @return object
|
||||||
|
*/
|
||||||
|
function &getDataSource($name)
|
||||||
|
{
|
||||||
|
$_this =& ConnectionManager::getInstance();
|
||||||
|
|
||||||
|
if(in_array($name, array_keys($_this->_dataSources)))
|
||||||
|
{
|
||||||
|
return $_this->_dataSources[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(in_array($name, array_keys(get_object_vars($_this->config))))
|
||||||
|
{
|
||||||
|
$config = $_this->config->{$name};
|
||||||
|
|
||||||
|
if(isset($config['driver']) && $config['driver'] != null && $config['driver'] != '')
|
||||||
|
{
|
||||||
|
$filename = 'dbo_'.$config['driver'];
|
||||||
|
$classname = Inflector::camelize(strtolower('DBO_'.$config['driver']));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$filename = $config['datasource'].'_source';
|
||||||
|
$classname = Inflector::camelize(strtolower($config['datasource'].'_source'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$tail = 'dbo'.DS.$filename.'.php';
|
||||||
|
if (file_exists(LIBS.'model'.DS.$tail))
|
||||||
|
{
|
||||||
|
require_once(LIBS.'model'.DS.$tail);
|
||||||
|
}
|
||||||
|
else if (file_exists(MODELS.$tail))
|
||||||
|
{
|
||||||
|
require_once(MODELS.$tail);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
trigger_error('Unable to load model file ' . $filename . '.php', E_USER_ERROR);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$_this->_dataSources[$name] =& new $classname($config);
|
||||||
|
$_this->_dataSources[$name]->configKeyName = $name;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
trigger_error("ConnectionManager::getDataSource - Non-existent data source {$name}", E_USER_ERROR);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return $_this->_dataSources[$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
422
cake/libs/model/datasources/datasource.php
Normal file
422
cake/libs/model/datasources/datasource.php
Normal file
|
@ -0,0 +1,422 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.model.datasources
|
||||||
|
* @since CakePHP v 0.10.x.1379
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.model.datasources
|
||||||
|
* @since CakePHP v 0.10.x.1379
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class DataSource extends Object
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we connected to the DataSource?
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $connected = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print debug info?
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $debug = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print full query debug info?
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $fullDebug = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error description of last query
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $error = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String to hold how many rows were affected by the last SQL operation.
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $affected = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of rows in current resultset
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $numRows = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time the last query took
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $took = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_result = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries count.
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_queriesCnt = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Total duration of all queries.
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_queriesTime = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log of queries executed by this DataSource
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_queriesLog = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum number of items in query log, to prevent query log taking over
|
||||||
|
* too much memory on large amounts of queries -- I we've had problems at
|
||||||
|
* >6000 queries on one system.
|
||||||
|
*
|
||||||
|
* @var int Maximum number of queries in the queries log.
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_queriesLogMax = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default configuration of a specific DataSource
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $_baseConfig = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds references to descriptions loaded by the DataSource
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $__descriptions = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the physical connection of this DataSource
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $connection = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DataSource configuration
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $config = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DataSource configuration key name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $configKeyName = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not this DataSource is in the middle of a transaction
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $__transactionStarted = false;
|
||||||
|
|
||||||
|
|
||||||
|
function __construct ()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
if(func_num_args() > 0)
|
||||||
|
{
|
||||||
|
$this->setConfig(func_get_arg(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the DataSource supports the given interface (method)
|
||||||
|
*
|
||||||
|
* @param string $interface The name of the interface (method)
|
||||||
|
* @return boolean True on success
|
||||||
|
*/
|
||||||
|
function isInterfaceSupported ($interface)
|
||||||
|
{
|
||||||
|
$methods = get_class_methods(get_class($this));
|
||||||
|
$methods = strtolower(implode('|', $methods));
|
||||||
|
$methods = explode('|', $methods);
|
||||||
|
return in_array(strtolower($interface), $methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the configuration for the DataSource
|
||||||
|
*
|
||||||
|
* @param array $config The configuration array
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function setConfig ($config)
|
||||||
|
{
|
||||||
|
if(is_array($this->_baseConfig))
|
||||||
|
{
|
||||||
|
$this->config = $this->_baseConfig;
|
||||||
|
foreach($config as $key => $val)
|
||||||
|
{
|
||||||
|
$this->config[$key] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache the DataSource description
|
||||||
|
*
|
||||||
|
* @param string $object The name of the object (model) to cache
|
||||||
|
* @param mixed $data The description of the model, usually a string or array
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function __cacheDescription ($object, $data = null)
|
||||||
|
{
|
||||||
|
if (DEBUG > 0)
|
||||||
|
{
|
||||||
|
$expires = "+10 seconds";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$expires = "+1 day";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($data !== null)
|
||||||
|
{
|
||||||
|
$this->__descriptions[$object] = &$data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$new = cache('models'.DS.low(get_class($this)).'_'.$object, serialize($data), $expires);
|
||||||
|
if($new != null)
|
||||||
|
{
|
||||||
|
$new = unserialize($new);
|
||||||
|
}
|
||||||
|
return $new;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses conditions array (or just passes it if it's a string)
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function conditions ($conditions)
|
||||||
|
{
|
||||||
|
return $conditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function name ($name)
|
||||||
|
{
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function value ($value)
|
||||||
|
{
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function describe ($model)
|
||||||
|
{
|
||||||
|
if (isset($this->__descriptions[$model->source]))
|
||||||
|
{
|
||||||
|
return $this->__descriptions[$model->source];
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache = $this->__cacheDescription($model->source);
|
||||||
|
if ($cache !== null)
|
||||||
|
{
|
||||||
|
$this->__descriptions[$model->source] = &$cache;
|
||||||
|
return $cache;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function create (&$model, $fields = null, $values = null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function read (&$model, $queryData = array())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update (&$model, $fields = null, $values = null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete (&$model, $id = null)
|
||||||
|
{
|
||||||
|
if ($id == null)
|
||||||
|
{
|
||||||
|
$id = $model->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fields ($fields)
|
||||||
|
{
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColumnType (&$model, $fields)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $index)
|
||||||
|
{
|
||||||
|
$keys = array('{$__cake_id__$}', '{$__cake_foreignKey__$}');
|
||||||
|
foreach($keys as $key)
|
||||||
|
{
|
||||||
|
if (strpos($query, $key) !== false)
|
||||||
|
{
|
||||||
|
switch($key)
|
||||||
|
{
|
||||||
|
case '{$__cake_id__$}':
|
||||||
|
$val = null;
|
||||||
|
if (isset($data[$index][$model->name])) {
|
||||||
|
$val = $data[$index][$model->name][$model->primaryKey];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '{$__cake_foreignKey__$}':
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$query = r($key, $this->value($val), $query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveKey($model, $key)
|
||||||
|
{
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFieldValue ($data, $path)
|
||||||
|
{
|
||||||
|
if (!is_array($path))
|
||||||
|
{
|
||||||
|
$path = explode('.', $path);
|
||||||
|
}
|
||||||
|
$tmp = array();
|
||||||
|
|
||||||
|
foreach ($path as $i => $key)
|
||||||
|
{
|
||||||
|
if (intval($key) > 0 || $key == '0')
|
||||||
|
{
|
||||||
|
if (isset($data[intval($key)]))
|
||||||
|
{
|
||||||
|
$data = $data[intval($key)];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($key == '{n}')
|
||||||
|
{
|
||||||
|
foreach ($data as $j => $val)
|
||||||
|
{
|
||||||
|
if (is_subclass_of($this, 'DataSource') || is_subclass_of($this, 'datasource'))
|
||||||
|
{
|
||||||
|
$tmp[] = $this->getFieldValue($val, array_slice($path, $i + 1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$tmp[] = DataSource::getFieldValue($val, array_slice($path, $i + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $tmp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (isset($data[$key]))
|
||||||
|
{
|
||||||
|
$data = $data[$key];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function __destruct ()
|
||||||
|
{
|
||||||
|
if ($this->connected)
|
||||||
|
{
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
762
cake/libs/model/datasources/dbo_source.php
Normal file
762
cake/libs/model/datasources/dbo_source.php
Normal file
|
@ -0,0 +1,762 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.model.datasources
|
||||||
|
* @since CakePHP v 0.10.0.1076
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include DataSource base class
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
uses('model'.DS.'datasources'.DS.'datasource');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DboSource
|
||||||
|
*
|
||||||
|
* Creates DBO-descendant objects from a given db connection configuration
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.model.datasources
|
||||||
|
* @since CakePHP v 0.10.0.1076
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class DboSource extends DataSource
|
||||||
|
{
|
||||||
|
|
||||||
|
var $description = "Database Data Source";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function __construct($config = null)
|
||||||
|
{
|
||||||
|
$this->debug = DEBUG > 0;
|
||||||
|
$this->fullDebug = DEBUG > 1;
|
||||||
|
parent::__construct($config);
|
||||||
|
return $this->connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares a value, or an array of values for database queries by quoting and escaping them.
|
||||||
|
*
|
||||||
|
* @param mixed $data A value or an array of values to prepare.
|
||||||
|
* @return mixed Prepared value or array of values.
|
||||||
|
*/
|
||||||
|
function value ($data, $column = null)
|
||||||
|
{
|
||||||
|
if (is_array($data))
|
||||||
|
{
|
||||||
|
$out = array();
|
||||||
|
foreach ($data as $key => $item)
|
||||||
|
{
|
||||||
|
$out[$key] = $this->value($item);
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sources ()
|
||||||
|
{
|
||||||
|
return array_map('strtolower', $this->listSources());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes given SQL statement.
|
||||||
|
*
|
||||||
|
* @param string $sql SQL statement
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function rawQuery ($sql)
|
||||||
|
{
|
||||||
|
$this->took = $this->error = $this->numRows = false;
|
||||||
|
return $this->execute($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries the database with given SQL statement, and obtains some metadata about the result
|
||||||
|
* (rows affected, timing, any errors, number of rows in resultset). The query is also logged.
|
||||||
|
* If DEBUG is set, the log is shown all the time, else it is only shown on errors.
|
||||||
|
*
|
||||||
|
* @param string $sql
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function execute($sql)
|
||||||
|
{
|
||||||
|
$t = getMicrotime();
|
||||||
|
$this->_result = $this->__execute($sql);
|
||||||
|
|
||||||
|
$this->affected = $this->lastAffected();
|
||||||
|
$this->took = round((getMicrotime() - $t) * 1000, 0);
|
||||||
|
$this->error = $this->lastError();
|
||||||
|
$this->numRows = $this->lastNumRows($this->_result);
|
||||||
|
$this->logQuery($sql);
|
||||||
|
|
||||||
|
if (($this->debug && $this->error) || ($this->fullDebug))
|
||||||
|
{
|
||||||
|
$this->showQuery($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->error)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->_result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single row of results from the _last_ SQL query.
|
||||||
|
*
|
||||||
|
* @param resource $res
|
||||||
|
* @return array A single row of results
|
||||||
|
*/
|
||||||
|
function fetchArray ($assoc=false)
|
||||||
|
{
|
||||||
|
if ($assoc === false)
|
||||||
|
{
|
||||||
|
return $this->fetchRow();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->fetchRow($assoc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single row of results for a _given_ SQL query.
|
||||||
|
*
|
||||||
|
* @param string $sql SQL statement
|
||||||
|
* @return array A single row of results
|
||||||
|
*/
|
||||||
|
function one ($sql)
|
||||||
|
{
|
||||||
|
if ($this->query($sql))
|
||||||
|
{
|
||||||
|
return $this->fetchArray();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of all result rows for a given SQL query.
|
||||||
|
* Returns false if no rows matched.
|
||||||
|
*
|
||||||
|
* @param string $sql SQL statement
|
||||||
|
* @return array Array of resultset rows, or false if no rows matched
|
||||||
|
*/
|
||||||
|
function fetchAll ($sql)
|
||||||
|
{
|
||||||
|
if($this->execute($sql))
|
||||||
|
{
|
||||||
|
$out = array();
|
||||||
|
while ($item = $this->fetchArray(null, true))
|
||||||
|
{
|
||||||
|
$out[] = $item;
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single field of the first of query results for a given SQL query, or false if empty.
|
||||||
|
*
|
||||||
|
* @param string $name Name of the field
|
||||||
|
* @param string $sql SQL query
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function field ($name, $sql)
|
||||||
|
{
|
||||||
|
$data = $this->one($sql);
|
||||||
|
if (empty($data[$name]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $data[$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if it's connected to the database
|
||||||
|
*
|
||||||
|
* @return boolean True if the database is connected, else false
|
||||||
|
*/
|
||||||
|
function isConnected()
|
||||||
|
{
|
||||||
|
return $this->connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outputs the contents of the log.
|
||||||
|
*
|
||||||
|
* @param boolean $sorted
|
||||||
|
*/
|
||||||
|
function showLog($sorted=false)
|
||||||
|
{
|
||||||
|
$log = $sorted?
|
||||||
|
sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC):
|
||||||
|
$this->_queriesLog;
|
||||||
|
|
||||||
|
print("<table border=1>\n<tr><th colspan=7>{$this->_queriesCnt} queries took {$this->_queriesTime} ms</th></tr>\n");
|
||||||
|
print("<tr><td>Nr</td><td>Query</td><td>Error</td><td>Affected</td><td>Num. rows</td><td>Took (ms)</td></tr>\n");
|
||||||
|
|
||||||
|
foreach($log AS $k=>$i)
|
||||||
|
{
|
||||||
|
print("<tr><td>".($k+1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td align='right'>{$i['affected']}</td><td align='right'>{$i['numRows']}</td><td align='right'>{$i['took']}</td></tr>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
print("</table>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log given SQL query.
|
||||||
|
*
|
||||||
|
* @param string $sql SQL statement
|
||||||
|
*/
|
||||||
|
function logQuery($sql)
|
||||||
|
{
|
||||||
|
$this->_queriesCnt++;
|
||||||
|
$this->_queriesTime += $this->took;
|
||||||
|
|
||||||
|
$this->_queriesLog[] = array(
|
||||||
|
'query' => $sql,
|
||||||
|
'error' => $this->error,
|
||||||
|
'affected' => $this->affected,
|
||||||
|
'numRows' => $this->numRows,
|
||||||
|
'took' => $this->took
|
||||||
|
);
|
||||||
|
|
||||||
|
if (count($this->_queriesLog) > $this->_queriesLogMax)
|
||||||
|
{
|
||||||
|
array_pop($this->_queriesLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->error)
|
||||||
|
{
|
||||||
|
return false; // shouldn't we be logging errors somehow?
|
||||||
|
// TODO: Add hook to error log
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output information about an SQL query. The SQL statement, number of rows in resultset,
|
||||||
|
* and execution time in microseconds. If the query fails, and error is output instead.
|
||||||
|
*
|
||||||
|
* @param string $sql
|
||||||
|
*/
|
||||||
|
function showQuery($sql)
|
||||||
|
{
|
||||||
|
$error = $this->error;
|
||||||
|
|
||||||
|
if (strlen($sql)>200 && !$this->fullDebug)
|
||||||
|
{
|
||||||
|
$sql = substr($sql, 0, 200) .'[...]';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->debug || $error)
|
||||||
|
{
|
||||||
|
print("<p style=\"text-align:left\"><b>Query:</b> {$sql} <small>[Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]</small>");
|
||||||
|
if($error)
|
||||||
|
{
|
||||||
|
print("<br /><span style=\"color:Red;text-align:left\"><b>ERROR:</b> {$this->error}</span>");
|
||||||
|
}
|
||||||
|
print('</p>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function create(&$model, $fields = null, $values = null)
|
||||||
|
{
|
||||||
|
if ($fields == null)
|
||||||
|
{
|
||||||
|
unset($fields, $values);
|
||||||
|
$fields = array_keys($model->data);
|
||||||
|
$values = array_values($model->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->execute('INSERT INTO '.$model->source.' ('.join(',', $fields).') VALUES ('.join(',', $values).')'))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function read (&$model, $queryData = array(), $recursive = 1)
|
||||||
|
{
|
||||||
|
$this->__scrubQueryData($queryData);
|
||||||
|
$null = null;
|
||||||
|
$array = array();
|
||||||
|
$linkedModels = array();
|
||||||
|
|
||||||
|
if ($recursive > 0)
|
||||||
|
{
|
||||||
|
foreach($model->__associations as $type)
|
||||||
|
{
|
||||||
|
foreach($model->{$type} as $assoc => $assocData)
|
||||||
|
{
|
||||||
|
$linkModel =& $model->{$assocData['className']};
|
||||||
|
if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, false, $null))
|
||||||
|
{
|
||||||
|
$linkedModels[] = $type.$assoc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build final query SQL
|
||||||
|
$query = $this->generateAssociationQuery($model, $null, null, null, null, $queryData, false, $null);
|
||||||
|
$resultSet = $this->fetchAll($query);
|
||||||
|
|
||||||
|
if ($recursive > 0)
|
||||||
|
{
|
||||||
|
foreach($model->__associations as $type)
|
||||||
|
{
|
||||||
|
foreach($model->{$type} as $assoc => $assocData)
|
||||||
|
{
|
||||||
|
if (!in_array($type.$assoc, $linkedModels))
|
||||||
|
{
|
||||||
|
$linkModel =& $model->{$assocData['className']};
|
||||||
|
$this->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $recursive - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $resultSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive = 1)
|
||||||
|
{
|
||||||
|
//$external = (($linkModel->ds === $this) && $resultSet == null);
|
||||||
|
|
||||||
|
$query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet);
|
||||||
|
if ($query)
|
||||||
|
{
|
||||||
|
foreach ($resultSet as $i => $row)
|
||||||
|
{
|
||||||
|
$q = $this->insertQueryData($query, $resultSet, $association, $assocData, $model, $linkModel, $i);
|
||||||
|
$fetch = $this->fetchAll($q);
|
||||||
|
|
||||||
|
if (!empty($fetch) && is_array($fetch))
|
||||||
|
{
|
||||||
|
if (isset($fetch[0][$association]))
|
||||||
|
{
|
||||||
|
foreach ($fetch as $j => $row)
|
||||||
|
{
|
||||||
|
$resultSet[$i][$association][$j] = $row[$association];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$plural = Inflector::pluralize($association);
|
||||||
|
foreach ($fetch as $j => $row)
|
||||||
|
{
|
||||||
|
$resultSet[$i][$plural][$j] = $row[$plural];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateAssociationQuery(&$model, &$linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet)
|
||||||
|
{
|
||||||
|
$this->__scrubQueryData($queryData);
|
||||||
|
if ($linkModel == null)
|
||||||
|
{
|
||||||
|
// Generates primary query
|
||||||
|
$sql = 'SELECT ' . join(', ', $this->fields($queryData['fields'])) . ' FROM ';
|
||||||
|
$sql .= $this->name($model->source).' AS ';
|
||||||
|
$sql .= $this->name($model->name).' ' . join(' ', $queryData['joins']).' ';
|
||||||
|
$sql .= $this->conditions($queryData['conditions']).' '.$this->order($queryData['order']);
|
||||||
|
$sql .= ' '.$this->limit($queryData['limit']);
|
||||||
|
return $sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
$alias = $association;
|
||||||
|
if($model->name == $linkModel->name)
|
||||||
|
{
|
||||||
|
$alias = Inflector::pluralize($association);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($type)
|
||||||
|
{
|
||||||
|
case 'hasOne':
|
||||||
|
if ($external)
|
||||||
|
{
|
||||||
|
if ($assocData['finderQuery'])
|
||||||
|
{
|
||||||
|
return $assocData['finderQuery'];
|
||||||
|
}
|
||||||
|
$sql = 'SELECT * FROM '.$this->name($linkModel->source).' AS '.$alias;
|
||||||
|
$conditions = $queryData['conditions'];
|
||||||
|
$condition = $model->escapeField($assocData['foreignKey']);
|
||||||
|
$condition .= '={$__cake_foreignKey__$}';
|
||||||
|
if (is_array($conditions))
|
||||||
|
{
|
||||||
|
$conditions[] = $condition;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (trim($conditions) != '')
|
||||||
|
{
|
||||||
|
$conditions .= ' AND ';
|
||||||
|
}
|
||||||
|
$conditions .= $condition;
|
||||||
|
}
|
||||||
|
$sql .= $this->conditions($queryData['conditions']) . $this->order($queryData['order']);
|
||||||
|
$sql .= $this->limit($queryData['limit']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sql = ' LEFT JOIN '.$this->name($linkModel->source);
|
||||||
|
$sql .= ' AS '.$this->name($alias).' ON '.$this->name($alias).'.';
|
||||||
|
$sql .= $this->name($assocData['foreignKey']).'='.$model->escapeField($model->primaryKey);
|
||||||
|
$sql .= $this->conditions($assocData['conditions']);
|
||||||
|
$sql .= $this->order($assocData['order']);
|
||||||
|
|
||||||
|
if (!in_array($queryData['joins'], $sql))
|
||||||
|
{
|
||||||
|
$queryData['joins'][] = $sql;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'belongsTo':
|
||||||
|
if ($external)
|
||||||
|
{
|
||||||
|
pr('external');
|
||||||
|
$conditions = $assocData['conditions'];
|
||||||
|
$sql = 'SELECT * FROM '.$this->name($linkModel->source).' AS '.$this->name($alias);
|
||||||
|
|
||||||
|
$condition = $linkModel->escapeField($assocData['foreignKey']);
|
||||||
|
$condition .= '={$__cake_id__$}';
|
||||||
|
if (is_array($conditions))
|
||||||
|
{
|
||||||
|
$conditions[] = $condition;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (trim($conditions) != '')
|
||||||
|
{
|
||||||
|
$conditions .= ' AND ';
|
||||||
|
}
|
||||||
|
$conditions .= $condition;
|
||||||
|
}
|
||||||
|
$sql .= $this->conditions($queryData['conditions']) . $this->order($queryData['order']);
|
||||||
|
$sql .= $this->limit($queryData['limit']);
|
||||||
|
return $sql;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sql = ' LEFT JOIN '.$this->name($linkModel->source);
|
||||||
|
$sql .= ' AS ' . $this->name($alias) . ' ON ';
|
||||||
|
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
||||||
|
$sql .= '='.$linkModel->escapeField($linkModel->primaryKey);
|
||||||
|
|
||||||
|
if (!in_array($sql, $queryData['joins']))
|
||||||
|
{
|
||||||
|
$queryData['joins'][] = $sql;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'hasMany':
|
||||||
|
if(isset($assocData['finderQuery']) && $assocData['finderQuery'] != null)
|
||||||
|
{
|
||||||
|
$sql = $assocData['finderQuery'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$conditions = $assocData['conditions'];
|
||||||
|
$sql = 'SELECT * FROM '.$this->name($linkModel->source).' AS ';
|
||||||
|
$sql .= $this->name($alias);
|
||||||
|
|
||||||
|
$cond = $this->name($alias).'.'.$this->name($assocData['foreignKey']);
|
||||||
|
$cond .= '={$__cake_id__$}';
|
||||||
|
if (is_array($conditions))
|
||||||
|
{
|
||||||
|
$conditions[] = $cond;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (trim($conditions) != '')
|
||||||
|
{
|
||||||
|
$conditions .= ' AND ';
|
||||||
|
}
|
||||||
|
$conditions .= $cond;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= $this->conditions($conditions);
|
||||||
|
$sql .= $this->order($assocData['order']);
|
||||||
|
}
|
||||||
|
return $sql;
|
||||||
|
break;
|
||||||
|
case 'hasAndBelongsToMany':
|
||||||
|
if(isset($assocData['finderQuery']) && $assocData['finderQuery'] != null)
|
||||||
|
{
|
||||||
|
$sql = $assocData['finderQuery'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$joinTbl = $this->name($assocData['joinTable']);
|
||||||
|
$alias = $this->name($alias);
|
||||||
|
|
||||||
|
$sql = 'SELECT '.join(', ', $this->fields($assocData['fields']));
|
||||||
|
$sql .= ' FROM '.$this->name($linkModel->source).' AS '.$alias;
|
||||||
|
$sql .= ' JOIN '.$joinTbl.' ON '.$joinTbl;
|
||||||
|
$sql .= '.'.$this->name($assocData['foreignKey']).'={$__cake_id__$}';
|
||||||
|
$sql .= ' AND '.$joinTbl.'.'.$this->name($assocData['associationForeignKey']);
|
||||||
|
$sql .= ' = '.$alias.'.'.$this->name($linkModel->primaryKey);
|
||||||
|
|
||||||
|
$sql .= $this->conditions($assocData['conditions']);
|
||||||
|
$sql .= $this->order($assocData['order']);
|
||||||
|
}
|
||||||
|
return $sql;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function update (&$model, $fields = null, $values = null)
|
||||||
|
{
|
||||||
|
$updates = array();
|
||||||
|
foreach (array_combine($fields, $values) as $field => $value)
|
||||||
|
{
|
||||||
|
$updates[] = $this->name($field).'='.$this->value($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = 'UPDATE '.$this->name($model->source).' AS '.$this->name($model->name);
|
||||||
|
$sql .= ' SET '.join(',', $updates);
|
||||||
|
$sql .= ' WHERE '.$model->escapeField($model->primaryKey).'='.$this->value($model->getID());
|
||||||
|
|
||||||
|
return $this->execute($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete (&$model, $id = null)
|
||||||
|
{
|
||||||
|
$_id = $model->id;
|
||||||
|
if ($id != null)
|
||||||
|
{
|
||||||
|
$model->id = $id;
|
||||||
|
}
|
||||||
|
if (!is_array($model->id))
|
||||||
|
{
|
||||||
|
$model->id = array($model->id);
|
||||||
|
}
|
||||||
|
foreach ($model->id as $id)
|
||||||
|
{
|
||||||
|
$result = $this->execute('DELETE FROM '.$this->name($model->source).' WHERE '.$this->name($model->primaryKey).'='.$this->value($id));
|
||||||
|
}
|
||||||
|
if ($result)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveKey($model, $key, $assoc = null)
|
||||||
|
{
|
||||||
|
if ($assoc == null)
|
||||||
|
{
|
||||||
|
$assoc = $model->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strpos('.', $key))
|
||||||
|
{
|
||||||
|
return $this->name($model->source).'.'.$this->name($key);
|
||||||
|
}
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getColumnType (&$model, $field)
|
||||||
|
{
|
||||||
|
$columns = $model->loadInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
function __scrubQueryData(&$data)
|
||||||
|
{
|
||||||
|
if (!isset($data['conditions']))
|
||||||
|
{
|
||||||
|
$data['conditions'] = ' 1 ';
|
||||||
|
}
|
||||||
|
if (!isset($data['fields']))
|
||||||
|
{
|
||||||
|
$data['fields'] = '*';
|
||||||
|
}
|
||||||
|
if (!isset($data['joins']))
|
||||||
|
{
|
||||||
|
$data['joins'] = array();
|
||||||
|
}
|
||||||
|
if (!isset($data['order']))
|
||||||
|
{
|
||||||
|
$data['order'] = '';
|
||||||
|
}
|
||||||
|
if (!isset($data['limit']))
|
||||||
|
{
|
||||||
|
$data['limit'] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fields ($fields)
|
||||||
|
{
|
||||||
|
if (is_array($fields))
|
||||||
|
{
|
||||||
|
$f = $fields;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($fields != null)
|
||||||
|
{
|
||||||
|
if (strpos($fields, ','))
|
||||||
|
{
|
||||||
|
$fields = explode(',', $fields);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$fields = array($fields);
|
||||||
|
}
|
||||||
|
$fields = array_map('trim', $fields);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$fields = array('*');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($fields) > 1 && $fields[0] != '*')
|
||||||
|
{
|
||||||
|
for ($i = 0; $i < count($fields); $i++)
|
||||||
|
{
|
||||||
|
$fields[$i] = $this->name($fields[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses conditions array (or just passes it if it's a string)
|
||||||
|
* @return string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function conditions ($conditions)
|
||||||
|
{
|
||||||
|
$rt = '';
|
||||||
|
if (!strpos(low($conditions), 'where') || strpos(low($conditions), 'where') === 0)
|
||||||
|
{
|
||||||
|
$rt = ' WHERE ';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($conditions))
|
||||||
|
{
|
||||||
|
if (trim($conditions) == '')
|
||||||
|
{
|
||||||
|
$conditions = ' 1';
|
||||||
|
}
|
||||||
|
return $rt.$conditions;
|
||||||
|
}
|
||||||
|
elseif (is_array($conditions))
|
||||||
|
{
|
||||||
|
$out = array();
|
||||||
|
foreach ($conditions as $key => $value)
|
||||||
|
{
|
||||||
|
$slashedValue = $this->value($value);
|
||||||
|
//TODO: Remove the = below so LIKE and other compares can be used
|
||||||
|
$data = $key . '=';
|
||||||
|
if ($value === null)
|
||||||
|
{
|
||||||
|
$data .= 'null';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data = $slashedValue;
|
||||||
|
}
|
||||||
|
$out[] = $data;
|
||||||
|
}
|
||||||
|
return ' WHERE ' . join(' AND ', $out);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $rt.' 1 ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function limit ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
function order ($key, $dir = '')
|
||||||
|
{
|
||||||
|
if (trim($key) == '')
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return ' ORDER BY '.$key.' '.$dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disconnects database, kills the connection and says the connection is closed, and if DEBUG is turned on, the log for this object is shown.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function close ()
|
||||||
|
{
|
||||||
|
if ($this->fullDebug)
|
||||||
|
{
|
||||||
|
$this->showLog();
|
||||||
|
}
|
||||||
|
$this->disconnect();
|
||||||
|
$this->_conn = NULL;
|
||||||
|
$this->connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor. Closes connection to the database.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function __destruct()
|
||||||
|
{
|
||||||
|
if ($this->__transactionStarted)
|
||||||
|
{
|
||||||
|
$this->rollback();
|
||||||
|
}
|
||||||
|
$this->close();
|
||||||
|
parent::__destruct();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for file.
|
* Short description for file.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -32,12 +32,15 @@
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uses('object');
|
if(!class_exists('Object'))
|
||||||
|
{
|
||||||
|
uses('object');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purpose: DBO/ADO
|
* Purpose: DBO/ADO
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* A SQL functions wrapper. Provides ability to get results as arrays
|
* A SQL functions wrapper. Provides ability to get results as arrays
|
||||||
* and query logging (with execution time).
|
* and query logging (with execution time).
|
||||||
*
|
*
|
||||||
|
@ -60,9 +63,9 @@ uses('object');
|
||||||
* $first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
|
* $first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
|
||||||
*
|
*
|
||||||
* // emulate the usual way of reading query results
|
* // emulate the usual way of reading query results
|
||||||
* if ($db->query("SELECT a,b,c FROM table"))
|
* if ($db->query("SELECT a,b,c FROM table"))
|
||||||
* {
|
* {
|
||||||
* while ( $row = $db->farr() )
|
* while ( $row = $db->farr() )
|
||||||
* {
|
* {
|
||||||
* print $row['a'].$row['b'].$row['c'];
|
* print $row['a'].$row['b'].$row['c'];
|
||||||
* }
|
* }
|
||||||
|
@ -185,7 +188,7 @@ class DBO extends Object
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of items in query log, to prevent query log taking over
|
* Maximum number of items in query log, to prevent query log taking over
|
||||||
* too much memory on large amounts of queries -- I we've had problems at
|
* too much memory on large amounts of queries -- I we've had problems at
|
||||||
* >6000 queries on one system.
|
* >6000 queries on one system.
|
||||||
*
|
*
|
||||||
* @var int Maximum number of queries in the queries log.
|
* @var int Maximum number of queries in the queries log.
|
||||||
|
@ -195,7 +198,7 @@ class DBO extends Object
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. Sets the level of debug for dbo (fullDebug or debug).
|
* Constructor. Sets the level of debug for dbo (fullDebug or debug).
|
||||||
*
|
*
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @return unknown
|
* @return unknown
|
||||||
|
@ -281,8 +284,8 @@ class DBO extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries the database with given SQL statement, and obtains some metadata about the result
|
* Queries the database with given SQL statement, and obtains some metadata about the result
|
||||||
* (rows affected, timing, any errors, number of rows in resultset). The query is also logged.
|
* (rows affected, timing, any errors, number of rows in resultset). The query is also logged.
|
||||||
* If DEBUG is set, the log is shown all the time, else it is only shown on errors.
|
* If DEBUG is set, the log is shown all the time, else it is only shown on errors.
|
||||||
*
|
*
|
||||||
* @param string $sql
|
* @param string $sql
|
||||||
|
@ -333,7 +336,7 @@ class DBO extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of all result rows for a given SQL query.
|
* Returns an array of all result rows for a given SQL query.
|
||||||
* Returns false if no rows matched.
|
* Returns false if no rows matched.
|
||||||
*
|
*
|
||||||
* @param string $sql SQL statement
|
* @param string $sql SQL statement
|
||||||
|
@ -442,7 +445,7 @@ class DBO extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output information about an SQL query. The SQL statement, number of rows in resultset,
|
* Output information about an SQL query. The SQL statement, number of rows in resultset,
|
||||||
* and execution time in microseconds. If the query fails, and error is output instead.
|
* and execution time in microseconds. If the query fails, and error is output instead.
|
||||||
*
|
*
|
||||||
* @param string $sql
|
* @param string $sql
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AdoDB layer for DBO.
|
* AdoDB layer for DBO.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
|
@ -16,11 +16,11 @@
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.2.9
|
* @since CakePHP v 0.2.9
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
* @modifiedby $LastChangedBy$
|
* @modifiedby $LastChangedBy$
|
||||||
|
@ -35,16 +35,16 @@ require_once(VENDORS.'adodb/adodb.inc.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AdoDB DBO implementation.
|
* AdoDB DBO implementation.
|
||||||
*
|
*
|
||||||
* Database abstraction implementation for the AdoDB library.
|
* Database abstraction implementation for the AdoDB library.
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.2.9
|
* @since CakePHP v 0.2.9
|
||||||
*/
|
*/
|
||||||
class DBO_AdoDB extends DBO
|
class DBO_AdoDB extends DBO
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADOConnection object with which we connect.
|
* ADOConnection object with which we connect.
|
||||||
*
|
*
|
||||||
|
@ -58,7 +58,7 @@ class DBO_AdoDB extends DBO
|
||||||
*
|
*
|
||||||
* @param array $config Configuration array for connecting
|
* @param array $config Configuration array for connecting
|
||||||
*/
|
*/
|
||||||
function connect ($config)
|
function connect ($config)
|
||||||
{
|
{
|
||||||
if ($this->config = $config)
|
if ($this->config = $config)
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,7 @@ class DBO_AdoDB extends DBO
|
||||||
*
|
*
|
||||||
* @return boolean True if the database could be disconnected, else false
|
* @return boolean True if the database could be disconnected, else false
|
||||||
*/
|
*/
|
||||||
function disconnect ()
|
function disconnect ()
|
||||||
{
|
{
|
||||||
return $this->_adodb->close();
|
return $this->_adodb->close();
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ class DBO_AdoDB extends DBO
|
||||||
* @param string $sql SQL statement
|
* @param string $sql SQL statement
|
||||||
* @return resource Result resource identifier
|
* @return resource Result resource identifier
|
||||||
*/
|
*/
|
||||||
function execute ($sql)
|
function execute ($sql)
|
||||||
{
|
{
|
||||||
return $this->_adodb->execute($sql);
|
return $this->_adodb->execute($sql);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ class DBO_AdoDB extends DBO
|
||||||
*
|
*
|
||||||
* @return array The fetched row as an array
|
* @return array The fetched row as an array
|
||||||
*/
|
*/
|
||||||
function fetchRow ()
|
function fetchRow ()
|
||||||
{
|
{
|
||||||
return $this->_result->FetchRow();
|
return $this->_result->FetchRow();
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ class DBO_AdoDB extends DBO
|
||||||
*
|
*
|
||||||
* @return array Array of tablenames in the database
|
* @return array Array of tablenames in the database
|
||||||
*/
|
*/
|
||||||
function tablesList ()
|
function tablesList ()
|
||||||
{
|
{
|
||||||
$tables = $this->_adodb->MetaTables('TABLES');
|
$tables = $this->_adodb->MetaTables('TABLES');
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ class DBO_AdoDB extends DBO
|
||||||
*
|
*
|
||||||
* @todo To be implemented.
|
* @todo To be implemented.
|
||||||
*/
|
*/
|
||||||
function prepareValue ($data)
|
function prepareValue ($data)
|
||||||
{
|
{
|
||||||
return $this->_adodb->Quote($data);
|
return $this->_adodb->Quote($data);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ class DBO_AdoDB extends DBO
|
||||||
*
|
*
|
||||||
* @return string Error message
|
* @return string Error message
|
||||||
*/
|
*/
|
||||||
function lastError ()
|
function lastError ()
|
||||||
{
|
{
|
||||||
return $this->_adodb->ErrorMsg();
|
return $this->_adodb->ErrorMsg();
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ class DBO_AdoDB extends DBO
|
||||||
*/
|
*/
|
||||||
function lastAffected ()
|
function lastAffected ()
|
||||||
{
|
{
|
||||||
return $this->_adodb->Affected_Rows();
|
return $this->_adodb->Affected_Rows();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -178,7 +178,7 @@ class DBO_AdoDB extends DBO
|
||||||
*
|
*
|
||||||
* @return int Number of rows in resultset
|
* @return int Number of rows in resultset
|
||||||
*/
|
*/
|
||||||
function lastNumRows ()
|
function lastNumRows ()
|
||||||
{
|
{
|
||||||
return $this->_result? $this->_result->RecordCount(): false;
|
return $this->_result? $this->_result->RecordCount(): false;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ class DBO_AdoDB extends DBO
|
||||||
/**
|
/**
|
||||||
* To-be-implemented. Returns the ID generated from the previous INSERT operation.
|
* To-be-implemented. Returns the ID generated from the previous INSERT operation.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*
|
*
|
||||||
* @todo To be implemented.
|
* @todo To be implemented.
|
||||||
*/
|
*/
|
||||||
|
|
471
cake/libs/model/dbo/dbo_dbo.php
Normal file
471
cake/libs/model/dbo/dbo_dbo.php
Normal file
|
@ -0,0 +1,471 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
|
* @since CakePHP v 0.2.9
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
uses('object');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purpose: DBO/ADO
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* A SQL functions wrapper. Provides ability to get results as arrays
|
||||||
|
* and query logging (with execution time).
|
||||||
|
*
|
||||||
|
* Example usage:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* require_once('dbo_mysql.php'); // or 'dbo_postgres.php'
|
||||||
|
*
|
||||||
|
* // create and connect the object
|
||||||
|
* $db = new DBO_MySQL(array( // or 'DBO_Postgres'
|
||||||
|
* 'host'=>'localhost',
|
||||||
|
* 'login'=>'username',
|
||||||
|
* 'password'=>'password',
|
||||||
|
* 'database'=>'database'));
|
||||||
|
*
|
||||||
|
* // read the whole query result array (of rows)
|
||||||
|
* $all_rows = $db->fetchAll("SELECT a,b,c FROM table");
|
||||||
|
*
|
||||||
|
* // read the first row with debugging on
|
||||||
|
* $first_row_only = $db->one("SELECT a,b,c FROM table WHERE a=1", TRUE);
|
||||||
|
*
|
||||||
|
* // emulate the usual way of reading query results
|
||||||
|
* if ($db->query("SELECT a,b,c FROM table"))
|
||||||
|
* {
|
||||||
|
* while ($row = $db->fetchArray())
|
||||||
|
* {
|
||||||
|
* print $row['a'].$row['b'].$row['c'];
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* // show a log of all queries, sorted by execution time
|
||||||
|
* $db->showLog(TRUE);
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
|
* @since CakePHP v 0.2.9
|
||||||
|
*/
|
||||||
|
class DBO extends Object
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Are we connected to the database?
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $connected=FALSE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connection configuration.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $config=FALSE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $debug=FALSE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $fullDebug=FALSE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $error=NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String to hold how many rows were affected by the last SQL operation.
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $affected=NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of rows in current resultset
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $numRows=NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time the last query took
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $took=NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_conn=NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_result=NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries count.
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_queriesCnt=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Total duration of all queries.
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_queriesTime=NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_queriesLog=array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum number of items in query log, to prevent query log taking over
|
||||||
|
* too much memory on large amounts of queries -- I we've had problems at
|
||||||
|
* >6000 queries on one system.
|
||||||
|
*
|
||||||
|
* @var int Maximum number of queries in the queries log.
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
var $_queriesLogMax=200;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor. Sets the level of debug for dbo (fullDebug or debug).
|
||||||
|
*
|
||||||
|
* @param array $config
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function __construct($config=NULL)
|
||||||
|
{
|
||||||
|
$this->debug = DEBUG > 0;
|
||||||
|
$this->fullDebug = DEBUG > 1;
|
||||||
|
parent::__construct();
|
||||||
|
return $this->connect($config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor. Closes connection to the database.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function __destructor()
|
||||||
|
{
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string with a USE [databasename] SQL statement.
|
||||||
|
*
|
||||||
|
* @param string $db_name Name of database to use
|
||||||
|
* @return unknown Result of the query
|
||||||
|
*/
|
||||||
|
function useDb($db_name)
|
||||||
|
{
|
||||||
|
return $this->query("USE {$db_name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disconnects database, kills the connection and says the connection is closed, and if DEBUG is turned on, the log for this object is shown.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function close ()
|
||||||
|
{
|
||||||
|
if ($this->fullDebug) $this->showLog();
|
||||||
|
$this->disconnect();
|
||||||
|
$this->_conn = NULL;
|
||||||
|
$this->connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares a value, or an array of values for database queries by quoting and escaping them.
|
||||||
|
*
|
||||||
|
* @param mixed $data A value or an array of values to prepare.
|
||||||
|
* @return mixed Prepared value or array of values.
|
||||||
|
*/
|
||||||
|
function prepare ($data)
|
||||||
|
{
|
||||||
|
if (is_array($data))
|
||||||
|
{
|
||||||
|
$out = null;
|
||||||
|
foreach ($data as $key=>$item)
|
||||||
|
{
|
||||||
|
$out[$key] = $this->prepareValue($item);
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->prepareValue($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function sources ()
|
||||||
|
{
|
||||||
|
return array_map('strtolower', $this->listSources());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes given SQL statement.
|
||||||
|
*
|
||||||
|
* @param string $sql SQL statement
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function rawQuery ($sql)
|
||||||
|
{
|
||||||
|
$this->took = $this->error = $this->numRows = false;
|
||||||
|
return $this->execute($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries the database with given SQL statement, and obtains some metadata about the result
|
||||||
|
* (rows affected, timing, any errors, number of rows in resultset). The query is also logged.
|
||||||
|
* If DEBUG is set, the log is shown all the time, else it is only shown on errors.
|
||||||
|
*
|
||||||
|
* @param string $sql
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function query($sql)
|
||||||
|
{
|
||||||
|
$t = getMicrotime();
|
||||||
|
$this->_result = $this->execute($sql);
|
||||||
|
$this->affected = $this->lastAffected();
|
||||||
|
$this->took = round((getMicrotime()-$t)*1000, 0);
|
||||||
|
$this->error = $this->lastError();
|
||||||
|
$this->numRows = $this->lastNumRows($this->_result);
|
||||||
|
$this->logQuery($sql);
|
||||||
|
if (($this->debug && $this->error) || ($this->fullDebug))
|
||||||
|
$this->showQuery($sql);
|
||||||
|
|
||||||
|
return $this->error? false: $this->_result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single row of results from the _last_ SQL query.
|
||||||
|
*
|
||||||
|
* @param resource $res
|
||||||
|
* @return array A single row of results
|
||||||
|
*/
|
||||||
|
function farr ($assoc=false)
|
||||||
|
{
|
||||||
|
if ($assoc === false)
|
||||||
|
{
|
||||||
|
return $this->fetchRow();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->fetchRow($assoc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single row of results for a _given_ SQL query.
|
||||||
|
*
|
||||||
|
* @param string $sql SQL statement
|
||||||
|
* @return array A single row of results
|
||||||
|
*/
|
||||||
|
function one ($sql)
|
||||||
|
{
|
||||||
|
return $this->query($sql)? $this->fetchArray(): false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of all result rows for a given SQL query.
|
||||||
|
* Returns false if no rows matched.
|
||||||
|
*
|
||||||
|
* @param string $sql SQL statement
|
||||||
|
* @return array Array of resultset rows, or false if no rows matched
|
||||||
|
*/
|
||||||
|
function all ($sql)
|
||||||
|
{
|
||||||
|
if($this->query($sql))
|
||||||
|
{
|
||||||
|
$out=array();
|
||||||
|
while ($item = $this->fetchArray(null, true))
|
||||||
|
{
|
||||||
|
$out[] = $item;
|
||||||
|
}
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a single field of the first of query results for a given SQL query, or false if empty.
|
||||||
|
*
|
||||||
|
* @param string $name Name of the field
|
||||||
|
* @param string $sql SQL query
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
|
function field ($name, $sql)
|
||||||
|
{
|
||||||
|
$data = $this->one($sql);
|
||||||
|
return empty($data[$name])? false: $data[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the specified table contains any record matching specified SQL
|
||||||
|
*
|
||||||
|
* @param string $table Name of table to look in
|
||||||
|
* @param string $sql SQL WHERE clause (condition only, not the "WHERE" part)
|
||||||
|
* @return boolean True if the table has a matching record, else false
|
||||||
|
*/
|
||||||
|
function hasAny($table, $sql)
|
||||||
|
{
|
||||||
|
$out = $this->one("SELECT COUNT(*) AS count FROM {$table}".($sql? " WHERE {$sql}":""));
|
||||||
|
return is_array($out)? $out[0]['count']: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if it's connected to the database
|
||||||
|
*
|
||||||
|
* @return boolean True if the database is connected, else false
|
||||||
|
*/
|
||||||
|
function isConnected()
|
||||||
|
{
|
||||||
|
return $this->connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outputs the contents of the log.
|
||||||
|
*
|
||||||
|
* @param boolean $sorted
|
||||||
|
*/
|
||||||
|
function showLog($sorted=false)
|
||||||
|
{
|
||||||
|
$log = $sorted?
|
||||||
|
sortByKey($this->_queriesLog, 'took', 'desc', SORT_NUMERIC):
|
||||||
|
$this->_queriesLog;
|
||||||
|
|
||||||
|
print("<table border=1>\n<tr><th colspan=7>{$this->_queriesCnt} queries took {$this->_queriesTime} ms</th></tr>\n");
|
||||||
|
print("<tr><td>Nr</td><td>Query</td><td>Error</td><td>Affected</td><td>Num. rows</td><td>Took (ms)</td></tr>\n");
|
||||||
|
|
||||||
|
foreach($log AS $k=>$i)
|
||||||
|
{
|
||||||
|
print("<tr><td>".($k+1)."</td><td>{$i['query']}</td><td>{$i['error']}</td><td align='right'>{$i['affected']}</td><td align='right'>{$i['numRows']}</td><td align='right'>{$i['took']}</td></tr>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
print("</table>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log given SQL query.
|
||||||
|
*
|
||||||
|
* @param string $sql SQL statement
|
||||||
|
*/
|
||||||
|
function logQuery($sql)
|
||||||
|
{
|
||||||
|
$this->_queriesCnt++;
|
||||||
|
$this->_queriesTime += $this->took;
|
||||||
|
|
||||||
|
$this->_queriesLog[] = array(
|
||||||
|
'query'=>$sql,
|
||||||
|
'error'=>$this->error,
|
||||||
|
'affected'=>$this->affected,
|
||||||
|
'numRows'=>$this->numRows,
|
||||||
|
'took'=>$this->took
|
||||||
|
);
|
||||||
|
|
||||||
|
if (count($this->_queriesLog) > $this->_queriesLogMax)
|
||||||
|
{
|
||||||
|
array_pop($this->_queriesLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->error)
|
||||||
|
return false; // shouldn't we be logging errors somehow?
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output information about an SQL query. The SQL statement, number of rows in resultset,
|
||||||
|
* and execution time in microseconds. If the query fails, and error is output instead.
|
||||||
|
*
|
||||||
|
* @param string $sql
|
||||||
|
*/
|
||||||
|
function showQuery($sql)
|
||||||
|
{
|
||||||
|
$error = $this->error;
|
||||||
|
|
||||||
|
if (strlen($sql)>200 && !$this->fullDebug)
|
||||||
|
{
|
||||||
|
$sql = substr($sql, 0, 200) .'[...]';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->debug || $error)
|
||||||
|
{
|
||||||
|
print("<p style=\"text-align:left\"><b>Query:</b> {$sql} <small>[Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]</small>");
|
||||||
|
if($error)
|
||||||
|
{
|
||||||
|
print("<br /><span style=\"color:Red;text-align:left\"><b>ERROR:</b> {$this->error}</span>");
|
||||||
|
}
|
||||||
|
print('</p>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -9,7 +9,7 @@
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
|
@ -32,12 +32,18 @@
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uses('object');
|
if(!class_exists('Object'))
|
||||||
|
{
|
||||||
|
uses('object');
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
config('database');
|
if (!class_exists('DATABASE_CONFIG'))
|
||||||
|
{
|
||||||
|
config('database');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DbFactory
|
* DbFactory
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic layer for DBO.
|
* Generic layer for DBO.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
|
@ -16,11 +16,11 @@
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.2.9
|
* @since CakePHP v 0.2.9
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
* @modifiedby $LastChangedBy$
|
* @modifiedby $LastChangedBy$
|
||||||
|
@ -30,60 +30,60 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract DBO class file.
|
* Abstract DBO class file.
|
||||||
*
|
*
|
||||||
* All implementations override this class.
|
* All implementations override this class.
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.2.9
|
* @since CakePHP v 0.2.9
|
||||||
*/
|
*/
|
||||||
class DBO_generic extends DBO
|
class DBO_generic extends DBO
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function connect ($config)
|
function connect ($config)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function disconnect ()
|
function disconnect ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function execute ($sql)
|
function execute ($sql)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function fetchRow ()
|
function fetchRow ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function tablesList ()
|
function tablesList ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function fields ($tableName)
|
function fields ($tableName)
|
||||||
|
@ -91,7 +91,7 @@ class DBO_generic extends DBO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function prepareValue ($data)
|
function prepareValue ($data)
|
||||||
|
@ -99,15 +99,15 @@ class DBO_generic extends DBO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function lastError ()
|
function lastError ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function lastAffected ()
|
function lastAffected ()
|
||||||
|
@ -115,23 +115,23 @@ class DBO_generic extends DBO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function lastNumRows ()
|
function lastNumRows ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function lastInsertId ()
|
function lastInsertId ()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method defined in subclasses.
|
* Abstract method defined in subclasses.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function selectLimit ($limit, $offset=null)
|
function selectLimit ($limit, $offset=null)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.2.9
|
* @since CakePHP v 0.2.9
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
* @modifiedby $LastChangedBy$
|
* @modifiedby $LastChangedBy$
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
/**
|
/**
|
||||||
* Include DBO.
|
* Include DBO.
|
||||||
*/
|
*/
|
||||||
uses('model'.DS.'dbo'.DS.'dbo');
|
uses('model'.DS.'datasources'.DS.'dbo_source');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for class.
|
* Short description for class.
|
||||||
|
@ -40,30 +40,72 @@ uses('model'.DS.'dbo'.DS.'dbo');
|
||||||
* Long description for class
|
* Long description for class
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.2.9
|
* @since CakePHP v 0.2.9
|
||||||
*/
|
*/
|
||||||
class DBO_MySQL extends DBO
|
class DboMysql extends DboSource
|
||||||
{
|
{
|
||||||
|
|
||||||
|
var $description = "MySQL DBO Driver";
|
||||||
|
|
||||||
|
var $_baseConfig = array('persistent' => true,
|
||||||
|
'host' => 'localhost',
|
||||||
|
'login' => 'root',
|
||||||
|
'password' => '',
|
||||||
|
'database' => 'cake',
|
||||||
|
'port' => 3306
|
||||||
|
);
|
||||||
|
|
||||||
|
var $columns = array(
|
||||||
|
'primary_key' => array('name' => 'int(11) DEFAULT NULL auto_increment'),
|
||||||
|
'string' => array('name' => 'varchar', 'limit' => '255'),
|
||||||
|
'text' => array('name' => 'text'),
|
||||||
|
'integer' => array('name' => 'int', 'limit' => '11'),
|
||||||
|
'float' => array('name' => 'float'),
|
||||||
|
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s'),
|
||||||
|
'timestamp' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s'),
|
||||||
|
'time' => array('name' => 'time', 'format' => 'h:i:s'),
|
||||||
|
'date' => array('name' => 'date', 'format' => 'Y-m-d'),
|
||||||
|
'binary' => array('name' => 'blob'),
|
||||||
|
'boolean' => array('name' => 'tinyint', 'limit' => '1')
|
||||||
|
);
|
||||||
|
|
||||||
|
function __construct ($config)
|
||||||
|
{
|
||||||
|
parent::__construct($config);
|
||||||
|
return $this->connect();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to the database using options in the given configuration array.
|
* Connects to the database using options in the given configuration array.
|
||||||
*
|
*
|
||||||
* @param array $config Configuration array for connecting
|
|
||||||
* @return boolean True if the database could be connected, else false
|
* @return boolean True if the database could be connected, else false
|
||||||
*/
|
*/
|
||||||
function connect ($config)
|
function connect ()
|
||||||
{
|
{
|
||||||
if ($config)
|
$config = $this->config;
|
||||||
|
if ($config['persistent'])
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$connect = 'mysql_pconnect';
|
||||||
$this->_conn = $config['connect']($config['host'],$config['login'],$config['password']);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$connect = 'mysql_connect';
|
||||||
}
|
}
|
||||||
$this->connected = $this->_conn? true: false;
|
|
||||||
|
|
||||||
if($this->connected)
|
$this->connected = false;
|
||||||
return mysql_select_db($config['database'], $this->_conn);
|
$this->connection = $connect($config['host'], $config['login'], $config['password']);
|
||||||
else{
|
if ($this->connection)
|
||||||
|
{
|
||||||
|
$this->connected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->connected)
|
||||||
|
{
|
||||||
|
return mysql_select_db($config['database'], $this->connection);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
//die('Could not connect to DB.');
|
//die('Could not connect to DB.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +117,7 @@ class DBO_MySQL extends DBO
|
||||||
*/
|
*/
|
||||||
function disconnect ()
|
function disconnect ()
|
||||||
{
|
{
|
||||||
return mysql_close($this->_conn);
|
return mysql_close($this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,39 +126,65 @@ class DBO_MySQL extends DBO
|
||||||
* @param string $sql SQL statement
|
* @param string $sql SQL statement
|
||||||
* @return resource Result resource identifier
|
* @return resource Result resource identifier
|
||||||
*/
|
*/
|
||||||
function execute ($sql)
|
function __execute ($sql)
|
||||||
{
|
{
|
||||||
return mysql_query($sql, $this->_conn);
|
return mysql_query($sql, $this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MySQL query abstraction
|
||||||
|
*
|
||||||
|
* @param string $method Method name
|
||||||
|
* @param array $params Parameters
|
||||||
|
* @return resource Result resource identifier
|
||||||
|
*/
|
||||||
|
function query ()
|
||||||
|
{
|
||||||
|
$args = func_get_args();
|
||||||
|
if (count($args) == 1)
|
||||||
|
{
|
||||||
|
return $this->fetchAll($args[0]);
|
||||||
|
}
|
||||||
|
elseif (count($args) > 1 && strpos($args[0], 'findBy') === 0)
|
||||||
|
{
|
||||||
|
$field = Inflector::underscore(str_replace('findBy', '', $args[0]));
|
||||||
|
$query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]);
|
||||||
|
return $args[2]->find($query);
|
||||||
|
}
|
||||||
|
elseif (count($args) > 1 && strpos($args[0], 'findAllBy') === 0)
|
||||||
|
{
|
||||||
|
$field = Inflector::underscore(str_replace('findAllBy', '', $args[0]));
|
||||||
|
$query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]);
|
||||||
|
return $args[2]->findAll($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a row from given resultset as an array .
|
* Returns a row from given resultset as an array .
|
||||||
*
|
*
|
||||||
* @param bool $assoc Associative array only, or both?
|
* @param bool $assoc Associative array only, or both?
|
||||||
* @return array The fetched row as an array
|
* @return array The fetched row as an array
|
||||||
*/
|
*/
|
||||||
function fetchRow ($assoc=false)
|
function fetchRow ($assoc = false)
|
||||||
{
|
{
|
||||||
//return mysql_fetch_array($this->_result, $assoc? MYSQL_ASSOC: MYSQL_BOTH);
|
//return mysql_fetch_array($this->_result, $assoc? MYSQL_ASSOC: MYSQL_BOTH);
|
||||||
$this->mysqlResultSet($this->_result);
|
$this->resultSet($this->_result);
|
||||||
$resultRow = $this->fetchResult();
|
$resultRow = $this->fetchResult();
|
||||||
return $resultRow;
|
return $resultRow;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
|
* Returns an array of sources (tables) in the database.
|
||||||
*
|
*
|
||||||
* @return array Array of tablenames in the database
|
* @return array Array of tablenames in the database
|
||||||
*/
|
*/
|
||||||
function tablesList ()
|
function listSources ()
|
||||||
{
|
{
|
||||||
$result = mysql_list_tables($this->config['database'], $this->_conn);
|
$result = mysql_list_tables($this->config['database'], $this->connection);
|
||||||
|
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
|
return null;
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -135,39 +203,164 @@ class DBO_MySQL extends DBO
|
||||||
* @param string $tableName Name of database table to inspect
|
* @param string $tableName Name of database table to inspect
|
||||||
* @return array Fields in table. Keys are name and type
|
* @return array Fields in table. Keys are name and type
|
||||||
*/
|
*/
|
||||||
function fields ($tableName)
|
function &describe (&$model)
|
||||||
{
|
{
|
||||||
|
$cache = parent::describe($model);
|
||||||
|
if ($cache != null)
|
||||||
|
{
|
||||||
|
return $cache;
|
||||||
|
}
|
||||||
|
|
||||||
$fields = false;
|
$fields = false;
|
||||||
$cols = $this->all("DESC {$tableName}");
|
$cols = $this->query('DESC ' . $this->name($model->source));
|
||||||
|
|
||||||
foreach ($cols as $column)
|
foreach ($cols as $column)
|
||||||
{
|
{
|
||||||
// $fields[] = array('name'=>$column['Field'], 'type'=>$column['Type']);
|
$colKey = array_keys($column);
|
||||||
if(isset($column['COLUMNS']) && !isset($column[0]))
|
if (isset($column[$colKey[0]]) && !isset($column[0]))
|
||||||
{
|
{
|
||||||
$column[0] = $column['COLUMNS'];
|
$column[0] = $column[$colKey[0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($column[0]))
|
if (isset($column[0]))
|
||||||
{
|
{
|
||||||
$fields[] = array('name' => $column[0]['Field'], 'type' => $column[0]['Type']);
|
$fields[] = array('name' => $column[0]['Field'], 'type' => $column[0]['Type']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->__cacheDescription($model->source, $fields);
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a quoted name of $data for use in an SQL statement.
|
||||||
|
*
|
||||||
|
* @param string $data Name (table/field) to be prepared for use in an SQL statement
|
||||||
|
* @return string Quoted for MySQL
|
||||||
|
*/
|
||||||
|
function name ($data)
|
||||||
|
{
|
||||||
|
if ($data == '*')
|
||||||
|
{
|
||||||
|
return '*';
|
||||||
|
}
|
||||||
|
return '`'.$data.'`';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||||
*
|
*
|
||||||
* @param string $data String to be prepared for use in an SQL statement
|
* @param string $data String to be prepared for use in an SQL statement
|
||||||
|
* @param string $column The column into which this data will be inserted
|
||||||
* @return string Quoted and escaped
|
* @return string Quoted and escaped
|
||||||
*/
|
*/
|
||||||
function prepareValue ($data)
|
function value ($data, $column = null)
|
||||||
{
|
{
|
||||||
return "'".mysql_real_escape_string($data, $this->_conn)."'";
|
$parent = parent::value($data, $column);
|
||||||
|
if ($parent != null)
|
||||||
|
{
|
||||||
|
return $parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ini_get('magic_quotes_gpc') == 1)
|
||||||
|
{
|
||||||
|
$data = stripslashes($data);
|
||||||
|
}
|
||||||
|
if (version_compare(phpversion(),"4.3.0") == "-1")
|
||||||
|
{
|
||||||
|
$data = mysql_escape_string($data, $this->connection);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$data = mysql_real_escape_string($data, $this->connection);
|
||||||
|
}
|
||||||
|
return "'" . $data . "'";
|
||||||
|
// TODO: Add logic that formats/escapes data based on column type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates between PHP boolean values and MySQL (faked) boolean values
|
||||||
|
*
|
||||||
|
* @param mixed $data Value to be translated
|
||||||
|
* @return mixed Converted boolean value
|
||||||
|
*/
|
||||||
|
function boolean ($data)
|
||||||
|
{
|
||||||
|
if ($data === true || $data === false)
|
||||||
|
{
|
||||||
|
if ($data === true)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (intval($data !== 0))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function create(&$model, $fields = null, $values = null)
|
||||||
|
{
|
||||||
|
return parent::create($model, $fields, $values);
|
||||||
|
}
|
||||||
|
|
||||||
|
function update(&$model, $fields = null, $values = null)
|
||||||
|
{
|
||||||
|
return parent::update($model, $fields, $values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Begin a transaction
|
||||||
|
*
|
||||||
|
* @return boolean True on success, false on fail (i.e. if the database/model does not support transactions).
|
||||||
|
*/
|
||||||
|
function begin (&$model)
|
||||||
|
{
|
||||||
|
if (parent::begin($model))
|
||||||
|
{
|
||||||
|
if ($this->execute('START TRANSACTION'))
|
||||||
|
{
|
||||||
|
$this->__transactionStarted = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commit a transaction
|
||||||
|
*
|
||||||
|
* @return boolean True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
|
||||||
|
*/
|
||||||
|
function commit (&$model)
|
||||||
|
{
|
||||||
|
if (parent::commit($model))
|
||||||
|
{
|
||||||
|
$this->__transactionStarted;
|
||||||
|
return $this->execute('COMMIT');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rollback a transaction
|
||||||
|
*
|
||||||
|
* @return boolean True on success, false on fail (i.e. if the database/model does not support transactions, or a transaction has not started).
|
||||||
|
*/
|
||||||
|
function rollback (&$model)
|
||||||
|
{
|
||||||
|
if (parent::rollback($model))
|
||||||
|
{
|
||||||
|
return $this->execute('ROLLBACK');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a formatted error message from previous database operation.
|
* Returns a formatted error message from previous database operation.
|
||||||
*
|
*
|
||||||
|
@ -175,17 +368,26 @@ class DBO_MySQL extends DBO
|
||||||
*/
|
*/
|
||||||
function lastError ()
|
function lastError ()
|
||||||
{
|
{
|
||||||
return mysql_errno($this->_conn)? mysql_errno($this->_conn).': '.mysql_error($this->_conn): null;
|
if (mysql_errno($this->connection))
|
||||||
|
{
|
||||||
|
return mysql_errno($this->connection).': '.mysql_error($this->connection);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
|
* Returns number of affected rows in previous database operation. If no previous operation exists,
|
||||||
|
* this returns false.
|
||||||
*
|
*
|
||||||
* @return int Number of affected rows
|
* @return int Number of affected rows
|
||||||
*/
|
*/
|
||||||
function lastAffected ()
|
function lastAffected ()
|
||||||
{
|
{
|
||||||
return $this->_result? mysql_affected_rows($this->_conn): false;
|
if ($this->_result)
|
||||||
|
{
|
||||||
|
return mysql_affected_rows($this->connection);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,7 +398,11 @@ class DBO_MySQL extends DBO
|
||||||
*/
|
*/
|
||||||
function lastNumRows ()
|
function lastNumRows ()
|
||||||
{
|
{
|
||||||
return $this->_result? @mysql_num_rows($this->_result): false;
|
if ($this->_result)
|
||||||
|
{
|
||||||
|
return @mysql_num_rows($this->_result);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -204,9 +410,9 @@ class DBO_MySQL extends DBO
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function lastInsertId ()
|
function lastInsertId ($source = null)
|
||||||
{
|
{
|
||||||
return mysql_insert_id($this->_conn);
|
return mysql_insert_id($this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,9 +422,23 @@ class DBO_MySQL extends DBO
|
||||||
* @param int $offset Offset from which to start results
|
* @param int $offset Offset from which to start results
|
||||||
* @return string SQL limit/offset statement
|
* @return string SQL limit/offset statement
|
||||||
*/
|
*/
|
||||||
function selectLimit ($limit, $offset=null)
|
function limit ($limit, $offset = null)
|
||||||
{
|
{
|
||||||
return $limit? " LIMIT".($offset? " {$offset},": null)." {$limit}": null;
|
if ($limit)
|
||||||
|
{
|
||||||
|
$rt = '';
|
||||||
|
if (!strpos(low($limit), 'limit') || strpos(low($limit), 'limit') === 0)
|
||||||
|
{
|
||||||
|
$rt = ' LIMIT';
|
||||||
|
}
|
||||||
|
if ($offset)
|
||||||
|
{
|
||||||
|
$rt .= ' ' . $offset. ',';
|
||||||
|
}
|
||||||
|
$rt .= ' ' . $limit;
|
||||||
|
return $rt;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -226,19 +446,19 @@ class DBO_MySQL extends DBO
|
||||||
*
|
*
|
||||||
* @param unknown_type $results
|
* @param unknown_type $results
|
||||||
*/
|
*/
|
||||||
function mysqlResultSet(&$results)
|
function resultSet(&$results)
|
||||||
{
|
{
|
||||||
$this->results =& $results;
|
$this->results =& $results;
|
||||||
$this->map = array();
|
$this->map = array();
|
||||||
$index = 0;
|
|
||||||
$num_fields = mysql_num_fields($results);
|
$num_fields = mysql_num_fields($results);
|
||||||
$j=0;
|
$index = 0;
|
||||||
|
$j = 0;
|
||||||
|
|
||||||
while ($j < $num_fields)
|
while ($j < $num_fields)
|
||||||
{
|
{
|
||||||
$column = mysql_fetch_field($results,$j);
|
$column = mysql_fetch_field($results,$j);
|
||||||
|
|
||||||
if(!empty($column->table))
|
if (!empty($column->table))
|
||||||
{
|
{
|
||||||
$this->map[$index++] = array($column->table, $column->name);
|
$this->map[$index++] = array($column->table, $column->name);
|
||||||
}
|
}
|
||||||
|
@ -251,7 +471,7 @@ class DBO_MySQL extends DBO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Fetches the next row from the current result set
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
|
@ -274,7 +494,6 @@ class DBO_MySQL extends DBO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link http://pear.php.net/package/DB PEAR::DB} layer for DBO.
|
* {@link http://pear.php.net/package/DB PEAR::DB} layer for DBO.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
|
@ -16,11 +16,11 @@
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.2.9
|
* @since CakePHP v 0.2.9
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
* @modifiedby $LastChangedBy$
|
* @modifiedby $LastChangedBy$
|
||||||
|
@ -37,16 +37,16 @@ vendor('Pear/DB');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link http://pear.php.net/package/DB PEAR::DB} layer for DBO.
|
* {@link http://pear.php.net/package/DB PEAR::DB} layer for DBO.
|
||||||
*
|
*
|
||||||
* Long description for class
|
* Long description for class
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.2.9
|
* @since CakePHP v 0.2.9
|
||||||
*/
|
*/
|
||||||
class DBO_Pear extends DBO
|
class DBO_Pear extends DBO
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PEAR::DB object with which we connect.
|
* PEAR::DB object with which we connect.
|
||||||
*
|
*
|
||||||
|
@ -61,26 +61,21 @@ class DBO_Pear extends DBO
|
||||||
* @param array $config Configuration array for connecting
|
* @param array $config Configuration array for connecting
|
||||||
* @return boolean True if the database could be connected, else false
|
* @return boolean True if the database could be connected, else false
|
||||||
*/
|
*/
|
||||||
function connect ($config)
|
function connect ($config)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
|
|
||||||
if (preg_match('#^pear[-_](.*)$#i', $config['driver'], $res))
|
|
||||||
{
|
|
||||||
$config['driver'] = $res[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
$dsn = $config['driver'].'://'.$config['login'].':'.$config['password'].'@'.$config['host'].'/'.$config['database'];
|
$dsn = $config['driver'].'://'.$config['login'].':'.$config['password'].'@'.$config['host'].'/'.$config['database'];
|
||||||
$options = array(
|
$options = array(
|
||||||
'debug' => DEBUG-1,
|
'debug' => DEBUG-1,
|
||||||
'portability' => DB_PORTABILITY_ALL,
|
'portability' => DB_PORTABILITY_ALL,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->_pear =& DB::connect($dsn, $options);
|
$this->_pear =& DB::connect($dsn, $options);
|
||||||
$this->connected = $this->_pear? true: false;
|
$this->connected = $this->_pear? true: false;
|
||||||
|
|
||||||
return !(PEAR::isError($this->_pear));
|
return !(PEAR::isError($this->_pear));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,7 +83,7 @@ class DBO_Pear extends DBO
|
||||||
*
|
*
|
||||||
* @return boolean True if the database could be disconnected, else false
|
* @return boolean True if the database could be disconnected, else false
|
||||||
*/
|
*/
|
||||||
function disconnect ()
|
function disconnect ()
|
||||||
{
|
{
|
||||||
die('Please implement DBO::disconnect() first.');
|
die('Please implement DBO::disconnect() first.');
|
||||||
}
|
}
|
||||||
|
@ -99,7 +94,7 @@ class DBO_Pear extends DBO
|
||||||
* @param string $sql SQL statement
|
* @param string $sql SQL statement
|
||||||
* @return resource Result resource identifier
|
* @return resource Result resource identifier
|
||||||
*/
|
*/
|
||||||
function execute ($sql)
|
function execute ($sql)
|
||||||
{
|
{
|
||||||
return $this->_pear->query($sql);
|
return $this->_pear->query($sql);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +104,7 @@ class DBO_Pear extends DBO
|
||||||
*
|
*
|
||||||
* @return array The fetched row as an array
|
* @return array The fetched row as an array
|
||||||
*/
|
*/
|
||||||
function fetchRow ()
|
function fetchRow ()
|
||||||
{
|
{
|
||||||
return $this->_result->fetchRow(DB_FETCHMODE_ASSOC);
|
return $this->_result->fetchRow(DB_FETCHMODE_ASSOC);
|
||||||
}
|
}
|
||||||
|
@ -120,11 +115,11 @@ class DBO_Pear extends DBO
|
||||||
*
|
*
|
||||||
* @return array Array of tablenames in the database
|
* @return array Array of tablenames in the database
|
||||||
*/
|
*/
|
||||||
function tablesList ()
|
function tablesList ()
|
||||||
{
|
{
|
||||||
$driver = $this->config['driver'];
|
$driver = $this->config['driver'];
|
||||||
$tables = array();
|
$tables = array();
|
||||||
|
|
||||||
if ('postgres' == $driver)
|
if ('postgres' == $driver)
|
||||||
{
|
{
|
||||||
$sql = "SELECT a.relname AS name
|
$sql = "SELECT a.relname AS name
|
||||||
|
@ -134,7 +129,7 @@ class DBO_Pear extends DBO
|
||||||
AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));";
|
AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));";
|
||||||
|
|
||||||
$result = $this->all($sql);
|
$result = $this->all($sql);
|
||||||
foreach ($result as $item)
|
foreach ($result as $item)
|
||||||
{
|
{
|
||||||
$tables[] = $item['name'];
|
$tables[] = $item['name'];
|
||||||
}
|
}
|
||||||
|
@ -155,12 +150,12 @@ class DBO_Pear extends DBO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR);
|
trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $tables;
|
return $tables;
|
||||||
}
|
}
|
||||||
|
@ -199,7 +194,7 @@ class DBO_Pear extends DBO
|
||||||
*
|
*
|
||||||
* @return string Error message
|
* @return string Error message
|
||||||
*/
|
*/
|
||||||
function lastError ()
|
function lastError ()
|
||||||
{
|
{
|
||||||
return PEAR::isError($this->_result)? $this->_result->getMessage(): null;
|
return PEAR::isError($this->_result)? $this->_result->getMessage(): null;
|
||||||
}
|
}
|
||||||
|
@ -215,12 +210,12 @@ class DBO_Pear extends DBO
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||||
* this returns false.
|
* this returns false.
|
||||||
*
|
*
|
||||||
* @return int Number of rows in resultset
|
* @return int Number of rows in resultset
|
||||||
*/
|
*/
|
||||||
function lastNumRows ()
|
function lastNumRows ()
|
||||||
{
|
{
|
||||||
if (method_exists($this->_result, 'numRows'))
|
if (method_exists($this->_result, 'numRows'))
|
||||||
{
|
{
|
||||||
|
@ -236,9 +231,9 @@ class DBO_Pear extends DBO
|
||||||
* Returns the ID generated from the previous INSERT operation.
|
* Returns the ID generated from the previous INSERT operation.
|
||||||
*
|
*
|
||||||
* @param string $table Name of the database table
|
* @param string $table Name of the database table
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function lastInsertId ($table)
|
function lastInsertId ($table)
|
||||||
{
|
{
|
||||||
return $this->field('id', "SELECT MAX(id) FROM {$table}");
|
return $this->field('id', "SELECT MAX(id) FROM {$table}");
|
||||||
}
|
}
|
||||||
|
@ -254,7 +249,7 @@ class DBO_Pear extends DBO
|
||||||
{
|
{
|
||||||
return ' ' . $this->_pear->modifyLimitQuery('', $offset, $limit);
|
return ' ' . $this->_pear->modifyLimitQuery('', $offset, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -3,24 +3,24 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PostgreSQL layer for DBO.
|
* PostgreSQL layer for DBO.
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.9.1.114
|
* @since CakePHP v 0.9.1.114
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
* @modifiedby $LastChangedBy$
|
* @modifiedby $LastChangedBy$
|
||||||
|
@ -31,41 +31,75 @@
|
||||||
/**
|
/**
|
||||||
* Include DBO.
|
* Include DBO.
|
||||||
*/
|
*/
|
||||||
uses('model'.DS.'dbo'.DS.'dbo');
|
uses('model'.DS.'datasources'.DS.'dbo_source');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PostgreSQL layer for DBO.
|
* PostgreSQL layer for DBO.
|
||||||
*
|
*
|
||||||
* Long description for class
|
* Long description for class
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.9.1.114
|
* @since CakePHP v 0.9.1.114
|
||||||
*/
|
*/
|
||||||
class DBO_Postgres extends DBO
|
class DboPostgres extends DboSource
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
var $description = "PostgreSQL DBO Driver";
|
||||||
|
|
||||||
|
var $_baseConfig = array('persistent' => true,
|
||||||
|
'host' => 'localhost',
|
||||||
|
'login' => 'root',
|
||||||
|
'password' => '',
|
||||||
|
'database' => 'cake',
|
||||||
|
'port' => 3306
|
||||||
|
);
|
||||||
|
|
||||||
|
var $columns = array(
|
||||||
|
'primary_key' => array('name' => 'serial primary key'),
|
||||||
|
'string' => array('name' => 'varchar', 'limit' => '255'),
|
||||||
|
'text' => array('name' => 'text'),
|
||||||
|
'integer' => array('name' => 'integer'),
|
||||||
|
'float' => array('name' => 'float'),
|
||||||
|
'datetime' => array('name' => 'timestamp'),
|
||||||
|
'timestamp' => array('name' => 'timestamp'),
|
||||||
|
'time' => array('name' => 'time'),
|
||||||
|
'date' => array('name' => 'date'),
|
||||||
|
'binary' => array('name' => 'bytea'),
|
||||||
|
'boolean' => array('name' => 'boolean')
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to the database using options in the given configuration array.
|
* Connects to the database using options in the given configuration array.
|
||||||
*
|
*
|
||||||
* @param array $config Configuration array for connecting
|
|
||||||
* @return True if successfully connected.
|
* @return True if successfully connected.
|
||||||
*/
|
*/
|
||||||
function connect ($config)
|
function connect ()
|
||||||
{
|
{
|
||||||
if ($config)
|
$config = $this->config;
|
||||||
|
if ($config['persistent'])
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$connect = 'pg_pconnect';
|
||||||
$this->_conn = $config['connect']("host={$config['host']} dbname={$config['database']} user={$config['login']} password={$config['password']}");
|
|
||||||
}
|
}
|
||||||
$this->connected = $this->_conn? true: false;
|
|
||||||
|
|
||||||
if($this->connected)
|
|
||||||
return true;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//die('Could not connect to DB.');
|
$connect = 'pg_connect';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->connection = $connect("dbname={$config['database']} user={$config['login']} password={$config['password']}");
|
||||||
|
if ($this->connection)
|
||||||
|
{
|
||||||
|
$this->connected = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,9 +107,9 @@ class DBO_Postgres extends DBO
|
||||||
*
|
*
|
||||||
* @return boolean True if the database could be disconnected, else false
|
* @return boolean True if the database could be disconnected, else false
|
||||||
*/
|
*/
|
||||||
function disconnect ()
|
function disconnect ()
|
||||||
{
|
{
|
||||||
return pg_close($this->_conn);
|
return pg_close($this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,9 +118,34 @@ class DBO_Postgres extends DBO
|
||||||
* @param string $sql SQL statement
|
* @param string $sql SQL statement
|
||||||
* @return resource Result resource identifier
|
* @return resource Result resource identifier
|
||||||
*/
|
*/
|
||||||
function execute ($sql)
|
function __execute ($sql)
|
||||||
{
|
{
|
||||||
return pg_query($this->_conn, $sql);
|
return pg_query($this->connection, $sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
function query ()
|
||||||
|
{
|
||||||
|
$args = func_get_args();
|
||||||
|
echo "<pre>";
|
||||||
|
print_r($args);
|
||||||
|
echo "</pre>";
|
||||||
|
die();
|
||||||
|
if (count($args) == 1)
|
||||||
|
{
|
||||||
|
return $this->fetchAll($args[0]);
|
||||||
|
}
|
||||||
|
elseif (count($args) > 1 && strpos($args[0], 'findBy') === 0)
|
||||||
|
{
|
||||||
|
$field = Inflector::underscore(str_replace('findBy', '', $args[0]));
|
||||||
|
$query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]);
|
||||||
|
return $args[2]->find($query);
|
||||||
|
}
|
||||||
|
elseif (count($args) > 1 && strpos($args[0], 'findAllBy') === 0)
|
||||||
|
{
|
||||||
|
$field = Inflector::underscore(str_replace('findAllBy', '', $args[0]));
|
||||||
|
$query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]);
|
||||||
|
return $args[2]->findAll($query);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,7 +153,7 @@ class DBO_Postgres extends DBO
|
||||||
*
|
*
|
||||||
* @return array The fetched row as an array
|
* @return array The fetched row as an array
|
||||||
*/
|
*/
|
||||||
function fetchRow ()
|
function fetchRow ()
|
||||||
{
|
{
|
||||||
return pg_fetch_array($this->_result);
|
return pg_fetch_array($this->_result);
|
||||||
}
|
}
|
||||||
|
@ -104,7 +163,7 @@ class DBO_Postgres extends DBO
|
||||||
*
|
*
|
||||||
* @return array Array of tablenames in the database
|
* @return array Array of tablenames in the database
|
||||||
*/
|
*/
|
||||||
function tablesList ()
|
function listSources ()
|
||||||
{
|
{
|
||||||
$sql = "SELECT a.relname AS name
|
$sql = "SELECT a.relname AS name
|
||||||
FROM pg_class a, pg_user b
|
FROM pg_class a, pg_user b
|
||||||
|
@ -112,17 +171,20 @@ class DBO_Postgres extends DBO
|
||||||
AND relname !~ '^xin[vx][0-9]+' AND b.usesysid = a.relowner
|
AND relname !~ '^xin[vx][0-9]+' AND b.usesysid = a.relowner
|
||||||
AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));";
|
AND NOT (EXISTS (SELECT viewname FROM pg_views WHERE viewname=a.relname));";
|
||||||
|
|
||||||
$result = $this->all($sql);
|
$this->execute($sql);
|
||||||
|
$result = $this->fetchRow();
|
||||||
|
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
trigger_error(ERROR_NO_TABLE_LIST, E_USER_ERROR);
|
return null;
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tables = array();
|
$tables = array();
|
||||||
foreach ($result as $item) $tables[] = $item['name'];
|
foreach ($result as $item)
|
||||||
|
{
|
||||||
|
$tables[] = $item['name'];
|
||||||
|
}
|
||||||
return $tables;
|
return $tables;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +198,7 @@ class DBO_Postgres extends DBO
|
||||||
function fields ($tableName)
|
function fields ($tableName)
|
||||||
{
|
{
|
||||||
$sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$tableName}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid";
|
$sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$tableName}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid";
|
||||||
|
|
||||||
$fields = false;
|
$fields = false;
|
||||||
foreach ($this->all($sql) as $field) {
|
foreach ($this->all($sql) as $field) {
|
||||||
$fields[] = array(
|
$fields[] = array(
|
||||||
|
@ -153,7 +215,18 @@ class DBO_Postgres extends DBO
|
||||||
* @param string $data String to be prepared for use in an SQL statement
|
* @param string $data String to be prepared for use in an SQL statement
|
||||||
* @return string Quoted and escaped
|
* @return string Quoted and escaped
|
||||||
*/
|
*/
|
||||||
function prepareValue ($data)
|
function name ($data)
|
||||||
|
{
|
||||||
|
return "'". $data."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||||
|
*
|
||||||
|
* @param string $data String to be prepared for use in an SQL statement
|
||||||
|
* @return string Quoted and escaped
|
||||||
|
*/
|
||||||
|
function value ($data)
|
||||||
{
|
{
|
||||||
return "'".pg_escape_string($data)."'";
|
return "'".pg_escape_string($data)."'";
|
||||||
}
|
}
|
||||||
|
@ -163,10 +236,14 @@ class DBO_Postgres extends DBO
|
||||||
*
|
*
|
||||||
* @return string Error message
|
* @return string Error message
|
||||||
*/
|
*/
|
||||||
function lastError ()
|
function lastError ()
|
||||||
{
|
{
|
||||||
$last_error = pg_last_error($this->_conn);
|
$last_error = pg_last_error($this->connection);
|
||||||
return $last_error? $last_error: null;
|
if ($last_error)
|
||||||
|
{
|
||||||
|
return $last_error;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,30 +253,38 @@ class DBO_Postgres extends DBO
|
||||||
*/
|
*/
|
||||||
function lastAffected ()
|
function lastAffected ()
|
||||||
{
|
{
|
||||||
return $this->_result? pg_affected_rows($this->_result): false;
|
if ($this->_result)
|
||||||
|
{
|
||||||
|
return pg_affected_rows($this->_result);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||||
* this returns false.
|
* this returns false.
|
||||||
*
|
*
|
||||||
* @return int Number of rows in resultset
|
* @return int Number of rows in resultset
|
||||||
*/
|
*/
|
||||||
function lastNumRows ()
|
function lastNumRows ()
|
||||||
{
|
{
|
||||||
return $this->_result? pg_num_rows($this->_result): false;
|
if ($this->_result)
|
||||||
|
{
|
||||||
|
return pg_num_rows($this->_result);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ID generated from the previous INSERT operation.
|
* Returns the ID generated from the previous INSERT operation.
|
||||||
*
|
*
|
||||||
* @param string $table Name of the database table
|
* @param string $source Name of the database table
|
||||||
* @param string $field Name of the ID database field. Defaults to "id"
|
* @param string $field Name of the ID database field. Defaults to "id"
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function lastInsertId ($table, $field='id')
|
function lastInsertId ($source, $field='id')
|
||||||
{
|
{
|
||||||
$sql = "SELECT CURRVAL('{$table}_{$field}_seq') AS max";
|
$sql = "SELECT CURRVAL('{$source}_{$field}_seq') AS max";
|
||||||
$res = $this->rawQuery($sql);
|
$res = $this->rawQuery($sql);
|
||||||
$data = $this->fetchRow($res);
|
$data = $this->fetchRow($res);
|
||||||
return $data['max'];
|
return $data['max'];
|
||||||
|
@ -212,9 +297,14 @@ class DBO_Postgres extends DBO
|
||||||
* @param int $offset Offset from which to start results
|
* @param int $offset Offset from which to start results
|
||||||
* @return string SQL limit/offset statement
|
* @return string SQL limit/offset statement
|
||||||
*/
|
*/
|
||||||
function selectLimit ($limit, $offset=null)
|
function limit ($limit, $offset = null)
|
||||||
{
|
{
|
||||||
return " LIMIT {$limit}".($offset? " OFFSET {$offset}": null);
|
$rt = ' LIMIT ' . $limit;
|
||||||
|
if ($offset)
|
||||||
|
{
|
||||||
|
$rt .= ' OFFSET ' . $offset;
|
||||||
|
}
|
||||||
|
return $rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQLite layer for DBO
|
* SQLite layer for DBO
|
||||||
*
|
*
|
||||||
* Long description for file
|
* Long description for file
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
|
@ -16,11 +16,11 @@
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.9.0
|
* @since CakePHP v 0.9.0
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
* @modifiedby $LastChangedBy$
|
* @modifiedby $LastChangedBy$
|
||||||
|
@ -35,14 +35,14 @@ uses('model'.DS.'dbo'.DS.'dbo');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DBO implementation for the SQLite DBMS.
|
* DBO implementation for the SQLite DBMS.
|
||||||
*
|
*
|
||||||
* Long description for class
|
* Long description for class
|
||||||
*
|
*
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.libs.model.dbo
|
* @subpackage cake.cake.libs.model.datasources.dbo
|
||||||
* @since CakePHP v 0.9.0
|
* @since CakePHP v 0.9.0
|
||||||
*/
|
*/
|
||||||
class DBO_SQLite extends DBO
|
class DBO_SQLite extends DBO
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,9 +51,9 @@ class DBO_SQLite extends DBO
|
||||||
* @param array $config Configuration array for connecting
|
* @param array $config Configuration array for connecting
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function connect($config)
|
function connect($config)
|
||||||
{
|
{
|
||||||
if ($config)
|
if ($config)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->_conn = $config['connect']($config['file']);
|
$this->_conn = $config['connect']($config['file']);
|
||||||
|
@ -75,7 +75,7 @@ class DBO_SQLite extends DBO
|
||||||
*
|
*
|
||||||
* @return boolean True if the database could be disconnected, else false
|
* @return boolean True if the database could be disconnected, else false
|
||||||
*/
|
*/
|
||||||
function disconnect()
|
function disconnect()
|
||||||
{
|
{
|
||||||
return sqlite_close($this->_conn);
|
return sqlite_close($this->_conn);
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ class DBO_SQLite extends DBO
|
||||||
* @param string $sql SQL statement
|
* @param string $sql SQL statement
|
||||||
* @return resource Result resource identifier
|
* @return resource Result resource identifier
|
||||||
*/
|
*/
|
||||||
function execute($sql)
|
function execute($sql)
|
||||||
{
|
{
|
||||||
return sqlite_query($this->_conn, $sql);
|
return sqlite_query($this->_conn, $sql);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ class DBO_SQLite extends DBO
|
||||||
*
|
*
|
||||||
* @return array The fetched row as an array
|
* @return array The fetched row as an array
|
||||||
*/
|
*/
|
||||||
function fetchRow()
|
function fetchRow()
|
||||||
{
|
{
|
||||||
return sqlite_fetch_array($this->_result);
|
return sqlite_fetch_array($this->_result);
|
||||||
}
|
}
|
||||||
|
@ -106,27 +106,27 @@ class DBO_SQLite extends DBO
|
||||||
*
|
*
|
||||||
* @return array Array of tablenames in the database
|
* @return array Array of tablenames in the database
|
||||||
*/
|
*/
|
||||||
function tablesList()
|
function tablesList()
|
||||||
{
|
{
|
||||||
$result = sqlite_query($this->_conn, "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
|
$result = sqlite_query($this->_conn, "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
|
||||||
|
|
||||||
if (!$result)
|
if (!$result)
|
||||||
{
|
{
|
||||||
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
|
trigger_error(ERROR_NO_TABLE_LIST, E_USER_NOTICE);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tables = array();
|
$tables = array();
|
||||||
while ($line = sqlite_fetch_array($result))
|
while ($line = sqlite_fetch_array($result))
|
||||||
{
|
{
|
||||||
$tables[] = $line[0];
|
$tables[] = $line[0];
|
||||||
}
|
}
|
||||||
return $tables;
|
return $tables;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of the fields in given table name.
|
* Returns an array of the fields in given table name.
|
||||||
*
|
*
|
||||||
* @param string $tableName Name of database table to inspect
|
* @param string $tableName Name of database table to inspect
|
||||||
|
@ -145,7 +145,7 @@ class DBO_SQLite extends DBO
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
* Returns a quoted and escaped string of $data for use in an SQL statement.
|
||||||
*
|
*
|
||||||
* @param string $data String to be prepared for use in an SQL statement
|
* @param string $data String to be prepared for use in an SQL statement
|
||||||
|
@ -156,17 +156,17 @@ class DBO_SQLite extends DBO
|
||||||
return "'" . sqlite_escape_string($data) . "'";
|
return "'" . sqlite_escape_string($data) . "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a formatted error message from previous database operation.
|
* Returns a formatted error message from previous database operation.
|
||||||
*
|
*
|
||||||
* @return string Error message
|
* @return string Error message
|
||||||
*/
|
*/
|
||||||
function lastError()
|
function lastError()
|
||||||
{
|
{
|
||||||
return sqlite_last_error($this->_conn)? sqlite_last_error($this->_conn).': '.sqlite_error_string(sqlite_last_error($this->_conn)): null;
|
return sqlite_last_error($this->_conn)? sqlite_last_error($this->_conn).': '.sqlite_error_string(sqlite_last_error($this->_conn)): null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
|
* Returns number of affected rows in previous database operation. If no previous operation exists, this returns false.
|
||||||
*
|
*
|
||||||
* @return int Number of affected rows
|
* @return int Number of affected rows
|
||||||
|
@ -176,28 +176,28 @@ class DBO_SQLite extends DBO
|
||||||
return $this->_result? sqlite_changes($this->_conn): false;
|
return $this->_result? sqlite_changes($this->_conn): false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns number of rows in previous resultset. If no previous resultset exists,
|
* Returns number of rows in previous resultset. If no previous resultset exists,
|
||||||
* this returns false.
|
* this returns false.
|
||||||
*
|
*
|
||||||
* @return int Number of rows in resultset
|
* @return int Number of rows in resultset
|
||||||
*/
|
*/
|
||||||
function lastNumRows()
|
function lastNumRows()
|
||||||
{
|
{
|
||||||
return $this->_result? sqlite_num_rows($this->_result): false;
|
return $this->_result? sqlite_num_rows($this->_result): false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ID generated from the previous INSERT operation.
|
* Returns the ID generated from the previous INSERT operation.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function lastInsertId()
|
function lastInsertId()
|
||||||
{
|
{
|
||||||
return sqlite_last_insert_rowid($this->_conn);
|
return sqlite_last_insert_rowid($this->_conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a limit statement in the correct format for the particular database.
|
* Returns a limit statement in the correct format for the particular database.
|
||||||
*
|
*
|
||||||
* @param int $limit Limit of results returned
|
* @param int $limit Limit of results returned
|
||||||
|
@ -209,4 +209,4 @@ class DBO_SQLite extends DBO
|
||||||
return " LIMIT {$limit}".($offset? ", {$offset}": null);
|
return " LIMIT {$limit}".($offset? ", {$offset}": null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
File diff suppressed because it is too large
Load diff
1454
cake/libs/model/model_php4.php
Normal file
1454
cake/libs/model/model_php4.php
Normal file
File diff suppressed because it is too large
Load diff
1449
cake/libs/model/model_php5.php
Normal file
1449
cake/libs/model/model_php5.php
Normal file
File diff suppressed because it is too large
Load diff
|
@ -140,98 +140,6 @@ class Object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the Missing Controller web page.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function missingController()
|
|
||||||
{
|
|
||||||
//$this->autoLayout = true;
|
|
||||||
$this->pageTitle = 'Missing Controller';
|
|
||||||
$this->render('../errors/missingController');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the Missing Action web page.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function missingAction()
|
|
||||||
{
|
|
||||||
//$this->autoLayout = true;
|
|
||||||
$this->pageTitle = 'Missing Method in Controller';
|
|
||||||
$this->render('../errors/missingAction');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the Private Action web page.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function privateAction()
|
|
||||||
{
|
|
||||||
//$this->autoLayout = true;
|
|
||||||
$this->pageTitle = 'Trying to access private method in class';
|
|
||||||
$this->render('../errors/privateAction');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the Missing View web page.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function missingView()
|
|
||||||
{
|
|
||||||
//We are simulating action call below, this is not a filename!
|
|
||||||
//$this->autoLayout = true;
|
|
||||||
$this->missingView = $this->name;
|
|
||||||
$this->pageTitle = 'Missing View';
|
|
||||||
$this->render('../errors/missingView');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the Missing Database web page.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function missingDatabase()
|
|
||||||
{
|
|
||||||
//$this->autoLayout = true;
|
|
||||||
$this->pageTitle = 'Scaffold Missing Database Connection';
|
|
||||||
$this->render('../errors/missingScaffolddb');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the Missing Table web page.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function missingTable($tableName)
|
|
||||||
{
|
|
||||||
$error =& new Controller();
|
|
||||||
$error->constructClasses();
|
|
||||||
$error->missingTable = $this->table;
|
|
||||||
$error->missingTableName = $tableName;
|
|
||||||
$error->pageTitle = 'Missing Database Table';
|
|
||||||
$error->render('../errors/missingTable');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the Missing Table web page.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function missingConnection()
|
|
||||||
{
|
|
||||||
$error =& new Controller();
|
|
||||||
$error->constructClasses();
|
|
||||||
$error->missingConnection = $this->name;
|
|
||||||
//$error->autoLayout = true;
|
|
||||||
$error->pageTitle = 'Missing Database Connection';
|
|
||||||
$error->render('../errors/missingDatabase');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the Missing Helper file web page.
|
* Renders the Missing Helper file web page.
|
||||||
*
|
*
|
||||||
|
@ -257,6 +165,15 @@ class Object
|
||||||
$this->render('../errors/missingHelperClass');
|
$this->render('../errors/missingHelperClass');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cakeError($method, $messages)
|
||||||
|
{
|
||||||
|
if(!class_exists('ErrorHandler'))
|
||||||
|
{
|
||||||
|
uses('error');
|
||||||
|
}
|
||||||
|
return new ErrorHandler($method, $messages);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -51,12 +51,6 @@ class CakeSession extends Object
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $error = false;
|
var $error = false;
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @var unknown_type
|
|
||||||
*/
|
|
||||||
var $ip = false;
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
|
@ -87,6 +81,18 @@ class CakeSession extends Object
|
||||||
* @var unknown_type
|
* @var unknown_type
|
||||||
*/
|
*/
|
||||||
var $security = null;
|
var $security = null;
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $time = false;
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @var unknown_type
|
||||||
|
*/
|
||||||
|
var $sessionTime = false;
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
|
@ -94,7 +100,7 @@ class CakeSession extends Object
|
||||||
*/
|
*/
|
||||||
function __construct($base = null)
|
function __construct($base = null)
|
||||||
{
|
{
|
||||||
$this->host = $_SERVER['HTTP_HOST'];
|
$this->host = env('HTTP_HOST');
|
||||||
|
|
||||||
if (empty($base))
|
if (empty($base))
|
||||||
{
|
{
|
||||||
|
@ -110,24 +116,17 @@ class CakeSession extends Object
|
||||||
$this->host = substr($this->host,0, strpos($this->host, ':'));
|
$this->host = substr($this->host,0, strpos($this->host, ':'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
|
if(env('HTTP_USER_AGENT') != null)
|
||||||
{
|
{
|
||||||
$this->ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
$this->userAgent = md5(env('HTTP_USER_AGENT').CAKE_SESSION_STRING);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->ip = $_SERVER['REMOTE_ADDR'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($_SERVER['HTTP_USER_AGENT']))
|
|
||||||
{
|
|
||||||
$this->userAgent = md5($_SERVER['HTTP_USER_AGENT']);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->userAgent = "";
|
$this->userAgent = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->time = time();
|
||||||
|
$this->sessionTime = $this->time + (Security::inactiveMins() * 60);
|
||||||
$this->security = CAKE_SECURITY;
|
$this->security = CAKE_SECURITY;
|
||||||
$this->_initSession();
|
$this->_initSession();
|
||||||
$this->_begin();
|
$this->_begin();
|
||||||
|
@ -298,6 +297,26 @@ class CakeSession extends Object
|
||||||
echo "</pre>";
|
echo "</pre>";
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _destroyInvalid()
|
||||||
|
{
|
||||||
|
$sessionpath = session_save_path();
|
||||||
|
if (empty($sessionpath))
|
||||||
|
{
|
||||||
|
$sessionpath = "/tmp";
|
||||||
|
}
|
||||||
|
if (isset($_COOKIE[session_name()]))
|
||||||
|
{
|
||||||
|
setcookie(CAKE_SESSION_COOKIE, '', time()-42000, $this->path);
|
||||||
|
}
|
||||||
|
$file = $sessionpath.DS."sess_".session_id();
|
||||||
|
@unlink($file);
|
||||||
|
$this->__construct($this->path);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
|
@ -406,39 +425,29 @@ class CakeSession extends Object
|
||||||
*/
|
*/
|
||||||
function _new()
|
function _new()
|
||||||
{
|
{
|
||||||
if(!ereg("\.aol\.com$", gethost($this->ip)))
|
if($this->readSessionVar("Config"))
|
||||||
{
|
{
|
||||||
if($this->readSessionVar("Config"))
|
if($this->userAgent == $this->readSessionVar("Config.userAgent") &&
|
||||||
|
$this->time <= $this->readSessionVar("Config.time"))
|
||||||
{
|
{
|
||||||
if($this->ip == $this->readSessionVar("Config.ip") && $this->userAgent == $this->readSessionVar("Config.userAgent"))
|
$this->writeSessionVar("Config.time", $this->sessionTime);
|
||||||
{
|
$this->valid = true;
|
||||||
$this->valid = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->valid = false;
|
|
||||||
$this->_setError(1, "Session Highjacking Attempted !!!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
srand((double)microtime() * 1000000);
|
$this->valid = false;
|
||||||
$this->writeSessionVar('Config.rand', rand());
|
$this->_setError(1, "Session Highjacking Attempted !!!");
|
||||||
$this->writeSessionVar("Config.ip", $this->ip);
|
$this->_destroyInvalid();
|
||||||
$this->writeSessionVar("Config.userAgent", $this->userAgent);
|
|
||||||
$this->valid = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!$this->readSessionVar("Config"))
|
srand((double)microtime() * 1000000);
|
||||||
{
|
$this->writeSessionVar('Config.rand', rand());
|
||||||
srand((double)microtime() * 1000000);
|
$this->writeSessionVar("Config.time", $this->sessionTime);
|
||||||
$this->writeSessionVar('Config.rand', rand());
|
$this->writeSessionVar("Config.userAgent", $this->userAgent);
|
||||||
$this->writeSessionVar("Config.ip", $this->ip);
|
|
||||||
$this->writeSessionVar("Config.userAgent", $this->userAgent);
|
|
||||||
}
|
|
||||||
$this->valid = true;
|
$this->valid = true;
|
||||||
|
$this->_setError(1, "Session is valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->security == 'high')
|
if($this->security == 'high')
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
|
@ -44,50 +44,50 @@
|
||||||
class AjaxHelper extends Helper
|
class AjaxHelper extends Helper
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Included helpers.
|
* Included helpers.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $helpers = array('Html', 'Javascript');
|
var $helpers = array('Html', 'Javascript');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $callbacks = array('uninitialized', 'loading', 'loaded', 'interactive', 'complete');
|
var $callbacks = array('uninitialized', 'loading', 'loaded', 'interactive', 'complete');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $ajaxOptions = array('method','position','form','parameters','evalScripts', 'asynchronous', 'onComplete', 'onUninitialized', 'onLoading', 'onLoaded', 'onInteractive');
|
var $ajaxOptions = array('method','position','form','parameters','evalScripts', 'asynchronous', 'onComplete', 'onUninitialized', 'onLoading', 'onLoaded', 'onInteractive');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $dragOptions = array('handle', 'revert', 'constraint', 'change');
|
var $dragOptions = array('handle', 'revert', 'constraint', 'change');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $dropOptions = array('accept', 'containment', 'overlap', 'greedy', 'hoverclass', 'onHover', 'onDrop');
|
var $dropOptions = array('accept', 'containment', 'overlap', 'greedy', 'hoverclass', 'onHover', 'onDrop');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $sortOptions = array('tag', 'only', 'overlap', 'constraint', 'containment', 'handle', 'hoverClass', 'ghosting', 'dropOnEmpty', 'onUpdate', 'onChange');
|
var $sortOptions = array('tag', 'only', 'overlap', 'constraint', 'containment', 'handle', 'hoverClass', 'ghosting', 'dropOnEmpty', 'onUpdate', 'onChange');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns link to remote action
|
* Returns link to remote action
|
||||||
*
|
*
|
||||||
* Returns a link to a remote action defined by <i>options[url]</i>
|
* Returns a link to a remote action defined by <i>options[url]</i>
|
||||||
|
@ -148,7 +148,7 @@ class AjaxHelper extends Helper
|
||||||
* @param array $options Options for JavaScript function
|
* @param array $options Options for JavaScript function
|
||||||
* @return string HTML code for link to remote action
|
* @return string HTML code for link to remote action
|
||||||
*/
|
*/
|
||||||
function linkToRemote ($title, $options = null, $html_options = null)
|
function linkToRemote ($title, $options = null, $html_options = null)
|
||||||
{
|
{
|
||||||
$href = (!empty($options['fallback'])) ? $options['fallback'] : '#';
|
$href = (!empty($options['fallback'])) ? $options['fallback'] : '#';
|
||||||
if(isset($html_options['id']))
|
if(isset($html_options['id']))
|
||||||
|
@ -162,18 +162,18 @@ class AjaxHelper extends Helper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates JavaScript function for remote AJAX call
|
* Creates JavaScript function for remote AJAX call
|
||||||
*
|
*
|
||||||
* This function creates the javascript needed to make a remote call
|
* This function creates the javascript needed to make a remote call
|
||||||
* it is primarily used as a helper for linkToRemote.
|
* it is primarily used as a helper for linkToRemote.
|
||||||
*
|
*
|
||||||
* @see linkToRemote() for docs on options parameter.
|
* @see linkToRemote() for docs on options parameter.
|
||||||
*
|
*
|
||||||
* @param array $options options for javascript
|
* @param array $options options for javascript
|
||||||
* @return string html code for link to remote action
|
* @return string html code for link to remote action
|
||||||
*/
|
*/
|
||||||
function remoteFunction ($options = null)
|
function remoteFunction ($options = null)
|
||||||
{
|
{
|
||||||
$javascript_options = $this->_optionsForAjax($options);
|
$javascript_options = $this->_optionsForAjax($options);
|
||||||
$func = isset($options['update']) ? "new Ajax.Updater('{$options['update']}'," : "new Ajax.Request(";
|
$func = isset($options['update']) ? "new Ajax.Updater('{$options['update']}'," : "new Ajax.Request(";
|
||||||
|
@ -181,35 +181,35 @@ class AjaxHelper extends Helper
|
||||||
$func .= "'" . $this->Html->url(isset($options['url']) ? $options['url'] : "") . "'";
|
$func .= "'" . $this->Html->url(isset($options['url']) ? $options['url'] : "") . "'";
|
||||||
$func .= "$javascript_options)";
|
$func .= "$javascript_options)";
|
||||||
|
|
||||||
if (isset($options['before']))
|
if (isset($options['before']))
|
||||||
{
|
{
|
||||||
$func = "{$options['before']}; $func";
|
$func = "{$options['before']}; $func";
|
||||||
}
|
}
|
||||||
if (isset($options['after']))
|
if (isset($options['after']))
|
||||||
{
|
{
|
||||||
$func = "$func; {$options['after']};";
|
$func = "$func; {$options['after']};";
|
||||||
}
|
}
|
||||||
if (isset($options['condition']))
|
if (isset($options['condition']))
|
||||||
{
|
{
|
||||||
$func = "if ({$options['condition']}) { $func; }";
|
$func = "if ({$options['condition']}) { $func; }";
|
||||||
}
|
}
|
||||||
if (isset($options['confirm']))
|
if (isset($options['confirm']))
|
||||||
{
|
{
|
||||||
$func = "if (confirm('" . $this->Javascript->escapeScript($options['confirm']) . "')) { $func; } else { return false; }";
|
$func = "if (confirm('" . $this->Javascript->escapeScript($options['confirm']) . "')) { $func; } else { return false; }";
|
||||||
}
|
}
|
||||||
return $func;
|
return $func;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Periodically call remote url via AJAX.
|
* Periodically call remote url via AJAX.
|
||||||
*
|
*
|
||||||
* Periodically calls the specified url (<i>options[url]</i>) every <i>options[frequency]</i> seconds (default is 10).
|
* Periodically calls the specified url (<i>options[url]</i>) every <i>options[frequency]</i> seconds (default is 10).
|
||||||
* Usually used to update a specified div (<i>options[update]</i>) with the results of the remote call.
|
* Usually used to update a specified div (<i>options[update]</i>) with the results of the remote call.
|
||||||
* The options for specifying the target with url and defining callbacks is the same as linkToRemote.
|
* The options for specifying the target with url and defining callbacks is the same as linkToRemote.
|
||||||
*
|
*
|
||||||
* @param array $options Callback options
|
* @param array $options Callback options
|
||||||
* @return string Javascript code
|
* @return string Javascript code
|
||||||
*/
|
*/
|
||||||
function remoteTimer ($options = null)
|
function remoteTimer ($options = null)
|
||||||
{
|
{
|
||||||
$frequency = (isset($options['frequency']))? $options['frequency'] : 10;
|
$frequency = (isset($options['frequency']))? $options['frequency'] : 10;
|
||||||
|
@ -217,37 +217,37 @@ class AjaxHelper extends Helper
|
||||||
return $this->Javascript->codeBlock($code);
|
return $this->Javascript->codeBlock($code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns form tag that will submit using Ajax.
|
* Returns form tag that will submit using Ajax.
|
||||||
*
|
*
|
||||||
* Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular
|
* Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular
|
||||||
* reloading POST arrangement. Even though it's using Javascript to serialize the form elements, the form submission
|
* reloading POST arrangement. Even though it's using Javascript to serialize the form elements, the form submission
|
||||||
* will work just like a regular submission as viewed by the receiving side (all elements available in params).
|
* will work just like a regular submission as viewed by the receiving side (all elements available in params).
|
||||||
* The options for specifying the target with :url and defining callbacks is the same as link_to_remote.
|
* The options for specifying the target with :url and defining callbacks is the same as link_to_remote.
|
||||||
*
|
*
|
||||||
* @param string $id Form id
|
* @param string $id Form id
|
||||||
* @param array $options Callback options
|
* @param array $options Callback options
|
||||||
* @return string JavaScript code
|
* @return string JavaScript code
|
||||||
*/
|
*/
|
||||||
function form($id, $options = null, $html_options = array())
|
function form($id, $options = null, $html_options = array())
|
||||||
{
|
{
|
||||||
$html_options['id'] = $id;
|
$html_options['id'] = $id;
|
||||||
return $this->Html->formTag(null, "post", $html_options) .
|
return $this->Html->formTag(null, "post", $html_options) .
|
||||||
$this->Javascript->event("$('$id')", "submit", "function(){" .
|
$this->Javascript->event("$('$id')", "submit", "function(){" .
|
||||||
$this->remoteFunction($options) . "; return false;}");
|
$this->remoteFunction($options) . "; return false;}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a button input tag that will submit using Ajax
|
* Returns a button input tag that will submit using Ajax
|
||||||
*
|
*
|
||||||
* Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular
|
* Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular
|
||||||
* reloading POST arrangement. <i>options</i> argument is the same as in <i>form_remote_tag</i>
|
* reloading POST arrangement. <i>options</i> argument is the same as in <i>form_remote_tag</i>
|
||||||
*
|
*
|
||||||
* @param string $name Input button name
|
* @param string $name Input button name
|
||||||
* @param string $value Input button value
|
* @param string $value Input button value
|
||||||
* @param array $options Callback options
|
* @param array $options Callback options
|
||||||
* @return string Ajaxed input button
|
* @return string Ajaxed input button
|
||||||
*/
|
*/
|
||||||
function submit ($name, $value, $options = null)
|
function submit ($name, $value, $options = null)
|
||||||
{
|
{
|
||||||
$options['with'] = 'Form.serialize(this.form)';
|
$options['with'] = 'Form.serialize(this.form)';
|
||||||
|
@ -258,55 +258,55 @@ class AjaxHelper extends Helper
|
||||||
return $this->Html->tag("input", $options['html'], false);
|
return $this->Html->tag("input", $options['html'], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Observe field and call ajax on change.
|
* Observe field and call ajax on change.
|
||||||
*
|
*
|
||||||
* Observes the field with the DOM ID specified by <i>field_id</i> and makes
|
* Observes the field with the DOM ID specified by <i>field_id</i> and makes
|
||||||
* an Ajax when its contents have changed.
|
* an Ajax when its contents have changed.
|
||||||
*
|
*
|
||||||
* Required +options+ are:
|
* Required +options+ are:
|
||||||
* - <i>frequency</i>:: The frequency (in seconds) at which changes to
|
* - <i>frequency</i>:: The frequency (in seconds) at which changes to
|
||||||
* this field will be detected.
|
* this field will be detected.
|
||||||
* - <i>url</i>:: @see urlFor() -style options for the action to call
|
* - <i>url</i>:: @see urlFor() -style options for the action to call
|
||||||
* when the field has changed.
|
* when the field has changed.
|
||||||
*
|
*
|
||||||
* Additional options are:
|
* Additional options are:
|
||||||
* - <i>update</i>:: Specifies the DOM ID of the element whose
|
* - <i>update</i>:: Specifies the DOM ID of the element whose
|
||||||
* innerHTML should be updated with the
|
* innerHTML should be updated with the
|
||||||
* XMLHttpRequest response text.
|
* XMLHttpRequest response text.
|
||||||
* - <i>with</i>:: A Javascript expression specifying the
|
* - <i>with</i>:: A Javascript expression specifying the
|
||||||
* parameters for the XMLHttpRequest. This defaults
|
* parameters for the XMLHttpRequest. This defaults
|
||||||
* to Form.Element.serialize('$field_id'), which can be
|
* to Form.Element.serialize('$field_id'), which can be
|
||||||
* accessed from params['form']['field_id'].
|
* accessed from params['form']['field_id'].
|
||||||
*
|
*
|
||||||
* Additionally, you may specify any of the options documented in
|
* Additionally, you may specify any of the options documented in
|
||||||
* @see linkToRemote().
|
* @see linkToRemote().
|
||||||
*
|
*
|
||||||
* @param string $field_id DOM ID of field to observe
|
* @param string $field_id DOM ID of field to observe
|
||||||
* @param array $options ajax options
|
* @param array $options ajax options
|
||||||
* @return string ajax script
|
* @return string ajax script
|
||||||
*/
|
*/
|
||||||
function observeField ($field_id, $options = null)
|
function observeField ($field_id, $options = null)
|
||||||
{
|
{
|
||||||
if (!isset($options['with']))
|
if (!isset($options['with']))
|
||||||
{
|
{
|
||||||
$options['with'] = "Form.Element.serialize('$field_id')";
|
$options['with'] = "Form.Element.serialize('$field_id')";
|
||||||
}
|
}
|
||||||
return $this->Javascript->codeBlock($this->_buildObserver('Form.Element.Observer', $field_id, $options));
|
return $this->Javascript->codeBlock($this->_buildObserver('Form.Element.Observer', $field_id, $options));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Observe entire form and call ajax on change.
|
* Observe entire form and call ajax on change.
|
||||||
*
|
*
|
||||||
* Like @see observeField(), but operates on an entire form identified by the
|
* Like @see observeField(), but operates on an entire form identified by the
|
||||||
* DOM ID <b>form_id</b>. <b>options</b> are the same as <b>observe_field</b>, except
|
* DOM ID <b>form_id</b>. <b>options</b> are the same as <b>observe_field</b>, except
|
||||||
* the default value of the <i>with</i> option evaluates to the
|
* the default value of the <i>with</i> option evaluates to the
|
||||||
* serialized (request string) value of the form.
|
* serialized (request string) value of the form.
|
||||||
*
|
*
|
||||||
* @param string $field_id DOM ID of field to observe
|
* @param string $field_id DOM ID of field to observe
|
||||||
* @param array $options ajax options
|
* @param array $options ajax options
|
||||||
* @return string ajax script
|
* @return string ajax script
|
||||||
*/
|
*/
|
||||||
function observeForm ($field_id, $options = array())
|
function observeForm ($field_id, $options = array())
|
||||||
{
|
{
|
||||||
if (!isset($options['with']))
|
if (!isset($options['with']))
|
||||||
|
@ -316,21 +316,21 @@ class AjaxHelper extends Helper
|
||||||
return $this->Javascript->codeBlock($this->_buildObserver('Form.Observer', $field_id, $options));
|
return $this->Javascript->codeBlock($this->_buildObserver('Form.Observer', $field_id, $options));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a text field with Autocomplete.
|
* Create a text field with Autocomplete.
|
||||||
*
|
*
|
||||||
* Creates an autocomplete field with the given ID and options.
|
* Creates an autocomplete field with the given ID and options.
|
||||||
*
|
*
|
||||||
* options['with'] defaults to "Form.Element.serialize('$field_id')",
|
* options['with'] defaults to "Form.Element.serialize('$field_id')",
|
||||||
* but can be any valid javascript expression defining the
|
* but can be any valid javascript expression defining the
|
||||||
*
|
*
|
||||||
* @param string $field_id DOM ID of field to observe
|
* @param string $field_id DOM ID of field to observe
|
||||||
* @param array $options ajax options
|
* @param array $options ajax options
|
||||||
* @return string ajax script
|
* @return string ajax script
|
||||||
*/
|
*/
|
||||||
function autoComplete ($field, $url = "", $options = array())
|
function autoComplete ($field, $url = "", $options = array())
|
||||||
{
|
{
|
||||||
if (!isset($options['id']))
|
if (!isset($options['id']))
|
||||||
{
|
{
|
||||||
$options['id'] = str_replace("/", "_", $field);
|
$options['id'] = str_replace("/", "_", $field);
|
||||||
}
|
}
|
||||||
|
@ -342,11 +342,11 @@ class AjaxHelper extends Helper
|
||||||
|
|
||||||
foreach($ajaxOptions as $key)
|
foreach($ajaxOptions as $key)
|
||||||
{
|
{
|
||||||
if(isset($options[$key]))
|
if(isset($options[$key]))
|
||||||
{
|
{
|
||||||
$ajaxOptions[$key] = $options[$key];
|
$ajaxOptions[$key] = $options[$key];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unset($ajaxOptions[$key]);
|
unset($ajaxOptions[$key]);
|
||||||
}
|
}
|
||||||
|
@ -359,14 +359,20 @@ class AjaxHelper extends Helper
|
||||||
$this->Javascript->codeBlock("new Ajax.Autocompleter('" . $options['id'] . "', '" .
|
$this->Javascript->codeBlock("new Ajax.Autocompleter('" . $options['id'] . "', '" .
|
||||||
$divOptions['id'] . "', '" . $this->Html->url($url) . "', " . $this->_optionsForAjax($ajaxOptions) . ");");
|
$divOptions['id'] . "', '" . $this->Html->url($url) . "', " . $this->_optionsForAjax($ajaxOptions) . ");");
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $id
|
||||||
|
* @param unknown_type $options
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
function drag($id, $options = array())
|
function drag($id, $options = array())
|
||||||
{
|
{
|
||||||
$options = $this->_optionsForDraggable($options);
|
$options = $this->_optionsForDraggable($options);
|
||||||
return $this->Javascript->codeBlock("new Draggable('$id'$options);");
|
return $this->Javascript->codeBlock("new Draggable('$id'$options);");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Enter description here...
|
||||||
*
|
*
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
@ -379,37 +385,55 @@ class AjaxHelper extends Helper
|
||||||
return $this->_buildOptions($options, $this->dragOptions);
|
return $this->_buildOptions($options, $this->dragOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For a reference on the options for this function, check out
|
* For a reference on the options for this function, check out
|
||||||
* http://wiki.script.aculo.us/scriptaculous/show/Droppables.add
|
* http://wiki.script.aculo.us/scriptaculous/show/Droppables.add
|
||||||
*
|
*
|
||||||
*/
|
* @param unknown_type $id
|
||||||
|
* @param unknown_type $options
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
function drop($id, $options = array())
|
function drop($id, $options = array())
|
||||||
{
|
{
|
||||||
$options = $this->_optionsForDroppable($options);
|
$options = $this->_optionsForDroppable($options);
|
||||||
return $this->Javascript->codeBlock("Droppables.add('$id'$options);");
|
return $this->Javascript->codeBlock("Droppables.add('$id'$options);");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $options
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
function _optionsForDroppable ($options)
|
function _optionsForDroppable ($options)
|
||||||
{
|
{
|
||||||
$options = $this->_optionsToString($options, array('accept','overlap','hoverclass'));
|
$options = $this->_optionsToString($options, array('accept','overlap','hoverclass'));
|
||||||
|
|
||||||
return $this->_buildOptions($options, $this->dropOptions);
|
return $this->_buildOptions($options, $this->dropOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $id
|
||||||
|
* @param unknown_type $options
|
||||||
|
* @param unknown_type $ajaxOptions
|
||||||
|
* @return unknown
|
||||||
|
*/
|
||||||
function dropRemote($id, $options = array(), $ajaxOptions = array())
|
function dropRemote($id, $options = array(), $ajaxOptions = array())
|
||||||
{
|
{
|
||||||
$options['onDrop'] = "function(element){" . $this->remoteFunction($ajaxOptions) . "}";
|
$options['onDrop'] = "function(element){" . $this->remoteFunction($ajaxOptions) . "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes a list or group of floated objects sortable.
|
* Makes a list or group of floated objects sortable.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param string $id DOM ID of parent
|
* @param string $id DOM ID of parent
|
||||||
* @param array $options Array of options to control sort.http://wiki.script.aculo.us/scriptaculous/show/Sortable.create
|
* @param array $options Array of options to control sort.http://wiki.script.aculo.us/scriptaculous/show/Sortable.create
|
||||||
* @link http://wiki.script.aculo.us/scriptaculous/show/Sortable.create
|
* @link http://wiki.script.aculo.us/scriptaculous/show/Sortable.create
|
||||||
*/
|
* @return unknown
|
||||||
|
*/
|
||||||
|
|
||||||
function sortable($id, $options = array())
|
function sortable($id, $options = array())
|
||||||
{
|
{
|
||||||
|
@ -421,25 +445,36 @@ class AjaxHelper extends Helper
|
||||||
$options = $this->_optionsForSortable($options);
|
$options = $this->_optionsForSortable($options);
|
||||||
return $this->Javascript->codeBlock("Sortable.create('$id'$options);");
|
return $this->Javascript->codeBlock("Sortable.create('$id'$options);");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $options
|
||||||
|
* @return unknown
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function _optionsForSortable ($options)
|
function _optionsForSortable ($options)
|
||||||
{
|
{
|
||||||
$options = $this->_optionsToString($options, array('handle','tag','constraint','ghosting'));
|
$options = $this->_optionsToString($options, array('handle','tag','constraint','ghosting'));
|
||||||
return $this->_buildOptions($options, $this->sortOptions);
|
return $this->_buildOptions($options, $this->sortOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Javascript helper function (private).
|
/**
|
||||||
*
|
* Javascript helper function.
|
||||||
*/
|
*
|
||||||
|
* @param unknown_type $options
|
||||||
|
* @return unknown
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function _optionsForAjax ($options = array())
|
function _optionsForAjax ($options = array())
|
||||||
{
|
{
|
||||||
$js_options = $this->_buildCallbacks($options);
|
$js_options = $this->_buildCallbacks($options);
|
||||||
|
|
||||||
$js_options['asynchronous'] = 'true';
|
$js_options['asynchronous'] = 'true';
|
||||||
|
|
||||||
$options = $this->_optionsToString($options, array('method'));
|
$options = $this->_optionsToString($options, array('method'));
|
||||||
|
|
||||||
foreach($options as $key => $value)
|
foreach($options as $key => $value)
|
||||||
{
|
{
|
||||||
switch($key)
|
switch($key)
|
||||||
|
@ -447,15 +482,15 @@ class AjaxHelper extends Helper
|
||||||
case 'type':
|
case 'type':
|
||||||
$js_options['asynchronous'] = ($value == 'synchronous') ? 'false' : 'true';
|
$js_options['asynchronous'] = ($value == 'synchronous') ? 'false' : 'true';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'position':
|
case 'position':
|
||||||
$js_options['insertion'] = "Insertion." . Inflector::camelize($options['position']);
|
$js_options['insertion'] = "Insertion." . Inflector::camelize($options['position']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'with':
|
case 'with':
|
||||||
$js_options['parameters'] = $options['with'];
|
$js_options['parameters'] = $options['with'];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'form':
|
case 'form':
|
||||||
$js_options['parameters'] = 'Form.serialize(this)';
|
$js_options['parameters'] = 'Form.serialize(this)';
|
||||||
break;
|
break;
|
||||||
|
@ -466,7 +501,15 @@ class AjaxHelper extends Helper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function _buildOptions ($options, $acceptable) {
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $options
|
||||||
|
* @param unknown_type $acceptable
|
||||||
|
* @return unknown
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
|
function _buildOptions ($options, $acceptable) {
|
||||||
if(is_array($options))
|
if(is_array($options))
|
||||||
{
|
{
|
||||||
$out = array();
|
$out = array();
|
||||||
|
@ -487,13 +530,14 @@ class AjaxHelper extends Helper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here... Return JavaScript text for ...
|
* Enter description here... Return JavaScript text for ...
|
||||||
*
|
*
|
||||||
* @param string $klass Name of JavaScript class
|
* @param string $klass Name of JavaScript class
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return string Formatted JavaScript
|
* @return string Formatted JavaScript
|
||||||
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _buildObserver ($klass, $name, $options=null)
|
function _buildObserver ($klass, $name, $options=null)
|
||||||
{
|
{
|
||||||
|
@ -509,11 +553,12 @@ class AjaxHelper extends Helper
|
||||||
return $javascript;
|
return $javascript;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here... Return JavaScript text for ...
|
* Enter description here... Return JavaScript text for ...
|
||||||
*
|
*
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return array
|
* @return array
|
||||||
|
* @access private
|
||||||
*/
|
*/
|
||||||
function _buildCallbacks($options)
|
function _buildCallbacks($options)
|
||||||
{
|
{
|
||||||
|
@ -530,6 +575,14 @@ class AjaxHelper extends Helper
|
||||||
return $callbacks;
|
return $callbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter description here...
|
||||||
|
*
|
||||||
|
* @param unknown_type $options
|
||||||
|
* @param unknown_type $stringOpts
|
||||||
|
* @return unknown
|
||||||
|
* @access private
|
||||||
|
*/
|
||||||
function _optionsToString ($options, $stringOpts = array())
|
function _optionsToString ($options, $stringOpts = array())
|
||||||
{
|
{
|
||||||
foreach ($stringOpts as $option)
|
foreach ($stringOpts as $option)
|
||||||
|
|
|
@ -360,7 +360,6 @@ class FormHelper extends Helper
|
||||||
function generateSubmitDiv($displayText, $htmlOptions = null)
|
function generateSubmitDiv($displayText, $htmlOptions = null)
|
||||||
{
|
{
|
||||||
return $this->divTag( 'submit', $this->Html->submitTag( $displayText, $htmlOptions) );
|
return $this->divTag( 'submit', $this->Html->submitTag( $displayText, $htmlOptions) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -373,98 +372,106 @@ class FormHelper extends Helper
|
||||||
function generateFields( $fields, $readOnly = false )
|
function generateFields( $fields, $readOnly = false )
|
||||||
{
|
{
|
||||||
$strFormFields = '';
|
$strFormFields = '';
|
||||||
|
|
||||||
foreach( $fields as $field )
|
foreach( $fields as $field )
|
||||||
{
|
{
|
||||||
if( isset( $field['type'] ) )
|
if(isset( $field['type']))
|
||||||
{
|
|
||||||
// initialize some optional parameters to avoid the notices
|
|
||||||
if( !isset($field['required'] ) )
|
|
||||||
$field['required'] = false;
|
|
||||||
if( !isset( $field['errorMsg'] ) )
|
|
||||||
$field['errorMsg'] = null;
|
|
||||||
if( !isset( $field['htmlOptions'] ) )
|
|
||||||
$field['htmlOptions'] = array();
|
|
||||||
|
|
||||||
if( $readOnly )
|
|
||||||
{
|
{
|
||||||
$field['htmlOptions']['READONLY'] = "readonly";
|
if(!isset($field['required']))
|
||||||
|
{
|
||||||
|
$field['required'] = false;
|
||||||
|
}
|
||||||
|
if(!isset( $field['errorMsg']))
|
||||||
|
{
|
||||||
|
$field['errorMsg'] = null;
|
||||||
|
}
|
||||||
|
if(!isset( $field['htmlOptions']))
|
||||||
|
{
|
||||||
|
$field['htmlOptions'] = array();
|
||||||
|
}
|
||||||
|
if( $readOnly )
|
||||||
|
{
|
||||||
|
$field['htmlOptions']['READONLY'] = "readonly";
|
||||||
|
}
|
||||||
|
|
||||||
|
switch( $field['type'] )
|
||||||
|
{
|
||||||
|
case "input" :
|
||||||
|
if( !isset( $field['size'] ) )
|
||||||
|
{
|
||||||
|
$field['size'] = 40;
|
||||||
|
}
|
||||||
|
$strFormFields = $strFormFields.$this->generateInputDiv( $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['size'], $field['htmlOptions'] );
|
||||||
|
break;
|
||||||
|
case "checkbox" :
|
||||||
|
$strFormFields = $strFormFields.$this->generateCheckboxDiv( $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['htmlOptions'] );
|
||||||
|
break;
|
||||||
|
case "select";
|
||||||
|
case "selectMultiple";
|
||||||
|
if( "selectMultiple" == $field['type'] )
|
||||||
|
{
|
||||||
|
$field['selectAttr']['multiple'] = 'multiple';
|
||||||
|
$field['selectAttr']['class'] = 'selectMultiple';
|
||||||
|
}
|
||||||
|
if(!isset( $field['selected']))
|
||||||
|
{
|
||||||
|
$field['selected'] = null;
|
||||||
|
}
|
||||||
|
if(!isset( $field['selectAttr']))
|
||||||
|
{
|
||||||
|
$field['selectAttr'] = null;
|
||||||
|
}
|
||||||
|
if(!isset( $field['optionsAttr']))
|
||||||
|
{
|
||||||
|
$field['optionsAttr'] = null;
|
||||||
|
}
|
||||||
|
if($readOnly)
|
||||||
|
{
|
||||||
|
$field['selectAttr']['DISABLED'] = true;
|
||||||
|
}
|
||||||
|
$strFormFields = $strFormFields.$this->generateSelectDiv( $field['tagName'], $field['prompt'], $field['options'], $field['selected'], $field['selectAttr'], $field['optionsAttr'], $field['required'], $field['errorMsg'] );
|
||||||
|
break;
|
||||||
|
case "area";
|
||||||
|
if(!isset( $field['rows']))
|
||||||
|
{
|
||||||
|
$field['rows'] = 10;
|
||||||
|
}
|
||||||
|
if(!isset( $field['cols']))
|
||||||
|
{
|
||||||
|
$field['cols'] = 60;
|
||||||
|
}
|
||||||
|
$strFormFields = $strFormFields.$this->generateAreaDiv( $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['cols'], $field['rows'], $field['htmlOptions'] );
|
||||||
|
break;
|
||||||
|
case "fieldset";
|
||||||
|
|
||||||
|
$strFieldsetFields = $this->generateFields( $field['fields'] );
|
||||||
|
$strFieldSet = sprintf( '
|
||||||
|
<fieldset><legend>%s</legend><div class="notes"><h4>%s</h4><p class="last">%s</p></div>%s</fieldset>',
|
||||||
|
$field['legend'], $field['noteHeading'], $field['note'], $strFieldsetFields );
|
||||||
|
$strFormFields = $strFormFields.$strFieldSet;
|
||||||
|
break;
|
||||||
|
case "hidden";
|
||||||
|
$strFormFields = $strFormFields . $this->Html->hiddenTag( $field['tagName']);
|
||||||
|
break;
|
||||||
|
case "date":
|
||||||
|
if( !isset( $field['selected']))
|
||||||
|
{
|
||||||
|
$field['selected'] = null;
|
||||||
|
}
|
||||||
|
$strFormFields = $strFormFields.$this->generateDate( $field['tagName'], $field['prompt'], null, null, null, null, $field['selected']);
|
||||||
|
break;
|
||||||
|
case "datetime":
|
||||||
|
if( !isset( $field['selected']))
|
||||||
|
{
|
||||||
|
$field['selected'] = null;
|
||||||
|
}
|
||||||
|
$strFormFields = $strFormFields.$this->generateDateTime( $field['tagName'], $field['prompt'], '','','', '', $field['selected']);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch( $field['type'] )
|
|
||||||
{
|
|
||||||
case "input" :
|
|
||||||
// If the size has not been set, initialize it to 40.
|
|
||||||
if( !isset( $field['size'] ) )
|
|
||||||
{
|
|
||||||
$field['size'] = 40;
|
|
||||||
}
|
|
||||||
$strFormFields = $strFormFields.$this->generateInputDiv( $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['size'], $field['htmlOptions'] );
|
|
||||||
break;
|
|
||||||
case "checkbox" :
|
|
||||||
$strFormFields = $strFormFields.$this->generateCheckboxDiv( $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['htmlOptions'] );
|
|
||||||
break;
|
|
||||||
case "select";
|
|
||||||
case "selectMultiple";
|
|
||||||
{
|
|
||||||
if( "selectMultiple" == $field['type'] )
|
|
||||||
{
|
|
||||||
$field['selectAttr']['multiple'] = 'multiple';
|
|
||||||
$field['selectAttr']['class'] = 'selectMultiple';
|
|
||||||
}
|
|
||||||
// If the selected attribute has not been set, initialize it to null.
|
|
||||||
if( !isset( $field['selected'] ) )
|
|
||||||
$field['selected'] = null;
|
|
||||||
if( !isset( $field['selectAttr'] ) )
|
|
||||||
$field['selectAttr'] = null;
|
|
||||||
if( !isset( $field['optionsAttr'] ) )
|
|
||||||
$field['optionsAttr'] = null;
|
|
||||||
|
|
||||||
if( $readOnly )
|
|
||||||
$field['selectAttr']['DISABLED'] = true;
|
|
||||||
|
|
||||||
$strFormFields = $strFormFields.$this->generateSelectDiv( $field['tagName'], $field['prompt'], $field['options'], $field['selected'], $field['selectAttr'], $field['optionsAttr'], $field['required'], $field['errorMsg'] );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "area";
|
|
||||||
{
|
|
||||||
if( !isset( $field['rows'] ) )
|
|
||||||
$field['rows'] = 10;
|
|
||||||
if( !isset( $field['cols'] ) )
|
|
||||||
$field['cols'] = 60;
|
|
||||||
$strFormFields = $strFormFields.$this->generateAreaDiv( $field['tagName'], $field['prompt'], $field['required'], $field['errorMsg'], $field['cols'], $field['rows'], $field['htmlOptions'] );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "fieldset";
|
|
||||||
$strFieldsetFields = $this->generateFields( $field['fields'] );
|
|
||||||
|
|
||||||
$strFieldSet = sprintf( '
|
|
||||||
<fieldset>
|
|
||||||
<legend>%s</legend>
|
|
||||||
<div class="notes">
|
|
||||||
<h4>%s</h4>
|
|
||||||
<p class="last">%s</p>
|
|
||||||
</div>
|
|
||||||
%s
|
|
||||||
</fieldset>', $field['legend'], $field['noteHeading'], $field['note'], $strFieldsetFields );
|
|
||||||
$strFormFields = $strFormFields.$strFieldSet;
|
|
||||||
break;
|
|
||||||
case "hidden";
|
|
||||||
$strFormFields = $strFormFields . $this->Html->hiddenTag( $field['tagName']);
|
|
||||||
break;
|
|
||||||
case "date":
|
|
||||||
$strFormFields = $strFormFields.$this->generateDate( $field['tagName'], $field['prompt'], null, null, null, null, $field['selected']);
|
|
||||||
break;
|
|
||||||
case "datetime":
|
|
||||||
$strFormFields = $strFormFields.$this->generateDateTime( $field['tagName'], $field['prompt'], '','','', '', $field['selected']);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//bugbug: i don't know how to put out a notice that an unknown type was entered.
|
|
||||||
break;
|
|
||||||
} // end switch $field['type']
|
|
||||||
} // end if isset $field['type']
|
|
||||||
}
|
}
|
||||||
return $strFormFields;
|
return $strFormFields;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -608,7 +608,7 @@ class HtmlHelper extends Helper
|
||||||
|
|
||||||
if ($error == $this->tagIsInvalid($this->model, $this->field))
|
if ($error == $this->tagIsInvalid($this->model, $this->field))
|
||||||
{
|
{
|
||||||
return sprintf(SHORT_ERROR_MESSAGE, is_array($text)? (empty($text[$error-1])? 'Error in field': $text[$error-1]): $text);
|
return sprintf('<div class="error_message">%s</div>', is_array($text)? (empty($text[$error-1])? 'Error in field': $text[$error-1]): $text);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,34 +28,37 @@
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
<?php $controller = Inflector::camelize($this->name)."Controller"; ?>
|
|
||||||
|
|
||||||
<h1>Missing Method in <?php echo $controller;?></h1>
|
<h1>Missing Method in <?php echo $controller;?></h1>
|
||||||
|
|
||||||
<p class="error">You are seeing this error because the action <em><?php echo $this->controller->missingAction;?></em>
|
<p class="error">You are seeing this error because the action <em><?php echo $action;?></em>
|
||||||
is not defined in controller <em><?php echo $controller;?></em>
|
is not defined in controller <em><?php echo $controller;?></em>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span class="notice"><strong>Notice:</strong> this error is being rendered by the <code>app/views/errors/missing_action.thtml</code>
|
<span class="notice"><strong>Notice:</strong> this error is being rendered by the <strong>app/views/errors/missing_action.thtml</strong>
|
||||||
view file, a user-customizable error page for handling invalid action dispatches.</span>
|
view file, a user-customizable error page for handling invalid action dispatches.</span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong>Fatal</strong>: Create Method:
|
<strong>Fatal</strong>: Create Method:
|
||||||
</p>
|
</p>
|
||||||
|
<p><?php<br />
|
||||||
|
class <?php echo $controller;?> extends AppController<br />
|
||||||
|
{<br />
|
||||||
|
function <?php echo $action;?>()<br />
|
||||||
|
{<br /><br />
|
||||||
|
}<br />
|
||||||
|
}<br />
|
||||||
|
?><br />
|
||||||
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<?php echo "<pre><?php\n\nclass " . $controller ." extends AppController {\n
|
|
||||||
function ".$this->controller->missingAction."()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}\n?></pre>"; ?>
|
|
||||||
in file : <?php echo "app".DS."controllers".DS.Inflector::underscore($controller).".php"; ?>
|
in file : <?php echo "app".DS."controllers".DS.Inflector::underscore($controller).".php"; ?>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong>Error</strong>: Unable to execute action <em><?php echo $this->controller->missingAction;?></em> in
|
<strong>Error</strong>: Unable to execute action <em><?php echo $action;?></em> in
|
||||||
<em><?php echo $controller;?></em>
|
<em><?php echo $controller;?></em>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -30,8 +30,8 @@
|
||||||
?>
|
?>
|
||||||
<h1>Requires a Database Connection</h1>
|
<h1>Requires a Database Connection</h1>
|
||||||
|
|
||||||
<p class="error">Missing Database Connection: Model <?php echo $this->controller->missingConnection;?> requires a database connection
|
<p class="error">Missing Database Connection: Model <?php echo $model;?> requires a database connection
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<span class="notice"><strong>Notice:</strong> this error is being rendered by the <code>app/views/errors/missing_database.thtml</code>
|
<span class="notice"><strong>Notice:</strong> this error is being rendered by the <code>app/views/errors/missing_database.thtml</code>
|
||||||
|
@ -42,6 +42,6 @@ view file, a user-customizable error page for handling errors within CakePHP.</s
|
||||||
<h2>Controller dump:</h2>
|
<h2>Controller dump:</h2>
|
||||||
<?php
|
<?php
|
||||||
unset($this->db);
|
unset($this->db);
|
||||||
pr($this);
|
pr($this);
|
||||||
?>
|
?>
|
||||||
<?php } ?>
|
<?php } ?>
|
|
@ -29,8 +29,7 @@
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
<h1>Missing controller</h1>
|
<h1>Missing controller</h1>
|
||||||
<?php $missing = $this->controller->missingController; ?>
|
<p class="error">You are seeing this error because controller <em><?php echo $controller;?></em>
|
||||||
<p class="error">You are seeing this error because controller <em><?php echo $missing;?></em>
|
|
||||||
could not be found.
|
could not be found.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -40,21 +39,26 @@ view file, a user-customizable error page for handling invalid controller dispat
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong>Fatal</strong>: Unable to load controller <em><?php echo $missing;?></em>
|
<strong>Fatal</strong>: Unable to load controller <em><?php echo $controller;?></em>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<strong>Fatal</strong>: Create Class:
|
<strong>Fatal</strong>: Create Class:
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<?php echo "<pre><?php\n\nclass " . $missing ." extends AppController {\n}\n\n?></pre>"; ?>
|
<p><?php<br />
|
||||||
in file : <?php echo "app".DS."controllers".DS.Inflector::underscore($missing).".php"; ?>
|
class <?php echo $controller;?> extends AppController<br />
|
||||||
|
{<br />
|
||||||
|
}<br />
|
||||||
|
?><br />
|
||||||
|
</p>
|
||||||
|
in file : <?php echo "app".DS."controllers".DS.Inflector::underscore($controller).".php"; ?>
|
||||||
</p>
|
</p>
|
||||||
<?php if (DEBUG>1):?>
|
<?php if (DEBUG>1):?>
|
||||||
<h2>Controller dump:</h2>
|
<h2>Controller dump:</h2>
|
||||||
<pre>
|
<pre>
|
||||||
<?php
|
<?php
|
||||||
unset($this->db);
|
unset($this->db);
|
||||||
print_r($this);
|
print_r($this->controller);
|
||||||
?>
|
?>
|
||||||
</pre>
|
</pre>
|
||||||
<?php endif;?>
|
<?php endif;?>
|
|
@ -28,9 +28,8 @@
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
<?php $missing = $this->controller->missingTable;?>
|
|
||||||
<h1>Missing Database Table</h1>
|
<h1>Missing Database Table</h1>
|
||||||
<p class="error">No Database table for model <?php echo $missing;?> (expected "<?php echo $this->controller->missingTableName;?>"), create it first.
|
<p class="error">No Database table for model <?php echo $model;?> (expected "<?php echo $table;?>"), create it first.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<span class="notice"><strong>Notice:</strong> this error is being rendered by the <code>app/views/errors/missing_table.thtml</code>
|
<span class="notice"><strong>Notice:</strong> this error is being rendered by the <code>app/views/errors/missing_table.thtml</code>
|
||||||
|
|
|
@ -31,8 +31,8 @@
|
||||||
<h1>Missing view</h1>
|
<h1>Missing view</h1>
|
||||||
|
|
||||||
<p class="error">You are seeing this error because the view <em><?php echo $this->missingView;?></em>
|
<p class="error">You are seeing this error because the view <em><?php echo $this->missingView;?></em>
|
||||||
for action <em><?php echo $this->params['action'];?></em>
|
for action <em><?php echo $action;?></em>
|
||||||
in controller <em><?php echo Inflector::camelize($this->name);?></em> could not be found.
|
in controller <em><?php echo $controller;?></em> could not be found.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -42,7 +42,7 @@ view file, a user-customizable error page for handling missing/invalid views dur
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<strong>Fatal</strong>: Unable to load view file <em><?php echo $this->missingView;?></em> for
|
<strong>Fatal</strong>: Unable to load view file <em><?php echo $this->missingView;?></em> for
|
||||||
action <em><?php echo $this->missingView;?>::<?php echo $this->params['action'];?></em>
|
action <em><?php echo $this->missingView;?>::<?php echo $action;?></em>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<?php if (DEBUG>1):?>
|
<?php if (DEBUG>1):?>
|
||||||
|
|
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* 1785 E. Sahara Avenue, Suite 490-204
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
* Las Vegas, Nevada 89104
|
* Las Vegas, Nevada 89104
|
||||||
*
|
*
|
||||||
* Licensed under The MIT License
|
* Licensed under The MIT License
|
||||||
* Redistributions of files must retain the above copyright notice.
|
* Redistributions of files must retain the above copyright notice.
|
||||||
*
|
*
|
||||||
* @filesource
|
* @filesource
|
||||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||||
* @package cake
|
* @package cake
|
||||||
|
@ -28,10 +28,8 @@
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
<?php $controller = Inflector::camelize($this->name)."Controller"; ?>
|
|
||||||
|
|
||||||
<h1>Private Method in <?php echo $controller;?></h1>
|
<h1>Private Method in <?php echo $controller;?></h1>
|
||||||
|
|
||||||
<p class="error">You are seeing this error because the action <em><?php echo $this->controller->privateAction;?></em>
|
<p class="error">You are seeing this error because the private class method <em><?php echo $action;?></em>
|
||||||
should not be accessed directly
|
should not be accessed directly
|
||||||
</p>
|
</p>
|
|
@ -28,10 +28,10 @@
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
<p style="background:#DBA941;padding:4px;font-size: 16px;">Your database configuration file is <?php echo file_exists(CONFIGS.'database.php') ? 'present.' . $filePresent = ' ' : 'not present.';?></p>
|
<p style="background:#DBA941;padding:4px;font-size: 16px;">Your database configuration file is <?php echo file_exists(CONFIGS.'database.php') ?' present.' . $filePresent = ' ' : ' not present.'; ?></p>
|
||||||
<?php $db = DboFactory::getInstance(); ?>
|
<?php $db = ConnectionManager::getInstance(); ?>
|
||||||
<?php if (!empty($filePresent)):?>
|
<?php if (!empty($filePresent)):?>
|
||||||
<p style="background:#DBA941;padding:4px;font-size: 16px;">Cake<?php echo $db->connected ? ' is able to ' : ' is not able to ';?>connect to the database.</p>
|
<p style="background:#DBA941;padding:4px;font-size: 16px;">Cake<?php echo $db->getDataSource('default')->connected ? ' is able to' : ' is not able to';?> connect to the database.</p>
|
||||||
<br />
|
<br />
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<h1>Take a bite out of Cake<em>PHP</em> Beta</h1>
|
<h1>Take a bite out of Cake<em>PHP</em> Beta</h1>
|
||||||
|
|
|
@ -52,9 +52,9 @@ else
|
||||||
<?php
|
<?php
|
||||||
if($type == 'Edit')
|
if($type == 'Edit')
|
||||||
{
|
{
|
||||||
echo "<li>".$html->linkTo('Delete '.Inflector::humanize($modelName), '/'.$this->viewPath.'/destroy/'.$data[$modelKey][$this->controller->{$modelName}->primaryKey])."</li>";
|
echo "<li>".$html->link('Delete '.Inflector::humanize($modelName), '/'.$this->viewPath.'/destroy/'.$data[$modelKey][$this->controller->{$modelName}->primaryKey])."</li>";
|
||||||
}
|
}
|
||||||
echo "<li>".$html->linkTo('List '.Inflector::humanize($modelName), '/'.$this->viewPath.'/index')."</li>";
|
echo "<li>".$html->link('List '.Inflector::humanize($modelName), '/'.$this->viewPath.'/index')."</li>";
|
||||||
|
|
||||||
if($type == 'Edit')
|
if($type == 'Edit')
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@ if($type == 'Edit')
|
||||||
{
|
{
|
||||||
if( isset( $value['foreignKey'] ) )
|
if( isset( $value['foreignKey'] ) )
|
||||||
{
|
{
|
||||||
echo "<li>".$html->linkTo( "View ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/show/".$data[$modelKey][$field] )."</li>";
|
echo "<li>".$html->link( "View ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/show/".$data[$modelKey][$field] )."</li>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,9 +61,8 @@
|
||||||
{
|
{
|
||||||
// this is a foreign key, figure out what the display field should be for this model.
|
// this is a foreign key, figure out what the display field should be for this model.
|
||||||
$otherModelKey = Inflector::underscore($value['modelKey']);
|
$otherModelKey = Inflector::underscore($value['modelKey']);
|
||||||
$otherControllerName = $value['controller'];
|
$otherControllerName = $value['controller'];
|
||||||
$registry = ClassRegistry::getInstance();
|
$otherModelObject = ClassRegistry::getObject( $otherModelKey );
|
||||||
$otherModelObject = $registry->getObject( $otherModelKey );
|
|
||||||
$alias = array_search($value['table'],$this->controller->{$model}->alias);
|
$alias = array_search($value['table'],$this->controller->{$model}->alias);
|
||||||
if( is_object($otherModelObject) )
|
if( is_object($otherModelObject) )
|
||||||
{
|
{
|
||||||
|
@ -71,16 +70,16 @@
|
||||||
} else{
|
} else{
|
||||||
$displayText = $row[$alias][$field];
|
$displayText = $row[$alias][$field];
|
||||||
}
|
}
|
||||||
echo $html->linkTo( $displayText, "/".Inflector::underscore($otherControllerName)."/show/".$row[$modelKey][$field] );
|
echo $html->link( $displayText, "/".Inflector::underscore($otherControllerName)."/show/".$row[$modelKey][$field] );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo $row[$modelKey][$field];
|
echo $row[$modelKey][$field];
|
||||||
} ?>
|
} ?>
|
||||||
</td>
|
</td>
|
||||||
<?php } // end for each $fieldNames as $field=>value ?>
|
<?php } // end for each $fieldNames as $field=>value ?>
|
||||||
<td class="listactions"><?php echo $html->linkTo('View',"/".$this->viewPath."/show/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
<td class="listactions"><?php echo $html->link('View',"/".$this->viewPath."/show/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
||||||
<?php echo $html->linkTo('Edit',"/".$this->viewPath."/edit/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
<?php echo $html->link('Edit',"/".$this->viewPath."/edit/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
||||||
<?php echo $html->linkTo('Delete',"/".$this->viewPath."/destroy/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
<?php echo $html->link('Delete',"/".$this->viewPath."/destroy/{$row[$modelKey][$this->controller->{$model}->primaryKey]}/")?>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -90,7 +89,7 @@
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
<ul class="actions">
|
<ul class="actions">
|
||||||
<li><?php echo $html->linkTo('New '.$humanSingularName, '/'.$this->viewPath.'/add'); ?></li>
|
<li><?php echo $html->link('New '.$humanSingularName, '/'.$this->viewPath.'/add'); ?></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
</form>
|
</form>
|
||||||
<ul class='actions'>
|
<ul class='actions'>
|
||||||
<?php
|
<?php
|
||||||
echo "<li>".$html->linkTo('List '.Inflector::humanize($this->name), '/'.$this->viewPath.'/index')."</li>";
|
echo "<li>".$html->link('List '.Inflector::humanize($this->name), '/'.$this->viewPath.'/index')."</li>";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
</ul>
|
</ul>
|
|
@ -30,8 +30,7 @@
|
||||||
<?php
|
<?php
|
||||||
$modelName = Inflector::singularize($this->name);
|
$modelName = Inflector::singularize($this->name);
|
||||||
$modelKey = Inflector::underscore($modelName);
|
$modelKey = Inflector::underscore($modelName);
|
||||||
$registry =& ClassRegistry::getInstance();
|
$objModel = ClassRegistry::getObject($modelKey);
|
||||||
$objModel = $registry->getObject($modelKey);
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<h1>Show <?php echo Inflector::humanize($modelName)?></h1>
|
<h1>Show <?php echo Inflector::humanize($modelName)?></h1>
|
||||||
|
@ -43,14 +42,14 @@
|
||||||
if(isset($value['foreignKey']))
|
if(isset($value['foreignKey']))
|
||||||
{
|
{
|
||||||
$alias = array_search($value['table'],$objModel->alias);
|
$alias = array_search($value['table'],$objModel->alias);
|
||||||
$otherModelObject = $registry->getObject(Inflector::underscore($objModel->tableToModel[$value['table']]));
|
$otherModelObject = ClassRegistry::getObject(Inflector::underscore($objModel->tableToModel[$value['table']]));
|
||||||
$displayField = $otherModelObject->getDisplayField();
|
$displayField = $otherModelObject->getDisplayField();
|
||||||
$displayText = $data[$alias][$displayField];
|
$displayText = $data[$alias][$displayField];
|
||||||
|
|
||||||
if(!empty($data[$objModel->tableToModel[$objModel->table]][$field]))
|
if(!empty($data[$objModel->tableToModel[$objModel->source]][$field]))
|
||||||
{
|
{
|
||||||
echo "<dd>".$html->linkTo($displayText, '/'.Inflector::underscore($value['controller']).'/show/'
|
echo "<dd>".$html->link($displayText, '/'.Inflector::underscore($value['controller']).'/show/'
|
||||||
.$data[$objModel->tableToModel[$objModel->table]][$field] )."</dd>";
|
.$data[$objModel->tableToModel[$objModel->source]][$field] )."</dd>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -60,9 +59,9 @@
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// this is just a plain old field.
|
// this is just a plain old field.
|
||||||
if( !empty($data[$objModel->tableToModel[$objModel->table]][$field]))
|
if( !empty($data[$objModel->tableToModel[$objModel->source]][$field]))
|
||||||
{
|
{
|
||||||
echo "<dd>".$data[$objModel->tableToModel[$objModel->table]][$field]."</dd>";
|
echo "<dd>".$data[$objModel->tableToModel[$objModel->source]][$field]."</dd>";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -75,25 +74,27 @@
|
||||||
</dl>
|
</dl>
|
||||||
<ul class='actions'>
|
<ul class='actions'>
|
||||||
<?php
|
<?php
|
||||||
echo "<li>".$html->linkTo('Edit '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey])."</li>";
|
echo "<li>".$html->link('Edit '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->source]][$this->controller->{$modelName}->primaryKey])."</li>";
|
||||||
echo "<li>".$html->linkTo('Delete '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/destroy/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey])."</li>";
|
echo "<li>".$html->link('Delete '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/destroy/'.$data[$objModel->tableToModel[$objModel->source]][$this->controller->{$modelName}->primaryKey])."</li>";
|
||||||
echo "<li>".$html->linkTo('List '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/index')."</li>";
|
echo "<li>".$html->link('List '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/index')."</li>";
|
||||||
echo "<li>".$html->linkTo('New '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/add')."</li>";
|
echo "<li>".$html->link('New '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/add')."</li>";
|
||||||
foreach( $fieldNames as $field => $value ) {
|
|
||||||
if( isset( $value['foreignKey'] ) )
|
foreach( $fieldNames as $field => $value )
|
||||||
{
|
{
|
||||||
echo "<li>".$html->linkTo( "View ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/show/".$data[$alias][$otherModelObject->primaryKey] )."</li>";
|
if( isset( $value['foreignKey'] ) )
|
||||||
}
|
{
|
||||||
}
|
echo "<li>".$html->link( "List ".Inflector::humanize($value['controller']), "/".Inflector::underscore($value['controller'])."/index/")."</li>";
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<!--hasOne relationships -->
|
<!--hasOne relationships -->
|
||||||
<?php
|
<?php
|
||||||
foreach ($objModel->_oneToOne as $relation)
|
foreach ($objModel->hasOne as $association => $relation)
|
||||||
{
|
{
|
||||||
list($association, $model, $value) = $relation;
|
$model = $relation['className'];
|
||||||
$otherModelName = $objModel->tableToModel[$objModel->{$model}->table];
|
$otherModelName = $objModel->tableToModel[$objModel->{$model}->source];
|
||||||
$controller = Inflector::pluralize($model);
|
$controller = Inflector::pluralize($model);
|
||||||
|
|
||||||
echo "<div class='related'><H2>Related ".Inflector::humanize($association)."</H2>";
|
echo "<div class='related'><H2>Related ".Inflector::humanize($association)."</H2>";
|
||||||
|
@ -113,26 +114,17 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
echo "</dl>";
|
echo "</dl>";
|
||||||
echo "<ul class='actions'><li>".$html->linkTo('Edit '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/edit/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
|
echo "<ul class='actions'><li>".$html->link('Edit '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/edit/{$data[$association][$objModel->{$model}->primaryKey]}")."</li></ul></div>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- HAS MANY AND HASANDBELONGSTOMANY -->
|
<!-- HAS MANY AND HASANDBELONGSTOMANY -->
|
||||||
<?php
|
<?php
|
||||||
$relations = array();
|
|
||||||
foreach( $objModel->_oneToMany as $relation )
|
|
||||||
{
|
|
||||||
$relations[] = $relation;
|
|
||||||
} // end loop through onetomany relations.
|
|
||||||
|
|
||||||
foreach( $objModel->_manyToMany as $relation )
|
$relations = array_merge($objModel->hasMany, $objModel->hasAndBelongsToMany);
|
||||||
|
foreach($relations as $association => $relation)
|
||||||
{
|
{
|
||||||
$relations[] = $relation;
|
$model = $relation['className'];
|
||||||
} // end loop through manytomany relations.
|
|
||||||
|
|
||||||
foreach( $relations as $relation )
|
|
||||||
{
|
|
||||||
list($association, $model, $value) = $relation;
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
$otherModelName = Inflector::singularize($model);
|
$otherModelName = Inflector::singularize($model);
|
||||||
$controller = Inflector::pluralize($model);
|
$controller = Inflector::pluralize($model);
|
||||||
|
@ -163,9 +155,9 @@
|
||||||
echo "<td>".$value."</td>";
|
echo "<td>".$value."</td>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<td class="listactions"><?php echo $html->linkTo('View',"/".Inflector::underscore($controller)."/show/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
<td class="listactions"><?php echo $html->link('View',"/".Inflector::underscore($controller)."/show/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
||||||
<?php echo $html->linkTo('Edit',"/".Inflector::underscore($controller)."/edit/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
<?php echo $html->link('Edit',"/".Inflector::underscore($controller)."/edit/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
||||||
<?php echo $html->linkTo('Delete',"/".Inflector::underscore($controller)."/destroy/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
<?php echo $html->link('Delete',"/".Inflector::underscore($controller)."/destroy/{$row[$this->controller->{$modelName}->{$association}->primaryKey]}/")?>
|
||||||
</td>
|
</td>
|
||||||
<?php
|
<?php
|
||||||
echo "</tr>";
|
echo "</tr>";
|
||||||
|
@ -178,7 +170,7 @@
|
||||||
<?php
|
<?php
|
||||||
// add a link to create a new relation.
|
// add a link to create a new relation.
|
||||||
|
|
||||||
echo "<li>".$html->linkTo('New '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/add/")."</li>";
|
echo "<li>".$html->link('New '.Inflector::humanize($association),"/".Inflector::underscore($controller)."/add/")."</li>";
|
||||||
?>
|
?>
|
||||||
</ul></div>
|
</ul></div>
|
||||||
|
|
||||||
|
|
|
@ -324,11 +324,11 @@ class View extends Object
|
||||||
// app/view/errors/missing_view.thtml view is missing!
|
// app/view/errors/missing_view.thtml view is missing!
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
{
|
{
|
||||||
trigger_error(sprintf(ERROR_NO_VIEW, $action, $viewFileName), E_USER_ERROR);
|
trigger_error(sprintf(__("No template file for view %s (expected %s), create it first'"), $action, $viewFileName), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error('404', 'Not found', sprintf(ERROR_404, '', "missing view \"{$action}\""));
|
$this->error('404', 'Not found', sprintf("The requested address %s was not found on this server.", '', "missing view \"{$action}\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
die();
|
die();
|
||||||
|
@ -358,7 +358,7 @@ class View extends Object
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$out = $this->_render($viewFileName, $this->_viewVars, false);
|
$out = $this->_render($viewFileName, $this->_viewVars, false);
|
||||||
trigger_error(sprintf(ERROR_IN_VIEW, $viewFileName, $out), E_USER_ERROR);
|
trigger_error(sprintf(__("Error in view %s, got: <blockquote>%s</blockquote>"), $viewFileName, $out), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -418,7 +418,7 @@ class View extends Object
|
||||||
if ($out === false)
|
if ($out === false)
|
||||||
{
|
{
|
||||||
$out = $this->_render($layout_fn, $data_for_layout, false);
|
$out = $this->_render($layout_fn, $data_for_layout, false);
|
||||||
trigger_error(sprintf(ERROR_IN_LAYOUT, $layout_fn, $out), E_USER_ERROR);
|
trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>"), $layout_fn, $out), E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -428,7 +428,7 @@ class View extends Object
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
trigger_error(sprintf(ERROR_NO_LAYOUT, $this->layout, $layout_fn), E_USER_ERROR);
|
trigger_error(sprintf(__("Could not find layout %s (expected %s), create it first"), $this->layout, $layout_fn), E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -605,8 +605,13 @@ class View extends Object
|
||||||
*/
|
*/
|
||||||
function &_loadHelpers(&$loaded, $helpers)
|
function &_loadHelpers(&$loaded, $helpers)
|
||||||
{
|
{
|
||||||
$helperTags = new Helper();
|
static $tags;
|
||||||
$tags = $helperTags->loadConfig();
|
if(empty($tags))
|
||||||
|
{
|
||||||
|
$helperTags = new Helper();
|
||||||
|
$tags = $helperTags->loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($helpers as $helper)
|
foreach ($helpers as $helper)
|
||||||
{
|
{
|
||||||
$helperCn = $helper.'Helper';
|
$helperCn = $helper.'Helper';
|
||||||
|
|
|
@ -71,9 +71,10 @@ uses ('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'acoaction');
|
||||||
uses ('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aro');
|
uses ('controller'.DS.'components'.DS.'dbacl'.DS.'models'.DS.'aro');
|
||||||
|
|
||||||
//Get and format args: first arg is the name of the script.
|
//Get and format args: first arg is the name of the script.
|
||||||
$wasted = array_shift($_SERVER['argv']);
|
$serverArgs = env('argv');
|
||||||
$command = array_shift($_SERVER['argv']);
|
$wasted = array_shift($serverArgs);
|
||||||
$args = $_SERVER['argv'];
|
$command = array_shift($serverArgs);
|
||||||
|
$args = $serverArgs;
|
||||||
|
|
||||||
$aclCLI = new AclCLI ($command, $args);
|
$aclCLI = new AclCLI ($command, $args);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue