96 public function fill($fileIn, $fileOut,
$filetype, $parameters, $classPath, $download =
true)
101 $page =
$MIOLO->getPage();
103 if ($this->connectionType==
'local')
107 if (is_array($parameters))
109 foreach ($parameters as $pn => $pv)
111 $param .=
'&' . $pn .
"~" . $pv;
115 $this->objDb =
$MIOLO->GetDatabase($this->db);
116 $dbUser = $this->objDb->user;
117 $dbPass = $this->objDb->pass;
118 $dbHost = $this->objDb->host;
119 $dbName = $this->objDb->db;
120 $dbPort = $this->objDb->port;
122 if ( $this->objDb->system ==
'postgres' )
124 $jdbcDriver =
'org.postgresql.Driver';
125 $dbPort = $dbPort ? $dbPort :
'5432';
126 $jdbcDb =
"jdbc:postgresql://{$dbHost}:{$dbPort}/{$dbName}";
128 elseif ( $this->objDb->system ==
'mysql' )
130 $jdbcDriver =
'com.mysql.jdbc.Driver';
131 $dbPort = $dbPort ? $dbPort :
'3306';
132 $jdbcDb =
"jdbc:mysql://{$dbHost}:{$dbPort}/{$dbName}";
136 $jdbcDriver =
'org.postgresql.Driver';
137 $jdbcDb =
"jdbc:postgresql://localhost:5432/postgres";
138 $dbUser =
"postgres";
139 $dbPass =
"postgres";
143 $pathInfo = pathinfo($fileIn);
144 chdir(realpath($pathInfo[
'dirname']));
146 $param =
"relatorio~$fileIn".$param.
"&fileout~".$fileOut.
"&filetype~".
$this->filetype;
148 $pathLog =
$MIOLO->GetConf(
'home.logs');
149 $fileLogTmp =
'/tmp/' . uniqid(md5(uniqid(
""))) .
'.txt';
150 $fileLog =
"mjasperreport.log";
152 $this->javaPath = $this->javaPath ? $this->javaPath .
'/bin/java' :
'java';
157 if ( !stripos(
$lang,
'utf') && !stripos(
$lang,
'iso') )
162 $cmd =
"export LANG=$lang; " . $this->javaPath .
" -Xms2g -Xmx2g -XX:-UseGCOverheadLimit -classpath $classPath MJasper \"{$pathMJasper}\" \"{$param}\" \"{$dbUser}\" \"{$dbPass}\" \"{$jdbcDriver}\" \"{$jdbcDb}\"";
163 $cmd .=
" 2>> $fileLogTmp";
167 if (trim($output[0])==
"end")
175 if ( strtoupper(trim($this->filetype)) ==
'HTML' )
177 $fileData = pathinfo($fileOut);
178 $fileName = $fileData[
'basename'];
179 $visibleFile =
$MIOLO->getConf(
"home.html") .
"/reports/$fileName";
180 copy($fileOut, $visibleFile);
185 $MIOLO->page->redirect(
$MIOLO->getConf(
'home.url') .
"/reports/$fileName");
193 if ( in_array(strtoupper(trim($this->filetype)), array(
'TXT',
'XLS')) )
195 $fileDown = $fileOut;
200 $MIOLO->sendFile($fileOut, $fileDown);
205 $this->arquivoRecemGerado = $fileOut;
209 elseif ( trim($output[0]) ==
'empty' )
215 $logerror .= file_get_contents($fileLogTmp);
216 $detalhes = _M(
"Ocorreu um erro durante a geração do relatório.");
217 $detalhes .=
"<br/>Detalhes do erro:<br/> ";
218 $detalhes .= $logerror;
219 $detalhes .= trim(implode(
"\n",$output));
221 if ( $output !=
'null' )
223 $file = fopen(
"$pathLog/$fileLog",
'a+');
224 $error = implode(
"\n\n", $output) .
"\n" . $logerror;
225 fwrite($file,
"\n\n$error");
233 else if ($this->connectionType==
'remote')
236 $this->fileout =
$MIOLO->getConf(
"home.url_jasper").
"?bd={$this->db}&relatorio=$filein" . $param;
237 $MIOLO->getPage()->window($this->fileout);
257 $uniqid = current(explode(
'.', basename($fileIn)));
258 $uniqid .=
'_' . uniqid(md5(uniqid(rand(),
true)));
261 for ( $count = 1; ( file_exists($pathout) || ( $pathout === null ) ); $count ++ )
263 $this->fileout = $uniqid . $count .
'.' . strtolower($this->filetype);
266 $this->absoluteFileOut = $pathout;
269 $pathMJasper =
$MIOLO->getConf(
"home.extensions").
"/jasper";
270 $pathLibs =
"$pathMJasper/lib/deps/*:$pathMJasper/lib/ext/*:$pathMJasper/lib/ireport/*:$pathMJasper/lib/jasperreports/*";
271 $classPath =
"$pathLibs:$pathMJasper/:$this->javaPath/lib";
273 return $this->
fill($fileIn, $pathout, $this->filetype, $parameters, $classPath, $download);
345 if ( !file_exists($reportFile) )
350 $xml = simplexml_load_file($reportFile);
352 $parameters = array();
354 foreach ( $xml->parameter as $parameter )
358 $name = (string) $parameter->attributes()->name;
361 $javaType = (string) $parameter->attributes()->class;
362 $p[
'type'] = self::getTypeFromJavaType($javaType);
365 foreach ( $parameter->property as $property )
367 $key = (string) $property->attributes()->name;
368 $value = (string) $property->attributes()->value;
371 $value = (string) $property;
377 $parameters[$name] = $p;
488 if ( $parameter[
'required'] ==
't' )
493 $control = strlen($parameter[
'tipo']) ? $parameter[
'tipo'] : $parameter[
'control'];
503 if ( isset($parameter[
'related']) )
507 $relateds = explode(
',', $parameter[
'related']);
509 foreach ( $relateds as $r )
511 if ( $r ==
"{$oldId}_Description" )
513 $related[] =
"str_{$oldId}_Description";
515 elseif ( $types[$r] )
517 $related[] =
"{$types[$r]}_$r";
521 $related[] =
"str_$r";
525 if ( count($related) > 1 )
527 $descriptionField =
"str_{$oldId}_Description";
531 $descriptionField = $related[0];
534 $related = implode(
',', $related);
538 if ( isset($parameter[
'filter']) )
540 $filters = explode(
',', $parameter[
'filter']);
542 foreach ( $filters as $filts )
544 $filter[$filts] =
'str_' . $filts;
548 $module = $parameter[
'module'];
549 $item = $parameter[
'item'];
551 if ( $descriptionField == NULL )
553 $descriptionField =
"str_{$oldId}_Description";
556 $field =
new MLookupContainer(
$id, $descriptionField, NULL, $label, $related, $module, $item, $filter);
557 $field->getDescriptionField()->hint = $parameter[
'hint'];
559 if ( $parameter[
'required'] ==
't' )
561 $field->showRequiredLabel =
true;
564 if ( $parameter[
'forceAutoComplete'] ==
't' )
566 $jsCode =
" function forceAutoComplete()
568 var valor = document.getElementById('{$id}').value;
569 document.getElementById('{$descriptionField}').focus();
570 document.getElementById('{$id}').focus();
572 setTimeout(function() { document.getElementById('{$id}').value = valor; }, 500);
574 $MIOLO->page->addJsCode($jsCode);
578 $field->addAttribute(
'onkeyup',
" javascript:forceAutoComplete(); ");
588 $item = $parameter[
'item'];
591 $keys = array_keys($parameter);
595 foreach( $keys as $key )
598 if( strpos($key,
"p_") === 0 )
600 $propriedade = substr($key, 2);
605 $typeArgs[$propriedade] = $parameter[$key];
611 if (isset($parameter[
'query']))
614 $typeInstance =
new BasGenericType();
617 foreach( $typeArgs as $propriedade => $valor)
619 $typeInstance->$propriedade = $valor;
624 $field =
new sEscolha(
$id, NULL, $label, $typeInstance, $parameter[
'hint'],
null, $parameter[
'query']);
629 $typeInstance =
new $item();
632 foreach( $typeArgs as $propriedade => $valor)
634 $typeInstance->$propriedade = $valor;
638 $field =
new sEscolha(
$id, NULL, $label, $typeInstance, $parameter[
'hint']);
645 if ( $parameter[
'query'] )
647 if ( ! $_SESSION[
'deleteReport'] )
652 elseif ( $parameter[
'options'] )
654 foreach(explode(
';',$parameter[
'options']) as $k=>$params)
656 $value = explode(
'=',trim($params));
659 $options[$k][0] = $value[0];
660 $options[$k][1] = $value[1];
665 $field = ( $control ==
'selection' ) ?
new MSelection(
$id, NULL, $label, $options,
false, $parameter[
'hint']) :
new MComboBox(
$id,
null, $label, $options,
false, $parameter[
'hint']);
669 if ( $parameter[
'query'] )
671 if ( ! $_SESSION[
'deleteReport'] )
676 elseif ( $parameter[
'options'] )
678 foreach(explode(
';',$parameter[
'options']) as $k=>$params)
680 $value = explode(
'=',trim($params));
683 $options[$k][0] = $value[1];
684 $options[$k][1] = $value[0];
693 $common =
$MIOLO->getConf(
'options.common');
694 $modulesPath =
$MIOLO->getConf(
'home.modules');
696 $class =
"$modulesPath/$common/classes/reportList.class";
698 if ( !file_exists($class) )
703 $MIOLO->uses(
'classes/reportList.class', $common);
705 $options = reportList::search($parameter[
'dados']);
706 $field =
new MSelection(
$id, NULL, $label, $options,
false, $parameter[
'hint']);
713 $typeInstance =
'optional';
714 if ( $parameter[
'required'] ==
't' )
716 $field->setIsRequired(
true);
717 $typeInstance =
'required';
718 $field->validator->type =
'required';
720 $validator =
new MDateDMYValidator(
$id, $label, $typeInstance);
729 $field =
new MSelection(
$id, NULL, $label, $listNoYes,
false, $parameter[
'hint']);
731 if ( $parameter[
'required'] ==
't' )
733 $field->validator->type =
'required';
737 case 'dicionarioDeCampos':
738 case 'dicionariodecampos':
747 list ( $field, $validator ) = SDicionarioDeCampos::obterCampo($oldId);
749 catch (Exception $ex)
757 $field =
new MTextField(
$id, NULL, $label, 10, $parameter[
'hint']);
762 $field =
new SHiddenField(substr(
$id, 4), $parameter[
'value']);
767 $field =
new $control();
769 if ( property_exists($field,
'hint') )
771 $field->hint = $parameter[
'hint'];
774 if ( $parameter[
'required'] ==
't' && method_exists($field,
'showRequiredLabel') )
776 $field->showRequiredLabel();
784 switch ( $parameter[
'type'] )
792 $field =
new MSelection(
$id, NULL, $label, $listNoYes,
false, $parameter[
'hint']);
798 if ( $parameter[
'required'] ==
't' )
800 $field->validator->type =
'required';
806 $field =
new MFloatField(
$id, NULL, $label, 10, $parameter[
'hint']);
810 $field =
new MTextField(
$id, NULL, $label, 10, $parameter[
'hint']);
811 $validatorType = $parameter[
'required'] ==
't' ?
'required' :
'optional';
819 $field =
new MTextField(
$id, NULL, $label, 10, $parameter[
'hint']);
824 return array(
$id, $field, $validator);