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

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

00001 <?php
00025 class ioService
00026 {
00033     public function __construct(&$xmlArr)
00034     {
00035     }
00036 
00043     public function exportXML($objName)
00044     {
00045         // get the current UI bizobj
00046         /* @var $bizForm EasyForm */
00047         $bizForm = BizSystem::getObject($objName);    // get the existing bizform object
00048         $bizObj = $bizForm->getDataObj();
00049 
00050         $recList = array();
00051         $bizObj->fetchRecords("", $recList, -1, -1, false);
00052 
00053         $xmlString = "<?xml version='1.0' standalone='yes'?>\n";
00054         $xmlString .= "<BizDataObj Name=\"".$bizObj->m_Name."\">\n";
00055         foreach ($recList as $rec)
00056         {
00057             $xmlRecord = "\t<Record>\n";
00058             foreach ($rec as $fld=>$val)
00059             {
00060                 $xmlRecord .= "\t\t<Field Name=\"$fld\" Value=\"$val\" />\n";
00061             }
00062             $xmlRecord .= "\t</Record>\n";
00063             $xmlString .= $xmlRecord;
00064         }
00065         $xmlString .= "</BizDataObj>";
00066 
00067         // output variables
00068         $name = str_replace(".","_",$bizObj->m_Name).".xml";
00069         $size = strlen($xmlString);
00070         $type = "text/plain";
00071 
00072         ob_clean();
00073 
00074         header("Cache-Control: ");// leave blank to avoid IE errors
00075         header("Pragma: ");// leave blank to avoid IE errors
00076         header("Content-Disposition: attachment; filename=\"$name\"");
00077         header("Content-length: $size");
00078         header("Content-type: $type");
00079         
00080         echo $xmlString;
00081 
00082         exit;
00083     }
00084 
00091     public function importXML($objName)
00092     {
00093         // read in file from $_FILE
00094         // read in file data and attributes
00095         foreach ($_FILES as $file)
00096         {
00097             $error = $file['error'];
00098             if ($error != 0)
00099             {
00100                 $this->reportError($error);
00101                 return;
00102             }
00103 
00104             $tmpName  = $file['tmp_name'];
00105             $xml = simplexml_load_file($tmpName);
00106             if (!$xml)
00107             {
00108                 $errorMsg = "Invalid input data format, could not create xml object.";
00109                 BizSystem::clientProxy()->showErrorMessage($errorMsg);
00110                 return;
00111             }
00112             // only read the first one
00113             break;
00114         }
00115 
00116         // get the current UI bizobj
00117         /* @var $form EasyForm */
00118         $form = BizSystem::getObject($objName);    // get the existing bizform object
00119         /* @var $parentForm EasyForm */
00120         $parentForm = BizSystem::getObject($form->GetParentForm());
00121         /* @var $dataObj BizDataObj */
00122         $dataObj = $parentForm->getDataObj();
00123 
00124         //$oldCacheMode = $dataObj->GetCacheMode();
00125         //$dataObj->SetCacheMode(0);    // turn off cache mode, not affect the current cache
00126 
00127         // check if BizDataObj name matches
00128         $dataObjName = $xml['Name'];
00129         if ($dataObj->m_Name != $$dataObjName)
00130         {
00131             $errorMsg = "Invalid input data. Input data object is not same as the current data object.";
00132             BizSystem::clientProxy()->showErrorMessage($errorMsg);
00133             return;
00134         }
00135 
00136         // read records
00137         foreach ($xml->Record as $record)
00138         {
00139             // insert record
00140             // todo: check if there's same user keys in the table
00141             $recArray = null;
00142             $recArray = $dataObj->newRecord();
00143             foreach ($record as $field)
00144             {
00145                 $value = "";
00146                 foreach ($field->attributes() as $attributeName=>$attributeValue)
00147                 {
00148                     if ($attributeName == 'Name') $name = $attributeValue."";
00149                     else if ($attributeName == 'Value') $value = $attributeValue."";
00150                 }
00151                 if ($name != "Id")
00152                     $recArray[$name] = $value;
00153             }
00154 
00155             if (!$dataObj->insertRecord($recArray))
00156             {
00157                 $errorMsg = $dataObj->getErrorMessage();
00158                 BizSystem::clientProxy()->showErrorMessage($errorMsg);
00159                 return;
00160             }
00161         }
00162         // $dataObj->SetCacheMode($oldCacheMode);  // restore cache mode
00163 
00164         $form->setFormState(1); // indicate the import is done
00165     }
00166 
00173     protected function reportError($error)
00174     {
00175         if ($error==1)
00176             $errorStr = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
00177         else if ($error==2)
00178             $errorStr = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
00179         else if ($error==3)
00180             $errorStr = "The uploaded file was only partially uploaded";
00181         else if ($error==4)
00182             $errorStr = "No file was uploaded";
00183         else if ($error==6)
00184             $errorStr = "Missing a temporary folder";
00185         else if ($error==7)
00186             $errorStr = "Failed to write file to disk";
00187         else
00188             $errorStr = "Error in file upload";
00189 
00190         global $g_BizSystem;
00191         BizSystem::clientProxy()->showErrorMessage($errorStr);
00192     }
00193 }
00194 
00195 ?>

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