mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Turned dos line endings into unix
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63113 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
b27797598f
commit
6915ac9bc7
@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Classes that must be run yearly extend this class
|
* Classes that must be run yearly extend this class
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage cron
|
* @subpackage cron
|
||||||
*/
|
*/
|
||||||
class YearlyTask extends ScheduledTask {
|
class YearlyTask extends ScheduledTask {
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -1,716 +1,716 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* PDO (general database) connector class.
|
* PDO (general database) connector class.
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
*/
|
*/
|
||||||
class PDODatabase extends Database {
|
class PDODatabase extends Database {
|
||||||
/**
|
/**
|
||||||
* Connection to the DBMS.
|
* Connection to the DBMS.
|
||||||
* @var resource
|
* @var resource
|
||||||
*/
|
*/
|
||||||
private $dbConn;
|
private $dbConn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True if we are connected to a database.
|
* True if we are connected to a database.
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
private $active;
|
private $active;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the database.
|
* The name of the database.
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $database;
|
private $database;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Last PDO statement, needed for affectedRows()
|
* Last PDO statement, needed for affectedRows()
|
||||||
* @var PDO object
|
* @var PDO object
|
||||||
*/
|
*/
|
||||||
private $stmt;
|
private $stmt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters used for creating a connection
|
* Parameters used for creating a connection
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $param;
|
private $param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to a database (MySQL, PostgreSQL, or MS SQL).
|
* Connect to a database (MySQL, PostgreSQL, or MS SQL).
|
||||||
* @param parameters An map of parameters, which should include:
|
* @param parameters An map of parameters, which should include:
|
||||||
* <ul><li>database: The database to connect with</li>
|
* <ul><li>database: The database to connect with</li>
|
||||||
* <li>server: The server, eg, localhost</li>
|
* <li>server: The server, eg, localhost</li>
|
||||||
* <li>port: The port on which the server is listening (optional)</li>
|
* <li>port: The port on which the server is listening (optional)</li>
|
||||||
* <li>instance: Instance of the server, MS SQL only (optional)</li>
|
* <li>instance: Instance of the server, MS SQL only (optional)</li>
|
||||||
* <li>username: The username to log on with</li>
|
* <li>username: The username to log on with</li>
|
||||||
* <li>password: The password to log on with</li>
|
* <li>password: The password to log on with</li>
|
||||||
* <li>database: The database to connect to</li></ul>
|
* <li>database: The database to connect to</li></ul>
|
||||||
*/
|
*/
|
||||||
public function __construct($parameters) {
|
public function __construct($parameters) {
|
||||||
$this->param = $parameters;
|
$this->param = $parameters;
|
||||||
$connect = self::getConnect($parameters);
|
$connect = self::getConnect($parameters);
|
||||||
$connectWithDB = $connect . ';dbname=' . $parameters['database'];
|
$connectWithDB = $connect . ';dbname=' . $parameters['database'];
|
||||||
try { // Try connect to the database, if it does not exist, create it
|
try { // Try connect to the database, if it does not exist, create it
|
||||||
$this->dbConn = new PDO($connectWithDB, $parameters['username'], $parameters['password']);
|
$this->dbConn = new PDO($connectWithDB, $parameters['username'], $parameters['password']);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
// To do - this is an instance method, not a static method. Call it as such.
|
// To do - this is an instance method, not a static method. Call it as such.
|
||||||
if (!self::createDatabase($connect, $parameters['username'], $parameters['password'], $parameters['database'])) {
|
if (!self::createDatabase($connect, $parameters['username'], $parameters['password'], $parameters['database'])) {
|
||||||
$this->databaseError("Could not connect to the database, make sure the server is available and user credentials are correct");
|
$this->databaseError("Could not connect to the database, make sure the server is available and user credentials are correct");
|
||||||
} else {
|
} else {
|
||||||
$this->dbConn = new PDO($connectWithDB, $parameters['username'], $parameters['password']); // After creating the database, connect to it
|
$this->dbConn = new PDO($connectWithDB, $parameters['username'], $parameters['password']); // After creating the database, connect to it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the connection string from input.
|
* Build the connection string from input.
|
||||||
* @param array $parameters The connection details.
|
* @param array $parameters The connection details.
|
||||||
* @return string $connect The connection string.
|
* @return string $connect The connection string.
|
||||||
**/
|
**/
|
||||||
public function getConnect($parameters) {
|
public function getConnect($parameters) {
|
||||||
switch ($parameters['type']) {
|
switch ($parameters['type']) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
$port = '3306';
|
$port = '3306';
|
||||||
$type = 'mysql';
|
$type = 'mysql';
|
||||||
$instance = '';
|
$instance = '';
|
||||||
break;
|
break;
|
||||||
case "postgresql":
|
case "postgresql":
|
||||||
$port = '5432';
|
$port = '5432';
|
||||||
$type = 'pgsql';
|
$type = 'pgsql';
|
||||||
$instance = '';
|
$instance = '';
|
||||||
break;
|
break;
|
||||||
case "mssql":
|
case "mssql":
|
||||||
$port = '1433';
|
$port = '1433';
|
||||||
if (isset($parameters['instance']) && $parameters['instance'] != '') {
|
if (isset($parameters['instance']) && $parameters['instance'] != '') {
|
||||||
$instance = '\\' . $parameters['instance'];
|
$instance = '\\' . $parameters['instance'];
|
||||||
} else {
|
} else {
|
||||||
$instance = '';
|
$instance = '';
|
||||||
}
|
}
|
||||||
$type = 'mssql';
|
$type = 'mssql';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->databaseError("This database server is not available");
|
$this->databaseError("This database server is not available");
|
||||||
}
|
}
|
||||||
if (isset($parameters['port']) && is_numeric($parameters['port'])) {
|
if (isset($parameters['port']) && is_numeric($parameters['port'])) {
|
||||||
$port = $parameters['port'];
|
$port = $parameters['port'];
|
||||||
}
|
}
|
||||||
$connect = $type . ':host=' . $parameters['server'] . $instance . ';port=' . $port;
|
$connect = $type . ':host=' . $parameters['server'] . $instance . ';port=' . $port;
|
||||||
return $connect;
|
return $connect;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this database supports collations
|
* Returns true if this database supports collations
|
||||||
*/
|
*/
|
||||||
public function supportsCollations() {
|
public function supportsCollations() {
|
||||||
$collations = false;
|
$collations = false;
|
||||||
switch (self::getDatabaseServer()) {
|
switch (self::getDatabaseServer()) {
|
||||||
case "pgsql": // Generally supported in PostgreSQL (supported versions), but handled differently than in MySQL, so do not set
|
case "pgsql": // Generally supported in PostgreSQL (supported versions), but handled differently than in MySQL, so do not set
|
||||||
case "mssql": // Generally supported in MS SQL (supported versions), but handled differently than in MySQL, so do not set
|
case "mssql": // Generally supported in MS SQL (supported versions), but handled differently than in MySQL, so do not set
|
||||||
$collations = false;
|
$collations = false;
|
||||||
break;
|
break;
|
||||||
case "mysql":
|
case "mysql":
|
||||||
if (self::getVersion() >= 4.1) { // Supported in MySQL since 4.1
|
if (self::getVersion() >= 4.1) { // Supported in MySQL since 4.1
|
||||||
$collations = true;
|
$collations = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $collations;
|
return $collations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the database version.
|
* Get the database version.
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function getVersion() {
|
public function getVersion() {
|
||||||
switch (self::getDatabaseServer()) {
|
switch (self::getDatabaseServer()) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
case "pgsql":
|
case "pgsql":
|
||||||
$query = "SELECT VERSION()";
|
$query = "SELECT VERSION()";
|
||||||
break;
|
break;
|
||||||
case "mssql":
|
case "mssql":
|
||||||
$query = "SELECT @@VERSION";
|
$query = "SELECT @@VERSION";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$stmt = $this->dbConn->prepare($query);
|
$stmt = $this->dbConn->prepare($query);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$dbVersion = $stmt->fetchColumn();
|
$dbVersion = $stmt->fetchColumn();
|
||||||
$version = ereg_replace("([A-Za-z-])", "", $dbVersion);
|
$version = ereg_replace("([A-Za-z-])", "", $dbVersion);
|
||||||
return substr(trim($version), 0, 3); // Just get the major and minor version
|
return substr(trim($version), 0, 3); // Just get the major and minor version
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the database server, namely mysql, pgsql, or mssql.
|
* Get the database server, namely mysql, pgsql, or mssql.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getDatabaseServer() {
|
public function getDatabaseServer() {
|
||||||
return $this->dbConn->getAttribute(PDO::ATTR_DRIVER_NAME);
|
return $this->dbConn->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the database.
|
* Query the database.
|
||||||
* @var string $sql The query to be issued to the database.
|
* @var string $sql The query to be issued to the database.
|
||||||
* @return result Return the result of the quers (if any).
|
* @return result Return the result of the quers (if any).
|
||||||
*/
|
*/
|
||||||
public function query($sql, $errorLevel = E_USER_ERROR) {
|
public function query($sql, $errorLevel = E_USER_ERROR) {
|
||||||
if(isset($_REQUEST['previewwrite']) && in_array(strtolower(substr($sql,0,6)), array('insert','update'))) {
|
if(isset($_REQUEST['previewwrite']) && in_array(strtolower(substr($sql,0,6)), array('insert','update'))) {
|
||||||
Debug::message("Will execute: $sql");
|
Debug::message("Will execute: $sql");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Debug::backtrace();
|
//Debug::backtrace();
|
||||||
if(isset($_REQUEST['showqueries'])) {
|
if(isset($_REQUEST['showqueries'])) {
|
||||||
Debug::message("\n" . $sql . "\n");
|
Debug::message("\n" . $sql . "\n");
|
||||||
$starttime = microtime(true);
|
$starttime = microtime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = $dbConn->prepare($sql);
|
$stmt = $dbConn->prepare($sql);
|
||||||
|
|
||||||
$stmt = $this->dbConn->prepare($sql);
|
$stmt = $this->dbConn->prepare($sql);
|
||||||
$handle = $stmt->execute(); // Execute and save the return value (true or false)
|
$handle = $stmt->execute(); // Execute and save the return value (true or false)
|
||||||
|
|
||||||
if(isset($_REQUEST['showqueries'])) {
|
if(isset($_REQUEST['showqueries'])) {
|
||||||
$duration = microtime(true) - $starttime;
|
$duration = microtime(true) - $starttime;
|
||||||
Debug::message("\n" . $duration . "\n");
|
Debug::message("\n" . $duration . "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$handle && $errorLevel) {
|
if(!$handle && $errorLevel) {
|
||||||
$error = $stmt->errorInfo();
|
$error = $stmt->errorInfo();
|
||||||
$this->databaseError("Couldn't run query: $sql | " . $error[2], $errorLevel);
|
$this->databaseError("Couldn't run query: $sql | " . $error[2], $errorLevel);
|
||||||
}
|
}
|
||||||
return new PDOQuery($this, $stmt);
|
return new PDOQuery($this, $stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ID for the next new record for the table.
|
* Get the ID for the next new record for the table.
|
||||||
* Get the autogenerated ID from the previous INSERT query.
|
* Get the autogenerated ID from the previous INSERT query.
|
||||||
* Simulate mysql_insert_id by fetching the highest ID as there is no other reliable method across databases.
|
* Simulate mysql_insert_id by fetching the highest ID as there is no other reliable method across databases.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getGeneratedID($table) {
|
public function getGeneratedID($table) {
|
||||||
$stmt = $this->dbConn->prepare("SELECT MAX(ID) FROM $table");
|
$stmt = $this->dbConn->prepare("SELECT MAX(ID) FROM $table");
|
||||||
$handle = $stmt->execute();
|
$handle = $stmt->execute();
|
||||||
$result = $stmt->fetchColumn();
|
$result = $stmt->fetchColumn();
|
||||||
return $handle ? $result : 0;
|
return $handle ? $result : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OBSOLETE: Get the ID for the next new record for the table.
|
* OBSOLETE: Get the ID for the next new record for the table.
|
||||||
* @var string $table The name od the table.
|
* @var string $table The name od the table.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getNextID($table) {
|
public function getNextID($table) {
|
||||||
user_error('getNextID is OBSOLETE (and will no longer work properly)', E_USER_WARNING);
|
user_error('getNextID is OBSOLETE (and will no longer work properly)', E_USER_WARNING);
|
||||||
$stmt = $this->dbConn->prepare("SELECT MAX(ID)+1 FROM $table");
|
$stmt = $this->dbConn->prepare("SELECT MAX(ID)+1 FROM $table");
|
||||||
$handle = $stmt->execute();
|
$handle = $stmt->execute();
|
||||||
$result = $stmt->fetchColumn();
|
$result = $stmt->fetchColumn();
|
||||||
return $handle ? $result : 1;
|
return $handle ? $result : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the the table is active.
|
* Determine if the the table is active.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isActive() {
|
public function isActive() {
|
||||||
return $this->active ? true : false;
|
return $this->active ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the database and connect to it. This can be called if the
|
* Create the database and connect to it. This can be called if the
|
||||||
* initial database connection is not successful because the database
|
* initial database connection is not successful because the database
|
||||||
* does not exist.
|
* does not exist.
|
||||||
* @param string $connect Connection string
|
* @param string $connect Connection string
|
||||||
* @param string $username Database username
|
* @param string $username Database username
|
||||||
* @param string $password Database Password
|
* @param string $password Database Password
|
||||||
* @param string $database Database to which to create
|
* @param string $database Database to which to create
|
||||||
* @return boolean Returns true if successful
|
* @return boolean Returns true if successful
|
||||||
* @todo This shouldn't take any arguments; it should take the information given in the constructor instead.
|
* @todo This shouldn't take any arguments; it should take the information given in the constructor instead.
|
||||||
*/
|
*/
|
||||||
public function createDatabase() {
|
public function createDatabase() {
|
||||||
try {
|
try {
|
||||||
$dbh = new PDO($connect, $username, $password);
|
$dbh = new PDO($connect, $username, $password);
|
||||||
$stmt = $dbh->prepare("CREATE DATABASE $database");
|
$stmt = $dbh->prepare("CREATE DATABASE $database");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$this->active = true;
|
$this->active = true;
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$this->databaseError($e->getMessage());
|
$this->databaseError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the named database exists.
|
* Returns true if the named database exists.
|
||||||
*/
|
*/
|
||||||
public function databaseExists($name) {
|
public function databaseExists($name) {
|
||||||
$SQL_name = Convert::raw2sql($name);
|
$SQL_name = Convert::raw2sql($name);
|
||||||
$connect = self::getConnect($this->param);
|
$connect = self::getConnect($this->param);
|
||||||
$connectWithDB = $connect . ';dbname=' . $SQL_name;
|
$connectWithDB = $connect . ';dbname=' . $SQL_name;
|
||||||
try { // Try connect to the database
|
try { // Try connect to the database
|
||||||
$testConn = new PDO($connectWithDB, $this->param['username'], $this->param['password']);
|
$testConn = new PDO($connectWithDB, $this->param['username'], $this->param['password']);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switches to the given database.
|
* Switches to the given database.
|
||||||
* Simply switching database in PDO is not possible, you need to create a new PDO object
|
* Simply switching database in PDO is not possible, you need to create a new PDO object
|
||||||
*/
|
*/
|
||||||
public function selectDatabase($dbname) {
|
public function selectDatabase($dbname) {
|
||||||
$this->dbConn = null; // Remove the old connection
|
$this->dbConn = null; // Remove the old connection
|
||||||
$connect = self::getConnect($param);
|
$connect = self::getConnect($param);
|
||||||
$connectWithDB = $connect . ';dbname=' . $dbname;
|
$connectWithDB = $connect . ';dbname=' . $dbname;
|
||||||
try { // Try connect to the database, if it does not exist, create it
|
try { // Try connect to the database, if it does not exist, create it
|
||||||
$this->dbConn = new PDO($connectWithDB, $param['username'], $param['password']);
|
$this->dbConn = new PDO($connectWithDB, $param['username'], $param['password']);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
if (!self::createDatabase($connect, $param['username'], $param['password'], $dbname)) {
|
if (!self::createDatabase($connect, $param['username'], $param['password'], $dbname)) {
|
||||||
$this->databaseError("Could not connect to the database, make sure the server is available and user credentials are correct");
|
$this->databaseError("Could not connect to the database, make sure the server is available and user credentials are correct");
|
||||||
} else {
|
} else {
|
||||||
$this->dbConn = new PDO($connectWithDB, $param['username'], $param['password']); // After creating the database, connect to it
|
$this->dbConn = new PDO($connectWithDB, $param['username'], $param['password']); // After creating the database, connect to it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new table with an integer primary key called ID.
|
* Create a new table with an integer primary key called ID.
|
||||||
* @var string $tableName The name of the table.
|
* @var string $tableName The name of the table.
|
||||||
* @return void.
|
* @return void.
|
||||||
*/
|
*/
|
||||||
public function createTable($tableName, $fields = null, $indexes = null) {
|
public function createTable($tableName, $fields = null, $indexes = null) {
|
||||||
$fieldSchemas = $indexSchemas = "";
|
$fieldSchemas = $indexSchemas = "";
|
||||||
if ($fields) {
|
if ($fields) {
|
||||||
foreach($fields as $k => $v) $fieldSchemas .= "`$k` $v,\n";
|
foreach($fields as $k => $v) $fieldSchemas .= "`$k` $v,\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (self::getDatabaseServer()) {
|
switch (self::getDatabaseServer()) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
$stmt = $this->dbConn->prepare("CREATE TABLE $tableName (ID INT(11) NOT NULL AUTO_INCREMENT, $fieldSchemas PRIMARY KEY (ID)) TYPE=MyISAM");
|
$stmt = $this->dbConn->prepare("CREATE TABLE $tableName (ID INT(11) NOT NULL AUTO_INCREMENT, $fieldSchemas PRIMARY KEY (ID)) TYPE=MyISAM");
|
||||||
break;
|
break;
|
||||||
case "pgsql":
|
case "pgsql":
|
||||||
$stmt = $this->dbConn->prepare("CREATE TABLE $tableName (ID SERIAL, $fieldSchemas PRIMARY KEY (ID))");
|
$stmt = $this->dbConn->prepare("CREATE TABLE $tableName (ID SERIAL, $fieldSchemas PRIMARY KEY (ID))");
|
||||||
break;
|
break;
|
||||||
case "mssql":
|
case "mssql":
|
||||||
$stmt = $this->dbConn->prepare("CREATE TABLE $tableName (ID INT(11) IDENTITY(1,1), $fieldSchemas PRIMARY KEY (ID))");
|
$stmt = $this->dbConn->prepare("CREATE TABLE $tableName (ID INT(11) IDENTITY(1,1), $fieldSchemas PRIMARY KEY (ID))");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->databaseError("This database server is not available");
|
$this->databaseError("This database server is not available");
|
||||||
}
|
}
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
|
|
||||||
if ($indexes) {
|
if ($indexes) {
|
||||||
self::alterTable($tableName, null, $indexes, null, null);
|
self::alterTable($tableName, null, $indexes, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alter fields and indexes in existing table.
|
* Alter fields and indexes in existing table.
|
||||||
* @param string $tableName The name of the table.
|
* @param string $tableName The name of the table.
|
||||||
* @param string $newFields Fields to add.
|
* @param string $newFields Fields to add.
|
||||||
* @param string $newIndexes Indexes to add.
|
* @param string $newIndexes Indexes to add.
|
||||||
* @param string $alteredFields Fields to change.
|
* @param string $alteredFields Fields to change.
|
||||||
* @param string $alteredIndexes Indexes to change.
|
* @param string $alteredIndexes Indexes to change.
|
||||||
* @return void.
|
* @return void.
|
||||||
*/
|
*/
|
||||||
public function alterTable($table, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null) {
|
public function alterTable($table, $newFields = null, $newIndexes = null, $alteredFields = null, $alteredIndexes = null) {
|
||||||
|
|
||||||
if ($newFields) {
|
if ($newFields) {
|
||||||
foreach ($newFields as $field => $type) {
|
foreach ($newFields as $field => $type) {
|
||||||
$stmt = $this->dbConn->prepare("ALTER TABLE $table ADD $field $type");
|
$stmt = $this->dbConn->prepare("ALTER TABLE $table ADD $field $type");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($newIndexes) {
|
if ($newIndexes) {
|
||||||
foreach ($newIndexes as $name => $column) {
|
foreach ($newIndexes as $name => $column) {
|
||||||
$stmt = $this->dbConn->prepare("CREATE INDEX $name ON $table $column");
|
$stmt = $this->dbConn->prepare("CREATE INDEX $name ON $table $column");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($alteredFields) {
|
if ($alteredFields) {
|
||||||
foreach ($alteredFields as $field => $type) {
|
foreach ($alteredFields as $field => $type) {
|
||||||
self::alterField($table, $field, $type);
|
self::alterField($table, $field, $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($alteredIndexes) {
|
if ($alteredIndexes) {
|
||||||
foreach ($newIndexes as $name => $column) {
|
foreach ($newIndexes as $name => $column) {
|
||||||
$this->dbConn->query("DROP INDEX $name");
|
$this->dbConn->query("DROP INDEX $name");
|
||||||
$stmt = $this->dbConn->prepare("CREATE INDEX $name ON $table $column");
|
$stmt = $this->dbConn->prepare("CREATE INDEX $name ON $table $column");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rename an existing table, the TO is necessary for PostgreSQL and MS SQL.
|
* Rename an existing table, the TO is necessary for PostgreSQL and MS SQL.
|
||||||
* @param string $oldTableName The name of the existing table.
|
* @param string $oldTableName The name of the existing table.
|
||||||
* @param string $newTableName How the table should be named from now on.
|
* @param string $newTableName How the table should be named from now on.
|
||||||
* @return void.
|
* @return void.
|
||||||
*/
|
*/
|
||||||
public function renameTable($oldTableName, $newTableName) {
|
public function renameTable($oldTableName, $newTableName) {
|
||||||
$stmt = $this->dbConn->prepare("ALTER TABLE $oldTableName RENAME TO $newTableName");
|
$stmt = $this->dbConn->prepare("ALTER TABLE $oldTableName RENAME TO $newTableName");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks a table's integrity and repairs it if necessary - only available in MySQL, not supported in PostgreSQL and MS SQL.
|
* Checks a table's integrity and repairs it if necessary - only available in MySQL, not supported in PostgreSQL and MS SQL.
|
||||||
* @var string $tableName The name of the table.
|
* @var string $tableName The name of the table.
|
||||||
* @return boolean Return true if the table has integrity after the method is complete.
|
* @return boolean Return true if the table has integrity after the method is complete.
|
||||||
*/
|
*/
|
||||||
public function checkAndRepairTable($tableName) {
|
public function checkAndRepairTable($tableName) {
|
||||||
if ($parameters['type'] == "mysql") {
|
if ($parameters['type'] == "mysql") {
|
||||||
if (!$this->runTableCheckCommand("CHECK TABLE `$tableName`")) {
|
if (!$this->runTableCheckCommand("CHECK TABLE `$tableName`")) {
|
||||||
if(!Database::$supressOutput) {
|
if(!Database::$supressOutput) {
|
||||||
echo "<li style=\"color: orange\">Table $tableName: repaired</li>";
|
echo "<li style=\"color: orange\">Table $tableName: repaired</li>";
|
||||||
}
|
}
|
||||||
return $this->runTableCheckCommand("REPAIR TABLE `$tableName` USE_FRM");
|
return $this->runTableCheckCommand("REPAIR TABLE `$tableName` USE_FRM");
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->databaseError("Checking and repairing of tables is only supported in MySQL, for other databases please do manual checks");
|
$this->databaseError("Checking and repairing of tables is only supported in MySQL, for other databases please do manual checks");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function used by checkAndRepairTable.
|
* Helper function used by checkAndRepairTable.
|
||||||
* @param string $sql Query to run.
|
* @param string $sql Query to run.
|
||||||
* @return boolean Returns if the query returns a successful result.
|
* @return boolean Returns if the query returns a successful result.
|
||||||
*/
|
*/
|
||||||
protected function runTableCheckCommand($sql) {
|
protected function runTableCheckCommand($sql) {
|
||||||
foreach($this->dbConn->query($sql) as $testRecord) {
|
foreach($this->dbConn->query($sql) as $testRecord) {
|
||||||
if(strtolower($testRecord['Msg_text']) != 'ok') {
|
if(strtolower($testRecord['Msg_text']) != 'ok') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the given field to the given table.
|
* Add the given field to the given table.
|
||||||
* @param string $tableName The name of the table on which to create the field.
|
* @param string $tableName The name of the table on which to create the field.
|
||||||
* @param string $fieldName The field to create.
|
* @param string $fieldName The field to create.
|
||||||
* @param string $fieldSpec The datatype of the field.
|
* @param string $fieldSpec The datatype of the field.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function createField($tableName, $fieldName, $fieldSpec) {
|
public function createField($tableName, $fieldName, $fieldSpec) {
|
||||||
$stmt = $this->dbConn->prepare("ALTER TABLE $tableName ADD $fieldName $fieldSpec");
|
$stmt = $this->dbConn->prepare("ALTER TABLE $tableName ADD $fieldName $fieldSpec");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the database type of the given field.
|
* Change the database type of the given field.
|
||||||
* @param string $table The table where to change the field.
|
* @param string $table The table where to change the field.
|
||||||
* @param string $field The field to change.
|
* @param string $field The field to change.
|
||||||
* @param string $type The new type of the field
|
* @param string $type The new type of the field
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function alterField($table, $field, $type) {
|
public function alterField($table, $field, $type) {
|
||||||
switch (self::getDatabaseServer()) {
|
switch (self::getDatabaseServer()) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
$stmt = $this->dbConn->prepare("ALTER TABLE $table CHANGE $field $field $type");
|
$stmt = $this->dbConn->prepare("ALTER TABLE $table CHANGE $field $field $type");
|
||||||
break;
|
break;
|
||||||
case "pgsql":
|
case "pgsql":
|
||||||
$stmt = $this->dbConn->prepare("
|
$stmt = $this->dbConn->prepare("
|
||||||
BEGIN;
|
BEGIN;
|
||||||
ALTER TABLE $table RENAME $field TO oldfield;
|
ALTER TABLE $table RENAME $field TO oldfield;
|
||||||
ALTER TABLE $table ADD COLUMN $field $type;
|
ALTER TABLE $table ADD COLUMN $field $type;
|
||||||
UPDATE $table SET $field = CAST(oldfield AS $type);
|
UPDATE $table SET $field = CAST(oldfield AS $type);
|
||||||
ALTER TABLE $table DROP COLUMN oldfield;
|
ALTER TABLE $table DROP COLUMN oldfield;
|
||||||
COMMIT;
|
COMMIT;
|
||||||
");
|
");
|
||||||
break;
|
break;
|
||||||
case "mssql":
|
case "mssql":
|
||||||
$stmt = $this->dbConn->prepare("ALTER TABLE $table ALTER COLUMN $field $type");
|
$stmt = $this->dbConn->prepare("ALTER TABLE $table ALTER COLUMN $field $type");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->databaseError("This database server is not available");
|
$this->databaseError("This database server is not available");
|
||||||
}
|
}
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an index on a table.
|
* Create an index on a table.
|
||||||
* @param string $tableName The name of the table.
|
* @param string $tableName The name of the table.
|
||||||
* @param string $indexName The name of the index.
|
* @param string $indexName The name of the index.
|
||||||
* @param string $indexSpec The specification of the index, see Database::requireIndex() for more details.
|
* @param string $indexSpec The specification of the index, see Database::requireIndex() for more details.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function createIndex($tableName, $indexName, $indexSpec) {
|
public function createIndex($tableName, $indexName, $indexSpec) {
|
||||||
$stmt = $this->dbConn->prepare("CREATE INDEX $indexName ON $tableName $indexSpec");
|
$stmt = $this->dbConn->prepare("CREATE INDEX $indexName ON $tableName $indexSpec");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alter an index on a table.
|
* Alter an index on a table.
|
||||||
* @param string $tableName The name of the table.
|
* @param string $tableName The name of the table.
|
||||||
* @param string $indexName The name of the index.
|
* @param string $indexName The name of the index.
|
||||||
* @param string $indexSpec The specification of the index, see Database::requireIndex() for more details.
|
* @param string $indexSpec The specification of the index, see Database::requireIndex() for more details.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function alterIndex($tableName, $indexName, $indexSpec) {
|
public function alterIndex($tableName, $indexName, $indexSpec) {
|
||||||
$this->dbConn->query("DROP INDEX $indexName");
|
$this->dbConn->query("DROP INDEX $indexName");
|
||||||
$stmt = $this->dbConn->prepare("CREATE INDEX $indexName ON $tableName $indexSpec");
|
$stmt = $this->dbConn->prepare("CREATE INDEX $indexName ON $tableName $indexSpec");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all the fields for the given table.
|
* Get a list of all the fields for the given table.
|
||||||
* The results are not totally equal for all databases (for example collations are handled very differently, PostgreSQL disregards zerofill,...)
|
* The results are not totally equal for all databases (for example collations are handled very differently, PostgreSQL disregards zerofill,...)
|
||||||
* but as close as possible and necessary.
|
* but as close as possible and necessary.
|
||||||
* @param string $able Table of which to show the fields.
|
* @param string $able Table of which to show the fields.
|
||||||
* Returns a map of field name => field spec.
|
* Returns a map of field name => field spec.
|
||||||
*/
|
*/
|
||||||
public function fieldList($table) {
|
public function fieldList($table) {
|
||||||
switch (self::getDatabaseServer()) {
|
switch (self::getDatabaseServer()) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
foreach ($this->dbConn->query("SHOW FULL FIELDS IN $table") as $field) {
|
foreach ($this->dbConn->query("SHOW FULL FIELDS IN $table") as $field) {
|
||||||
$fieldSpec = $field['Type'];
|
$fieldSpec = $field['Type'];
|
||||||
if(!$field['Null'] || $field['Null'] == 'NO') {
|
if(!$field['Null'] || $field['Null'] == 'NO') {
|
||||||
$fieldSpec .= ' not null';
|
$fieldSpec .= ' not null';
|
||||||
}
|
}
|
||||||
if($field['Collation'] && $field['Collation'] != 'NULL') {
|
if($field['Collation'] && $field['Collation'] != 'NULL') {
|
||||||
$values = $this->dbConn->prepare("SHOW COLLATION LIKE '$field[Collation]'");
|
$values = $this->dbConn->prepare("SHOW COLLATION LIKE '$field[Collation]'");
|
||||||
$values->execute();
|
$values->execute();
|
||||||
$collInfo = $values->fetchColumn();
|
$collInfo = $values->fetchColumn();
|
||||||
$fieldSpec .= " character set $collInfo[Charset] collate $field[Collation]";
|
$fieldSpec .= " character set $collInfo[Charset] collate $field[Collation]";
|
||||||
}
|
}
|
||||||
if($field['Default'] || $field['Default'] === "0") {
|
if($field['Default'] || $field['Default'] === "0") {
|
||||||
$fieldSpec .= " default '" . addslashes($field['Default']) . "'";
|
$fieldSpec .= " default '" . addslashes($field['Default']) . "'";
|
||||||
}
|
}
|
||||||
if($field['Extra']) $fieldSpec .= " $field[Extra]";
|
if($field['Extra']) $fieldSpec .= " $field[Extra]";
|
||||||
$fieldList[$field['Field']] = $fieldSpec;
|
$fieldList[$field['Field']] = $fieldSpec;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "pgsql":
|
case "pgsql":
|
||||||
foreach ($this->dbConn->query("
|
foreach ($this->dbConn->query("
|
||||||
SELECT
|
SELECT
|
||||||
column_name AS cname,
|
column_name AS cname,
|
||||||
column_default AS cdefault,
|
column_default AS cdefault,
|
||||||
is_nullable AS nullable,
|
is_nullable AS nullable,
|
||||||
data_type AS dtype,
|
data_type AS dtype,
|
||||||
character_maximum_length AS maxlength
|
character_maximum_length AS maxlength
|
||||||
FROM
|
FROM
|
||||||
information_schema.columns
|
information_schema.columns
|
||||||
WHERE
|
WHERE
|
||||||
table_name = $table
|
table_name = $table
|
||||||
") as $field) {
|
") as $field) {
|
||||||
if ($field['maxlength']) {
|
if ($field['maxlength']) {
|
||||||
$fieldSpec = $field['dtype'] . "(" . $field['maxlength'] . ")";
|
$fieldSpec = $field['dtype'] . "(" . $field['maxlength'] . ")";
|
||||||
} else {
|
} else {
|
||||||
$fieldSpec = $field['dtype'];
|
$fieldSpec = $field['dtype'];
|
||||||
}
|
}
|
||||||
if ($field['nullable'] == 'NO') {
|
if ($field['nullable'] == 'NO') {
|
||||||
$fieldSpec .= ' not null';
|
$fieldSpec .= ' not null';
|
||||||
}
|
}
|
||||||
if($field['cdefault'] || $field['cdefault'] === "0") {
|
if($field['cdefault'] || $field['cdefault'] === "0") {
|
||||||
$fieldSpec .= " default '" . addslashes($field['cdefault']) . "'";
|
$fieldSpec .= " default '" . addslashes($field['cdefault']) . "'";
|
||||||
}
|
}
|
||||||
$fieldList[$field['cname']] = $fieldSpec;
|
$fieldList[$field['cname']] = $fieldSpec;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "mssql":
|
case "mssql":
|
||||||
foreach ($this->dbConn->query("
|
foreach ($this->dbConn->query("
|
||||||
SELECT
|
SELECT
|
||||||
COLUMN_NAME AS 'cname',
|
COLUMN_NAME AS 'cname',
|
||||||
COLUMN_DEFAULT AS 'cdefault',
|
COLUMN_DEFAULT AS 'cdefault',
|
||||||
IS_NULLABLE AS 'nullable',
|
IS_NULLABLE AS 'nullable',
|
||||||
DATA_TYPE AS 'dtype',
|
DATA_TYPE AS 'dtype',
|
||||||
COLLATION_NAME AS 'collname',
|
COLLATION_NAME AS 'collname',
|
||||||
CHARACTER_SET_NAME AS 'cset',
|
CHARACTER_SET_NAME AS 'cset',
|
||||||
CHARACTER_MAXIMUM_LENGTH AS 'maxlength'
|
CHARACTER_MAXIMUM_LENGTH AS 'maxlength'
|
||||||
FROM
|
FROM
|
||||||
information_schema.columns
|
information_schema.columns
|
||||||
WHERE
|
WHERE
|
||||||
TABLE_NAME = '$table'
|
TABLE_NAME = '$table'
|
||||||
") as $field) {
|
") as $field) {
|
||||||
if ($field['maxlength']) {
|
if ($field['maxlength']) {
|
||||||
$fieldSpec = $field['dtype'] . "(" . $field['maxlength'] . ")";
|
$fieldSpec = $field['dtype'] . "(" . $field['maxlength'] . ")";
|
||||||
} else {
|
} else {
|
||||||
$fieldSpec = $field['dtype'];
|
$fieldSpec = $field['dtype'];
|
||||||
}
|
}
|
||||||
if ($field['nullable'] == 'NO') {
|
if ($field['nullable'] == 'NO') {
|
||||||
$fieldSpec .= ' not null';
|
$fieldSpec .= ' not null';
|
||||||
}
|
}
|
||||||
|
|
||||||
if($field['collname'] && $field['collname'] != 'NULL') {
|
if($field['collname'] && $field['collname'] != 'NULL') {
|
||||||
$fieldSpec .= " character set $field[cset] collate $field[collname]";
|
$fieldSpec .= " character set $field[cset] collate $field[collname]";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($field['cdefault'] || $field['cdefault'] === "0") {
|
if($field['cdefault'] || $field['cdefault'] === "0") {
|
||||||
$fieldSpec .= " default '" . addslashes($field['cdefault']) . "'";
|
$fieldSpec .= " default '" . addslashes($field['cdefault']) . "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
$fieldList[$field['cname']] = $fieldSpec;
|
$fieldList[$field['cname']] = $fieldSpec;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->databaseError("This database server is not available");
|
$this->databaseError("This database server is not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $fieldList;
|
return $fieldList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all the indexes for the given table.
|
* Get a list of all the indexes for the given table.
|
||||||
* @param string $able Table of which to show the indexes.
|
* @param string $able Table of which to show the indexes.
|
||||||
* Returns a map of indexes.
|
* Returns a map of indexes.
|
||||||
*/
|
*/
|
||||||
public function indexList($table) {
|
public function indexList($table) {
|
||||||
switch (self::getDatabaseServer()) {
|
switch (self::getDatabaseServer()) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
foreach($this->dbConn->query("SHOW INDEXES IN '$table'") as $index) {
|
foreach($this->dbConn->query("SHOW INDEXES IN '$table'") as $index) {
|
||||||
$groupedIndexes[$index['Key_name']]['fields'][$index['Seq_in_index']] = $index['Column_name'];
|
$groupedIndexes[$index['Key_name']]['fields'][$index['Seq_in_index']] = $index['Column_name'];
|
||||||
if($index['Index_type'] == 'FULLTEXT') {
|
if($index['Index_type'] == 'FULLTEXT') {
|
||||||
$groupedIndexes[$index['Key_name']]['type'] = 'fulltext ';
|
$groupedIndexes[$index['Key_name']]['type'] = 'fulltext ';
|
||||||
} else if(!$index['Non_unique']) {
|
} else if(!$index['Non_unique']) {
|
||||||
$groupedIndexes[$index['Key_name']]['type'] = 'unique ';
|
$groupedIndexes[$index['Key_name']]['type'] = 'unique ';
|
||||||
} else {
|
} else {
|
||||||
$groupedIndexes[$index['Key_name']]['type'] = '';
|
$groupedIndexes[$index['Key_name']]['type'] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach($groupedIndexes as $index => $details) {
|
foreach($groupedIndexes as $index => $details) {
|
||||||
ksort($details['fields']);
|
ksort($details['fields']);
|
||||||
$indexList[$index] = $details['type'] . '(' . implode(',',$details['fields']) . ')';
|
$indexList[$index] = $details['type'] . '(' . implode(',',$details['fields']) . ')';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "pgsql":
|
case "pgsql":
|
||||||
foreach($this->dbConn->query("SELECT indexname, indexdef FROM pg_indexes WHERE tablename = '$table'") as $index) {
|
foreach($this->dbConn->query("SELECT indexname, indexdef FROM pg_indexes WHERE tablename = '$table'") as $index) {
|
||||||
$indexList[$index['indexname']] = $index['indexdef'];
|
$indexList[$index['indexname']] = $index['indexdef'];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "mssql":
|
case "mssql":
|
||||||
foreach($this->dbConn->query("
|
foreach($this->dbConn->query("
|
||||||
SELECT
|
SELECT
|
||||||
i.name AS 'iname',
|
i.name AS 'iname',
|
||||||
i.type_desc AS 'itype',
|
i.type_desc AS 'itype',
|
||||||
s.name AS 'sname'
|
s.name AS 'sname'
|
||||||
FROM
|
FROM
|
||||||
sys.indexes i,
|
sys.indexes i,
|
||||||
sys.objects o,
|
sys.objects o,
|
||||||
sys.index_columns c,
|
sys.index_columns c,
|
||||||
sys.columns s
|
sys.columns s
|
||||||
WHERE
|
WHERE
|
||||||
o.name = '$table'
|
o.name = '$table'
|
||||||
AND o.object_id = i.object_id
|
AND o.object_id = i.object_id
|
||||||
AND o.object_id = c.object_id
|
AND o.object_id = c.object_id
|
||||||
AND o.object_id = s.object_id
|
AND o.object_id = s.object_id
|
||||||
AND s.column_id = c.column_id
|
AND s.column_id = c.column_id
|
||||||
") as $index) {
|
") as $index) {
|
||||||
$indexList[$index['iname']] = $index['itype'] . " (" . $index['sname'] . ")";
|
$indexList[$index['iname']] = $index['itype'] . " (" . $index['sname'] . ")";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->databaseError("This database server is not available");
|
$this->databaseError("This database server is not available");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $indexList;
|
return $indexList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all the tables in the database.
|
* Returns a list of all the tables in the database.
|
||||||
* Table names will all be in lowercase.
|
* Table names will all be in lowercase.
|
||||||
* Returns a map of a table.
|
* Returns a map of a table.
|
||||||
*/
|
*/
|
||||||
public function tableList() {
|
public function tableList() {
|
||||||
switch (self::getDatabaseServer()) {
|
switch (self::getDatabaseServer()) {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
$sql = "SHOW TABLES";
|
$sql = "SHOW TABLES";
|
||||||
break;
|
break;
|
||||||
case "pgsql":
|
case "pgsql":
|
||||||
$sql = "SELECT tablename FROM pg_tables WHERE tablename NOT ILIKE 'pg_%' AND tablename NOT ILIKE 'sql_%'";
|
$sql = "SELECT tablename FROM pg_tables WHERE tablename NOT ILIKE 'pg_%' AND tablename NOT ILIKE 'sql_%'";
|
||||||
break;
|
break;
|
||||||
case "mssql":
|
case "mssql":
|
||||||
$sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME NOT LIKE 'sysdiagrams%'";
|
$sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME NOT LIKE 'sysdiagrams%'";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$this->databaseError("This database server is not available");
|
$this->databaseError("This database server is not available");
|
||||||
}
|
}
|
||||||
if (is_array($this->dbConn->query($sql))) {
|
if (is_array($this->dbConn->query($sql))) {
|
||||||
foreach($this->dbConn->query($sql) as $record) {
|
foreach($this->dbConn->query($sql) as $record) {
|
||||||
$table = strtolower(reset($record));
|
$table = strtolower(reset($record));
|
||||||
$tables[$table] = $table;
|
$tables[$table] = $table;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return isset($tables) ? $tables : null;
|
return isset($tables) ? $tables : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of rows affected (DELETE, INSERT, or UPDATE) by the previous operation.
|
* Return the number of rows affected (DELETE, INSERT, or UPDATE) by the previous operation.
|
||||||
*/
|
*/
|
||||||
public function affectedRows() {
|
public function affectedRows() {
|
||||||
return $stmt->rowCount();
|
return $stmt->rowCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A result-set from a database query (array).
|
* A result-set from a database query (array).
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
*/
|
*/
|
||||||
class PDOQuery extends Query {
|
class PDOQuery extends Query {
|
||||||
private $database;
|
private $database;
|
||||||
private $handle;
|
private $handle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object that holds the result set.
|
* The object that holds the result set.
|
||||||
* @var $stmt
|
* @var $stmt
|
||||||
*/
|
*/
|
||||||
private $stmt;
|
private $stmt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook the result-set given into a Query class, suitable for use by sapphire.
|
* Hook the result-set given into a Query class, suitable for use by sapphire.
|
||||||
* @param PDO object $stmt The object of all returned values.
|
* @param PDO object $stmt The object of all returned values.
|
||||||
*/
|
*/
|
||||||
public function __construct(PDODatabase $database, $stmt) {
|
public function __construct(PDODatabase $database, $stmt) {
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
$this->stmt = $stmt;
|
$this->stmt = $stmt;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free the result-set given into a Query class.
|
* Free the result-set given into a Query class.
|
||||||
*/
|
*/
|
||||||
public function __destroy() {
|
public function __destroy() {
|
||||||
$this->stmt = null;
|
$this->stmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a given element is part of the result set.
|
* Determine if a given element is part of the result set.
|
||||||
* @param string string $row The element to search for.
|
* @param string string $row The element to search for.
|
||||||
*/
|
*/
|
||||||
public function seek($row) {
|
public function seek($row) {
|
||||||
return in_array($row, $this->stmt->fetchAll());
|
return in_array($row, $this->stmt->fetchAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of results.
|
* Return the number of results.
|
||||||
*/
|
*/
|
||||||
public function numRecords() {
|
public function numRecords() {
|
||||||
$value = $this->stmt->fetchAll();
|
$value = $this->stmt->fetchAll();
|
||||||
return count($value);
|
return count($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function nextRecord() {
|
public function nextRecord() {
|
||||||
$record = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
$record = $this->stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
if (count($record)) {
|
if (count($record)) {
|
||||||
return $record;
|
return $record;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,153 +1,153 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* ComplexTableField designed to edit a has_many join.
|
* ComplexTableField designed to edit a has_many join.
|
||||||
* @package forms
|
* @package forms
|
||||||
* @subpackage fields-relational
|
* @subpackage fields-relational
|
||||||
*/
|
*/
|
||||||
class HasManyComplexTableField extends ComplexTableField {
|
class HasManyComplexTableField extends ComplexTableField {
|
||||||
|
|
||||||
public $joinField;
|
public $joinField;
|
||||||
|
|
||||||
protected $addTitle;
|
protected $addTitle;
|
||||||
|
|
||||||
protected $htmlListEndName = 'CheckedList'; // If you change the value, do not forget to change it also in the JS file
|
protected $htmlListEndName = 'CheckedList'; // If you change the value, do not forget to change it also in the JS file
|
||||||
|
|
||||||
protected $htmlListField = 'selected'; // If you change the value, do not forget to change it also in the JS file
|
protected $htmlListField = 'selected'; // If you change the value, do not forget to change it also in the JS file
|
||||||
|
|
||||||
public $template = 'RelationComplexTableField';
|
public $template = 'RelationComplexTableField';
|
||||||
|
|
||||||
public $itemClass = 'HasManyComplexTableField_Item';
|
public $itemClass = 'HasManyComplexTableField_Item';
|
||||||
|
|
||||||
protected $relationAutoSetting = false;
|
protected $relationAutoSetting = false;
|
||||||
|
|
||||||
function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
|
function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
|
||||||
|
|
||||||
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
|
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
|
||||||
|
|
||||||
$this->Markable = true;
|
$this->Markable = true;
|
||||||
|
|
||||||
$this->joinField = $this->getParentIdName($this->controller->ClassName, $this->sourceClass);
|
$this->joinField = $this->getParentIdName($this->controller->ClassName, $this->sourceClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQuery($limitClause = null) {
|
function getQuery($limitClause = null) {
|
||||||
if($this->customQuery) {
|
if($this->customQuery) {
|
||||||
$query = $this->customQuery;
|
$query = $this->customQuery;
|
||||||
$query->select[] = "{$this->sourceClass}.ID AS ID";
|
$query->select[] = "{$this->sourceClass}.ID AS ID";
|
||||||
$query->select[] = "{$this->sourceClass}.ClassName AS ClassName";
|
$query->select[] = "{$this->sourceClass}.ClassName AS ClassName";
|
||||||
$query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName";
|
$query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin);
|
$query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin);
|
||||||
|
|
||||||
// Add more selected fields if they are from joined table.
|
// Add more selected fields if they are from joined table.
|
||||||
|
|
||||||
$SNG = singleton($this->sourceClass);
|
$SNG = singleton($this->sourceClass);
|
||||||
foreach($this->FieldList() as $k => $title) {
|
foreach($this->FieldList() as $k => $title) {
|
||||||
if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k))
|
if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k))
|
||||||
$query->select[] = $k;
|
$query->select[] = $k;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return clone $query;
|
return clone $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sourceItems() {
|
function sourceItems() {
|
||||||
if($this->sourceItems)
|
if($this->sourceItems)
|
||||||
return $this->sourceItems;
|
return $this->sourceItems;
|
||||||
|
|
||||||
$limitClause = '';
|
$limitClause = '';
|
||||||
if(isset($_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ]) && is_numeric($_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ]))
|
if(isset($_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ]) && is_numeric($_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ]))
|
||||||
$limitClause = $_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ] . ", $this->pageSize";
|
$limitClause = $_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ] . ", $this->pageSize";
|
||||||
else
|
else
|
||||||
$limitClause = "0, $this->pageSize";
|
$limitClause = "0, $this->pageSize";
|
||||||
|
|
||||||
$dataQuery = $this->getQuery($limitClause);
|
$dataQuery = $this->getQuery($limitClause);
|
||||||
$records = $dataQuery->execute();
|
$records = $dataQuery->execute();
|
||||||
$items = new DataObjectSet();
|
$items = new DataObjectSet();
|
||||||
foreach($records as $record) {
|
foreach($records as $record) {
|
||||||
if(! get_class($record))
|
if(! get_class($record))
|
||||||
$record = new DataObject($record);
|
$record = new DataObject($record);
|
||||||
$items->push($record);
|
$items->push($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dataQuery = $this->getQuery();
|
$dataQuery = $this->getQuery();
|
||||||
$records = $dataQuery->execute();
|
$records = $dataQuery->execute();
|
||||||
$unpagedItems = new DataObjectSet();
|
$unpagedItems = new DataObjectSet();
|
||||||
foreach($records as $record) {
|
foreach($records as $record) {
|
||||||
if(! get_class($record))
|
if(! get_class($record))
|
||||||
$record = new DataObject($record);
|
$record = new DataObject($record);
|
||||||
$unpagedItems->push($record);
|
$unpagedItems->push($record);
|
||||||
}
|
}
|
||||||
$this->unpagedSourceItems = $unpagedItems;
|
$this->unpagedSourceItems = $unpagedItems;
|
||||||
|
|
||||||
$this->totalCount = ($this->unpagedSourceItems) ? $this->unpagedSourceItems->TotalItems() : null;
|
$this->totalCount = ($this->unpagedSourceItems) ? $this->unpagedSourceItems->TotalItems() : null;
|
||||||
|
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getControllerID() {
|
function getControllerID() {
|
||||||
return $this->controller->ID;
|
return $this->controller->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveInto(DataObject $record) {
|
function saveInto(DataObject $record) {
|
||||||
$fieldName = $this->name;
|
$fieldName = $this->name;
|
||||||
$saveDest = $record->$fieldName();
|
$saveDest = $record->$fieldName();
|
||||||
|
|
||||||
if(! $saveDest)
|
if(! $saveDest)
|
||||||
user_error("HasManyComplexTableField::saveInto() Field '$fieldName' not found on $record->class.$record->ID", E_USER_ERROR);
|
user_error("HasManyComplexTableField::saveInto() Field '$fieldName' not found on $record->class.$record->ID", E_USER_ERROR);
|
||||||
|
|
||||||
$items = array();
|
$items = array();
|
||||||
|
|
||||||
if($list = $this->value[ $this->htmlListField ]) {
|
if($list = $this->value[ $this->htmlListField ]) {
|
||||||
if($list != 'undefined')
|
if($list != 'undefined')
|
||||||
$items = explode(',', $list);
|
$items = explode(',', $list);
|
||||||
}
|
}
|
||||||
|
|
||||||
$saveDest->setByIDList($items);
|
$saveDest->setByIDList($items);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAddTitle($addTitle) {
|
function setAddTitle($addTitle) {
|
||||||
if(is_string($addTitle))
|
if(is_string($addTitle))
|
||||||
$this->addTitle = $addTitle;
|
$this->addTitle = $addTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Title() {
|
function Title() {
|
||||||
return $this->addTitle ? $this->addTitle : parent::Title();
|
return $this->addTitle ? $this->addTitle : parent::Title();
|
||||||
}
|
}
|
||||||
|
|
||||||
function ExtraData() {
|
function ExtraData() {
|
||||||
$items = array();
|
$items = array();
|
||||||
foreach($this->unpagedSourceItems as $item) {
|
foreach($this->unpagedSourceItems as $item) {
|
||||||
if($item->{$this->joinField} == $this->controller->ID)
|
if($item->{$this->joinField} == $this->controller->ID)
|
||||||
$items[] = $item->ID;
|
$items[] = $item->ID;
|
||||||
}
|
}
|
||||||
$list = implode(',', $items);
|
$list = implode(',', $items);
|
||||||
$inputId = $this->id() . '_' . $this->htmlListEndName;
|
$inputId = $this->id() . '_' . $this->htmlListEndName;
|
||||||
return <<<HTML
|
return <<<HTML
|
||||||
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$list"/>
|
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$list"/>
|
||||||
HTML;
|
HTML;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single record of a {@link HasManyComplexTableField} field.
|
* Single record of a {@link HasManyComplexTableField} field.
|
||||||
* @package forms
|
* @package forms
|
||||||
* @subpackage fields-relational
|
* @subpackage fields-relational
|
||||||
*/
|
*/
|
||||||
class HasManyComplexTableField_Item extends ComplexTableField_Item {
|
class HasManyComplexTableField_Item extends ComplexTableField_Item {
|
||||||
|
|
||||||
function MarkingCheckbox() {
|
function MarkingCheckbox() {
|
||||||
$name = $this->parent->Name() . '[]';
|
$name = $this->parent->Name() . '[]';
|
||||||
|
|
||||||
$joinVal = $this->item->{$this->parent->joinField};
|
$joinVal = $this->item->{$this->parent->joinField};
|
||||||
$parentID = $this->parent->getControllerID();
|
$parentID = $this->parent->getControllerID();
|
||||||
|
|
||||||
if($this->parent->IsReadOnly || ($joinVal > 0 && $joinVal != $parentID))
|
if($this->parent->IsReadOnly || ($joinVal > 0 && $joinVal != $parentID))
|
||||||
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
|
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
|
||||||
else if($joinVal == $parentID)
|
else if($joinVal == $parentID)
|
||||||
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
|
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
|
||||||
else
|
else
|
||||||
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>";
|
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -1,74 +1,74 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* ComplexTableField with a radio button column, designed to edit a has_one join.
|
* ComplexTableField with a radio button column, designed to edit a has_one join.
|
||||||
* @package forms
|
* @package forms
|
||||||
* @subpackage fields-relational
|
* @subpackage fields-relational
|
||||||
*/
|
*/
|
||||||
class HasOneComplexTableField extends HasManyComplexTableField {
|
class HasOneComplexTableField extends HasManyComplexTableField {
|
||||||
|
|
||||||
public $itemClass = 'HasOneComplexTableField_Item';
|
public $itemClass = 'HasOneComplexTableField_Item';
|
||||||
|
|
||||||
public $isOneToOne = false;
|
public $isOneToOne = false;
|
||||||
|
|
||||||
function getParentIdName($parentClass, $childClass) {
|
function getParentIdName($parentClass, $childClass) {
|
||||||
return $this->getParentIdNameRelation($parentClass, $childClass, 'has_one');
|
return $this->getParentIdNameRelation($parentClass, $childClass, 'has_one');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getControllerJoinID() {
|
function getControllerJoinID() {
|
||||||
return $this->controller->{$this->joinField};
|
return $this->controller->{$this->joinField};
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveInto(DataObject $record) {
|
function saveInto(DataObject $record) {
|
||||||
$fieldName = $this->name;
|
$fieldName = $this->name;
|
||||||
$fieldNameID = $fieldName . 'ID';
|
$fieldNameID = $fieldName . 'ID';
|
||||||
|
|
||||||
$record->$fieldNameID = 0;
|
$record->$fieldNameID = 0;
|
||||||
if($val = $this->value[ $this->htmlListField ]) {
|
if($val = $this->value[ $this->htmlListField ]) {
|
||||||
if($val != 'undefined')
|
if($val != 'undefined')
|
||||||
$record->$fieldNameID = $val;
|
$record->$fieldNameID = $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
$record->write();
|
$record->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setOneToOne() {
|
function setOneToOne() {
|
||||||
$this->isOneToOne = true;
|
$this->isOneToOne = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isChildSet($childID) {
|
function isChildSet($childID) {
|
||||||
return DataObject::get($this->controller->ClassName, '`' . $this->joinField . "` = '$childID'");
|
return DataObject::get($this->controller->ClassName, '`' . $this->joinField . "` = '$childID'");
|
||||||
}
|
}
|
||||||
|
|
||||||
function ExtraData() {
|
function ExtraData() {
|
||||||
$val = $this->getControllerJoinID() ? $this->getControllerJoinID() : '';
|
$val = $this->getControllerJoinID() ? $this->getControllerJoinID() : '';
|
||||||
$inputId = $this->id() . '_' . $this->htmlListEndName;
|
$inputId = $this->id() . '_' . $this->htmlListEndName;
|
||||||
return <<<HTML
|
return <<<HTML
|
||||||
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$val"/>
|
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$val"/>
|
||||||
HTML;
|
HTML;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single record of a {@link HasOneComplexTableField} field.
|
* Single record of a {@link HasOneComplexTableField} field.
|
||||||
* @package forms
|
* @package forms
|
||||||
* @subpackage fields-relational
|
* @subpackage fields-relational
|
||||||
*/
|
*/
|
||||||
class HasOneComplexTableField_Item extends ComplexTableField_Item {
|
class HasOneComplexTableField_Item extends ComplexTableField_Item {
|
||||||
|
|
||||||
function MarkingCheckbox() {
|
function MarkingCheckbox() {
|
||||||
$name = $this->parent->Name() . '[]';
|
$name = $this->parent->Name() . '[]';
|
||||||
|
|
||||||
$isOneToOne = $this->parent->isOneToOne;
|
$isOneToOne = $this->parent->isOneToOne;
|
||||||
$joinVal = $this->parent->getControllerJoinID();
|
$joinVal = $this->parent->getControllerJoinID();
|
||||||
$childID = $this->item->ID;
|
$childID = $this->item->ID;
|
||||||
|
|
||||||
if($this->parent->IsReadOnly || ($isOneToOne && $joinVal != $childID && $this->parent->isChildSet($childID)))
|
if($this->parent->IsReadOnly || ($isOneToOne && $joinVal != $childID && $this->parent->isChildSet($childID)))
|
||||||
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
|
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
|
||||||
else if($joinVal == $childID)
|
else if($joinVal == $childID)
|
||||||
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
|
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
|
||||||
else
|
else
|
||||||
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\"/>";
|
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\"/>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -1,105 +1,105 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Special ComplexTableField for editing a many_many relation.
|
* Special ComplexTableField for editing a many_many relation.
|
||||||
* @package forms
|
* @package forms
|
||||||
* @subpackage fields-relational
|
* @subpackage fields-relational
|
||||||
*/
|
*/
|
||||||
class ManyManyComplexTableField extends HasManyComplexTableField {
|
class ManyManyComplexTableField extends HasManyComplexTableField {
|
||||||
|
|
||||||
private $manyManyParentClass;
|
private $manyManyParentClass;
|
||||||
|
|
||||||
public $itemClass = 'ManyManyComplexTableField_Item';
|
public $itemClass = 'ManyManyComplexTableField_Item';
|
||||||
|
|
||||||
function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
|
function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") {
|
||||||
|
|
||||||
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
|
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin);
|
||||||
|
|
||||||
$classes = array_reverse(ClassInfo::ancestry($this->controller->ClassName));
|
$classes = array_reverse(ClassInfo::ancestry($this->controller->ClassName));
|
||||||
foreach($classes as $class) {
|
foreach($classes as $class) {
|
||||||
$singleton = singleton($class);
|
$singleton = singleton($class);
|
||||||
$manyManyRelations = $singleton->uninherited('many_many', true);
|
$manyManyRelations = $singleton->uninherited('many_many', true);
|
||||||
if(isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) {
|
if(isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) {
|
||||||
$this->manyManyParentClass = $class;
|
$this->manyManyParentClass = $class;
|
||||||
$manyManyTable = $class . '_' . $this->name;
|
$manyManyTable = $class . '_' . $this->name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$belongsManyManyRelations = $singleton->uninherited( 'belongs_many_many', true );
|
$belongsManyManyRelations = $singleton->uninherited( 'belongs_many_many', true );
|
||||||
if( isset( $belongsManyManyRelations ) && array_key_exists( $this->name, $belongsManyManyRelations ) ) {
|
if( isset( $belongsManyManyRelations ) && array_key_exists( $this->name, $belongsManyManyRelations ) ) {
|
||||||
$this->manyManyParentClass = $class;
|
$this->manyManyParentClass = $class;
|
||||||
$manyManyTable = $belongsManyManyRelations[$this->name] . '_' . $this->name;
|
$manyManyTable = $belongsManyManyRelations[$this->name] . '_' . $this->name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$tableClasses = ClassInfo::dataClassesFor($this->sourceClass);
|
$tableClasses = ClassInfo::dataClassesFor($this->sourceClass);
|
||||||
$source = array_shift($tableClasses);
|
$source = array_shift($tableClasses);
|
||||||
$sourceField = $this->sourceClass;
|
$sourceField = $this->sourceClass;
|
||||||
if($this->manyManyParentClass == $sourceField)
|
if($this->manyManyParentClass == $sourceField)
|
||||||
$sourceField = 'Child';
|
$sourceField = 'Child';
|
||||||
$parentID = $this->controller->ID;
|
$parentID = $this->controller->ID;
|
||||||
|
|
||||||
$this->sourceJoin .= " LEFT JOIN `$manyManyTable` ON (`$source`.`ID` = `{$sourceField}ID` AND `{$this->manyManyParentClass}ID` = '$parentID')";
|
$this->sourceJoin .= " LEFT JOIN `$manyManyTable` ON (`$source`.`ID` = `{$sourceField}ID` AND `{$this->manyManyParentClass}ID` = '$parentID')";
|
||||||
|
|
||||||
$this->joinField = 'Checked';
|
$this->joinField = 'Checked';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQuery($limitClause = null) {
|
function getQuery($limitClause = null) {
|
||||||
if($this->customQuery) {
|
if($this->customQuery) {
|
||||||
$query = $this->customQuery;
|
$query = $this->customQuery;
|
||||||
$query->select[] = "{$this->sourceClass}.ID AS ID";
|
$query->select[] = "{$this->sourceClass}.ID AS ID";
|
||||||
$query->select[] = "{$this->sourceClass}.ClassName AS ClassName";
|
$query->select[] = "{$this->sourceClass}.ClassName AS ClassName";
|
||||||
$query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName";
|
$query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin);
|
$query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin);
|
||||||
|
|
||||||
// Add more selected fields if they are from joined table.
|
// Add more selected fields if they are from joined table.
|
||||||
|
|
||||||
$SNG = singleton($this->sourceClass);
|
$SNG = singleton($this->sourceClass);
|
||||||
foreach($this->FieldList() as $k => $title) {
|
foreach($this->FieldList() as $k => $title) {
|
||||||
if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k))
|
if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k))
|
||||||
$query->select[] = $k;
|
$query->select[] = $k;
|
||||||
}
|
}
|
||||||
$parent = $this->controller->ClassName;
|
$parent = $this->controller->ClassName;
|
||||||
$query->select[] = "IF(`{$this->manyManyParentClass}ID` IS NULL, '0', '1') AS Checked";
|
$query->select[] = "IF(`{$this->manyManyParentClass}ID` IS NULL, '0', '1') AS Checked";
|
||||||
}
|
}
|
||||||
return clone $query;
|
return clone $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getParentIdName($parentClass, $childClass) {
|
function getParentIdName($parentClass, $childClass) {
|
||||||
return $this->getParentIdNameRelation($parentClass, $childClass, 'many_many');
|
return $this->getParentIdNameRelation($parentClass, $childClass, 'many_many');
|
||||||
}
|
}
|
||||||
|
|
||||||
function ExtraData() {
|
function ExtraData() {
|
||||||
$items = array();
|
$items = array();
|
||||||
foreach($this->unpagedSourceItems as $item) {
|
foreach($this->unpagedSourceItems as $item) {
|
||||||
if($item->{$this->joinField})
|
if($item->{$this->joinField})
|
||||||
$items[] = $item->ID;
|
$items[] = $item->ID;
|
||||||
}
|
}
|
||||||
$list = implode(',', $items);
|
$list = implode(',', $items);
|
||||||
$inputId = $this->id() . '_' . $this->htmlListEndName;
|
$inputId = $this->id() . '_' . $this->htmlListEndName;
|
||||||
return <<<HTML
|
return <<<HTML
|
||||||
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$list"/>
|
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$list"/>
|
||||||
HTML;
|
HTML;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One record in a {@link ManyManyComplexTableField}.
|
* One record in a {@link ManyManyComplexTableField}.
|
||||||
* @package forms
|
* @package forms
|
||||||
* @subpackage fields-relational
|
* @subpackage fields-relational
|
||||||
*/
|
*/
|
||||||
class ManyManyComplexTableField_Item extends ComplexTableField_Item {
|
class ManyManyComplexTableField_Item extends ComplexTableField_Item {
|
||||||
|
|
||||||
function MarkingCheckbox() {
|
function MarkingCheckbox() {
|
||||||
$name = $this->parent->Name() . '[]';
|
$name = $this->parent->Name() . '[]';
|
||||||
|
|
||||||
if($this->parent->IsReadOnly)
|
if($this->parent->IsReadOnly)
|
||||||
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
|
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
|
||||||
else if($this->item->{$this->parent->joinField})
|
else if($this->item->{$this->parent->joinField})
|
||||||
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
|
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
|
||||||
else
|
else
|
||||||
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>";
|
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,100 +1,100 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* ReadonlyField with added toggle-capabilities - will preview the first sentence of the contained text-value,
|
* ReadonlyField with added toggle-capabilities - will preview the first sentence of the contained text-value,
|
||||||
* and show the full content by a javascript-switch.
|
* and show the full content by a javascript-switch.
|
||||||
*
|
*
|
||||||
* Caution: Strips HTML-encoding for the preview.
|
* Caution: Strips HTML-encoding for the preview.
|
||||||
* @package forms
|
* @package forms
|
||||||
* @subpackage fields-dataless
|
* @subpackage fields-dataless
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ToggleField extends ReadonlyField {
|
class ToggleField extends ReadonlyField {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var $labelMore string Text shown as a link to see the full content of the field
|
* @var $labelMore string Text shown as a link to see the full content of the field
|
||||||
*/
|
*/
|
||||||
public $labelMore;
|
public $labelMore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var $labelLess string Text shown as a link to see the partial view of the field content
|
* @var $labelLess string Text shown as a link to see the partial view of the field content
|
||||||
*/
|
*/
|
||||||
public $labelLess;
|
public $labelLess;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var $truncateMethod string (FirstSentence|FirstParagraph) @see {Text}
|
* @var $truncateMethod string (FirstSentence|FirstParagraph) @see {Text}
|
||||||
*/
|
*/
|
||||||
public $truncateMethod = 'FirstSentence';
|
public $truncateMethod = 'FirstSentence';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var $truncateChars int Number of chars to preview (optional).
|
* @var $truncateChars int Number of chars to preview (optional).
|
||||||
* Truncating will be applied with $truncateMethod by default.
|
* Truncating will be applied with $truncateMethod by default.
|
||||||
*/
|
*/
|
||||||
public $truncateChars;
|
public $truncateChars;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name The field name
|
* @param name The field name
|
||||||
* @param title The field title
|
* @param title The field title
|
||||||
* @param value The current value
|
* @param value The current value
|
||||||
*/
|
*/
|
||||||
function __construct($name, $title = "", $value = "") {
|
function __construct($name, $title = "", $value = "") {
|
||||||
$this->labelMore = _t('ToggleField.MORE', 'more');
|
$this->labelMore = _t('ToggleField.MORE', 'more');
|
||||||
$this->labelLess = _t('ToggleField.LESS', 'less');
|
$this->labelLess = _t('ToggleField.LESS', 'less');
|
||||||
|
|
||||||
$this->startClosed(true);
|
$this->startClosed(true);
|
||||||
|
|
||||||
parent::__construct($name, $title, $value);
|
parent::__construct($name, $title, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Field() {
|
function Field() {
|
||||||
$content = '';
|
$content = '';
|
||||||
|
|
||||||
Requirements::javascript("jsparty/prototype.js");
|
Requirements::javascript("jsparty/prototype.js");
|
||||||
Requirements::javascript("jsparty/behaviour.js");
|
Requirements::javascript("jsparty/behaviour.js");
|
||||||
Requirements::javascript("jsparty/prototype_improvements.js");
|
Requirements::javascript("jsparty/prototype_improvements.js");
|
||||||
Requirements::javascript("sapphire/javascript/ToggleField.js");
|
Requirements::javascript("sapphire/javascript/ToggleField.js");
|
||||||
|
|
||||||
if($this->startClosed) $this->addExtraClass('startClosed');
|
if($this->startClosed) $this->addExtraClass('startClosed');
|
||||||
|
|
||||||
$valforInput = $this->value ? Convert::raw2att($this->value) : "";
|
$valforInput = $this->value ? Convert::raw2att($this->value) : "";
|
||||||
$rawInput = Convert::html2raw($valforInput);
|
$rawInput = Convert::html2raw($valforInput);
|
||||||
|
|
||||||
if($this->charNum) $reducedVal = substr($rawInput,0,$this->charNum);
|
if($this->charNum) $reducedVal = substr($rawInput,0,$this->charNum);
|
||||||
else $reducedVal = DBField::create('Text',$rawInput)->{$this->truncateMethod}();
|
else $reducedVal = DBField::create('Text',$rawInput)->{$this->truncateMethod}();
|
||||||
|
|
||||||
// only create togglefield if the truncated content is shorter
|
// only create togglefield if the truncated content is shorter
|
||||||
if(strlen($reducedVal) < strlen($rawInput)) {
|
if(strlen($reducedVal) < strlen($rawInput)) {
|
||||||
$content = <<<HTML
|
$content = <<<HTML
|
||||||
<div class="readonly typography contentLess" style="display: none">
|
<div class="readonly typography contentLess" style="display: none">
|
||||||
$reducedVal
|
$reducedVal
|
||||||
<a href="#" class="triggerMore">$this->labelMore</a>
|
<a href="#" class="triggerMore">$this->labelMore</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="readonly typography contentMore">
|
<div class="readonly typography contentMore">
|
||||||
$this->value
|
$this->value
|
||||||
<a href="#" class="triggerLess">$this->labelLess</a>
|
<a href="#" class="triggerLess">$this->labelLess</a>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<input type="hidden" name="$this->name" value="$valforInput" />
|
<input type="hidden" name="$this->name" value="$valforInput" />
|
||||||
HTML;
|
HTML;
|
||||||
} else {
|
} else {
|
||||||
$this->dontEscape = true;
|
$this->dontEscape = true;
|
||||||
$content = parent::Field();
|
$content = parent::Field();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the field should render open or closed by default.
|
* Determines if the field should render open or closed by default.
|
||||||
*
|
*
|
||||||
* @param boolean
|
* @param boolean
|
||||||
*/
|
*/
|
||||||
public function startClosed($bool) {
|
public function startClosed($bool) {
|
||||||
($bool) ? $this->addExtraClass('startClosed') : $this->removeExtraClass('startClosed');
|
($bool) ? $this->addExtraClass('startClosed') : $this->removeExtraClass('startClosed');
|
||||||
}
|
}
|
||||||
|
|
||||||
function Type() {
|
function Type() {
|
||||||
return "toggleField";
|
return "toggleField";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -244,7 +244,7 @@ $lang['ru_RU']['SiteTree']['METAPAGEPRIO'] = 'Приоритет страниц
|
|||||||
$lang['ru_RU']['SiteTree']['METATITLE'] = 'Заголовок';
|
$lang['ru_RU']['SiteTree']['METATITLE'] = 'Заголовок';
|
||||||
$lang['ru_RU']['SiteTree']['MODIFIEDONDRAFT'] = 'Изменено на черновом сайте';
|
$lang['ru_RU']['SiteTree']['MODIFIEDONDRAFT'] = 'Изменено на черновом сайте';
|
||||||
$lang['ru_RU']['SiteTree']['NOBACKLINKS'] = 'На эту страницу нет ссылок с других страниц';
|
$lang['ru_RU']['SiteTree']['NOBACKLINKS'] = 'На эту страницу нет ссылок с других страниц';
|
||||||
$lang['ru_RU']['SiteTree']['NOTEUSEASHOMEPAGE'] = 'Использовать эту страницу в качестве домашней для следующих доменов:
|
$lang['ru_RU']['SiteTree']['NOTEUSEASHOMEPAGE'] = 'Использовать эту страницу в качестве домашней для следующих доменов:
|
||||||
(несколько доменов разделяйте запятыми)';
|
(несколько доменов разделяйте запятыми)';
|
||||||
$lang['ru_RU']['SiteTree']['PAGESLINKING'] = 'На эту страницу ссылаются следующие страницы:';
|
$lang['ru_RU']['SiteTree']['PAGESLINKING'] = 'На эту страницу ссылаются следующие страницы:';
|
||||||
$lang['ru_RU']['SiteTree']['PAGETITLE'] = 'Название страницы';
|
$lang['ru_RU']['SiteTree']['PAGETITLE'] = 'Название страницы';
|
||||||
|
@ -1,116 +1,116 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once('HTML/HTMLBBCodeParser.php');
|
require_once('HTML/HTMLBBCodeParser.php');
|
||||||
/*Seting up the PEAR bbcode parser*/
|
/*Seting up the PEAR bbcode parser*/
|
||||||
$config = parse_ini_file('BBCodeParser.ini', true);
|
$config = parse_ini_file('BBCodeParser.ini', true);
|
||||||
$options = &SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
|
$options = &SSHTMLBBCodeParser::getStaticProperty('SSHTMLBBCodeParser', '_options');
|
||||||
$options = $config['SSHTMLBBCodeParser'];
|
$options = $config['SSHTMLBBCodeParser'];
|
||||||
//Debug::show($options);
|
//Debug::show($options);
|
||||||
unset($options);
|
unset($options);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BBCode parser object.
|
* BBCode parser object.
|
||||||
* Use on a text field in a template with $Content.Parse(BBCodeParser).
|
* Use on a text field in a template with $Content.Parse(BBCodeParser).
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage misc
|
* @subpackage misc
|
||||||
*/
|
*/
|
||||||
class BBCodeParser extends TextParser {
|
class BBCodeParser extends TextParser {
|
||||||
|
|
||||||
protected static $autolinkUrls = true;
|
protected static $autolinkUrls = true;
|
||||||
|
|
||||||
static function autolinkUrls() {
|
static function autolinkUrls() {
|
||||||
return (self::$autolinkUrls != null) ? true : false;
|
return (self::$autolinkUrls != null) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function disable_autolink_urls($autolink = false) {
|
static function disable_autolink_urls($autolink = false) {
|
||||||
BBCodeParser::$autolinkUrls = $autolink;
|
BBCodeParser::$autolinkUrls = $autolink;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function usable_tags() {
|
static function usable_tags() {
|
||||||
return new DataObjectSet(
|
return new DataObjectSet(
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.BOLD', 'Bold Text'),
|
"Title" => _t('BBCodeParser.BOLD', 'Bold Text'),
|
||||||
"Example" => '[b]<b>'._t('BBCodeParser.BOLDEXAMPLE', 'Bold').'</b>[/b]'
|
"Example" => '[b]<b>'._t('BBCodeParser.BOLDEXAMPLE', 'Bold').'</b>[/b]'
|
||||||
)),
|
)),
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.ITALIC', 'Italic Text'),
|
"Title" => _t('BBCodeParser.ITALIC', 'Italic Text'),
|
||||||
"Example" => '[i]<i>'._t('BBCodeParser.ITALICEXAMPLE', 'Italics').'</i>[/i]'
|
"Example" => '[i]<i>'._t('BBCodeParser.ITALICEXAMPLE', 'Italics').'</i>[/i]'
|
||||||
)),
|
)),
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.UNDERLINE', 'Underlined Text'),
|
"Title" => _t('BBCodeParser.UNDERLINE', 'Underlined Text'),
|
||||||
"Example" => '[u]<u>'._t('BBCodeParser.UNDERLINEEXAMPLE', 'Underlined').'</u>[/u]'
|
"Example" => '[u]<u>'._t('BBCodeParser.UNDERLINEEXAMPLE', 'Underlined').'</u>[/u]'
|
||||||
)),
|
)),
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.STRUCK', 'Struck-out Text'),
|
"Title" => _t('BBCodeParser.STRUCK', 'Struck-out Text'),
|
||||||
"Example" => '[s]<s>'._t('BBCodeParser.STRUCKEXAMPLE', 'Struck-out').'</s>[/s]'
|
"Example" => '[s]<s>'._t('BBCodeParser.STRUCKEXAMPLE', 'Struck-out').'</s>[/s]'
|
||||||
)),
|
)),
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.COLORED', 'Colored text'),
|
"Title" => _t('BBCodeParser.COLORED', 'Colored text'),
|
||||||
"Example" => '[color=blue]'._t('BBCodeParser.COLOREDEXAMPLE', 'blue text').'[/color]'
|
"Example" => '[color=blue]'._t('BBCodeParser.COLOREDEXAMPLE', 'blue text').'[/color]'
|
||||||
)),
|
)),
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.ALIGNEMENT', 'Alignment'),
|
"Title" => _t('BBCodeParser.ALIGNEMENT', 'Alignment'),
|
||||||
"Example" => '[align=right]'._t('BBCodeParser.ALIGNEMENTEXAMPLE', 'right aligned').'[/align]'
|
"Example" => '[align=right]'._t('BBCodeParser.ALIGNEMENTEXAMPLE', 'right aligned').'[/align]'
|
||||||
)),
|
)),
|
||||||
|
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.LINK', 'Website link'),
|
"Title" => _t('BBCodeParser.LINK', 'Website link'),
|
||||||
"Description" => _t('BBCodeParser.LINKDESCRIPTION', 'Link to another website or URL'),
|
"Description" => _t('BBCodeParser.LINKDESCRIPTION', 'Link to another website or URL'),
|
||||||
"Example" => '[url]http://www.website.com/[/url]'
|
"Example" => '[url]http://www.website.com/[/url]'
|
||||||
)),
|
)),
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.LINK', 'Website link'),
|
"Title" => _t('BBCodeParser.LINK', 'Website link'),
|
||||||
"Description" => _t('BBCodeParser.LINKDESCRIPTION', 'Link to another website or URL'),
|
"Description" => _t('BBCodeParser.LINKDESCRIPTION', 'Link to another website or URL'),
|
||||||
"Example" => "[url=http://www.website.com/]Some website[/url]"
|
"Example" => "[url=http://www.website.com/]Some website[/url]"
|
||||||
)),
|
)),
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.EMAILLINK', 'Email link'),
|
"Title" => _t('BBCodeParser.EMAILLINK', 'Email link'),
|
||||||
"Description" => _t('BBCodeParser.EMAILLINKDESCRIPTION', 'Create link to an email address'),
|
"Description" => _t('BBCodeParser.EMAILLINKDESCRIPTION', 'Create link to an email address'),
|
||||||
"Example" => "[email]you@yoursite.com[/email]"
|
"Example" => "[email]you@yoursite.com[/email]"
|
||||||
)),
|
)),
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.EMAILLINK', 'Email link'),
|
"Title" => _t('BBCodeParser.EMAILLINK', 'Email link'),
|
||||||
"Description" => _t('BBCodeParser.EMAILLINKDESCRIPTION', 'Create link to an email address'),
|
"Description" => _t('BBCodeParser.EMAILLINKDESCRIPTION', 'Create link to an email address'),
|
||||||
"Example" => "[email=you@yoursite.com]email me[/email]"
|
"Example" => "[email=you@yoursite.com]email me[/email]"
|
||||||
)),
|
)),
|
||||||
|
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.IMAGE', 'Image'),
|
"Title" => _t('BBCodeParser.IMAGE', 'Image'),
|
||||||
"Description" => _t('BBCodeParser.IMAGEDESCRIPTION', 'Show an image in your post'),
|
"Description" => _t('BBCodeParser.IMAGEDESCRIPTION', 'Show an image in your post'),
|
||||||
"Example" => "[img]http://www.website.com/image.jpg[/img]"
|
"Example" => "[img]http://www.website.com/image.jpg[/img]"
|
||||||
)),
|
)),
|
||||||
|
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.CODE', 'Code Block'),
|
"Title" => _t('BBCodeParser.CODE', 'Code Block'),
|
||||||
"Description" => _t('BBCodeParser.CODEDESCRIPTION', 'Unformatted code block'),
|
"Description" => _t('BBCodeParser.CODEDESCRIPTION', 'Unformatted code block'),
|
||||||
"Example" => '[code]'._t('BBCodeParser.CODEEXAMPLE', 'Code block').'[/code]'
|
"Example" => '[code]'._t('BBCodeParser.CODEEXAMPLE', 'Code block').'[/code]'
|
||||||
)),
|
)),
|
||||||
new ArrayData(array(
|
new ArrayData(array(
|
||||||
"Title" => _t('BBCodeParser.UNORDERED', 'Unordered list'),
|
"Title" => _t('BBCodeParser.UNORDERED', 'Unordered list'),
|
||||||
"Description" => _t('BBCodeParser.UNORDEREDDESCRIPTION', 'Unordered list'),
|
"Description" => _t('BBCodeParser.UNORDEREDDESCRIPTION', 'Unordered list'),
|
||||||
"Example" => '[ulist][*]'._t('BBCodeParser.UNORDEREDEXAMPLE1', 'unordered item 1').'[*]'._t('BBCodeParser.UNORDEREDEXAMPLE2', 'unordered item 2').'[/ulist]'
|
"Example" => '[ulist][*]'._t('BBCodeParser.UNORDEREDEXAMPLE1', 'unordered item 1').'[*]'._t('BBCodeParser.UNORDEREDEXAMPLE2', 'unordered item 2').'[/ulist]'
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function useable_tagsHTML(){
|
function useable_tagsHTML(){
|
||||||
$useabletags = "<ul class='bbcodeExamples'>";
|
$useabletags = "<ul class='bbcodeExamples'>";
|
||||||
foreach($this->usable_tags()->toArray() as $tag){
|
foreach($this->usable_tags()->toArray() as $tag){
|
||||||
$useabletags = $useabletags."<li><span>".$tag->Example."</span></li>";
|
$useabletags = $useabletags."<li><span>".$tag->Example."</span></li>";
|
||||||
}
|
}
|
||||||
return $useabletags."</ul>";
|
return $useabletags."</ul>";
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse() {
|
function parse() {
|
||||||
$this->content = str_replace(array('&', '<', '>'), array('&', '<', '>'), $this->content);
|
$this->content = str_replace(array('&', '<', '>'), array('&', '<', '>'), $this->content);
|
||||||
$this->content = SSHTMLBBCodeParser::staticQparse($this->content);
|
$this->content = SSHTMLBBCodeParser::staticQparse($this->content);
|
||||||
$this->content = "<p>".$this->content."</p>";
|
$this->content = "<p>".$this->content."</p>";
|
||||||
$this->content = preg_replace("/\n\s*\n/", "</p><p>", $this->content);
|
$this->content = preg_replace("/\n\s*\n/", "</p><p>", $this->content);
|
||||||
$this->content = str_replace("\n", "<br />", $this->content);
|
$this->content = str_replace("\n", "<br />", $this->content);
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -1,53 +1,53 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Parses text in a variety of ways.
|
* Parses text in a variety of ways.
|
||||||
*
|
*
|
||||||
* Called from a template by $Content.Parse(SubClassName), similar to $Content.XML.
|
* Called from a template by $Content.Parse(SubClassName), similar to $Content.XML.
|
||||||
* This will work on any Text database field (Or a sub-class, such as HTMLText,
|
* This will work on any Text database field (Or a sub-class, such as HTMLText,
|
||||||
* although it's usefulness in this situation is more limited).
|
* although it's usefulness in this situation is more limited).
|
||||||
*
|
*
|
||||||
* Any sub-classes of TextParser must implement a parse() method.
|
* Any sub-classes of TextParser must implement a parse() method.
|
||||||
* This should take $this->content and parse it however you want. For an example
|
* This should take $this->content and parse it however you want. For an example
|
||||||
* of the implementation, @see BBCodeParser.
|
* of the implementation, @see BBCodeParser.
|
||||||
*
|
*
|
||||||
* Your sub-class will be initialized with a string of text, then parse() will be called.
|
* Your sub-class will be initialized with a string of text, then parse() will be called.
|
||||||
* parse() should (after processing) return the formatted string.
|
* parse() should (after processing) return the formatted string.
|
||||||
*
|
*
|
||||||
* Note: $this->content will have NO conversions applied to it.
|
* Note: $this->content will have NO conversions applied to it.
|
||||||
* You should run Covert::raw2xml or whatever is appropriate before using it.
|
* You should run Covert::raw2xml or whatever is appropriate before using it.
|
||||||
*
|
*
|
||||||
* Optionally (but recommended), is creating a static usable_tags method,
|
* Optionally (but recommended), is creating a static usable_tags method,
|
||||||
* which will return a DataObjectSet of all the usable tags that can be parsed.
|
* which will return a DataObjectSet of all the usable tags that can be parsed.
|
||||||
* This will (mostly) be used to create helper blocks - telling users what things will be parsed.
|
* This will (mostly) be used to create helper blocks - telling users what things will be parsed.
|
||||||
* Again, @see BBCodeParser for an example of the syntax
|
* Again, @see BBCodeParser for an example of the syntax
|
||||||
*
|
*
|
||||||
* @todo Define a proper syntax for (or refactor) usable_tags that can be extended as needed.
|
* @todo Define a proper syntax for (or refactor) usable_tags that can be extended as needed.
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage misc
|
* @subpackage misc
|
||||||
*/
|
*/
|
||||||
abstract class TextParser extends Object {
|
abstract class TextParser extends Object {
|
||||||
protected $content;
|
protected $content;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new TextParser object.
|
* Creates a new TextParser object.
|
||||||
*
|
*
|
||||||
* @param string $content The contents of the dbfield
|
* @param string $content The contents of the dbfield
|
||||||
*/
|
*/
|
||||||
function __construct($content = "") {
|
function __construct($content = "") {
|
||||||
$this->content = $content;
|
$this->content = $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method, shouldn't really be used, but it's here if you want it
|
* Convenience method, shouldn't really be used, but it's here if you want it
|
||||||
*/
|
*/
|
||||||
function setContent($content = "") {
|
function setContent($content = "") {
|
||||||
$this->content = $content;
|
$this->content = $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define your own parse method to parse $this->content appropriately.
|
* Define your own parse method to parse $this->content appropriately.
|
||||||
* See the class doc-block for more implementation details.
|
* See the class doc-block for more implementation details.
|
||||||
*/
|
*/
|
||||||
abstract function parse();
|
abstract function parse();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -1,207 +1,207 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Log-in form for the "member" authentication method
|
* Log-in form for the "member" authentication method
|
||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage security
|
* @subpackage security
|
||||||
*/
|
*/
|
||||||
class MemberLoginForm extends LoginForm {
|
class MemberLoginForm extends LoginForm {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param Controller $controller The parent controller, necessary to
|
* @param Controller $controller The parent controller, necessary to
|
||||||
* create the appropriate form action tag.
|
* create the appropriate form action tag.
|
||||||
* @param string $name The method on the controller that will return this
|
* @param string $name The method on the controller that will return this
|
||||||
* form object.
|
* form object.
|
||||||
* @param FieldSet|FormField $fields All of the fields in the form - a
|
* @param FieldSet|FormField $fields All of the fields in the form - a
|
||||||
* {@link FieldSet} of {@link FormField}
|
* {@link FieldSet} of {@link FormField}
|
||||||
* objects.
|
* objects.
|
||||||
* @param FieldSet|FormAction $actions All of the action buttons in the
|
* @param FieldSet|FormAction $actions All of the action buttons in the
|
||||||
* form - a {@link FieldSet} of
|
* form - a {@link FieldSet} of
|
||||||
* {@link FormAction} objects
|
* {@link FormAction} objects
|
||||||
* @param bool $checkCurrentUser If set to TRUE, it will be checked if a
|
* @param bool $checkCurrentUser If set to TRUE, it will be checked if a
|
||||||
* the user is currently logged in, and if
|
* the user is currently logged in, and if
|
||||||
* so, only a logout button will be rendered
|
* so, only a logout button will be rendered
|
||||||
*/
|
*/
|
||||||
function __construct($controller, $name, $fields = null, $actions = null,
|
function __construct($controller, $name, $fields = null, $actions = null,
|
||||||
$checkCurrentUser = true) {
|
$checkCurrentUser = true) {
|
||||||
|
|
||||||
$this->authenticator_class = 'MemberAuthenticator';
|
$this->authenticator_class = 'MemberAuthenticator';
|
||||||
|
|
||||||
$customCSS = project() . '/css/member_login.css';
|
$customCSS = project() . '/css/member_login.css';
|
||||||
if(Director::fileExists($customCSS)) {
|
if(Director::fileExists($customCSS)) {
|
||||||
Requirements::css($customCSS);
|
Requirements::css($customCSS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_REQUEST['BackURL'])) {
|
if(isset($_REQUEST['BackURL'])) {
|
||||||
$backURL = $_REQUEST['BackURL'];
|
$backURL = $_REQUEST['BackURL'];
|
||||||
} else {
|
} else {
|
||||||
$backURL = Session::get('BackURL');
|
$backURL = Session::get('BackURL');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($checkCurrentUser && Member::currentUserID()) {
|
if($checkCurrentUser && Member::currentUserID()) {
|
||||||
$fields = new FieldSet();
|
$fields = new FieldSet();
|
||||||
$actions = new FieldSet(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
|
$actions = new FieldSet(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
|
||||||
} else {
|
} else {
|
||||||
if(!$fields) {
|
if(!$fields) {
|
||||||
$fields = new FieldSet(
|
$fields = new FieldSet(
|
||||||
new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this),
|
new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this),
|
||||||
new TextField("Email", _t('Member.EMAIL'),
|
new TextField("Email", _t('Member.EMAIL'),
|
||||||
Session::get('SessionForms.MemberLoginForm.Email'), null, $this),
|
Session::get('SessionForms.MemberLoginForm.Email'), null, $this),
|
||||||
new EncryptField("Password", _t('Member.PASSWORD'), null, $this),
|
new EncryptField("Password", _t('Member.PASSWORD'), null, $this),
|
||||||
new CheckboxField("Remember", _t('Member.REMEMBERME', "Remember me next time?"),
|
new CheckboxField("Remember", _t('Member.REMEMBERME', "Remember me next time?"),
|
||||||
Session::get('SessionForms.MemberLoginForm.Remember'), $this)
|
Session::get('SessionForms.MemberLoginForm.Remember'), $this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if(!$actions) {
|
if(!$actions) {
|
||||||
$actions = new FieldSet(
|
$actions = new FieldSet(
|
||||||
new FormAction("dologin", _t('Member.BUTTONLOGIN', "Log in")),
|
new FormAction("dologin", _t('Member.BUTTONLOGIN', "Log in")),
|
||||||
new FormAction("forgotPassword", _t('Member.BUTTONLOSTPASSWORD', "I've lost my password"))
|
new FormAction("forgotPassword", _t('Member.BUTTONLOSTPASSWORD', "I've lost my password"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($backURL)) {
|
if(isset($backURL)) {
|
||||||
$fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
|
$fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($controller, $name, $fields, $actions);
|
parent::__construct($controller, $name, $fields, $actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get message from session
|
* Get message from session
|
||||||
*/
|
*/
|
||||||
protected function getMessageFromSession() {
|
protected function getMessageFromSession() {
|
||||||
parent::getMessageFromSession();
|
parent::getMessageFromSession();
|
||||||
if(($member = Member::currentUser()) &&
|
if(($member = Member::currentUser()) &&
|
||||||
!Session::get('MemberLoginForm.force_message')) {
|
!Session::get('MemberLoginForm.force_message')) {
|
||||||
$this->message = sprintf(_t('Member.LOGGEDINAS', "You're logged in as %s."), $member->FirstName);
|
$this->message = sprintf(_t('Member.LOGGEDINAS', "You're logged in as %s."), $member->FirstName);
|
||||||
}
|
}
|
||||||
Session::set('MemberLoginForm.force_message', false);
|
Session::set('MemberLoginForm.force_message', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login form handler method
|
* Login form handler method
|
||||||
*
|
*
|
||||||
* This method is called when the user clicks on "Log in"
|
* This method is called when the user clicks on "Log in"
|
||||||
*
|
*
|
||||||
* @param array $data Submitted data
|
* @param array $data Submitted data
|
||||||
*/
|
*/
|
||||||
public function dologin($data) {
|
public function dologin($data) {
|
||||||
if($this->performLogin($data)) {
|
if($this->performLogin($data)) {
|
||||||
Session::clear('SessionForms.MemberLoginForm.Email');
|
Session::clear('SessionForms.MemberLoginForm.Email');
|
||||||
Session::clear('SessionForms.MemberLoginForm.Remember');
|
Session::clear('SessionForms.MemberLoginForm.Remember');
|
||||||
|
|
||||||
if(Member::currentUser()->isPasswordExpired()) {
|
if(Member::currentUser()->isPasswordExpired()) {
|
||||||
if(isset($_REQUEST['BackURL']) && $backURL = $_REQUEST['BackURL']) {
|
if(isset($_REQUEST['BackURL']) && $backURL = $_REQUEST['BackURL']) {
|
||||||
Session::set('BackURL', $backURL);
|
Session::set('BackURL', $backURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cp = new ChangePasswordForm($this->controller, 'ChangePasswordForm');
|
$cp = new ChangePasswordForm($this->controller, 'ChangePasswordForm');
|
||||||
$cp->sessionMessage('Your password has expired. Please choose a new one.', 'good');
|
$cp->sessionMessage('Your password has expired. Please choose a new one.', 'good');
|
||||||
|
|
||||||
Director::redirect('Security/changepassword');
|
Director::redirect('Security/changepassword');
|
||||||
|
|
||||||
|
|
||||||
} else if(isset($_REQUEST['BackURL']) && $backURL = $_REQUEST['BackURL']) {
|
} else if(isset($_REQUEST['BackURL']) && $backURL = $_REQUEST['BackURL']) {
|
||||||
Session::clear("BackURL");
|
Session::clear("BackURL");
|
||||||
Director::redirect($backURL);
|
Director::redirect($backURL);
|
||||||
} else {
|
} else {
|
||||||
Director::redirect(Security::default_login_dest());
|
Director::redirect(Security::default_login_dest());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Session::set('SessionForms.MemberLoginForm.Email', $data['Email']);
|
Session::set('SessionForms.MemberLoginForm.Email', $data['Email']);
|
||||||
Session::set('SessionForms.MemberLoginForm.Remember', isset($data['Remember']));
|
Session::set('SessionForms.MemberLoginForm.Remember', isset($data['Remember']));
|
||||||
|
|
||||||
if(isset($_REQUEST['BackURL']) && $backURL = $_REQUEST['BackURL']) {
|
if(isset($_REQUEST['BackURL']) && $backURL = $_REQUEST['BackURL']) {
|
||||||
Session::set('BackURL', $backURL);
|
Session::set('BackURL', $backURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($badLoginURL = Session::get("BadLoginURL")) {
|
if($badLoginURL = Session::get("BadLoginURL")) {
|
||||||
Director::redirect($badLoginURL);
|
Director::redirect($badLoginURL);
|
||||||
} else {
|
} else {
|
||||||
// Show the right tab on failed login
|
// Show the right tab on failed login
|
||||||
Director::redirect(Director::absoluteURL(Security::Link("login")) .
|
Director::redirect(Director::absoluteURL(Security::Link("login")) .
|
||||||
'#' . $this->FormName() .'_tab');
|
'#' . $this->FormName() .'_tab');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log out form handler method
|
* Log out form handler method
|
||||||
*
|
*
|
||||||
* This method is called when the user clicks on "logout" on the form
|
* This method is called when the user clicks on "logout" on the form
|
||||||
* created when the parameter <i>$checkCurrentUser</i> of the
|
* created when the parameter <i>$checkCurrentUser</i> of the
|
||||||
* {@link __construct constructor} was set to TRUE and the user was
|
* {@link __construct constructor} was set to TRUE and the user was
|
||||||
* currently logged in.
|
* currently logged in.
|
||||||
*/
|
*/
|
||||||
public function logout() {
|
public function logout() {
|
||||||
$s = new Security();
|
$s = new Security();
|
||||||
$s->logout();
|
$s->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to authenticate the user
|
* Try to authenticate the user
|
||||||
*
|
*
|
||||||
* @param array Submitted data
|
* @param array Submitted data
|
||||||
* @return Member Returns the member object on successful authentication
|
* @return Member Returns the member object on successful authentication
|
||||||
* or NULL on failure.
|
* or NULL on failure.
|
||||||
*/
|
*/
|
||||||
public function performLogin($data) {
|
public function performLogin($data) {
|
||||||
if($member = MemberAuthenticator::authenticate($data, $this)) {
|
if($member = MemberAuthenticator::authenticate($data, $this)) {
|
||||||
$firstname = Convert::raw2xml($member->FirstName);
|
$firstname = Convert::raw2xml($member->FirstName);
|
||||||
Session::set("Security.Message.message",
|
Session::set("Security.Message.message",
|
||||||
sprintf(_t('Member.WELCOMEBACK', "Welcome Back, %s"), $firstname)
|
sprintf(_t('Member.WELCOMEBACK', "Welcome Back, %s"), $firstname)
|
||||||
);
|
);
|
||||||
Session::set("Security.Message.type", "good");
|
Session::set("Security.Message.type", "good");
|
||||||
|
|
||||||
$member->LogIn(isset($data['Remember']));
|
$member->LogIn(isset($data['Remember']));
|
||||||
return $member;
|
return $member;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->extend('authenticationFailed', $data);
|
$this->extend('authenticationFailed', $data);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forgot password form handler method
|
* Forgot password form handler method
|
||||||
*
|
*
|
||||||
* This method is called when the user clicks on "I've lost my password"
|
* This method is called when the user clicks on "I've lost my password"
|
||||||
*
|
*
|
||||||
* @param array $data Submitted data
|
* @param array $data Submitted data
|
||||||
*/
|
*/
|
||||||
function forgotPassword($data) {
|
function forgotPassword($data) {
|
||||||
$SQL_data = Convert::raw2sql($data);
|
$SQL_data = Convert::raw2sql($data);
|
||||||
|
|
||||||
if(($data['Email']) && ($member = DataObject::get_one("Member",
|
if(($data['Email']) && ($member = DataObject::get_one("Member",
|
||||||
"Member.Email = '$SQL_data[Email]'"))) {
|
"Member.Email = '$SQL_data[Email]'"))) {
|
||||||
|
|
||||||
$member->generateAutologinHash();
|
$member->generateAutologinHash();
|
||||||
|
|
||||||
$member->sendInfo('forgotPassword', array('PasswordResetLink' =>
|
$member->sendInfo('forgotPassword', array('PasswordResetLink' =>
|
||||||
Security::getPasswordResetLink($member->AutoLoginHash)));
|
Security::getPasswordResetLink($member->AutoLoginHash)));
|
||||||
|
|
||||||
Director::redirect('Security/passwordsent/?email=' . urlencode($data['Email']));
|
Director::redirect('Security/passwordsent/?email=' . urlencode($data['Email']));
|
||||||
|
|
||||||
} else if($data['Email']) {
|
} else if($data['Email']) {
|
||||||
$this->sessionMessage(
|
$this->sessionMessage(
|
||||||
_t('Member.ERRORSIGNUP', "Sorry, but I don't recognise the e-mail address. Maybe you need " .
|
_t('Member.ERRORSIGNUP', "Sorry, but I don't recognise the e-mail address. Maybe you need " .
|
||||||
"to sign up, or perhaps you used another e-mail address?"),
|
"to sign up, or perhaps you used another e-mail address?"),
|
||||||
"bad");
|
"bad");
|
||||||
Director::redirectBack();
|
Director::redirectBack();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Director::redirect("Security/lostpassword");
|
Director::redirect("Security/lostpassword");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user