31 $weightArray = array();
32 $headerArray = array();
38 $db = db::raw_connect();
40 if(isset($form[
'dataFilter'])&&$form[
'dataFilter']){
41 if(strpos($form[
'dataFilter'],
'@')){
42 ereg(
"[\@][A-Za-z0-9_]+", $form[
'dataFilter'], $regs);
43 foreach($regs as $reg){
44 $form[
'dataFilter'] = str_replace($reg, $_REQUEST[
"fl_".str_replace(
"@",
"", $reg)], $form[
'dataFilter']);
48 if($form[
'type']==
'standard'){
49 if(isset($form[
'joinTables'])&&$form[
'joinTables']) {
50 $tables = $form[
'joinTables'];
52 if(isset($form[
'joinConditions'])&&$form[
'joinConditions']) {
53 $whereCondition =
" ".$form[
'joinConditions'];
55 foreach($form[
'components'] as $name => $com){
56 if(!isset($com[
'attributes'][
'value'])){
57 $com[
'attributes'][
'value'] =
"";
59 if($_REQUEST[
'fl_'.$name]==$com[
'attributes'][
'value']){
60 $_REQUEST[
'fl_'.$name] =
"";
62 if(trim($_REQUEST[
"fl_".$name])&&$_REQUEST[
"fl_".$name]!=
'@'){
63 if($form[
'components'][$name][
'valueType']==
'date'){
64 $whereCondition.=
" and ".$form[
'source'].
".$name = '".$_REQUEST[
"fl_".$name].
"'";
66 if($form[
'components'][$name][
'valueType']==
'numeric'){
67 $whereCondition.=
" and ".$form[
'source'].
".$name = '".$_REQUEST[
"fl_".$name].
"'";
69 if($form[
'components'][$name][
'type']==
'hidden'){
70 $whereCondition.=
" and ".$form[
'source'].
".$name = '".$_REQUEST[
"fl_".$name].
"'";
72 if($com[
'type']==
'check'){
73 if($_REQUEST[
"fl_".$name]==$form[
'components'][$name][
'checkedValue'])
74 $whereCondition.=
" and ".$form[
'source'].
".$name = '".$_REQUEST[
"fl_".$name].
"'";
76 if($com[
'type']==
'time'){
77 if($_REQUEST[
"fl_".$name]!=
'00:00'){
78 $whereCondition.=
" and {$form['source']}.$name = '".$_REQUEST[
"fl_".$name].
"'";
81 if($com[
'primary']||$com[
'type']==
'combo'){
82 $whereCondition.=
" and ".$form[
'source'].
".$name = '".$_REQUEST[
"fl_".$name].
"'";
84 $whereCondition.=
" and ".$form[
'source'].
".$name like '%".$_REQUEST[
"fl_".$name].
"%'";
97 ActiveRecord::sql_item_sanizite($_REQUEST[
'reportTypeField']);
98 if (substr($_REQUEST[
'reportTypeField'],strlen($_REQUEST[
'reportTypeField']) -3,strlen($_REQUEST[
'reportTypeField'])) ==
"_id"){
99 $OrderFields = substr($_REQUEST[
'reportTypeField'],0,strlen($_REQUEST[
'reportTypeField'])-3);
101 $OrderFields =$_REQUEST[
'reportTypeField'];
103 $maxCondition = $whereCondition;
105 foreach($form[
'components'] as $name => $com){
106 if(!isset($com[
'notReport'])){
107 $com[
'notReport'] =
false;
109 if(!isset($com[
'class'])){
110 $com[
'class'] =
false;
112 if(!$com[
'notReport']){
113 if(isset($com[
'caption'])&&$com[
'caption']){
114 $headerArray[$n] = str_replace(
"ó",
"ó", $com[
'caption']);
115 $headerArray[$n] = str_replace(
"á",
"á", $headerArray[$n]);
116 $headerArray[$n] = str_replace(
"é",
"é", $headerArray[$n]);
117 $headerArray[$n] = str_replace(
"í",
"í", $headerArray[$n]);
118 $headerArray[$n] = str_replace(
"ú",
"ú", $headerArray[$n]);
119 $headerArray[$n] = str_replace(
"<br/>",
" ", $headerArray[$n]);
121 $com[
'caption'] =
"";
123 if($com[
'type']==
'combo'&&$com[
'class']==
'dynamic'){
124 if(isset($com[
'extraTables'])&&$com[
'extraTables']){
125 $tables.=
"{$com['extraTables']},";
127 if(isset($com[
'whereConditionOnQuery'])&&$com[
'whereConditionOnQuery']){
128 $whereCondition.=
" and {$com['whereConditionOnQuery']}";
130 if(strpos(
" ".$com[
'detailField'],
"concat(")){
131 $selectedFields.=$com[
'detailField'].
",";
133 $selectedFields.=$com[
'foreignTable'].
".".$com[
'detailField'].
",";
136 if ($com[
'foreignTable'] == $OrderFields){
137 $OrderFields = $com[
'foreignTable'].
".".$com[
'detailField'];
140 $tables.=$com[
'foreignTable'].
",";
141 if($com[
'column_relation']){
142 $whereCondition.=
" and ".$com[
'foreignTable'].
".".$com[
'column_relation'].
" = ".$form[
'source'].
".".$name;
144 $whereCondition.=
" and ".$com[
'foreignTable'].
".".$name.
" = ".$form[
'source'].
".".$name;
146 $weightArray[$n] = strlen($headerArray[$n])+2;
149 if($com[
'type']!=
'hidden'){
150 if($com[
'class']==
'static' && isset($com[
'type']) && $com[
'type']==
'combo'){
151 $weightArray[$n] = strlen($headerArray[$n])+2;
153 $selectedFields.=
"case ";
156 for($i=0;$i<=count($com[
'items'])-2;$i++){
157 $selectedFields.=
"if(".$form[
'source'].
".".$name.
"='".$com[
'items'][$i][0].
"', '".$com[
'items'][$i][1].
"', ";
158 if($weightArray[$n]<strlen($com[
'items'][$i][1])) {
159 $weightArray[$n] = strlen($com[
'items'][$i][1])+1;
165 for($i=0;$i<=count($com[
'items'])-1;$i++){
166 $selectedFields.=
" when ".$form[
'source'].
".".$name.
"='".$com[
'items'][$i][0].
"' THEN '".$com[
'items'][$i][1].
"' ";
167 if($weightArray[$n]<strlen($com[
'items'][$i][1])) {
168 $weightArray[$n] = strlen($com[
'items'][$i][1])+1;
176 $selectedFields.=
"'".$com[
'items'][$i][1].
"')";
177 for($j=0;$j<=$i-2;$j++) {
178 $selectedFields.=
")";
182 $selectedFields.=
" end ";
184 $selectedFields.=
",";
186 $selectedFields.=$form[
'source'].
".".$name.
",";
189 if ($name == $OrderFields){
190 $OrderFields = $form[
'source'].
".".$OrderFields;
192 $weightArray[$n] = strlen($headerArray[$n])+2;
199 $tables.=$form[
'source'];
200 $selectedFields = substr($selectedFields, 0, strlen($selectedFields)-1);
202 if(isset($form[
'dataRequisite'])&&$form[
'dataRequisite']){
203 $whereCondition.=
" and {$form['dataFilter']}";
208 $OrderCondition =
"Order By ".$OrderFields;
210 $OrderCondition =
"";
213 $query =
"select $selectedFields from $tables where 1 = 1 ".$whereCondition.
" " .$OrderCondition;
215 $q = $db->query($query);
217 if(!$db->num_rows($q)){
228 while($row = $db->fetch_array($q, db::DB_NUM)){
229 $result[$n++] = $row;
232 foreach($result as $row){
233 for($i=0;$i<=count($row)-1;$i++){
234 if($weightArray[$i]<strlen(trim($row[$i]))){
235 $weightArray[$i] = strlen(trim($row[$i]));
240 for($i=0;$i<=count($weightArray)-1;$i++){
241 $weightArray[$i]*= 1.8;
244 $sumArray = array_sum($weightArray);
246 if(!$_REQUEST[
'reportType']){
247 $_REQUEST[
'reportType'] =
'pdf';
250 if($_REQUEST[
'reportType']!=
'html'){
251 $title = str_replace(
"ó",
"ó", $form[
'caption']);
252 $title = str_replace(
"á",
"á", $title);
253 $title = str_replace(
"é",
"é", $title);
254 $title = str_replace(
"í",
"í", $title);
255 $title = str_replace(
"ú",
"ú", $title);
257 $title = $form[
'caption'];
260 switch($_REQUEST[
'reportType']){
262 require_once
CORE_PATH .
'extensions/report/format/pdf.php';
263 pdf($result, $sumArray, $title, $weightArray, $headerArray);
266 require_once
CORE_PATH .
'extensions/report/format/xls.php';
267 xls($result, $sumArray, $title, $weightArray, $headerArray);
270 require_once
CORE_PATH .
'extensions/report/format/htm.php';
271 htm($result, $sumArray, $title, $weightArray, $headerArray);
274 require_once
CORE_PATH .
'extensions/report/format/doc.php';
275 doc($result, $sumArray, $title, $weightArray, $headerArray);
278 require_once
CORE_PATH .
'extensions/report/format/pdf.php';
279 pdf($result, $sumArray, $title, $weightArray, $headerArray);