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

E:/E/GEAMP/www/openbiz/openbiz/bin/service/reportService.php

00001 <?php
00025 class reportService extends MetaObject
00026 {
00027     public $m_targetReportPath; // = "D:\\Tomcat5\\webapps\\birt-viewer\\report\\";
00028     public $m_rptTemplate; // = "dataobj.rptdesign.tpl";
00029     public $m_birtViewer; // = "http://localhost:8080/birt-viewer";
00030 
00037     function __construct(&$xmlArr)
00038     {
00039         $this->readMetadata($xmlArr);
00040     }
00041 
00048     protected function readMetadata(&$xmlArr)
00049     {
00050         parent::readMetaData($xmlArr);
00051         $this->m_targetReportPath = isset($xmlArr["PLUGINSERVICE"]["ATTRIBUTES"]["TARGETREPORTPATH"]) ? $xmlArr["PLUGINSERVICE"]["ATTRIBUTES"]["TARGETREPORTPATH"] : null;
00052         $this->m_rptTemplate = isset($xmlArr["PLUGINSERVICE"]["ATTRIBUTES"]["REPORTTEMPLATE"]) ? $xmlArr["PLUGINSERVICE"]["ATTRIBUTES"]["REPORTTEMPLATE"] : null;
00053         $this->m_birtViewer = isset($xmlArr["PLUGINSERVICE"]["ATTRIBUTES"]["BIRTVIEWER"]) ? $xmlArr["PLUGINSERVICE"]["ATTRIBUTES"]["BIRTVIEWER"] : null;
00054     }
00055 
00062     public function render($objName)
00063     {
00064         // get the current UI bizobj
00065         $bizform = BizSystem::getObject($objName);    // get the existing bizform object
00066         $bizobj = $bizform->getDataObj();
00067 
00068         $h=opendir($this->m_targetReportPath);
00069         if (!$h)
00070         {
00071             echo "cannot read dir ".$this->m_targetReportPath;
00072             exit;
00073         }
00074         // create a tmp csv file for hold the data, then feed csv file to report engine
00075         $uid = $this->getUniqueString();
00076         $tmpfname = $this->m_targetReportPath . $uid . ".csv";
00077         //echo "csv file is at $tmpfname.<br>";
00078         $fp = fopen($tmpfname, 'w');
00079 
00080         $keyList = $bizform->m_RecordRow->GetSortControlKeys();
00081         $fieldNames = array();
00082         foreach($keyList as $key)
00083         {
00084             $fieldNames[] = $bizform->GetControl($key)->m_BizFieldName;
00085         }
00086         fputcsv($fp, $fieldNames);
00087 
00088         $recList = $bizobj->directFetch();
00089         foreach ($recList as $recArray)
00090         {
00091             unset($fieldValues);
00092             $fieldValues = array();
00093             $line = "";
00094             foreach($keyList as $key)
00095             {
00096                 $fieldValues[] = $recArray[$bizform->GetControl($key)->m_BizFieldName];
00097             }
00098             fputcsv($fp, $fieldValues);
00099         }
00100 
00101         fclose($fp);
00102 
00103         $i = 0;
00104         foreach($keyList as $key)
00105         {
00106             $rpt_fields[$i]["name"] = $bizform->GetControl($key)->m_BizFieldName;
00107             $rpt_fields[$i]["type"] = $bizobj->getField($rpt_fields[$i]["name"])->m_Type;
00108             $i++;
00109         }
00110 
00111         // dataobj.rptdesign.tpl
00112         // $rpt_data_dir, $rpt_title, $rpt_csv_file, $rpt_fields[](name,type)
00113         $smarty = BizSystem::getSmartyTemplate();
00114         $smarty->assign("rpt_data_dir", $this->m_targetReportPath);
00115         $smarty->assign("rpt_title", $bizform->m_Title);
00116         $smarty->assign("rpt_csv_file", basename($tmpfname));
00117         $smarty->assign("rpt_fields", $rpt_fields);
00118         $reportContent = $smarty->fetch($this->m_rptTemplate);
00119 
00120         $tmpRptDsgn = $this->m_targetReportPath . $uid . ".rptdesign";
00121         //echo "temp rpt design file is at $tmpRptDsgn.<br>";
00122         $fp = fopen($tmpRptDsgn, 'w');
00123         fwrite($fp, $reportContent);
00124         fclose($fp);
00125 
00126         ob_clean();
00127         $designFileName = $uid . ".rptdesign";
00128         $content = "<div style='font-family:Arial; font-size:12px; background-color:#FCFCFC;'>";
00129         $content .= "Reports can be viewed as ";
00130         $content .= "<li><a href='".$this->m_birtViewer."/run?__report=report\\$designFileName' target='__blank'>HTML report</a></li>";
00131         $content .= "<li><a href='".$this->m_birtViewer."/run?__report=report\\$designFileName&__format=pdf' target='__blank'>PDF report</a></li>";
00132         $content .= "<li><a href='".$this->m_birtViewer."/frameset?__report=report\\$designFileName' target='__blank'>Interactive report</a></li>";
00133         $content .= "</div>";
00134 
00135         echo $content;
00136         exit;
00137     }
00138 
00145     public function cleanFiles($dir, $seconds)
00146     {
00147         //Delete temporary files
00148         $currentTime = time();
00149         $dirHandle = opendir($dir);
00150         while($file = readdir($dirHandle))
00151         {
00152             $path=$dir.'/'.$file;
00153             if($currentTime - filemtime($path) > $seconds)
00154                 unlink($path);
00155         }
00156         closedir($dirHandle);
00157     }
00158 
00164     public function getUniqueString()
00165     {
00166         $mdy = date("mdy");
00167         $hms = date("His");
00168         $rightnow = $mdy.$hms;
00169 
00170         return md5($rightnow);
00171     }
00172 }
00173 ?>

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