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"); include_once(dirname(__FILE__)."/../Button.php"); /** * a simple widget to link to another page */ class Link extends CWCWidget { var $moButton; var $mbPopup = false; var $mszHref = null; var $mszLinkType = "HREF"; var $maszJSFunctions = array(); /** * construct a new link widget */ function Link() { // invoke constructor of parent parent::CWCWidget(); // set the description for this widget $this->szWidgetDescription = <<moButton = new CWCButton($this); $this->maAttributes["APPENDGET"] = new BooleanAttribute( "APPENDGET", false ); $this->maAttributes["APPENDSID"] = new BooleanAttribute("APPENDSID", false ); $this->maAttributes["HREF"] = new StringAttribute( "HREF", false ); $this->maAttributes["JSFUNCTION"] = new StringAttribute( "JSFUNCTION", false ); $this->maAttributes["JSPARAMS"] = new StringAttribute( "JSPARAMS", false ); $this->maAttributes["LINKTYPE"] = new StringAttribute( "LINKTYPE", true, array( "HREF", "JAVASCRIPT" ) ); $this->maAttributes["TARGET"] = new StringAttribute("TARGET", false ); $this->maAttributes['DIV'] = new StringAttribute( "DIV", false ); $this->mnMaturityLevel = MATURITY_TECHNICALRELEASE; } /** * initialize default values */ function InitDefaults() { parent::InitDefaults(); if ($this->mbVisible) { $this->moButton->InitDefaults(); if (isset($this->maParams['LINKTYPE'])) { $this->mszLinkType = strtoupper($this->maParams['LINKTYPE']); } if ($this->mszLinkType == "HREF") { $szHref = $this->maParams["HREF"]; $aszHrefParams = array(); if (strpos($szHref, "?") !== false) $aszHrefParams = explode("&",substr(strstr($szHref, "?"), 1)); if (isset($this->maParams["APPENDGET"]) && strcasecmp($this->maParams["APPENDGET"],"true") == 0) { $szGET = ""; foreach($GLOBALS["_GET"] as $szKey => $szVal) { // Check all get var if it was set in user link // dont overwrite it. $bFound=false; foreach($aszHrefParams as $szParams) { $aszParams = explode("=", $szParams); if ($aszParams[0] == $szKey) $bFound = true; } if (!$bFound) $szGET .= "$szKey=".urlencode($szVal)."&"; } if (substr($szHref, -1) == "?" || substr($szHref, -1) == "&") $szHref .= $szGET; else if (strpos($szHref, "?") !== false) { $szHref .= "&$szGET"; } else $szHref .= "?$szGET"; } if (isset($this->maParams["APPENDSID"]) && strcasecmp($this->maParams["APPENDSID"],"true") == 0) { if (substr($szHref, -1) == "?" || substr($szHref, -1) == "&") $szHref .= SID; else if (strpos($szHref, "?") !== false) $szHref .= "&".SID; else $szHref .= "?".SID; } $szTarget = ""; if (isset($this->maParams["TARGET"])) $szTarget = $this->maParams["TARGET"]; $szJS = "var wh = window.open( '$szHref', '$szTarget' );\n"; $szJS .= "wh.focus();\n"; $szJSName = 'linkWidget'.$this->mnId; $this->maszJSFunctions[$szJSName] = <<moButton->SetOnClick( 'linkWidget'.$this->mnId ); } elseif ($this->mszLinkType == "JAVASCRIPT") { if (isset($this->maParams['JSFUNCTION'])) { $szJS = "void"; $szJSParams = "0"; if ($this->maParams["JSFUNCTION"] != "") { $szJS = $this->maParams["JSFUNCTION"]; $szJSParams = ""; } if (isset($this->maParams["JSPARAMS"])) { $szJSParams = $this->maParams["JSPARAMS"]; } $this->moButton->SetOnClick( $szJS, $szJSParams ); } } } } function ParseURL() { if ($this->mbVisible) return $this->moButton->ParseURL(); else return true; } /** * return javascript functions */ function GetJavascriptFunctions() { $aReturn = array(); if ($this->mbVisible) $aReturn = array_merge($this->moButton->GetJavascriptFunctions(), $this->maszJSFunctions); return $aReturn; } /** * return javascript functions */ function GetJavascriptIncludeFunctions() { $aResult = array(); if ($this->mbVisible) $aResult = $this->moButton->GetJavascriptIncludeFunctions(); return $aResult; } /** * return javascript variables */ function GetJavascriptVariables() { $aResult = array(); if ($this->mbVisible) $aResult = $this->moButton->GetJavascriptVariables(); return $aResult; } /** * return javascript onload functions */ function GetJavascriptOnLoadFunctions() { $aResult = array(); if ($this->mbVisible) $aResult = $this->moButton->GetJavascriptOnLoadFunctions(); return $aResult; } /** * return javascript initialization funcitons */ function GetJavascriptInitFunctions() { $aResult = array(); if ($this->mbVisible) $aResult = $this->moButton->GetJavascriptInitFunctions(); return $aResult; } function GetHTMLHiddenVariables() { $aResult = array(); if ($this->mbVisible) $aResult = $this->moButton->GetHTMLHiddenVariables(); return $aResult; } /** * draw the link widget */ function DrawPublish() { if (!$this->mbVisible) return ""; $szReturn = $this->moButton->DrawPublish(); return $szReturn; } } ?>