<?php include 'sets.php';?>
<?php
$superuser="0";
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Webadmin <?php echo $domain ?></title>
<?php include 'codes.php';?>
</head>
<body>

<?php include 'navbar.php';?>

<?php
$id = $mysqli->real_escape_string(stripslashes($_REQUEST['id']));

$result = $mysqli->query("SELECT insert_id, parent FROM sections WHERE insert_id='$id' AND lang_id=$lang");
$row = $result->fetch_array(); 
$insertid=$row['insert_id'];
$parent1=$row['parent'];
?>
    
<div class="container">
<div class="frame">
<div class="frametitles fedit"><?php echo $adminedit ?>
<div class="floatright"><a href="add-section.php"><img src="img/add.png" alt="<?php echo $adminaddcat ?>" title="<?php echo $adminaddcat ?>"></a></div>
</div>
<div class="framein">
<?php
if  (isset($_POST['deleteimg'])) {
unlink("./".$filepath."sections/".$id.".jpg");
$mysqli->query("UPDATE sections SET image='0' WHERE insert_id=$id AND image>0");
}?>

<?php if ($id) { ?>
<form name="forma" method="post" enctype="multipart/form-data">
<input type="hidden" name="max_file_size" value="5000000">
<input type="hidden" name="id" value="<?php echo $id ?>">
<input type="hidden" name="level" value="<?php echo $level ?>">
<input type="hidden" name="parent" value="<?php echo $parent ?>">

<table>
    <tr>
      <td class="tabletd1">&nbsp;</td>
      <td class="tabletd2"><span class="icon fa-folder-open"></span></td>
      <td>
     <select name="parent">
     <option value="0" class="color1"><?php echo $adminmaincat ?></option> 
     <option value="0" class="color1"><?php echo $adminaddin ?></option>  
<?php
$result1 = $mysqli->query("SELECT insert_id, name FROM sections WHERE level=1 AND insert_id!='$id' AND lang_id=$lang ORDER BY priority");
while($row = $result1->fetch_array()) {
$catid=$row['insert_id'];
$section=$row['name'];
?>
  <?php if ($catid == $parent ) { ?>
          <option value="<?php echo $parent ?>" selected> 
            <?php } else { ?>
 <?php if ($catid == $parent1 ) { ?>
          <option value="<?php echo $parent1 ?>" selected> 
            <?php } else { ?>           
            <option value="<?php echo $catid ?>">
   <?php }}?>         
           &raquo; <?php echo $section ?>
            </option>
<?php } ?>
      </select>
      </td>
    </tr>
    
    </table>
    
<?php
$result30 = $mysqli->query("SELECT * FROM lang WHERE active=1 ORDER BY priority");
while($row = $result30->fetch_array()) {
$langid=$row['id'];
$language=$row['language'];
$dir=$row['dir'];
?>

<?php
$result51 = $mysqli->query("SELECT * FROM sections WHERE insert_id=$id AND lang_id=$langid");
while($row = $result51->fetch_array()) {
$page=$row['page'];
$name=$row['name'];
$text=$row['text'];
$title=$row['title'];
$description=$row['description'];
$keywords=$row['keywords'];

$insert_id=$row['insert_id'];
$lang_id=$row['lang_id'];
$image=$row['image'];
$promote=$row['promote'];
$publish=$row['publish'];
$priority=$row['priority'];
$parent=$row['parent'];
?>

<?php 
if  (isset($_POST['submit'])) {
$name = $mysqli->real_escape_string(stripslashes($_REQUEST["name$langid"]));
$name = strip_tags($name);
$name = trim($name);

$page = $mysqli->real_escape_string(stripslashes($_REQUEST["page"]));
$page = strip_tags($page);
$page = trim($page);
$page=preg_replace('/[^\p{L}\p{N}\s]/u', ' ', $page);
$page=transliterate($page);
setlocale(LC_ALL, 'en_GB'); 
$page = iconv("UTF-8", "ASCII//TRANSLIT", $page); 
$page=preg_replace("/[^a-zA-Z0-9- ]/", ' ', $page);
$page = trim($page);
$page=preg_replace('/\s+/', '', $page);
$page=strtolower(preg_replace('/\-+/', '', $page));

$resultpags = $mysqli->query("SELECT id FROM sections WHERE page='$page' AND insert_id!=$insertid AND lang_id=$langid");
$rowspags = mysqli_num_rows($resultpags);
if ($rowspags>0) {
$page=$page.$insertid;
}

$name = preg_replace('/\s+/', ' ',$name);
$text = $mysqli->real_escape_string(stripslashes($_REQUEST["text$langid"]));
$text = str_replace('\r\n', ' ',$text);
$title = $mysqli->real_escape_string(stripslashes($_REQUEST["title$langid"]));
$title = strip_tags($title);
$title = preg_replace('/\s+/', ' ',$title);
$description = $mysqli->real_escape_string(stripslashes($_REQUEST["description$langid"]));
$description = strip_tags($description);
$description = str_replace('\r\n', ' ',$description);
$description = preg_replace('/\s+/', ' ',$description);
$keywords = $mysqli->real_escape_string(stripslashes($_REQUEST["keywords$langid"]));
$keywords = strip_tags($keywords);
$keywords = str_replace('\r\n', ' ',$keywords);
$keywords = preg_replace('/\s+/', ' ',$keywords);

$image = $mysqli->real_escape_string(stripslashes($_REQUEST['image']));
$publish = $mysqli->real_escape_string(stripslashes($_REQUEST['publish']));	  
$priority = $mysqli->real_escape_string(stripslashes($_REQUEST['priority']));
$level = $mysqli->real_escape_string(stripslashes($_REQUEST['level']));
$parent = $mysqli->real_escape_string(stripslashes($_REQUEST['parent']));
$promote = $mysqli->real_escape_string(stripslashes($_REQUEST['promote']));

if( $parent==0 ){
$level='1';
} else {
$level='2';
}

$mysqli->query("UPDATE sections SET page='$page', name='$name', text='$text', title='$title', description='$description', keywords='$keywords', image='$image', promote='$promote', publish='$publish', priority='$priority', level='$level', parent='$parent'  WHERE insert_id='$id' AND lang_id=$langid");
?>
<meta http-equiv="refresh" content="0;URL=edit-section.php?id=<?php echo $id ?>">    
<?php } ?>

<hr class="overline bordercolor1">
<table>
    <tr>
      <td class="tabletd1"><img src="img/<?php echo $dir ?>.png" width="16" height="16" title="<?php echo $language ?>" alt="<?php echo $language ?>"></td> 
      <td class="tabletd2"><?php echo $adminnamed ?> *
        </td>
      <td> 
        <input type="text" name="name<?php echo $langid ?>" value="<?php echo $name ?>" size="100" required>
        </td>
    </tr>
    <tr>
      <td><img src="img/<?php echo $dir ?>.png" width="16" height="16" title="<?php echo $language ?>" alt="<?php echo $language ?>"></td>
      <td><?php echo $admintext ?> </td>
      <td><div class="diveditor"><textarea name="text<?php echo $langid ?>" cols="75" rows="10" class="mceEditor"><?php echo $text ?></textarea></div></td>
    </tr>
    </table>

<div class="divtags">    
<span class="icon icstyle1 fa-tags color2" title="meta tags"></span>
<hr>
  <table class="tcolor">
    <tr>
      <td class="tabletd1"><img src="img/<?php echo $dir ?>.png" width="16" height="16" title="<?php echo $language ?>" alt="<?php echo $language ?>"></td> 
      <td class="tabletd2"><?php echo $admintitle ?> 
        </td>
      <td> 
        <input type="text" name="title<?php echo $langid ?>" value="<?php echo $title ?>" size="100">
        </td>
    </tr>
    <tr>
      <td><img src="img/<?php echo $dir ?>.png" width="16" height="16" title="<?php echo $language ?>" alt="<?php echo $language ?>"></td>
      <td><?php echo $admindesc ?></td>
      <td><textarea name="description<?php echo $langid ?>" cols="75" rows="3"><?php echo $description ?></textarea></td>
    </tr>
    <tr class="divkeywords">
      <td><img src="img/<?php echo $dir ?>.png" width="16" height="16" title="<?php echo $language ?>" alt="<?php echo $language ?>"></td>
      <td><?php echo $adminkeywords ?> </td>
      <td><textarea name="keywords<?php echo $langid ?>" cols="75" rows="2"><?php echo $keywords ?></textarea></td>
    </tr>
    </table>
</div>
<?php } ?>
<?php } ?>

<!--NEW LANG -->

<?php
$result52 = $mysqli->query("SELECT * FROM lang WHERE id NOT IN (SELECT lang_id FROM sections WHERE insert_id='$id') AND active=1 ORDER BY main desc, priority");
$nrrows52 = mysqli_num_rows($result52);
while($row = $result52->fetch_array()) {
$langid2=$row['id'];
$language2=$row['language'];
$dir2=$row['dir'];
?>
<?php if  ($nrrows52>0) { ?>

<hr class="overline bordercolor1">
<table>
    <tr>
      <td class="tabletd1"><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td> 
      <td class="tabletd2"><?php echo $adminnamed ?> *
        </td>
      <td> 
        <input type="text" name="name<?php echo $langid2 ?>" size="100" required>
        </td>
    </tr>
    <tr>
      <td><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td>
      <td><?php echo $admintext ?> </td>
      <td><div class="diveditor"><textarea name="text<?php echo $langid2 ?>" cols="75" rows="10" class="mceEditor"></textarea></div></td>
    </tr>
    </table>

<div class="divtags">
<span class="icon icstyle1 fa-tags color2" title="meta tags"></span>
<hr>
  <table class="tcolor">
    <tr>
      <td class="tabletd1"><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td> 
      <td class="tabletd2"><?php echo $admintitle ?> 
        </td>
      <td> 
        <input type="text" name="title<?php echo $langid2 ?>" size="100">
        </td>
    </tr>
    <tr>
      <td><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td>
      <td><?php echo $admindesc ?> </td>
      <td><textarea name="description<?php echo $langid2 ?>" cols="75" rows="3"></textarea></td>
    </tr>
    <tr class="divkeywords">
      <td><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td>
      <td><?php echo $adminkeywords ?> </td>
      <td><textarea name="keywords<?php echo $langid2 ?>" cols="75" rows="2"></textarea></td>
    </tr>
    </table>
</div> 
    
<?php 
if  (isset($_POST['submit'])) {
$name = $mysqli->real_escape_string(stripslashes($_REQUEST["name$langid2"]));
$name = strip_tags($name);
$name = trim($name);
$name2 = preg_replace('/\s+/', ' ',$name);
$text2 = $mysqli->real_escape_string(stripslashes($_REQUEST["text$langid2"]));
$text2 = str_replace('\r\n', ' ',$text2);
$title2 = $mysqli->real_escape_string(stripslashes($_REQUEST["title$langid2"]));
$title2 = strip_tags($title2);
$title2 = preg_replace('/\s+/', ' ',$title2);
$description2 = $mysqli->real_escape_string(stripslashes($_REQUEST["description$langid2"]));
$description2 = strip_tags($description2);
$description2 = str_replace('\r\n', ' ',$description2);
$description2 = preg_replace('/\s+/', ' ',$description2);
$keywords2 = $mysqli->real_escape_string(stripslashes($_REQUEST["keywords$langid2"]));
$keywords2 = strip_tags($keywords2);
$keywords2 = str_replace('\r\n', ' ',$keywords2);
$keywords2 = preg_replace('/\s+/', ' ',$keywords2);

$mysqli->query("INSERT INTO sections (insert_id, lang_id, page, name, text, title, description, keywords, image, promote, publish, priority, level, parent) VALUES ('$insert_id', '$langid2', '$page', '$name2', '$text2', '$title2', '$description2', '$keywords2', '$image', '$promote', '$publish', '$priority', '$level', '$parent')");
?>
<meta http-equiv="refresh" content="0;URL=edit-section.php?id=<?php echo $id ?>">    
    
<?php } ?>
<?php } ?>
<?php } ?>

<!--END NEW LANG -->

<hr>
<table>
<tr>
      <td>&nbsp;</td>
      <td><?php echo $adminpage ?>*</td>
      <td><input name="page" type="text" value="<?php echo $page ?>" size="100" required></td>
    </tr>
    <tr>
      <td class="tabletd1">&nbsp;</td> 
      <td class="tabletd2"><span class="icon fa-image" title="<?php echo $adminimg ?>"></span></td>
      <td>
  <input type="hidden" name="image" value="1">    
  <input type="checkbox" name="image" value="<?php if (file_exists("./".$filepath."sections/".$id.".jpg")) { ?>2<?php } ?>"<?php if ($image==2) { echo " checked"; }?>> 
            
  <input name="upload" type="file" size="50" title="upload photo .jpg">    
   
<?php if (file_exists("./".$filepath."sections/".$id.".jpg")) { ?>
<img src="<?php echo $filepath ?>sections/<?php echo $id ?>.jpg" width="80">

<button type="submit" name="deleteimg" title="<?php echo $admindelete ?> <?php echo $adminimg ?>" class="buttonicon color1"><span class="icon fa-trash-o"></span></button>
<?php } ?>        
        </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-cog" title="<?php echo $adminfeatures ?>"></span></td>
      <td>
        
        <table class="widthauto aligncenter text1">
          <tr>
            <td><?php echo $adminpromote ?></td>
            </tr>
          <tr>
            <td>
<input type="hidden" name="promote" value="0">
<span class="icon icstyle fa-home"></span>
<input type="checkbox" name="promote" value="1"<?php if (preg_match("/1/", $promote)) { echo " checked"; }?>>
              </td>
            </tr>
          </table></td>
    </tr>
    <tr>
      <td>&nbsp;</td> 
      <td><span class="icon fa-eye<?php if ($publish=='no') { echo "-slash"; }?>" title="<?php echo $adminpublish ?>"></span></td>
      <td>
	<input type="hidden" name="publish" value="no"> <input type="checkbox" name="publish" value="yes"<?php if ($publish=='yes') { echo " checked"; }?>>
     </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-sort-numeric-asc" title="<?php echo $adminpriority ?>"></span></td>
      <td><input type="text" name="priority" value="<?php echo $priority ?>" size="15" maxlength="11" class="inputauto"></td>
    </tr>
    </table>

<!--UPLOAD --> 
<?php
if  ( isset($_POST['submit']) AND ($_FILES['upload']['tmp_name'] != "" ) ) {

	    $file_tmp =$_FILES['upload']['tmp_name'];
	   
		$uploadid=$id;
		$uploaddir = $filepath.'sections/';
		$uploadname = $uploadid.'.jpg'; 
	
		copy($file_tmp,$uploaddir.$uploadname);
		$mysqli->query("UPDATE sections SET image='2' WHERE insert_id=$uploadid");
	
resizephoto($uploaddir.$uploadname,$uploaddir.$uploadname,$thumb_w,$thumb_h);

}
?>   
   
   <hr>
  <div class="divallbuttons">
<div class="divlist"></div>   
<div class="divbuttons">
  <button type="submit" name="submit" class="button"><span class="icon fa-check"></span> <?php echo $adminsubmit ?></button>
  <button type="reset" name="reset" class="button buttondelete"><span class="icon fa-refresh"></span> <?php echo $adminreset ?></button> 
</div>
   </div>
   
</form>
<?php } ?> 

</div>
</div>
</div>

<?php include 'menudown.php';?>

</body>
</html>