<?php 
/*
 *
 * sflog!
 * Copyright (C) 2005 Alberto Sfolcini <a.sfolcini@gmail.com>
 *
 * This file is a part of sflog!.
 *
 * sflog! is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * sflog! is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */
 
  error_reporting(E_USER_ERROR);
  
  require_once(dirname(__FILE__)."/../../cms/Validator.class.php");
  require_once(dirname(__FILE__)."/../../common/WriteFile.class.php");
  require_once(dirname(__FILE__)."/../../cms/Auth.class.php");
  require_once(dirname(__FILE__)."/../../cms/Constants.inc.php");

  
  // Check for authorizations
  $auth = new Auth();
  if (!$auth->isAuth()){
  	header("Location: login.php");
  	die();
  }
  // ------ end auth's check
  
  error_reporting(E_USER_ERROR);
  // read the current values
  $siteTitle =  file_get_contents(SITETITLE);
  $domain    =  file_get_contents(SITEDOMAIN);
  $siteFooterbar =  file_get_contents(SITEFOOTERBAR);
  $siteLogo	=  file_get_contents(SITELOGO);
  
  if (isset($_POST['siteTitle'])){
  	if (!($_POST['siteTitle']=='')){

	    $siteTitle = stripslashes($_POST['siteTitle']);  	  	  	

	    if (isset($_POST['domain']))
	   		$domain = stripslashes(strip_tags($_POST['domain']));
	    else
	   		$domain = '';

	    if (isset($_POST['siteFooterbar']))
	   		$siteFooterbar = stripslashes(strip_tags($_POST['siteFooterbar']));
	    else
	   		$siteFooterbar = '';
	   		
	    if (isset($_POST['siteLogo']))
	   		$siteLogo = stripslashes($_POST['siteLogo']);
	    else
	   		$siteLogo = '';	   			   		

		/** 
		 * Check values
		 */
		 $validator = new Validator();
		 $validator->validateGeneral($siteTitle,"siteTitle is empty or contains invalid chars");
		 $validator->validateGeneral($domain,"Site domain is empty or contains invalid chars");
		 $validator->validateGeneral($siteFooterbar,"FooterBar contains invalid chars");
		 // prints errors
		 if ($validator->foundErrors()){
		 	print("Errors found:<BR>");
		 	print("<font color=\"red\">");	 	
		 	print($validator->listDotErrors());
		 	print("</font>");
		 }else { 	
			 /**
			  * Write it
		  	  */
			  // write title
		  	  $file = new WriteFile(SITETITLE,REWRITE);
		  	  $file->writeStr($siteTitle);
		  	  $file->closeFile();
		  	  // write domain
		  	  $file = new WriteFile(SITEDOMAIN,REWRITE);
		  	  $file->writeStr($domain);
		  	  $file->closeFile();		  	  
		  	  // write footerbar
		  	  $file = new WriteFile(SITEFOOTERBAR,REWRITE);
		  	  $file->writeStr($siteFooterbar);
		  	  $file->closeFile();	
		  	  // write logo
		  	  $file = new WriteFile(SITELOGO,REWRITE);
		  	  $file->writeStr($siteLogo);
		  	  $file->closeFile();		  	  		  		  		  	  
		 }

		 
  	}
  }
?>	
<script>
function win(str) {
   Win = window.open(str,'browseContent','scrollbars=yes,resizable=no,width=800,height=600,status=no,location=no,toolbar=no');
}
function winsmall(str) {
   Win = window.open(str,'Help','scrollbars=yes,resizable=no,width=600,height=400,status=no,location=no,toolbar=no');
}
</script>
<FORM action="<?=$_SERVER['PHP_SELF']?>" method="POST">
	<table cellspacing="0" cellpaddgin="0" border="0">
		<tr>
			<td><b>site title</b></td>
			<td><input type="TEXT" name="siteTitle" size="25" value="<?=$siteTitle?>"></td>
		</tr>
		<tr>
			<td><b>site domain</b></td>
			<td><input type="TEXT" name="domain" size="25" value="<?=$domain?>">
			&nbsp;&nbsp;ex. www.opensource.org or www.opensource.org/docs/
			</td>
			
		</tr>
		<tr>
			<td><b>site footerBar</b></td>
			<td><input type="TEXT" name="siteFooterbar" size="60" value="<?=$siteFooterbar?>"></td>			
		</tr>
		<tr>
			<td><b>site logo</b></td>
			<td>
				<a href="javascript:win('../admin/manage.php?blogID=<?=$blogID?>&contentType=<?=_CONTENT?>');">browse contents</a>
				<a href="javascript:winsmall('../admin/helpPost.html');"><img src="./images/help.png" border="0" width="16" height="16"></a>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td><TEXTAREA name="siteLogo" cols="60" rows="3"><?=$siteLogo?></TEXTAREA></td>			
		</tr>

		<tr>
			<td>&nbsp;</td>
			<td>
				<input type="SUBMIT" value="update" size="1">
			</td>
		</tr>
	</table>
</FORM>