Thread: [CS-Project-svn_notify] SF.net SVN: cs-project: [795] trunk/1.1
Brought to you by:
crazedsanity
From: <cra...@us...> - 2008-02-07 03:55:04
|
Revision: 795 http://cs-project.svn.sourceforge.net/cs-project/?rev=795&view=rev Author: crazedsanity Date: 2008-02-06 19:55:00 -0800 (Wed, 06 Feb 2008) Log Message: ----------- *** RELEASE 1.0.1 *** SUMMARY OF CHANGES::: * update to cs-content v0.10.8 * update to cs-phpxml v0.5.5 * minor template & include changes for updated version of cs-content. * remove invalid links to non-existent "contacts" page... NOTE: changes from trunk of v1.0 were merged SVN COMMAND::: merge -r789:HEAD https://cs-project.svn.sourceforge.net/svnroot/cs-project/trunk/1.0 Modified Paths: -------------- trunk/1.1/VERSION trunk/1.1/includes/login.inc trunk/1.1/lib/cs-arrayToPath/VERSION trunk/1.1/lib/cs-arrayToPath/arrayToPathClass.php trunk/1.1/lib/cs-content/VERSION trunk/1.1/lib/cs-content/contentSystemClass.php trunk/1.1/lib/cs-content/cs_fileSystemClass.php trunk/1.1/lib/cs-content/cs_genericPageClass.php trunk/1.1/lib/cs-content/cs_phpDB.php trunk/1.1/lib/cs-phpxml/xmlAbstract.class.php trunk/1.1/lib/cs-phpxml/xmlBuilderClass.php trunk/1.1/lib/cs-phpxml/xmlParserClass.php trunk/1.1/lib/globalFunctions.php trunk/1.1/lib/projectClass.php trunk/1.1/lib/sessionCacheClass.php trunk/1.1/lib/session_class.php trunk/1.1/lib/site_config.php trunk/1.1/templates/content/helpdesk/view.content.tmpl trunk/1.1/templates/infobar.shared.tmpl Added Paths: ----------- trunk/1.1/lib/cs-content/db_types/ trunk/1.1/lib/cs-content/db_types/cs_phpDB__pgsql.class.php trunk/1.1/templates/content/notes/create.content.tmpl trunk/1.1/templates/content/notes/view.content.tmpl trunk/1.1/templates/login.content.tmpl Removed Paths: ------------- trunk/1.1/templates/content/notes/index.shared.tmpl trunk/1.1/templates/login.tmpl Modified: trunk/1.1/VERSION =================================================================== --- trunk/1.1/VERSION 2008-02-07 02:19:25 UTC (rev 794) +++ trunk/1.1/VERSION 2008-02-07 03:55:00 UTC (rev 795) @@ -1,4 +1,4 @@ $Id:VERSION 628 2007-11-20 16:58:45Z crazedsanity $ -VERSION: 1.1.0 +VERSION: 1.1.1 $HeadURL:https://cs-project.svn.sourceforge.net/svnroot/cs-project/trunk/VERSION $ Modified: trunk/1.1/includes/login.inc =================================================================== --- trunk/1.1/includes/login.inc 2008-02-07 02:19:25 UTC (rev 794) +++ trunk/1.1/includes/login.inc 2008-02-07 03:55:00 UTC (rev 795) @@ -57,7 +57,7 @@ if($_GET['destination']) { $_SESSION['loginDestination'] = urlencode($_GET['destination']); } -//show the default page. -$page->change_content(html_file_to_string("login.tmpl")); +$page->add_template_var('cs-project_version', VERSION_STRING); + ?> \ No newline at end of file Modified: trunk/1.1/lib/cs-arrayToPath/VERSION =================================================================== --- trunk/1.1/lib/cs-arrayToPath/VERSION 2008-02-07 02:19:25 UTC (rev 794) +++ trunk/1.1/lib/cs-arrayToPath/VERSION 2008-02-07 03:55:00 UTC (rev 795) @@ -2,4 +2,4 @@ VERSION: 0.2.2 PROJECT: cs-arrayToPath -$HeadURL: https://cs-arraytopath.svn.sourceforge.net/svnroot/cs-arraytopath/releases/0.2.2/VERSION $ \ No newline at end of file +$HeadURL: https://cs-arraytopath.svn.sourceforge.net/svnroot/cs-arraytopath/releases/0.2/VERSION $ \ No newline at end of file Modified: trunk/1.1/lib/cs-arrayToPath/arrayToPathClass.php =================================================================== --- trunk/1.1/lib/cs-arrayToPath/arrayToPathClass.php 2008-02-07 02:19:25 UTC (rev 794) +++ trunk/1.1/lib/cs-arrayToPath/arrayToPathClass.php 2008-02-07 03:55:00 UTC (rev 795) @@ -6,7 +6,7 @@ * ------------------- * Last Author::::::::: $Author: crazedsanity $ * Current Revision:::: $Revision: 17 $ - * Repository Location: $HeadURL: https://cs-arraytopath.svn.sourceforge.net/svnroot/cs-arraytopath/releases/0.2.2/arrayToPathClass.php $ + * Repository Location: $HeadURL: https://cs-arraytopath.svn.sourceforge.net/svnroot/cs-arraytopath/releases/0.2/arrayToPathClass.php $ * Last Updated:::::::: $Date: 2007-09-12 14:24:46 -0500 (Wed, 12 Sep 2007) $ * * Modified: trunk/1.1/lib/cs-content/VERSION =================================================================== --- trunk/1.1/lib/cs-content/VERSION 2008-02-07 02:19:25 UTC (rev 794) +++ trunk/1.1/lib/cs-content/VERSION 2008-02-07 03:55:00 UTC (rev 795) @@ -1,5 +1,5 @@ ## Stores the current version of the cs-content system, and it's source. Please do NOT modify this file. -VERSION: 0.10.6 +VERSION: 0.10.8 PROJECT: cs-content $HeadURL:https://cs-content.svn.sourceforge.net/svnroot/cs-content/trunk/VERSION $ \ No newline at end of file Modified: trunk/1.1/lib/cs-content/contentSystemClass.php =================================================================== --- trunk/1.1/lib/cs-content/contentSystemClass.php 2008-02-07 02:19:25 UTC (rev 794) +++ trunk/1.1/lib/cs-content/contentSystemClass.php 2008-02-07 03:55:00 UTC (rev 795) @@ -1,10 +1,10 @@ -<? +<?php /* * FILE INFORMATION: * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/contentSystemClass.php $ - * $Id: contentSystemClass.php 221 2007-11-21 17:39:01Z crazedsanity $ - * $LastChangedDate: 2007-11-21 11:39:01 -0600 (Wed, 21 Nov 2007) $ - * $LastChangedRevision: 221 $ + * $Id: contentSystemClass.php 252 2008-01-31 21:57:49Z crazedsanity $ + * $LastChangedDate: 2008-01-31 15:57:49 -0600 (Thu, 31 Jan 2008) $ + * $LastChangedRevision: 252 $ * $LastChangedBy: crazedsanity $ * * HOW THE SYSTEM WORKS::: @@ -90,12 +90,15 @@ ); protected $templateList = array(); protected $includesList = array(); - protected $templateObj = NULL; + public $templateObj = NULL; protected $gfObj = NULL; protected $tabs = NULL; protected $finalSection; + private $isValid=FALSE; + private $reason=NULL; + //------------------------------------------------------------------------ /** * The CONSTRUCTOR. Duh. @@ -257,8 +260,7 @@ * Rips apart the "section" string, setting $this->section and $this->sectionArr. */ private function parse_section() { - // - if($this->section === 0) { + if($this->section === 0 || is_null($this->section) || !strlen($this->section)) { $this->section = "content/index"; } $myArr = split('/', $this->section); @@ -286,8 +288,10 @@ //make sure we've still got something valid to work with. if(!strlen($section)) { + //TODO: remove the extra return statement (should only be one at the bottom of the method). return(0); - } else { + } + else { //check the string to make sure it doesn't begin or end with a "/" if($section[0] == '/') { $section = substr($section, 1, strlen($section)); @@ -359,8 +363,9 @@ //now cd() all the way back. $this->fileSystemObj->cd('/'); - } else { - //couldn't find the templates directory... ick. + } + else { + //couldn't find the templates directory, and no includes... it's dead. $this->die_gracefully(__METHOD__ .": unable to find the templates directory, or non-valid page [". $this->validate_page() ."]"); } }//end prepare() @@ -399,14 +404,17 @@ } $lsDir = $this->fileSystemObj->ls($indexFilename); + $lsDirVals = array_values($lsDir); $lsFile = $this->fileSystemObj->ls("$finalSection.content.tmpl"); - if(is_array(array_values($lsDir))) { - //it's the dir. + + if(is_array(array_values($lsFile)) && is_array($lsFile[$finalSection .".content.tmpl"])) { + //it's the file ("{finalSection}.content.tmpl", like "mySection.content.tmpl") + $myIndex = $finalSection .".content.tmpl"; + } + elseif(is_array(array_values($lsDir)) && (is_array($lsDir[$indexFilename]))) { $myIndex = $indexFilename; - } elseif(is_array(array_values($lsFile))) { - //it's the file (no dir, or dir w/o index) - $myIndex = $finalSection.content.tmpl; - } else { + } + else { //nothin' doin'. $myIndex = NULL; } @@ -420,21 +428,35 @@ if(isset($myIndex)) { $valid = TRUE; $this->fileSystemObj->cd('/templates'); - } else { - $this->reason = __METHOD__ .": couldn't find page template for (". $this->section .", final=[$finalSection])..."; } - } else { - //just the base template. Make sure it's good. + else { + $this->reason = __METHOD__ .": couldn't find page template for ". $this->section; + } + } + else { + //if the baseDir is "help", this would try to use "/help/index.content.tmpl" $myFile = $this->baseDir .'/index.content.tmpl'; - $lsData = $this->fileSystemObj->ls($myFile); - if(isset($lsData[$myFile]) && $lsData[$myFile]['type'] == 'file') { + $sectionLsData = $this->fileSystemObj->ls($myFile); + + //if the baseDir is "help", this would try to use "/help.content.tmpl" + $sectionFile = $this->baseDir .'.content.tmpl'; + $lsData = $this->fileSystemObj->ls(); + + if(isset($lsData[$sectionFile]) && is_array($lsData[$sectionFile])) { + $valid = TRUE; + $this->finalSection = $this->baseDir; + } + elseif(isset($sectionLsData[$myFile]) && $sectionLsData[$myFile]['type'] == 'file') { //we're good. $valid = TRUE; $this->finalSection = $this->baseDir; - } else { + } + else { $this->reason = __METHOD__ .": couldn't find base template."; } } + $this->isValid = $valid; + return($valid); }//end validate_page() //------------------------------------------------------------------------ @@ -486,6 +508,10 @@ $this->templateList[$mySection] = $myTmpl; } } + if(isset($tmplList[$this->baseDir]['content'])) { + //load template for the main page (if $this->baseDir == "help", this would load "/help.content.tmpl" as content) + $this->templateList['content'] = $tmplList[$this->baseDir]['content']; + } } }//end load_page_templates() //------------------------------------------------------------------------ @@ -553,6 +579,7 @@ if(($myType == 'file') && !in_array($index, $this->ignoredList[$myType])) { $filename = $this->gfObj->create_list($this->fileSystemObj->cwd, $index, '/'); $filename = preg_replace('/^\/templates/', '', $filename); + $filename = preg_replace('/^\/\//', '/', $filename); //call another method to rip the filename apart properly, then arrange things as needed. $pieces = $this->parse_filename($index); $myPriIndex = $pieces[$primaryIndex]; @@ -687,7 +714,7 @@ } else { //TODO: make it *actually* die gracefully... the way it works now looks more like puke than grace. - throw new exception(__METHOD__ .": something broke. \nDETAILS::: $details" . + throw new exception(__METHOD__ .": Couldn't find 404 template, plus additional error... \nDETAILS::: $details" . "\nREASON::: ". $this->reason); } }//end die_gracefully() @@ -762,7 +789,16 @@ unset($myInternalScriptName); } - $page->print_page(); + if(is_bool($this->templateObj->allow_invalid_urls() === TRUE) && $this->isValid === FALSE) { + $this->isValid = $this->templateObj->allow_invalid_urls(); + } + + if($this->isValid === TRUE) { + $page->print_page(); + } + else { + $this->die_gracefully($this->reason); + } }//end finish() //------------------------------------------------------------------------ @@ -772,8 +808,7 @@ /** * Method for accessing the protected $this->sectionArr array. */ - public function get_sectionArr() - { + public function get_sectionArr() { //give 'em what they want. return($this->sectionArr); }//end get_sectionArr() @@ -785,8 +820,7 @@ /** * Method for accessing the protected member $this->finalSection. */ - public function get_finalSection() - { + public function get_finalSection() { //give 'em what they want. return($this->finalSection); }//end get_finalSection() @@ -798,8 +832,7 @@ /** * Method for accessing "baseDir", only referenced as the base section. */ - public function get_baseSection() - { + public function get_baseSection() { return($this->baseDir); }//end get_baseSection() //------------------------------------------------------------------------ Modified: trunk/1.1/lib/cs-content/cs_fileSystemClass.php =================================================================== --- trunk/1.1/lib/cs-content/cs_fileSystemClass.php 2008-02-07 02:19:25 UTC (rev 794) +++ trunk/1.1/lib/cs-content/cs_fileSystemClass.php 2008-02-07 03:55:00 UTC (rev 795) @@ -1,12 +1,12 @@ -<? +<?php /* * FILE INFORMATION: * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/cs_fileSystemClass.php $ - * $Id: cs_fileSystemClass.php 221 2007-11-21 17:39:01Z crazedsanity $ - * $LastChangedDate: 2007-11-21 11:39:01 -0600 (Wed, 21 Nov 2007) $ + * $Id: cs_fileSystemClass.php 252 2008-01-31 21:57:49Z crazedsanity $ + * $LastChangedDate: 2008-01-31 15:57:49 -0600 (Thu, 31 Jan 2008) $ * $LastChangedBy: crazedsanity $ - * $LastChangedRevision: 221 $ + * $LastChangedRevision: 252 $ */ require_once(dirname(__FILE__) ."/cs_globalFunctions.php"); Modified: trunk/1.1/lib/cs-content/cs_genericPageClass.php =================================================================== --- trunk/1.1/lib/cs-content/cs_genericPageClass.php 2008-02-07 02:19:25 UTC (rev 794) +++ trunk/1.1/lib/cs-content/cs_genericPageClass.php 2008-02-07 03:55:00 UTC (rev 795) @@ -2,10 +2,10 @@ /* * FILE INFORMATION: * $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/cs_genericPageClass.php $ - * $Id: cs_genericPageClass.php 221 2007-11-21 17:39:01Z crazedsanity $ - * $LastChangedDate: 2007-11-21 11:39:01 -0600 (Wed, 21 Nov 2007) $ + * $Id: cs_genericPageClass.php 252 2008-01-31 21:57:49Z crazedsanity $ + * $LastChangedDate: 2008-01-31 15:57:49 -0600 (Thu, 31 Jan 2008) $ * $LastChangedBy: crazedsanity $ - * $LastChangedRevision: 221 $ + * $LastChangedRevision: 252 $ */ require_once(dirname(__FILE__) ."/template.inc"); require_once(dirname(__FILE__) ."/cs_versionAbstract.class.php"); @@ -22,6 +22,8 @@ private $showEditableLink = FALSE; + private $allowInvalidUrls=NULL; + //--------------------------------------------------------------------------------------------- /** * The constructor. @@ -257,7 +259,7 @@ if($stripUndefVars) { $numLoops = 0; - while(preg_match_all('/\{.*?\}/', $this->templateObj->varvals['out'], $tags) && $numLoops < 50) { + while(preg_match_all('/\{.\S+?\}/', $this->templateObj->varvals['out'], $tags) && $numLoops < 50) { $tags = $tags[0]; //TODO: figure out why this works when running it twice. @@ -286,8 +288,9 @@ */ public function process_set_message() { //if there's not a message set, skip. - $errorBox = $this->file_to_string("system/message_box.tmpl"); + $errorBox = ""; if(isset($_SESSION['message']) && is_array($_SESSION['message'])) { + $errorBox = $this->file_to_string("system/message_box.tmpl"); //let's make sure the "type" value is *lowercase*. $_SESSION['message']['type'] = strtolower($_SESSION['message']['type']); @@ -307,6 +310,7 @@ // they'll never get past this point). unset($_SESSION['message']); } + return($errorBox); }//end of process_set_message() //--------------------------------------------------------------------------------------------- @@ -595,6 +599,17 @@ return($retval); }//end set_all_block_rows() //--------------------------------------------------------------------------------------------- + + + + //--------------------------------------------------------------------------------------------- + public function allow_invalid_urls($newSetting=NULL) { + if(!is_null($newSetting) && is_bool($newSetting)) { + $this->allowInvalidUrls = $newSetting; + } + return($this->allowInvalidUrls); + }//end allow_invalid_urls() + //--------------------------------------------------------------------------------------------- }//end cs_genericPage{} ?> Modified: trunk/1.1/lib/cs-content/cs_phpDB.php =================================================================== --- trunk/1.1/lib/cs-content/cs_phpDB.php 2008-02-07 02:19:25 UTC (rev 794) +++ trunk/1.1/lib/cs-content/cs_phpDB.php 2008-02-07 03:55:00 UTC (rev 795) @@ -4,8 +4,8 @@ * A class for generic PostgreSQL database access. * * SVN INFORMATION::: - * SVN Signature:::::::: $Id: cs_phpDB.php 225 2007-12-19 00:20:13Z crazedsanity $ - * Last Committted Date: $Date: 2007-12-18 18:20:13 -0600 (Tue, 18 Dec 2007) $ + * SVN Signature:::::::: $Id: cs_phpDB.php 252 2008-01-31 21:57:49Z crazedsanity $ + * Last Committted Date: $Date: 2008-01-31 15:57:49 -0600 (Thu, 31 Jan 2008) $ * Last Committed Path:: $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/cs_phpDB.php $ * */ @@ -32,1132 +32,51 @@ require_once(dirname(__FILE__) ."/cs_versionAbstract.class.php"); class cs_phpDB extends cs_versionAbstract { - - /** Internal result set pointer. */ - protected $result = NULL; - /** Internal error code. */ - protected $errorCode = 0; + private $dbLayerObj; + private $dbType; - /** Status of the current transaction. */ - protected $transStatus = NULL; - - /** Whether there is a transaction in progress or not. */ - protected $inTrans = FALSE; - - /** Holds the last query performed. */ - protected $lastQuery = NULL; - - /** List of queries that have been run */ - protected $queryList=array(); - - /** How many seconds to wait for a query before cancelling it. */ - protected $timeOutSeconds = NULL; - - /** Internal check to determine if a connection has been established. */ - protected $isConnected=FALSE; - - /** Internal check to determine if the parameters have been set. */ - protected $paramsAreSet=FALSE; - - /** Resource handle. */ - protected $connectionID = -1; - - /** Hostname or IP to connect to */ - protected $host; - - /** Port to connect to (default for Postgres is 5432) */ - protected $port; - - /** Name of the database */ - protected $dbname; - - /** Username to connect to the database */ - protected $user; - - /** password to connect to the database */ - protected $password; - - /** Row counter for looping through records */ - protected $row = -1; - - /** cs_globalFunctions object, for string stuff. */ - protected $gfObj; - - /** Internal check to ensure the object has been properly created. */ - protected $isInitialized=FALSE; - - /** List of prepared statements, indexed off the name, with the sub-array being fieldname=>dataType. */ - protected $preparedStatements = array(); - - /** Set to TRUE to save all queries into an array. */ - protected $useQueryList=FALSE; - - /** array that essentially remembers how many times beginTrans() was called. */ - protected $transactionTree = NULL; - - //////////////////////////////////////////// - // Core primary connection/database function - //////////////////////////////////////////// - - //========================================================================= - public function __construct() { - $this->gfObj = new cs_globalFunctions; + public function __construct($type='pgsql') { - if(defined('DEBUGPRINTOPT')) { - $this->gfObj->debugPrintOpt = DEBUGPRINTOPT; - } - - $this->isInitialized = TRUE; - }//end __construct() - //========================================================================= - - - - //========================================================================= - /** - * Make sure the object is sane. - */ - final protected function sanity_check() { - if($this->isInitialized !== TRUE) { - throw new exception(__METHOD__ .": not properly initialized"); - } - }//end sanity_check() - //========================================================================= - - - - //========================================================================= - /** - * Set appropriate parameters for database connection - */ - public function set_db_info(array $params){ - $this->sanity_check(); - $required = array('host', 'port', 'dbname', 'user', 'password'); - - $requiredCount = 0; - foreach($params as $index=>$value) { - if(property_exists($this, $index) && in_array($index, $required)) { - $this->$index = $value; - $requiredCount++; - } - else { - throw new exception(__METHOD__. ": property (". $index .") does " . - "not exist or isn't allowed"); - } - } - - if($requiredCount == count($required)) { - $this->paramsAreSet = TRUE; - } - else { - throw new exception(__METHOD__ .": required count (". $requiredCount - .") does not match required number of fields (". count($required) .")"); - } - }//end set_db_info() - //========================================================================= - - - - //========================================================================= - /** - * Wrapper for close() - */ - function disconnect() { - //Disconnect from $database - return($this->close()); - }//end disconnect() - //========================================================================= - - - - //========================================================================= - /** - * Standard method to close connection. - */ - function close() { - $this->isConnected = FALSE; - $retval = null; - if($this->connectionID != -1) { - $retval = pg_close($this->connectionID); - } - else { - throw new exception(__METHOD__ .": Failed to close connection: connection is invalid"); - } - - return($retval); - }//end close() - //========================================================================= - - - - //========================================================================= - /** - * Connect to the database - */ - function connect(array $dbParams=NULL, $forceNewConnection=FALSE){ - $this->sanity_check(); - $retval = NULL; - if(is_array($dbParams)) { - $this->set_db_info($dbParams); - } - - if($this->paramsAreSet === TRUE && $this->isConnected === FALSE) { + if(strlen($type)) { - $myConnArr = array( - 'host' => $this->host, - 'port' => $this->port, - 'dbname' => $this->dbname, - 'user' => $this->user, - 'password' => $this->password - ); + require_once(dirname(__FILE__) .'/db_types/'. __CLASS__ .'__'. $type .'.class.php'); + $className = __CLASS__ .'__'. $type; + $this->dbLayerObj = new $className; + $this->dbType = $type; - //make it into a string separated by spaces, don't clean anything, remove null elements - $connStr = $this->gfObj->string_from_array($myConnArr, 'url', " "); + $this->gfObj = new cs_globalFunctions; - //start output buffer for displaying error. - ob_start(); - if($forceNewConnection) { - $connID = pg_connect($connStr, PGSQL_CONNECT_FORCE_NEW); + if(defined('DEBUGPRINTOPT')) { + $this->gfObj->debugPrintOpt = DEBUGPRINTOPT; } - else { - $connID =pg_connect($connStr); - } - $connectError = ob_get_contents(); - ob_end_clean(); - if(is_resource($connID)) { - $this->errorCode=0; - $this->connectionID = $connID; - $this->isConnected = TRUE; - $retval = $this->connectionID; - } - else { - throw new exception(__METHOD__ .": FATAL ERROR: ". $connectError); - } + $this->isInitialized = TRUE; } else { - throw new exception(__METHOD__ .": paramsAreSet=(". $this->paramsAreSet ."), isConnected=(". $this->isConnected .")"); + throw new exception(__METHOD__ .": failed to give a type (". $type .")"); } - - return($retval); - }//end connect() + }//end __construct() //========================================================================= //========================================================================= - function get_hostname() { - $this->sanity_check(); - return($this->host); - }//end get_hostname() - //========================================================================= - - - - //========================================================================= - /** - * Run sql queries - * - * TODO: re-implement query logging (setting debug, logfilename, etc). - */ - function exec($query) { - $this->lastQuery = $query; - if($this->useQueryList) { - $this->queryList[] = $query; - } - $returnVal = false; - - if(($this->get_transaction_status() != -1) && ($this->connectionID != -1)) { - $this->result = @pg_query($this->connectionID, $query); - - if($this->result !== false) { - if (eregi("^[[:space:]]*select", $query)) { - //If we didn't have an error and we are a select statement, move the pointer to first result - $numRows = $this->numRows(); - if($numRows > 0) { - $this->move_first(); - } - $returnVal = $numRows; - - } - else { - //We got something other than an update. Use numAffected - $returnVal = $this->numAffected(); - } - } - } - return($returnVal); - }//end exec() - //========================================================================= - - - - //========================================================================= /** - * Returns any error caused by the last executed query. - * - * @return NULL OK: no error - * @return (string) FAIL: contains error returned from the query. + * Magic method to call methods within the database abstraction layer ($this->dbLayerObj). */ - function errorMsg($setMessage=NULL,$logError=NULL) { - $this->sanity_check(); - if ($this->connectionID < 0) { - switch ($this->errorCode) { - //############################################### - case -1: - $retVal = "FATAL ERROR - CONNECTION ERROR: RESOURCE NOT FOUND"; - break; - //############################################### - - //############################################### - case -2: - $retVal = "FATAL ERROR - CLASS ERROR: FUNCTION CALLED WITHOUT PARAMETERS"; - break; - //############################################### - - //############################################### - case -3: - $retVal = "Query exceeded maximum timeout (". $this->timeoutSeconds .")"; - break; - //############################################### - - //############################################### - default: - $retVal = null; - //############################################### - } - } else { - $retVal = pg_last_error($this->connectionID); + public function __call($methodName, $args) { + if(method_exists($this->dbLayerObj, $methodName)) { + $retval = call_user_func_array(array($this->dbLayerObj, $methodName), $args); } - - return($retVal); - }//end errorMsg() - //========================================================================= - - - - - //////////////////// - // Cursor movement - //////////////////// - - - - - //========================================================================= - /** - * move pointer to first row of result set - */ - function move_first() { - $this->sanity_check(); - if($this->result == NULL) { - $retval = FALSE; - } else { - $this->set_row(0); - $retval = TRUE; + throw new exception(__METHOD__ .': unsupported method ('. $methodName .') for database of type ('. $this->dbType .')'); } - return($retval); - }//end move_first() + }//end __call() //========================================================================= - - - //========================================================================= - /** - * move pointer to last row of result set - */ - function move_last() { - $this->sanity_check(); - if($this->result == NULL) { - $retval = FALSE; - } - else { - $this->set_row($this->numRows()-1); - $retval = TRUE; - } - - return($retval); - }//end move_list() - //========================================================================= - - - - //========================================================================= - /** - * point to the next row, return false if no next row - */ - function move_next() { - $this->sanity_check(); - // If more rows, then advance row pointer - if($this->row < $this->numRows()-1) { - $this->set_row($this->row +1); - $retval = TRUE; - } - else { - $retval = FALSE; - } - - return($retval); - }//end move_next() - //========================================================================= - - - - //========================================================================= - /** - * point to the previous row, return false if no previous row - */ - function move_previous() { - // If not first row, then advance row pointer - if ($this->row > 0) { - $this->set_row($this->row -1); - return true; - } - else return false; - }//end move_previous() - //========================================================================= - - - - //========================================================================= - // point to the next row, return false if no next row - function next_row() { - // If more rows, then advance row pointer - if ($this->row < $this->numRows()-1) { - $this->set_row($this->row +1); - return true; - } - else return false; - }//end next_row() - //========================================================================= - - - - //========================================================================= - // can be used to set a pointer to a perticular row - function set_row($row){ - if(is_numeric($row)) { - $this->row = $row; - } - else { - throw new exception(__METHOD__ .": invalid data for row (". $row .")"); - } - return($this->row); - }//end set_row(); - //========================================================================= - - - - - /////////////////////// - // Result set related - /////////////////////// - - - - //========================================================================= - /** - * Return the current row as an object. - */ - function fobject() { - $this->sanity_check(); - if($this->result == NULL || $this->row == -1) { - $retval = NULL; - } - else { - $retval = pg_fetch_object($this->result, $this->row); - } - - return($retval); - } - //========================================================================= - - - - //========================================================================= - /** - * Fetch the current row as an array containing fieldnames AND numeric indexes. - */ - function farray(){ - if($this->result == NULL || $this->row == -1) { - $retval = NULL; - } - else { - $retval = pg_fetch_array($this->result,$this->row); - } - - return($retval); - }//end farray() - //========================================================================= - - - - //========================================================================= - /** - * Another way to retrieve a single row (useful for loops). - */ - function frow(){ - $this->sanity_check(); - if($this->numRows() <= 0) { - $retval = NULL; - } - else { - if($this->result == null || $this->row == -1) { - $retval = NULL; - } - else { - $retval = pg_fetch_row($this->result, $this->row); - } - } - - return($retval); - }//end frow() - //========================================================================= - - - - //========================================================================= - /** - * Similar to farray(), except all indexes are non-numeric, and the entire - * result set is retrieved: if only one row is available, no numeric index - * is set, unless $numbered is TRUE. - * - * TODO: clean this up! - */ - function farray_fieldnames($index=NULL, $numbered=NULL,$unsetIndex=1) { - $this->sanity_check(); - $retval = NULL; - - //before we get too far, let's make sure there's something there. - if($this->numRows() <= 0) { - $retval = 0; - } - else { - //keep any errors/warnings from printing to the screen by using OUTPUT BUFFERS. - ob_start(); - - $x = 0; - do { - $temp = $this->farray(); - foreach($temp as $key=>$value) { - //remove the numbered indexes. - if(is_string($key)) { - $tArr[$key] = $value; - } - } - $newArr[$x] = $tArr; - $x++; - } - while($this->next_row()); - - if($index) { - foreach($newArr as $row=>$contents) { //For each of the returned sets of information - foreach($contents as $fieldname=>$value) { //And now for each of the items in that set - if($fieldname == $index) { - //The index for the new array will be this fieldname's value - $arrayKey = $value; - } - - $tempContent[$fieldname] = $value; - //don't include the "index" field in the subarray; that always seems to end badly. - if ($unsetIndex) { - unset($tempContent[$index]); - } - } - - if (!isset($tempArr[$arrayKey])) { - //Make sure we didn't already set this in the array. If so, then we don't have a unique variable to use for the array index. - $tempArr[$arrayKey] = $tempContent; - } - else { - //TODO: bigtime cleaning... should only return at the bottom of the method. - $retval = 0; - break; - } - $arrayKey = NULL; //Blank this out after using it, just in case we don't find one in the next iteration - } - - if (count($tempArr) != count($newArr)) { - $details = "farray_fieldnames(): Array counts don't match.<BR>\n" - ."FUNCTION ARGUMENTS: index=[$index], numbered=[$numbered], unsetIndex=[$unsetIndex]<BR>\n" - ."LAST QUERY: ". $this->lastQuery; - throw new exception(__METHOD__ .": $details"); - } - $newArr = $tempArr; - } - //this is where, if there's only one row (and the planets align just the way - // I like them to), there's no row w/ a sub-array... This is only done - // if $index is NOT set... - if(($this->numRows() == 1) AND (!$index) AND (!$numbered)) { - $newArr = $newArr[0]; - } - $retval = $newArr; - ob_end_clean(); - } - return($retval); - }//end farray_fieldnames() - //========================================================================= - - - - //========================================================================= - /** - * Uses farray_fieldnames() to retrieve the entire result set, but the final - * array is contains name=>value pairs. - */ - function farray_nvp($name, $value) { - if((!$name) OR (!$value)) { - $retval = 0; - } - else { - $tArr = $this->farray_fieldnames(NULL,1); - if(!is_array($tArr)) { - $retval = 0; - } - else { - //loop through it & grab the proper info. - $retval = array(); - foreach($tArr as $row=>$array) { - $tKey = $array[$name]; - $tVal = $array[$value]; - $retval[$tKey] = $tVal; - } - } - } - - //return the new array. - return($retval); - }//end farray_nvp() - //========================================================================= - - - - //========================================================================= - /** - * Similar to farray_fieldnames(), but only returns the NUMERIC indexes - */ - function farray_numbered() { - do { - $temp = $this->frow(); - $retArr[] = $temp[0]; - } - while($this->next_row()); - - return($retArr); - }//end farray_numbered() - //========================================================================= - - - - //========================================================================= - /** - * Returns the number of tuples affected by an insert/delete/update query. - * NOTE: select queries must use numRows() - */ - function numAffected() { - if($this->result == null) { - $retval = 0; - } else { - $this->affectedRows = pg_affected_rows($this->result); - $retval = $this->affectedRows; - } - - return($retval); - }//end numAffected() - //========================================================================= - - - - //========================================================================= - /** - * Returns the number of rows in a result (from a SELECT query). - */ - function numRows() { - if ($this->result == null) { - $retval = 0; - } - else { - $this->numrows = pg_num_rows($this->result); - $retval = $this->numrows; - } - - return($retval); - }//end numRows() - //========================================================================= - - - - //========================================================================= - /** - * wrapper for numAffected() - */ - function affectedRows(){ - return($this->numAffected()); - }//end affectedRows() - //========================================================================= - - - - //========================================================================= - /** - * Returns the current row number. - */ - function currRow(){ - return($this->row); - }//end currRow() - //========================================================================= - - - - //========================================================================= - /** - * Get the number of fields in a result. - */ - // get the number of fields in a result - function num_fields() { - if($this->result == null) { - $retval = 0; - } - else { - $retval = pg_num_fields($this->result); - } - return($retval); - }//end num_fields() - //========================================================================= - - - - //========================================================================= - function column_count() { - return($this->numFields()); - }//end column_count() - //========================================================================= - - - - //========================================================================= - /** - * get last OID (object identifier) of last INSERT statement - */ - function lastOID($doItForMe=0, $field=NULL) { - if($this->result == NULL) { - $retval = NULL; - } - else { - $tOid = pg_last_oid($this->result); - $retval = $tOid; - - if(($doItForMe) AND (eregi("^insert", $this->last_query))) { - //attempt to parse the insert statement, then select - // all fields (unless $field is set) from it. - $t = split(" into ", strtolower($this->last_query)); - $t = split(" ", $t[1]); - $t = split("\(", $t[0]); - $table = $t[0]; - - //now we have the table. - if(!$field) { - $field = "*"; - } - $query = "SELECT $field FROM $table WHERE OID=$tOid"; - $this->exec($query); - $dberror = $this->errorMsg(1,1,1,"lastOID(): "); - - if(!$dberror) { - $res = $this->farray(); - if(is_string($field)) { - $retval = $res[0]; - } - } - } - } - return($retval); - }//end lastOID() - //========================================================================= - - - - //========================================================================= - /** - * get result field name of the given field number. - */ - // get result field name - function fieldname($fieldnum) { - if($this->result == NULL) { - $retval =NULL; - } - else { - $retval = pg_field_name($this->result, $fieldnum); - } - - return($retval); - }//end fieldname() - //========================================================================= - - - - - //////////////////////// - // Transaction related - //////////////////////// - - - - - //========================================================================= - /** - * Start a transaction. - */ - function beginTrans($transName=NULL) { - $transStatus = $this->get_transaction_status(TRUE); - if(!$this->inTrans) { - //not in a transaction. Set up the transaction tree properly. - $this->transactionTree = array(); - } - else { - if($this->inTrans && is_null($this->transactionTree)) { - $transLevel = $this->get_transaction_level(); - //transaction started without using beginTrans()... - $this->transactionTree = array(); - $this->gfObj->debug_print(__METHOD__ .": transaction already started, transStatus=(". $transStatus ."), transLevel=(". $transLevel .")"); - $this->transactionTree[] = "Already started..."; - } - } - - if(is_null($transName)) { - $transName = time(TRUE); - } - $this->transactionTree[] = $transName; - $transLevel = $this->get_transaction_level(); - $this->gfObj->debug_print(__METHOD__ .": starting transaction at transLevel=(". $transLevel .")"); - return($this->exec("BEGIN")); - }//end beginTrans() - //========================================================================= - - - - //========================================================================= - /** - * Commit a transaction. - */ - function commitTrans() { - $retval = $this->get_transaction_status(); - $lastTransLayer = array_pop($this->transactionTree); - $transLevel = $this->get_transaction_level(); - if($transLevel == 0) { - if($retval > 1) { - $retval = 1; - } - $this->exec("COMMIT"); - - //check to see if there was an error (deferred constraints are checked at commit time) - if(strlen($this->errorMsg())) { - $retval = 0; - } - } - $this->get_transaction_status(); - return($retval); - }//end commitTrans() - //========================================================================= - - - - //========================================================================= - // returns true/false - function rollbackTrans() { - $retval = $this->exec("ABORT"); - $this->get_transaction_status(); - return($retval); - }//end rollbackTrans() - //========================================================================= - - - - //////////////////////// - // SQL String Related - //////////////////////// - - - - //========================================================================= - /** - * Gets rid of evil characters that might lead ot SQL injection attacks. - */ - function querySafe($string) { - return($this->gfObj->cleanString($string,"query")); - }//end querySafe() - //========================================================================= - - - - //========================================================================= - /** - * Make it SQL safe. - */ - function sqlSafe($string) { - return($this->gfObj->cleanString($string,"sql")); - }//end sqlSafe() - //========================================================================= - - - - //========================================================================= - /** - * Gives textual explanation of the current status of our database - * connection. - * - * @param $goodOrBad (bool,optional) return good/bad status. - * - * @return (-1) (FAIL) connection is broken - * @return (0) (FAIL) error was encountered (transient error) - * @return (1) (PASS) useable - * @return (2) (PASS) useable, but not just yet (working - * on something) - */ - function get_transaction_status($goodOrBad=TRUE) { - $myStatus = pg_transaction_status($this->connectionID); - $text = 'unknown'; - switch($myStatus) { - case PGSQL_TRANSACTION_IDLE: { - //No query in progress: it's idle. - $goodOrBadValue = 1; - $text = 'idle'; - $this->inTrans = FALSE; - } - break; - - - case PGSQL_TRANSACTION_ACTIVE: { - //there's a command in progress. - $goodOrBadValue = 2; - $text = 'processing'; - } - break; - - - case PGSQL_TRANSACTION_INTRANS: { - //connection idle within a valid transaction block. - $goodOrBadValue = 1; - $text = 'valid transaction'; - $this->inTrans = TRUE; - } - break; - - - case PGSQL_TRANSACTION_INERROR: { - //connection idle within a broken transaction. - $goodOrBadValue = 0; - $text = 'failed transaction'; - $this->inTrans = TRUE; - } - break; - - - case PGSQL_TRANSACTION_UNKNOWN: - default: { - //the connection is bad. - $goodOrBadValue = -1; - $text = 'bad connection'; - } - break; - } - - //do they want text or the good/bad number? - $retval = $text; - $this->transactionStatus = $goodOrBadValue; - if($goodOrBad) { - //they want the number. - $retval = $goodOrBadValue; - } - - return($retval); - }//end get_transaction_status() - //========================================================================= - - - - //========================================================================= - public function is_connected() { - $retval = FALSE; - if(is_resource($this->connectionID) && $this->isConnected === TRUE) { - $retval = TRUE; - } - - return($retval); - }//end is_connected() - //========================================================================= - - - - //========================================================================= - /** - * Create a prepared statement. - */ - public function create_prepared_statement($planName,array $fieldToType, $statement) { - $retval = FALSE; - //store the mappings. - $this->preparedStatements[$planName] = $fieldToType; - - //TODO: check that the string in "$statement" has the same number of "${n}" as are in "$fieldToType". - - $dataTypeString = ""; - foreach($fieldToType as $field => $type) { - $dataTypeString = $this->gfObj->create_list($dataTypeString, $type, ", "); - } - - $sql = "PREPARE ". $planName ."(". $dataTypeString .") AS ". $statement; - - $myNumrows = $this->exec($sql); - $myDberror = $this->errorMsg(); - - if(!strlen($myDberror)) { - $retval = TRUE; - } - else { - throw new exception(__METHOD__ .": failed to create prepared statement '". $planName ."'... dberror::: ". $myDberror ."\n\nSQL::: ". $sql); - } - - return($retval); - }//end create_prepared_statement() - //========================================================================= - - - - //========================================================================= - /** - * Run a statement prepared by this object. - * - * NOTE: determination of rows affected (numAffected) vs. rows returned (numRows) - * must be done by the user via the referenced methods. - */ - public function run_prepared_statement($name, array $data) { - $retval = FALSE; - if(is_array($this->preparedStatements[$name]) && count($data) == count($this->preparedStatements[$name])) { - $this->result = pg_execute($this->connectionID, $name, $data); - $dberror = $this->errorMsg(); - - if(!strlen($dberror)) { - $retval = TRUE; - } - } - else { - throw new exception(__METHOD__ .": invalid statement name (". $name ."), or incorrect number of elements"); - } - - return($retval); - }//end run_prepared_statement() - //========================================================================= - - - - //========================================================================= - /** - * Starts a copy command. - * - * TODO: implement safeguards so they can only put a line until the copy is ended. - */ - public function start_copy($tableName, array $fields) { - $retval = FALSE; - $copyStmt = "COPY ". $tableName ." (". $this->gfObj->string_from_array($fields, NULL, ", ") . ") FROM stdin;"; - $this->exec($copyStmt); - if(!strlen($this->errorMsg())) { - //TODO: set something here so that NOTHING ELSE can be done except put_line() and end_copy(). - $this->copyInProgress = TRUE; - $retval = TRUE; - } - else { - $this->end_copy(); - $retval = FALSE; - } - - return($retval); - }//end start_copy() - //========================================================================= - - - - //========================================================================= - /** - * Used to send a line to the COPY in progress (only if it was initiated by - * the internal start_copy() method). - * - * NOTE: the "end-of-copy" line, '\.', should NEVER be sent here. - */ - public function put_line($line) { - $retval = FALSE; - if($this->copyInProgress === TRUE) { - $myLine = trim($line); - $myLine .= "\n"; - - $retval = pg_put_line($this->connectionID, $myLine); - } - else { - throw new exception(__METHOD__ .": cannot send line if no copy is in progress"); - } - - return($retval); - }//end put_line() - //========================================================================= - - - - //========================================================================= - public function end_copy() { - if($this->copyInProgress === TRUE) { - //send the end-of-copy line... - $this->put_line("\\.\n"); - } - - $retval = pg_end_copy($this->connectionID); - - return($retval); - }//end end_copy() - //========================================================================= - - - - //========================================================================= - /** - * Determines how many times a transaction has been started. Starting - * multiple transactions does NOT protect the outer transaction from - * problems that occur in the inner transaction. In fact, it does the - * opposite: it protects the code from committing too early (which might - * destroy something that depending on the transaction). - */ - public function get_transaction_level() { - if(is_array($this->transactionTree)) { - $retval = count($this->transactionTree); - } - else { - $retval = 0; - } - - return($retval); - }//end get_transaction_level() - //========================================================================= - - - - //========================================================================= - /** - * Simple way to determine if the current connection is inside a - * transaction or not. - */ - public function is_in_transaction() { - $retval = 0; - if($this->inTrans || $this->get_transaction_level() != 0) { - $retval = TRUE; - } - return($retval); - }//end is_in_transaction() - //========================================================================= - - - } // end class phpDB ?> Added: trunk/1.1/lib/cs-content/db_types/cs_phpDB__pgsql.class.php =================================================================== --- trunk/1.1/lib/cs-content/db_types/cs_phpDB__pgsql.class.php (rev 0) +++ trunk/1.1/lib/cs-content/db_types/cs_phpDB__pgsql.class.php 2008-02-07 03:55:00 UTC (rev 795) @@ -0,0 +1,1160 @@ +<?php + +/* + * A class for generic PostgreSQL database access. + * + * SVN INFORMATION::: + * SVN Signature:::::::: $Id: cs_phpDB__pgsql.class.php 252 2008-01-31 21:57:49Z crazedsanity $ + * Last Committted Date: $Date: 2008-01-31 15:57:49 -0600 (Thu, 31 Jan 2008) $ + * Last Committed Path:: $HeadURL: https://cs-content.svn.sourceforge.net/svnroot/cs-content/releases/0.10/db_types/cs_phpDB__pgsql.class.php $ + * + */ + +/////////////////////// +// ORIGINATION INFO: +// Author: Trevin Chow (with contributions from Lee Pang, wle...@ho...) +// Email: t1...@ma... +// Date: February 21, 2000 +// Last Updated: August 14, 2001 +// +// Description: +// Abstracts both the php function calls and the server information to POSTGRES +// databases. Utilizes class variables to maintain connection information such +// as number of rows, result id of last operation, etc. +// +/////////////////////// + +//TODO: option to not use layered transactions +//TODO: rollbackTrans() in layered transaction causes abort when final layer is committed/aborted +//TODO: stop sending queries to backend when transction is bad/aborted. +//TODO: commit/abort specific layer requests (i.e. if there's 8 layers & the first is named "x", calling commitTrans("x") will cause the whole transaction to commit & all layers to be destroyed. + +class cs_phpDB__pgsql { + + /** Internal result set pointer. */ + protected $result = NULL; + + /** Internal error code. */ + protected $errorCode = 0; + + /** Status of the current transaction. */ + protected $transStatus = NULL; + + /** Whether there is a transaction in progress or not. */ + protected $inTrans = FALSE; + + /** Holds the last query performed. */ + protected $lastQuery = NULL; + + /** List of queries that have been run */ + protected $queryList=array(); + + /** How many seconds to wait for a query before cancelling it. */ + protected $timeOutSeconds = NULL; + + /** Internal check to determine if a connection has been established. */ + protected $isConnected=FALSE; + + /** Internal check to determine if the parameters have been set. */ + protected $paramsAreSet=FALSE; + + /** Resource handle. */ + protected $connectionID = -1; + + /** Hostname or IP to connect to */ + protected $host; + + /** Port to connect to (default for Postgres is 5432) */ + protected $port; + + /** Name of the database */ + protected $dbname; + + /** Username to connect to the database */ + protected $user; + + /** password to connect to the database */ + protected $password; + + /** Row counter for looping through records */ + protected $row = -1; + + /** cs_globalFunctions object, for string stuff. */ + protected $gfObj; + + /** Internal check to ensure the object has been properly created. */ + protected $isInitialized=FALSE; + + /** List of prepared statements, indexed off the name, with the sub-array being fieldname=>dataType. */ + protected $preparedStatements = array(); + + /** Set to TRUE to save all queries into an array. */ + protected $useQueryList=FALSE; + + /** array that essentially remembers how many times beginTrans() was called. */ + protected $transactionTree = NULL; + + //////////////////////////////////////////// + // Core primary connection/database function + //////////////////////////////////////////// + + + //========================================================================= + public function __construct() { + $this->gfObj = new cs_globalFunctions; + + if(defined('DEBUGPRINTOPT')) { + $this->gfObj->debugPrintOpt = DEBUGPRINTOPT; + } + + $this->isInitialized = TRUE; + }//end __construct() + //========================================================================= + + + + //========================================================================= + /** + * Make sure the object is sane. + */ + final protected function sanity_check() { + if($this->isInitialized !== TRUE) { + throw new exception(__METHOD__ .": not properly initialized"); + } + }//end sanity_check() + //========================================================================= + + + + //========================================================================= + /** + * Set appropriate parameters for database connection + */ + public function set_db_info(array $params){ + $this->sanity_check(); + $required = array('host', 'port', 'dbname', 'user', 'password'); + + $requiredCount = 0; + foreach($params as $index=>$value) { + if(property_exists($this, $index) && in_array($index, $required)) { + $this->$index = $value; + $requiredCount++; + } + else { + throw new exception(__METHOD__. ": property (". $index .") does " . + "not exist or isn't allowed"); + } + } + + if($requiredCount == count($required)) { + $this->paramsAreSet = TRUE; + } + else { + throw new exception(__METHOD__ .": required count (". $requiredCount + .") does not match required number of fields (". count($required) .")"); + } + }//end set_db_info() + //========================================================================= + + + + //========================================================================= + /** + * Wrapper for close() + */ + function disconnect() { + //Disconnect from $database + return($this->close()); + }//end disconnect() + //========================================================================= + + + + //========================================================================= + /** + * Standard method to close connection. + */ + function close() { + $this->isConnected = FALSE; + $retval = null; + if($this->connectionID != -1) { + $retval = pg_close($this->connectionID); + } + else { + throw new exception(__METHOD__ .": Failed to close connection: connection is invalid"); + } + + return($retval); + }//end close() + //========================================================================= + + + + //========================================================================= + /** + * Connect to the database + */ + function connect(array $dbParams=NULL, $forceNewConnection=FALSE){ + $this->sanity_check(); + $retval = NULL; + if(is_array($dbParams)) { + $this->set_db_info($dbParams); + } + + if($this->paramsAreSet === TRUE && $this->isConnected === FALSE) { + + $myConnArr = array( + 'host' => $this->host, + 'port' => $this->port, + 'dbname' => $this->dbname, + 'user' => $this->user, + 'password' => $this->password + ); + + //make it into a string separated by spaces, don't clean anything, remove null elements + $connStr = $this->gfObj->string_from_array($myConnArr, 'url', " "); + + //start output buffer for displaying error. + ob_start(); + if($forceNewConnection) { + $connID = pg_connect($connStr, PGSQL_CONNECT_FORCE_NEW); + } + else { + $connID =pg_connect($connStr); + } + $connectError = ob_get_contents(); + ob_end_clean(); + + if(is_resource($connID)) { + $this->errorCode=0; + $this->connectionID = $connID; + $this->isConnected = TRUE; + $retval = $this->connectionID; + } + else { + throw new exception(__METHOD__ .": FATAL ERROR: ". $connectError); + } + } + else { + throw new exception(__METHOD__ .": paramsAreSet=(". $this->paramsAreSet ."), isConnected=(". $this->isConnected .")"); + } + + return($retval); + }//end connect() + //========================================================================= + + + + //========================================================================= + function get_hostname() { + $this->sanity_check(); + return($this->host); + }//end get_hostname() + //========================================================================= + + + + //========================================================================= + /** + * Run sql queries + * + * TODO: re-implement query logging (setting debug, logfilename, etc). + */ + function exec($query) { + $this->lastQuery = $query; + if($this->useQueryList) { + $this->queryList[] = $query; + } + $returnVal = false; + + if(($this->get_transaction_status() != -1) && ($this->connectionID != -1)) { + $this->result = @pg_query($this->connectionID, $query); + + if($this->result !== false) { + if (eregi("^[[:space:]]*select", $query)) { + //If we didn't have an error and we are a select statement, move the pointer to first result + $numRows = $this->numRows(); + if($numRows > 0) { + $this->move_first(); + } + $returnVal = $numRows; + + } + else { + //We got something other than an update. Use numAffected + $returnVal = $this->numAffected(); + } + } + } + return($returnVal); + }//end exec() + //========================================================================= + + + + //========================================================================= + /** + * Returns any error caused by the last executed query. + * + * @return NULL OK: no error + * @return (string) FAIL: contains error returned from the query. + */ + function errorMsg($setMessage=NULL,$logError=NULL) { + $this->sanity_check(); + if ($this->connectionID < 0) { + switch ($this->errorCode) { + //############################################### + case -1: + $retVal = "FATAL ERROR - CONNECTION ERROR: RESOURCE NOT FOUND"; + break; + //############################################### + + //############################################### + case -2: + $retVal = "FATAL ERROR - CLASS ERROR: FUNCTION CALLED WITHOUT PARAMETERS"; + break; + //############################################### + + //############################################### + case -3: + $retVal = "Query exceeded maximum timeout (". $this->timeoutSeconds .")"; + break; + //############################################### + + //############################################### + default: + $retVal = null; + //############################################### + } + } else { + $retVal = pg_last_error($this->connectionID); + } + + return($retVal); + }//end errorMsg() + //========================================================================= + + + + + //////////////////// + // Cursor movement + //////////////////// + + + + + //========================================================================= + /** + * move pointer to first row of result set + */ + function move_first() { + $this->sanity_check(); + if($this->result == NULL) { + $retval = FALSE; + } + else { + $this->set_row(0); + $retval = TRUE; + } + + return($retval); + }//end move_first() + //========================================================================= + + + + //========================================================================= + /** + * move poi... [truncated message content] |
From: <cra...@us...> - 2008-02-07 05:28:50
|
Revision: 797 http://cs-project.svn.sourceforge.net/cs-project/?rev=797&view=rev Author: crazedsanity Date: 2008-02-06 21:28:32 -0800 (Wed, 06 Feb 2008) Log Message: ----------- *** RELEASE 1.1.2 *** SUMMARY OF CHANGES::: * fix invalid/missing schema for tags during initial setup (issue #147) Modified Paths: -------------- trunk/1.1/VERSION trunk/1.1/docs/schema/cs_project.schema.sql trunk/1.1/docs/sql/setup/02__tables.sql trunk/1.1/includes/setup/3.inc Modified: trunk/1.1/VERSION =================================================================== --- trunk/1.1/VERSION 2008-02-07 03:59:47 UTC (rev 796) +++ trunk/1.1/VERSION 2008-02-07 05:28:32 UTC (rev 797) @@ -1,4 +1,4 @@ $Id:VERSION 628 2007-11-20 16:58:45Z crazedsanity $ -VERSION: 1.1.1 +VERSION: 1.1.2 $HeadURL:https://cs-project.svn.sourceforge.net/svnroot/cs-project/trunk/VERSION $ Modified: trunk/1.1/docs/schema/cs_project.schema.sql =================================================================== --- trunk/1.1/docs/schema/cs_project.schema.sql 2008-02-07 03:59:47 UTC (rev 796) +++ trunk/1.1/docs/schema/cs_project.schema.sql 2008-02-07 05:28:32 UTC (rev 797) @@ -1300,7 +1300,8 @@ CREATE TABLE tag_name_table ( tag_name_id integer NOT NULL, - name text NOT NULL + name text NOT NULL, + modifier integer NOT NULL default -1 ); Modified: trunk/1.1/docs/sql/setup/02__tables.sql =================================================================== --- trunk/1.1/docs/sql/setup/02__tables.sql 2008-02-07 03:59:47 UTC (rev 796) +++ trunk/1.1/docs/sql/setup/02__tables.sql 2008-02-07 05:28:32 UTC (rev 797) @@ -690,7 +690,8 @@ CREATE TABLE tag_name_table ( tag_name_id integer NOT NULL, - name text NOT NULL + name text NOT NULL, + modifier integer NOT NULL default -1 ); Modified: trunk/1.1/includes/setup/3.inc =================================================================== --- trunk/1.1/includes/setup/3.inc 2008-02-07 03:59:47 UTC (rev 796) +++ trunk/1.1/includes/setup/3.inc 2008-02-07 05:28:32 UTC (rev 797) @@ -790,19 +790,21 @@ //========================================================================= private function create_tag_names() { $tags = array( - 1 => 'bug', - 2 => 'feature request', - 3 => 'information', - 4 => 'network related', - 5 => 'critical', - 6 => 'exception' + 1 => array(-1, 'bug'), + 2 => array(-1, 'feature request'), + 3 => array(0, 'information'), + 4 => array(0, 'network related'), + 5 => array(-5, 'critical'), + 6 => array(-2, 'exception') ); $retval = 0; - foreach($tags as $id=>$name) { + foreach($tags as $id=>$data) { + $name = $data[1]; $insertArr = array( 'tag_name_id' => $id, - 'name' => $name + 'name' => $data[1], + 'modifier' => $data[0] ); $sql = "INSERT INTO tag_name_table ". $this->gfObj->string_from_array($insertArr, 'insert', NULL, 'sql'); $numrows = $this->db->exec($sql); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2008-03-31 01:58:29
|
Revision: 867 http://cs-project.svn.sourceforge.net/cs-project/?rev=867&view=rev Author: crazedsanity Date: 2008-03-30 18:58:27 -0700 (Sun, 30 Mar 2008) Log Message: ----------- Modify BBCode & email template to show issue ancestry. FIXES ISSUE::: #146: Email notice -- display ancestry /templates/email/helpdesk-remark.tmpl: -- change template var from {name} to "[helpdesk_id={public_id}]" so it can be parsed by the BBCode parser. /lib/bbCodeParser.class.php: * get_helpdesk_bbcode(): -- adds linkage to parent project if one is set. Modified Paths: -------------- trunk/1.1/lib/bbCodeParser.class.php trunk/1.1/templates/email/helpdesk-remark.tmpl Modified: trunk/1.1/lib/bbCodeParser.class.php =================================================================== --- trunk/1.1/lib/bbCodeParser.class.php 2008-03-31 01:56:53 UTC (rev 866) +++ trunk/1.1/lib/bbCodeParser.class.php 2008-03-31 01:58:27 UTC (rev 867) @@ -69,8 +69,18 @@ $retval = '[helpdesk_id='. $helpdeskId .']'; if(is_numeric($helpdeskId)) { try { - $data = $this->helpdeskObj->get_record($helpdeskId); - $retval = '[<a href="http://'. PROJECT_URL .'/content/helpdesk/view?ID='. $helpdeskId .'">'. $data['name'] .'</a>]'; + $data = $this->helpdeskObj->get_record($helpdeskId); + $displayName = $data['name']; + + //add project linkage if there is any... + if($data['ancestry_level'] > 1) { + //pull the ancestry string. + $parentRecord = $this->projectObj->get_parent_record($data['ancestry']); + $x = $this->projectObj->get_ancestry_link_list($parentRecord['public_id'], TRUE, TRUE, TRUE); + $displayName = $x .' / <b>'. $displayName ."</b>"; + } + + $retval = '[<a href="http://'. PROJECT_URL .'/content/helpdesk/view?ID='. $helpdeskId .'">'. $displayName .'</a>]'; } catch(exception $e) { debug_print($e->getMessage); Modified: trunk/1.1/templates/email/helpdesk-remark.tmpl =================================================================== --- trunk/1.1/templates/email/helpdesk-remark.tmpl 2008-03-31 01:56:53 UTC (rev 866) +++ trunk/1.1/templates/email/helpdesk-remark.tmpl 2008-03-31 01:58:27 UTC (rev 867) @@ -12,7 +12,7 @@ </tr> <tr> <th>Name of Issue:</th> - <td><pre>{name}</pre></td> + <td><pre>[helpdesk_id={public_id}]</pre></td> </tr> <tr> <th>Submitted by:</th> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2008-03-31 02:19:50
|
Revision: 868 http://cs-project.svn.sourceforge.net/cs-project/?rev=868&view=rev Author: crazedsanity Date: 2008-03-30 19:19:47 -0700 (Sun, 30 Mar 2008) Log Message: ----------- *** RELEASE 1.1.5 *** Add ancestry link list to issue title (issue #146), plus remove wrapping from send_single_email() so wrapping isn't terrible. Modified Paths: -------------- trunk/1.1/VERSION trunk/1.1/lib/globalFunctions.php Modified: trunk/1.1/VERSION =================================================================== --- trunk/1.1/VERSION 2008-03-31 01:58:27 UTC (rev 867) +++ trunk/1.1/VERSION 2008-03-31 02:19:47 UTC (rev 868) @@ -1,4 +1,4 @@ $Id:VERSION 628 2007-11-20 16:58:45Z crazedsanity $ -VERSION: 1.1.4 +VERSION: 1.1.5 $HeadURL:https://cs-project.svn.sourceforge.net/svnroot/cs-project/trunk/VERSION $ Modified: trunk/1.1/lib/globalFunctions.php =================================================================== --- trunk/1.1/lib/globalFunctions.php 2008-03-31 01:58:27 UTC (rev 867) +++ trunk/1.1/lib/globalFunctions.php 2008-03-31 02:19:47 UTC (rev 868) @@ -1756,7 +1756,6 @@ $mail->ContentType = "text/html"; $mail->Subject = $subject; $mail->Body = $bbCodeParser->parseString($body); - $mail->WordWrap = 75; $logsObj = new logsClass($db, 'Email'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |