Copyright (c) 2002, DM Solutions Group Inc. * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ include_once(dirname(__FILE__)."/../Widget.php"); /** * class SharedResource * * @description Base Shared memory widget class */ class SharedResource extends CWCWidget { var $mszName = ""; var $mbEnableJS = false; /** * ShareResourceWidget * * Base CWC Share memory Widget. */ function SharedResource() { // invoke constructor of parent parent::CWCWidget(); // set the description for this widget $this->szWidgetDescription = <<maAttributes["NAME"] = new StringAttribute( "NAME", true ); $this->maAttributes["ENABLEJS"] = new BooleanAttribute( "ENABLEJS", false); $this->mnMaturityLevel = MATURITY_TECHNICALRELEASE; } /** * MakeJSObject * utility function to parse object trees * and create a javascript object hierarchy to attach to the root object. */ function MakeJSObject($szJSResourceType, $aChildren, $szJSParent) { $szJSResult = ""; if (!is_array( $aChildren )) { return ""; } foreach ($aChildren as $szChild => $aProperties) { if (!is_array($aProperties)) continue; $szJSObjectName = $szJSResourceType; // . $szChild; $szJSResult .= "var " . $szJSObjectName . " = new CWC_JS_SharedResource();\n"; foreach ($aProperties as $key => $val) { $szJSElement = $key; if (is_array ($val)) { foreach ($val as $szChildResource => $aSubChildren) { $szJSResult .= $this->MakeJSObject ($szJSObjectName . "_" /*. $szChildResource*/, $aSubChildren, $szJSObjectName); } } else { $szJSResult .= $szJSObjectName . ".SetProperty(\"" . addslashes(trim($key)) . "\",\"" . addslashes(trim($val)) . "\");\n"; } } $szJSResult .= $szJSParent . ".AddChild($szJSObjectName);\n"; } return $szJSResult; } /** * InitDefaults * */ function InitDefaults() { parent::InitDefaults(); $this->mbEnableJS = 0; if (isset($this->maParams["ENABLEJS"])) { $this->mbEnableJS = (strcasecmp($this->maParams["ENABLEJS"], "true") == 0) ? true : false; } if (isset($this->maParams["NAME"])) $this->mszName = $this->maParams["NAME"]; } /** * GetJavascriptFunctions * */ function GetJavascriptFunctions() { $aReturn = array(); parent::GetJavascriptFunctions(); //check if there is a resource to build as javascript if (!($this->maszContents != "" && $this->mbEnableJS)) { return $aReturn; } //print_r($this->maszContents); $szJSTree = "var ".$this->mszName." = new CWC_JS_SharedResource();\n"; foreach ($this->maszContents as $szJSResourceType => $aProperties) { $szJSTree .= $this->MakeJSObject($szJSResourceType, $aProperties, $this->mszName); } $szJSTree .= "goJSSR.SetProperty( \"".$this->mszName."\", $this->mszName );\n"; $szJsFunctionName = "JSSharedResourceInit_".$this->mnId; $szFunction = <<mbEnableJS) { $szJsIncludeName = $_SESSION["gszCoreWebPath"]."/widgets/js/cwc_sr.js"; $szInclude = ""; $aReturn[$szJsIncludeName] = $szInclude; } return $aReturn; } /** * GetJavascriptVariables * * Global var code */ function GetJavascriptVariables() { $aReturn = array(); if ($this->mbEnableJS) { $szVariable = "goJSSR"; $szValue = " var $szVariable = new CWC_JS_SharedResource();\n"; $aReturn[$szVariable] = $szValue; } return $aReturn; } } ?>