CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
webreport.php506 linesDownload Raw Back to public
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 9if( !Security::getUserName() )10{11	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];12	header("Location: ".GetTableLink("login", "", "message=expired"));13	return;14}15 16if(isLoggedAsGuest())17{18	$_SESSION["MyURL"]=$_SERVER["SCRIPT_NAME"]."?".$_SERVER["QUERY_STRING"];19}20 21 22$cMaxTitleLength=30;23 24$_SESSION["back_to_menu"]="true";25$_SESSION['webreports_oldname']="";26include('include/xtempl.php');27$xt = new Xtempl();28 29$h_includes = "";30$b_includes = "";31 32$h_includes .= '33	<link rel="stylesheet" href="'.GetRootPathForResources("include/css/jquery-ui.css").'" type="text/css">34	<link rel="stylesheet" href="'.GetRootPathForResources("include/css/dstyle.css").'" type="text/css">35	36	<script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.min.js").'"></script>37	<script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery.dimensions.pack.js").'"></script>38    <script type="text/javascript" src="'.GetRootPathForResources("include/js/jquery-ui.js").'"></script>39'."\r\n";40 41$xt->assign("h_includes", $h_includes);42$arr_UserGroups = GetUserGroup();43 44$b_includes .= '<script type="text/javascript">'."\r\n";45$b_includes .= '46$(document).ready(function(){47	$("#alert").dialog({48		title: "Message",49		draggable: false,50		resizable: false,51		bgiframe: true,52		autoOpen: false,53		modal: true,54		buttons: {55			Ok: function() {56				$(this).dialog("close");57			}58		}59	});60 61	$(".view").each(function(){62		var type = $(this).attr("type");63		var scriptName = (type == "report") ? "'.GetTableLink("dreport").'?rname=" : "'.GetTableLink("dchart").'?cname=";64		var name = $(this).parent("span").attr("id");65		this.href = scriptName + name;66	});67	68	69	$(".del").click(function(){70		var type = $(this).attr("type"),71			scriptName = (type == "report") ? "dreport" : "dchart",72			name = $(this).parent("span").attr("id"),73			title = $(this).parent("span").attr("title");74			75		var mess = (type == "report") ? "'. "Do you really want to delete report %s ?".'" : "'."Do you really want to delete chart %s ?".'";';76		$b_includes .= 'mess=mess.replace("%s",title);77		$("#alert")78			.html("<p>"+mess+"</p>")79			.dialog("option", "buttons", {80				"'."No".'": function() { $(this).dialog("close"); },'.81				'"'. "Delete";82 83				$b_includes .= '": function() {84					$.ajax({85						type: "POST",86						url: "'.GetTableLink("save-state").'",87						data: {88							del: 1,89							web: "web"+type+"s",90							name: ""+name,91							owner: (type == "report") ? reportsList[name]["owner"] : chartsList[name]["owner"],92							rnd: (new Date().getTime())93						},94						success: function(msg){95							if ( msg == "OK" ) {96								window.location.reload();97							} else {98								$("#alert").html("<p>"+msg+"</p>").dialog("open");99							}100						},101						error: function() {102							$("#alert").html("<p>'."Try again later".103							'</p>").dialog("open");104						}105					});				106				}107			})108			.dialog("open");		109	});110	111	$("#return_app").click(function(){112		window.location = "'.GetTableLink("menu").'";113    });';114	115	if(!pre8count($arr_UserGroups))116	{117		$b_includes .= '$("#admin_sql").click(function(){118			$("#alert").dialog("option","title","'."Enter password".119			'");120			$("#alert")121				.html("'."Password".122				':&nbsp;<input type=password id=admin_password size=30 value=\"\">")123				.dialog("option", "buttons", {124					"'."Cancel".125					'": function() { $(this).dialog("close"); },126					"'."OK".127					'": function() {128						$.ajax({129							type: "POST",130							url: "'.GetTableLink("save-admin").'",131							data: {132								name: "password",133								password: $("#admin_password").val(),134								rnd: (new Date().getTime())135							},136							success: function(msg){137								if ( msg == "OK" ) {138									window.location="'.GetTableLink("webreport_sql").'";139								} else {140									$("#alert").dialog("option", "buttons", {"'."Cancel".141										'": function() { $(this).dialog("close");}});142									$("#alert").html("<p>'."Invalid password".143									'</p>").dialog("open");144								}145							}146						});				147					}148				})149				.dialog("open");	150		});';151	}152	else153	{154		$b_includes .= '$("#admin_sql").click(function(){155			window.location = "'.GetTableLink("webreport_sql").'";156		});';157	}158	159	if($wr_is_standalone)160		$b_includes .= '$("#users_list").click(function(){161			window.location = "'.GetTableLink("webreport_users_list").'";162		});';163 164	if(!pre8count($arr_UserGroups))165	{166		$b_includes .= '$("#admin_page").click(function(){167			$("#alert").dialog("option","title","'."Enter password".168			'");169			$("#alert")170				.html("'."Password".171				':&nbsp;<input type=password id=admin_password size=30 value=\"\">")172				.dialog("option", "buttons", {173					"'."Cancel".174					'": function() { $(this).dialog("close"); },175					"'."OK".176					'": function() {177						$.ajax({178							type: "POST",179							url: "'.GetTableLink("save-admin").'",180							data: {181								name: "password",182								password: $("#admin_password").val(),183								rnd: (new Date().getTime())184							},185							success: function(msg){186								if ( msg == "OK" ) {187									window.location="'.GetTableLink("webreport_admin").'";188								} else {189									$("#alert").dialog("option", "buttons", {"'."Cancel".190										'": function() { $(this).dialog("close");}});191									$("#alert").html("<p>'."Invalid password".192									'</p>").dialog("open");193								}194							}195						});				196					}197				})198				.dialog("open");	199		});';200	}201	else202	{203		$b_includes .= '$("#admin_page").click(function(){204		window.location = "'.GetTableLink("webreport_admin").'";});';205	}206 207	$b_includes .= '$(".edit").click(function(){208		var type = $(this).attr("type");209		var scriptName = (type == "report") ? "'.GetTableLink("webreport0").'" : "'.GetTableLink("webchart0").'";210		211		$.ajax({212			type: "POST",213			url: "'.GetTableLink("get-state").'",214			data: {215				type: "open",216				web: "web"+type+"s",217				name: $(this).parent("span").attr("id"),218				rnd: (new Date().getTime())219			},220			success: function(msg){221				if ( msg == "OK" ) {222					window.location = scriptName;223				} else {224					$("#alert").html("<p>"+msg+"</p>").dialog("open");225				}226			},227			error: function() {228				$("#alert").html("<p>'."Try again later".229				'</p>").dialog("open");230			}231		});232	});233 234	$("#report_createbtn, #chart_createbtn").click(function(){235		var type = $(this).attr("wtype");236		var scriptName = (type == "report") ? "'.GetTableLink("webreport0").'" : "'.GetTableLink("webchart0").'";237	238		$.ajax({239			type: "POST",240			url: "'.GetTableLink("get-state").'",241			data: {242				type: "new",243				web: "web"+type+"s",244				rnd: (new Date().getTime())245			},246			success: function(msg){247				if ( msg == "OK" ) {248					window.location = scriptName;249				} else {250					$("#alert").html("<p>"+msg+"</p>").dialog("open");					251				}252			},253			error: function() {254				$("#alert").html("<p>'."Try again later".255				'</p>").dialog("open");				256			}257		});258	});259});'."\r\n";260 261$shared_reports = "";262$private_reports = "";263$shared_charts = "";264$private_charts = "";265 266$arr_reports = array();267$arrPrivateReports = array();268$arrSharedReports = array();269$arr_charts = array();270$arrPrivateCharts = array();271$arrSharedCharts = array();272 273$arr_reports = wrGetEntityList( WR_REPORT );274foreach ( $arr_reports as $rpt ) {275	if ( (trim($rpt["owner"]) != Security::getUserName() || trim($rpt["owner"]) == "") && $rpt["status"]=="public") {276		$arrSharedReports[] = $rpt;277	} elseif ( trim($rpt["owner"]) == Security::getUserName() ) {278		$arrPrivateReports[] = $rpt;279	}280}281 282$arr_charts = wrGetEntityList( WR_CHART );283foreach ( $arr_charts as $chart ) {284	if (( trim($chart["owner"]) != Security::getUserName() || trim($chart["owner"]) == "" ) && $chart["status"]=="public") {285		$arrSharedCharts[] = $chart;286	} elseif ( trim($chart["owner"]) == Security::getUserName() ) {287		$arrPrivateCharts[] = $chart;288	}289}290 291$arr_tables_db = DBGetTablesListByGroup("db");292$arr_tables_project = DBGetTablesListByGroup("project");293$arr_tables_custom = DBGetTablesListByGroup("custom");294if( Security::permissionsAvailable() ) {295	foreach ( $arrSharedReports as $rpt ) {296		if ( $rpt["status"] == "public" && ($rpt['view'] || $rpt['edit'])) {297			$shared_reports .= '<div style="margin-bottom:5px;">';298			$shared_reports .= '<span class="ritem" id="' . $rpt['name'] . '" title="'.runner_htmlspecialchars($rpt['title']).'">';299			$shared_reports .= ( strlen( $rpt['title'] ) > $cMaxTitleLength+5 ) ? substr( $rpt['title'], 0, $cMaxTitleLength  ) . "..." : $rpt['title'];300		// if @BUILDER.bDynamicPermissions301			if ( $rpt['view'] ) {302				$shared_reports .= '<a class="action view" type="report" href="#">['."View".']</a>';303			}304			if ( $rpt['edit'] ) {305				if(pre8count($arr_tables_db) || pre8count($arr_tables_project) || pre8count($arr_tables_custom))	306					$shared_reports .= '<a class="action edit" type="report" href="#">['."Edit".']</a>';307				$shared_reports .= '<a class="action del" type="report" href="#">['."Delete".']</a>';308			}309			$shared_reports .= '</span>';310			$shared_reports .= '</div>'."\r\n";311		}312	}313	foreach ( $arrSharedCharts as $chart ) {314		if ( $chart["status"] == "public" && ($chart['view'] || $chart['edit']) ) {315			$shared_charts .= '<div style="margin-bottom:5px;">';316			$shared_charts .= '<span class="ritem" id="' . $chart['name'] . '" title="'.runner_htmlspecialchars($chart['title']).'">';317			$shared_charts .= ( strlen( $chart['title'] ) > $cMaxTitleLength+5 ) ? substr( $chart['title'], 0, $cMaxTitleLength  ) . "..." : $chart['title'];318		// if @BUILDER.bDynamicPermissions319			if ( $chart['view'] ) {320				$shared_charts .= '<a class="action view" type="chart" href="#">['."View".']</a>';321			}322			if ( $chart['edit'] ) {323				if(pre8count($arr_tables_db) || pre8count($arr_tables_project) || pre8count($arr_tables_custom))	324					$shared_charts .= '<a class="action edit" type="chart" href="#">['."Edit".']</a>';325				$shared_charts .= '<a class="action del" type="chart" href="#">['."Delete".']</a>';326			}327			$shared_charts .= '</span>';		328			$shared_charts .= '</div>'."\r\n";329		}330	}331} else {332	foreach ( $arrSharedReports as $rpt ) {333		$shared_reports .= '<div style="margin-bottom:5px;">';334		$shared_reports .= '<span class="ritem" id="' . $rpt['name'] . '" title="'.runner_htmlspecialchars($rpt['title']).'">';335		$shared_reports .= ( strlen( $rpt['title'] ) > $cMaxTitleLength+5 ) ? substr( $rpt['title'], 0, $cMaxTitleLength  ) . "..." : $rpt['title'];336		$shared_reports .= '<a class="action view" type="report" href="#">['."View".']</a>';337		/*338		 * If there's no login page339		 */340		if(trim($rpt["owner"]) == Security::getUserName() )341		{		342			if(pre8count($arr_tables_db) || pre8count($arr_tables_project) || pre8count($arr_tables_custom))	343				$shared_reports .= '<a class="action edit" type="report" href="#">['."Edit".']</a>';344			$shared_reports .= '<a class="action del" type="report" href="#">['."Delete".']</a>';345		}346		$shared_reports .= '</span>';347		$shared_reports .= '</div>'."\r\n";348	}349	foreach ( $arrSharedCharts as $chart ) {350		$shared_charts .= '<div style="margin-bottom:5px;">';351		$shared_charts .= '<span class="ritem" id="' . $chart['name'] . '" title="'.runner_htmlspecialchars($chart['title']).'">';352		$shared_charts .= ( strlen( $chart['title'] ) > $cMaxTitleLength+5 ) ? substr( $chart['title'], 0, $cMaxTitleLength  ) . "..." : $chart['title'];353		$shared_charts .= '<a class="action view" type="chart" href="#">['."View".']</a>';354		/*355		 * If there's no login page356		 */357		if(trim($chart["owner"]) == Security::getUserName() )358		{359			if(pre8count($arr_tables_db) || pre8count($arr_tables_project) || pre8count($arr_tables_custom))	360				$shared_charts .= '<a class="action edit" type="chart" href="#">['."Edit".']</a>';361			$shared_charts .= '<a class="action del" type="chart" href="#">['."Delete".']</a>';362		}363		$shared_charts .= '</span>';	364		$shared_charts .= '</div>'."\r\n";365	}366}367 368foreach ( $arrPrivateReports as $rpt ) {369	if ( $rpt["status"] == "public" ) {370		$private_reports .= '<div style="margin-bottom:5px;">';371		$private_reports .= '<span class="ritem" id="' . $rpt['name'] . '" title="'.runner_htmlspecialchars($rpt['title']).'">';372				$private_reports .= '<img src="images/unlock16.png" title="'."Public report".'"/>';373		$private_reports .= ( strlen( $rpt['title'] ) > $cMaxTitleLength+5 ) ? substr( $rpt['title'], 0, $cMaxTitleLength  ) . "..." : $rpt['title'];374		$private_reports .= '<a class="action view" type="report" href="#">['."View".']</a>';375		if(pre8count($arr_tables_db) || pre8count($arr_tables_project) || pre8count($arr_tables_custom))	376			$private_reports .= '<a class="action edit" type="report" href="#">['."Edit".']</a>';377		$private_reports .= '<a class="action del" type="report" href="#">['."Delete".']</a>';378		$private_reports .= '</span>';379		$private_reports .= '</div>'."\r\n";380	} else {381		$private_reports .= '<div style="margin-bottom:5px;">';382		$private_reports .= '<span class="ritem" id="' . $rpt['name'] . '" title="'.runner_htmlspecialchars($rpt['title']).'">';383				$private_reports .= '<img src="images/lock16.png" title="'."Private report".'"/>';384		$private_reports .= ( strlen( $rpt['title'] ) > $cMaxTitleLength+5 ) ? substr( $rpt['title'], 0, $cMaxTitleLength  ) . "..." : $rpt['title'];385		$private_reports .= '<a class="action view" type="report" href="#">['."View".']</a>';386		if(pre8count($arr_tables_db) || pre8count($arr_tables_project) || pre8count($arr_tables_custom))	387			$private_reports .= '<a class="action edit" type="report" href="#">['."Edit".']</a>';388		$private_reports .= '<a class="action del" type="report" href="#">['."Delete".']</a>';389		$private_reports .= '</span>';390		$private_reports .= '</div>'."\r\n";391	}392}393 394foreach ( $arrPrivateCharts as $chart ) {395	if ( $chart["status"] == "public" ) {396		$private_charts .= '<div style="margin-bottom:5px;">';397		$private_charts .= '<span class="ritem" id="' . $chart['name'] . '" title="'.runner_htmlspecialchars($chart['title']).'">';398				$private_charts .= '<img src="images/unlock16.png" title="'."Public chart".'"/>';399		$private_charts .= ( strlen( $chart['title'] ) > $cMaxTitleLength+5 ) ? substr( $chart['title'], 0, $cMaxTitleLength  ) . "..." : $chart['title'];400		$private_charts .= '<a class="action view" type="chart" href="#">['."View".']</a>';401		if(pre8count($arr_tables_db) || pre8count($arr_tables_project) || pre8count($arr_tables_custom))	402			$private_charts .= '<a class="action edit" type="chart" href="#">['."Edit".']</a>';403		$private_charts .= '<a class="action del" type="chart" href="#">['."Delete".']</a>';404		$private_charts .= '</span>';		405		$private_charts .= '</div>'."\r\n";406	} else {407		$private_charts .= '<div style="margin-bottom:5px;">';408		$private_charts .= '<span class="ritem" id="' . $chart['name'] . '" title="'.runner_htmlspecialchars($chart['title']).'">';409				$private_charts .= '<img src="images/lock16.png" title="'."Private chart".'"/>';410		$private_charts .= ( strlen( $chart['title'] ) > $cMaxTitleLength+5 ) ? substr( $chart['title'], 0, $cMaxTitleLength  ) . "..." : $chart['title'];411		$private_charts .= '<a class="action view" type="chart" href="#">['."View".']</a>';412		if(pre8count($arr_tables_db) || pre8count($arr_tables_project) || pre8count($arr_tables_custom))	413			$private_charts .= '<a class="action edit" type="chart" href="#">['."Edit".']</a>';414		$private_charts .= '<a class="action del" type="chart" href="#">['."Delete".']</a>';415		$private_charts .= '</span>';		416		$private_charts .= '</div>'."\r\n";417	}418}419 420$xt->assign("css_height_report","height:100px;");421$xt->assign("css_height_chart","height:100px;");422if ((pre8count($arrPrivateReports)>6 || pre8count($arrSharedReports)>6) || (pre8count($arrPrivateCharts)>6 || count ($arrSharedCharts)>6)) {423	$xt->assign("css_height_report","height:200px;");424	$xt->assign("css_height_chart","height:200px;");425}426 427$b_includes .= 'var reportsList = new Array();'."\r\n";428$b_includes .= 'var chartsList = new Array();'."\r\n";429 430foreach ($arr_reports as $rpt) {431	$b_includes .= 'reportsList["' . $rpt['name'] . '"] = new Array();'."\r\n";432	$b_includes .= 'reportsList["' . $rpt['name'] . '"]["status"] = "' . $rpt['status'] . '";'."\r\n";433	$b_includes .= 'reportsList["' . $rpt['name'] . '"]["owner"] = "' . $rpt['owner'] . '";'."\r\n";434}435 436foreach ($arr_charts as $chart) {437	$b_includes .= 'chartsList["' . $chart['name'] . '"] = new Array();'."\r\n";438	$b_includes .= 'chartsList["' . $chart['name'] . '"]["status"] = "' . $chart['status'] . '";'."\r\n";439	$b_includes .= 'chartsList["' . $chart['name'] . '"]["owner"] = "' . $chart['owner'] . '";'."\r\n";440}441 442$b_includes .= '</script>'."\r\n";443$xt->assign("b_includes", $b_includes);444 445if(isWRAdmin() || !pre8count($arr_UserGroups))446{447	$create_butt="<a id=\"admin_page\" class=\"rnr-button\" onmouseover=\"this.focus();\" name=\"admin_page\" href=\"#\">"."Admin Area"."</a>";448	$xt->assign("admin_page", $create_butt);449}450if(!$wr_is_standalone)451{452	$create_butt="<a id=\"return_app\" class=\"rnr-button\" onmouseover=\"this.focus();\" name=\"return_app\" href=\"#\">"."Back to main application"."</a>";453	$xt->assign("back_to_app", $create_butt);454}455if($wr_is_standalone && isWRAdmin())	456{457	$create_butt="<a id=\"users_list\" class=\"rnr-button\" onmouseover=\"this.focus();\" name=\"users_list\" href=\"#\">"."Users list"."</a>";458	$xt->assign("users_list_page", $create_butt);459}460if( Security::hasLogin() ) {461	if(isLoggedAsGuest())462	{463		$strLogin="<A class=tablelinks href=\"".GetTableLink("login")."\">Log in</A>";464	} 465	else 466	{467		$strLogin="Logged on as"." <b>".$_SESSION["UserName"]."</b>&nbsp;&nbsp;&nbsp;<A class=tablelinks href=\"".GetTableLink("login")."?a=logout\">"."Log out"."</A>";468	}469 470	$xt->assign("login_mess",$strLogin);		471}472 473if(isWRAdmin() || !pre8count($arr_UserGroups))474{475	$create_butt="<a id=\"admin_sql\" class=\"rnr-button\" onmouseover=\"this.focus();\" name=\"admin_sql\" href=\"#\">"."Custom SQL"."</a>";476	$xt->assign("admin_sql", $create_butt);477}	478else	479	$xt->assign("admin_sql",false);480	481if(pre8count($arr_tables_db) || pre8count($arr_tables_project) || pre8count($arr_tables_custom))	482{                 483	$create_butt="<a id=\"report_createbtn\" class=\"rnr-button\" onmouseover=\"this.focus();\" name=\"report_createbtn\" wtype=\"report\" href=\"#\">"."Create Report"."</a>";484    $create_butt.="<a id=\"chart_createbtn\" class=\"rnr-button\" onmouseover=\"this.focus();\" name=\"chart_createbtn\" wtype=\"chart\" href=\"#\">"."Create chart"."</a>";485	$xt->assign("create_report_chart", $create_butt);486}487else488{	489	if($wr_is_standalone && !isWRAdmin())490		$xt->assign("create_report_chart", "<b>"."You do not have permissions to create reports and charts. Contact administrator in this regard."."</b>");491}492 493if( Security::isGuest() && $wr_is_standalone)494	$xt->assign("create_report_chart", "<b>"."You do not have permissions to create reports and charts. Contact administrator in this regard."."</b>");495 496 497	498$xt->assign("wr_pagestylepath", $wr_pagestylepath);499$xt->assign("shared_reports", $shared_reports);500$xt->assign("private_reports", $private_reports);501$xt->assign("shared_charts", $shared_charts);502$xt->assign("private_charts", $private_charts);503 504$templatefile = GetTemplateName("", "webreport");505$xt->display($templatefile);506?>