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

E:/E/GEAMP/www/openbiz/openbiz/bin/easy/EasyView.php

00001 <?PHP
00026 class EasyView extends MetaObject implements iSessionObject
00027 {
00028     public $m_Title;
00029     public $m_Keywords;
00030        public $m_TemplateEngine;
00031     public $m_TemplateFile;
00032     public $m_ViewSet;
00033     public $m_Tab;
00034     public $m_FormRefs;
00035 
00036     public $m_IsPopup = false;
00037     public $m_Height;
00038     public $m_Width;
00039     public $m_ConsoleOutput = true;
00040 
00041     public $m_MessageFile = null;        // message file path
00042     protected $m_Messages;
00043     public $m_CacheLifeTime = 0;
00044     
00045     public $m_LastRenderedForm;
00046 
00053     public function __construct(&$xmlArr)
00054     {
00055         $this->readMetadata($xmlArr);
00056     }
00057 
00064     protected function readMetadata(&$xmlArr)
00065     {
00066         parent::readMetaData($xmlArr);
00067         $this->m_Name = $this->prefixPackage($this->m_Name);
00068         $this->m_Title = isset($xmlArr["EASYVIEW"]["ATTRIBUTES"]["TITLE"]) ? $xmlArr["EASYVIEW"]["ATTRIBUTES"]["TITLE"] : null;
00069         $this->m_Keywords = isset($xmlArr["EASYVIEW"]["ATTRIBUTES"]["KEYWORDS"]) ? $xmlArr["EASYVIEW"]["ATTRIBUTES"]["KEYWORDS"] : null;
00070         $this->m_TemplateEngine = isset($xmlArr["EASYVIEW"]["ATTRIBUTES"]["TEMPLATEENGINE"]) ? $xmlArr["EASYVIEW"]["ATTRIBUTES"]["TEMPLATEENGINE"] : null;
00071         $this->m_TemplateFile = isset($xmlArr["EASYVIEW"]["ATTRIBUTES"]["TEMPLATEFILE"]) ? $xmlArr["EASYVIEW"]["ATTRIBUTES"]["TEMPLATEFILE"] : null;
00072         $this->m_ViewSet = isset($xmlArr["EASYVIEW"]["ATTRIBUTES"]["VIEWSET"]) ? $xmlArr["EASYVIEW"]["ATTRIBUTES"]["VIEWSET"] : null;
00073         $this->m_Tab = isset($xmlArr["EASYVIEW"]["ATTRIBUTES"]["TAB"]) ? $xmlArr["EASYVIEW"]["ATTRIBUTES"]["TAB"] : null;
00074 
00075         $this->m_FormRefs = new MetaIterator($xmlArr["EASYVIEW"]["FORMREFERENCES"]["REFERENCE"],"FormReference",$this);
00076         if($xmlArr["EASYVIEW"]["FORMREFERENCELIBS"])
00077         {
00078               $this->m_FormRefLibs = new MetaIterator($xmlArr["EASYVIEW"]["FORMREFERENCELIBS"]["REFERENCE"],"FormReference",$this);
00079         }
00080         $this->m_MessageFile = isset($xmlArr["EASYVIEW"]["ATTRIBUTES"]["MESSAGEFILE"]) ? $xmlArr["EASYVIEW"]["ATTRIBUTES"]["MESSAGEFILE"] : null;
00081         $this->m_Messages = Resource::loadMessage($this->m_MessageFile);
00082         $this->m_CacheLifeTime = isset($xmlArr["EASYVIEW"]["ATTRIBUTES"]["CACHELIFETIME"]) ? $xmlArr["EASYVIEW"]["ATTRIBUTES"]["CACHELIFETIME"] : "0";
00083               
00084         $this->readTile($xmlArr);  // TODO: is this needed as title supports expression?
00085         
00086         $this->translate(); // translate for multi-language support
00087         if (empty($this->m_Title))
00088               $this->m_Title = $this->m_Description;
00089     }
00090     
00091     protected function readTile(&$xmlArr)
00092     {
00093        if (isset($xmlArr["EASYVIEW"]["TILE"]))
00094         {
00095               $this->m_FormRefs = array();
00096               if (isset($xmlArr["EASYVIEW"]["TILE"]["ATTRIBUTES"])) 
00097               {
00098                      $tileName = $xmlArr["EASYVIEW"]["TILE"]["ATTRIBUTES"]["NAME"];
00099                      $this->m_Tiles[$tileName] = new MetaIterator($xmlArr["EASYVIEW"]["TILE"]["REFERENCE"],"FormReference",$this);
00100               }
00101               else 
00102               {
00103                      foreach ($xmlArr["EASYVIEW"]["TILE"] as $child)
00104                      {
00105                             $tileName = $child["ATTRIBUTES"]["NAME"];
00106                             $this->m_Tiles[$tileName] = new MetaIterator($child["REFERENCE"],"FormReference",$this);
00107                      }
00108               }
00109               //echo "<pre>"; print_r($this->m_Tiles); echo "</pre>"; 
00110               $tmp = array();
00111               $this->m_FormRefs = new MetaIterator($tmp,"",$this);
00112               foreach ($this->m_Tiles as $tile)
00113               {
00114                      foreach ($tile as $ref)
00115                             $this->m_FormRefs->set($ref->m_Name, $ref);
00116               }
00117         }
00118     }
00119 
00126     public function isInFormRefLibs($formName)
00127     {
00128        if($this->m_FormRefLibs)
00129        {
00130               $this->m_FormRefLibs->rewind();
00131               while($this->m_FormRefLibs->valid())
00132               {
00133                      $reference = $this->m_FormRefLibs->current();
00134                      if($reference->m_Name == $formName)
00135                      {
00136                             return true;
00137                      }
00138                      $this->m_FormRefLibs->next();
00139               }
00140               return false;
00141        }
00142        else
00143        {
00144               return true;
00145        }
00146     }
00147     
00155     protected function getMessage($msgId, $params=array())
00156     {
00157         $message = isset($this->m_Messages[$msgId]) ? $this->m_Messages[$msgId] : constant($msgId);
00158         //$message = I18n::getInstance()->translate($message);
00159         $message = I18n::t($message, $messageId, $this->getModuleName($this->m_Name));
00160         return vsprintf($message,$params);
00161     }
00162 
00163 
00170     public function getSessionVars($sessionContext)
00171     {
00172         $sessionContext->getObjVar($this->m_Name, "LastRenderedForm", $this->m_LastRenderedForm);        
00173     }
00174     
00181     public function setSessionVars($sessionContext)
00182     {       
00183         $sessionContext->setObjVar($this->m_Name, "LastRenderedForm", $this->m_LastRenderedForm);
00184     }
00185 
00191     public function getViewSet()
00192     { 
00193         return $this->m_ViewSet;
00194     }
00195 
00202     public function setConsoleOutput($consoleOutput)
00203     {
00204         $this->m_ConsoleOutput = $consoleOutput;
00205     }
00206 
00212     public function processRule()
00213     {}
00214 
00220     public function setParameters()
00221     {}
00222 
00228     public function render()
00229     {
00230        if (!$this->allowAccess())
00231         {
00232             $accessDenyView = BizSystem::objectFactory()->getObject(ACCESS_DENIED_VIEW);
00233             return $accessDenyView->render();
00234         }
00235 
00236         $this->initAllForms();
00237 
00238         // check the "fld_..." arg in url and put it in the search rule
00239         $this->processRequest();
00240         return $this->_render();
00241     }
00242 
00248     protected function _render()
00249     {
00250         $this->setClientScripts();
00251 
00252         if($this->m_CacheLifeTime>0)
00253         {
00254             $pageUrl = $this->curPageURL();
00255             $cache_id = md5($pageUrl);
00256             //try to process cache service.
00257             $cacheSvc = BizSystem::getService(CACHE_SERVICE,1);
00258             $cacheSvc->init($this->m_Name,$this->m_CacheLifeTime);
00259             if($cacheSvc->test($cache_id))
00260             {
00261                 BizSystem::log(LOG_DEBUG, "VIEW", "Cache Hit. url = ".$pageUrl);
00262                 $output = $cacheSvc->load($cache_id);
00263             }
00264             else
00265             {
00266                 include_once(OPENBIZ_BIN."/easy/ViewRenderer.php");
00267                 $this->m_ConsoleOutput = false;
00268                 $output = ViewRenderer::render($this);
00269                 BizSystem::log(LOG_DEBUG, "VIEW", "Set cache. url = ".$pageUrl);
00270                 $cacheSvc->save($output, $cache_id);
00271             }
00272             print $output;
00273         }
00274         else
00275         {
00276             include_once(OPENBIZ_BIN."/easy/ViewRenderer.php");
00277             ViewRenderer::render($this);
00278         }
00279         return;
00280         /*
00281         $this->setClientScripts();
00282        include_once(OPENBIZ_BIN."/easy/ViewRenderer.php"); 
00283            return ViewRenderer::render($this);*/
00284     }
00285 
00294     public function curPageURL()
00295     {
00296         return $this->getCurrentPageUrl();
00297     }
00298 
00305     public function getCurrentPageUrl()
00306     {
00307         $pageURL = 'http';
00308         if ($_SERVER["HTTPS"] == "on")
00309         {
00310             $pageURL .= "s";
00311         }
00312         $pageURL .= "://";
00313         if ($_SERVER["SERVER_PORT"] != "80")
00314         {
00315             $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
00316         }
00317         else
00318         {
00319             $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
00320         }
00321         return $pageURL;
00322     }
00323 
00329     protected function setClientScripts()
00330     {
00331         BizSystem::clientProxy()->appendScripts("prototype", "prototype.js");
00332         BizSystem::clientProxy()->appendScripts("scriptaculous", "scriptaculous.js");
00333         BizSystem::clientProxy()->appendScripts("openbiz", "openbiz.js");      
00334         BizSystem::clientProxy()->appendStyles("default", "openbiz.css");
00335         // window lib
00336         BizSystem::clientProxy()->includePropWindowScripts();
00337         // validator lib
00338         //BizSystem::clientProxy()->includeValidatorScripts();
00339     }
00340 
00346     protected function initAllForms()
00347     {
00348         foreach ($this->m_FormRefs as $formRef)
00349         {
00350             $formRef->setViewName($this->m_Name);
00351             $formName = $formRef->m_Name;
00352             $formObj = BizSystem::objectFactory()->getObject($formName);
00353             if ($formRef->m_SubForms && method_exists($formObj,"SetSubForms"))
00354                 $formObj->setSubForms($formRef->m_SubForms);
00355         }
00356     }
00357 
00363     protected function processRequest()
00364     {
00365         // if url has form=...
00366         $paramForm = isset($_REQUEST['form']) ? $_REQUEST['form'] : null;
00367         // check url arg as fld:name=val
00368         $getKeys = array_keys($_REQUEST);
00369         $pageid = $_GET["pageid"];
00370         
00371         $paramFields = null;
00372         foreach ($getKeys as $key)
00373         {
00374             if (substr($key, 0, 4) == "fld:")
00375             {
00376                 $fieldName = substr($key, 4);
00377                 $fieldValue = $_REQUEST[$key];
00378                 $paramFields[$fieldName] = $fieldValue;
00379             }
00380         }
00381 
00382         if (!$paramFields && !$pageid)
00383             return;
00384 
00385         // get the form object
00386         if (!$paramForm)
00387         { // get the first form name if no form is given
00388             foreach ($this->m_FormRefs as $formRef)
00389             {
00390                 $paramForm = $formRef->m_Name;
00391                 break;
00392             }
00393         }
00394         if (!$paramForm)
00395             return;
00396         $paramForm = $this->prefixPackage($paramForm);
00397         $formObj = BizSystem::objectFactory()->getObject($paramForm);
00398         $formObj->setRequestParams($paramFields);
00399         if($pageid){
00400                      $formObj->setCurrentPage($pageid);
00401         }        
00402     }
00403 
00410     public function outputAttrs() 
00411     {
00412         $out['name'] = $this->m_Name;
00413         $out['description'] = $this->m_Description;
00414         $out["keywords"] = $this->m_Keywords;
00415         if ($this->m_Title)
00416             $title = Expression::evaluateExpression($this->m_Title,$this);
00417         else
00418               $title = $this->m_Description;
00419         $out['title'] = $title;
00420         return $out;
00421     }
00422     
00423     protected function translate()
00424     {
00425        $module = $this->getModuleName($this->m_Name);
00426        $trans_string = I18n::t($this->m_Title, $this->getTransKey('Title'), $module);
00427        if($trans_string){
00428               $this->m_Title =  $trans_string;
00429        }
00430        $trans_string = I18n::t($this->m_Description, $this->getTransKey('Description'), $module);
00431        if($trans_string){
00432               $this->m_Description = $trans_string;
00433        }
00434     }
00435     
00436     protected function getTransKey($name)
00437     {
00438        $shortFormName = substr($this->m_Name,intval(strrpos($this->m_Name,'.'))+1);
00439        return strtoupper($shortFormName.'_'.$name);
00440     }
00441 }
00442 
00443 
00452 class FormReference
00453 {
00454     public $m_Name;
00455     public $m_SubForms;
00456     public $m_Description;
00457     private $_parentForm;
00458     public $m_Display = true;
00459     protected $m_ViewName;
00460 
00466     public function __construct($xmlArr)
00467     {
00468         $this->m_Name = $xmlArr["ATTRIBUTES"]["NAME"];
00469         $this->m_SubForms = $xmlArr["ATTRIBUTES"]["SUBFORMS"];
00470         $this->m_Description = $xmlArr["ATTRIBUTES"]["DESCRIPTION"];
00471         
00472     }
00473 
00480     public function setParentForm($formName)
00481     {
00482         $this->_parentForm = $formName;
00483     }
00484     
00485     public function setViewName($viewName)
00486     {
00487         $this->m_ViewName = $viewName;
00488         $this->translate();
00489     }
00490     
00491     protected function translate()
00492     {
00493        $module = substr($this->m_ViewName,0,intval(strpos($this->m_ViewName,'.')));
00494         //echo $this->getTransKey('Description');
00495         $this->m_Description = I18n::t($this->m_Description, $this->getTransKey('Description'), $module);
00496     }
00497     
00498     protected function getTransKey($name)
00499     {
00500        $shortViewName = substr($this->m_ViewName,intval(strrpos($this->m_ViewName,'.')+1));
00501        return strtoupper($shortViewName.'_'.$this->m_Name.'_'.$name);
00502     }
00503 }
00504 
00505 ?>

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