<?php
###################################################################
##                           WARNING!                            ##
##                                                               ##
##         THIS SCRIPT IS COPYRIGHTED TO EASYBUILDR.COM          ##
##      DUPLICATING, SELLING OR TRANSFERRING OF THIS SCRIPT      ##
##    IS A VIOLATION OF THE COPYRIGHT AND PURCHASE AGREEMENT     ##
##          PLEASE READ THE TERMS AND CONDITIONS HERE:           ##
##            https://easybuildr.com/members/terms/              ##
## ANY VIOLATION OF THESE TERMS WILL BE DEALT WITH LEGAL ACTION! ##
###################################################################
error_reporting(E_ERROR);
ini_set('display_errors',1);
session_save_path('./sessions');
session_start();

       if($_SESSION['logged_in']!=true)
	     {
			header("location:index.php?flag=2");
			exit;
	     }
		if(!empty($_REQUEST['flag']) and $_REQUEST['flag']==4) 
		  {
					$display = 0;
					if(!empty($_REQUEST['display_pages']) and $_REQUEST['display_pages']==1)
				    $display = 1;
					$thefile = 'settings/display_content.txt';
					$openedfile = fopen($thefile, "w");
					fwrite($openedfile, $display);	
					fclose($openedfile);  
		  }
		if(!empty($_REQUEST['flag']) and $_REQUEST['flag']==1) 
		  {

             $page_name = preg_replace(
                 "/[^a-zA-Z0-9\-_]/",
                 '',
                 $_REQUEST['page_name']
             );
			 $filename=$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(!empty($_REQUEST['flag']) and $_REQUEST['flag']==2) 
		  {
			foreach($_REQUEST['page_remove'] as $val )
			     {
                    $val = str_replace( "..", "", $val );
					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(!empty($_REQUEST['flag']) and $_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>
<html>
<head>
<meta charset='utf-8'>
<title>Easy Page 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" class="header_bg"><img src="images/logo.png" width="597" height="77" /></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="20" 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/Basic Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="sales_page_settings.php"><b>Sales Page Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="optin_settings.php"><b>Optin Page Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="download_page_settings.php"><b>Download Page 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="jv_page_settings.php"><b>Affiliate Page Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="20" 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="20" align="center" valign="middle"></td>
          </tr>
          <tr>
            <td height="30" align="center" valign="middle"><div id="link"><a id="link" href="privacy_terms_settings.php"><b>Privacy/Terms Settings</b></a></div></td>
          </tr>
          <tr>
            <td height="20" 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/CSS/Script 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>

    <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(!empty($_REQUEST['flag']) and $_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(!empty($_REQUEST['flag']) and $_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(!empty($_REQUEST['flag']) and $_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">
            <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]."'>".str_replace('.html','',$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 EasyBuildr.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>, EasyBuildr.com. All Rights Reserved.</strong></span></div>
</body>
</html>
