• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List

E:/E/GEAMP/www/openbiz/openbiz/bin/BizSystem.php

00001 <?PHP
00017 // register __destruct method as shutdown function
00018 register_shutdown_function("bizsystem_shutdown");
00019 
00020 function bizsystem_shutdown()
00021 {
00022     BizSystem::sessionContext()->saveSessionObjects();
00023 }
00024 
00025 include_once 'Resource.php';
00026 
00040 class BizSystem
00041 {
00042     private $_objectFactory = null;
00043     private $_sessionContext = null; // instant of SessionContext class
00044     private $_confgiuration = null;
00045     private $_clientProxy = null;
00046     private $_typeManager = null;
00047     private $_currentViewName = "";
00048     private $_currentViewSet = "";
00049     private $_dbConnection = array();
00050     private $_theme = array();       // TODO: unused variable
00051     private $_serviceList = array(); // TODO: unused variable
00052     private $_userProfile = null;    // TODO: unused variable (store on Session with SessionContext)
00053 
00054     private static $_instance = null;
00055     
00056     private static $_classNameCache = array();
00057 
00063     public static function instance()
00064     {
00065         if (self::$_instance == null)
00066             self::$_instance = new BizSystem();
00067         return self::$_instance;
00068     }
00069 
00075     private function __construct()
00076     {
00077         $this->getObjectFactory();
00078         /*
00079         include_once(OPENBIZ_BIN."SessionContext.php");
00080         $this->_sessionContext = new SessionContext();
00081         // retrieve object session vars
00082         $this->_sessionContext->retrieveSessionObjects();
00083         */
00084     }
00085 
00091     public function __destruct()
00092     {
00093         // save object session vars
00094         //$this->_sessionContext->saveSessionObjects();
00095         //echo "<br>destruct bizSystem";
00096     }
00097 
00103     public static function getVersion()
00104     {
00105         return '3.0';
00106     }
00107 
00113     public function getObjectFactory()
00114     {
00115         if (!$this->_objectFactory)
00116         {
00117             include_once(OPENBIZ_BIN."ObjectFactory.php");
00118             $this->_objectFactory = new ObjectFactory();
00119         }
00120         return $this->_objectFactory;
00121     }
00122 
00129     public static function objectFactory()
00130     {
00131         return BizSystem::instance()->getObjectFactory();
00132     }
00133 
00139     public function getSessionContext()
00140     {
00141         if ($this->_sessionContext)
00142             return $this->_sessionContext;
00143         include_once(OPENBIZ_BIN."SessionContext.php");
00144         $this->_sessionContext = new SessionContext();
00145         // retrieve object session vars
00146         $this->_sessionContext->retrieveSessionObjects();
00147         return $this->_sessionContext;
00148     }
00149 
00156     public static function sessionContext()
00157     {
00158         return BizSystem::instance()->getSessionContext();
00159     }
00160 
00166     public function getConfiguration()
00167     {
00168         if (!$this->_confgiuration)
00169         {
00170             include_once(OPENBIZ_BIN."Configuration.php");
00171             $this->_confgiuration = new Configuration();
00172         }
00173         return $this->_confgiuration;
00174     }
00175 
00182     public static function configuration()
00183     {
00184         return BizSystem::instance()->getConfiguration();
00185     }
00186 
00192     public function getClientProxy()
00193     {
00194         if (!$this->_clientProxy)
00195         {
00196             include_once(OPENBIZ_BIN."ClientProxy.php");
00197             $this->_clientProxy = new ClientProxy();
00198         }
00199         return $this->_clientProxy;
00200     }
00201 
00208     public static function clientProxy()
00209     {
00210         return BizSystem::instance()->getClientProxy();
00211     }
00212 
00218     public function getTypeManager()
00219     {
00220         if (!$this->_typeManager)
00221         {
00222             include_once(OPENBIZ_BIN."TypeManager.php");
00223             $this->_typeManager = new TypeManager();
00224             
00225             /* @var $localeInfoService localeInfoService */
00226             $localeInfoService = BizSystem::getService(LOCALEINFO_SERVICE);
00227             $localeInfo = $localeInfoService->getLocaleInfo();
00228             
00229             if ($localeInfo) 
00230             {
00231                 $this->_typeManager->setLocaleInfo($localeInfo);
00232             }            
00233         }        
00234         return $this->_typeManager;
00235     }
00236 
00243     public static function typeManager()
00244     {
00245         return BizSystem::instance()->getTypeManager();
00246     }
00247 
00254     public static function getService($service, $new=0)
00255     {
00256         $default_package = "service";
00257         $svc_name = $service;
00258         if (strpos($service, ".") === false)
00259             $svc_name = $default_package . "." . $service;
00260         return BizSystem::getObject($svc_name, $new);
00261     }
00262     
00269     public static function getObject($objectName, $new=0)
00270     {
00271         return BizSystem::ObjectFactory()->getObject($objectName, $new);
00272     }
00273 
00280     public static function allowUserAccess($resourceAction)
00281     {
00282         $serviceObj = BizSystem::getService(ACL_SERVICE);
00283         return $serviceObj->allowAccess($resourceAction);
00284     }
00285 
00292     public static function initUserProfile($userId)
00293     {
00294         $serviceObj = BizSystem::getService(PROFILE_SERVICE);
00295 
00296         if (method_exists($serviceObj,'InitProfile'))
00297             $profile = $serviceObj->InitProfile($userId);
00298         else
00299             $profile = $serviceObj->getProfile($userId);
00300 
00301         BizSystem::sessionContext()->setVar("_USER_PROFILE", $profile);
00302         return $profile;
00303     }
00304 
00311     public static function getUserProfile($attribute=null)
00312     {
00313        if(!BizSystem::GetXmlFileWithPath (PROFILE_SERVICE)){
00314               return null;
00315        }
00316         $serviceObj = BizSystem::getService(PROFILE_SERVICE);
00317         if (method_exists($serviceObj,'getProfile'))
00318             return $serviceObj->getProfile($attribute);
00319         else
00320         {
00321             $profile = BizSystem::sessionContext()->getVar("_USER_PROFILE");
00322             return isset($profile[$attribute]) ? $profile[$attribute] : "";
00323         }
00324     }
00325     
00326     public static function getUserPreference($attribute=null)
00327     {
00328        if(!BizSystem::GetXmlFileWithPath (PREFERENCE_SERVICE)){
00329               return null;
00330        }
00331         $serviceObj = BizSystem::getService(PREFERENCE_SERVICE);
00332         if (method_exists($serviceObj,'getPreference'))
00333             return $serviceObj->getPreference($attribute);
00334         else
00335         {
00336             $preference = BizSystem::sessionContext()->getVar("_USER_PREFERENCE");
00337             return isset($preference[$attribute]) ? $preference[$attribute] : "";
00338         }
00339     }    
00340 
00341     public static function getProfileName($account_id,$type='full'){
00342        $serviceObj = BizSystem::getService(PROFILE_SERVICE);
00343        return $serviceObj->GetProfileName($account_id,$type);
00344     }    
00345     
00346        public static function getProfileEmail($account_id){
00347        $serviceObj = BizSystem::getService(PROFILE_SERVICE);
00348        return $serviceObj->getProfileEmail($account_id);
00349     }
00350     
00351        public static function getProfileId($account_id){
00352        $serviceObj = BizSystem::getService(PROFILE_SERVICE);
00353        return $serviceObj->getProfileId($account_id);
00354     }
00355     
00356     public static function getDefaultPerm($group)
00357     {
00358        $group = strtolower($group);
00359        switch($group){
00360               default:
00361               case 'owner':
00362                      $setting = BizSystem::getUserPreference('owner_perm');
00363                      if($setting!=''){
00364                             $perm_code = $setting;
00365                      }else{
00366                             $perm_code = DEFAULT_OWNER_PERM;
00367                      }
00368                      break;
00369               case 'group':
00370                      $setting = BizSystem::getUserPreference('owner_group');
00371                      if($setting!=''){
00372                             $perm_code = $setting;
00373                      }else{
00374                             $perm_code = DEFAULT_GROUP_PERM;
00375                      }
00376                      break;
00377               case 'other':
00378                      $setting = BizSystem::getUserPreference('owner_other');
00379                      if($setting!=''){
00380                             $perm_code = $setting;
00381                      }else{
00382                             $perm_code = DEFAULT_OTHER_PERM;
00383                      }
00384                      break;
00385        }    
00386        return $perm_code;   
00387     }
00393     public function getCurrentViewName()
00394     {
00395         if ($this->_currentViewName == "")
00396             $this->_currentViewName = $this->getSessionContext()->getVar("CVN");   // CVN stands for CurrentViewName
00397         return $this->_currentViewName;
00398     }
00399 
00405     public function setCurrentViewName($viewname)
00406     {
00407         $this->_currentViewName = $viewname;
00408         $this->getSessionContext()->setVar("CVN", $this->_currentViewName);   // CVN stands for CurrentViewName
00409     }
00410 
00416     public function getCurrentViewSet()
00417     {
00418         if ($this->_currentViewSet == "")
00419             $this->_currentViewSet = $this->getSessionContext()->getVar("CVS");   // CVS stands for CurrentViewSet
00420         return $this->_currentViewSet;
00421     }
00422 
00428     public function setCurrentViewSet($viewSet)
00429     {
00430         $this->_currentViewSet = $viewSet;
00431         $this->getSessionContext()->setVar("CVS", $this->_currentViewSet);   // CVS stands for CurrentViewSet
00432     }
00433 
00440     public static function currentPageURL()
00441     {
00442         if ($_REQUEST['__url'])
00443             return $_REQUEST['__url'];
00444         else
00445             return $_SERVER['REQUEST_URI'];
00446     }
00447 
00448     
00449     public static function resetDBConnection($dbName=null)
00450     {         
00451         return BizSystem::instance()->removeDBConnection($dbName);
00452     }
00453     
00454     public function removeDBConnection($dbName=null){
00455        $rDBName = (!$dbName) ? "Default" : $dbName;
00456         if (isset($this->_dbConnection[$rDBName])){
00457             $this->_dbConnection[$rDBName]->closeConnection();
00458             unset($this->_dbConnection[$rDBName]);                           
00459         }
00460         return $this->getDBConnection($rDBName);
00461     }
00462     
00469     public function getDBConnection($dbName=null)
00470     {
00471         $rDBName = (!$dbName) ? "Default" : $dbName;
00472         if (isset($this->_dbConnection[$rDBName])){
00473               $db =  $this->_dbConnection[$rDBName];
00474               if(!CLI){
00475                      return $db;          
00476               }
00477         }
00478 
00479         $dbInfo = $this->getConfiguration()->getDatabaseInfo($rDBName);
00480 
00481         require_once 'Zend/Db.php';
00482 
00483         $params = array (
00484                 'host'     => $dbInfo["Server"],
00485                 'username' => $dbInfo["User"],
00486                 'password' => $dbInfo["Password"],
00487                 'dbname'   => $dbInfo["DBName"],
00488                 'port'     => $dbInfo["Port"],
00489                 'charset'  => $dbInfo["Charset"]
00490         );
00491         if ($dbInfo["Options"]) {
00492               $options = explode(";",$dbInfo["Options"]);
00493                foreach ($options as $opt) {
00494                      list($k,$v) = explode("=",$opt);
00495                      $params[$k] = $v;
00496                }
00497         }
00498         foreach ($params as $name=>$val) {
00499               if (empty($val)) unset($params[$name]);
00500         }
00501         if(strtoupper($dbInfo["Driver"])=="PDO_MYSQL")
00502         {
00503               $pdoParams = array(
00504                      PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
00505                      );
00506                      $params["driver_options"]=$pdoParams;
00507         }
00508         $db = Zend_Db::factory($dbInfo["Driver"], $params);
00509 
00510         $db->setFetchMode(PDO::FETCH_NUM);
00511         
00512         if(strtoupper($dbInfo["Driver"])=="PDO_MYSQL" &&
00513                 $dbInfo["Charset"]!="")
00514         {
00515             $db->query("SET NAMES '".$params['charset']."'");
00516         }
00517         
00518         $this->_dbConnection[$rDBName] = $db;
00519 
00520         return $db;
00521     }
00522 
00529     public static function dbConnection($dbName=null)
00530     {
00531         return BizSystem::instance()->getDBConnection($dbName);
00532     }
00533 
00542     public static function getMacroValue($var, $key)
00543     {
00544         if ($var == "profile")
00545         {
00546             return BizSystem::instance()->getUserProfile($key);
00547         }
00548         return null;
00549     }
00550 
00556     public static function getSmartyTemplate()
00557     {
00558         return Resource::getSmartyTemplate();
00559     }
00560 
00566     public static function getZendTemplate()
00567     {
00568         return Resource::getZendTemplate();
00569     }
00570 
00588     public static function log($priority, $subject, $message)
00589     {
00590         $svcobj = BizSystem::getService(LOG_SERVICE);
00591         $svcobj->log($priority, $subject, $message);
00592     }
00593 
00614     public static function logError($priority, $subject, $message, $fileName = NULL)
00615     {
00616         $svcobj = BizSystem::getService(LOG_SERVICE);
00617         $svcobj->logError($priority, $subject, $message, $fileName);
00618     }
00619 
00630     public static function getXmlFileWithPath($xmlObj)
00631     {
00632         return Resource::GetXmlFileWithPath($xmlObj);
00633     }
00634     
00635        public static function getCompiledFileWithPath($xmlObj)
00636     {
00637         return Resource::GetCompiledFileWithPath($xmlObj);
00638     }
00639 
00646     public static function getTplFileWithPath($templateFile, $packageName)
00647     {
00648         return Resource::getTplFileWithPath($templateFile, $packageName);
00649     }
00650     
00651     public static function loadClass($className, $packageName='')
00652     {
00653         if (isset(self::$_classNameCache[$packageName.$className])) return true;
00654         if (strpos($className, 'Zend') === 0) return true;
00655         $filePath = BizSystem::getLibFileWithPath($className, $packageName);
00656         if ($filePath)
00657         {
00658             include_once($filePath);
00659             self::$_classNameCache[$packageName.$className] = 1;
00660             return true;
00661         }
00662         return false;
00663     }
00664 
00671     public static function getLibFileWithPath($className, $packageName="")
00672     {
00673         return Resource::getLibFileWithPath($className, $packageName);
00674     }
00675 
00683     private static function _getCoreLibFilePath($className)
00684     {
00685         return Resource::getCoreLibFilePath($className);
00686     }
00687 
00698     public static function &getXmlArray($xmlFile)
00699     {
00700         return Resource::getXmlArray($xmlFile);
00701     }
00702 
00711     public static function getMessage($msgid, $params=array())
00712     {
00713         return Resource::getMessage($msgid, $params);
00714     }
00715 
00716 }
00717 
00718 ?>

Generated on Thu Apr 19 2012 17:09:13 for openbiz by  doxygen 1.7.2