diff --git a/gulliver/system/class.headPublisher.php b/gulliver/system/class.headPublisher.php old mode 100755 new mode 100644 index 699fc2fae..b857d5788 --- a/gulliver/system/class.headPublisher.php +++ b/gulliver/system/class.headPublisher.php @@ -1,6 +1,8 @@ . + * along with this program. If not, see . * * For more information, contact Colosa Inc, 2566 Le Jeune Rd., * Coral Gables, FL, 33134, USA, or email info@colosa.com. @@ -25,634 +27,675 @@ */ /** * Class headPublisher + * * @author David S. Callizaya S. * @package gulliver.system * @access public */ -class headPublisher { - private static $instance = NULL; - var $maborakFiles = array (); - var $maborakLoaderFiles = array (); - var $scriptFiles = array (); - var $leimnudLoad = array (); +class headPublisher +{ + private static $instance = null; + var $maborakFiles = array (); + var $maborakLoaderFiles = array (); + var $scriptFiles = array (); + var $leimnudLoad = array (); - /* extJsSkin init coreLoad flag*/ - var $extJsInit = 'false'; + /* extJsSkin init coreLoad flag*/ + var $extJsInit = 'false'; - /* extJsSkin store the current skin for the ExtJs*/ - var $extJsSkin = ''; + /* extJsSkin store the current skin for the ExtJs*/ + var $extJsSkin = ''; - /* extJsScript Array, to store the file to be include */ - var $extJsScript = array (); + /* extJsScript Array, to store the file to be include */ + var $extJsScript = array (); - /* extJsLibrary Array, to store extended ExtJs lybraries */ - var $extJsLibrary = array (); + /* extJsLibrary Array, to store extended ExtJs lybraries */ + var $extJsLibrary = array (); - /* extJsContent Array, to store the file to be include in the skin content */ - var $extJsContent = array (); + /* extJsContent Array, to store the file to be include in the skin content */ + var $extJsContent = array (); - /* extVariable array, to store the variables generated in PHP, and used in JavaScript */ - var $extVariable = array (); + /* extVariable array, to store the variables generated in PHP, and used in JavaScript */ + var $extVariable = array (); - /* variable array, to store the variables generated in PHP, and used in JavaScript */ - var $vars = array (); + /* variable array, to store the variables generated in PHP, and used in JavaScript */ + var $vars = array (); - /* tplVariable array, to store the variables for template power */ - var $tplVariable = array (); + /* tplVariable array, to store the variables for template power */ + var $tplVariable = array (); - var $leimnudInitString = ' var leimnud = new maborak(); + var $leimnudInitString = ' var leimnud = new maborak(); leimnud.make({ zip:true, inGulliver:true, modules :"dom,abbr,rpc,drag,drop,app,panel,fx,grid,xmlform,validator,dashboard", files :"" });'; - var $headerScript = ' + var $headerScript = ' try{ leimnud.exec(leimnud.fix.memoryLeak); if(leimnud.browser.isIphone){ leimnud.iphone.make(); } }catch(e){}'; - var $disableHeaderScripts = false; - var $title = ''; + var $disableHeaderScripts = false; + var $title = ''; - /** - * Function headPublisher - * @author David S. Callizaya S. - * @access public - * @return string - */ + /** + * Function headPublisher + * + * @author David S. Callizaya S. + * @access public + * @return string + */ - public function __construct() { - $this->addScriptFile ( "/js/maborak/core/maborak.js" ); - } - - function &getSingleton() { - if (self::$instance == NULL) { - self::$instance = new headPublisher ( ); + public function __construct () + { + $this->addScriptFile( "/js/maborak/core/maborak.js" ); } - return self::$instance; - } - /** - * Function setTitle - * @author David S. Callizaya S. - * @access public - * @parameter string url - * @parameter string LoadType - * @return string - */ - function setTitle($title) { - $this->title = $title; - } + function &getSingleton () + { + if (self::$instance == null) { + self::$instance = new headPublisher(); + } + return self::$instance; + } - /** - * Function addMaborakFile - * @access public - * @parameter string filename - * @parameter string loader; false -> maborak files, true maborak.loader - * @return string - */ - function addMaborakFile($filename, $loader = false) { - if ($loader) - $this->maborakLoaderFiles [] = $filename; - else - $this->maborakFiles [] = $filename; - } + /** + * Function setTitle + * + * @author David S. Callizaya S. + * @access public + * @param eter string url + * @param eter string LoadType + * @return string + */ + function setTitle ($title) + { + $this->title = $title; + } - /** - * Function addScriptFile - * @author David S. Callizaya S. - * @access public - * @parameter string url - * @parameter string LoadType - * @return string - */ - function addScriptFile($url, $LoadType = 1) { - if ($LoadType == 1) - $this->scriptFiles [$url] = $url; - if ($LoadType == 2) - $this->leimnudLoad [$url] = $url; - } + /** + * Function addMaborakFile + * + * @access public + * @param eter string filename + * @param eter string loader; false -> maborak files, true maborak.loader + * @return string + */ + function addMaborakFile ($filename, $loader = false) + { + if ($loader) { + $this->maborakLoaderFiles[] = $filename; + } else { + $this->maborakFiles[] = $filename; + } + } - /** - * Function addInstanceModule - * @author David S. Callizaya S. - * @access public - * @parameter string instance - * @parameter string module - * @return string - */ + /** + * Function addScriptFile + * + * @author David S. Callizaya S. + * @access public + * @param eter string url + * @param eter string LoadType + * @return string + */ + function addScriptFile ($url, $LoadType = 1) + { + if ($LoadType == 1) { + $this->scriptFiles[$url] = $url; + } + if ($LoadType == 2) { + $this->leimnudLoad[$url] = $url; + } + } - function addInstanceModule($instance, $module) { - $this->headerScript .= "leimnud.Package.Load('" . $module . "',{Instance:" . $instance . ",Type:'module'});\n"; - } + /** + * Function addInstanceModule + * + * @author David S. Callizaya S. + * @access public + * @param eter string instance + * @param eter string module + * @return string + */ - /** - * Function addClassModule - * @author David S. Callizaya S. - * @access public - * @parameter string class - * @parameter string module - * @return string - */ - function addClassModule($class, $module) { - $this->headerScript .= "leimnud.Package.Load('" . $module . "',{Class:" . $class . ",Type:'module'});\n"; - } + function addInstanceModule ($instance, $module) + { + $this->headerScript .= "leimnud.Package.Load('" . $module . "',{Instance:" . $instance . ",Type:'module'});\n"; + } - /** - * Function addScriptCode - * @author David S. Callizaya S. - * @access public - * @parameter string script - * @return string - */ - function addScriptCode($script) { - $this->headerScript .= $script; - } + /** + * Function addClassModule + * + * @author David S. Callizaya S. + * @access public + * @param eter string class + * @param eter string module + * @return string + */ + function addClassModule ($class, $module) + { + $this->headerScript .= "leimnud.Package.Load('" . $module . "',{Class:" . $class . ",Type:'module'});\n"; + } - /** - * Function printHeader - * @author David S. Callizaya S. - * @access public - * @return string - */ - function printHeader() { - $jslabel = 'labels/en.js'; - if (defined ( 'SYS_LANG' )) { - $jslabel = 'labels' . PATH_SEP . SYS_LANG . '.js'; - if (! file_exists ( PATH_CORE . 'js' . PATH_SEP . $jslabel )) + /** + * Function addScriptCode + * + * @author David S. Callizaya S. + * @access public + * @param eter string script + * @return string + */ + function addScriptCode ($script) + { + $this->headerScript .= $script; + } + + /** + * Function printHeader + * + * @author David S. Callizaya S. + * @access public + * @return string + */ + function printHeader () + { $jslabel = 'labels/en.js'; - } - if (file_exists ( PATH_CORE . 'js' . PATH_SEP . $jslabel )) { - $this->addScriptFile ( '/jscore/' . $jslabel, 1 ); - } - if ($this->disableHeaderScripts) - return ''; - - // available js-calendar languages array - $availableJsCalendarLang = array('ca', 'cn', 'cz', 'de', 'en', 'es', 'fr', 'it', 'jp', 'nl', 'pl', 'pt', 'ro', 'ru', 'sv'); - - // get the system language without locale - $sysLang = explode('-', SYS_LANG); - $sysLang = $sysLang[0]; - - // verify if the requested lang by the system is supported by js-calendar library, if not set english by default - $sysLang = in_array($sysLang, $availableJsCalendarLang) ? $sysLang : 'en'; - - $this->addScriptFile ( "/js/widgets/js-calendar/unicode-letter.js" ); - $this->addScriptFile ( "/js/widgets/js-calendar/lang/".$sysLang.".js" ); - - $head = ''; - $head .= '' . $this->title . "\n"; - foreach ( $this->scriptFiles as $file ) - $head .= "\n"; - $head .= "\n"; - return $head; - } - - /** - * Function printRawHeader - * Its prupose is to load el HEADs initialization javascript - * into a single SCRIPT tag, it is usefull when it is needed - * to load a page by leimnud floating panel of by another ajax - * method. (See also RAW skin) - * - * @author David S. Callizaya S. - * @access public - * @return string - */ - function printRawHeader() { - $jslabel = '/jscore/labels/en.js'; - if (defined ( 'SYS_LANG' )) { - $jslabel1 = 'labels' . PATH_SEP . SYS_LANG . '.js'; - if (! file_exists ( PATH_CORE . 'js' . PATH_SEP . $jslabel1 )) - $jslabel = '/jscore/labels/en.js'; - } - $head = ''; - //$head .= "\n"; - return $head; - } - - /** - * Function clearScripts - * Its prupose is to clear all the scripts of the header. - * - * @author David S. Callizaya S. - * @access public - * @return string - */ - function clearScripts() { - $this->scriptFiles = array (); - $this->leimnudLoad = array (); - $this->leimnudInitString = ''; - $this->headerScript = ''; - } - - /** - * Function includeExtJs - * with this function we are using the ExtJs library, this library is not compatible with - * previous libraries, for that reason oHeadPublisher will clear previous libraries like maborak - * we need to check if we need the language file - * this function returns the header needed to render a page using ExtJs - * - * @author Fernando Ontiveros - * @access public - * @return string - */ - function includeExtJs() { - $this->clearScripts (); - $head = ''; - $head .= " \n"; - $head .= " \n"; - $aux = explode('-', strtolower(SYS_LANG)); - if (($aux[0] != 'en') && file_exists(PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'ext' . PATH_SEP . 'locale' . PATH_SEP . 'ext-lang-' . $aux[0] . '.js')) { - $head .= " \n"; - } - - // enabled for particular use - $head .= $this->getExtJsLibraries(); - - // $head .= " \n"; - $head .= " \n"; - - if (! isset ( $this->extJsSkin ) || $this->extJsSkin == '') { - $this->extJsSkin = 'xtheme-gray'; - //$this->extJsSkin = 'gtheme'; - } - - //$head .= $this->getExtJsStylesheets(); - $head .= $this->getExtJsScripts(); - $head .= $this->getExtJsVariablesScript(); - - $oServerConf =& serverConf::getSingleton(); - if ($oServerConf->isRtl(SYS_LANG)) { - $head .= " \n"; - } - - return $head; - } - - function getExtJsStylesheets($skinName){ - $script = " \n"; - $script .= " \n"; -/* - $script .= " \n"; - $script .= " \n"; - - // - - //new interactive css decorator - $script .= " \n"; - $script .= " \n"; -*/ - // Load external/plugin css - // NOTE is necesary to move this to decorator server - if(class_exists('PMPluginRegistry')){ - $oPluginRegistry = & PMPluginRegistry::getSingleton (); - $registeredCss=$oPluginRegistry->getRegisteredCss(); - foreach($registeredCss as $cssFile){ - $script .= " \n"; - } - } - - return $script; - } - - function getExtJsScripts(){ - $script = ''; - if (isset ( $this->extJsScript ) && is_array ( $this->extJsScript )) { - foreach ( $this->extJsScript as $key => $file ) { - $script .= " \n"; - } - } - return $script; - } - - function getExtJsVariablesScript(){ - $script = ''; - - if (count ( $this->extVariable ) > 0) { - $script = "\n"; - } - - return $script; - } - - function getExtJsLibraries() - { - $script = ''; - if (isset ( $this->extJsLibrary ) && is_array ( $this->extJsLibrary )) { - foreach ( $this->extJsLibrary as $file ) { - $script .= " \n"; - } - } - return $script; - } - - /** - * add a ExtJS extended library - * - * @author Erik A. Ortiz - * @access public - * @param (String) http js path library - * @return none - */ - function usingExtJs($library) { - if (! is_string ( $library )) { - throw new Exception ( 'headPublisher::usingExt->ERROR - the parameter should be a js path string' ); - } - array_push ( $this->extJsLibrary, $library ); - } - - /** - * Function setExtSkin - * with this function we are using the ExtJs library, this library is not compatible with - * previous libraries, for that reason oHeadPublisher will clear previous libraries like maborak - * we need to check if we need the language file - * - * @author Fernando Ontiveros - * @access public - * @return string - */ - function setExtSkin($skin) { - $this->extJsSkin = $skin; - } - - /** - * Function addExtJsScript - * adding a javascript file .js - * add a js file in the extension Javascript Array, - * later, when we use the includeExtJs function, all the files in this array will be included in the output - * if the second argument is true, the file will not be minified, this is useful for debug purposes. - * - * Feature added - - * - Hook to find javascript registered from plugins and load them - * - * @author Fernando Ontiveros - * @author Erik Amaru Ortiz - * @access public - * @return string - */ - function addExtJsScript($filename, $debug = false, $isExternal=false) { - - $sPath = PATH_TPL; - //if the template file doesn't exists, then try with the plugins folders - - - if (! is_file ( $sPath . $filename . ".js" )) { - $aux = explode ( PATH_SEP, $filename ); - //check if G_PLUGIN_CLASS is defined, because publisher can be called without an environment - if (count ( $aux ) == 2 && defined ( 'G_PLUGIN_CLASS' )) { - $oPluginRegistry = & PMPluginRegistry::getSingleton (); - if ($oPluginRegistry->isRegisteredFolder ( $aux [0] )) { - $sPath = PATH_PLUGINS; - } - } - } - - if (!$isExternal) - $jsFilename = $sPath . $filename . '.js'; - else - $jsFilename = $filename . '.js'; - - if (! file_exists ( $jsFilename )) { - return; - } - - $mtime = filemtime ( $jsFilename ); - G::mk_dir ( PATH_C . 'ExtJs' ); - if ($debug) { - $cacheName = str_replace ( '/', '_', $filename ); - $cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $cacheName . '.js'; - file_put_contents ( $cacheFilename, file_get_contents ( $jsFilename ) ); - } - else { - $cacheName = md5 ( $mtime . $jsFilename ); - $cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $cacheName . '.js'; - - if (! file_exists ( $cacheFilename )) { - require_once (PATH_THIRDPARTY . 'jsmin/jsmin.php'); - $content = JSMin::minify ( file_get_contents ( $jsFilename ) ); - file_put_contents ( $cacheFilename, $content ); - } - } - - - $this->extJsScript [] = '/extjs/' . $cacheName; - - //hook for registered javascripts from plugins - if ( class_exists( 'PMPluginRegistry' ) ) { - $oPluginRegistry = & PMPluginRegistry::getSingleton(); - $pluginJavascripts = $oPluginRegistry->getRegisteredJavascriptBy($filename); - } - else - $pluginJavascripts = array(); - - if (count($pluginJavascripts) > 0) { - if ($debug) { - foreach ($pluginJavascripts as $pluginJsFile) { - $jsPluginCacheName = ''; - if (substr($pluginJsFile, -3) != '.js') { - $pluginJsFile .= '.js'; - } - - if (file_exists(PATH_PLUGINS . $pluginJsFile)) { - $jsPluginCacheName = str_replace ( '/', '_', str_replace('.js', '', $pluginJsFile) ); - $cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $jsPluginCacheName.".js"; - file_put_contents ( $cacheFilename, file_get_contents ( PATH_PLUGINS . $pluginJsFile ) ); - } - if ($jsPluginCacheName != '') { - $this->extJsScript [] = '/extjs/' . $jsPluginCacheName; - } - } - } - else { - foreach ($pluginJavascripts as $pluginJsFile) { - $jsPluginCacheName = ''; - if (substr($pluginJsFile, -3) !== '.js') { - $pluginJsFile .= '.js'; - } - if (file_exists(PATH_PLUGINS . $pluginJsFile)) { - $mtime = filemtime ( PATH_PLUGINS . $pluginJsFile ); - $jsPluginCacheName = md5 ( $mtime . $pluginJsFile ); - $cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $jsPluginCacheName . '.js'; - - if (! file_exists ( $cacheFilename )) { - require_once (PATH_THIRDPARTY . 'jsmin/jsmin.php'); - $content = JSMin::minify ( file_get_contents ( PATH_PLUGINS . $pluginJsFile ) ); - file_put_contents ( $cacheFilename, $content ); + if (defined( 'SYS_LANG' )) { + $jslabel = 'labels' . PATH_SEP . SYS_LANG . '.js'; + if (! file_exists( PATH_CORE . 'js' . PATH_SEP . $jslabel )) { + $jslabel = 'labels/en.js'; } - } - if ($jsPluginCacheName != '') { - $this->extJsScript [] = '/extjs/' . $jsPluginCacheName; - } } - } + if (file_exists( PATH_CORE . 'js' . PATH_SEP . $jslabel )) { + $this->addScriptFile( '/jscore/' . $jslabel, 1 ); + } + if ($this->disableHeaderScripts) { + return ''; + } + + // available js-calendar languages array + $availableJsCalendarLang = array ('ca','cn','cz','de','en','es','fr','it','jp','nl','pl','pt','ro','ru','sv'); + + // get the system language without locale + $sysLang = explode( '-', SYS_LANG ); + $sysLang = $sysLang[0]; + + // verify if the requested lang by the system is supported by js-calendar library, if not set english by default + $sysLang = in_array( $sysLang, $availableJsCalendarLang ) ? $sysLang : 'en'; + + $this->addScriptFile( "/js/widgets/js-calendar/unicode-letter.js" ); + $this->addScriptFile( "/js/widgets/js-calendar/lang/" . $sysLang . ".js" ); + + $head = ''; + $head .= '' . $this->title . "\n"; + foreach ($this->scriptFiles as $file) { + $head .= "\n"; + } + $head .= "\n"; + return $head; } - //end hook for registered javascripts from plugins - } + /** + * Function printRawHeader + * Its prupose is to load el HEADs initialization javascript + * into a single SCRIPT tag, it is usefull when it is needed + * to load a page by leimnud floating panel of by another ajax + * method. (See also RAW skin) + * + * @author David S. Callizaya S. + * @access public + * @return string + */ + function printRawHeader () + { + $jslabel = '/jscore/labels/en.js'; + if (defined( 'SYS_LANG' )) { + $jslabel1 = 'labels' . PATH_SEP . SYS_LANG . '.js'; + if (! file_exists( PATH_CORE . 'js' . PATH_SEP . $jslabel1 )) { + $jslabel = '/jscore/labels/en.js'; + } + } + $head = ''; + //$head .= "\n"; + return $head; + } - /** - * Function AddContent - * adding a html file .html. - * the main idea for this function, is to be a replacement to homonymous function in Publisher class. - * with this function you are adding Content to the output, the class HeadPublisher will maintain a list of - * files to render in the body of the output page - * - * @author Fernando Ontiveros - * @access public - * @return string - */ - function AddContent($templateHtml) { - $this->extJsContent [] = $templateHtml; - } + /** + * Function clearScripts + * Its prupose is to clear all the scripts of the header. + * + * @author David S. Callizaya S. + * @access public + * @return string + */ + function clearScripts () + { + $this->scriptFiles = array (); + $this->leimnudLoad = array (); + $this->leimnudInitString = ''; + $this->headerScript = ''; + } - function getContent() { - return $this->extJsContent; - } + /** + * Function includeExtJs + * with this function we are using the ExtJs library, this library is not compatible with + * previous libraries, for that reason oHeadPublisher will clear previous libraries like maborak + * we need to check if we need the language file + * this function returns the header needed to render a page using ExtJs + * + * @author Fernando Ontiveros + * @access public + * @return string + */ + function includeExtJs () + { + $this->clearScripts(); + $head = ''; + $head .= " \n"; + $head .= " \n"; + $aux = explode( '-', strtolower( SYS_LANG ) ); + if (($aux[0] != 'en') && file_exists( PATH_GULLIVER_HOME . 'js' . PATH_SEP . 'ext' . PATH_SEP . 'locale' . PATH_SEP . 'ext-lang-' . $aux[0] . '.js' )) { + $head .= " \n"; + } - /** - * Function assign - * assign a STRING value to a JS variable - * use this function to send from PHP variables to be used in JavaScript - * - * @author Fernando Ontiveros - * @access public - * @return string - */ - function Assign($variable, $value) { - $this->extVariable [] = array ('name' => $variable, 'value' => $value, 'type' => 'string' ); - } + // enabled for particular use + $head .= $this->getExtJsLibraries(); - function AssignVar($name, $value) { - $this->vars [$name] = $value; - } + // $head .= " \n"; + $head .= " \n"; - function getVars() { - return $this->vars; - } + if (! isset( $this->extJsSkin ) || $this->extJsSkin == '') { + $this->extJsSkin = 'xtheme-gray'; + //$this->extJsSkin = 'gtheme'; + } + //$head .= $this->getExtJsStylesheets(); + $head .= $this->getExtJsScripts(); + $head .= $this->getExtJsVariablesScript(); + $oServerConf = & serverConf::getSingleton(); + if ($oServerConf->isRtl( SYS_LANG )) { + $head .= " \n"; + } - /** - * Function assignNumber - * assign a Number value to a JS variable - * use this function to send from PHP variables to be used in JavaScript - * - * @author Fernando Ontiveros - * @access public - * @return string - */ - function AssignNumber($variable, $value) { - $this->extVariable [] = array ('name' => $variable, 'value' => $value, 'type' => 'number' ); - } - /** - * Function renderExtJs - * this function returns the content rendered using ExtJs - * extJsContent have an array, and we iterate this array to draw the content - * - * @author Fernando Ontiveros - * @access public - * @return string - */ - function renderExtJs() { - $body = ''; - if (isset ( $this->extJsContent ) && is_array ( $this->extJsContent )) { - foreach ( $this->extJsContent as $key => $file ) { + return $head; + } + + function getExtJsStylesheets ($skinName) + { + $script = " \n"; + $script .= " \n"; + /* + $script .= " \n"; + $script .= " \n"; + + // + + //new interactive css decorator + $script .= " \n"; + $script .= " \n"; + */ + // Load external/plugin css + // NOTE is necesary to move this to decorator server + if (class_exists( 'PMPluginRegistry' )) { + $oPluginRegistry = & PMPluginRegistry::getSingleton(); + $registeredCss = $oPluginRegistry->getRegisteredCss(); + foreach ($registeredCss as $cssFile) { + $script .= " \n"; + } + } + return $script; + } + + function getExtJsScripts () + { + $script = ''; + if (isset( $this->extJsScript ) && is_array( $this->extJsScript )) { + foreach ($this->extJsScript as $key => $file) { + $script .= " \n"; + } + } + return $script; + } + + function getExtJsVariablesScript () + { + $script = ''; + if (count( $this->extVariable ) > 0) { + $script = "\n"; + } + return $script; + } + + function getExtJsLibraries () + { + $script = ''; + if (isset( $this->extJsLibrary ) && is_array( $this->extJsLibrary )) { + foreach ($this->extJsLibrary as $file) { + $script .= " \n"; + } + } + return $script; + } + + /** + * add a ExtJS extended library + * + * @author Erik A. Ortiz + * @access public + * @param (String) http js path library + * @return none + */ + function usingExtJs ($library) + { + if (! is_string( $library )) { + throw new Exception( 'headPublisher::usingExt->ERROR - the parameter should be a js path string' ); + } + array_push( $this->extJsLibrary, $library ); + } + + /** + * Function setExtSkin + * with this function we are using the ExtJs library, this library is not compatible with + * previous libraries, for that reason oHeadPublisher will clear previous libraries like maborak + * we need to check if we need the language file + * + * @author Fernando Ontiveros + * @access public + * @return string + */ + function setExtSkin ($skin) + { + $this->extJsSkin = $skin; + } + + /** + * Function addExtJsScript + * adding a javascript file . + * js + * add a js file in the extension Javascript Array, + * later, when we use the includeExtJs function, all the files in this array will be included in the output + * if the second argument is true, the file will not be minified, this is useful for debug purposes. + * + * Feature added - + * - Hook to find javascript registered from plugins and load them + * + * @author Fernando Ontiveros + * @author Erik Amaru Ortiz + * @access public + * @return string + */ + function addExtJsScript ($filename, $debug = false, $isExternal = false) + { $sPath = PATH_TPL; //if the template file doesn't exists, then try with the plugins folders - if (! is_file ( $sPath . $file . ".html" )) { - $aux = explode ( PATH_SEP, $file ); - //check if G_PLUGIN_CLASS is defined, because publisher can be called without an environment - if (count ( $aux ) == 2 && defined ( 'G_PLUGIN_CLASS' )) { - $oPluginRegistry = & PMPluginRegistry::getSingleton (); - if ($oPluginRegistry->isRegisteredFolder ( $aux [0] )) { - $sPath = PATH_PLUGINS; + + + if (! is_file( $sPath . $filename . ".js" )) { + $aux = explode( PATH_SEP, $filename ); + //check if G_PLUGIN_CLASS is defined, because publisher can be called without an environment + if (count( $aux ) == 2 && defined( 'G_PLUGIN_CLASS' )) { + $oPluginRegistry = & PMPluginRegistry::getSingleton(); + if ($oPluginRegistry->isRegisteredFolder( $aux[0] )) { + $sPath = PATH_PLUGINS; + } } - } } - $template = new TemplatePower ( $sPath . $file . '.html' ); - $template->prepare (); - - foreach ($this->getVars() as $k => $v) { - $template->assign($k, $v); + if (! $isExternal) { + $jsFilename = $sPath . $filename . '.js'; + } else { + $jsFilename = $filename . '.js'; } - $body .= $template->getOutputContent (); - } - } - return $body; - } + if (! file_exists( $jsFilename )) { + return; + } - function stripCodeQuotes($sJson){ - $fields = array( "editor", "renderer" ); - foreach ($fields as $field) { - $pattern = '/"('.$field.')":"[a-zA-Z.()]*"/'; -// echo $pattern."
"; - preg_match ($pattern,$sJson,$matches); -// var_dump ($matches); -// echo "
"; - if (!empty($matches)){ - $rendererMatch = $matches[0]; - $replaceBy = explode(":", $matches[0]); - $replaceBy[1] = str_replace('"','',$replaceBy[1]); - $tmpString = implode(":",$replaceBy); - $sJson = str_replace($rendererMatch, $tmpString, $sJson); -// var_dump ($sJson); -// echo "
"; - } - } - return $sJson; - } + $mtime = filemtime( $jsFilename ); + G::mk_dir( PATH_C . 'ExtJs' ); + if ($debug) { + $cacheName = str_replace( '/', '_', $filename ); + $cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $cacheName . '.js'; + file_put_contents( $cacheFilename, file_get_contents( $jsFilename ) ); + } else { + $cacheName = md5( $mtime . $jsFilename ); + $cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $cacheName . '.js'; - /** - * Function disableHeaderScripts - * this function sets disableHeaderScripts to true - * to avoid print scripts into the header - * - * @author Enrique Ponce de Leom - * @access public - * @return string - */ - function disableHeaderScripts(){ - $this->disableHeaderScripts = true; - } + if (! file_exists( $cacheFilename )) { + require_once (PATH_THIRDPARTY . 'jsmin/jsmin.php'); + $content = JSMin::minify( file_get_contents( $jsFilename ) ); + file_put_contents( $cacheFilename, $content ); + } + } + + $this->extJsScript[] = '/extjs/' . $cacheName; + + //hook for registered javascripts from plugins + if (class_exists( 'PMPluginRegistry' )) { + $oPluginRegistry = & PMPluginRegistry::getSingleton(); + $pluginJavascripts = $oPluginRegistry->getRegisteredJavascriptBy( $filename ); + } else { + $pluginJavascripts = array (); + } + + if (count( $pluginJavascripts ) > 0) { + if ($debug) { + foreach ($pluginJavascripts as $pluginJsFile) { + $jsPluginCacheName = ''; + if (substr( $pluginJsFile, - 3 ) != '.js') { + $pluginJsFile .= '.js'; + } + + if (file_exists( PATH_PLUGINS . $pluginJsFile )) { + $jsPluginCacheName = str_replace( '/', '_', str_replace( '.js', '', $pluginJsFile ) ); + $cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $jsPluginCacheName . ".js"; + file_put_contents( $cacheFilename, file_get_contents( PATH_PLUGINS . $pluginJsFile ) ); + } + if ($jsPluginCacheName != '') { + $this->extJsScript[] = '/extjs/' . $jsPluginCacheName; + } + } + } else { + foreach ($pluginJavascripts as $pluginJsFile) { + $jsPluginCacheName = ''; + if (substr( $pluginJsFile, - 3 ) !== '.js') { + $pluginJsFile .= '.js'; + } + if (file_exists( PATH_PLUGINS . $pluginJsFile )) { + $mtime = filemtime( PATH_PLUGINS . $pluginJsFile ); + $jsPluginCacheName = md5( $mtime . $pluginJsFile ); + $cacheFilename = PATH_C . 'ExtJs' . PATH_SEP . $jsPluginCacheName . '.js'; + + if (! file_exists( $cacheFilename )) { + require_once (PATH_THIRDPARTY . 'jsmin/jsmin.php'); + $content = JSMin::minify( file_get_contents( PATH_PLUGINS . $pluginJsFile ) ); + file_put_contents( $cacheFilename, $content ); + } + } + if ($jsPluginCacheName != '') { + $this->extJsScript[] = '/extjs/' . $jsPluginCacheName; + } + } + } + } + //end hook for registered javascripts from plugins + } + + /** + * Function AddContent + * adding a html file . + * html. + * the main idea for this function, is to be a replacement to homonymous function in Publisher class. + * with this function you are adding Content to the output, the class HeadPublisher will maintain a list of + * files to render in the body of the output page + * + * @author Fernando Ontiveros + * @access public + * @return string + */ + function AddContent ($templateHtml) + { + $this->extJsContent[] = $templateHtml; + } + + function getContent () + { + return $this->extJsContent; + } + + /** + * Function assign + * assign a STRING value to a JS variable + * use this function to send from PHP variables to be used in JavaScript + * + * @author Fernando Ontiveros + * @access public + * @return string + */ + function Assign ($variable, $value) + { + $this->extVariable[] = array ('name' => $variable,'value' => $value,'type' => 'string'); + } + + function AssignVar ($name, $value) + { + $this->vars[$name] = $value; + } + + function getVars () + { + return $this->vars; + } + + /** + * Function assignNumber + * assign a Number value to a JS variable + * use this function to send from PHP variables to be used in JavaScript + * + * @author Fernando Ontiveros + * @access public + * @return string + */ + function AssignNumber ($variable, $value) + { + $this->extVariable[] = array ('name' => $variable,'value' => $value,'type' => 'number'); + } + + /** + * Function renderExtJs + * this function returns the content rendered using ExtJs + * extJsContent have an array, and we iterate this array to draw the content + * + * @author Fernando Ontiveros + * @access public + * @return string + */ + function renderExtJs () + { + $body = ''; + if (isset( $this->extJsContent ) && is_array( $this->extJsContent )) { + foreach ($this->extJsContent as $key => $file) { + $sPath = PATH_TPL; + //if the template file doesn't exists, then try with the plugins folders + if (! is_file( $sPath . $file . ".html" )) { + $aux = explode( PATH_SEP, $file ); + //check if G_PLUGIN_CLASS is defined, because publisher can be called without an environment + if (count( $aux ) == 2 && defined( 'G_PLUGIN_CLASS' )) { + $oPluginRegistry = & PMPluginRegistry::getSingleton(); + if ($oPluginRegistry->isRegisteredFolder( $aux[0] )) { + $sPath = PATH_PLUGINS; + } + } + } + + $template = new TemplatePower( $sPath . $file . '.html' ); + $template->prepare(); + + foreach ($this->getVars() as $k => $v) { + $template->assign( $k, $v ); + } + + $body .= $template->getOutputContent(); + } + } + return $body; + } + + function stripCodeQuotes ($sJson) + { + $fields = array ("editor","renderer"); + foreach ($fields as $field) { + $pattern = '/"(' . $field . ')":"[a-zA-Z.()]*"/'; + // echo $pattern."
"; + preg_match( $pattern, $sJson, $matches ); + // var_dump ($matches); + // echo "
"; + if (! empty( $matches )) { + $rendererMatch = $matches[0]; + $replaceBy = explode( ":", $matches[0] ); + $replaceBy[1] = str_replace( '"', '', $replaceBy[1] ); + $tmpString = implode( ":", $replaceBy ); + $sJson = str_replace( $rendererMatch, $tmpString, $sJson ); + // var_dump ($sJson); + // echo "
"; + } + } + return $sJson; + } + + /** + * Function disableHeaderScripts + * this function sets disableHeaderScripts to true + * to avoid print scripts into the header + * + * @author Enrique Ponce de Leom + * @access public + * @return string + */ + function disableHeaderScripts () + { + $this->disableHeaderScripts = true; + } } + diff --git a/gulliver/system/class.table.php b/gulliver/system/class.table.php old mode 100755 new mode 100644 index 42b2555e1..3a43acd9a --- a/gulliver/system/class.table.php +++ b/gulliver/system/class.table.php @@ -1,1213 +1,1207 @@ -. - * - * For more information, contact Colosa Inc, 2566 Le Jeune Rd., - * Coral Gables, FL, 33134, USA, or email info@colosa.com. - * - */ - -/** - * - * Table class definition - * Render table - * @package gulliver.system - * @author Fernando Ontiveros Lira - * @copyright (C) 2002 by Colosa Development Team. - * - */ - -class Table -{ - var $Columns = NULL; - var $Labels = NULL; - var $rows_per_page = 25; - var $show_nummbers = NULL; - var $first_row = 0; - var $row_pos = 0; - var $Action = ""; //not used - var $ActionLabel = "Continuar"; //not used - var $_dbc = NULL; - var $_dbses = NULL; - var $_dbset = NULL; - var $_source = ""; - var $DefaultOrder = "UID"; - var $DefaultOrderDir = 'ASC'; - var $CustomOrder = ""; - var $WhereClause = ""; - var $_row_values = NULL; - var $_ordered = true; - var $orderprefix = ""; - var $CountQry = ""; - var $filtro = 1; - var $title = ''; - - /** - * Asocia un arreglo con valores de traducci?n/conversi?n a un contexto - * - * @var array - */ - var $contexto = NULL; - - /** - * Arreglo que contiene las cadenas que van a ser usadas al traducir/convertir - * - * @var array - */ - var $translate = NULL; - - /** - * Establece el ?ltimo contexto utilizado - * - * @var string - */ - var $_contexto = ''; - - -/** - * Set conecction using default values - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $objConnection connection string - * @return void - */ - function Table( $objConnection = NULL ) - { - $this->SetTo( $objConnection ); - } - -/** - * Set conecction using default values - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $objConnection connection string - * @return void - */ - function SetTo( $objConnection = NULL ) - { - $this->_dbc = $objConnection; - } - -/** - * Set query string - * - * @author Fernando Ontiveros Lira - * @access public - * @param string $stQry query string - * @param string $stDefaultOrder index to order by, default value='UID' - * @return void - */ - function SetSource( $stQry = "", $stDefaultOrder = "UID", $stDefaultOrderDir = 'ASC' ) - { - //to fix missing value for variable orderDir, when between pages changes. - $url1 = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?'; - $url2 = strstr ( $_SERVER['HTTP_REFERER']. '?', $_SERVER['HTTP_HOST'] ); - $url1 = substr ( $url1, 0, strpos ( $url1, '?' ) ) ; - $url2 = substr ( $url2, 0, strpos ( $url2, '?' ) ) ; - if ( $url1 != $url2 ) { - if ( isset ($_SESSION['OrderBy'] ) ) unset ( $_SESSION['OrderBy'] ); - if ( isset ($_SESSION['OrderDir'] )) unset ( $_SESSION['OrderDir'] ); - } - $this->_source = $stQry; - $this->DefaultOrder = $stDefaultOrder; - $this->DefaultOrderDir = $stDefaultOrderDir; - } - -/** - * Obtains query string asociated - * - * @author Fernando Ontiveros Lira - * @access public - * @return void - */ - function GetSource() - { - global $HTTP_GET_VARS; - global $HTTP_SESSION_VARS; - $stOrderByDir = $this->DefaultOrderDir; - if( isset( $HTTP_SESSION_VARS['OrderDir'] ) && ( $HTTP_SESSION_VARS['OrderDir'] == 'DESC' || $HTTP_SESSION_VARS['OrderDir'] == 'ASC' ) ) - $stOrderByDir = $HTTP_SESSION_VARS['OrderDir'] ; - - - $stQry = $this->_source; - if( $this->WhereClause != "" ) - { - $stQry .= " WHERE " . $this->WhereClause; - } - - if( $this->_ordered == true ) - { - $stOrderBy = ( isset ( $HTTP_GET_VARS[ $this->orderprefix . 'order'] ) ? $HTTP_GET_VARS[ $this->orderprefix . 'order'] : '' ); - $stOrderLb = ( isset ( $HTTP_GET_VARS[ $this->orderprefix . 'label'] ) ? $HTTP_GET_VARS[ $this->orderprefix . 'label'] : '' ); - - //if( isset( $HTTP_SESSION_VARS['OrderDir'] ) && $HTTP_SESSION_VARS['OrderDir'] == $stOrderBy ) { - if ( $stOrderLb ) { - if ( $HTTP_SESSION_VARS['OrderDir'] == 'ASC') - $stOrderByDir = 'DESC'; - elseif ($HTTP_SESSION_VARS['OrderDir'] == 'DESC') - $stOrderByDir = 'ASC'; - } - else - if ( isset ( $HTTP_SESSION_VARS['OrderDir'] ) && $HTTP_SESSION_VARS['OrderDir'] != '' ) - $stOrderByDir = $HTTP_SESSION_VARS['OrderDir']; - else - $stOrderByDir = $this->DefaultOrderDir; - //} - - if( $stOrderBy == "" ) { - if( $this->DefaultOrder != "" ) - { - $aux = str_replace( ' ASC|', '', $this->DefaultOrder . '|' ); - $aux = str_replace( ' DESC|', '', $aux ); - $aux = str_replace( '|', '', $aux ); - $stQry .= " ORDER BY " . $aux . " " . $stOrderByDir; - } - } - else - { - $stQry .= " ORDER BY " . $stOrderBy; - if( $stOrderByDir != "" ) - $stQry .= " $stOrderByDir"; - } - } - else - { - if( $this->DefaultOrder != "" ) - { - $stQry .= " ORDER BY " . $this->DefaultOrder . " " . ( isset ( $stOrderBy ) ? $stOrderBy : '' ); - } - - } - //print $stQry; - - $HTTP_SESSION_VARS['OrderBy'] = isset ( $stOrderBy ) ? $stOrderBy : '' ; - $HTTP_SESSION_VARS['OrderDir'] = $stOrderByDir; - - $page = ( isset ($HTTP_GET_VARS[ "page"] ) ? $HTTP_GET_VARS[ "page"] : '' ) ; - - $tr = ( isset ( $HTTP_SESSION_VARS['TP'] ) ? $HTTP_SESSION_VARS['TP'] : '' ); - - $desde=0; - - if ($page != "") - { - //$desde=(($page-1)*25); - $desde=(($page-1) * $this->rows_per_page); - - //$strLimit = " LIMIT $desde , 25"; - $strLimit = " LIMIT $desde , $this->rows_per_page"; - if ( PEAR_DATABASE == 'pgsql' ) { - //$strLimit = " OFFSET $desde LIMIT 25"; - $strLimit = " OFFSET $desde LIMIT $this->rows_per_page"; - } - $stQry .= $strLimit; - } - - //print $stQry; - $this->_dbses = new DBSession( $this->_dbc ); - $this->_dbses->UseDB( DB_NAME ); - $this->_dbses->Query( $stQry ); - $this->_dbset = new DBRecordset( $this->_dbses->result ); - } - -/** - * Obtains number of elements of asociated query - * - * @author Fernando Ontiveros Lira - * @access public - * @return int - */ - function TotalCount() - { - global $HTTP_GET_VARS; - global $HTTP_SESSION_VARS; - - $stQry = $this->_source; - if( $this->WhereClause != "" ) { - $stQry .= " WHERE " . $this->WhereClause; - } - if( $this->_ordered == true ) { - $stOrderBy = ( isset($HTTP_GET_VARS[ $this->orderprefix . 'order']) ? $HTTP_GET_VARS[ $this->orderprefix . 'order'] : '' ); - if( $stOrderBy == "" ) - { - if( $this->DefaultOrder != "" ) - { - $stQry .= " ORDER BY " . $this->DefaultOrder; - } - } - else { - $stQry .= " ORDER BY " . $stOrderBy; - } - } - else - { - if( $this->DefaultOrder != "" ) { - $stQry .= " ORDER BY " . $this->DefaultOrder; - } - } - - $dbses = new DBSession( $this->_dbc ); - $dbses->UseDB( DB_NAME ); - $dset = $dbses->Execute( $stQry ); - return $dset->Count(); - } - - -/** - * Obtains number of elements of asociated recordset - * - * @author Fernando Ontiveros Lira - * @access public - * @return int - */ - function Count() - { - if( is_object($this->_dbset) ) { - return $this->_dbset->Count(); - } - else - { - return 0; - } - } - -/** - * Obtains row position - * - * @author Fernando Ontiveros Lira - * @access public - * @return int - */ - function CurRow() - { - return $this->row_pos; - } - -/** - * Obtains number columns - * - * @author Fernando Ontiveros Lira - * @access public - * @return int - */ - function ColumnCount() - { - $result = 0; - if( is_array( $this->Columns ) ) { - $result = count( $this->Columns ); - } - return $result; - } - -/** - * Obtains a row array and moves the internal data pointer ahead - * - * @author Fernando Ontiveros Lira - * @access public - * @return array - */ - function Read() - { - $this->_row_values = $this->_dbset->Read(); - $this->row_pos++; - return $this->_row_values; - } - -/** - * Moves the internal row pointer - * - * @author Fernando Ontiveros Lira - * @access public - * @param int $intPos position to seek - * @return int - */ - function Seek( $intPos=0 ) - { - $result = $this->_dbset->Seek( $intPos ); - if( $result ) { - $this->row_pos = $intPos; - } - return $result; - } - -/** - * Moves the internal row pointer to first position - * - * @author Fernando Ontiveros Lira - * @access public - * @return int - */ - function MoveFirst() - { - if( $this->Count() != 0 ) { - if( $this->first_row < $this->Count() ) { - $this->Seek( $this->first_row ); - } - } - } - -/** - * Verify if row position is in the end - * - * @author Fernando Ontiveros Lira - * @access public - * @return boolean - */ - function EOF() - { - $result = false; - if($this->Count() == 0 ) { - $result = true; - } - else { - if($this->row_pos >= $this->Count()) { - $result = true; - } - else { - if( $this->rows_per_page != 0 ) { - if( $this->row_pos >= $this->first_row + $this->rows_per_page ) { - $result = true; - } - } - } - } - return $result; - } - -/** - * Set values to add a column to show in the dynaform - * - * @author Fernando Ontiveros Lira - * @access public - * @param $strLabel - * @param $strType - * @param $strName - * @param $strAlign - * @param $intWidth - * @param $strTarget - * @param $strContent - * @return void - */ - function AddColumn( $strLabel = "", $strType = "text", $strName = "", $strAlign = "left", $intWidth = 0, $strTarget = "", $strContent = "" ) - { - $tmpCol = array( "Name" => $strName , - "Type" => $strType , - "Width" => $intWidth , - "Align" => $strAlign , - "Target" => $strTarget , - "Content" => $strContent ); - $pos = 0; - if( is_array( $this->Columns ) ) { - $pos = count( $this->Columns ); - } - $this->Columns[$pos] = $tmpCol; - $this->Labels[$pos] = $strLabel; - } - -/** - * Set values to add a column to show in the dynaform - * - * @author Fernando Ontiveros Lira - * @access public - * @param $strType - * @param $strName - * @param $strAlign - * @param $intWidth - * @param $strTarget - * @param $strContent - * @param $strExtra - * @param $strCondition - * @param $orderByThis - * @return void - */ - function AddRawColumn( $strType = "text", $strName = "", $strAlign = "left", $intWidth = 0, $strTarget = "", $strContent = "", $strExtra = "", $strCondition="", $orderByThis = true ) - { - $tmpCol = array( "Name" => $strName , - "Type" => $strType , - "Width" => $intWidth , - "Align" => $strAlign , - "Target" => $strTarget , - "Content" => $strContent, - "Extra" => $strExtra, - "Condition" => $strCondition, - "orderByThis" => $orderByThis); - $pos = 0; - if( is_array( $this->Columns ) ) { - $pos = count( $this->Columns ); - } - $this->Columns[$pos] = $tmpCol; - $this->Labels[$pos] = ""; - } - - -/** - * Show dynaform's title - * - * @author Fernando Ontiveros Lira - * @access public - * @param $pa - * @param $intPos - * @param $strClass - * @return void - */ - function RenderTitle($pa,$intPos=1, $strClass = "tblHeader" ) - { - if ( ! defined ( 'ENABLE_ENCRYPT') ) define ( 'ENABLE_ENCRYPT', 'no' ) ; - - global $HTTP_SESSION_VARS; - $col = $this->Columns[$intPos]; - $order = !($col["Type"] == "image"); - if( $this->_ordered == true && $order ) { - $res = " 0) $res .= " width=\"" . $col["Width"] . "\""; - $res .= ">"; - - //$res .= "" . $this->Labels[$intPos] . ""; - - $res .= "\n";//echo $res;die; - } - else { - $res = " 0) $res .= " width=\"" . $col["Width"] . "\""; - $res .= ">"; - $res .= $this->Labels[$intPos] . "\n"; - } - return $res; - } - -/** - * Show dynaform's title using ajax - * - * @author Fernando Ontiveros Lira - * @access public - * @param $pa - * @param $intPos - * @param $strClass - * @return void - */ - function RenderTitle_ajax($pa,$intPos=1, $strClass = "tblHeader" ) - { - global $HTTP_SESSION_VARS; - $col = $this->Columns[$intPos]; - $order = !(($col["Type"] == "image")||($col["Type"] == "jsimglink")); - - if( $this->_ordered == true && $order ) { - $res = " 0) $res .= " width=\"" . $col["Width"] . "\""; - $res .= ">"; - - //$res .= "Columns[$intPos]['Name']; - $res .= "Javascript:changetableOrder('$_temp_var',$pa)" ; - //$res .= $_SERVER['REDIRECT_URL'] . "?order=" . $this->Columns[$intPos]['Name']."&page=".$pa."&label=true"; - $res .= "\">" . $this->Labels[$intPos] . ""; - if($HTTP_SESSION_VARS['OrderBy'] == $this->Columns[$intPos]['Name'] ) { - if($HTTP_SESSION_VARS['OrderDir'] == 'DESC') - $res .= " "; - else - $res .= " "; - } - - $res .= "\n";//echo $res;die; - } - else { - $res = " 0) $res .= " width=\"" . $col["Width"] . "\""; - $res .= ">"; - $res .= $this->Labels[$intPos] . "\n"; - } - return $res; - } - -/** - * Show dynaform title - * - * @author Fernando Ontiveros Lira - * @access public - * @param $pa - * @param $fil - * @param $intPos - * @param $strClass - * @param $auxgetval - * @return void - */ - function RenderTitle2($pa, $fil, $intPos, $strClass = "tblHeader", $auxgetval = '') { - if ( ! defined ( 'ENABLE_ENCRYPT') ) define ( 'ENABLE_ENCRYPT', 'no' ) ; - global $HTTP_SESSION_VARS; - - if ($auxgetval == '') - $targ = SYS_TARGET.".html"; - else - $targ = SYS_TARGET.'.html?'.$auxgetval; - $target = (ENABLE_ENCRYPT=='yes'?G::encryptUrl(urldecode($targ), URL_KEY):$targ); - - $col = $this->Columns[$intPos]; - - if ($col['Type'] == 'hidden') return ''; - - $order = !($col["Type"] == "image"); - - if( ($this->_ordered == true) && ($order) && ($this->Columns[$intPos]['orderByThis'])) { - $res = ""; - if (($this->show_nummbers) and ($intPos == 0)) - $res = "# "; - - $res .= " 0) $res .= " width=\"" . $col["Width"] . "\""; - $res .= "> "; - - $res .= "Columns[$intPos]['Name']."&page=".$pa."&label=true"; - $res .= "javascript:bsearch('$direccion')"; - //$res .= $target . "?".$fil."order=" . $this->Columns[$intPos]['Name']."&page=".$pa."&label=true"; - $res .= "\">" . $this->Labels[$intPos] . ""; - - $res .= "\n"; - } - else { - $col = $this->Columns[$intPos]; - $res = " 0) $res .= " width=\"" . $col["Width"] . "\""; - $res .= ">"; - $res .= ( isset ( $this->Labels[$intPos] ) ? $this->Labels[$intPos] : '' ) . "\n"; - } - return $res; - } - -/** - * Show dynaform column - * - * @author Fernando Ontiveros Lira - * @access public - * @param $intPos - * @param $strClass - * @param $strClassLink - * @param $number - * @param $renderTD if this value = 1, this function will include the TD tags - * @return void - */ - function RenderColumn( $intPos = 0, $strClass = "tblCell", $strClassLink = "tblCellA" , $number = 0, $renderTD = 1) - { - if ( ! defined ( 'ENABLE_ENCRYPT') ) define ( 'ENABLE_ENCRYPT', 'no' ) ; - - global $G_DATE_FORMAT; - global $G_TABLE_DATE_FORMAT; - $col = $this->Columns[$intPos]; - - switch (substr($col['Name'], 0, 1)) { - case '=': - // Si empieza con '=' entonces se toma como valor constante - $val = substr($col['Name'], 1, strlen($col['Name'])-1); - break; - case '%': - // Si empieza con '%' entonces traducir/convertir el valor - $fieldname = substr($col['Name'], 1, strlen($col['Name'])-1); - $val = $this->_row_values[$fieldname]; - $val = $this->translateValue( $this->_contexto, $val, SYS_LANG ); - break; - default: - $fieldname = $col['Name']; - $val = isset ( $this->_row_values[$fieldname] ) ? $this->_row_values[$fieldname] : '' ; - } - - $res = ""; - if (($this->show_nummbers)and ($intPos == 0)) - $res = "$number"; - - if(!(stristr($val,"script") === false)) $val = htmlentities($val,ENT_QUOTES,'utf-8'); - - if ( $renderTD == 1 ) { - $res .= " 0 ) $res .= " width=\"" . $col["Width"] . "\""; - $res .= "> " ; - } - - switch ( $col["Type"] ) - { - case 'hidden': - return ''; - break; - case "text": - if ( $val != "" ) $res .= G::unhtmlentities($val,ENT_QUOTES,'utf-8'); - else $res .= " "; - break; - case "text-dontSearch": - if ( $val != "" ) $res .= G::unhtmlentities($val); - else $res .= " "; - break; - case "html": - if ( $val != "" ) $res .= ($val); - else $res .= " "; - break; - case "textPlain": - if ( $val != "" ) $res .= ($this->ParsingFromHtml(G::unhtmlentities($val),"300")); - //if ( $val != "" ) $res .= (($val)); - else $res .= " "; - break; - case "currency": - if ( $val != "" ) { - $aux = explode (' ', $val); - $format = number_format( (float)$aux[0], 2, ".", ","); - $res .= htmlentities( $format . ' ' . ( isset( $aux[1] ) ? $aux[1] : '' ) ,ENT_QUOTES,'utf-8'); - } - else - $res .= " "; - break; - - case "currency2": - if ( $val != "" ) { - $res .= G::NumberToCurrency( $val); - } - else - $res .= "$ 0.00"; - break; - - case "percentage2": - if ( $val != "" ) { - $res .= G::NumberToPercentage( $val); - } - else - $res .= "0.00 %"; - break; - - case "percentage": - if ( $val != "" ) { - $res .= htmlentities( number_format( (float)$val, 2, ".", ",") . " %" ,ENT_QUOTES,'utf-8'); - } - else { - $res .= " "; - } - break; - - case "date": - if ( $val != "" && $val != '0000-00-00 00:00:00' ) { - $part = explode (' ', $val); - $aux = explode ('-', $part[0]); - - switch($G_DATE_FORMAT) { - case 'DD/MM/AAAA':$res .= formatDate('$d/$m/$Y $H:$i:$s',$val); - break; - case 'MM/DD/AAAA':$res .= formatDate('$m/$d/$Y $H:$i:$s EST',$val); - break; - case 'AAAA/MM/DD':$res .= formatDate('$Y/$m/$d $H:$i:$s',$val); - break; - case 'LITERAL' :$res .= formatDate('$M $d $Y',$val); - break; - } - - } - else - $res .= " "; - - break; - - case "email": - if( $val != "" ) { - $res .= ""; - $res .= $val; - $res .= ""; - } - else { - $res .= " "; - } - break; - - case "ifpdf": - if ( $val == '1' ) { - $image = ""; - //valor - $tlabel = substr( $col["Content"] , 0, 1 ); - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $this->_row_values[$vname]; - //$res .= " $image "; //It open a new window... better the other way By JHL 16/11/06 - $res .= " $image "; - } - else - $res .= " "; - break; - - case "ifimg": - $image = ""; - if ( $val == '1' ) { - //valor - $tlabel = substr( $col["Content"] , 0, 1 ); - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $this->_row_values[$vname]; - $res .= " $image "; - } - else - $res .= " "; - break; - - - case "ifrtf": - if ( $val == '1' ) { - $image = ""; - //valor - $tlabel = substr( $col["Content"] , 0, 1 ); - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $this->_row_values[$vname]; - //$res .= " $image "; //It open a new window... better the other way By JHL 16/11/06 - $res .= " $image "; - } - else - $res .= " "; - break; - - case "image": - - if (is_array($col["Condition"])) //By JHL to enable Condition to display a image -- New parameter Condition in Addrawcolumn - { - $field_compare=$col["Condition"]['field']; - $tlabel = substr($field_compare,0,1); - switch($tlabel) - { - case "&": - $vname = substr($field_compare, 1, (strlen($field_compare) - 1) ); - $field_val = $this->_row_values[$vname]; - break; - } - - - } - else - $val = ""; -// break; - - case "textimage": - $AAS=$col['Extra']; - $val1 = " "; -// break; - case "image-text": - if ( is_array($col['Content']) && $col['Content'] != "") { - // Hay mas de un valor para el link - $values = $col['Content']; - $n = count($values); - - $res .= "_row_values[$vname]; - - $res .= $i == $n-1 ? $lval : $lval . "/"; - break; - } - } - $res .= "\">".strtoupper($fieldname)."$val"; - }else - $val2 = "".strtoupper($fieldname).""; -// break; - - - case "link": - if ( $val == "" ) $res .= " "; - $title = ''; - if ( $col["Type"] == 'link' && trim( isset ( $this->_row_values['TOOLTIP']) ? $this->_row_values['TOOLTIP'] : '' ) ); - $title = (isset ( $this->_row_values['TOOLTIP']) ? "title=\" " .$this->_row_values['TOOLTIP']. " \"" : '' ) ; - if ( is_array($col['Content']) && $col['Content'] != "") { - // Hay mas de un valor para el link - $values = $col['Content']; - $n = count($values); - - $res .= "_row_values[$vname]; - - $res .= $i == $n-1 ? $lval : $lval . "/"; - break; - } - } - $res .= "\">$val"; - } - elseif ( $col["Content"] != "" && !is_array($col['Content']) ) { - $tlabel = substr( $col["Content"] , 0, 1 ); - switch( $tlabel ) - { - case "&": - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $this->_row_values[$vname]; - if ( ENABLE_ENCRYPT == 'yes' ) { - - //$encoded = G::encrypt ( $col["Target"] . "/" . $lval . ".html", URL_KEY ); - $encoded = G::encryptUrl ( $col["Target"] . "/" . $lval . ".html", URL_KEY ); - $res .= ""; - if ($col["Type"]=="textimage") - { - $res .= $val1; - $val=" (".$val.")"; - } - if ($col["Type"]=="image-text") { - - $res .= $val2; - } - $res .= $val; - $res .= ""; - } - else { - $res .= ""; - if ($col["Type"]=="textimage") - { - $res .= $val1; - $val=" (".$val.")"; - } - if ($col["Type"]=="image-text") { - - $res .= $val2; - } - $res .= $val; - $res .= ""; - } - break; - case "$": - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $HTTP_SESSION_VARS[$vname]; - $res .= ""; - $res .= $val; - $res .= ""; - break; - default: - $res .= ""; - $res .= $col["Content"]; - $res .= ""; - break; - } - } - else - { - $res .= ""; - $res .= $val; - $res .= ""; - } - break; - - - case "linknew": - if ( $val == "" ) $res .= " "; - if ( $col["Content"] != "" ) { - $tlabel = substr( $col["Content"] , 0, 1 ); - switch( $tlabel ) - { - case "&": - if ( ENABLE_ENCRYPT == 'yes' ) { - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $this->_row_values[$vname]; - //$encoded = G::encryptUrl ( $col["Target"] , URL_KEY ). "/" . $lval . ".html"; - $encoded = G::encryptUrl ( $col["Target"]. "/" . $lval . "" , URL_KEY ); - $res .= ""; - $res .= $val; - $res .= ""; - } - else { - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $this->_row_values[$vname]; - $res .= ""; - $res .= $val; - $res .= ""; - } - break; - case "$": - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $HTTP_SESSION_VARS[$vname]; - $res .= ""; - $res .= $val; - $res .= ""; - break; - default: - $res .= ""; - $res .= $col["Content"]; - $res .= ""; - break; - } - } - else - { - $res .= ""; - $res .= $val; - $res .= ""; - } - break; - - case "iflink": - if ( $col["Content"] != "" ) - { - $tlabel = substr( $col["Content"] , 0, 1 ); - if( $val != "" ) - { - switch( $tlabel ) - { - case "&": - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $this->_row_values[$vname]; - $res .= ""; - $res .= $val; - $res .= ""; - break; - case "$": - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $HTTP_SESSION_VARS[$vname]; - $res .= ""; - $res .= $val; - $res .= ""; - break; - default: - $res .= ""; - $res .= $col["Content"]; - $res .= ""; - break; - } - } - else - { - $res .= " "; - } - } - else - { - $res .= ""; - $res .= $val; - $res .= ""; - } - break; - - - case "jsimglink": - $val = ""; - - case "jslink": - if ( $val == "" ) $val .= " " . $col['Name'] . ''; - if ( $val == "" ) $res .= " "; - if ( $col["Content"] != "" ) - { - $tlabel = substr( $col["Content"] , 0, 1 ); - switch( $tlabel ) - { - case "&": - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $this->_row_values[$vname]; - $res .= ""; - $res .= $val; - $res .= ""; - break; - - case "$": - $vname = substr( $col["Content"], 1, (strlen($col["Content"]) - 1) ); - $lval = $HTTP_SESSION_VARS[$vname]; - $res .= ""; - $res .= $val; - $res .= ""; - break; - - case '_': - $Values = explode(',', substr($col['Content'], 1, strlen($col['Content']))); - $res .= "_row_values[substr($Value, 1, strlen($Value))] . ','; - else - $res .= "'" . $this->_row_values[substr($Value, 1, strlen($Value))] . "',"; - else - $res .= $Value . ','; - } - $res = substr($res, 0, strlen($res) - 1); - $res .= ")\"" . $col['Extra'] . ">"; - $res .= $val; - $res .= ""; - break; - - default: - $res .= ""; - $res .= $col["Content"]; - $res .= ""; - break; - } - } - else - { - $res .= ""; - $res .= $val; - $res .= ""; - } - break; - - case "checkbox": - $res .= " - * @access public - * @param string $strAction Next action to do - * @param string $strLabel Label - * @return void - */ - function SetAction( $strAction, $strLabel="Continue" ) - { - $this->Action = $strAction; - $this->ActionLabel = $strLabel; - } - - /** - * Set contaxt and table (array) of translate - * - * @author Hardy Beltran Monasterios - * @param string $contexto Contexto en el cual se busca la traducci?n - * @param array $tabla Tabla con valores para traducir - * @param string $nombre Nombre del array $tabla - * @access public - * @return void - */ - function setTranslate( $contexto, $tabla, $nombre ) - { - if (is_array($this->contexto)) { - $this->contexto[0][] = $contexto; - $this->contexto[1][] = $nombre; - - } else { - $this->contexto = array(); - $this->contexto[0][] = $contexto; - $this->contexto[1][] = $nombre; - // array_push($this->contexto[0], $contexto); - // array_push($this->contexto[1], $nombre); - } - if (is_array($this->translate)) { - $this->translate = array(); - $this->translate[$nombre] = $tabla; - } else { - $this->translate[$nombre] = $tabla; - } - // Fijamos ultimo contexto usado - $this->_contexto = $contexto; - } - - /** - * Search value in the table of translation and returns last accourding to choised context - * Retorna el valor a su equivalente traducido/convertido - * @author Hardy Beltran Monasterios - * @param string $contexto Contexto en el cual se busca la traducci?n - * @param mixed $valor Valor que se va traducir/convertir - * @param string $lang El lenguaje que se va utilizar - * @return mixed - */ - function translateValue( $contexto, $valor, $lang ) - { - // Verificar si exite el contexto - if (in_array($contexto, $this->contexto[0])) { - $j = count($this->contexto[0]); - for ( $i=0; $i < $j; $i++ ) { - if ($contexto == $this->contexto[0][$i]){ - $origen = $this->contexto[1][$i]; - } - } - $tabla = $this->translate[$origen]; - if (isset($tabla[$lang][$valor])) { - return $tabla[$lang][$valor]; - } else { - print ("l10n error:no lang or value."); - } - } else { - print ("l10n error:no context."); - } - } - - /** - * Estable el contexto de traducci?n/conversi?n - * - * @author Hardy Beltran Monasterios - * @param string $contexto Contexto en el cual se busca la traducci?n - * @return void - */ - function setContext( $contexto ) - { - $this->_context = $contexto; - } - -/** - * Parse from HTML - * - * @author Fernando Ontiveros Lira - * @access public - * @return void - */ - function ParsingFromHtml($value, $number = '100000000') - { - $car = substr($value, 0,1); - $len = strlen($value); - $Flag = 1; - $token = ''; - $i = 0; - - While ($i<=$len and $i <= $number){ - $car=substr($value,$i,1); - $br = strtoupper(substr($value,$i,4)); - if ($car == '<'){ - $Flag = 0; - } - if ($car == '>'){ - $Flag = 1; - } - if($br == '
' || $br == '

') - $token .= "
"; - - if (($Flag == 1)&& ($car != '>')){ - $token .= $car; - if ( $i == $number ) - $token .= "... "; - } - $i = $i +1; - } - return $token; - } +. + * + * For more information, contact Colosa Inc, 2566 Le Jeune Rd., + * Coral Gables, FL, 33134, USA, or email info@colosa.com. + * + */ +/** + * + * + * + * + * Table class definition + * Render table + * + * @package gulliver.system + * @author Fernando Ontiveros Lira + * @copyright (C) 2002 by Colosa Development Team. + * + */ + +class Table +{ + var $Columns = null; + var $Labels = null; + var $rows_per_page = 25; + var $show_nummbers = null; + var $first_row = 0; + var $row_pos = 0; + var $Action = ""; //not used + var $ActionLabel = "Continuar"; //not used + var $_dbc = null; + var $_dbses = null; + var $_dbset = null; + var $_source = ""; + var $DefaultOrder = "UID"; + var $DefaultOrderDir = 'ASC'; + var $CustomOrder = ""; + var $WhereClause = ""; + var $_row_values = null; + var $_ordered = true; + var $orderprefix = ""; + var $CountQry = ""; + var $filtro = 1; + var $title = ''; + + /** + * Asocia un arreglo con valores de traducci?n/conversi?n a un contexto + * + * @var array + */ + var $contexto = null; + + /** + * Arreglo que contiene las cadenas que van a ser usadas al traducir/convertir + * + * @var array + */ + var $translate = null; + + /** + * Establece el ?ltimo contexto utilizado + * + * @var string + */ + var $_contexto = ''; + + /** + * Set conecction using default values + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $objConnection connection string + * @return void + */ + function Table ($objConnection = null) + { + $this->SetTo( $objConnection ); + } + + /** + * Set conecction using default values + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $objConnection connection string + * @return void + */ + function SetTo ($objConnection = null) + { + $this->_dbc = $objConnection; + } + + /** + * Set query string + * + * @author Fernando Ontiveros Lira + * @access public + * @param string $stQry query string + * @param string $stDefaultOrder index to order by, default value='UID' + * @return void + */ + function SetSource ($stQry = "", $stDefaultOrder = "UID", $stDefaultOrderDir = 'ASC') + { + //to fix missing value for variable orderDir, when between pages changes. + $url1 = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?'; + $url2 = strstr( $_SERVER['HTTP_REFERER'] . '?', $_SERVER['HTTP_HOST'] ); + $url1 = substr( $url1, 0, strpos( $url1, '?' ) ); + $url2 = substr( $url2, 0, strpos( $url2, '?' ) ); + if ($url1 != $url2) { + if (isset( $_SESSION['OrderBy'] )) { + unset( $_SESSION['OrderBy'] ); + } + if (isset( $_SESSION['OrderDir'] )) { + unset( $_SESSION['OrderDir'] ); + } + } + $this->_source = $stQry; + $this->DefaultOrder = $stDefaultOrder; + $this->DefaultOrderDir = $stDefaultOrderDir; + } + + /** + * Obtains query string asociated + * + * @author Fernando Ontiveros Lira + * @access public + * @return void + */ + function GetSource () + { + global $HTTP_GET_VARS; + global $HTTP_SESSION_VARS; + $stOrderByDir = $this->DefaultOrderDir; + if (isset( $HTTP_SESSION_VARS['OrderDir'] ) && ($HTTP_SESSION_VARS['OrderDir'] == 'DESC' || $HTTP_SESSION_VARS['OrderDir'] == 'ASC')) + $stOrderByDir = $HTTP_SESSION_VARS['OrderDir']; + + $stQry = $this->_source; + if ($this->WhereClause != "") { + $stQry .= " WHERE " . $this->WhereClause; + } + + if ($this->_ordered == true) { + $stOrderBy = (isset( $HTTP_GET_VARS[$this->orderprefix . 'order'] ) ? $HTTP_GET_VARS[$this->orderprefix . 'order'] : ''); + $stOrderLb = (isset( $HTTP_GET_VARS[$this->orderprefix . 'label'] ) ? $HTTP_GET_VARS[$this->orderprefix . 'label'] : ''); + + //if( isset( $HTTP_SESSION_VARS['OrderDir'] ) && $HTTP_SESSION_VARS['OrderDir'] == $stOrderBy ) { + if ($stOrderLb) { + if ($HTTP_SESSION_VARS['OrderDir'] == 'ASC') { + $stOrderByDir = 'DESC'; + } elseif ($HTTP_SESSION_VARS['OrderDir'] == 'DESC') { + $stOrderByDir = 'ASC'; + } + } elseif (isset( $HTTP_SESSION_VARS['OrderDir'] ) && $HTTP_SESSION_VARS['OrderDir'] != '') { + $stOrderByDir = $HTTP_SESSION_VARS['OrderDir']; + } else { + $stOrderByDir = $this->DefaultOrderDir; + } + + if ($stOrderBy == "") { + if ($this->DefaultOrder != "") { + $aux = str_replace( ' ASC|', '', $this->DefaultOrder . '|' ); + $aux = str_replace( ' DESC|', '', $aux ); + $aux = str_replace( '|', '', $aux ); + $stQry .= " ORDER BY " . $aux . " " . $stOrderByDir; + } + } else { + $stQry .= " ORDER BY " . $stOrderBy; + if ($stOrderByDir != "") { + $stQry .= " $stOrderByDir"; + + } + } + } else { + if ($this->DefaultOrder != "") { + $stQry .= " ORDER BY " . $this->DefaultOrder . " " . (isset( $stOrderBy ) ? $stOrderBy : ''); + } + } + //print $stQry; + + + $HTTP_SESSION_VARS['OrderBy'] = isset( $stOrderBy ) ? $stOrderBy : ''; + $HTTP_SESSION_VARS['OrderDir'] = $stOrderByDir; + + $page = (isset( $HTTP_GET_VARS["page"] ) ? $HTTP_GET_VARS["page"] : ''); + + $tr = (isset( $HTTP_SESSION_VARS['TP'] ) ? $HTTP_SESSION_VARS['TP'] : ''); + + $desde = 0; + + if ($page != "") { + //$desde=(($page-1)*25); + $desde = (($page - 1) * $this->rows_per_page); + + //$strLimit = " LIMIT $desde , 25"; + $strLimit = " LIMIT $desde , $this->rows_per_page"; + if (PEAR_DATABASE == 'pgsql') { + //$strLimit = " OFFSET $desde LIMIT 25"; + $strLimit = " OFFSET $desde LIMIT $this->rows_per_page"; + } + $stQry .= $strLimit; + } + + //print $stQry; + $this->_dbses = new DBSession( $this->_dbc ); + $this->_dbses->UseDB( DB_NAME ); + $this->_dbses->Query( $stQry ); + $this->_dbset = new DBRecordset( $this->_dbses->result ); + } + + /** + * Obtains number of elements of asociated query + * + * @author Fernando Ontiveros Lira + * @access public + * @return int + */ + function TotalCount () + { + global $HTTP_GET_VARS; + global $HTTP_SESSION_VARS; + + $stQry = $this->_source; + if ($this->WhereClause != "") { + $stQry .= " WHERE " . $this->WhereClause; + } + if ($this->_ordered == true) { + $stOrderBy = (isset( $HTTP_GET_VARS[$this->orderprefix . 'order'] ) ? $HTTP_GET_VARS[$this->orderprefix . 'order'] : ''); + if ($stOrderBy == "") { + if ($this->DefaultOrder != "") { + $stQry .= " ORDER BY " . $this->DefaultOrder; + } + } else { + $stQry .= " ORDER BY " . $stOrderBy; + } + } else { + if ($this->DefaultOrder != "") { + $stQry .= " ORDER BY " . $this->DefaultOrder; + } + } + + $dbses = new DBSession( $this->_dbc ); + $dbses->UseDB( DB_NAME ); + $dset = $dbses->Execute( $stQry ); + return $dset->Count(); + } + + /** + * Obtains number of elements of asociated recordset + * + * @author Fernando Ontiveros Lira + * @access public + * @return int + */ + function Count () + { + if (is_object( $this->_dbset )) { + return $this->_dbset->Count(); + } else { + return 0; + } + } + + /** + * Obtains row position + * + * @author Fernando Ontiveros Lira + * @access public + * @return int + */ + function CurRow () + { + return $this->row_pos; + } + + /** + * Obtains number columns + * + * @author Fernando Ontiveros Lira + * @access public + * @return int + */ + function ColumnCount () + { + $result = 0; + if (is_array( $this->Columns )) { + $result = count( $this->Columns ); + } + return $result; + } + + /** + * Obtains a row array and moves the internal data pointer ahead + * + * @author Fernando Ontiveros Lira + * @access public + * @return array + */ + function Read () + { + $this->_row_values = $this->_dbset->Read(); + $this->row_pos ++; + return $this->_row_values; + } + + /** + * Moves the internal row pointer + * + * @author Fernando Ontiveros Lira + * @access public + * @param int $intPos position to seek + * @return int + */ + function Seek ($intPos = 0) + { + $result = $this->_dbset->Seek( $intPos ); + if ($result) { + $this->row_pos = $intPos; + } + return $result; + } + + /** + * Moves the internal row pointer to first position + * + * @author Fernando Ontiveros Lira + * @access public + * @return int + */ + function MoveFirst () + { + if ($this->Count() != 0) { + if ($this->first_row < $this->Count()) { + $this->Seek( $this->first_row ); + } + } + } + + /** + * Verify if row position is in the end + * + * @author Fernando Ontiveros Lira + * @access public + * @return boolean + */ + function EOF () + { + $result = false; + if ($this->Count() == 0) { + $result = true; + } else { + if ($this->row_pos >= $this->Count()) { + $result = true; + } else { + if ($this->rows_per_page != 0) { + if ($this->row_pos >= $this->first_row + $this->rows_per_page) { + $result = true; + } + } + } + } + return $result; + } + + /** + * Set values to add a column to show in the dynaform + * + * @author Fernando Ontiveros Lira + * @access public + * @param $strLabel + * @param $strType + * @param $strName + * @param $strAlign + * @param $intWidth + * @param $strTarget + * @param $strContent + * @return void + */ + function AddColumn ($strLabel = "", $strType = "text", $strName = "", $strAlign = "left", $intWidth = 0, $strTarget = "", $strContent = "") + { + $tmpCol = array ("Name" => $strName,"Type" => $strType,"Width" => $intWidth,"Align" => $strAlign,"Target" => $strTarget,"Content" => $strContent + ); + $pos = 0; + if (is_array( $this->Columns )) { + $pos = count( $this->Columns ); + } + $this->Columns[$pos] = $tmpCol; + $this->Labels[$pos] = $strLabel; + } + + /** + * Set values to add a column to show in the dynaform + * + * @author Fernando Ontiveros Lira + * @access public + * @param $strType + * @param $strName + * @param $strAlign + * @param $intWidth + * @param $strTarget + * @param $strContent + * @param $strExtra + * @param $strCondition + * @param $orderByThis + * @return void + */ + function AddRawColumn ($strType = "text", $strName = "", $strAlign = "left", $intWidth = 0, $strTarget = "", $strContent = "", $strExtra = "", $strCondition = "", $orderByThis = true) + { + $tmpCol = array ("Name" => $strName,"Type" => $strType,"Width" => $intWidth,"Align" => $strAlign,"Target" => $strTarget,"Content" => $strContent,"Extra" => $strExtra,"Condition" => $strCondition,"orderByThis" => $orderByThis + ); + $pos = 0; + if (is_array( $this->Columns )) { + $pos = count( $this->Columns ); + } + $this->Columns[$pos] = $tmpCol; + $this->Labels[$pos] = ""; + } + + /** + * Show dynaform's title + * + * @author Fernando Ontiveros Lira + * @access public + * @param $pa + * @param $intPos + * @param $strClass + * @return void + */ + function RenderTitle ($pa, $intPos = 1, $strClass = "tblHeader") + { + if (! defined( 'ENABLE_ENCRYPT' )) { + define( 'ENABLE_ENCRYPT', 'no' ); + } + global $HTTP_SESSION_VARS; + $col = $this->Columns[$intPos]; + $order = ! ($col["Type"] == "image"); + if ($this->_ordered == true && $order) { + $res = " 0) { + $res .= " width=\"" . $col["Width"] . "\""; + } + $res .= ">"; + + //$res .= "
" . $this->Labels[$intPos] . ""; + + $res .= "\n"; //echo $res;die; + } else { + $res = " 0) { + $res .= " width=\"" . $col["Width"] . "\""; + } + $res .= ">"; + $res .= $this->Labels[$intPos] . "\n"; + } + return $res; + } + + /** + * Show dynaform's title using ajax + * + * @author Fernando Ontiveros Lira + * @access public + * @param $pa + * @param $intPos + * @param $strClass + * @return void + */ + function RenderTitle_ajax ($pa, $intPos = 1, $strClass = "tblHeader") + { + global $HTTP_SESSION_VARS; + $col = $this->Columns[$intPos]; + $order = ! (($col["Type"] == "image") || ($col["Type"] == "jsimglink")); + + if ($this->_ordered == true && $order) { + $res = " 0) { + $res .= " width=\"" . $col["Width"] . "\""; + } + $res .= ">"; + + //$res .= "Columns[$intPos]['Name']; + $res .= "Javascript:changetableOrder('$_temp_var',$pa)"; + //$res .= $_SERVER['REDIRECT_URL'] . "?order=" . $this->Columns[$intPos]['Name']."&page=".$pa."&label=true"; + $res .= "\">" . $this->Labels[$intPos] . ""; + if ($HTTP_SESSION_VARS['OrderBy'] == $this->Columns[$intPos]['Name']) { + if ($HTTP_SESSION_VARS['OrderDir'] == 'DESC') { + $res .= " "; + } else { + $res .= " "; + } + } + + $res .= "\n"; //echo $res;die; + } else { + $res = " 0) { + $res .= " width=\"" . $col["Width"] . "\""; + } + $res .= ">"; + $res .= $this->Labels[$intPos] . "\n"; + } + return $res; + } + + /** + * Show dynaform title + * + * @author Fernando Ontiveros Lira + * @access public + * @param $pa + * @param $fil + * @param $intPos + * @param $strClass + * @param $auxgetval + * @return void + */ + function RenderTitle2 ($pa, $fil, $intPos, $strClass = "tblHeader", $auxgetval = '') + { + if (! defined( 'ENABLE_ENCRYPT' )) { + define( 'ENABLE_ENCRYPT', 'no' ); + } + global $HTTP_SESSION_VARS; + + if ($auxgetval == '') { + $targ = SYS_TARGET . ".html"; + } else { + $targ = SYS_TARGET . '.html?' . $auxgetval; + } + $target = (ENABLE_ENCRYPT == 'yes' ? G::encryptUrl( urldecode( $targ ), URL_KEY ) : $targ); + + $col = $this->Columns[$intPos]; + + if ($col['Type'] == 'hidden') { + return ''; + } + $order = ! ($col["Type"] == "image"); + + if (($this->_ordered == true) && ($order) && ($this->Columns[$intPos]['orderByThis'])) { + $res = ""; + if (($this->show_nummbers) and ($intPos == 0)) { + $res = "# "; + } + $res .= " 0) { + $res .= " width=\"" . $col["Width"] . "\""; + } + $res .= "> "; + + $res .= "" . $this->Labels[$intPos] . ""; + + $res .= "\n"; + } else { + $col = $this->Columns[$intPos]; + $res = " 0) { + $res .= " width=\"" . $col["Width"] . "\""; + } + $res .= ">"; + $res .= (isset( $this->Labels[$intPos] ) ? $this->Labels[$intPos] : '') . "\n"; + } + return $res; + } + + /** + * Show dynaform column + * + * @author Fernando Ontiveros Lira + * @access public + * @param $intPos + * @param $strClass + * @param $strClassLink + * @param $number + * @param $renderTD if this value = 1, this function will include the TD tags + * @return void + */ + function RenderColumn ($intPos = 0, $strClass = "tblCell", $strClassLink = "tblCellA", $number = 0, $renderTD = 1) + { + if (! defined( 'ENABLE_ENCRYPT' )) { + define( 'ENABLE_ENCRYPT', 'no' ); + } + global $G_DATE_FORMAT; + global $G_TABLE_DATE_FORMAT; + $col = $this->Columns[$intPos]; + + switch (substr( $col['Name'], 0, 1 )) { + case '=': + // Si empieza con '=' entonces se toma como valor constante + $val = substr( $col['Name'], 1, strlen( $col['Name'] ) - 1 ); + break; + case '%': + // Si empieza con '%' entonces traducir/convertir el valor + $fieldname = substr( $col['Name'], 1, strlen( $col['Name'] ) - 1 ); + $val = $this->_row_values[$fieldname]; + $val = $this->translateValue( $this->_contexto, $val, SYS_LANG ); + break; + default: + $fieldname = $col['Name']; + $val = isset( $this->_row_values[$fieldname] ) ? $this->_row_values[$fieldname] : ''; + } + + $res = ""; + if (($this->show_nummbers) and ($intPos == 0)) { + $res = "$number"; + } + if (! (stristr( $val, "script" ) === false)) { + $val = htmlentities( $val, ENT_QUOTES, 'utf-8' ); + } + + if ($renderTD == 1) { + $res .= " 0) { + $res .= " width=\"" . $col["Width"] . "\""; + } + $res .= "> "; + } + + switch ($col["Type"]) { + case 'hidden': + return ''; + break; + case "text": + if ($val != "") { + $res .= G::unhtmlentities( $val, ENT_QUOTES, 'utf-8' ); + } else { + $res .= " "; + } + break; + case "text-dontSearch": + if ($val != "") { + $res .= G::unhtmlentities( $val ); + } else { + $res .= " "; + } + break; + case "html": + if ($val != "") { + $res .= ($val); + } else { + $res .= " "; + } + break; + case "textPlain": + if ($val != "") { + $res .= ($this->ParsingFromHtml( G::unhtmlentities( $val ), "300" )); + //if ( $val != "" ) $res .= (($val)); + } else { + $res .= " "; + } + break; + case "currency": + if ($val != "") { + $aux = explode( ' ', $val ); + $format = number_format( (float) $aux[0], 2, ".", "," ); + $res .= htmlentities( $format . ' ' . (isset( $aux[1] ) ? $aux[1] : ''), ENT_QUOTES, 'utf-8' ); + } else { + $res .= " "; + } + break; + + case "currency2": + if ($val != "") { + $res .= G::NumberToCurrency( $val ); + } else { + $res .= "$ 0.00"; + } + break; + + case "percentage2": + if ($val != "") { + $res .= G::NumberToPercentage( $val ); + } else { + $res .= "0.00 %"; + } + break; + + case "percentage": + if ($val != "") { + $res .= htmlentities( number_format( (float) $val, 2, ".", "," ) . " %", ENT_QUOTES, 'utf-8' ); + } else { + $res .= " "; + } + break; + + case "date": + if ($val != "" && $val != '0000-00-00 00:00:00') { + $part = explode( ' ', $val ); + $aux = explode( '-', $part[0] ); + + switch ($G_DATE_FORMAT) { + case 'DD/MM/AAAA': + $res .= formatDate( '$d/$m/$Y $H:$i:$s', $val ); + break; + case 'MM/DD/AAAA': + $res .= formatDate( '$m/$d/$Y $H:$i:$s EST', $val ); + break; + case 'AAAA/MM/DD': + $res .= formatDate( '$Y/$m/$d $H:$i:$s', $val ); + break; + case 'LITERAL': + $res .= formatDate( '$M $d $Y', $val ); + break; + } + + } else { + $res .= " "; + } + break; + + case "email": + if ($val != "") { + $res .= ""; + $res .= $val; + $res .= ""; + } else { + $res .= " "; + } + break; + + case "ifpdf": + if ($val == '1') { + $image = ""; + //valor + $tlabel = substr( $col["Content"], 0, 1 ); + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $this->_row_values[$vname]; + //$res .= " $image "; //It open a new window... better the other way By JHL 16/11/06 + $res .= " $image "; + } else { + $res .= " "; + } + break; + + case "ifimg": + $image = ""; + if ($val == '1') { + //valor + $tlabel = substr( $col["Content"], 0, 1 ); + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $this->_row_values[$vname]; + $res .= " $image "; + } else { + $res .= " "; + } + break; + + case "ifrtf": + if ($val == '1') { + $image = ""; + //valor + $tlabel = substr( $col["Content"], 0, 1 ); + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $this->_row_values[$vname]; + //$res .= " $image "; //It open a new window... better the other way By JHL 16/11/06 + $res .= " $image "; + } else { + $res .= " "; + } + break; + + case "image": + + if (is_array( $col["Condition"] )) //By JHL to enable Condition to display a image -- New parameter Condition in Addrawcolumn +{ + $field_compare = $col["Condition"]['field']; + $tlabel = substr( $field_compare, 0, 1 ); + switch ($tlabel) { + case "&": + $vname = substr( $field_compare, 1, (strlen( $field_compare ) - 1) ); + $field_val = $this->_row_values[$vname]; + break; + } + + } else { + $val = ""; + } + // break; + + + case "textimage": + $AAS = $col['Extra']; + $val1 = " "; + // break; + case "image-text": + if (is_array( $col['Content'] ) && $col['Content'] != "") { + // Hay mas de un valor para el link + $values = $col['Content']; + $n = count( $values ); + + $res .= "_row_values[$vname]; + + $res .= $i == $n - 1 ? $lval : $lval . "/"; + break; + } + } + $res .= "\">" . strtoupper( $fieldname ) . "$val"; + } else + $val2 = "" . strtoupper( $fieldname ) . ""; + // break; + + + case "link": + if ($val == "") + $res .= " "; + $title = ''; + if ($col["Type"] == 'link' && trim( isset( $this->_row_values['TOOLTIP'] ) ? $this->_row_values['TOOLTIP'] : '' )) + ; + $title = (isset( $this->_row_values['TOOLTIP'] ) ? "title=\" " . $this->_row_values['TOOLTIP'] . " \"" : ''); + if (is_array( $col['Content'] ) && $col['Content'] != "") { + // Hay mas de un valor para el link + $values = $col['Content']; + $n = count( $values ); + + $res .= "_row_values[$vname]; + + $res .= $i == $n - 1 ? $lval : $lval . "/"; + break; + } + } + $res .= "\">$val"; + } elseif ($col["Content"] != "" && ! is_array( $col['Content'] )) { + $tlabel = substr( $col["Content"], 0, 1 ); + switch ($tlabel) { + case "&": + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $this->_row_values[$vname]; + if (ENABLE_ENCRYPT == 'yes') { + + //$encoded = G::encrypt ( $col["Target"] . "/" . $lval . ".html", URL_KEY ); + $encoded = G::encryptUrl( $col["Target"] . "/" . $lval . ".html", URL_KEY ); + $res .= ""; + if ($col["Type"] == "textimage") { + $res .= $val1; + $val = " (" . $val . ")"; + } + if ($col["Type"] == "image-text") { + + $res .= $val2; + } + $res .= $val; + $res .= ""; + } else { + $res .= ""; + if ($col["Type"] == "textimage") { + $res .= $val1; + $val = " (" . $val . ")"; + } + if ($col["Type"] == "image-text") { + + $res .= $val2; + } + $res .= $val; + $res .= ""; + } + break; + case "$": + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $HTTP_SESSION_VARS[$vname]; + $res .= ""; + $res .= $val; + $res .= ""; + break; + default: + $res .= ""; + $res .= $col["Content"]; + $res .= ""; + break; + } + } else { + $res .= ""; + $res .= $val; + $res .= ""; + } + break; + + case "linknew": + if ($val == "") + $res .= " "; + if ($col["Content"] != "") { + $tlabel = substr( $col["Content"], 0, 1 ); + switch ($tlabel) { + case "&": + if (ENABLE_ENCRYPT == 'yes') { + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $this->_row_values[$vname]; + //$encoded = G::encryptUrl ( $col["Target"] , URL_KEY ). "/" . $lval . ".html"; + $encoded = G::encryptUrl( $col["Target"] . "/" . $lval . "", URL_KEY ); + $res .= ""; + $res .= $val; + $res .= ""; + } else { + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $this->_row_values[$vname]; + $res .= ""; + $res .= $val; + $res .= ""; + } + break; + case "$": + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $HTTP_SESSION_VARS[$vname]; + $res .= ""; + $res .= $val; + $res .= ""; + break; + default: + $res .= ""; + $res .= $col["Content"]; + $res .= ""; + break; + } + } else { + $res .= ""; + $res .= $val; + $res .= ""; + } + break; + + case "iflink": + if ($col["Content"] != "") { + $tlabel = substr( $col["Content"], 0, 1 ); + if ($val != "") { + switch ($tlabel) { + case "&": + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $this->_row_values[$vname]; + $res .= ""; + $res .= $val; + $res .= ""; + break; + case "$": + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $HTTP_SESSION_VARS[$vname]; + $res .= ""; + $res .= $val; + $res .= ""; + break; + default: + $res .= ""; + $res .= $col["Content"]; + $res .= ""; + break; + } + } else { + $res .= " "; + } + } else { + $res .= ""; + $res .= $val; + $res .= ""; + } + break; + + case "jsimglink": + $val = ""; + + case "jslink": + if ($val == "") { + $val .= " " . $col['Name'] . ''; + } + if ($val == "") { + $res .= " "; + } + if ($col["Content"] != "") { + $tlabel = substr( $col["Content"], 0, 1 ); + switch ($tlabel) { + case "&": + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $this->_row_values[$vname]; + $res .= ""; + $res .= $val; + $res .= ""; + break; + + case "$": + $vname = substr( $col["Content"], 1, (strlen( $col["Content"] ) - 1) ); + $lval = $HTTP_SESSION_VARS[$vname]; + $res .= ""; + $res .= $val; + $res .= ""; + break; + + case '_': + $Values = explode( ',', substr( $col['Content'], 1, strlen( $col['Content'] ) ) ); + $res .= "_row_values[substr( $Value, 1, strlen( $Value ) )] . ','; + } else { + $res .= "'" . $this->_row_values[substr( $Value, 1, strlen( $Value ) )] . "',"; + } + } else { + $res .= $Value . ','; + } + } + $res = substr( $res, 0, strlen( $res ) - 1 ); + $res .= ")\"" . $col['Extra'] . ">"; + $res .= $val; + $res .= ""; + break; + + default: + $res .= ""; + $res .= $col["Content"]; + $res .= ""; + break; + } + } else { + $res .= ""; + $res .= $val; + $res .= ""; + } + break; + + case "checkbox": + $res .= " + * @access public + * @param string $strAction Next action to do + * @param string $strLabel Label + * @return void + */ + function SetAction ($strAction, $strLabel = "Continue") + { + $this->Action = $strAction; + $this->ActionLabel = $strLabel; + } + + /** + * Set contaxt and table (array) of translate + * + * @author Hardy Beltran Monasterios + * @param string $contexto Contexto en el cual se busca la traducci?n + * @param array $tabla Tabla con valores para traducir + * @param string $nombre Nombre del array $tabla + * @access public + * @return void + */ + function setTranslate ($contexto, $tabla, $nombre) + { + if (is_array( $this->contexto )) { + $this->contexto[0][] = $contexto; + $this->contexto[1][] = $nombre; + + } else { + $this->contexto = array (); + $this->contexto[0][] = $contexto; + $this->contexto[1][] = $nombre; + // array_push($this->contexto[0], $contexto); + // array_push($this->contexto[1], $nombre); + } + if (is_array( $this->translate )) { + $this->translate = array (); + $this->translate[$nombre] = $tabla; + } else { + $this->translate[$nombre] = $tabla; + } + // Fijamos ultimo contexto usado + $this->_contexto = $contexto; + } + + /** + * Search value in the table of translation and returns last accourding to choised context + * Retorna el valor a su equivalente traducido/convertido + * + * @author Hardy Beltran Monasterios + * @param string $contexto Contexto en el cual se busca la traducci?n + * @param mixed $valor Valor que se va traducir/convertir + * @param string $lang El lenguaje que se va utilizar + * @return mixed + */ + function translateValue ($contexto, $valor, $lang) + { + // Verificar si exite el contexto + if (in_array( $contexto, $this->contexto[0] )) { + $j = count( $this->contexto[0] ); + for ($i = 0; $i < $j; $i ++) { + if ($contexto == $this->contexto[0][$i]) { + $origen = $this->contexto[1][$i]; + } + } + $tabla = $this->translate[$origen]; + if (isset( $tabla[$lang][$valor] )) { + return $tabla[$lang][$valor]; + } else { + print ("l10n error:no lang or value.") ; + } + } else { + print ("l10n error:no context.") ; + } + } + + /** + * Estable el contexto de traducci?n/conversi?n + * + * @author Hardy Beltran Monasterios + * @param string $contexto Contexto en el cual se busca la traducci?n + * @return void + */ + function setContext ($contexto) + { + $this->_context = $contexto; + } + + /** + * Parse from HTML + * + * @author Fernando Ontiveros Lira + * @access public + * @return void + */ + function ParsingFromHtml ($value, $number = '100000000') + { + $car = substr( $value, 0, 1 ); + $len = strlen( $value ); + $Flag = 1; + $token = ''; + $i = 0; + + While ($i <= $len and $i <= $number) { + $car = substr( $value, $i, 1 ); + $br = strtoupper( substr( $value, $i, 4 ) ); + if ($car == '<') { + $Flag = 0; + } + if ($car == '>') { + $Flag = 1; + } + if ($br == '
' || $br == '

') + $token .= "
"; + + if (($Flag == 1) && ($car != '>')) { + $token .= $car; + if ($i == $number) + $token .= "... "; + } + $i = $i + 1; + } + return $token; + } }