<?php
ob_start();
if(!(is_readable(realpath(dirname(__FILE__)).'/include/includesroutines.inc'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__)).'/include/includesroutines.inc');
} else {
	include_once(realpath(dirname(__FILE__)).'/include/includesroutines.inc');
}

//STU
if(!(is_readable(realpath(dirname(__FILE__)).'/include/bsservice.inc'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__)).'/include/bsservice.inc');
} else {
	include_once(realpath(dirname(__FILE__)).'/include/bsservice.inc');
}

function bsreportParser($buff, $cn, $oguid, $skbranch, $userids, $useRht, $modepr, $isMainBranch, $contlng, $contlngid, $selfeventClassText ){
	$lpos = strpos($buff, '<bsportal:report');
	while(!($lpos === FALSE )){
		$rpos = strpos($buff, '</bsportal:report>', $lpos + 16); // slide from start tag <bsportal:report
		$linksource = substr($buff, $lpos, $rpos - $lpos + 18);
		$link = str_replace('&', '&amp;', $linksource );
		$linkHtml = "";
		$patern = substr($link, 0, 4);
		$xmlstr = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>'.str_replace('bsportal:report', 'bsrep', $link);
		$xml = simplexml_load_string($xmlstr);
		$title = $xml;
		$elem = $xml->xpath('//bsrep');
		$i_guid = $oguid ;
		if (isset($elem[0]["oguid"])) {
			$i_guid = $elem[0]["oguid"];
		}
		$i_rguid = '';
		if ( isset ($elem[0]["rguid"])){
			$i_rguid = $elem[0]["rguid"];
		}
		if (strpos($link, 'coords="') === FALSE){
			if ( ( $useRht == 0 && (db_isObjectExits($cn, $i_guid, $skbranch) && (($i_rguid == '') || db_isObjectsReportsExits($cn, $i_guid, $i_rguid, $skbranch))))
				|| (  $useRht == 1 && db_isObjectExits($cn, $i_guid, $skbranch) /*61786*/ && (db_getUserRightsToObject($cn, $userids, $i_guid, $skbranch) && (($i_rguid == '') || (db_getUserRightsToReport($cn, $userids, $i_rguid, $i_guid, $contlngid, $skbranch)))))) {
				$linkHtml .= '<a class="self-report-link '.$selfeventClassText.'" href="';
				if ($modepr && $isMainBranch) {
					$linkHtml .= getCurPageSubFolders().'/businessmodel.php?'.$contlng.'&oguid='.$i_guid.($i_rguid == '' ? '' : '&rguid='.$i_rguid);
				} else  {
					$linkHtml .= "javascript:parent.postMessage('";
					if ( $i_guid != '' ) {
						$linkHtml .= "oguid=".$i_guid;
					}
					if ( $i_guid != '' && $i_rguid != '' ) {
						$linkHtml .= "&";
					}
					if ( $i_rguid != '' ) {
						$linkHtml .= "rguid=".$i_rguid;
					}
					$linkHtml .= "','*');";
				}
				$linkHtml .= '">';
				$linkHtml .= $title;
				$linkHtml .= '</a>';
			} else {
				$linkHtml .= $title;
			}
		} else {
			if ( ( $useRht == 0 && (db_isObjectExits($cn, $i_guid, $skbranch) && (($i_rguid == '') || db_isObjectsReportsExits($cn, $i_guid, $i_rguid, $skbranch))))
				|| (  $useRht == 1 && db_isObjectExits($cn, $i_guid, $skbranch) /*61786*/ && (db_getUserRightsToObject($cn, $userids, $i_guid, $skbranch) && (($i_rguid == '') || (db_getUserRightsToReport($cn, $userids, $i_rguid, $i_guid, $contlngid, $skbranch)))))) {
					$linkHtml .= '<area shape="rect" coords="';
					$linkHtml .= $elem[0]["coords"].'" ';
					$linkHtml .= ' href="';
				if ($modepr && $isMainBranch) {
					$linkHtml .= getCurPageSubFolders().'/businessmodel.php?'.$contlng.'&oguid='.$i_guid.($i_rguid == '' ? '' : '&rguid='.$i_rguid);
				} else  {
					$linkHtml .= "javascript:parent.postMessage('";
					if ( $i_guid != '' ) {
						$linkHtml .= "oguid=".$i_guid;
					}
					if ( $i_guid != '' && $i_rguid != '' ) {
						$linkHtml .= "&";
					}
					if ( $i_rguid != '' ) {
						$linkHtml .= "rguid=".$i_rguid;
					}
					$linkHtml .= "','*');";
				}
				$linkHtml .= '" alt=" ';
				$linkHtml .= $title;
				$linkHtml .= '" /> ';
			}
		}
		$buff = str_replace($linksource, $linkHtml, $buff);
		$lpos = strpos($buff, '<bsportal:report');
	}
	return $buff;
}

checkUserAndRedirectToLogin();
$cn = db_connect();
if (isset($_REQUEST['lang']))
{
	$lng = '&lang='.$_REQUEST['lang'];
	$contlngid = db_getLanguageID($cn, $_REQUEST['lang']);
	$contlng = $lng;
	$contlngid = $contlngid;
} else {
	$contlng = '&lang='.db_getLanguageShortByID($cn, $_SESSION['user_idlanguagecontent']);
	$contlngid = $_SESSION['user_idlanguagecontent'];
}
session_write_close();
$isMainBranch = false;
if (isset($_REQUEST['idbranch'])) {
	$idbranch = $_REQUEST['idbranch'];
	$skbranch = db_getSKBranch($cn,$idbranch);	
} else if (isset($_REQUEST['skbranch'])) {
	$skbranch = $_REQUEST['skbranch'];
	$idbranch = db_getIDBranch($cn, $skbranch );	
} else {
	$isMainBranch = true;
	$skbranch = db_getMainSKBranch($cn);
	$idbranch = db_getMainIDBranch($cn);	
}

if  (!isset($_REQUEST['oguid']) || !db_isObjectExits($cn, $_REQUEST['oguid'], $skbranch)) {
	header("Location: ".getCurPageURLWO()."/pagenotfound.php?url=".getCurPageWithEncodeParams());
	ob_end_flush();
	exit;
}

//59836
$selfeventClassText = (isset($_REQUEST['safeLinks']) ? "self-event" : "");

if (!$isMainBranch) {
	$isMainBranch = $skbranch == db_getMainSKBranch($cn);
}

$useRht = getSetting('portal','useRights', 0);
if ( $useRht == 1 && !IsUserLogin()){
	header("Location: ".getCurPageURLWO()."/login.php?returl=".getCurPageWithEncodeParams());
	ob_end_flush();
	exit;
} else {
	header("Content-Type: text/html; charset=UTF-8"); 
	$flroot = getSetting('storage','fileroot',realpath(dirname(__FILE__)).'/data/');
	$userids = GetUserIDs();
	$oguid = $_REQUEST['oguid'];
	$rguid = null;
	if (isset($_REQUEST['rguid'])) {
		$rguid = $_REQUEST['rguid'] ;
	} else {
		$trSt = db_getReportsToObject($cn, $oguid , $userids, $contlngid, $skbranch);
		if (sizeof($trSt) > 0 ) {
			$rguid = $trSt[0]['r_guid'];
		}
	}

	$reportLangID = db_getReportIDLanguage($cn, $oguid, $rguid, $contlngid, $skbranch); //60628
	$contlngid = $reportLangID;
	$contlng = '&lang='.db_getLanguageShortByID($cn, $contlngid);

	if (isset($_REQUEST['action']) && ($_REQUEST['action']) == 'refresh') {
		if(!(is_readable(realpath(dirname(__FILE__)).'/include/bsservice.inc'))) {
			die('Error - Could not open or read file '.realpath(dirname(__FILE__)).'/include/bsservice.inc');
		} else {
			include_once(realpath(dirname(__FILE__)).'/include/bsservice.inc');
		}
		db_ReportResetExpireDate($cn, $oguid, $rguid, $contlngid, $skbranch);
		// $reportLangID = db_getReportIDLanguage($cn, $oguid, $rguid, $contlngid, $skbranch); //60628
		sendRepotCall($cn, $oguid, $rguid, ($reportLangID != 0 ? db_getLanguageShortByID($cn, $reportLangID) : ""), "1", "0", $idbranch);
	}

	if ($rguid === null){
		header("Location: ".getCurPageURLWO()."/service/empty.php?oguid=".$oguid."&rguid=".$rguid.(!$isMainBranch ? "&skbranch=".$skbranch : '').''.$contlng."&url=".getCurPageWithEncodeParams());
		db_disconnect($cn);
		unset($userids);
		ob_end_flush();
		exit;
	} else if($rguid == '' || !db_isObjectsReportsExits($cn, $oguid, $rguid, $contlngid, $skbranch)) {
		db_disconnect($cn);
		unset($userids);
		header("Location: ".getCurPageURLWO()."/pagenotfound.php?oguid=".$oguid."&rguid=".$rguid.(!$isMainBranch ? "&skbranch=".$skbranch : '').$contlng."&url=".getCurPageWithEncodeParams(), true, 302);
		ob_end_flush();
		exit;
	} else if(db_getUserRightsToObject($cn, $userids, $oguid, $skbranch) === null || db_getUserRightsToReport($cn, $userids, $rguid, $oguid, $contlngid, $skbranch) === null ) {
		//60116, 60115
		db_disconnect($cn);
		unset($userids);
		header("Location: ".getCurPageURLWO()."/notenoughrights.php?oguid=".$oguid."&rguid=".$rguid.(!$isMainBranch ? "&skbranch=".$skbranch : '').$contlng."&url=".getCurPageWithEncodeParams(), true, 302);
		ob_end_flush();
		exit;
	} else {
		if (isset($_REQUEST['savehtml']) && $_REQUEST['savehtml'] == '1') {
			header('Content-Type: application/octet-stream' );
			header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
			header('Accept-Ranges: bytes');
			header("Cache-control: private");
			header('Pragma: private');
			header('Content-Disposition: attachment; filename="'.$oguid.'_'.$rguid.'.html"');
			header('BSPortalReport:'.$rguid);
		}

		mb_internal_encoding("UTF-8");
		
		if (db_isObjectsMultianguage($cn, $oguid, $rguid, $skbranch)){
			$lang_short = null;
		} else {
			if (db_isLanguageValidByID($cn, $contlngid)){
				$lang_short = db_getLanguageShortByID($cn, $contlngid);
			} else {
				$lang_short = 'falseLang';
			}
		}
		$fname = nameReportWithBranchAndLanguage($flroot, $oguid, $rguid, $lang_short, $idbranch);
		if (!is_readable($fname) || !db_isReportNotExpire($cn, $oguid, $rguid, $contlngid, $skbranch )){
			db_disconnect($cn);
			//STU: показывать ошибку если некуда послать запрос
			if (getSetting('portal','useRights',0) == 0){
				header("Location: ".getCurPageURLWO()."/reportnotfound.php?".$contlng."&oguid=".$oguid.'&rguid='.$rguid.'&idbranch='.$idbranch."&url=".getCurPageWithEncodeParams());
			} else {
				if (isset($_REQUEST['timer'])){
					$timer = "&timer=1";
				}
				header("Location: ".getCurPageURLWO()."/reportnotexist.php?".$contlng."&oguid=".$oguid.'&rguid='.$rguid.'&idbranch='.$idbranch.(isset($_REQUEST['call']) ? '&call' : '' )."&url=".getCurPageWithEncodeParams().$timer);
			}
			unset($userids);
			ob_end_flush();
			exit;
		}
		else {
			$fhr = fopen($fname,  'r');
			db_deleteReportsUsersQuery($cn, $userids[0], $oguid, $rguid, $skbranch);
			db_addViewCount_ReportData($cn, $userids[0], $oguid, $rguid, $skbranch);
			$i_guid = '';
			$patern = '';
			$lpos = 0;
			$fpos = 0;
			$dpos = 0;
			$rpos = 0;
			$elem = null;
			$title = '';
			$modepr = (isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'print' );
			$hlwset = isset($_REQUEST['hlwords']);
			/*proxy for imagies*/
			$img_ext = array('.jpeg','.jpg','.gif','.png','.bmp','.ico','.tiff');
			echo '<div id="reportcontainer" style="min-height: 100%; position: relative;">';
			$body_close_tag = FALSE;
			while (!feof($fhr)) {
				$buff = fgets($fhr);
				
				$buff = bsreportParser($buff, $cn, $oguid, $skbranch, $userids, $useRht, $modepr, $isMainBranch, $contlng, $contlngid, $selfeventClassText );
				
				/* 70411 if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || preg_match('~Trident/7.0(; Touch)?; rv:11.0~',$_SERVER['HTTP_USER_AGENT'])) {
					// 60374
					if ( strpos($buff, '<svg') !== false ){
						$buff = str_replace('<svg', '<div id="svg-container" data-pan-on-drag="" data-zoom-on-wheel="max-scale: 1000;" style="border: 0px solid #ccc; box-shadow: 0 0 0px #aaa; width: 95vw; height: 99vh;" data-scale="2.2" data-scroll-left="0" data-scroll-top="0"><svg', $buff );
					}
					if ( strpos($buff, 'svg>') !== false ){
						$buff = str_replace('svg>', 'svg></div>', $buff );
					}				
				}*/
                // add inline-report class to a-proccesor
				if ( strpos($buff, '<body') !== FALSE ){
					$add_ie = "";
					if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || preg_match('~Trident/7.0(; Touch)?; rv:11.0~',$_SERVER['HTTP_USER_AGENT'])) {
						$add_ie = '<style>svg{visibility: hidden;}</style>'; //70642
					}
					$buff = str_replace('<body', $add_ie.'<body style="display: none;visibility: hidden;" class="inline-report reset-bottom" ', $buff );
				}
               	// add icon to head
				if ( strpos($buff, '<head>') !== FALSE ){
					$buff = str_replace('<head>', '<head><head><meta http-equiv="X-UA-Compatible" content="IE=edge"/><link rel="shortcut icon" href="'.getCurPageURLWO().'/favicon.ico" /><link rel="stylesheet" href="css/report-reset.css">', $buff );
				}
			   	// add title and description
			   	if ( strpos($buff, '<head>') !== FALSE ){
					$objectName = db_getObjectName($cn, $oguid, $contlngid, $skbranch);
					$reportName = '';
					if ($oguid !== $rguid) {
						$reportName = db_getReportName($cn, $rguid, $contlngid, $skbranch);
					}
					$title = renderTitle($objectName, $reportName);
					$buff = str_replace('<head>', '<head><title>'.$title.'</title><meta name="description" content="'.$title.'"/>', $buff );
			   	}				
				/*proxy for imagies*/
				$buff = str_replace('<IMG ', '<img ', $buff );  
				$buff = str_replace('<Img ', '<img ', $buff );  
				$buff = str_replace('<IMg ', '<img ', $buff );  
				$buff = str_replace('<ImG ', '<img ', $buff );   

				if ( strpos($buff, '</body>') !== FALSE ){
					$buff = str_replace('</body>',  '', $buff );
					$body_close_tag = TRUE;
				}


				$imgArray = explode('<img ', $buff);
				if (count($imgArray) < 2){
					if((preg_match("/src=[^1]data/is", $buff) || preg_match('/src=[^1]\/data/is', $buff)) && preg_match("/(".implode('|', $img_ext).")/is", $buff)){
						$imlpos = strpos($buff, 'src=');
						$folderext = substr($buff, strpos($buff, 'data/') + 5 /* 5 is length of 'data/' */ );
						$folderext = substr($folderext, 0, strpos($folderext, '/') );
						$cntxtfe = explode("_", $folderext);
						if ( sizeof($cntxtfe) == 2 && strpos($folderext, ".") > 0) {
							$cntxtfe = explode(".", $folderext);
							$folderext = ".".$cntxtfe[1];
						} else if ( sizeof($cntxtfe) == 2 && strpos($folderext, "-") > 0) {
							$cntxtfe = explode("-", $folderext);
							$folderext = "-".$cntxtfe[1];
						} else if ( sizeof($cntxtfe) == 3 ) {
							$folderext = "_".$cntxtfe[2];
						} else {
							$folderext = "";
						}
						$imfpos = strpos($buff, $folderext.'/');
						$imglink= 'img.php?'.$contlng.'&dboguid='.urlencode($oguid).'&oguid='.urlencode($oguid).'&rguid='.urlencode($rguid).'&folderext='.$folderext.'&idbranch='.$idbranch.'&name=';
						$newbuff = substr($buff, 0, $imlpos + 5 /* 5 is length of 'src="' */ ).$imglink.substr($buff, $imfpos + strlen($folderext) + 1);
						$buff = $newbuff;
					}
				} else {
					$buff = "";
					for($img_index=0; $img_index < count($imgArray); $img_index++) {
						$local_buff = ($img_index > 0 ? '<img ' : "").$imgArray[$img_index];
						$imlpos = 0;
						$imglink = 0;
						if((preg_match("/src=[^1]data/is", $local_buff) || preg_match('/src=[^1]\/data/is', $local_buff)) && preg_match("/(".implode('|', $img_ext).")/is", $local_buff)){
							$imlpos = strpos($local_buff, 'src=');
							$folderext = substr($local_buff, strpos($local_buff, 'data/') + 5 /* 5 is length of 'data/' */ );
							$folderext = substr($folderext, 0, strpos($folderext, '/') );
							$cntxtfe = explode("_", $folderext);
							if ( sizeof($cntxtfe) == 2 && strpos($folderext, ".") > 0) {
								$cntxtfe = explode(".", $folderext);
								$folderext = ".".$cntxtfe[1];
							} else if ( sizeof($cntxtfe) == 2 && strpos($folderext, "-") > 0) {
								$cntxtfe = explode("-", $folderext);
								$folderext = "-".$cntxtfe[1];
							} else if ( sizeof($cntxtfe) == 3 ) {
								$folderext = "_".$cntxtfe[2];
							} else {
								$folderext = "";
							}
							$imfpos = strpos($local_buff, $folderext.'/');
							$imglink = 'img.php?'.$contlng.'&dboguid='.urlencode($oguid).'&oguid='.urlencode($oguid).'&rguid='.urlencode($rguid).'&folderext='.$folderext.'&idbranch='.$idbranch.'&name=';
							$local_buff = substr($local_buff, 0, $imlpos + 5 /* 5 is length of 'src="' */ ).$imglink.substr($local_buff, $imfpos + strlen($folderext) + 1);
						}
						$buff = $buff.$local_buff;
					}
				}
				
				/*proxy for imagies*/
				$lpos = strpos($buff, '<bsportal:report');
				$fpos = strpos($buff, '<bsportal:file');
				$xlinkrefpos = strpos($buff, 'bsportal:xlinkhref');
				if ( $lpos === FALSE && $fpos === FALSE && $xlinkrefpos === FALSE) {
					if ( strpos($buff, '<body') !== FALSE && $hlwset){
						echo $buff.'<div id="highlight-plugin">';
					} else if ( strpos($buff, '</body>') === FALSE ){
						echo $buff;
					} 
				} else if (!($fpos === FALSE )) {
					echo substr($buff, 0, $lpos);
					$rpos = strpos($buff, '</bsportal:file>', $lpos + 14); // slide from start tag <bsportal:file
					$link = substr($buff, $fpos, $rpos - $fpos + 16);
					$patern = substr($link, 0, 4);
					$xmlstr = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>'.str_replace('bsportal:file', 'bsfile', $link);
					$xml = simplexml_load_string($xmlstr);
					$title = $xml;
					$elem = $xml->xpath('//bsfile');
					$i_guid = $elem[0]["oguid"];
					$i_file = $elem[0]["file"];
					if (( $useRht == 0 && (db_isObjectExits($cn, $i_guid, $skbranch) )) || (  $useRht == 1 && db_isObjectExits($cn, $i_guid, $skbranch) && db_getUserRightsToObject($cn, $userids, $i_guid, $skbranch))) {
						echo '<a class="self-report-link '.$selfeventClassText.'" href="';
						echo getCurPageSubFolders().'/downloadreportfile.php?&langshort='.$lang_short.'&oguid='.$i_guid.'&idbranch='.$idbranch.'&file='.$i_file;
						echo '">';
						echo $title;
						echo '</a>';
					} else {
						echo $title; //8757
					}

				} else if (strpos($buff, '<bsportal:xlinkhref') > -1) {
					$ogpos = strpos($buff, 'oguid="') + 7 /* leng of 'oguid="' */;
					$ogpos_end = strpos($buff, '"', $ogpos );
					$i_guid = substr($buff, $ogpos,  $ogpos_end - $ogpos );
					if (( $useRht == 0 && (db_isObjectExits($cn, $i_guid, $skbranch) )) || (  $useRht == 1 && db_isObjectExits($cn, $i_guid, $skbranch) && db_getUserRightsToObject($cn, $userids, $i_guid, $skbranch))) {
						if ($modepr && $isMainBranch) {
							$xlinkhref = getCurPageSubFolders().'/businessmodel.php?'.$contlng.'&oguid='.$i_guid;
						} else  {
							$xlinkhref = 'javascript:parent.postMessage(\'oguid='.$i_guid.'\',\'*\')';
						}
						echo str_replace('<bsportal:xlinkhref', '<a class="self-report-link '.$selfeventClassText.'" xlink:href = "'.$xlinkhref.'"', $buff );
					} else {
						echo str_replace('<bsportal:xlinkhref', '<a class="self-report-link '.$selfeventClassText.'" xlink:href = "javascript:void()" onclick="return false" style="cursor: default; text-decoration: none;" ', $buff );
					}
				} else if (strpos($buff, '</bsportal:xlinkhref>') > -1 ) {
					echo str_replace('</bsportal:xlinkhref>', '</a>', $buff );
				}
			}
			fclose($fhr);

			if (!$modepr) {
				if ($body_close_tag){
					echo PHP_EOL.'<br/></div></body>'; //Task 77953
					getReportVotingFooterJS();
					getReportVotingFooter();
				}
			} else {
				echo '<script src="js/libs/jquery.js"></script>';
			}

			echo '<script src="js/svgclickarea.js" charset="utf-8"></script>';
			echo '<script src="js/a-processor.js" charset="utf-8"></script>';
			
			//10235
			if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || preg_match('~Trident/7.0(; Touch)?; rv:11.0~',$_SERVER['HTTP_USER_AGENT'])) {
				// 9949, 60374, off by Task 67371
				// echo '<script src="js/svgzoomdrag.js" charset="utf-8"></script>';
				// echo '<style>svg{width: 100%;height: 100%;}</style>'; //  69007
				// activate again by  77583
				echo '<script src="js/svgzoomdrag.js" charset="utf-8"></script>';
				echo '<style>svg{width: 100%;height: 100%;}</style>'; //  69007
				echo '<script src="js/svgzoom_ie.js" charset="utf-8"></script>';// 70411
			} else {  
				echo '<script src="js/svgzoom.js" charset="utf-8"></script>';
			}			
			

			/*			
			//STU: убрал, т.к. в firefox портится внешний вид - в нём как-то по другому рассчитывается положение div внутри фреймов
			//Подробности в задаче: http://stusoftsrv2:8080/tfs/web/wi.aspx?pcguid=77b48ac3-4049-4234-87d9-157f29a15e9b&id=49717
				echo '<script>
					$(document).ready(function () {
						$( window ).resize(function() {
  							if ($( window ).height() > $("#reportcontainer").height()){
  								$("#box-frame-footer").addClass("drown-footer");
  							} else {
  								$("#box-frame-footer").removeClass("drown-footer");
  							}
						});
						$( window ).resize();
     				});
				 </script>' ;
				 */

			// add pollobjectdescription section
			// 60772
			echo '<script> var _GTPollObjectVersionUrl = "'.getCurPageURLWO().'/service/objectdescription.php?skbranch='.$skbranch.'&oguid='.$oguid.'&rguid='.$rguid.'";</script>';
			echo '<script src="js/libs/jquery.cookie.js"></script>';
			echo '<script src="js/objectdescription.js"></script>';

			echo '<script src="js/reporcontainer.js"></script>';
			echo '<script src="js/a-confirm.js"></script>';
			echo '<script> 
				var gConfirmsavelesValue = "'; 
				getResource("confirm.savelesValue"); 
	
			echo '"; </script>';
			db_disconnect($cn);
			unset($userids);
			ob_end_flush();
			exit;
		}
	}
}

ob_end_flush();
?>
