<?
/*
 *
 * 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.
 *
 */
 
  require_once(dirname(__FILE__)."/../../cms/Validator.class.php");
  require_once(dirname(__FILE__)."/../../common/WriteFile.class.php");
  require_once(dirname(__FILE__)."/../../cms/SectionBar.class.php");
  require_once(dirname(__FILE__)."/../../cms/Constants.inc.php");
  require_once(dirname(__FILE__)."/../../cms/Errors.inc.php");
  
  $_removed = false;
  // checking the remove section
  if (isset($_GET['remove'])){
	$_removed = true;
	// read the current banner value
    if (file_exists(BLOG_PATH.$blogID.LINKBAR)||file_exists(BLOG_PATH.$blogID.'/'.LINK_INI)){
		$fn  = BLOG_PATH.$blogID.LINKBAR;
		$fn2 = BLOG_PATH.$blogID.BLOG_LINK_TITLE;
		$fn3 = BLOG_PATH.$blogID.'/'.LINK_INI;
		fclose($fn);
		fclose($fn2);
		fclose($fn3);
		// delete the title file, do not check here
		unlink($fn2);
		unlink($fn3);
		// delete the main file, check here!
		if (unlink($fn)){			
  			print('<font color=red>Link section removed.</font>');
		} else{
  			print('<font color=red>Cannot delete file, please check your permissions.</font>');
		}
    }else{
    	print('<font color=red>Link section cannot be removed because it does not exist.</font>');
    }
	die();
  } 
  
  // read the current siteTitle value
  if (file_exists(BLOG_PATH.$blogID.BLOG_LINK_TITLE))
  	$linkTitle = file_get_contents(BLOG_PATH.$blogID.BLOG_LINK_TITLE);
  else
  	$linkTitle = "";

  if (isset($_POST['linkTitle'])){
  	if (!($_POST['linkTitle']=='')){

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

		/** 
		 * Check values
		 */
		 $validator = new Validator();
		 $validator->validateTextOnly($linkTitle,"linkTitle is empty or contains invalid chars");
		 // prints errors
		 if ($validator->foundErrors()){
		 	print("Errors found:<BR>");
		 	print("<font color=\"red\">");	 	
		 	print($validator->listDotErrors());
		 	print("</font>");
		 }else { 	
			 /**
			  * Write it
		  	  */
		  	  $file = new WriteFile(BLOG_PATH.$blogID.BLOG_LINK_TITLE,REWRITE);
		  	  $file->writeStr($linkTitle);
		  	  $file->closeFile();	
		  	  // generate sectionBar
		  	  // create SectionBar
			  $sb = new SectionBar($blogID);
		 	  $sb->generate(); 	  	  
		 }

  	}
  }
?>	
<FORM name="linkTitle" action="<?=$_SERVER['PHP_SELF']?>" method="POST">
	<input type="hidden" name="blogID" value="<?=$blogID?>">
	<input type="hidden" name="contentType" value="<?=$contentType?>">	
	<table cellspacing="0" cellpadding="0" border="0" width="100%">
	<tr>
		<td>
			<table cellspacing="0" cellpaddgin="0" border="0">
			<tr>
				<td><b>Links section title</b></td>
				<td><input type="TEXT" name="linkTitle" size="25" value="<?=$linkTitle?>"></td>
				<td>&nbsp;&nbsp;</td>
				<td><input type="SUBMIT" value="update" size="1"></td>			
			</tr>		
			</table>
		</td>
		<td align=right>
			<a onClick="javascript:if (confirm('<?=SECTION_REMOVE_QUESTION?>')){location.href='<?=$_SERVER['PHP_SELF'].'?blogID='.$blogID.'&contentType='.$contentType.'&remove=remove'?>';}" href="#">
				<img src="./images/delete.png" border="0" alt="Remove this section">
			</a>			
		</td>
	</tr>
	</table>
</FORM>

