<?php
####################################################################################
##                                      WARNING!                                  ##
##                                                                                ##
##             This script is copyrighted to Free Monthly Websites.               ##
##               Duplication, selling, or transferring of this script             ##
##              is a violation of the copyright and purchase agreement.           ##
##                   Please read the Terms and Conditions here:                   ##
##   https://freemonthlywebsites2.com/legal/Copyright_Terms_and_Conditions.pdf    ##
##      Any violation of these terms will be dealt with serious 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(!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)
		  {
			 $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(!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);

		}

?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Admin Control Panel</title>
<link href="css/admin_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="914" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
  <tr>
    <td height="160" colspan="3" align="center" valign="middle" class="header">
	</td>
  </tr>
  <tr>
    <td colspan="3" align="center" valign="top" class="main_mid"><table width="888" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="3" height="5" class="table_topl">&nbsp;</td>
        <td width="220" height="5" class="table_top">&nbsp;</td>
        <td width="5" class="table_topr">&nbsp;</td>
        <td width="1" rowspan="3">&nbsp;</td>
        <td width="3" class="table_topl">&nbsp;</td>
        <td width="645" class="table_top">&nbsp;</td>
        <td width="5" height="5" class="table_topr">&nbsp;</td>
      </tr>
      <tr>
        <td width="3" class="table_left">&nbsp;</td>
        <td width="220" align="center" valign="top"><table width="215" border="0" align="left" cellpadding="0" cellspacing="0">
          <tr>
            <td width="215" height="80" colspan="2" align="center" valign="middle" class="admin_button"><a href="../" target="_blank"><strong>View Your Website</strong></a></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="welcome.php"><strong>Home</strong></a></td>
            </tr>
          <tr>
            <td height="60" colspan="2" align="center" valign="middle"><img src="images/bulletaro_dn.gif" width="13" height="9" hspace="10"><span class="style1">Standard Settings</span><img src="images/bulletaro_dn.gif" width="13" height="9" hspace="10"></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="admin_settings.php"><strong>Admin Settings</strong></a></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="personal_settings.php"><strong>Personal Settings</strong></a></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="website_settings.php"><strong>Basic Website Settings</strong></a></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="seo_settings.php"><strong>S.E.O Settings</strong></a></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="theme_settings.php"><strong>Theme Settings</strong></a></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="advert_settings.php"><strong>Advert Settings</strong></a></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="affiliate_settings.php"><strong>Affiliate Settings</strong></a></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="optin_settings.php"><strong>Optin Form Settings</strong></a></td>
          </tr>
          <tr>
            <td height="60" colspan="2" align="center" valign="middle"><img src="images/bulletaro_dn.gif" width="13" height="9" hspace="10"><span class="style1">Article Settings</span><img src="images/bulletaro_dn.gif" width="13" height="9" hspace="10"></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="add_content_pages.php"><strong>Add/Remove Article Pages</strong></a></td>
          </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="edit_content_pages.php"><strong>Edit Article Pages</strong></a></td>
          </tr>
          <tr>
            <td height="60" colspan="2" align="center" valign="middle"><img src="images/bulletaro_dn.gif" width="13" height="9" hspace="10"><span class="style1">Other</span><img src="images/bulletaro_dn.gif" width="13" height="9" hspace="10"></td>
          </tr>

          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="https://freemonthlywebsites2.com/legal/Copyright_Terms_and_Conditions.pdf" target="_blank"><strong>Terms and Conditions</strong></a></td>
          </tr>
          <tr>
            <td height="30" colspan="2" align="center" valign="middle">&nbsp;</td>
            </tr>
          <tr>
            <td height="45" colspan="2" align="center" valign="middle" class="admin_button"><a href="logout.php"><strong>Logout</strong></a></td>
          </tr>
          <tr>
            <td height="30" colspan="2" align="center" valign="middle">&nbsp;</td>
          </tr>
        </table>
        <td width="5" class="table_right">&nbsp;</td>
        <td width="3" class="table_left">&nbsp;</td>
        <td width="645" align="center" valign="top"><table width="645" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="50" colspan="2" align="center" valign="middle" class="title1">Add/Remove New Article Pages </td>
          </tr>
          <?php
		if(!empty( $_REQUEST['flag'] ) and $_REQUEST['flag']==2)
		  {
?>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="title1">&gt;&gt; <span class="style3">Page Removed Successfully</span> &lt;&lt;</td>
            </tr>
          <?php
		}
?>
          <?php
		if(!empty( $_REQUEST['flag'] ) and $_REQUEST['flag']==1)
		  {
?>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="title1">&gt;&gt; <span class="style3">Page Added Successfully</span> &lt;&lt;</td>
            </tr>
            <?php

		}

?>
          <tr>
            <td height="80" colspan="2" align="center" valign="middle" class="main2"><p>Article pages are pages that 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 Article 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" class="main2">Enter a Name For Your New Article Page That You Wish To Add:<a href="#" onClick="mm_showHide('help_add_page');return false;"><img src="images/help.gif" width="21" height="21" hspace="8" border="0" align="top"></a><br>
              (no spaces and no irregular characters)</td>
            </tr>
            <tr>
              <td colspan="2" align="center" valign="middle" class="main2"><div class="userhelp_cell" id="help_add_page">
                  <p><br>
                    Enter a name for your new article page with no spaces and no irregular characters, only letters and numbers.                  
                  <p>You may use underscore (_) and hyphen (-) to separate words. <br>
                                <br>
                                <strong>example main page name: </strong>my_new_article1                  
                  <p>Once you have added a new page you must then proceed to edit that page from the '<a href="edit_content_pages.php"><u>Edit Article Pages</u></a>' section.<br>
                                <br>
                    This will allow you to enter content for the page you have just created.
                    <br>
                    <br>
                  </div></td>
            </tr>
            <tr>
              <td height="100" colspan="2" align="center" valign="middle" class="main2"><p>
                  <input name="page_name" type="text" id="page_name" value="your_new_article_page_name_here" size="40">
              </p></td>
            </tr>
            <tr>
              <td height="60" colspan="2" align="center" valign="middle" class="main2"><input name="Submit2" type="submit" value="Add New Article Page">              </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" class="main2">&nbsp;</td>
            </tr>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="main2">Remove an Article Page:<a href="#" onClick="mm_showHide('help_rem_page');return false;"><img src="images/help.gif" width="21" height="21" 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_rem_page">
                  <p><br>
                    Simply select the page you wish to be removed and click on the 'Remove an Article Page'<br>
                    button below to remove the page totally.                
                  <p><span class="style1">Warning!</span> <strong>This will delete the chosen page  forever, so be sure before you remove. </strong><br>
                                <br>
                                <br>
                                <br>
                                </div></td>
            </tr>
            <tr>
              <td height="150" colspan="2" align="center" valign="middle" class="main2"><p>
                  <select name="page_remove[]" size="6"  multiple class="remove">
                    <?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" class="main2"><input type="submit" name="Submit" value="Remove an Article Page"></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" class="main2">&nbsp;</td>
            </tr>
            <tr>
              <td height="50" colspan="2" align="center" valign="middle" class="main2">Sort Your Page Links:<a href="#" onClick="mm_showHide('help_sort');return false;"><img src="images/help.gif" width="21" height="21" 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_sort">
                  <p><br>
                    Choose the order in which you wish your page links to be displayed.                  
                  <p>Simply enter a number that corresponds with your preferred order of that particular link.                  
                  <p>Links are displayed  top to bottom.                  
                  <p><strong>example: </strong>if you had a page named 'page_1' and you wanted the navigation link displayed at the top, you would enter 
                    the number <strong>1</strong> into the sorting field. If you wanted it to be shown at the bottom, you would enter a higher number, depending on how many pages you have.<br>
                    <br>
                    <br>
                  </div></td>
            </tr>
            <tr>
              <td height="150" colspan="2" align="center" valign="middle" class="main2"><table width="340" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="256" align="center" class="main2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Page Name</td>
                  <td width="84" align="center" class="main2">Page<br>
                    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" class="main2"><input type="submit" name="Submit" value="Sort Pages"></td>
            </tr>
          </form>
          <tr>
            <td height="50" colspan="2" align="center" valign="middle" class="main2"><p> </p></td>
          </tr>
        </table></td>
        <td width="5" class="table_right">&nbsp;</td>
      </tr>
      <tr>
        <td width="3" height="6" class="table_botl">&nbsp;</td>
        <td width="220" height="6" class="table_bot">&nbsp;</td>
        <td width="5" class="table_botr">&nbsp;</td>
        <td width="3" class="table_botl">&nbsp;</td>
        <td width="645" class="table_bot">&nbsp;</td>
        <td width="5" height="6" class="table_botr">&nbsp;</td>
      </tr>
    </table></td>
  </tr> 
  <tr>
    <td height="60" colspan="3" align="center" valign="middle" class="footer">    </td>
  </tr>
  <tr class="footer_bg">
    <td width="8" height="30">&nbsp;</td>
    <td width="898" height="30"><table width="898" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td align="center" valign="middle" class="copyright">Copyright &copy; <a href="https://freemonthlywebsites2.com" target="_blank">Free Monthly Websites 2.0</a>. All Rights Reserved.</td>
      </tr>
      <tr>
        <td align="center" valign="middle" class="powered">Powered By: <a href="https://freemonthlywebsites2.com" target="_blank">Free Monthly Websites 2.0</a></td>
      </tr>
    </table></td>
    <td width="8" height="30">&nbsp;</td>
  </tr>
</table>
</body>
</html>