<?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();

       if($_SESSION['logged_in']!=true)
	     {
			header("location:index.php?flag=2");
			exit;
	     }
		if($_REQUEST['flag']==4) 
		  {
					$display = 0;
					if($_REQUEST['display_pages']==1)
				    $display = 1;
					$thefile = 'settings/display_content.txt';
					$openedfile = fopen($thefile, "w");
					fwrite($openedfile, $display);	
					fclose($openedfile);  
		  }
		if($_REQUEST['flag']==1) 
		  {
			 $filename=$_REQUEST['page_name'].".html";
			 $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);
				$pos = strpos($line_of_text, $filename);
				if($pos==0)
				{
					if(empty($files[0]))
					{
						$content = $filename;
					}
					else
						$content = ';'.$filename;
					 if(!file_exists("../content_pages/$filename"))
					  {
						 copy("blank.txt","../content_pages/$filename");
						 chmod("../content_pages/$filename", 0777);
		 	          }
					$thefile = 'settings/order_content.txt';
					$openedfile = fopen($thefile, "a");
					fwrite($openedfile, $content);	
					fclose($openedfile);
					
				}
		  }

        if($_REQUEST[flag]==2) 
		  {
			 while(list($key,$val)=each($_REQUEST['page_remove']))
			     {
					unlink("../content_pages/$val");
					$file_handle = fopen("settings/order_content.txt", "rb");
					while (!feof($file_handle) ) {
						$line_of_text = fgets($file_handle);
						$content = $line_of_text;
					}
					fclose($file_handle);
					$content =  str_replace(';'.$val,'',$content);
					$content =  str_replace($val.';','',$content);
					$content =  str_replace($val,'',$content);
					$thefile = 'settings/order_content.txt';
					$openedfile = fopen($thefile, "w");
					fwrite($openedfile, $content);	
					fclose($openedfile);
			     }
		  }
		if($_REQUEST['flag']==3)
		{
			$numpage = $_REQUEST['numpage'];
			$page_s = array();
			$order_s = array();
			for($i=0;$i<$numpage;$i++)
			{
				$page_s[] = $_REQUEST['pages'.$i];
				$order_s[] = $_REQUEST['orders'.$i];
			}
			for($i=0;$i< $numpage-1;$i++)
			{
				for($j=$i+1;$j< $numpage;$j++)
				{
					if($order_s[$j]<$order_s[$i])
					{
						$temp = $order_s[$i];
						$order_s[$i] = $order_s[$j];
						$order_s[$j] = $temp;
						$temp = $page_s[$i];
						$page_s[$i] = $page_s[$j];
						$page_s[$j] = $temp;
					}
				}
			}
			$contents = array();
			foreach($page_s as $page)
				$contents[] = $page;
			$content = implode(";",$contents);
			$thefile = 'settings/order_content.txt';
			$openedfile = fopen($thefile, "w");
			fwrite($openedfile, $content);	
			fclose($openedfile);
		}
?>
<!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_add_page {display:none; }
#help_rem_page {display:none; }
#help_sort {display:none; }
#help_display {display:none; }
-->
</style>
<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;
}
</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>Add/Remove New Pages</strong></div>
<!--Main -->
<table width="705" border="0" align="center" cellpadding="0" cellspacing="0">
            <?php
		if($_REQUEST[flag]==3)
		  {
?>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="saved">Pages Sorted Successfully <img src="images/check-green2.png" width="20" height="20" align="absmiddle" /></td>
            </tr>
        <?php
		}
?>
            <?php
		if($_REQUEST[flag]==2)
		  {
?>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="saved">Page Removed Successfully <img src="images/check-green2.png" width="20" height="20" align="absmiddle" /></td>
            </tr>
            <?php
		}
?>
            <?php
		if($_REQUEST[flag]==1)
		  {
?>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="saved">Page Added Successfully <img src="images/check-green2.png" width="20" height="20" align="absmiddle" /></td>
            </tr>
        <?php
		}
?>
          <tr>
            <td height="80" colspan="2" align="center" valign="middle"><p>New pages allow you to add any content you like. Simply enter the name for the page to be created, once created then you
            can edit that page from the '<a href="edit_content_pages.php"><u>Edit  Pages</u></a>' section.</p>              </td>
          </tr>
      <form name="frm" action="add_content_pages.php" method="post" onSubmit="return chk()">
            <input type="hidden" name="flag" value="1">
            
            <tr>
              <td height="50" colspan="2" align="center" valign="middle">Enter a Name For Your New Page That You Wish To Add:<a href="#" onclick="mm_showHide('help_add_page');return false;"><img src="images/help.png" width="20" height="20" hspace="8" border="0" align="top" /></a><a href="#" onClick="mm_showHide('help_add_page');return false;"></a><br>
              (no spaces and no irregular characters)</td>
          </tr>
            <tr>
              <td colspan="2" align="center" valign="middle"><div class="userhelp_cell" id="help_add_page">
Enter a name for your new  page with <b>no spaces and no irregular characters</b>,<br /> 
only letters and numbers.<br>                
You may use underscore (_) and hyphen (-) to separate words. <br><br>
<strong>example page name: </strong>my-new-page1                  
<br />
Once you have added a new page you must then proceed to edit that page from the<br />
'<a href="edit_content_pages.php"><u>Edit Pages</u></a>' section.<br>
                                <br>
                    This will allow you to enter content for the page you have just created.
                  </div></td>
            </tr>
            <tr>
              <td height="60" colspan="2" align="center" valign="middle"><p>
                  <input name="page_name" type="text" id="page_name" value="your_new_page_name_here" size="40">
              </p></td>
          </tr>
            <tr>
              <td height="60" colspan="2" align="center" valign="middle"><input name="Submit2" type="submit" value="Add New Page" id="submit-butt">              </td>
            </tr>
        </form>
          <form name="frm" action="add_content_pages.php" method="post" onSubmit="return chk()">
            <input type="hidden" name="flag" value="2">
            <tr>
              <td height="50" colspan="2" align="center" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="70" colspan="2" align="center" valign="middle">Remove a Page:<a href="#" onclick="mm_showHide('help_rem_page');return false;"><img src="images/help.png" width="20" height="20" hspace="8" border="0" align="top" /></a><a href="#" onClick="mm_showHide('help_rem_page');return false;"></a></td>
            </tr>
            <tr>
              <td colspan="2" align="center" valign="middle"><div class="userhelp_cell" id="help_rem_page">
                Simply select the page you wish to be removed and click on the 'Remove Page'<br>
                  button below to remove the page totally.<br />
                <span style="color:#CC0000">Warning!</span> <strong>This will delete the chosen page  forever, so be sure before you remove.</strong>
              </div></td>
            </tr>
            <tr>
              <td colspan="2" align="center" valign="middle"><p>
                  <select name="page_remove[]" size="6"  multiple class="remove" style="min-width:300px">
                    <?php
						$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]))
							{
								$order = $j+1;
								echo "<option value='".$files[$j]."'>".$files[$j]."</option>";
							}
						}
					?>
                  </select>
              </p></td>
            </tr>
            <tr>
              <td height="60" colspan="2" align="center" valign="middle"><input type="submit" name="Submit" value="Remove Page" id="submit-butt"></td>
            </tr>
          </form>
          <form name="frm" action="add_content_pages.php" method="post" onSubmit="return chk()">
            <input type="hidden" name="flag" value="3">
            <tr>
              <td height="50" colspan="2" align="center" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle">Sort Your Page Links:<a href="#" onclick="mm_showHide('help_sort');return false;"><img src="images/help.png" width="20" height="20" hspace="8" border="0" align="top" /></a><a href="#" onClick="mm_showHide('help_sort');return false;"></a></td>
            </tr>
            <tr>
              <td colspan="2" align="center" valign="middle"><div class="userhelp_cell" id="help_sort">
                Choose the order in which you wish your page links to be displayed.<br />
                  Simply enter a number that corresponds with your preferred order of that particular link.<br />
                  Links are displayed  left to right.<br />
              </div></td>
            </tr>
            <tr>
              <td height="150" colspan="2" align="center" valign="middle"><table width="400" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="294" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Page Name</td>
                  <td width="106" align="center">Page Order</td>
                </tr>
              </table><br>
                    <?php
						$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]))
						{
							$order = $j+1;	
				$hack = str_replace("/", "", $files[$j]);
				$hack = str_replace(".php", "", $hack);
					?>
                              <input name="pages<?=$j?>" type="text" value="<?=$hack?>" size="40" />
                              
                              <input name="orders<?=$j?>" type="text" value="<?=$order?>" size="2" /><br />
 					<?php
						}
					}
					?>
						<input name="numpage" type="hidden" value="<?=$j?>" size="4" />
              </p></td>
            </tr>
            <tr>
              <td height="60" colspan="2" align="center" valign="middle"><input type="submit" name="Submit" value="Sort Pages" id="submit-butt"></td>
            </tr>
          </form>
          <tr>
            <td height="50" colspan="2" align="center" valign="middle"><p> </p></td>
          </tr>
      </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>
