kenken999/php
0
1<?php2ini_set("display_errors","1");3ini_set("display_startup_errors","1");4include("include/dbcommon.php");5header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");6 7include("include/reportfunctions.php");8 9 if( !Security::getUserName() )10 {11 $_SESSION["MyURL"] = GetTableLink("webreport");12 header("Location: ".GetTableLink("login", "", "message=expired"));13 return;14 }15 16Reload_Report(postvalue("rname"));17 18if (is_wr_project()) 19 include("include/" . GetTableURL( $_SESSION['webreports']['tables'][0] ) . "_variables.php");20 21 22include('include/xtempl.php');23$xt = new Xtempl();24 25$arr_tables = getReportTablesList();26$group_fields = array();27 28foreach($arr_tables as $t)29{30 $tfields = WRGetNBFieldsList($t);31 foreach($tfields as $f)32 {33 if(is_wr_db())34 $group_fields[] = $t.".".$f;35 else36 $group_fields[] = $f;37 }38}39if (@$_SESSION['webreports']['settings']['title'] != "") {40 $title=@$_SESSION['webreports']['settings']['title'];41 if(strlen($title)>25)42 $title=substr($title,25)."...";43 $xt->assign("report_title",", "."Title".": ".$title);44} else {45 $xt->assign("report_title","");46}47if (@$_SESSION['webreports']['tables'][0] != "") {48 $stable=@$_SESSION['webreports']['tables'][0];49 if(strlen($stable)>25)50 $stable=substr($stable,25)."...";51 52 $xt->assign("report_table",", "."Table".": ".$stable);53} else {54 $xt->assign("report_table","");55}56 57$xt->assign("b_is_report_save",($_SESSION['webreports']['tmp_active'] != "x"));58$xt->assign("b_is_report_name",($_SESSION['webreports']['settings']['name'] != ""));59$xt->assign("report_name",$_SESSION['webreports']['settings']['name']);60 61$sGroupFields = "";62$types = "";63 64 65$h_includes = "";66$b_includes = "";67 68$h_includes .= '69 <link rel="stylesheet" href="'.GetRootPathForResources("include/css/stylesheet.css").'" type="text/css">70 <link rel="stylesheet" href="'.GetRootPathForResources("include/css/dstyle.css").'" type="text/css">71 <link rel="stylesheet" href="'.GetRootPathForResources("include/css/jquery-ui.css").'" type="text/css">72 <link rel="stylesheet" href="'.GetRootPathForResources("include/fancybox/jquery.fancybox.css").'" type="text/css" media="screen">73 74 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.min.js").'"></script>75 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.dimensions.pack.js").'"></script>76 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.easing.js").'"></script>77 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.fancybox.pack.js").'"></script>78 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery-ui.js").'"></script>79 <script type="text/javascript" src="'.GetRootPathForResources("include/js/json.js").'"></script>80'."\r\n";81 82 83$xt->assign("h_includes", $h_includes);84 85$b_includes .= '<script type="text/javascript">'."\r\n";86$b_includes .= '87arr_color = new Array();88 89arr_color["0"]="FFFFFF";90 91arr_color["1"]="FF0000";92arr_color["2"]="008000";93arr_color["3"]="0000FF";94 95arr_color["4"]="DC143C";96arr_color["5"]="2E8B57";97arr_color["6"]="6A5ACD";98 99arr_color["7"]="FF7F50";100arr_color["8"]="7FFF00";101arr_color["9"]="5F9EA0";102 103arr_color["10"]="FF8C00";104arr_color["11"]="8FBC8B";105arr_color["12"]="00008B";106 107arr_color["13"]="FF1493";108arr_color["14"]="556B2F";109arr_color["15"]="00BFFF";110 111arr_color["16"]="FF69B4";112arr_color["17"]="008B8B";113arr_color["18"]="ADD8E6";114 115arr_color["19"]="F08080";116arr_color["20"]="32CD32";117arr_color["21"]="4169E1";118 119arr_color["22"]="A52A2A";120arr_color["23"]="006400";121arr_color["24"]="6495ED";122'."\r\n";123$b_includes .= 'fld_types = new Array();'."\r\n";124 125if(is_wr_custom())126{127 $fields_type=array();128 $fields_type=WRGetAllCustomFieldType();129}130 131foreach ($group_fields as $fld) {132 if(!is_wr_custom())133 $type = WRGetFieldType($fld);134 else135 $type = $fields_type[$fld];136 137 if ( IsNumberType( $type ) ) {138 $b_includes .= "fld_types['" . jsreplace($fld) . "'] = \"number\";"."\r\n";139 } elseif ( IsCharType( $type ) ) {140 $b_includes .= "fld_types['" . jsreplace($fld) . "'] = \"string\";"."\r\n";141 } elseif ( IsDateFieldType( $type ) ) {142 $b_includes .= "fld_types['" . jsreplace($fld) . "'] = \"date\";"."\r\n";143 }144}145 146if (is_wr_db()) {147 $b_includes .= '148 var NEXT_PAGE_URL = "'.GetTableLink("webreport4").'",149 PREV_PAGE_URL = "'.GetTableLink("webreport2").'";150 '."\r\n";151} else {152 $b_includes .= '153 var NEXT_PAGE_URL = "'.GetTableLink("webreport4").'",154 PREV_PAGE_URL = "'.GetTableLink("webreport0").'";155 '."\r\n"; 156}157 158$b_includes .= '159var timeout = 200,160 closetimerpicker = 0,161 closetimer=0,162 timeoutpicker = 300,163 relation_stack = [],164 int_types = new Array(165 [0, "Normal"],166 [10, "10s"],167 [50, "50s"],168 [100, "100s"],169 [500, "500s"],170 [1000, "1000s"]171 ),172 str_types = new Array(173 [0, "Normal"],174 [1, "1st Letter"],175 [2, "2 Initial Letters"],176 [3, "3 Initial Letters"],177 [4, "4 Initial Letters"],178 [5, "5 Initial Letters"]179 ),180 date_types = new Array(181 [0, "Normal"],182 [1, "Year"],183 [2, "Quarter"],184 [3, "Month"],185 [4, "Week"],186 [5, "Day"],187 [6, "Hour"],188 [7, "Minute"]189 );190 191$(document).ready(function(){192 $("a#preview").fancybox({193 fitToView: false,194 autoSize: false,195 width : 820,196 height : 660,197 overlayShow: true198 });199 ';200 $b_includes .= alertDialog();201 $b_includes .= '202 function add_dataseries(th)203 {204 total_fields=$("select[id^=field]").length;205 this_id=parseInt($(th).attr("id").replace("field",""));206 if($(th)[0].selectedIndex==0)207 {208 color="FFFFFF";209 if(this_id<25) 210 color=arr_color[this_id];211 $("#picker"+this_id).css("background-color",color);212 for(i=this_id+1;i<=total_fields;i++)213 $("#groupfield"+i).remove();214 }215 else216 {217 if($("select[id=field"+total_fields+"]")[0].selectedIndex!=0)218 {219 groupfield=$("tr[id=clone]").clone();220 groupfield.insertBefore("#end_of_group_fields");221 groupfield.attr("id","groupfield"+parseInt(total_fields+1));222 groupfield.find("input:eq(0)").attr("id","go"+parseInt(total_fields+1))223 .attr("name","go"+parseInt(total_fields+1))224 .attr("value",parseInt(total_fields+1));225 groupfield.find("select:eq(0)").attr("id","field"+parseInt(total_fields+1))226 .attr("name","field"+parseInt(total_fields+1))227 .change(function(){228 add_dataseries(this);229 })[0].selectedIndex = 0;230 groupfield.find("select:eq(1)").attr("id","type"+parseInt(total_fields+1))231 .attr("name","type"+parseInt(total_fields+1));232 groupfield.find("select:eq(2)").attr("id","group_type"+parseInt(total_fields+1))233 .attr("name","group_type"+parseInt(total_fields+1));234 groupfield.find("input:eq(1)").attr("id","ss"+parseInt(total_fields+1))235 .attr("name","ss"+parseInt(total_fields+1));236 color = "FFFFFF";237 if((total_fields+1)<25) 238 color = arr_color[total_fields+1];239 arr = HexToDec(color);240 red = parseInt( arr[0] * 0.85 );241 green = parseInt( arr[1] * 0.85 );242 blue = parseInt( arr[2] * 0.85 );243 hex = DecToHex( red, green, blue );244 groupfield.find("div:eq(0)").attr("id","picker"+parseInt(total_fields+1))245 .css("background-color",color)246 .attr("color1",color)247 .attr("color2",hex)248 .click(function(){249 click_color_event(this);250 });251 groupfield.find(".selector").click(function(){252 click_color_event(this);253 });254 groupfield.show();255 }256 }257 $("select[id=type" + this_id + "]").empty();258 switch ( fld_types[th.value] ) {259 case "number":260 for (var i=0; i < int_types.length; i++) {261 $("select[id=type" + this_id + "]").append(\'<option value="\' + int_types[i][0] + \'">\' + int_types[i][1] + \'</option>\');262 }263 $("select[id=type" + this_id + "]")[0].selectedIndex = 0;264 break;265 case "string":266 for (var i=0; i < str_types.length; i++) {267 $("select[id=type" + this_id + "]").append("<option value=\"" + str_types[i][0] + "\">" + str_types[i][1] +"</option>");268 }269 $("select[id=type" + this_id + "]")[0].selectedIndex = 0;270 break;271 case "date":272 for (var i=0; i < date_types.length; i++) {273 $("select[id=type" + this_id + "]").append(\'<option value="\' + date_types[i][0] + \'">\' + date_types[i][1] + \'</option>\');274 }275 $("select[id=type" + this_id + "]")[0].selectedIndex = 0;276 break;277 default:278 break;279 }280 }281 function collect_input_data() {282 var output = {};283 output.group_fields = [];284 k=0;285 $("tr[id^=groupfield]").each(function(i){286 val_field=$(this).find("select:eq(0)").val();287 flag=true;288 $("tr[id^=groupfield]").each(function(j){289 if(j >= i)290 return false;291 if(j<i && val_field==$(this).find("select:eq(0)").val()){292 flag = false;293 return false;294 }295 });296 if ( $(this).find("select:eq(0)").val() != "" && $(this).find("select:eq(0)").val() != undefined && flag) {297 output.group_fields[k] = {298 name : $("select[id^=field]",this).val(),299 int_type : $("select[id^=type]",this).val(),300 ss : $("input[id^=ss]",this).prop("checked").toString(),301 group_order : $("input[id^=go]",this).val(),302 group_type : $("select[id^=group_type]",this).val(),303 color1 : $("div[id^=picker]",this).attr("color1"),304 color2 : $("div[id^=picker]",this).attr("color2")305 };306 k++;307 }308 });309 output.group_fields.push({310 name : "Summary",311 cross_table : $("#select_cross")[0].checked.toString(),312 sps : $("#sps").prop("checked").toString(),313 sds : $("#sds").prop("checked").toString(),314 sgs : $("#sgs").prop("checked").toString(),315 sum_x : $("#sum_x").prop("checked").toString(),316 sum_y : $("#sum_y").prop("checked").toString(),317 sum_total : $("#sum_total").prop("checked").toString()318 });319 return JSON.stringify(output);320 }';321 322$b_includes .= colorPickerMouse();323 324$b_includes .= '325 326 $("#sum_x,#sum_y").click(function(){327 if(!$("#sum_x")[0].checked || !$("#sum_y")[0].checked)328 {329 $("#sum_total")[0].checked=false;330 $("#sum_total")[0].disabled=true;331 }332 else333 $("#sum_total")[0].disabled=false;334 });335 $("#select_cross").click(function(){336 show_hide_cross_table_report($(this)[0].checked);337 });338 function show_hide_cross_table_report(ch)339 {340 if(ch)341 {342 $("td[name=report_col],th[name=report_col],table[name=report_col]").hide();343 $("td[name=cross_col],th[name=cross_col],table[name=cross_col]").show();344 if($("#field2").length>0)345 {346 if($("#field2")[0].selectedIndex==0)347 {348 $("#field2")[0].selectedIndex=2;349 $("#field2").change();350 $("#group_type2")[0].selectedIndex=1;351 }352 }353 $("#row5,#row6").hide();354 if(!$("#sum_x")[0].checked || !$("#sum_y")[0].checked)355 {356 $("#sum_total")[0].checked=false;357 $("#sum_total")[0].disabled=true;358 }359 else360 $("#sum_total")[0].disabled=false;361 }362 else363 {364 $("td[name=report_col],th[name=report_col],table[name=report_col]").show();365 $("td[name=cross_col],th[name=cross_col],table[name=cross_col]").hide();366 $("#row5,#row6").show();367 }368 }369 $("select[id^=field]").change(function(){370 add_dataseries(this);371 }); 372 $("#row3")373 .css("cursor", "default")374 .css("font-weight", "bold");375 376 $("td[id^=row]").mouseover(function(){377 for(var i=0; i<=11; i++) {378 if(i == this.id.replace("row", "")) {379 $("td[id=row" + i + "]").css("background-color","#92BEEB");380 }381 else {382 $("td[id=row" + i + "]").css("background-color","#F4F7FB");383 }384 }385 });386 387 388'."\r\n";389 390$b_includes .= JumpTo();391 392if (count(GetUserGroups()) < 2393 || isset( $_SESSION['webreports']['settings']['status'] ) && $_SESSION['webreports']['settings']['status'] == "private" ) {394 $b_includes .= '$("td[id=row9]").hide();'."\r\n";395}396if (is_wr_project() || is_wr_custom()) {397 $b_includes .= '$("td[id=row1], td[id=row2]").hide();'."\r\n";398}399if($wr_is_standalone)400 $b_includes .= '$("td[id=row11]").hide();'."\n";401 402if ($_SESSION['webreports']['settings']['title'] == "") {403 $b_includes .= '404 for (var i=2; i<=9; i++){405 $("td[id=row" + i + "]").hide();406 };407 '."\r\n";408}409 410$rLinks = "var rlinks = {};\r\n";411for($ri = 0; $ri < 10; $ri++)412 $rLinks.= "rlinks['".$ri."'] = '".GetTableLink("webreport".$ri)."';\r\n";413 414$b_includes .= '415 $("#nextbtn, #backbtn, td[id^=row], #savebtn, #saveasbtn, #previewbtn").click(function(){416 if($("#colorPickerVtd"))417 $("#colorPickerVtd").hide();418 var URL = "'.GetTableLink("webreport").'";419 '.$rLinks.'420 if( this.id == "nextbtn" )421 URL = NEXT_PAGE_URL;422 if( this.id == "backbtn" )423 URL = PREV_PAGE_URL;424 if( this.id == "saveasbtn" )425 URL = "'.GetTableLink("webreport8", "", "saveas=1").'"; 426 if( this.id.substr(0,3)=="row" && this.id != "row3" )427 URL = rlinks[this.id.replace(\'row\',\'\')];428 if( this.id == "row10" )429 URL = "'.GetTableLink("webreport").'";430 if( this.id == "row11" )431 URL = "'.GetTableLink("menu").'";432 if ( this.id == "row7" )433 URL = "'.GetTableLink("dreport").'?edit=style&rname='.@$_SESSION['webreports']['settings']['name'].'";434 435 var output = collect_input_data();436 var_save=0;437 if( this.id == "savebtn")438 var_save=1;439 if( this.id == "savebtn" || this.id == "previewbtn" ) {440 id=this.id;441 $.ajax({442 type: "POST",443 url: "'.GetTableLink("save-state").'",444 data: {445 save: var_save,446 web: "webreports",447 name: "group_fields",448 str_xml: output,449 rnd: (new Date().getTime())450 },451 success: function(msg){452 if ( msg == "OK" ) {453 if(id=="savebtn")454 {455 $("#alert")456 .html("<p>'."Report Saved".'</p>")457 .dialog("option", "close", function(){458 window.location = "'.GetTableLink("webreport").'";459 })460 .dialog("open");461 }462 else463 $("#preview").click();464 } else {465 $("#alert").html("<p>"+msg+"</p>").dialog("open");466 }467 },468 error: function() {469 $("#alert").html("<p>'."Some problems appear during saving".'</p>").dialog("open");470 }471 });472 }473 474 thisid=this.id;475 if(this.id != "row3" && this.id !="savebtn" && this.id !="previewbtn") {476 $.ajax({477 type: "POST",478 url: "'.GetTableLink("save-state").'",479 data: {480 name: "group_fields",481 web: "webreports",482 str_xml: output,483 rnd: (new Date().getTime())484 },485 success: function(msg){486 if ( msg == "OK" ) {487 window.location = URL;488 } else {489 $("#alert").html("<p>"+msg+"</p>").dialog("open");490 if( thisid == "row10" || thisid == "row11" )491 window.location=URL; 492 }493 }494 });495 }496 });'."\r\n";497 498foreach ($group_fields as $fld) {499 $sGroupFields .= "<option value=\"" . runner_htmlspecialchars($fld) . "\">" . $fld . "</option>"."\r\n";500}501 502$aGroupFields = array();503//$aGroupFields = $sGroupFields;504$aTypes = array();505$aChecked = array();506$aColor1 = array();507$aColor2 = array();508$aGrTypes=array();509 510$arr = $_SESSION['webreports']['group_fields'];511if(count($arr)==1)512{513 $arr[]=$arr[0];514 $table=@$_SESSION['webreports']['tables'][0];515 $arr_fields = WRGetNBFieldsList($table);516 517 $gfield=$arr_fields[0];518 if(is_wr_db())519 $gfield=$table.".".$arr_fields[0];520 $arr[0] = array(521 522 array(523 "name" => $gfield,524 "int_type" => "0",525 "ss" => "true",526 "group_order" => "1",527 "color1" => "FF0000",528 "color2" => "CC0000"529 )530 ); 531}532 533if ( !empty( $arr )){534 for ( $i=0; $i < count($arr)-1; $i++ ) {535 536 $sGroupFields = "";537 $key=0;538 $j=0;539 foreach ($group_fields as $fld) 540 {541 if($fld == $arr[$i]["name"])542 $key=$j+1;543 $sGroupFields .= "<option value=\"" . runner_htmlspecialchars($fld) . "\">" . $fld . "</option>"."\r\n";544 $j++;545 }546 $aGroupFields[$i] = $sGroupFields;547 $aTypes[$i] = $arr[$i]["int_type"];548 $aColor1[$i] = $arr[$i]["color1"];549 $aColor2[$i] = $arr[$i]["color2"];550 $aGrTypes[$i] = $arr[$i]["group_type"];551 if($arr[$i]["ss"] == "true")552 $b_includes .= '$("#ss'.($i+1).'")[0].checked=true;';553 $b_includes .= '554 $("#field'.($i+1).'")[0].selectedIndex='.$key.';555 add_dataseries($("#field'.($i+1).'"));556 '."\r\n";557 }558 559 $akeys = array_keys($arr);560 $summIdx = $akeys[count($akeys)-1];561 $xt->assign("sps", ( $arr[$summIdx]["sps"] == "true" ) ? "checked" : "");562 $xt->assign("sds", ( $arr[$summIdx]["sds"] == "true" ) ? "checked" : "");563 $xt->assign("sgs", ( $arr[$summIdx]["sgs"] == "true" ) ? "checked" : "");564 $xt->assign("sum_x", ( $arr[$summIdx]["sum_x"] == "true" ) ? "checked" : "");565 $xt->assign("sum_y", ( $arr[$summIdx]["sum_y"] == "true" ) ? "checked" : "");566 $xt->assign("sum_total", ( $arr[$summIdx]["sum_total"] == "true" ) ? "checked" : "");567} else {568 $xt->assign("sps", "");569 $xt->assign("sds", "checked");570 $xt->assign("sgs", "");571 $xt->assign("sum_x", "checked");572 $xt->assign("sum_y", "checked");573 $xt->assign("sum_total", "checked");574}575 576$is_crosstable_report="";577if(count($group_fields)<3)578 $b_includes .= '$("#select_cross").parent().parent().hide();579 $("#select_cross")[0].checked=false';580else 581 $is_crosstable_report=$arr[count($arr)-1]["cross_table"];582 583if($is_crosstable_report=="true")584 $b_includes .= '585 $("#select_cross")[0].checked=true;586 $("#row5,#row6").hide();show_hide_cross_table_report(true);587 '."\r\n";588 589for ( $i=0; $i < count($aGroupFields); $i++ ) {590 $xt->assign("groupFields" . ($i+1), $aGroupFields[$i]);591 //$xt->assign("schecked" . ($i+1), $aChecked[$i]);592}593 594$b_includes .= '595 $("select[id^=field]").change();'."\r\n";596 597for ( $i=0; $i < count($aTypes); $i++ ) {598 $b_includes .= '$("select[id=type' . ($i+1) . ']").children().each(function(i){599 if ( $(this).attr("value") == "' . $aTypes[$i] . '" ) {600 setTimeout("$(\'select[id=type' . ($i+1) . ']\')[0].selectedIndex = " + i + ";",500);601 }602 });'."\r\n";603}604for ( $i=0; $i < count($aGrTypes); $i++ ) {605 $b_includes .= '$("select[id=group_type' . ($i+1) . ']").children().each(function(i){606 if ( $(this).attr("value") == "' . $aGrTypes[$i] . '" ) {607 setTimeout("$(\'select[id=group_type' . ($i+1) . ']\')[0].selectedIndex = " + i + ";",500);608 }609 });'."\r\n";610}611for ( $i=0; $i < count($aColor1); $i++ ) {612 $b_includes .= ' var picker' . ($i+1) . ' = $("div[id=picker' . ($i+1) . ']");613 ';614 if ( $aColor1[$i] != "" ) {615 $b_includes .= 'picker' . ($i+1) . '.css("background-color","#' . $aColor1[$i] . '");'."\r\n";616 }617 $b_includes .= 'picker' . ($i+1) . '.attr("color1", "' . $aColor1[$i] . '");' . "\r\n";618 $b_includes .= 'picker' . ($i+1) . '.attr("color2", "' . $aColor2[$i] . '");' . "\r\n";619 $b_includes .= 'if( $("#field'.($i+1).'").attr("disabled") ){' . "\r\n";620 $b_includes .= 'picker' . ($i+1) . '.css("cursor","default");' . "\r\n";621 $b_includes .= 'picker' . ($i+1) . '.parent().next("td").find("img").css("cursor","default");' . "\r\n";622 $b_includes .= '}' . "\r\n";623 624}625 626$b_includes .= '});627</script>';628$xt->assign("report_name_preview",$_SESSION['webreports']['settings']['name']);629$xt->assign("b_includes", $b_includes);630$xt->assign("wr_pagestylepath", $wr_pagestylepath);631$templatefile = GetTemplateName("", "webreport3");632$xt->display($templatefile);633?>