<?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');
}

checkUserAndRedirectToLogin();
$cn = db_connect();
$contlng = null;
$contlngid = null;
if (getSetting('portal','useRights',0) == 1){
	$contlng = 'lang='.db_getLanguageShortByID($cn, $_SESSION['user_idlanguagecontent']);
	$contlngid = $_SESSION['user_idlanguagecontent'];
}
$hideheader = (isset($_COOKIE['hideheader']) ?  $_COOKIE['hideheader'] : 0);

if ( GetSetting('portal','useRights',0) == 0 ){
	if( !IsUserLogin() ){
		header("Location: ".getCurPageURLWO()."/businessmodel.php");
		ob_end_flush();
		exit;
	}
} else {
	if( !IsUserLogin() ){
		header("Location: ".getCurPageURLWO()."/login.php?returl=admingeneral.php");
		ob_end_flush();
		exit;
	}
	$cn = db_connect();
	if (!isUserAdmin()){ 
		if (db_isUserAdminToPolls($cn, GetUserIDs())) {
			header("Location: ".getCurPageURLWO()."/adminpollobject.php");
			ob_end_flush();
			exit;
		} else {
			header("Location: ".getCurPageURLWO()."/personal.php");
			ob_end_flush();
			exit;
		}
	}
}
$usr_arr = GetUserIDs();
setCookieAdminLastPage('admingeneral');
?>
<!doctype html>
<html>
<head>
	<title><?php echo renderTitle();?></title>
	<? 
	renderCommonMeta(renderTitle()); 
	renderCommonCSS(); 
	?>
	<style type="text/css">
	div.modal{
		position:absolute;
		z-index:99;
		display:none;
		width:300px;
		height:150px;
		padding:10px;
		display: table-cell;
		vertical-align: middle;
		text-align:center;
	}
	</style>
</head>
<body>
	<?php renderModalHourGlassDiv();?>
	<div id="container">
		<?php renderLoginBlock();	?>
	<div id="main" role="main" class="ui-layout-center">
		<?php renderMainMenu(strtolower(pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME)), FALSE); ?>
			<div id="box-tabs">
				<ul class="list-tabs">
					<li class="active"><a href="#"><?php getResource("button.admin.general");?></a></li>
					<li><a href="admin.php"><?php getResource("button.admin.statistic");?></a></li>
					<li><a href="adminconsole.php"><?php getResource("button.admin.console");?></a></li>
					<li><a href="adminpollobject.php"><?php getResource("button.admin.polls");?></a></li>
				</ul>
			</div>
		</section>
		<div id="content" class="ui-layout-center">
			<section class="box-front-bottom front-menu clearfix">

<form id="save" action="" method="post">
<?php
$ini = new TIniFileEx(getSettingsFilePath());
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'save'){
	$ini->write('company','name',stripslashes($_REQUEST['name']),1);
	$ini->write('company','logo',$_REQUEST['logo']);
	$ini->write('company','portalname',stripslashes($_REQUEST['portalname']),1);
	$ini->write('portal','log.size',stripslashes($_REQUEST['logsize']),1);
	if (isset($_REQUEST['showpage_personal'])) {
		$ini->write('page','showpage.personal','1');
	} else {
		$ini->write('page','showpage.personal','0');
	}

	if (isset($_REQUEST['showpage_indicators'])) {
		$ini->write('page','showpage.indicators','1');
	} else {
		$ini->write('page','showpage.indicators','0');
	}

	if (isset($_REQUEST['showpage_pollobjects'])) {
		$ini->write('page','showpage.pollobjects','1');
	} else {
		$ini->write('page','showpage.pollobjects','0');
	}

	if (isset($_REQUEST['admin_notification_portalstart'])) {
		$ini->write('portal','admin.notification_portalstart','1');
	} else {
		$ini->write('portal','admin.notification_portalstart','0');
	}

	if (isset($_REQUEST['admin_notification_portalstoppedonerror'])) {
		$ini->write('portal','admin.notification_portalstoponerror','1');
	} else {
		$ini->write('portal','admin.notification_portalstoponerror','0');
	}
	
	if (isset($_REQUEST['polls_createarchive'])) {
		$ini->write('portal','polls.createarchive','1');
	} else {
		$ini->write('portal','polls.createarchive','0');
	}

	if (isset($_REQUEST['log_sendemails'])) {
		$ini->write('portal','log.sendemails','1');
	} else {
		$ini->write('portal','log.sendemails','0');
	}

	$ini->updateFile(); // скидываем информацию в ini файл

	header("Location: ".getCurPageURL());
	ob_end_flush();
}
?>
   <input type="hidden" name="action" value="save">
   <table width="100%">
   <tr><td width="5%">
   <h3><nobr><?php getResource("field.CompanyName");?>&nbsp;&nbsp;&nbsp;&nbsp;</nobr></h3>
   </td><td width="95%"><h3><input style="width: 400px;" name="name" type="text" value="<?php echo html_entity_decode($ini->read('company','name','',1));?>"/></h3></td></tr>
   <tr><td>
   <h3><nobr><?php getResource("field.CompanyLogo");?>&nbsp;&nbsp;&nbsp;&nbsp;</nobr></h3>
   </td><td><h3><input style="width: 400px;" name="logo" type="text" value="<?php echo $ini->read('company','logo','');?>"/></h3></td></tr>
   <tr><td>
   <h3><nobr><?php getResource("field.PortalName");?>&nbsp;&nbsp;&nbsp;&nbsp;</nobr></h3>
   </td><td><h3><input style="width: 400px;" name="portalname" type="text" value="<?php echo html_entity_decode($ini->read('company','portalname','',1));?>"/></h3></td></tr>
   <tr><td>
   <h3><nobr><?php getResource("field.logSize");?>&nbsp;&nbsp;&nbsp;&nbsp;</nobr></h3>
   </td><td><h3><input style="width: 400px;" type="number" pattern="[0-9]{1,4}" onkeyup = "this.value=(parseInt(this.value) > 9999 ? 9999 : (parseInt(this.value) < 0 ? 0 : parseInt(this.value))) | 0"  onchange= "this.value=(parseInt(this.value) > 9999 ? 9999 : parseInt(this.value) < 0 ? 0 : parseInt(this.value)) | 0" name="logsize" type="text" value="<?php echo html_entity_decode($ini->read('portal','log.size','1024',1));?>"/></h3></td></tr>
   </table><br/>
   <h3><input type="checkbox" name="showpage_personal" value="1" <?php $ini->read('page','showpage.personal','') == 1 ? print('checked') : print('');?> ><?php getResource("field.showPersonalPage");?></h3>
   <h3><input type="checkbox" name="showpage_indicators" value="1" <?php $ini->read('page','showpage.indicators','') == 1 ? print('checked') : print('');?>><?php getResource("field.showInputPage");?></h3>
   <h3><input type="checkbox" name="showpage_pollobjects" value="1" <?php /*61865*/ $ini->read('page','showpage.pollobjects','1') == 1 ? print('checked') : print('');?> ><?php getResource("field.showPollObjectsPage");?></h3>
   <h3><input type="checkbox" name="admin_notification_portalstart" value="1" <?php $ini->read('portal','admin.notification_portalstart','') == 1 ? print('checked') : print('');?>><?php getResource("field.admin_notification_portalstart");?></h3>
   <h3><input type="checkbox" name="admin_notification_portalstoppedonerror" value="1" <?php $ini->read('portal','admin.notification_portalstoponerror','') == 1 ? print('checked') : print('');?>><?php getResource("field.admin_notification_portalstoppedonerror");?></h3>
   <h3><input type="checkbox" name="log_sendemails" value="1" <?php $ini->read('portal','log.sendemails','') == 1 ? print('checked') : print('');?>><?php getResource("field.log_sendemails");?></h3>
   <h3><input type="checkbox" name="polls_createarchive" value="1" <?php $ini->read('portal','polls.createarchive','') == 1 ? print('checked') : print('');?>><?php getResource("field.polls.createarchive");?></h3>

   <br/>
   <br/>
   <span><button class="btn-top btn-top-text" title="<?php getResource("button.Save.hint");?>"><span><i class="fa fa-floppy-o" aria-hidden="true"></i> <?php getResource("button.Save");?></span></button></span>
</form>

<br>
<br>

<?php
if (isset($_REQUEST['action'])){
	$cn = db_connect();
	if (($_REQUEST['action']) == 'clearrat') {
		db_clearReportDataRating($cn);
	} else if (($_REQUEST['action']) == 'clearcnt') {
		db_clearReportDataViewCount($cn);
	} else if (($_REQUEST['action']) == 'clearmsg') {
		db_clearForumMessages($cn);
	}
	db_disconnect($cn);
}

?>
		<form id="clearrat" action="" method="post" onsubmit="return confirm('<?php getResource("confirm.delete");?>')">
			<input type="hidden" name="action" value="clearrat">
			<span><button class="btn-top btn-top-text btn-top-w170" title="<?php getResource("button.deleteRating.hint");?>"><span><?php getResource("button.deleteRating");?></span></button></span>
		</form>
		<br>
		<br>

		<form id="clearcnt" action="" method="post" onsubmit="return confirm('<?php getResource("confirm.delete");?>')">
			<input type="hidden" name="action" value="clearcnt">
			<span><button class="btn-top btn-top-text btn-top-w170" title="<?php getResource("button.deleteCounters.hint");?>"><span><?php getResource("button.deleteCounters");?></span></button></span>
		</form>
		<br>
		<br>

		<form id="clearmsg" action="" method="post" onsubmit="return confirm('<?php getResource("confirm.delete");?>')">
			<input type="hidden" name="action" value="clearmsg">
			<span><button class="btn-top btn-top-text btn-top-w170" title="<?php getResource("button.deleteMessages.hint");?>"><span><?php getResource("button.deleteMessages");?></span></button></span>
		</form>
		<br>
		<br>

		<form id="testemail" action="" method="post">
			<input type="hidden" name="action" value="testemail">
			<span><button class="btn-top btn-top-text btn-top-w170" title="<?php getResource("button.sendTestEmail.hint");?>"><span><?php getResource("button.sendTestEmail");?></span></button></span>
		</form>
		<br>
		<br>
	</section>
</div>
<script src="js/script.js"></script>
<script src="js/libs/jquery.cookie.js"></script>
<script>
	$serviceUrl = 'service/testemail.php';
	$(document).ready(function (){
		$("#testemail").submit(function(e){
			ShowGlassWindow(true);
			$.ajax({
				type: "GET",
				url: $serviceUrl,
				success: function( data ) {
					ShowGlassWindow(false);
					alert( data );
				},
				error: function() {
					alert('inernal error!');
					ShowGlassWindow(false);
				}
			});
			return false;
		});
	});
</script>
<?php
	if(!(is_readable(realpath(dirname(__FILE__)).'/templates/languagesbox.template'))) {
		die('Error - Could not open or read file '.realpath(dirname(__FILE__)).'/templates/languagesbox.template');
	} else {
		include_once(realpath(dirname(__FILE__)).'/templates/languagesbox.template');
	}
?>
<?php renderFooterTemplate(); ?>
</body>
</html>
<?php ob_end_flush(); ?>