<?php
include('header.php');
echo $h;

$action = $_GET['action'];
if(!isset($action)) $action = "add";

IF ($action=="add"){
$sql = "SELECT * FROM opitions where id=1";
$result = mysql_query ($sql) or die ("Query failed");
$p_cats = mysql_fetch_array($result);
?>
<form name="vbform" method="post" action="style_cp.php?action=default">
<table class='xtable' width="100%" id="AutoNu44mber1">
     <tr>
      <td width="100%" class='xtt' align="center"><?php echo $LANGAUGE_CP[509]; ?></td>
    </tr>
    <tr>
      <td width="100%" class='xtd' align="center">
<select size='1' name="folder">
<?php
$sql = "SELECT * FROM pathstyle";
$result = mysql_query ($sql) or die ("Query failed");
while ($p_s=mysql_fetch_array($result))
{
if($p_s['pathfolder'] == $p_cats['folder'])
{
echo "<OPTION value='$p_s[pathfolder]' selected='selected'>$p_s[name]</OPTION>";
}else echo "<OPTION value='$p_s[pathfolder]'>$p_s[name]</OPTION>";
}
?>
</select> <select size="1" name="allstyle">
  <option value="1"><?php echo $LANGAUGE_CP[510]; ?></option>
  <option value="0" selected="selected">- - - - -</option>
</select> <input type="submit" value=" <?php echo $LANGAUGE_CP[18]; ?> " name="cmdAdd" />
</td>

</tr>
</table>
</form>

<form name="vbform" method="post" action="style_cp.php?action=insert">
<table class='xtable' width="100%" id="AutoNumber1">
     <tr>
      <td width="100%" colspan="2" class='xtx' align="center"><?php echo $LANGAUGE_CP[511]; ?></td>
    </tr>
    <tr>
      <td width="100%" colspan="2" class='xtr' align="center"><?php echo $LANGAUGE_CP[512]; ?></td>
    </tr>
    <tr>
      <td width="35%" class='xtr'><?php echo $LANGAUGE_CP[513]; ?></td>
      <td width="65%" class='xtd'><input size="50" name="name" /></td>
    </tr>

    <tr>
      <td width="35%" class='xtr'><?php echo $LANGAUGE_CP[514]; ?></td>
      <td width="65%" class='xtd'><input dir="ltr" size="50" name="pathfolder" /></td>
    </tr>

     <tr>
      <td width="100%" colspan="2" class='xtr' align="center"><input type="submit" value=" <?php echo $LANGAUGE_CP[18]; ?> " name="cmdAdd" /></td>
    </tr>
  </table>
</form>
<?php

$queryx = mysql_query("SELECT * FROM pathstyle order by id desc");
$xx = mysql_num_rows($queryx);
if($xx == 0){
echo "";
}else{

echo "<table class='xtable' width='100%' id='Auto44Number15'>
  <tr>
<td width='100%' colspan='6' class='xtt' align='center'>".$LANGAUGE_CP[97]."</td>
</tr>
  <tr>
      <td width='32%' align='center' class='xtr'>".$LANGAUGE_CP[515]."</td>
      <td width='40%' align='center' class='xtr'>".$LANGAUGE_CP[516]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[517]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[28]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[26]."</td>
      <td width='7%' align='center' class='xtr'>".$LANGAUGE_CP[27]."</td>
    </tr>";
while($p = mysql_fetch_array($queryx))
{
$p['name'] = stripslashes($p['name']);
$p['name'] = htmlspecialchars($p['name']);

$p['pathfolder'] = stripslashes($p['pathfolder']);
$p['pathfolder'] = htmlspecialchars($p['pathfolder']);

$d = date("j/n/Y",$p['date']);

if($p['active'] == 1){
$fx = "<img src='images/on.gif' alt='".$LANGAUGE_CP[518]."' border='0' />";
}else{
$fx = "<img src='images/off.gif' alt='".$LANGAUGE_CP[519]."' border='0' />";
}

if($p['active'] == 1){
$im = "images/on.gif";
$li = "style_cp.php?action=actx&id=$p[id]&act=0";
$te = $LANGAUGE_CP[72];
}else{
$im = "images/off.gif";
$li = "style_cp.php?action=actx&id=$p[id]&act=1";
$te = $LANGAUGE_CP[73];
}

echo "<tr>
      <td width='32%' class='xtd'>» ".$p['name']."</td>
      <td width='40%' class='xtd' align='center'>".$p['pathfolder']."</td>
      <td width='7%' align='center' class='xtd'><a href='style_cp.php?action=templates&id=$p[id]&path=".$p['pathfolder']."'><img border='0' src='images/source.gif' alt='".$LANGAUGE_CP[520]." ".$p['name']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='$li'><img border='0' src='$im' alt='$te ".$p['name']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='style_cp.php?action=edit&id=$p[id]'><img border='0' src='images/edit.gif' alt='".$p['name']."' /></a></td>
      <td width='7%' align='center' class='xtd'><a href='style_cp.php?action=delete&id=$p[id]'><img border='0' src='images/delete.gif' alt='".$p['name']."' /></a></td>
    </tr>";
}
echo "</table>";
}

}ELSEIF ($action=="default"){
$folder  = $_POST['folder'];
$allstyle = intval($_POST['allstyle']);

if($allstyle==1){
$query1 =  mysql_query("UPDATE opitions SET folder='$folder',foldernews='',folderquran='',foldersound='',folderfatawa='',folderbook='',folderanashed='',foldersignatures='',folderlinks='',folderstory='',folderdownload='',folderflash='',foldergeustbook='',folderyoutube='',foldervideo='',foldertext='' where id='1'");
}else{
$query1 = mysql_query("UPDATE opitions SET folder='$folder' where id='1'");
}

echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=style_cp.php' />";
}ELSEIF ($action=="insert"){

$name      = addslashes($_POST['name']);
$pathfolder = addslashes($_POST['pathfolder']);
$d = time();

$check = file_exists("../$pathfolder");
if(!$check)
{
echo "<div align='center'><b><font color='#FF0000'>".$LANGAUGE_CP[521]."$pathfolder</font></b></div>";
echo $f;
exit;
}

if (empty($name)){
echo $LANGAUGE_CP[522];
}elseif(empty($pathfolder)){
echo $LANGAUGE_CP[523];
}else{
$query =  mysql_query ("INSERT INTO pathstyle (name,pathfolder,active,date) VALUES ('$name','$pathfolder',1,'$d')") or die ("error");
print $LANGAUGE_CP[21];
echo "<META HTTP-EQUIV='refresh' CONTENT='1; URL=style_cp.php?action=add' />";
}

}ELSEIF ($action=="actx"){
$id = intval($_GET['id']);
$act = intval($_GET['act']);
if ($act == 0){
$query =  mysql_query("UPDATE pathstyle SET active='$act' where id='$id'");
echo $LANGAUGE_CP[61];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=style_cp.php?action=add' />";
}elseif($act == 1){
$query =  mysql_query("UPDATE pathstyle SET active='$act' where id='$id'");
echo $LANGAUGE_CP[62];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=style_cp.php?action=add' />";
}else{
echo $LANGAUGE_CP[63];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=style_cp.php?action=add' />";
}

}ELSEIF ($action=="edit"){
$id = intval($_GET['id']);
$query = mysql_query("SELECT * FROM pathstyle where id='$id'");
$p = mysql_fetch_array($query);

$p['name'] = stripslashes($p['name']);
$p['name'] = htmlspecialchars($p['name']);

$p['pathfolder'] = stripslashes($p['pathfolder']);
$p['pathfolder'] = htmlspecialchars($p['pathfolder']);

echo "<form name='vbform' method='POST' action='style_cp.php?action=editok'>
<input type='hidden' name='id' value='$p[id]' />

<table class='xtable' width='100%' id='AutoNumber15' dir='rtl'>

<tr>
<td width='100%' colspan='2' class='xtx' align='center'>".$LANGAUGE_CP[32]."</td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[513]."</td>
<td width='70%' class='xtd'><input name='name' size='60' value='".$p['name']."' /></td>
</tr>

<tr>
<td width='30%' class='xtr'>".$LANGAUGE_CP[514]."</td>
<td width='70%' class='xtd'><input dir='ltr' name='pathfolder' size='60' value='".$p['pathfolder']."' /></td>
</tr>

<tr>
<td width='20%' class='xtr'>".$LANGAUGE_CP[117]."</td>
<td width='80%' class='xtd'>
<select size='1' name='active'>";

if($p['active']==1){
echo "<option value='1' selected='selected'>".$LANGAUGE_CP[139]."</option>";
echo "<option value='0'>".$LANGAUGE_CP[140]."</option>";
}else{
echo "<option value='1'>".$LANGAUGE_CP[139]."</option>";
echo "<option value='0' selected='selected'>".$LANGAUGE_CP[140]."</option>";
}

echo "</select>
</td>
</tr>

<tr>
<td width='100%' colspan='2' align='center' class='xtr'><input type='submit' value=' ".$LANGAUGE_CP[33]." ' name='B1' /></td>
</tr>

</table>
</form>";

}ELSEIF ($action=="editok"){

$id    = intval($_POST['id']);
$name      = addslashes($_POST['name']);
$pathfolder = addslashes($_POST['pathfolder']);
$active = $_POST['active'];

$check = file_exists("../$pathfolder");
if(!$check)
{
echo "<div align='center'><b><font color='#FF0000'>".$LANGAUGE_CP[521]."$pathfolder</font></b></div>";
echo $f;
exit;
}

if (empty($name)){
echo $LANGAUGE_CP[522];
}elseif(empty($pathfolder)){
echo $LANGAUGE_CP[523];
}else{
$query =  mysql_query("UPDATE pathstyle SET name='$name', pathfolder='$pathfolder', active='$active' where id='$id'");
echo $LANGAUGE_CP[34];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=style_cp.php?action=add' />";
}

}ELSEIF ($action=="delete"){
$id = intval($_GET['id']);
$query =  mysql_query("DELETE FROM pathstyle WHERE id='$id'");
echo $LANGAUGE_CP[35];
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=style_cp.php?action=add' />";




}ELSEIF ($action=="templates"){
$id = intval($_GET['id']);
$query = mysql_query("SELECT * FROM pathstyle where id='$id'");
$p = mysql_fetch_array($query);

$p['name'] = stripslashes($p['name']);
$p['name'] = htmlspecialchars($p['name']);

$p['pathfolder'] = stripslashes($p['pathfolder']);
$filefilter = htmlspecialchars($p['pathfolder']);

$filename = "../".$filefilter;

$filename_header = "../".$filefilter."/header.htm";
$filename_footer = "../".$filefilter."/footer.htm";
$filename_table = "../".$filefilter."/table.htm";
$filename_menu = "../".$filefilter."/menu.htm";
$filename_css = "../".$filefilter."/style.css";

if(!file_exists($filename_header)){
$xxxx_h = $LANGAUGE_CP[524];
$xxxx_h_a = $filename_header;
}else{
$xxxx_h = $LANGAUGE_CP[525];
$xxxx_h_a = '<a href="style_cp.php?action=file&id='.$id.'&path='.$filefilter.'&template=header">'.$filename_header.'</a>';
}

if(!file_exists($filename_footer)){
$xxxx_f = $LANGAUGE_CP[524];
$xxxx_f_a = $filename_footer;
}else{
$xxxx_f = $LANGAUGE_CP[525];
$xxxx_f_a = '<a href="style_cp.php?action=file&id='.$id.'&path='.$filefilter.'&template=footer">'.$filename_footer.'</a>';
}


if(!file_exists($filename_table)){
$xxxx_t = $LANGAUGE_CP[524];
$xxxx_t_a = $filename_table;
}else{
$xxxx_t = $LANGAUGE_CP[525];
$xxxx_t_a = '<a href="style_cp.php?action=file&id='.$id.'&path='.$filefilter.'&template=table">'.$filename_table.'</a>';
}

if(!file_exists($filename_menu)){
$xxxx_m = $LANGAUGE_CP[524];
$xxxx_m_a = $filename_menu;
}else{
$xxxx_m = $LANGAUGE_CP[525];
$xxxx_m_a = '<a href="style_cp.php?action=file&id='.$id.'&path='.$filefilter.'&template=menu">'.$filename_menu.'</a>';
}

if(!file_exists($filename_css)){
$xxxx_s = $LANGAUGE_CP[524];
$xxxx_s_a = $filename_css;
}else{
$xxxx_s = $LANGAUGE_CP[525];
$xxxx_s_a = '<a href="style_cp.php?action=file&id='.$id.'&path='.$filefilter.'&template=style">'.$filename_css.'</a>';
}

if(!file_exists($filename)){
echo "".$LANGAUGE_CP[526]." <b>$filefilter</b> ".$LANGAUGE_CP[527]."";
echo $f;
exit;
}

if (!is_writable($filename)) {
echo "".$LANGAUGE_CP[526]." <b>$filefilter</b> ".$LANGAUGE_CP[528]."";
echo $f;
exit;
}

echo "<table class='xtable' width='100%' id='Auto44Number15'>
<tr>
<td width='100%' colspan='3' class='xtx' align='center'>".$LANGAUGE_CP[529]." ".$p['name']."</td>
</tr>

<tr>
<td width='40%' align='center' class='xtr'>".$LANGAUGE_CP[530]."</td>
<td width='40%' align='center' class='xtr'>".$LANGAUGE_CP[531]."</td>
<td width='20%' align='center' class='xtr'>".$LANGAUGE_CP[532]."</td>
</tr>

<tr>
<td width='50%' class='xtd'>".$LANGAUGE_CP[533]."</td>
<td width='40%' class='xtd' align='center' dir='ltr'>".$xxxx_h_a."</td>
<td width='10%' class='xtd' align='center'>".$xxxx_h."</td>
</tr>

<tr>
<td width='50%' class='xtd'>".$LANGAUGE_CP[534]."</td>
<td width='40%' class='xtd' align='center' dir='ltr'>".$xxxx_f_a."</td>
<td width='10%' class='xtd' align='center'>".$xxxx_f."</td>
</tr>

<tr>
<td width='50%' class='xtd'>".$LANGAUGE_CP[535]."</td>
<td width='40%' class='xtd' align='center' dir='ltr'>".$xxxx_t_a."</td>
<td width='10%' class='xtd' align='center'>".$xxxx_t."</td>
</tr>

<tr>
<td width='50%' class='xtd'>".$LANGAUGE_CP[536]."</td>
<td width='40%' class='xtd' align='center' dir='ltr'>".$xxxx_m_a."</td>
<td width='10%' class='xtd' align='center'>".$xxxx_m."</td>
</tr>

<tr>
<td width='50%' class='xtd'>".$LANGAUGE_CP[537]."</td>
<td width='40%' class='xtd' align='center' dir='ltr'>".$xxxx_s_a."</td>
<td width='10%' class='xtd' align='center'>".$xxxx_s."</td>
</tr>

</table>";


}ELSEIF ($action=="file"){
$id = intval($_GET['id']);
$query = mysql_query("SELECT * FROM pathstyle where id='$id'");
$p = mysql_fetch_array($query);

$p['name'] = stripslashes($p['name']);
$p['name'] = htmlspecialchars($p['name']);

$p['pathfolder'] = stripslashes($p['pathfolder']);
$filefilter = htmlspecialchars($p['pathfolder']);

$filename = "../".$filefilter;

$filename_header = "../".$filefilter."/header.htm";
$filename_footer = "../".$filefilter."/footer.htm";
$filename_table = "../".$filefilter."/table.htm";
$filename_menu = "../".$filefilter."/menu.htm";
$filename_css = "../".$filefilter."/style.css";

if(!file_exists($filename)){
echo "".$LANGAUGE_CP[526]." <b>$filefilter</b> ".$LANGAUGE_CP[527]."";
echo $f;
exit;
}

if (!is_writable($filename)) {
echo "".$LANGAUGE_CP[526]." <b>$filefilter</b> ".$LANGAUGE_CP[528]."";
echo $f;
exit;
}

if(!file_exists($filename_header)){
echo "".$LANGAUGE_CP[538]." <b>$filename_header</b> ".$LANGAUGE_CP[527]."";
echo $f;
exit;
}

if(!file_exists($filename_footer)){
echo "".$LANGAUGE_CP[538]." <b>$filename_footer</b> ".$LANGAUGE_CP[527]."";
echo $f;
exit;
}

if(!file_exists($filename_table)){
echo "".$LANGAUGE_CP[538]." <b>$filename_table</b> ".$LANGAUGE_CP[527]."";
echo $f;
exit;
}

if(!file_exists($filename_menu)){
echo "".$LANGAUGE_CP[538]." <b>$filename_menu</b> ".$LANGAUGE_CP[527]."";
echo $f;
exit;
}

if(!file_exists($filename_css)){
echo "".$LANGAUGE_CP[538]." <b>$filename_css</b> ".$LANGAUGE_CP[527]."";
echo $f;
exit;
}

if($_GET['template']=="header"){
$temp = $filename_header;
$fffn = "header.htm";
}elseif($_GET['template']=="footer"){
$temp = $filename_footer;
$fffn = "footer.htm";
}elseif($_GET['template']=="table"){
$temp = $filename_table;
$fffn = "table.htm";
}elseif($_GET['template']=="menu"){
$temp = $filename_menu;
$fffn = "menu.htm";
}elseif($_GET['template']=="style"){
$temp = $filename_css;
$fffn = "style.css";
}else{

}

$writefile = fopen($temp,"r");
$read = @fread($writefile,filesize($temp));

//$lines = count(file($filename_header));

echo "<form name='vbform' method='POST' action='style_cp.php?action=fileedit'>
<input type='hidden' name='pathfile' value='".$temp."' />
<input type='hidden' name='id' value='".$id."' />
<input type='hidden' name='template' value='".htmlspecialchars($_GET['template'])."' />

<table class='xtable' width='100%' id='AutoNumber15'>

<tr>
<td class='xtx' align='center'>".$LANGAUGE_CP[539]." ".$p['name']."</td>
</tr>

<tr>
<td class='xtr' align='center'>".$LANGAUGE_CP[540]." ".$fffn." ".$LANGAUGE_CP[541]." ".$filefilter."</td>
</tr>

<tr>
<td class='xtd' align='center'>
<textarea style='line-height:20px; width:670px; height:500px;' wrap='on' id='textarea1xx' dir='ltr' name='code'>".htmlspecialchars($read)."</textarea>

</td>
</tr>";

if (!is_writable($temp)) {
echo "<tr>
<td width='100%' colspan='2' align='center' class='xtr'>".$LANGAUGE_CP[542]."</td>
</tr>";
}else{
echo "<tr>
<td width='100%' colspan='2' align='center' class='xtr'><input class='buttonx' type='submit' value=' ".$LANGAUGE_CP[33]." ' name='B1' /> <input class='buttonx' type='submit' value=' ".$LANGAUGE_CP[154]." ' name='re' /></td>
</tr>";
}

echo "</table>
</form>";

fclose ($writefile);

}ELSEIF ($action=="fileedit"){
$id = intval($_POST['id']);
$template = addslashes($_POST['template']);

$path = stripslashes($_POST['pathfile']);
$filefilter = htmlspecialchars($path);
$filename = $filefilter;

$codex = $_POST['code'];
$code = stripslashes($codex);

if(!file_exists($filename)){
echo "".$LANGAUGE_CP[538]." <b>$filefilter</b> ".$LANGAUGE_CP[527]."";
echo $f;
exit;
}

if (!is_writable($filename)) {
echo "".$LANGAUGE_CP[538]." <b>$filefilter</b> ".$LANGAUGE_CP[528]."";
echo $f;
exit;
}

if (!$handle = fopen($filename, 'w')) {
echo "".$LANGAUGE_CP[543]." ($filefilter) ".$LANGAUGE_CP[544]."";
echo $f;
exit;
}

if (fwrite($handle, $code) === FALSE) {
echo "".$LANGAUGE_CP[545]." ($filefilter) ".$LANGAUGE_CP[544]."";
echo $f;
exit;
}

echo "".$LANGAUGE_CP[546]." ($filefilter)";

fclose($handle);

if(isset($_POST['re'])){
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=style_cp.php?action=file&path=".$filefilter."&id=".$id."&template=".$template."' />";
}else{
echo "<META HTTP-EQUIV='Refresh' CONTENT='1;URL=style_cp.php?action=templates&path=".$filefilter."&id=".$id."' />";
}

}
echo $f;
?>