<?php
###################################################################
##                           WARNING!                            ##
##                                                               ##
##        THIS SCRIPT IS COPYRIGHTED TO STOREBUILDR.COM          ##
##      DUPLICATING, SELLING OR TRANSFERRING OF THIS SCRIPT      ##
##    IS A VIOLATION OF THE COPYRIGHT AND PURCHASE AGREEMENT     ##
##          PLEASE READ THE TERMS AND CONDITIONS HERE:           ##
##      HTTP://STOREBUILDR.COM/ADMIN-TERMS-AND-CONDITIONS        ##
## ANY VIOLATION OF THESE TERMS WILL BE DEALT WITH LEGAL ACTION! ##
##                                                               ##
###################################################################
error_reporting(0);
ini_set('display_errors','off');
      session_start();

		function checkIfDirExists(){

		if(!file_exists('./settings/seo'))
		mkdir("./settings/seo", 0777);

		if(!file_exists('./settings/seo/content_pages'))
		mkdir("./settings/seo/content_pages", 0777);

		}



       if($_SESSION[logged_in]!=true)
	     {
			header("location:index.php?flag=2");
			exit;
	     }

		$filename="settings/seo_settings.txt";


		if(isset($_POST['page'])){

			
		
				$temp_var=explode("|",$_POST['page']);

				$seopage_select=trim($_POST['page']);

				$seopage=$temp_var[1];
				$filename=$temp_var[1];

				if($temp_var[0]=='c'){
					$file = basename($filename, ".html");
					$filename="./settings/seo/content_pages/$file.txt";			
					}
				else if($temp_var[0]=='o'){
				
				if($seopage=='index.php'){		
					$filename="settings/seo_settings.txt";	
				}
				else{
					$filename="settings/seo/$temp_var[1]";	
					$file = basename($filename, ".php");
					$filename="./settings/seo/$file.txt";	
				}
				}

		}
		else{ 
			$seopage='index.php';
		}




		if(isset($_POST['Submit'])){		

		$temp_var=explode("|",$_POST['seo_page']);
		$seopage=$temp_var[1];

		$seopage_select=trim($_POST['seo_page']);

		if($temp_var[0]=='c'){
			checkIfDirExists();
			$filename=$temp_var[1];
			$file = basename($filename, ".html");			
			$filename="./settings/seo/content_pages/$file.txt";
			if(!$handle = fopen($filename, 'w')) 
			{
			 echo "Cannot open file ($filename)";
			 exit;
			}
			$content .=stripslashes($_REQUEST[website_page_title]);
			$content .=stripslashes("#_1_#".$_REQUEST[website_description]);
			$content .=stripslashes("#_1_#".$_REQUEST[website_keywords]);
			if(fwrite($handle, $content) === FALSE) 
			{
			echo "Cannot write to file ($filename)";
			exit;
			}
			fclose($handle);
			$_REQUEST[flag]=1;
			
		}
		else if($temp_var[0]=='o'){

		if($seopage=='index.php'){	
			
			$filename="settings/seo_settings.txt";	

			$content .=stripslashes($_REQUEST[website_page_title]) ;
			$content .="#_1_#";
			$content .=stripslashes($_REQUEST[website_description]) ;
			$content .="#_1_#";
			$content .=stripslashes($_REQUEST[website_keywords]) ;
			$content .="#_1_#";
			$content .=stripslashes($_REQUEST[track]) ;

			if(!$handle = fopen($filename, 'w')) 
			{
				echo "Cannot open file ($filename)";
				exit;
			}


			if(fwrite($handle, $content) === FALSE) 
			{
				echo "Cannot write to file ($filename)";
				exit;
			}
			fclose($handle);

			$_REQUEST[flag]=1;
		}
		else{

			$filename="settings/seo/$temp_var[1]";	
			$file = basename($filename, ".php");
			$filename="./settings/seo/$file.txt";
			checkIfDirExists();

			if(!$handle = fopen($filename, 'w')) 
			{
			 echo "Cannot open file ($filename)";
			 exit;
			}
			$content .=stripslashes($_REQUEST[website_page_title]);
			$content .=stripslashes("#_1_#".$_REQUEST[website_description]);
			$content .=stripslashes("#_1_#".$_REQUEST[website_keywords]);
			if(fwrite($handle, $content) === FALSE) 
			{
			echo "Cannot write to file ($filename)";
			exit;
			}
			fclose($handle);
			$_REQUEST[flag]=1;
		}

		}
		
		}


	
		if($handle = @fopen($filename, 'r')) 
		  {
			 $contents = fread($handle, filesize($filename));
             fclose($handle);
		     $argument_arr=explode("#_1_#",$contents);
		  }


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Store Buildr Admin Area</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
#help_page_title { display:none; }
#help_desc { display:none; }
#help_key { display:none; }
#help_track { display:none; }
#help_select { display:none; }
-->
</style>
<script src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
function mm_showHide(id)
{
    a=document.getElementById(id);
    if(a.style.display != 'none' && a.style.display != 'block') a.style.display='none';
    if(a.style.display == 'block') {
        a.style.display='none';
    }
    else {
        a.style.display='block';
    }
    return false;
}

function loadSEOSettings(page){
	document.frmhid.page.value=page;
	document.frmhid.submit();
}

</script>
</head>

<body>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0" class="table_border">
  <tr>
    <td colspan="2" align="left" valign="top"><div align="center" style="background-color:#5cadcb"><img src="images/logo450.png" width="450" height="96" /></div></td>
  </tr>
  <tr>
    <td width="250" align="center" valign="top" style="padding-left:10px; padding-right:10px; padding-top:20px; padding-bottom:20px">
<!--Side Nav -->
<table width="250" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td align="center" valign="middle"></td>
          </tr>
          <tr>
            <td align="center" valign="middle"><div class="members_title"><strong>Navigation</strong></div></td>
          </tr>
          <tr>
            <td height="10" align="center" valign="middle"></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a href="../" target="_blank" id="link"><b>View Your Website</b></a></div></td>
          </tr>
          <tr>
            <td height="10" align="center" valign="middle"></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="welcome.php"><b>Home</b></a></div></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="admin_settings.php"><b>Admin Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="design_settings.php"><b>Design Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="home_page_settings.php"><b>Home/Main Page Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="sidebar_settings.php"><b>Sidebar Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="10" align="center" valign="middle"></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="add_content_pages.php"><b>Add/Remove Pages</b></a></div></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="edit_content_pages.php"><b>Edit Pages</b></a></div></td>
          </tr>
          <tr>
            <td height="10" align="center" valign="middle"></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="seo_settings.php"><b>S.E.O Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="10" align="center" valign="middle"></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="logout.php"><b>Log Out</b></a></div></td>
          </tr>
          <tr>
            <td align="center" valign="middle"></td>
          </tr>
        </table>
<!--Side Nav -->
    </td>
<!--Side Nav -->
    <td width="706" align="left" valign="top" style="padding-left:10px; padding-right:10px; padding-top:20px; padding-bottom:20px"><div class="members_title"><strong>Search Engine Optimization Website Settings </strong></div>
<!--Main -->
<script language="javascript">

 function submit_form()
 {
	 if(document.frm.edit.value=="")
	   {
		 alert("Please Select a Page To Edit");
         document.frm.edit.focus();
		 return false;
	   }
	 document.frm.flag.value=1;
	 document.frm.submit();
 }

function submitform()
 {
	 document.frm.flag.value=2;
 }
</script>
          <script language="JavaScript">     

	function chk()
	{
		if(document.frm.edit.value=="-1")
		{
			alert("Please Select a Page To Edit");
			document.frm.edit.focus();
			return false;
		}
	}

        </script>
<table width="705" border="0" align="center" cellpadding="0" cellspacing="0">
		          <form name="frmhid" action="seo_settings.php" method="post" >
<input type='hidden' name='page' value=''>
</form>
        <form name="frm" action="seo_settings.php" method="post" >
            <input type="hidden" name="do_type" value="seo_settings_write">
            <?php
		if($_REQUEST[flag]==1)
		  {
?>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="saved">Data Saved Successfully <img src="images/check-green2.png" width="20" height="20" align="absmiddle" /></td>
            </tr>
            <?php
		}
?>

            <tr>
              <td height="100" colspan="2" align="center" valign="middle" class="main2"><br>
                  Select Which Page to Optimize:<br />
                  <select name="seo_page"    class="remove"  onchange="loadSEOSettings(this.options[this.selectedIndex].value)">
                     <?php
					//loading php pages

					$pages=file('./settings/files.txt');
					foreach($pages as $key=>$value){ 
						$value=trim($value);
						?>
                          <option value="o|<?=$value?>"  <? if($seopage_select=="o|".$value) { echo 'selected'; }
					?>> <?=$value?></option>
<?
					}
					{
						
					?>
						 
 					<?php
					
					}
					//loading content pages

					$file_handle = fopen("settings/order_content.txt", "rb");
						while (!feof($file_handle) ) {
							$line_of_text = fgets($file_handle);
							$files = explode(';', $line_of_text);
						}
						fclose($file_handle);
						for($j=0;$j<count($files);$j++)
						{
							if(!empty($files[$j]))
							{

								//echo "<option value='c|".$files[$j]."' $issel>".$files[$j]."</option>";
?>
								 <option value="c|<?=$files[$j]?>" <? if($seopage_select=="c|".$files[$j]) { echo 'selected'; }?>><?=$files[$j]?></option>

<?
							}
						}
					?>
                  </select>
                  <a href="#" onClick="mm_showHide('help_select');return false;"><img src="images/help.png" width="20" height="20" hspace="8" border="0" align="top" /></a><br></td>
            </tr>
            <tr>
              <td colspan="2" align="center" valign="middle" class="main2"><div class="userhelp_cell" id="help_select">
                Select which page you would like to optimize, then enter details for that page below.
                </div></td>
            </tr>
            <tr>
              <td width="300" height="50" align="center" valign="middle" class="main2">Your Website Page Title<br />
              (for S.E.O purposes):</td>
              <td width="405" height="50" align="left" valign="middle" class="main2"><input name="website_page_title" type="text" id="website_page_title" value="<?php echo $argument_arr[0]; ?>" size="40">
                <a href="#" onClick="mm_showHide('help_page_title');return false;"><img src="images/help.png" width="20" height="20" hspace="8" border="0" align="top" /></a></td>
          </tr>
            <tr>
              <td colspan="2" align="center" valign="middle" class="main2"><div class="userhelp_cell" id="help_page_title">
                Enter a page title for your website, this will only be visible in your web browser title bar.<br />
                This is generally quite similar to your  website header title, however, you should try to add additional key words about your website into this title as it is used by search engines in the indexing of your website.</div></td>
            </tr>
            <tr>
              <td width="300" height="100" align="center" valign="middle" class="main2">Your Website Description<br />
              (for S.E.O purposes):</td>
              <td width="405" height="100" align="left" valign="middle" class="main2"><textarea name="website_description" cols="38" rows="4"><?php echo $argument_arr[1]; ?></textarea>
                <a href="#" onClick="mm_showHide('help_desc');return false;"><img src="images/help.png" width="20" height="20" hspace="8" border="0" align="top" /></a></td>
          </tr>
            <tr>
              <td colspan="2" align="center" valign="middle" class="main2"><div class="userhelp_cell" id="help_desc">
                Enter a description for your website, this is purely for Search Engine Optimization purposes.<br />
                Your description has no limit in length, however, we suggest you use a maximum of 250 characters  and try to make it as unique as possible.<br />
                You should also try to include some important key words in your description.
                </div></td>
            </tr>
            <tr>
              <td width="300" height="100" align="center" valign="middle" class="main2">Your Website Key Words<br />
              (for S.E.O purposes):</td>
              <td width="405" height="100" align="left" valign="middle" class="main2"><textarea name="website_keywords" cols="38" rows="4"><?php echo $argument_arr[2]; ?></textarea>
                <a href="#" onClick="mm_showHide('help_key');return false;"><img src="images/help.png" width="20" height="20" hspace="8" border="0" align="top" /></a></td>
          </tr>
            <tr>
              <td colspan="2" align="center" valign="middle" class="main2"><div class="userhelp_cell" id="help_key">
                Enter some key words for your website, this is purely for Search Engine Optimization purposes. 
                Key words are simply words or short phrases that you would associate with your website.
                Your key words, again, have no limit in length, however, we suggest you use a maximum of 1000 characters, but this time they do not have to be in a coherent phrase as they were in the title and description, they simply need to be listed with a comma and a space after each word.
                  Place your important keywords at the beginning, and make sure that all the keywords used in the title and the description are listed again.<br />
                Google has a very good tool if you require a little help with your key words. <br />You can view it <a href="https://adwords.google.com/select/KeywordToolExternal?defaultView=3" target="_blank"><u>here</u></a>.
              <strong>example keywords</strong>: your, key, words, here</div></td>
            </tr>
		
		<?php
		if($seopage=='index.php'){?>

            <tr>
              <td height="100" align="center" valign="middle" class="main2">Your Website Tracking Code<br />
              (optional):</td>
              <td height="100" align="left" valign="middle" class="main2"><textarea name="track" cols="38" rows="10" id="track"><?php echo $argument_arr[3]; ?></textarea>
                <a href="#" onClick="mm_showHide('help_track');return false;"><img src="images/help.png" width="20" height="20" hspace="8" border="0" align="top" /></a></td>
            </tr>
            <tr>
              <td colspan="2" align="center" valign="middle" class="main2_pad"><div class="userhelp_cell" id="help_track">
                Enter your website tracking code here if required.<br />
                  (your complete code that you are given)
                We highly recommend you track your websites progress to see what is working good for you and also, to see what is not working so good for you.<a href="https://adwords.google.com/select/KeywordToolExternal?defaultView=3" target="_blank"></a>
                  This is an essential part of 'fine tuning' your website.
                  <br />
                We can very highly recommend <a href="https://www.google.com/analytics" target="_blank"><u>Google Analytics</u></a> for website tracking.<br>
                   You can sign up for free <a href="https://www.google.com/analytics" target="_blank"><u>here</u></a>.
              </div></td>
            </tr>

		<? }
		?>

            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="main2">&nbsp;</td>
            </tr>
      <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="main2"><p>
                  <input type="submit" name="Submit" value="Save SEO Website Settings" id="submit-butt">
              </p></td>
            </tr>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="main2">&nbsp;</td>
            </tr>
          </form>
        </table>  
<!--Main --></td>
  </tr>
</table>
<div align="center"><span class="footer_policy">No part of this website may be reproduced or transmitted in any form or by any means without written permission from StoreBuildr.com<br />
        <strong>Copyright
<script type="text/javascript" language="JavaScript">function getCorrectedYear(year) {
year = year - 0;
if (year < 70) return (2000 + year);
if (year < 1900) return (1900 + year);
return year;
}
var lmod = new Date();
var yearstr = getCorrectedYear(lmod.getYear());
document.write(yearstr);
// -->
</script>, StoreBuildr.com. All Rights Reserved.</strong></span></div>
</body>
</html>
