/**
  * Import a report
  * 
  */
 public static function importFile($filename, $showMessage = true, $removeExistingReport = false)
 {
     $localErrors = array();
     $allAccounts = array();
     $dom = new domDocument();
     if (!$dom->load($filename)) {
         if ($showMessage) {
             throw new CException(Yii::t('lazy8', 'input file could not be xml parsed'));
         } else {
             throw new CException('input file could not be xml parsed');
         }
     }
     $root = $dom->documentElement;
     if ($root->nodeName != "lazy8webportreport") {
         if ($showMessage) {
             $localErrors = array(array(Yii::t('lazy8', 'Upload failed.  This is not a valid file.'), Yii::t('lazy8', 'Select a file and try again')));
         }
         return $localErrors;
     }
     if ($root->getAttribute('version') > 1.0) {
         if ($showMessage) {
             $localErrors = array(array(Yii::t('lazy8', 'There maybe problems because this is a file version greater then this programs version'), Yii::t('lazy8', 'Select a file and try again')));
         }
     }
     $nodeReports = $root->getElementsByTagName('report');
     unset($root);
     unset($dom);
     foreach ($nodeReports as $nodeReport) {
         if ($removeExistingReport) {
             $deleteReports = Report::model()->findAll(array('condition' => 'name=\'' . $nodeReport->getAttribute('name') . '\''));
             if ($deleteReports != null) {
                 foreach ($deleteReports as $deleteReport) {
                     $deleteReport->delete();
                 }
             }
         }
         $report = new Report();
         $report->name = $nodeReport->getAttribute('name');
         $report->desc = ReportController::getNodeText($nodeReport, "desc");
         $report->selectSql = ReportController::getNodeText($nodeReport, "selectsql");
         $report->sortOrder = ReportController::getNodeText($nodeReport, "sortOrder");
         $report->cssColorFileName = ReportController::getNodeText($nodeReport, "csscolorfilename");
         $report->cssBwFileName = ReportController::getNodeText($nodeReport, "cssbwfilename");
         $nodeParams = $nodeReport->getElementsByTagName('parameter');
         if (!$report->save()) {
             if ($showMessage) {
                 $localErrors = $report->getErrors();
             }
             return $localErrors;
         }
         foreach ($nodeParams as $nodeParam) {
             $reportParam = new ReportParameters();
             $reportParam->reportId = $report->id;
             $reportParam->sortOrder = $nodeParam->getAttribute('sortorder');
             $reportParam->name = $nodeParam->getAttribute('name');
             $reportParam->alias = $nodeParam->getAttribute('alias');
             $reportParam->dataType = $nodeParam->getAttribute('datatype');
             $reportParam->isDefaultPhp = $nodeParam->getAttribute('isdefaultphp') == 'true' ? 1 : 0;
             $reportParam->isDate = $nodeParam->getAttribute('isdate') == 'true' ? 1 : 0;
             $reportParam->isDecimal = $nodeParam->getAttribute('isdecimal') == 'true' ? 1 : 0;
             $reportParam->desc = ReportController::getNodeText($nodeParam, "desc");
             $reportParam->phpSecondaryInfo = ReportController::getNodeText($nodeParam, "phpsecondaryinfo");
             $reportParam->defaultValue = ReportController::getNodeText($nodeParam, "defaultvalue");
             if (!$reportParam->save()) {
                 if ($showMessage) {
                     $localErrors = $reportParam->getErrors();
                 }
             }
         }
         unset($nodeParams);
         $nodeGroups = $nodeReport->getElementsByTagName('group');
         foreach ($nodeGroups as $nodeGroup) {
             $reportGroup = new ReportGroups();
             $reportGroup->reportId = $report->id;
             $reportGroup->sortOrder = $nodeGroup->getAttribute('sortorder');
             $reportGroup->breakingField = $nodeGroup->getAttribute('breakingfield');
             $reportGroup->pageBreak = $nodeGroup->getAttribute('pagebreak') == 'true' ? 1 : 0;
             $reportGroup->showGrid = $nodeGroup->getAttribute('showgrid') == 'true' ? 1 : 0;
             $reportGroup->showHeader = $nodeGroup->getAttribute('showheader') == 'true' ? 1 : 0;
             $reportGroup->continueSumsOverGroup = $nodeGroup->getAttribute('continuesumsovergroup') == 'true' ? 1 : 0;
             if (!$reportGroup->save()) {
                 if ($showMessage) {
                     $localErrors = $reportGroup->getErrors();
                 }
             }
             $nodeGroupFields = $nodeGroup->getElementsByTagName('field');
             foreach ($nodeGroupFields as $nodeGroupField) {
                 $reportGroupField = new ReportGroupFields();
                 $reportGroupField->reportGroupId = $reportGroup->id;
                 $reportGroupField->sortOrder = $nodeGroupField->getAttribute('sortorder');
                 $reportGroupField->fieldName = $nodeGroupField->getAttribute('fieldname');
                 $reportGroupField->fieldWidth = $nodeGroupField->getAttribute('fieldwidth');
                 $reportGroupField->row = $nodeGroupField->getAttribute('row');
                 $reportGroupField->isDate = $nodeGroupField->getAttribute('isdate') == 'true' ? 1 : 0;
                 $reportGroupField->isDecimal = $nodeGroupField->getAttribute('isdecimal') == 'true' ? 1 : 0;
                 $reportGroupField->fieldCalc = ReportController::getNodeText($nodeGroupField, "fieldcalc");
                 if (!$reportGroupField->save()) {
                     if ($showMessage) {
                         $localErrors = $reportGroupField->getErrors();
                     }
                 }
             }
             unset($nodeGroupFields);
         }
         unset($nodeGroups);
         $nodeReportRows = $nodeReport->getElementsByTagName('rows');
         foreach ($nodeReportRows as $nodeReportRow) {
             $reportRow = new ReportRows();
             $reportRow->reportId = $report->id;
             $reportRow->sortOrder = $nodeReportRow->getAttribute('sortorder');
             $reportRow->fieldName = $nodeReportRow->getAttribute('fieldname');
             $reportRow->fieldWidth = $nodeReportRow->getAttribute('fieldwidth');
             $reportRow->row = $nodeReportRow->getAttribute('row');
             $reportRow->isSummed = $nodeReportRow->getAttribute('issummed') == 'true' ? 1 : 0;
             $reportRow->isAlignRight = $nodeReportRow->getAttribute('isalignright') == 'true' ? 1 : 0;
             $reportRow->isDate = $nodeReportRow->getAttribute('isdate') == 'true' ? 1 : 0;
             $reportRow->isDecimal = $nodeReportRow->getAttribute('isdecimal') == 'true' ? 1 : 0;
             $reportRow->fieldCalc = ReportController::getNodeText($nodeReportRow, "fieldcalc");
             if (!$reportRow->save()) {
                 if ($showMessage) {
                     $localErrors = $reportRow->getErrors();
                 }
             }
         }
     }
     return $localErrors;
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the primary key value. Defaults to null, meaning using the 'id' GET variable
  */
 public function loadReportParameters($id = null)
 {
     if ($this->_model === null) {
         if ($id !== null || isset($_GET['id'])) {
             $this->_model = ReportParameters::model()->findbyPk($id !== null ? $id : $_GET['id']);
         }
         if ($this->_model === null) {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
     return $this->_model;
 }