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"));17if (strpos($_SESSION['webreports']['table_relations']['join_tables'], ",") !== false) {18 $arr_join_tables = array_slice(explode(",", $_SESSION['webreports']['table_relations']['join_tables']), 0, -1); 19}20$arr_join_tables[] = $_SESSION['webreports']['tables'][0];21 22include('include/xtempl.php');23$xt = new Xtempl();24 25if (@$_SESSION['webreports']['settings']['title'] != "") {26 $title=@$_SESSION['webreports']['settings']['title'];27 if(strlen($title)>25)28 $title=substr($title,25)."...";29 $xt->assign("report_title",", "."Title".": ".$title);30} else {31 $xt->assign("report_title","");32}33if (@$_SESSION['webreports']['tables'][0] != "") {34 $stable=@$_SESSION['webreports']['tables'][0];35 if(strlen($stable)>25)36 $stable=substr($stable,25)."...";37 38 $xt->assign("report_table",", "."Table".": ".$stable);39} else {40 $xt->assign("report_table","");41}42$xt->assign("b_is_report_save",($_SESSION['webreports']['tmp_active'] != "x"));43$xt->assign("b_is_report_name",($_SESSION['webreports']['settings']['name'] != ""));44$xt->assign("report_name",$_SESSION['webreports']['settings']['name']);45 46$h_includes = "";47$b_includes = "";48 49$h_includes .= '50 <link rel="stylesheet" href="'.GetRootPathForResources("include/css/dstyle.css").'" type="text/css">51 <link rel="stylesheet" href="'.GetRootPathForResources("include/css/jquery-ui.css").'" type="text/css">52 <link rel="stylesheet" href="'.GetRootPathForResources("include/fancybox/jquery.fancybox.css").'" type="text/css" media="screen">53 54 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.min.js").'"></script>55 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.dimensions.pack.js").'"></script>56 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.easing.js").'"></script>57 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.fancybox.pack.js").'"></script>58 <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery-ui.js").'"></script>59 <script type="text/javascript" src="'.GetRootPathForResources("include/js/json.js").'"></script>60'."\r\n";61 62$xt->assign("h_includes", $h_includes);63 64$fields = "";65for ($i=0; $i < count($arr_join_tables); $i++ ) {66 $t = $arr_join_tables[$i];67 $arr_fields = array();68 $arr_fields = WRGetNBFieldsList($t);69 for ($j=0; $j < count($arr_fields); $j++) 70 {71 $field=$arr_fields[$j];72 if(strlen($field)>25)73 $field=substr($field,25)."...";74 $fields .= "<option value=\"".runner_htmlspecialchars($t.".".$field)."\">".$t.".".$field."</option>";75 }76}77$xt->assign("fields", $fields);78 79$b_includes .= '80<script type="text/javascript">81var timeout = 200;82var closetimer = 0;83var relation_stack = 0;84 85$(document).ready(function(){86 $("a#sql_query").fancybox({87 fitToView: false,88 autoSize: false,89 width : 800,90 height : 550,91 overlayShow: true92 });93 $("a#preview").fancybox({94 fitToView: false,95 autoSize: false,96 width : 820,97 height : 660,98 overlayShow: true99 });100';101 $b_includes .= alertDialog();102 $b_includes .= '103 function collect_input_data() {104 var output = {};105 output.where_condition = [];106 var idx=0;107 $(".condition-row").each(function(){108 if ($(this).find("td.field_value select").val() != "-1" && $(this).find("td.filter_value input").val() != "" && $(this).find("td.field_value select").val() != undefined && $(this).find("td.filter_value input").val() != undefined) 109 {110 output.where_condition[idx] = {};111 $(this).find("input:text,select").each(function(){112 output.where_condition[idx][$(this).attr("id")] = $(this).val();113 });114 idx++;115 }116 });117 118 return JSON.stringify(output);119 }120 121 $("#sqlbtn").click(function(){122 var output = collect_input_data();123 124 $.ajax({125 type: "POST",126 url: "'.GetTableLink("save-state").'",127 data: {128 name: "where_condition",129 web: "webreports",130 str_xml: output,131 rnd: (new Date().getTime())132 },133 success: function(msg){134 if ( msg == "OK" ) {135 $("#sql_query").click();136 } else {137 $("#alert").html("<p>"+msg+"</p>").dialog("open");138 }139 }140 });141 });142 143 for (var i=1; i < 10; i++) {144 var tr_elem = $(".condition-row").eq(0).clone();145 $(tr_elem).find("input, select").each(function(){this.value="";});146 $(tr_elem).attr("id","cond_row_"+i);147 $(tr_elem).find("input, select").each(function(){148 this.disabled = true;149 });150 $("#table_wh").append(tr_elem);151 $(tr_elem).hide();152 }153 154 $(".field_value select").change(function(){155 if ($(this).val() == "-1") 156 {157 $(this).parents("tr:first").find("input").each(function(){158 $(this).val("");159 });160 $(this).parents("tr:first").find("select").each(function()161 {162 var oldVal=$(this).val();163 $(this).val("-1");164 if(oldVal && oldVal!="-1")165 $(this).trigger("change");166 });167 $(this).parents("tr:first").hide();168 }169 else170 {171 enableRow($(this).parents("tr:first").get(0),true);172 showNewRow();173 }174 }); 175 176/*177 $(".filter_value").keyup(function(){178 if ($("input",this).val() == "") {179 $(this).parent("tr").next().find("input, select").each(function(){180 this.disabled = true;181 });182 $(this).parent("tr").next().hide(); 183 } else {184 $(this).parent("tr").next().find("input, select").each(function(){185 this.disabled = false;186 });187 $(this).parent("tr").next().show(); 188 }189 }); 190*/ 191 $("#row2")192 .css("cursor", "default")193 .css("font-weight", "bold");194 195 $("td[id^=row]").mouseover(function(){196 for(var i=0; i<=11; i++) {197 if(i == $(this).attr("id").replace("row", "")) {198 $("td[id=row" + i + "]").css("background-color","#92BEEB");199 }200 else {201 $("td[id=row" + i + "]").css("background-color","#F4F7FB");202 }203 }204 });205 206'."\r\n";207 208$b_includes .= JumpTo();209 210if (count(GetUserGroups()) < 2 || isset( $_SESSION['webreports']['settings']['status'] )211 && $_SESSION['webreports']['settings']['status'] == "private" ) {212 $b_includes .= '$("td[id=row9]").hide();'."\r\n";213}214if($wr_is_standalone)215 $b_includes .= '$("td[id=row11]").hide();'."\n";216 217if ($_SESSION['webreports']['settings']['title'] == "") {218 $b_includes .= '219 for (var i=2; i<=9; i++){220 $("td[id=row" + i + "]").hide();221 };222 '."\r\n";223}224if($_SESSION['webreports']['group_fields'][count($_SESSION['webreports']['group_fields'])-1]["cross_table"]=="true")225 $b_includes .= '$("#row5,#row6").hide();'."\r\n";226 227$rLinks = "var rlinks = {};\r\n";228for($ri = 0; $ri < 10; $ri++)229 $rLinks.= "rlinks['".$ri."'] = '".GetTableLink("webreport".$ri)."';\r\n";230 231$b_includes .= '232 $("#nextbtn, #backbtn, td[id^=row], #savebtn, #saveasbtn, #previewbtn").click(function(){233 234 var flag = true;235/*236 $(".filter_value input:enabled").each(function(){237 if ($(this).val() == "" && $(this).parents("tr").find(".field_value select").val() != "-1") {238 flag = false;239 }240 });241 if (!flag) {242 $("#alert").html("<p>Complete Filter field for selected column</p>").dialog("open");243 return;244 }245*/246 var URL = "'.GetTableLink("webreport").'";247 '.$rLinks.'248 if( $(this).attr("id") == "nextbtn" )249 URL = "'.GetTableLink("webreport3").'";250 if( $(this).attr("id") == "backbtn" )251 URL = "'.GetTableLink("webreport1").'";252 if( $(this).attr("id") == "saveasbtn" )253 URL = "'.GetTableLink("webreport8", "", "saveas=1").'"; 254 if( $(this).attr("id").substr(0,3)=="row" && $(this).attr("id") != "row2" )255 URL = rlinks[this.id.replace(\'row\',\'\')];256 if( $(this).attr("id") == "row10" )257 URL = "'.GetTableLink("webreport").'";258 if( $(this).attr("id") == "row11" )259 URL = "'.GetTableLink("menu").'";260 if ( $(this).attr("id") == "row7" )261 URL = "'.GetTableLink("dreport").'?edit=style&rname='.@$_SESSION['webreports']['settings']['name'].'"; 262 263 var output = collect_input_data();264 thisid=$(this).attr("id");265 var_save=0;266 if( this.id == "savebtn")267 var_save=1;268 if( $(this).attr("id") == "savebtn" || $(this).attr("id") == "previewbtn" ) {269 id=$(this).attr("id");270 $.ajax({271 type: "POST",272 url: "'.GetTableLink("save-state").'",273 data: {274 save: var_save,275 web: "webreports",276 name: "where_condition",277 str_xml: output,278 rnd: (new Date().getTime())279 },280 success: function(msg){281 if ( msg == "OK" ) {282 if(id=="savebtn")283 {284 $("#alert")285 .html("<p>'."Report Saved".'</p>")286 .dialog("option", "close", function(){287 window.location = "'.GetTableLink("webreport").'";288 })289 .dialog("open");290 }291 else292 $("#preview").click();293 } else {294 $("#alert").html("<p>"+msg+"</p>").dialog("open");295 }296 },297 error: function() {298 $("#alert").html("<p>'."Some problems appear during saving".'</p>").dialog("open");299 }300 });301 }302 303 304 if($(this).attr("id") !="row2" && $(this).attr("id") !="savebtn" && $(this).attr("id") !="previewbtn") {305 $.ajax({306 type: "POST",307 url: "'.GetTableLink("save-state").'",308 data: {309 name: "where_condition",310 web: "webreports",311 str_xml: output,312 rnd: (new Date().getTime())313 },314 success: function(msg){315 if ( msg == "OK" ) {316 window.location = URL;317 } else {318 $("#alert").html("<p>"+msg+"</p>").dialog("open");319 if( thisid == "row10" || thisid == "row11" )320 window.location=URL; 321 322 }323 }324 });325 }326 });327});328 329function showNewRow()330{331 var lastDisplayed=undefined;332 var existsEmpty=false;333 $("tr.condition-row").each(function() {334 if($("select[name=field_opt]",this).val()!="-1")335 return;336 if($(this).css("display")!="none")337 existsEmpty=true;338 });339 if(existsEmpty)340 return;341 var firstHidden=$("select[name=field_opt][value=-1]:first").parents("tr").get(0);342 343// append it to the end 344 $("#table_wh").append(firstHidden);345 enableRow(firstHidden,true);346}347 348function enableRow(tr,enable)349{350 $(tr).show();351 $("input, select",tr).each(function(){352 if(this.name=="field_opt")353 this.disabled=false;354 else if ((this.name == "group_by_value" || this.name == "having_value")) 355 this.disabled=!enable || !$("#group_by_toggle")[0].checked;356 else357 this.disabled = !enable;358 });359 if($("td.sort_dir select",tr).val() && $("td.sort_dir select",tr).val()!="-1")360 $("td.sort_order select",tr).show();361 else362 $("td.sort_order select",tr).hide();363 364}365 366</script>'."\r\n";367 368$arr = $_SESSION['webreports']['where_condition'];369if ( !empty( $arr ) ){370 $b_includes .= "<script type='text/javascript'>371 $(document).ready(function(){"."\r\n";372 373 for ($i=0; $i < count($arr); $i++) {374 $b_includes .= "375 tr_elem = $('.condition-row').eq('".$i."');376 $(tr_elem).show();377 $(tr_elem).find('input, select').each(function(){378 this.disabled = false;379 });380 $(tr_elem).find('select#field_opt').val('".jsreplace($arr[$i]["field_opt"])."');381 $(tr_elem).find('input#filter_value').val('".jsreplace($arr[$i]["filter_value"])."');382 $(tr_elem).find('input#first_or_value').val('".jsreplace($arr[$i]["first_or_value"])."');383 $(tr_elem).find('input#second_or_value').val('".jsreplace($arr[$i]["second_or_value"])."');384 $(tr_elem).find('input#third_or_value').val('".jsreplace($arr[$i]["third_or_value"])."');385 "."\r\n"; 386 }387 388 $b_includes .= '389 tr_elem = $(".condition-row").eq('.count($arr).');390 $(tr_elem).show();391 $(tr_elem).find("input, select").each(function(){392 this.disabled = false;393 });394 });395 </script>'."\r\n";396}397$xt->assign("report_name_preview",$_SESSION['webreports']['settings']['name']);398$xt->assign("b_includes", $b_includes);399$xt->assign("wr_pagestylepath", $wr_pagestylepath);400$templatefile = GetTemplateName("", "webreport2");401$xt->display($templatefile);402?>