Thread: [CS-Project-svn_notify] SF.net SVN: cs-project: [819] trunk/1.2/lib
Brought to you by:
crazedsanity
From: <cra...@us...> - 2008-02-09 10:01:15
|
Revision: 819 http://cs-project.svn.sourceforge.net/cs-project/?rev=819&view=rev Author: crazedsanity Date: 2008-02-09 02:01:10 -0800 (Sat, 09 Feb 2008) Log Message: ----------- Superficial changes for __autoload() and information in an exception from logsClass. Modified Paths: -------------- trunk/1.2/lib/logsClass.php trunk/1.2/lib/site_config.php Modified: trunk/1.2/lib/logsClass.php =================================================================== --- trunk/1.2/lib/logsClass.php 2008-02-09 05:34:13 UTC (rev 818) +++ trunk/1.2/lib/logsClass.php 2008-02-09 10:01:10 UTC (rev 819) @@ -501,7 +501,7 @@ } } else { - throw new exception(__METHOD__ .": failed to create new log_category"); + throw new exception(__METHOD__ .": failed to create new log_category (". $catName .")"); } return($retval); Modified: trunk/1.2/lib/site_config.php =================================================================== --- trunk/1.2/lib/site_config.php 2008-02-09 05:34:13 UTC (rev 818) +++ trunk/1.2/lib/site_config.php 2008-02-09 10:01:10 UTC (rev 819) @@ -185,13 +185,12 @@ } } - if($retval == TRUE) { - return($retval); - } - else { + if($retval !== TRUE) { throw new exception(__FUNCTION__ .": unable to find class file for (". $className .")"); } + return($retval); + }//end __autoload() //========================================================================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2008-02-17 21:57:20
|
Revision: 842 http://cs-project.svn.sourceforge.net/cs-project/?rev=842&view=rev Author: crazedsanity Date: 2008-02-17 13:57:13 -0800 (Sun, 17 Feb 2008) Log Message: ----------- Re-add redirect to setup page if config file doesn't exist. /lib/site_config.php: * if the "PROJECT__INITIALSETUP" constant isn't defined, call config::do_setup_redirect() to redirect to the setup page. /lib/config.class.php: * __construct(): -- remove confusing comment. * do_setup_redirect() [NEW]: -- redirect the the /setup page only if we're not already there. -- only add the "?from=" if there's something useful to put there. Modified Paths: -------------- trunk/1.2/lib/config.class.php trunk/1.2/lib/site_config.php Modified: trunk/1.2/lib/config.class.php =================================================================== --- trunk/1.2/lib/config.class.php 2008-02-14 08:24:34 UTC (rev 841) +++ trunk/1.2/lib/config.class.php 2008-02-17 21:57:13 UTC (rev 842) @@ -21,7 +21,6 @@ $this->fileName = $fileName; } - //Redirect them to the setup page. if(!file_exists($this->fileName)) { $this->fileExists = FALSE; } @@ -164,5 +163,19 @@ $page->add_template_var($defaultRowName, $parsedRows); }//end build_update_interface() //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function do_setup_redirect() { + if(!preg_match('/^setup/', $_SERVER['REQUEST_URI'])) { + $goHere = '/setup'; + if(strlen($_SERVER['REQUEST_URI']) > 1) { + $goHere .= '?from='. urlencode($_SERVER['REQUEST_URI']); + } + $this->gf->conditional_header($goHere); + } + }//end do_setup_redirect() + //------------------------------------------------------------------------- }//end config{} ?> \ No newline at end of file Modified: trunk/1.2/lib/site_config.php =================================================================== --- trunk/1.2/lib/site_config.php 2008-02-14 08:24:34 UTC (rev 841) +++ trunk/1.2/lib/site_config.php 2008-02-17 21:57:13 UTC (rev 842) @@ -70,6 +70,7 @@ if(!defined("PROJECT__INITIALSETUP") || PROJECT__INITIALSETUP !== TRUE) { + $configObj->do_setup_redirect(); $config = $configObj->read_config_file(FALSE); if(($config['WORKINGONIT'] != "0" && strlen($config['WORKINGONIT'])) || strlen($config['WORKINGONIT']) > 1) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2008-02-20 19:58:48
|
Revision: 846 http://cs-project.svn.sourceforge.net/cs-project/?rev=846&view=rev Author: crazedsanity Date: 2008-02-20 11:57:28 -0800 (Wed, 20 Feb 2008) Log Message: ----------- Move stuff into config{} from site_config.php to check for & run upgrades. Modified Paths: -------------- trunk/1.2/lib/config.class.php trunk/1.2/lib/site_config.php Modified: trunk/1.2/lib/config.class.php =================================================================== --- trunk/1.2/lib/config.class.php 2008-02-20 19:46:29 UTC (rev 845) +++ trunk/1.2/lib/config.class.php 2008-02-20 19:57:28 UTC (rev 846) @@ -92,90 +92,62 @@ //------------------------------------------------------------------------- - /** - * Create a page (portion of a page, actually) to set/update config settings. - */ - public function build_update_interface(cs_genericPage &$page) { - - //read the sample config. - $config = new config(dirname(__FILE__) .'/config.xml', FALSE); - $myData = $config->get_config_contents(); - - //parse the sample config for it's attributes, so we can display the page properly. - $sampleConfig = new config(dirname(__FILE__) .'/../docs/samples/sample_config.xml', FALSE); - $systemData = $sampleConfig->get_config_contents(FALSE); - - $mainAttributes = $myData['attributes']; - - unset($myData['type'], $myData['attributes']); - - $parsedRows = ""; - $defaultRowName = 'setting_text'; - foreach($systemData as $indexName=>$defaultValue) { - if(is_array($myData) && isset($myData[$indexName])) { - $value = $myData[$indexName]; + public function do_setup_redirect() { + if(!preg_match('/^setup/', $_SERVER['REQUEST_URI']) && !$_SESSION[SESSION_SETUP_KEY]) { + + //set something in the session so we know. + if(!isset($_SESSION[SESSION_SETUP_KEY])) { + $_SESSION[SESSION_SETUP_KEY]++; } else { - $value = $systemData[$indexName]['value']; + throw new exception(__METHOD__ .": setup key (". SESSION_SETUP_KEY .") found in session already"); } - $attributes = $systemData[$indexName]['attributes']; - $indexName = strtolower($indexName); - //pull the appropriate template row. - $rowName = $defaultRowName; - if(strlen($attributes['TYPE'])) { - $rowName = 'setting_'. $attributes['TYPE']; - - $optionList = NULL; - if($attributes['TYPE'] == 'select' && isset($attributes['OPTIONS'])) { - #debug_print(explode('|', $attributes['OPTIONS'])); - $tmpOptionList = explode('|', $attributes['OPTIONS']); - $optionList = array(); - foreach($tmpOptionList as $optionInfo) { - $x = explode('=', $optionInfo); - $optionList[$x[0]] = $x[1]; - } - $optionList = $page->gfObj->array_as_option_list($optionList, $attributes['DEFAULT']); - } - } - if(!isset($page->templateRows[$rowName])) { - $page->set_block_row('content', $rowName); - if(!isset($page->templateRows[$rowName])) { - throw new exception(__METHOD__ .": failed to retrieve block row named (". $rowName .")"); - } - } + $goHere = '/setup'; - //now parse stuff into the row... - $repArr = array( - 'disabled' => $attributes['disabled'], - 'index' => $indexName, - 'title' => $attributes['TITLE'], - 'description' => $attributes['DESCRIPTION'], - 'value' => $value - ); - if(!is_null($optionList)) { - $repArr['setting_select__normal'] = $optionList; + if(strlen($_SERVER['REQUEST_URI']) > 1) { + $goHere .= '?from='. urlencode($_SERVER['REQUEST_URI']); } - $parsedRows .= $page->mini_parser($page->templateRows[$rowName], $repArr); + $this->gf->conditional_header($goHere); } - #debug_print($parsedRows); - $page->add_template_var($defaultRowName, $parsedRows); - }//end build_update_interface() + }//end do_setup_redirect() //------------------------------------------------------------------------- //------------------------------------------------------------------------- - public function do_setup_redirect() { - if(!preg_match('/^setup/', $_SERVER['REQUEST_URI'])) { - $goHere = '/setup'; - if(strlen($_SERVER['REQUEST_URI']) > 1) { - $goHere .= '?from='. urlencode($_SERVER['REQUEST_URI']); + public function check_site_status() { + if(!defined("PROJECT__INITIALSETUP") || PROJECT__INITIALSETUP !== TRUE) { + $this->do_setup_redirect(); + $config = $this->read_config_file(FALSE); + + if(($config['WORKINGONIT'] != "0" && strlen($config['WORKINGONIT'])) || strlen($config['WORKINGONIT']) > 1) { + //TODO: consider making this look prettier... + $details = "The website/database is under construction... try back in a bit."; + if(preg_match('/upgrade/i', $config['WORKINGONIT'])) { + $details = "<b>Upgrade in progress</b>: ". $config['WORKINGONIT']; + } + elseif(strlen($config['WORKINGONIT']) > 1) { + $details .= "MORE INFORMATION::: ". $config['WORKINGONIT']; + } + throw new exception($details); } - $this->gf->conditional_header($goHere); + else { + //don't panic: we're going to check for upgrades, but this doesn't + // necessarily mean anything will ACTUALLY be upgraded. + $upgrade = new upgrade; + if($upgrade->upgrade_in_progress()) { + throw new exception("Upgrade in progress... reload the page after a few minutes and it should be complete. :) "); + } + else { + $upgrade->check_versions(); + } + $this->read_config_file(TRUE); + } } - }//end do_setup_redirect() + }//end check_site_status() //------------------------------------------------------------------------- + }//end config{} ?> \ No newline at end of file Modified: trunk/1.2/lib/site_config.php =================================================================== --- trunk/1.2/lib/site_config.php 2008-02-20 19:46:29 UTC (rev 845) +++ trunk/1.2/lib/site_config.php 2008-02-20 19:57:28 UTC (rev 846) @@ -25,9 +25,8 @@ require_once(dirname(__FILE__) .'/config.class.php'); define(CONFIG_FILENAME, 'config.xml'); -//Set of functions that should be usefull to everyone +define(SESSION_SETUP_KEY, '___setup_key___'); - set_exception_handler('exception_handler'); //########################################################################## @@ -68,36 +67,11 @@ check_external_lib_versions(); - -if(!defined("PROJECT__INITIALSETUP") || PROJECT__INITIALSETUP !== TRUE) { - $configObj->do_setup_redirect(); - $config = $configObj->read_config_file(FALSE); - - if(($config['WORKINGONIT'] != "0" && strlen($config['WORKINGONIT'])) || strlen($config['WORKINGONIT']) > 1) { - //TODO: consider making this look prettier... - $details = "The website/database is under construction... try back in a bit."; - if(preg_match('/upgrade/i', $config['WORKINGONIT'])) { - $details = "<b>Upgrade in progress</b>: ". $config['WORKINGONIT']; - } - elseif(strlen($config['WORKINGONIT']) > 1) { - $details .= "MORE INFORMATION::: ". $config['WORKINGONIT']; - } - throw new exception($details); - } - else { - //don't panic: we're going to check for upgrades, but this doesn't - // necessarily mean anything will ACTUALLY be upgraded. - $upgrade = new upgrade; - if($upgrade->upgrade_in_progress()) { - throw new exception("Upgrade in progress... reload the page after a few minutes and it should be complete. :) "); - } - else { - $upgrade->check_versions(); - } - $configObj->read_config_file(TRUE); - } -} +//call a method to see if setup should run. +$configObj->check_site_status(); + + if($_SERVER['DOCUMENT_ROOT']) { //it was called from the web... $GLOBALS['SITE_ROOT'] = $_SERVER['DOCUMENT_ROOT']; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2008-03-28 05:16:41
|
Revision: 857 http://cs-project.svn.sourceforge.net/cs-project/?rev=857&view=rev Author: crazedsanity Date: 2008-03-27 22:16:39 -0700 (Thu, 27 Mar 2008) Log Message: ----------- Old site config constant, thoughts + pseudo-code for config::check_site_status(). Modified Paths: -------------- trunk/1.2/lib/config.class.php trunk/1.2/lib/site_config.php Modified: trunk/1.2/lib/config.class.php =================================================================== --- trunk/1.2/lib/config.class.php 2008-03-27 04:43:00 UTC (rev 856) +++ trunk/1.2/lib/config.class.php 2008-03-28 05:16:39 UTC (rev 857) @@ -117,35 +117,96 @@ //------------------------------------------------------------------------- + /** + * Determines if the site is a fresh install, undergoing setup, being + * upgraded (by someone else), or good to go. + * + * @param (void) No parameters accepted + * + * TODO: make this actually WORK. + * TODO: match actual returns with those specified below + * TODO: implement a "reload timer" so the page with do a meta-refresh after X minutes/seconds (make sure any POST vars are retained!!!) + * TODO: instead of a ton of returns, just set true/false for return, and have internal message explaining what's up. + * + * @return TRUE OK: display normal page (no upgrade/setup needed/running) + * @return 1 OK: setup required (perform redirect) + * @return 2 OK: setup initiated by current user (display setup page) + * @return 3 ERROR: setup initiated by OTHER user (show "setup running" error) + * @return 4 OK: upgrade required (starts upgrade process, then displays normal page) + * @return 5 ERROR: upgrade started by other user (show temporary "upgrade in progress" message, set reload timer) + */ public function check_site_status() { - if(!defined("PROJECT__INITIALSETUP") || PROJECT__INITIALSETUP !== TRUE) { - $this->do_setup_redirect(); - $config = $this->read_config_file(FALSE); + + //============================================================= + //BEGIN pseudo code: + //-------------------------------------------------- + + + if($this->configFileExists()) { + //got an existing config file. - if(($config['WORKINGONIT'] != "0" && strlen($config['WORKINGONIT'])) || strlen($config['WORKINGONIT']) > 1) { - //TODO: consider making this look prettier... - $details = "The website/database is under construction... try back in a bit."; - if(preg_match('/upgrade/i', $config['WORKINGONIT'])) { - $details = "<b>Upgrade in progress</b>: ". $config['WORKINGONIT']; + if($this->isWorkingOnItSet()) { + //site access is locked (probably an upgrade); get the message and show 'em. + $retval = $this->isWorkingOnItSet(TRUE); + $this->showFatalError($retval); + } + elseif($this->setupConfigExists()) { + if($this->setupConfigExists() === 'current_user') { + //the currently logged-in user is actually running the setup, no worries. + $retval = 'undergoing setup by current user'; } - elseif(strlen($config['WORKINGONIT']) > 1) { - $details .= "MORE INFORMATION::: ". $config['WORKINGONIT']; + else { + //tell 'em somebody is working on setup and to WAIT. + $retval = $this->showSetupMessage(); } - throw new exception($details); } else { - //don't panic: we're going to check for upgrades, but this doesn't - // necessarily mean anything will ACTUALLY be upgraded. - $upgrade = new upgrade; - if($upgrade->upgrade_in_progress()) { - throw new exception("Upgrade in progress... reload the page after a few minutes and it should be complete. :) "); + //config exists, site not locked... GOOD TO GO! + $retval = $this->setOkay(); + } + } + else { + //check for the OLD config file. + if($this->oldConfigFileExists()) { + //copy old file to new location... + $this->copyOldConfigFile(); + + //now check if the site is locked. + if($this->isWorkingOnItSet()) { + //upgrade running. Show 'em the message. + $retval = $this->isWorkingOnItSet(TRUE); + $this->showFatalError($retval); } + elseif($this->setupConfigExists()) { + //SETUP IN PROGRESS... + + if($this->setupConfigExists() === 'current_user') { + //the currently logged-in user is actually running the setup, no worries. + $retval = 'undergoing setup by current user'; + } + else { + //tell 'em somebody is working on setup and to WAIT. + $retval = $this->showSetupMessage(); + } + } else { - $upgrade->check_versions(); + //good to go! + $retval=$this->setOkay(); } - $this->read_config_file(TRUE); } + else { + //okay, no config file (new or old), no setup running, so current user has option + // to run setup (viewing the page not enough; must click something to create the + // setup config file which locks setup to their session) + $this->do_setup_redirect(); + } } + + return($retval); + //-------------------------------------------------- + //END pseudo code; + //============================================================= + }//end check_site_status() //------------------------------------------------------------------------- Modified: trunk/1.2/lib/site_config.php =================================================================== --- trunk/1.2/lib/site_config.php 2008-03-27 04:43:00 UTC (rev 856) +++ trunk/1.2/lib/site_config.php 2008-03-28 05:16:39 UTC (rev 857) @@ -29,6 +29,11 @@ define(CONFIG_FILE_LOCATION, CONFIG_DIRECTORY .'/'. CONFIG_FILENAME); define(SESSION_SETUP_KEY, '___setup_key___'); +//location where the config file USED to be, for the purpose of upgrading from previous versions. +define(OLD_CONFIG_DIRECTORY, 'lib'); +define(OLD_CONFIG_FILENAME, CONFIG_FILENAME); +define(OLD_CONFIG_FILE_LOCATION, OLD_CONFIG_DIRECTORY .'/'. OLD_CONFIG_FILENAME); + set_exception_handler('exception_handler'); //TODO: turn off if it's not a dev site, but NOT if setup is running (so they can see problems). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2008-03-30 05:44:21
|
Revision: 859 http://cs-project.svn.sourceforge.net/cs-project/?rev=859&view=rev Author: crazedsanity Date: 2008-03-29 22:44:19 -0700 (Sat, 29 Mar 2008) Log Message: ----------- Implemented config::check_site_status() to determine if site is okay, locked, going through setup by another user, or if the current user has locked the setup. /lib/config.class.php: * MAIN::: -- NEW PROPERTY: siteStatus -- NEW PROPERTY: setupRequired=FALSE -- NEW PROPERTY: config * __construct(): -- run check to ensure the CONFIG_DIRECTORY (rw) is writable; if it's not, throw an exception. -- read the config file into $this->config * do_setup_redirect() -- only do a redirect if site status is okay, setup is required, and the current URL isn't /setup. -- call create_setup_config() to create /rw/setup.xml, so we know who is running the setup. * check_site_status(): -- updated header. -- always check if there's an old config; if there is, copy it to the rw directory & delete the old file. -- intelligent checks: if there's a setup file, site status is only good if the current user is the owner. -- if the config file exists, make sure the site isn't locked. -- if there's no config, site status is good & setupRequired is set. * is_workingonit_set() [NEW]: -- determines if the "WORKINGONIT" section of the site config has caused the site to be locked or not. * setup_config_exists() [NEW]: -- determines if setup is already being run, optionally saying if the current user owns the setup process. -- NOTE: the check for ownership should probably be moved to another method for sanity's sake. * is_setup_required() [NEW]: -- returns the value of the private property "setupRequired". * create_setup_config() [NEW]: -- create a setup config file (rw/setup.xml). * get_site_status() [NEW]: -- return the value of the private property "siteStatus". /lib/site_config.php: * define where and what the setup config file is. * turn on error reporting. * when creating config{}, pass CONFIG_FILE_LOCATION instead of deriving it. * use config::check_site_status() to determine if it needs to be setup, has already been setup, setup running by other users, etc. * removed an old global SITE_ROOT setting for CLI scripts. Modified Paths: -------------- trunk/1.2/lib/config.class.php trunk/1.2/lib/site_config.php Modified: trunk/1.2/lib/config.class.php =================================================================== --- trunk/1.2/lib/config.class.php 2008-03-30 04:08:45 UTC (rev 858) +++ trunk/1.2/lib/config.class.php 2008-03-30 05:44:19 UTC (rev 859) @@ -8,8 +8,10 @@ private $gf; private $fileExists; - + private $siteStatus; + private $setupRequired = FALSE; private $fileName; + private $config; //------------------------------------------------------------------------- public function __construct($fileName=NULL) { @@ -27,6 +29,11 @@ else { $this->fileExists = TRUE; } + + if(!$this->fs->is_writable(CONFIG_DIRECTORY)) { + throw new exception(__METHOD__ .": the config directory (". CONFIG_DIRECTORY .") isn't writable!"); + } + $this->config = $this->get_config_contents(TRUE); }//end __construct() //------------------------------------------------------------------------- @@ -93,23 +100,17 @@ //------------------------------------------------------------------------- public function do_setup_redirect() { - if(!preg_match('/^setup/', $_SERVER['REQUEST_URI']) && !$_SESSION[SESSION_SETUP_KEY]) { - - //set something in the session so we know. - if(!isset($_SESSION[SESSION_SETUP_KEY])) { - $_SESSION[SESSION_SETUP_KEY]++; + if($this->check_site_status() && $this->setupRequired) { + if(!($_SERVER['SCRIPT_NAME'] == '/setup')) { + $this->gf->debug_print("script_name check=(". ($_SERVER['script_name'] != '/setup') .")", 1); + $goHere = '/setup'; + if(strlen($_SERVER['REQUEST_URI']) > 1 && !isset($_SESSION['setup__viewed'])) { + $goHere .= '?from='. urlencode($_SERVER['REQUEST_URI']); + } + $_SESSION['setup_redirect'] = time(); + $this->create_setup_config(); + $this->gf->conditional_header($goHere); } - else { - throw new exception(__METHOD__ .": setup key (". SESSION_SETUP_KEY .") found in session already"); - } - - - $goHere = '/setup'; - - if(strlen($_SERVER['REQUEST_URI']) > 1) { - $goHere .= '?from='. urlencode($_SERVER['REQUEST_URI']); - } - $this->gf->conditional_header($goHere); } }//end do_setup_redirect() //------------------------------------------------------------------------- @@ -129,86 +130,145 @@ * TODO: instead of a ton of returns, just set true/false for return, and have internal message explaining what's up. * * @return TRUE OK: display normal page (no upgrade/setup needed/running) - * @return 1 OK: setup required (perform redirect) - * @return 2 OK: setup initiated by current user (display setup page) - * @return 3 ERROR: setup initiated by OTHER user (show "setup running" error) - * @return 4 OK: upgrade required (starts upgrade process, then displays normal page) - * @return 5 ERROR: upgrade started by other user (show temporary "upgrade in progress" message, set reload timer) + * @return FALSE FAIL: somebody else is running setup, or the site is otherwise locked. */ public function check_site_status() { - //============================================================= - //BEGIN pseudo code: - //-------------------------------------------------- + //check for the OLD config file. + /** + * WHY THE CHECK IS HERE::: + * + * The setup system expects that the config file exists in the location + * specified by CONFIG_FILE_LOCATION; if it's not there, the site_config + * will assume setup must be run... so we have to circumvent that + * behaviour right here. + */ + if(file_exists(OLD_CONFIG_FILE_LOCATION)) { + //copy old file to new location... + if(!$this->fs->copy_file(OLD_CONFIG_FILE_LOCATION, CONFIG_FILE_LOCATION)) { + throw new exception(__METHOD__ .": failed to copy existing config into new location"); + } + $this->fs->rm(OLD_CONFIG_FILE_LOCATION); + } - if($this->configFileExists()) { + if($this->setup_config_exists()) { + if($this->setup_config_exists(TRUE)) { + //the currently logged-in user is actually running the setup, no worries. + $this->siteStatus = 'You are running setup... please continue.'; + $this->setupRequired = TRUE; + $retval = TRUE; + } + else { + //tell 'em somebody is working on setup and to WAIT. + $this->siteStatus = 'Setup is in progress by another user. Please wait.'; + $retval = FALSE; + } + } + elseif($this->fileExists) { //got an existing config file. - if($this->isWorkingOnItSet()) { - //site access is locked (probably an upgrade); get the message and show 'em. - $retval = $this->isWorkingOnItSet(TRUE); - $this->showFatalError($retval); + if($this->is_workingonit_set()) { + //site access is locked; get the message and show 'em. + $this->siteStatus = $this->is_workingonit_set(TRUE); + $retval = $this->siteStatus; } - elseif($this->setupConfigExists()) { - if($this->setupConfigExists() === 'current_user') { - //the currently logged-in user is actually running the setup, no worries. - $retval = 'undergoing setup by current user'; - } - else { - //tell 'em somebody is working on setup and to WAIT. - $retval = $this->showSetupMessage(); - } - } else { //config exists, site not locked... GOOD TO GO! - $retval = $this->setOkay(); + $this->siteStatus = 'Normal (site is setup).'; + $retval = TRUE; } } else { - //check for the OLD config file. - if($this->oldConfigFileExists()) { - //copy old file to new location... - $this->copyOldConfigFile(); + //good to go! + $this->siteStatus = 'No existing config or setup file: you may initiate the setup process now.'; + $this->setupRequired = TRUE; + $retval = TRUE; + } + + return($retval); + + }//end check_site_status() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + private function is_workingonit_set($giveValue=FALSE) { + if((is_numeric($this->config['WORKINGONIT']) && $this->config['WORKINGONIT'] == 0) || ($this->config['WORKINGONIT'] === FALSE)) { + $retval = FALSE; + } + else { + $retval = TRUE; + } + + if($giveValue === TRUE) { + $retval = $this->config['WORKINGONIT']; + } + + return($retval); + }//end is_workingonit_set() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function setup_config_exists($checkOwnership=FALSE) { + $retval = FALSE; + + $dirContents = $this->fs->ls(CONFIG_DIRECTORY); + if($dirContents[SETUP_FILENAME]) { + $retval = TRUE; + + if($checkOwnership === TRUE) { + //read the object. + $xmlParser = new xmlParser($this->fs->read(SETUP_FILE_LOCATION)); + $configData = $xmlParser->get_tree(TRUE); + $configData = $configData['CONFIG']; - //now check if the site is locked. - if($this->isWorkingOnItSet()) { - //upgrade running. Show 'em the message. - $retval = $this->isWorkingOnItSet(TRUE); - $this->showFatalError($retval); + //now that we've got the data, determine if the current user is the owner. + if($configData['OWNER_SESSION'] === session_id()) { + $retval = TRUE; } - elseif($this->setupConfigExists()) { - //SETUP IN PROGRESS... - - if($this->setupConfigExists() === 'current_user') { - //the currently logged-in user is actually running the setup, no worries. - $retval = 'undergoing setup by current user'; - } - else { - //tell 'em somebody is working on setup and to WAIT. - $retval = $this->showSetupMessage(); - } - } else { - //good to go! - $retval=$this->setOkay(); + $retval = FALSE; } } - else { - //okay, no config file (new or old), no setup running, so current user has option - // to run setup (viewing the page not enough; must click something to create the - // setup config file which locks setup to their session) - $this->do_setup_redirect(); - } } return($retval); - //-------------------------------------------------- - //END pseudo code; - //============================================================= + }//end setup_config_exists() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + public function is_setup_required() { + return($this->setupRequired); + }//end is_setup_required() + //------------------------------------------------------------------------- + + + + //------------------------------------------------------------------------- + private function create_setup_config() { + $xmlCreator = new xmlCreator('config'); + $attributes = array( + 'creation' => time() + ); + $xmlCreator->add_tag('/config/owner_session', session_id(), $attributes); - }//end check_site_status() + $this->fs->create_file(SETUP_FILE_LOCATION); + $this->fs->write($xmlCreator->create_xml_string()); + }//end create_setup_config() //------------------------------------------------------------------------- + + + //------------------------------------------------------------------------- + public function get_site_status() { + return($this->siteStatus); + }//end get_site_status() + //------------------------------------------------------------------------- }//end config{} ?> \ No newline at end of file Modified: trunk/1.2/lib/site_config.php =================================================================== --- trunk/1.2/lib/site_config.php 2008-03-30 04:08:45 UTC (rev 858) +++ trunk/1.2/lib/site_config.php 2008-03-30 05:44:19 UTC (rev 859) @@ -25,9 +25,10 @@ require_once(dirname(__FILE__) .'/config.class.php'); define(CONFIG_FILENAME, 'config.xml'); +define(SETUP_FILENAME, 'setup.xml'); define(CONFIG_DIRECTORY, 'rw'); define(CONFIG_FILE_LOCATION, CONFIG_DIRECTORY .'/'. CONFIG_FILENAME); -define(SESSION_SETUP_KEY, '___setup_key___'); +define(SETUP_FILE_LOCATION, CONFIG_DIRECTORY .'/'. SETUP_FILENAME); //location where the config file USED to be, for the purpose of upgrading from previous versions. define(OLD_CONFIG_DIRECTORY, 'lib'); @@ -39,6 +40,7 @@ //TODO: turn off if it's not a dev site, but NOT if setup is running (so they can see problems). ini_set('error_reporting', 'On'); ini_set('display_errors', 'On'); +error_reporting(E_ALL && ~E_NOTICE); //########################################################################## function exception_handler($exception) { $exceptionMessage = $exception->getMessage(); @@ -72,14 +74,24 @@ //########################################################################## -$configObj = new config(dirname(__FILE__) .'/'. CONFIG_FILENAME, FALSE); -$configObj->read_config_file(TRUE, TRUE); +$configObj = new config(CONFIG_FILE_LOCATION, FALSE); check_external_lib_versions(); //call a method to see if setup should run. -$configObj->check_site_status(); +unset($_SESSION['setup_redirect']); +if($configObj->check_site_status()) { + if($configObj->is_setup_required()) { + $configObj->do_setup_redirect(); + } +} +else { + //tell 'em what the site's status is. + //TODO: make this look nicer. + echo($configObj->get_site_status()); + exit; +} if($_SERVER['DOCUMENT_ROOT']) { @@ -89,7 +101,7 @@ } else { //called from the command line. - $GLOBALS['SITE_ROOT'] = $_SERVER['HOME'] ."/partslogistics2002"; + $GLOBALS['SITE_ROOT'] = $_SERVER['HOME']; } $GLOBALS['LIBDIR']=$GLOBALS['SITE_ROOT'] . "/lib"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cra...@us...> - 2008-04-09 03:12:05
|
Revision: 874 http://cs-project.svn.sourceforge.net/cs-project/?rev=874&view=rev Author: crazedsanity Date: 2008-04-08 20:12:02 -0700 (Tue, 08 Apr 2008) Log Message: ----------- More renaming of "todo" to "task" (issue #151) Modified Paths: -------------- trunk/1.2/lib/globalFunctions.php trunk/1.2/lib/projectClass.php Removed Paths: ------------- trunk/1.2/lib/todoClass.php Modified: trunk/1.2/lib/globalFunctions.php =================================================================== --- trunk/1.2/lib/globalFunctions.php 2008-04-09 03:11:47 UTC (rev 873) +++ trunk/1.2/lib/globalFunctions.php 2008-04-09 03:12:02 UTC (rev 874) @@ -787,7 +787,7 @@ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ case "url":{ - //an array like "array('module'='todo','action'='view','ID'=164)" to "module=todo&action=view&ID=164" + //an array like "array('module'='task','action'='view','ID'=164)" to "module=task&action=view&ID=164" if(!$separator) { $separator = "&"; } Modified: trunk/1.2/lib/projectClass.php =================================================================== --- trunk/1.2/lib/projectClass.php 2008-04-09 03:11:47 UTC (rev 873) +++ trunk/1.2/lib/projectClass.php 2008-04-09 03:12:02 UTC (rev 874) @@ -42,7 +42,7 @@ //now create all those internal objects. $this->noteObj = new noteClass($this->db); - $this->todoObj = new todoClass($this->db); + $this->taskObj = new taskClass($this->db); $this->helpdeskObj = new helpdeskClass($this->db); $this->tagObj = new tagClass($this->db); $this->logsObj = new logsClass($this->db, "Project"); @@ -123,7 +123,7 @@ * Returns all details about a given project ID. * * @param $projectId (int) ID to lookup information for. - * @param $getRelated (bool) whether the related notes/todos/issues + * @param $getRelated (bool) whether the related notes/tasks/issues * should be retrieved or not. * * @return <array> PASS: contains all data relevant to given id. @@ -161,7 +161,7 @@ $this->internalRecordId = $retval['record_id']; if($getRelated) { $retval['related'] = array( - "todo" => $this->get_todos(), + "task" => $this->get_tasks(), "note" => $this->get_notes(), "issue" => $this->get_issues() ); @@ -264,34 +264,34 @@ //========================================================================= - function get_todos() { + function get_tasks() { $retval = 0; - //attempt to get a list of the todos... - $this->todoObj->projectId = $this->projectId; + //attempt to get a list of the tasks... + $this->taskObj->projectId = $this->projectId; - $todoDisplayPref = $this->prefObj->get_pref_value_by_name('projectDetails_todoDisplayOnlyMine'); + $taskDisplayPref = $this->prefObj->get_pref_value_by_name('projectDetails_taskDisplayOnlyMine'); $critArr = array("record_id"=>$this->internalRecordId); $contactCrit = NULL; - if($todoDisplayPref != 'all') { - if($todoDisplayPref == 'mine') { + if($taskDisplayPref != 'all') { + if($taskDisplayPref == 'mine') { $contactCrit = array( 't.creator_contact_id' => $_SESSION['contact_id'], 't.assigned_contact_id' => $_SESSION['contact_id'] ); } - elseif($todoDisplayPref == 'assigned') { + elseif($taskDisplayPref == 'assigned') { $contactCrit = array( 't.assigned_contact_id' => $_SESSION['contact_id'] ); } } - $retval = $this->todoObj->get_todos($critArr, NULL, $contactCrit); + $retval = $this->taskObj->get_tasks($critArr, NULL, $contactCrit); return($retval); - }//end get_todos() + }//end get_tasks() //========================================================================= Deleted: trunk/1.2/lib/todoClass.php =================================================================== --- trunk/1.2/lib/todoClass.php 2008-04-09 03:11:47 UTC (rev 873) +++ trunk/1.2/lib/todoClass.php 2008-04-09 03:12:02 UTC (rev 874) @@ -1,652 +0,0 @@ -<?php -/* - * SVN INFORMATION::: - * ------------------ - * SVN Signature::::::: $Id$ - * Last Author::::::::: $Author$ - * Current Revision:::: $Revision$ - * Repository Location: $HeadURL$ - * Last Updated:::::::: $Date$ - */ - -class todoClass { - - var $db = NULL; - var $projectId = NULL; - var $todoId = NULL; - var $lastError = NULL; - private $recordTypeId; - - /** Object for logging stuff */ - private $logsObj; - - - //================================================================================================ - /** - * The constructor. Duh. - */ - function todoClass(&$db,$projectId=NULL,$todoId=NULL) { - - if(!is_object($db)) { - throw new exception(__METHOD__ .": invalid database handle!"); - } - $this->db = $db; - - //not *REQUIRED*, but useful. - if(is_numeric($projectId) && $projectId > 0) { - $this->projectId = $projectId; - } - - //create the logging object. - $this->logsObj = new logsClass($this->db, 'Todo'); - }//end todoClass() - //================================================================================================ - - - - //================================================================================================ - /** - * Extensible method to grab a list of todo's based upon the given criteria. - * - * @param $critArr <array> criteria to feed to string_from_array(). - * @param $primaryOrder <array> field=>asc/desc sort options. - * - * @return 0 FAIL: unable to retrieve the list. - * @return <array> PASS: list of todo's, keyed off their id. - */ - function get_todos(array $critArr, $primaryOrder=NULL, array $contactCrit=NULL) { - - if(is_array($primaryOrder)) { - $arrayKeysArr = array_keys($primaryOrder); - $arrayValsArr = array_values($primaryOrder); - - $orderBy = "t.". $arrayKeysArr[0] ." ". $arrayValsArr[0]; - } - - if(!preg_match('/todo_id/', $orderBy) || (!strlen($orderBy))) { - if(!preg_match('/status/', $orderBy)) { - $orderBy = create_list($orderBy, 'status_id'); - } - if(!preg_match('/priority/', $orderBy)) { - $orderBy = create_list($orderBy, 'priority ASC'); - } - if(!preg_match('/name/', $orderBy)) { - $orderBy = create_list($orderBy, "name"); - } - } - - //TODO: change the database to have "project" or "projekt" or "projekte" or "project_id" be the column that indicates the project it's attached to. - //if we've got a projectId set, be sure to use it. - if(!is_array($critArr)) { - $details = __METHOD__ .": no criteria"; - $this->logsObj->log_dberror($details); - throw new exception($details); - } - - //now, fix the index names if the field exists in both tables... - $duplicateColumnsArr = array("record_id", "name", "contact_id", "progress"); - - foreach($critArr as $field=>$value) { - if(in_array($field, $duplicateColumnsArr)) { - // - $newKey = "t.". $field; - $critArr[$newKey] = $value; - unset($critArr[$field]); - } - } - - - $criteria = string_from_array($critArr, "select"); "where ". $criteria; - if(is_array($contactCrit)) { - $criteria .= ' AND ('. string_from_array($contactCrit, 'url', ' OR ') .')'; - } - - $query = "SELECT " . - "t.*, u.username AS creator, au.username AS assigned_user, estimate_original, " . - "estimate_current, estimate_elapsed, (estimate_current - estimate_elapsed) as hours_remaining, " . - "stat.name as status_text, rec.name AS record_name, t.record_id, rec.public_id " . - "FROM todo_table AS t " . - "INNER JOIN user_table AS u ON (u.contact_id=t.creator_contact_id) " . - "INNER JOIN status_table AS stat ON (t.status_id=stat.status_id) " . - "LEFT OUTER JOIN record_table AS rec ON (rec.record_id=t.record_id AND rec.is_helpdesk_issue IS FALSE) " . - "LEFT OUTER JOIN user_table AS au ON (t.assigned_contact_id=au.contact_id) " . - "WHERE ". $criteria ." ORDER BY ". $orderBy; - - $this->db->exec($query); - $numrows = $this->db->numRows(); - $dberror = $this->db->errorMsg(); - - if($dberror || $numrows < 1) { - //something bad happened, or no rows. - if($dberror) { - //log the problem. - $this->logsObj->log_dberror(__METHOD__ .": dberror encountered::: $dberror\n$query"); - } - $retval = 0; - } - else { - //good data. - $retval = $this->db->farray_fieldnames("todo_id",NULL,0); - - //set a list of fields that need to be rounded. - $precisionRound = array('hours_remaining', 'work_days_remaining', 'original_hours', 'estimate_current'); - - //format some of the fields... - foreach($retval as $id=>$subData) { - //if, for some reason, the title got into the database with - // bad characters, this will ensure they're parse properly. - $retval[$id]['name'] = cleanString($subData['name'], "htmlentity"); - - $retval[$id]['submit_date'] = parse_date_string($subData['submit_date'],TRUE); - - //round-out some numbers. - foreach($precisionRound as $roundThisField) { - $number = $retval[$id][$roundThisField]; - $retval[$id][$roundThisField] = number_format($number,2); - } - - //retrieve any comments. - $retval[$id]['comments'] = $this->get_comments($id); - } - } - - return($retval); - - }//end get_todos() - //================================================================================================ - - - //================================================================================================ - /** - * A wrapper for get_todos() to retrieve a single todo's info. - * - * @param $todoId <int> id of the todo to retrieve. - * - * @return <SPECIAL: returns the requested record using get_todos()> - */ - function get_todo($todoId=NULL) { - if(!is_numeric($todoId)) { - $retval = 0; - } - else { - - $retval = $this->get_todos(array("todo_id"=>$todoId)); - $retval = $retval[$todoId]; - } - - return($retval); - }//end get_todo() - //================================================================================================ - - - //================================================================================================ - /** - * Updates a single todo record with the specified data. - * - * @param $todoId <int> - * @param $updatesArr <array> - * - * @return 0 FAIL: unable to update. - * @return 1 PASS: update successful. - */ - function update_todo($todoId, $updatesArr) { - - //define a list of updateable fields, and how they should be cleaned. - $cleanFieldsArr = array( - "name" => "sql", - "body" => "sql", - "assigned_contact_id" => "numeric", - "record_id" => "numeric", - "started" => "sql", - "deadline" => "sql", - "status_id" => "numeric", - "priority" => "numeric", - "progress" => "numeric", - #"estimate_original" => "numeric", - "estimate_current" => "numeric", - "estimate_elapsed" => "sql" - ); - - - //do some automatic updates. - $updatesArr = $this->check_for_auto_updates($todoId, $updatesArr); - - if(is_numeric($updatesArr['add_elapsed'])) { - //they're adding time to elapsed. - $this->add_elapsed($todoId, $updatesArr['add_elapsed'], $this->logsObj->defaultUid); - } - - //get the old data for logging & such. - $oldData = $this->get_todo($todoId); - - $sqlArr = array(); - foreach($updatesArr as $field=>$value) { - if(isset($cleanFieldsArr[$field]) && !is_numeric($value) && $value == '') { - $sqlArr[$field] = "NULL"; - } - elseif(isset($cleanFieldsArr[$field])) { - $sqlArr[$field] = $value; - } - } - - //create the update statement. - $updateStr = string_from_array($sqlArr, "update", NULL, $cleanFieldsArr); - $sql = "UPDATE todo_table SET $updateStr WHERE todo_id=$todoId"; - - $numrows = $this->db->exec($sql); - $this->lastError = $this->db->errorMsg(); - - if($this->lastError || $numrows != 1) { - //bad things... - if($this->lastError) { - $this->logsObj->log_dberror(__METHOD__ .": database error::: ". $this->lastError); - } - $retval = 0; - } - else { - $retval = $numrows; - - //log the changes. - $doNotLog = array('ext', 'comments'); - $changesCount = 0; - $details = "Updated fields::: "; - - //define an array of realFieldname => whatTheCodeCallsTheField - $translationArr = array( - 'anfang' => 'begin_date', - 'datum' => 'submit_date' - ); - foreach($updatesArr as $field=>$newValue) { - if(isset($translationArr[$field])) { - //translate it into the fields that get_todos() uses (see it's query) - $field = $translationArr[$field]; - } - if((!in_array($field, $doNotLog)) && ($newValue != $oldData[$field])) { - //create the details. - $thisDetail = $field .": [". $oldData[$field] ."] => [". $newValue ."]"; - $details = create_list($details, $thisDetail, "\n"); - $changesCount++; - } - } - - if($changesCount > 0) { - //log it! - $this->logsObj->log_by_class($details, 'update', NULL, $this->recordTypeId, $todoId); - } - } - return($retval); - - }//end update_todo() - //================================================================================================ - - - - //================================================================================================ - /** - * Adds a comment to the existing comments for a todo. It's fun. - * - * @param $todoId <int> id of todo that will be updated. - * @param $comment <str> comment to add. - * - * @return -1 FAIL: comment too short. - * @return <special see output of update_todo()> - */ - function add_comment($todoId, $comment, $subject=NULL) { - $retval = NULL; - if(strlen($comment) >1 && is_numeric($todoId)) { - $todoData = $this->get_todo($todoId); - if(is_array($todoData)) { - //we're still good: setup the array of inserted information. - if(is_null($subject) || !strlen($subject)) { - $subject = 'Comment'; - } - $sqlArr = array( - 'todo_id' => $todoId, - 'creator_contact_id' => $_SESSION['contact_id'], - 'subject' => $subject, - 'body' => $comment, - ); - $cleanStringArr = array( - 'creator_contact_id' => 'numeric', - 'subject' => 'sql', - 'body' => 'sql' - ); - - //now run the insert. - $sql = 'INSERT INTO '. TABLE_TODOCOMMENT .' '. string_from_array($sqlArr, 'insert', NULL, $cleanStringArr); - - $numrows = $this->db->exec($sql); - $dberror = $this->db->errorMsg(); - - if(strlen($dberror) || $numrows != 1) { - //log it. - $this->logsObj->log_dberror("Unable to insert comment: numrows=($numrows), dberror::: ". $dberror); - } - else { - $retval = 1; - } - } - else { - throw new exception("Invalid todo (couldn't find record)"); - } - } - else { - throw new exception("Comment too short, or invalid todoId."); - } - - return($retval); - }//end add_comment() - //================================================================================================ - - - - //================================================================================================ - /** The work to insert a todo into the todo table. - * - * @param $dataArr <array> field=>value data to insert. - * - * return -1 FAIL: insert seemed to work, but couldn't get note_id. - * @return 0 FAIL: unable to insert data. - * @return <n> (hopefully) PASS: <n> is the note_id we just inserted. - */ - function create_todo($dataArr) { - //define the fields that can actually be SPECIFIED by $dataArr: - $reqFieldsArr = array( - "name" => "sql", - "body" => "sql", - "record_id" => "numeric", - "started" => "sql", - "estimate_original" => "decimal" - ); - - //make sure we've got a valid array. - $matchingFieldsCount = count(array_intersect(array_keys($dataArr), array_keys($reqFieldsArr))); - $requiredFieldsCount = count($reqFieldsArr); - if(!is_array($dataArr) || (is_array($dataArr) && count($dataArr) < 1) || $matchingFieldsCount != $requiredFieldsCount) { - $this->lastError = "Precheck failed. Check what was entered and try again. [fields: $matchingFieldsCount/$requiredFieldsCount]"; - $this->logsObj->log_by_class(__METHOD__ .": ". $this->lastError); - return(0); - } - - //make the body non-null. - if(!strlen($dataArr['body'])) { - $dataArr['body'] = '(N/A)'; - } - - $addFieldsArr = array( - "creator_contact_id" => $_SESSION['contact_id'], - "created" => "NOW()", - "estimate_current" => $dataArr['estimate_original'] - ); - - //okay, clean-up our given data... - $cleanStringArr = array_merge($addFieldsArr, $reqFieldsArr); - foreach($dataArr as $field=>$value) { - $cleanStringArg = $reqFieldsArr[$field]; - if(!$cleanStringArg) { - $cleanStringArr[$field] = "sql"; - } - - $insertArr[$field] = $value; - } - - //merge it with the fields we manually set.. - $insertArr = array_merge($insertArr, $addFieldsArr); - - //make it into an insert statement... - $insertStr = string_from_array($insertArr, "insert", NULL, $cleanStringArr, FALSE, TRUE); - $sql = "INSERT INTO todo_table $insertStr"; - - $numrows = $this->db->exec($sql); - $this->lastError = $this->db->errorMsg(); - - //determine what to do next... - if($this->lastError || $numrows != 1) { - $this->logsObj->log_dberror(__METHOD__ .": invalid numrows ($numrows) or dberror::: ". $this->lastError); - $retval = 0; - } - else { - //got good data... get the note_id. - $numrows = $this->db->exec("SELECT currval('todo_table_todo_id_seq')"); - $this->lastError = $this->db->errorMsg(); - - //make sure we're still okay. - if($this->lastError || $numrows != 1) { - $this->logsObj->log_dberror(__METHOD__ .": invalid numrows($numrows) or dberror::: ". $this->lastError); - $retval = -1; - } - else { - $tmp = $this->db->farray(); - $retval = $tmp[0]; - $this->logsObj->log_by_class("Created new todo [todo_id=". $retval ."]", 'create'); - } - } - - return($retval); - - }//end create_todo() - //================================================================================================ - - - - //================================================================================================ - private function check_for_auto_updates($todoId, $updatesArr) { - //get info about the todo, so we know what to do... - $todoData = $this->get_todo($todoId); - - //set variable for elapsed for later checking. - $myElapsed = $todoData['estimate_elapsed']; - if(is_numeric($updatesArr['add_elapsed'])) { - //update the internal variable (the updates array will be changed later). - $myElapsed = $this->get_sum_of_elapsed($todoId, $updatesArr['add_elapsed']); - - //check if the "estimate_elapsed" field contains more hours than were logged... - if(($todoData['estimate_elapsed'] + $updatesArr['add_elapsed']) != $myElapsed) { - //automatically update it. - $offBy = (($todoData['estimate_elapsed'] + $updatesArr['add_elapsed']) - $myElapsed); - $this->add_elapsed($todoId, $offBy, $this->logsObj->defaultUid, 'Automatic adjustment'); - $myElapsed = $this->get_sum_of_elapsed($todoId, $updatesArr['add_elapsed']); - } - - $updatesArr['estimate_elapsed'] = $myElapsed; - } - elseif(!is_numeric($todoData['estimate_elapsed'])) { - $myElapsed = 0; - $updatesArr['estimate_elapsed'] = 0; - } - - //set local variable for current estimate for later checking. - $myCurrEstimate = $todoData['estimate_current']; - if(is_numeric($updatesArr['estimate_current']) && $updatesArr['estimate_current'] > 0) { - $myCurrEstimate = $updatesArr['estimate_current']; - } - else { - unset($updatesArr['estimate_current']); - } - - - //if they're updating elapsed time, make sure estimate_current is... sane. - if(($myElapsed) && ($myCurrEstimate < $myElapsed)) { - //more time has elapsed than in the estimate? update the estimate to match. - $updatesArr['estimate_current'] = $myElapsed; - $myCurrEstimate = $myElapsed; - } - - //are they ENDING the todo? - if($updatesArr['status_id'] == 4 || $updatesArr['progress'] >= 100) { - //set it to 100% complete. - $updatesArr['progress'] = 100; - - //set it as ended. - $updatesArr['status_id'] = 4; - - //make "elapsed" match "estimate_current" - $updatesArr['elapsed'] = $myCurrEstimate; - } - //is it set to "accepted"? - elseif($updatesArr['status_id'] == 2) { - //set it as 0% complete. - $updatesArr['progress'] = 0; - } - else { - //not ended, not re-opened: set the progress properly. - $updatesArr['progress'] = (($myElapsed / $myCurrEstimate) * 100); - } - - if(isset($updatesArr['assigned_contact_id']) && !is_numeric($updatesArr['assigned_contact_id'])) { - $updatesArr['assigned_contact_id'] = "NULL"; - } - - return($updatesArr); - }//end check_for_auto_updates() - //================================================================================================ - - - - //================================================================================================ - private function get_comments($todoId) { - $sql = "SELECT tc.todo_comment_id, tc.subject, tc.body, (c.fname || ' ' || c.lname) as creator, " . - "tc.created, tc.updated FROM todo_comment_table AS tc INNER JOIN contact_table AS c ON " . - "(c.contact_id=tc.creator_contact_id) WHERE todo_id=". $todoId ." ORDER BY todo_comment_id ASC"; - $numrows = $this->db->exec($sql); - $this->lastError = $this->db->errorMsg(); - - $retval = array(); - if(strlen($this->lastError) || $numrows < 1) { - if(strlen($this->dberror)) { - $this->logsObj->log_dberror(__METHOD__ .": ". $this->lastError); - } - } - else { - $retval = $this->db->farray_fieldnames('todo_comment_id', NULL, 0); - } - - return($retval); - }//end get_comments() - //================================================================================================ - - - - //========================================================================= - /** - * Logs the added "elapsed" info for the given todo_id. - */ - public function add_elapsed($todoId, $addElapsed, $uid, $systemNote=NULL) - { - $retval = 0; - if(is_numeric($addElapsed)) { - //log the item into our log_estimate_table. - $sqlArr = array( - 'uid' => $uid, - 'todo_id' => $todoId, - 'add_elapsed' => $addElapsed - ); - - if(!is_null($systemNote) && strlen($systemNote)) { - $sqlArr['system_note'] = $systemNote; - } - - //create the SQL. - $sql = "INSERT INTO log_estimate_table ". string_from_array($sqlArr, 'insert'); - - //now run it. - $numrows = $this->db->exec($sql); - $this->lastError = $this->db->errorMsg(); - - - if(strlen($this->lastError) || $numrows !== 1) { - //got a database error, or nothing was inserted... - $details = __METHOD__ .": unable to insert (". $numrows .") or database error:::\n". $this->lastError; - $this->logsObj->log_dberror($details); - } - else { - //we're doing great! - $retval = $numrows; - - //now update the todo's estimate_elapsed field. - #$newElapsed = $this->get_sum_of_elapsed($todoId); - } - } - - return($retval); - }//end add_elapsed() - //========================================================================= - - - - //========================================================================= - private function get_sum_of_elapsed($todoId, $addThis=NULL) { - $retval = 0; - - $sql = "SELECT sum(add_elapsed) FROM log_estimate_table WHERE todo_id=". $todoId; - $numrows = $this->db->exec($sql); - $this->lastError = $this->db->errorMsg(); - - if(strlen($this->lastError) || $numrows != 1) { - if(strlen($this->lastError)) { - $details = __METHOD__ .": encountered error while trying to retrieve new sum of estimate_elapsed::: ". $this->lastError; - $this->logsObj->log_dberror($details); - } - $retval = 0; - } - else { - //retrieve our new sum of elapsed. - $tmp = $this->db->farray(); - $retval = 0; - if(is_numeric($tmp[0])) { - $retval = $tmp[0]; - } - - if(!is_null($addThis) && is_numeric($addThis)) { - $orig = $retval; - $retval = ($retval + $addThis); - } - } - - return($retval); - }//end get_sum_of_elapsed() - //========================================================================= - - - - //========================================================================= - public function get_hours_logged($todoId, $uid=NULL, $limit=NULL) { - //retrieve data from log_estimate_table WHERE record_id=$todoId... sort by creation... limit? - $criteria = array( - 'todo_id' => $todoId - ); - if(!is_null($uid) && is_numeric($uid)) { - $criteria['uid'] = $uid; - } - $sql = "SELECT le.*, u.username FROM log_estimate_table AS le INNER JOIN " . - "user_table AS u USING (uid) WHERE ". string_from_array($criteria, 'select'); - if(is_numeric($limit) && $limit > 0) { - $sql .= " LIMIT ". $limit; - } - - $numrows = $this->db->exec($sql); - $this->lastError = $this->db->errorMsg(); - - - if($numrows < 1 || strlen($this->lastError)) { - if(strlen($this->lastError)) { - $details = __METHOD__ .": ". $this->lastError; - $this->logsObj->log_dberror($details); - } - $retval = NULL; - } - else { - $retval = $this->db->farray_fieldnames('log_estimate_id', NULL, 0); - foreach($retval as $id=>$array) { - $tmp = explode(".", $array['creation']); - $retval[$id]['creation'] = $tmp[0]; - } - } - - return($retval); - - }//end get_hours_logged() - //========================================================================= - -}//end todoClass{} -?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |