Source for file OCSP_MOD_CONF.phpclass

Documentation is available at OCSP_MOD_CONF.phpclass

  1. <?php
  2. /**
  3.   * openCSP class OCSP_MOD_CONF.phpclass
  4.   *
  5.   * @project Open CSP-Management
  6.   * @package default
  7.   *
  8.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-17.03.2008
  12.   * @version $Id: OCSP_MOD_CONF.phpclass,v 1.2 2008/10/30 07:35:28 pitlinz Exp $
  13.   * 
  14.   * @deprecated since pk-08-10-28
  15.   ***/
  16.  
  17. // ---------------------------------------------------------
  18. // requirements
  19. // ---------------------------------------------------------
  20.  
  21. pcf_require_class('DBMS_TABLEOBJ',__OCSP_PHPINCPATH__ "db" _OCSP_DIRSEP_ "DBMS_TABLEOBJ.phpclass");
  22.  
  23.  
  24. if (!function_exists('pcf_checkDir'))
  25. {
  26.     require __OCSP_PHPINCPATH__ "common" _OCSP_DIRSEP_ "pcf_directory.phpinc";
  27. }
  28.  
  29. // ---------------------------------------------------------
  30. // constants
  31. // ---------------------------------------------------------
  32.  
  33. if (!defined('_OCSP_EXCEP_MOD_NOTREGISTERED_')) define('_OCSP_EXCEP_MOD_NOTREGISTERED_','OCSP MODULE NOT REGISTERED');
  34. if (!defined('_OCSP_EXCEP_MODULE_NOT_FOUND_'))    define('_OCSP_EXCEP_MODULE_NOT_FOUND_',"MODULE NOT FOUND");
  35.  
  36. /**
  37.   * openCSP class OCSP_MOD_CONF
  38.   *
  39.   * @project Open CSP-Management
  40.   * @package default
  41.   *
  42.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  43.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  44.   *
  45.   * @since pk-17.03.2008
  46.   * @version $Id: OCSP_MOD_CONF.phpclass,v 1.2 2008/10/30 07:35:28 pitlinz Exp $
  47.   * 
  48.   * @deprecated since pk-08-10-28
  49.   ***/
  50. class OCSP_MOD_CONF extends DBMS_TABLEOBJ
  51. {
  52.     /*** class constants  --------------------------------------------- */
  53.  
  54.     /**
  55.      * @constant string CLASS_SRC_FILE
  56.      *
  57.      * @abstract
  58.      */
  59.     const CLASS_SRC_FILE = __FILE__;
  60.         
  61.     /*** class variables  --------------------------------------------- */
  62.     
  63.     /**
  64.      * array of configured modules
  65.      *
  66.      * @var array $modules 
  67.      */
  68.     private static $modules array();
  69.     
  70.     /**
  71.      * name of the table the settings are stored
  72.      *
  73.      * @staticvar string $settingTbl 
  74.      */
  75.     private static $settingTbl "T_MOD_SETTINGS";
  76.     
  77.     /*** compostion ------------------------------------------------- */
  78.     
  79.     /*** attributes  ------------------------------------------------ */
  80.  
  81.     /**
  82.      * table name
  83.      *
  84.      * @var string 
  85.      */
  86.     protected $myTable="T_MOD_MODULES";    
  87.     
  88.     /**
  89.      * array of conf settings
  90.      * 
  91.      * @var array $mySettings 
  92.      */
  93.     protected $mySettings = array();
  94.     
  95.  
  96.     
  97.     /*** static functions ------------------------------------------- */
  98.     
  99.     /**
  100.      * returns the modul cache path
  101.      *
  102.      * @return string 
  103.      */
  104.     public static function getCachePath()
  105.     {
  106.         return OCSP_OBJ::getConf('CACHEPATH'_OCSP_DIRSEP_ "modules" _OCSP_DIRSEP_;
  107.     }
  108.  
  109.     
  110.     public static function loadModule($modName,$debug=false)
  111.     {
  112.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_MOD_CONF::loadModule($modName)");
  113.         
  114.         if (isset(self::$modules[$modName]&& is_object(self::$modules[$modName]))
  115.         {
  116.             return true;
  117.         else if (file_exists(self::getCachePath("config" _OCSP_DIRSEP_ $modName ".xml")) {        
  118.             self::$modules[$modNamenew OCSP_MOD_CONF($modName);
  119.             return true;    
  120.         else if (file_exists(self::getConf('MODULEPATH'"mod_" $modName "/config/config.phpinc")) {
  121.             require_once self::getConf('MODULEPATH'"mod_" $modName "/config/config.phpinc";
  122.  
  123.         else if (pcf_fileExists(dirname(__OCSP_PHPINCPATH___OCSP_DIRSEP_ .  "mod_" $modName "/config/config.phpinc")) {
  124.             require_once dirname(__OCSP_PHPINCPATH___OCSP_DIRSEP_ .  "mod_" $modName "/config/config.phpinc";
  125.         else if (pcf_fileExists(__OCSP_PROJECTPATH__ .  "mod_" $modName "/config/config.phpinc" )) {
  126.             require_once __OCSP_PROJECTPATH__ .  "mod_" $modName "/config/config.phpinc";        
  127.         else {
  128.             $obj_mod new OCSP_MOD_CONF($modName);
  129.             
  130.             if ($obj_mod->dbPopulate($debug))
  131.             {
  132.                 self::$modules[$modName]=$obj_mod;
  133.                 return true;
  134.             else {
  135.                 throw new Exception(_OCSP_EXCEP_MODULE_NOT_FOUND_ ":" $modName);
  136.             }
  137.         }    
  138.  
  139.         if ($debugechoDebugLine(__FILE__,__LINE__,'no config found');
  140.     }
  141.     
  142.     public static function installModule($modName,$debug=false)
  143.     {
  144.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_MOD_CONF::installModule()");
  145.  
  146.         $str_instPath "mod_" $modName _OCSP_DIRSEP_ "setup" _OCSP_DIRSEP_ "install.phpinc"
  147.         if (file_exists(self::getConf('MODULEPATH'$str_instPath))
  148.         {
  149.             include self::getConf('MODULEPATH'$str_instPath;    
  150.         else if (file_exists(__OCSP_PROJECTPATH__ $str_instPath)) {
  151.             include __OCSP_PROJECTPATH__ $str_instPath;
  152.         else if (file_exists(dirname(__OCSP_PHPINCPATH___OCSP_DIRSEP_ $str_instPath )) {
  153.             include dirname(__OCSP_PHPINCPATH___OCSP_DIRSEP_ $str_instPath;
  154.         else {
  155.             $str_debug "MODULEPATH:  " self::getConf('MODULEPATH'"<br />";
  156.             $str_debug .= "PROJECTPATH: " __OCSP_PROJECTPATH__ "<br />";
  157.             $str_debug .= "SYSTEMPATH:  " __OCSP_PHPINCPATH__ "<br />";
  158.             
  159.             echoDebugLine(__FILE__,__LINE__,"<p>" $str_debug "</p>");
  160.             
  161.             throw new Exception(_OCSP_EXCEP_MODULE_NOT_FOUND_ ": install " $str_instPath);
  162.         }
  163.     }
  164.     
  165.     
  166.     /**
  167.      * register all modules cached in self::getCachePath()
  168.      *
  169.      * @param boolean $debug 
  170.      */
  171.     public static function registerCachedModules($debug=false)
  172.     {
  173.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_MOD_CONF::registerCachedModules();");
  174.         
  175.         if ($arr_files pcf_getDirList(self::getCachePath()."config",'!D'))
  176.         {
  177.             foreach($arr_files as $str_fileName)
  178.             {
  179.                 if (substr($str_fileName,-4== ".xml")
  180.                 {
  181.                     self::registerModule(substr($str_fileName,0,-4));
  182.                 }
  183.             }
  184.         }
  185.     }
  186.     
  187.     /**
  188.      * register a module
  189.      *
  190.      * @param string $modName 
  191.      * @param boolean $debug 
  192.      * 
  193.      * @return OCSP_MOD_CONF 
  194.      */
  195.     public static function registerModule($modName,$debug=false)
  196.     {
  197.         if (!isset(self::$modules[$modName]))
  198.         {
  199.             self::$modules[$modNamenew OCSP_MOD_CONF($modName);
  200.         }
  201.         
  202.         return self::$modules[$modName];
  203.     }
  204.     
  205.     
  206.     /**
  207.      * returns a module configuration
  208.      *
  209.      * @param string $modName 
  210.      * @param boolean $debug 
  211.      * @return mixed 
  212.      */
  213.     public static function getConfObj($modName,$debug=false)
  214.     {
  215.         if (!isset(self::$modules[$modName]))
  216.         {
  217.             //throw new Exception(_OCSP_EXCEP_MOD_NOTREGISTERED_ . ":" . $modName);
  218.             if (!self::$modules[$modNameself::loadModule($modName))
  219.             {
  220.                 unset(self::$modules[$modName]);
  221.                 return Null;
  222.             }
  223.             
  224.         }
  225.         
  226.         return self::$modules[$modName];
  227.     }
  228.         
  229.     
  230.     /*** constructor ----------------------------------------------- */
  231.     
  232.     protected function __construct($modName)
  233.     {
  234.         $this->init($debug);
  235.         if (!empty($modName))
  236.         {
  237.             $this->setDBField('MOD_NAME',$modName);
  238.         }
  239.  
  240.         /*
  241.         if (!empty($modName))
  242.         {
  243.             
  244.             $str_cacheFile =  self::getCachePath() . "config" . _OCSP_DIRSEP_ . $modName . ".xml";
  245.             if (file_exists($str_cacheFile))
  246.             {
  247.                 $this->mySettings = OCSP_XMLARRAY::getArray($str_cacheFile);
  248.             } else {
  249.                 if (!$this->isConnected(true,$debug))
  250.                 {
  251.                     throw new Exception(_OCSP_EXCEP_NODBCONN_);
  252.                 }
  253.                 
  254.                 if (!($this->dbPopulate($debug)))
  255.                 {
  256.                     // module is not installed
  257.                     
  258.                 }
  259.                 
  260.             }                    
  261.         }
  262.         */
  263.     }
  264.     
  265.     /**
  266.      * cache the module
  267.      *
  268.      * @todo write to cache
  269.      */
  270.     public function __destruct()
  271.     {
  272.         /*
  273.         $str_path = self::getCachePath()."config";
  274.         if (pcf_checkDir($str_path,true))
  275.         {
  276.             OCSP_XMLARRAY::saveXML($this->mySettings,$str_path . _OCSP_DIRSEP_ . $this->getModuleName() . ".xml");
  277.         }
  278.         */        
  279.     }
  280.     
  281.     /*** getter / setter ------------------------------------------ */
  282.     
  283.     public function getId()
  284.     {
  285.         return intval($this->getDBField('MOD_ID'));
  286.     }
  287.     
  288.     /**
  289.      * returns the module name
  290.      * 
  291.      * @param boolean $debug 
  292.      * 
  293.      * @return string 
  294.      * 
  295.      * @since pk-08-03-20
  296.      */
  297.     public function getModuleName($debug=false)
  298.     {
  299.         return $this->getDBField('MOD_NAME',$debug,false);
  300.     }
  301.     
  302.     /**
  303.      * returns the module cache path
  304.      *
  305.      * @return string 
  306.      */
  307.     public function getMyCachePath()
  308.     {
  309.         return self::getCachePath($this->getModuleName(_OCSP_DIRSEP_;
  310.     }
  311.     
  312.     /**
  313.      * returns the root path of the module
  314.      *
  315.      * @param boolean $debug 
  316.      * 
  317.      * @return string 
  318.      * 
  319.      * @since pk-08-03-20
  320.      */
  321.     public function getModulePath($debug=false)
  322.     {
  323.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_MOD_CONF::getModulePath()");
  324.         
  325.         if (!($this->getModuleName()))
  326.         {
  327.             throw new Exception(_OCSP_EXCEP_NOID_);
  328.         }
  329.         
  330.         if ($str_path $this->getDBField('MOD_PATH'))
  331.         {
  332.             $str_ret str_replace('$@PROJECTPATH$',OCSP_OBJ::getConf('PROJECTPATH'),$str_path);
  333.             $str_ret str_replace('$@MODULEPATH$',self::getConf('MODULEPATH'),$str_path);
  334.             $str_ret trim($str_ret);
  335.             if (substr($str_ret,-1!= _OCSP_DIRSEP_)
  336.             {
  337.                 $str_ret .= _OCSP_DIRSEP_;
  338.                 $this->setDBField('MOD_PATH',$str_ret);                
  339.             }
  340.             return $str_ret;
  341.         }
  342.         if (is_dir(self::getConf('MODULEPATH'"mod_" $this->getModuleName()))
  343.         {
  344.             $this->setDBField('MOD_PATH','$@MODULEPATH$' "mod_" $this->getModuleName(_OCSP_DIRSEP_ );
  345.             return self::getConf('MODULEPATH'"mod_" $this->getModuleName(_OCSP_DIRSEP_;
  346.         }
  347.         
  348.         if (is_dir(self::getConf('PROJECTPATH'"mod_" $this->getModuleName()))
  349.         {
  350.             $this->setDBField('MOD_PATH','$@PROJECTPATH$' "mod_" $this->getModuleName(_OCSP_DIRSEP_ );
  351.             return self::getConf('PROJECTPATH'"mod_" $this->getModuleName(_OCSP_DIRSEP_;
  352.         }
  353.         
  354.         throw new Exception(_OCSP_EXCEP_MODULE_NOT_FOUND_ ":" $this->getModuleName());
  355.         
  356.     }
  357.     
  358.     /**
  359.      * returns the template path for the module
  360.      *
  361.      * @param boolean $debug 
  362.      * 
  363.      * @return string 
  364.      */
  365.     public function getTemplatePath($debug=false)
  366.     {
  367.         if ($debugechoDebugMethod(__FILE__,get_class($this),'OCSP_MOD_CONF::getTemplatePath()');
  368.         
  369.         return $this->getModulePath($debug"templates" _OCSP_DIRSEP_;
  370.     }
  371.     
  372.     
  373.     /*** DB key / filter ------------------------------------------ */
  374.     
  375.     /**
  376.       * generates a where clause to select the object identfied by DBMS_TBLOBJ::myKeys
  377.       *
  378.       * @param boolean $debug 
  379.       *
  380.       * @return string 
  381.       *
  382.       * @version pk-08-03-20
  383.       */
  384.     function getWhere($debug=FALSE
  385.     {
  386.         if ($debugechoDebugMethod(__FILE__,get_class($this),'OCSP_MOD_CONF::getWhere()');
  387.  
  388.         if (!intval($this->getDBField('MOD_ID')))
  389.         {
  390.             return "WHERE MOD_NAME=" $this->myDBObj->qs_getSlashedValue($this->getModuleName($debug));
  391.         else {
  392.             return parent::getWhere($debug);
  393.         }
  394.     }
  395.     
  396.     
  397.     /**
  398.      * populates the module configuration, settings and hooks
  399.      *
  400.      * @param debug $debug 
  401.      * 
  402.      * @returns boolean
  403.      * 
  404.      */
  405.     function dbPopulate($debug=False)
  406.     {
  407.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_MOD_CONF::dbPopulate();");
  408.         
  409.         if ($this->getId())
  410.         {
  411.             $arr_filter=array('MOD_ID' => $this->getId());
  412.         else if ($this->getModuleName($debug)) {
  413.             $arr_filter=array('MOD_NAME' => $this->getModuleName($debug));
  414.         else {
  415.             return false;
  416.         }
  417.         
  418.         if (!$this->isConnected(true))
  419.         {
  420.             throw new Exception(_OCSP_EXCEP_NODBCONN_);
  421.         }
  422.         
  423.         if ($arr_row $this->myDBObj->getArray($this->myTable,$arr_filter,0,0,"",$debug))
  424.         {
  425.             $this->setDBRow($arr_row[0],true,$debug);  
  426.             try {          
  427.                    $this->populateSettings($debug);
  428.                 $this->populateHooks($debug);
  429.             catch(Exception $e{
  430.                 if ($debugechoDebugLine(__FILE__,__LINE__,"Exception: <pre>" print_r($e,true"</pre>");
  431.             }
  432.             
  433.             return true;
  434.         else {
  435.             return false;
  436.         }
  437.     }
  438.  
  439.     /**
  440.      * inserts the module with settings and hooks
  441.      *
  442.      * @param boolean $debug 
  443.      * 
  444.      * @return int 
  445.      * 
  446.      */
  447.     function dbInsert($debug=false)
  448.     {
  449.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_MOD_CONF::dbInsert();");
  450.         if ($int_ret parent::dbInsert($debug))
  451.         {
  452.             $this->saveMySettings($debug);
  453.             return $int_ret;
  454.         
  455.         return false;
  456.     }
  457.     
  458.     /**
  459.      * replaces (update) a module configuration
  460.      * 
  461.      *
  462.      * @param boolean $debug 
  463.      * @param boolean $ignorPopulated 
  464.      * 
  465.      * @return boolean 
  466.      */
  467.     function dbReplace($debug=FALSE,$ignorPopulated=FALSE
  468.     {
  469.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_MOD_CONF::dbReplace()");    
  470.         
  471.         if (parent::dbReplace($debug,$ignorPopulated))
  472.         {
  473.             $this->saveMySettings($debug);
  474.         }
  475.     }
  476.         
  477.     /*** settings ------------------------------------------------- */
  478.     
  479.     /**
  480.      * populates the module settings
  481.      *
  482.      * @param boolean $debug 
  483.      */
  484.        protected function populateSettings($debug)
  485.        {
  486.            if ($this->getId())
  487.            {
  488.                $arr_filter=array('MOD_ID' => $this->getId());
  489.                if (!$this->isConnected(true))
  490.                {
  491.                    throw new Exception(_OCSP_EXCEP_NODBCONN_);
  492.                }
  493.                
  494.                if ($arr_settings=$this->myDBObj->getArray(self::$settingTbl,$arr_filter))
  495.                {
  496.                    if (!is_array($this->mySettings))
  497.                    {
  498.                        $this->mySettings = array();    
  499.                    }
  500.                
  501.                    foreach($arr_settings as $arr_row)
  502.                    {
  503.                        $this->mySettings[$arr_row['MOS_NAME']] $arr_row;                        
  504.                    }
  505.                }
  506.            }
  507.        }
  508.        
  509.        /**
  510.         * stores the settings to the database
  511.         *
  512.         * @param boolean $debug 
  513.         */
  514.        protected function saveMySettings($debug)
  515.        {
  516.            if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_MOD_CONF::saveMySettings()");
  517.            
  518.            if (!$this->isConnected(true))
  519.            {
  520.                throw new Exception(_OCSP_EXCEP_NODBCONN_);
  521.            }
  522.            foreach($this->mySettings as $str_name => $arr_mos)
  523.            {
  524.                $arr_mos['MOS_NAME'$str_name;
  525.                $arr_mos['MOD_ID'$this->getId();
  526.                
  527.                $this->myDBObj->replaceArray(self::$settingTbl,$arr_mos);
  528.            }
  529.        }
  530.     
  531.     /**
  532.      * returns a module setting
  533.      *
  534.      * @param string $optName 
  535.      * @param boolean $debug 
  536.      * 
  537.      * @return mixed 
  538.      */
  539.     public function getMySetting($optName,$debug=false)
  540.     {
  541.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_MOD_CONF::getMySetting(" $optName ")");
  542.         if ($optName=="[ALL]")
  543.         {
  544.             return $this->mySettings;
  545.         }
  546.         
  547.         if (isset($this->mySettings[$optName]['MOS_VALUE'])) 
  548.         {
  549.             if (!empty($this->mySettings[$optName]['MOS_VALUE']))
  550.             {
  551.                 return unserialize($this->mySettings[$optName]['MOS_VALUE']);
  552.             }
  553.         else {
  554.             return OCSP_OBJ::getConf($optName);
  555.         }
  556.     }
  557.     
  558.     public function setMySetting($optName,$value)
  559.     {
  560.         $this->mySettings[$optName]=array('MOS_VALUE' => serialize($value));
  561.     }
  562.     
  563.     /*** hooks ---------------------------------------------------- */
  564.     
  565.     /**
  566.      * populates the hooks
  567.      *
  568.      * @param boolean $debug 
  569.      */
  570.     protected function populateHooks($debug)
  571.     {
  572.         throw new Exception(_OCSP_EXCEP_TODO_ ": " basename(__FILE__" " . __LINE__ . "OCSP_MOD_CONF::populateHooks()");
  573.     }
  574.     
  575.     public function addHook($system,$part,$cmd,$className)
  576.     {
  577.         $arr_hook=array(
  578.             'MOD_ID'         => $this->getId(),
  579.             'HOO_SYSTEM'    => $system,
  580.             'HOO_PART'        => $part,
  581.             'HOO_CMD'        => $cmd,
  582.             'HOO_CLASS'        => $className
  583.         );
  584.         
  585.         if (!$this->isConnected(true,$debug))
  586.         {
  587.             throw new Exception(_OCSP_EXCEP_NODBCONN_);
  588.         }
  589.         
  590.         return $this->myDBObj->insertArray('T_MOD_HOOKS',$arr_hook,$debug,'HOO_ID');
  591.     }
  592.     
  593.     /*** modul Object  ----------------------------------------- */
  594.     
  595.     /**
  596.      * returns the name of the main class
  597.      * 
  598.      * which has to implement INFA_MODULE
  599.      *
  600.      * @return string 
  601.      */
  602.     public function getModuleClassName()
  603.     {
  604.         return strtoupper($this->getModuleName());
  605.     }
  606.     
  607.     /**
  608.      * returns the main object of the modul
  609.      *
  610.      * @param boolean $debug 
  611.      * 
  612.      * @return INFA_MODULE class
  613.      */
  614.     public function includeModuleObject($debug=false)
  615.     {
  616.         if ($debubechoDebugMethod(__FILE__,get_class($this),"OCSP_MOD_CONF::getModuleObject()");
  617.         
  618.         $str_class $this->getModuleClassName();
  619.         
  620.         if (!class_exists($str_class))
  621.         {
  622.             $str_incFile $this->getModulePath($debug"php" _OCSP_DIRSEP_ $str_class ".phpclass";
  623.             if (!file_exists($str_incFile))
  624.             {
  625.                 throw new Exception(_OCSP_EXCEP_FILENOTFOUND_ ":" $str_incFile);
  626.             }
  627.             require_once $str_incFile;
  628.             return true;
  629.         else {
  630.             return true;        
  631.         }
  632.     }
  633.  
  634.     /**
  635.      * returns the module main object
  636.      *
  637.      * @param boolean $debug 
  638.      * 
  639.      * @return INFA_MODULE object
  640.      */
  641.     public function factoryModuleObject($debug=false)
  642.     {
  643.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_MOD_CONF::factoryModuleObject();");
  644.         
  645.         $this->includeModuleObject($debug);
  646.         $str_cmd "\$obj_ret = " $this->getModuleClassName("::factoryFromEnv();";
  647.         if ($debugechoDebugLine(__FILE__,__LINE__,"ObjectCmd: <br />" $str_cmd);
  648.         
  649.         eval($str_cmd);
  650.         $obj_ret->setMyModConf($this);
  651.         
  652.         return $obj_ret;        
  653.     }
  654.     
  655. }
  656.  
  657. ?>

Documentation generated on Thu, 08 Jan 2009 17:47:02 +0100 by phpDocumentor 1.4.0a2