<?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';?>
    
<div class="container">
<div class="frame">
<div class="frametitles fadd"><?php echo $adminaddcat ?></div>
<div class="framein">

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

$result = $mysqli->query("SELECT insert_id FROM categories WHERE lang_id=$lang ORDER BY insert_id desc LIMIT 1");
$row = $result->fetch_array(); 
$isid=$row['insert_id'];
$insertid=$isid + 1;

$result = $mysqli->query("SELECT type FROM categories WHERE insert_id='$id' AND lang_id=$lang ORDER BY insert_id desc LIMIT 1");
$row = $result->fetch_array(); 
$typec1=$row['type'];
if (!$typec1) { 
$typec1=1;
}

if ($_REQUEST['typec1']) {
$typec1 = $mysqli->real_escape_string(stripslashes($_REQUEST['typec1']));
}
?>

<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 ?>">
<table>
    <tr>
      <td class="tabletd1">&nbsp;</td>
      <td class="tabletd2">
     <?php if ($id!=1) { ?> <span class="icon fa-folder-open"></span> <?php } ?>
      </td>
      <td>
<?php if ($id!=1) { ?> 
      
<select name="parent">
<option value="0" class="color1" selected><?php echo $adminmaincat ?></option>    
<option value="0" class="color1"><?php echo $adminaddin ?></option>  
<?php 
$result1 = $mysqli->query("SELECT insert_id, name FROM categories WHERE level=1 AND type<3 AND insert_id>1 AND lang_id=$lang ORDER BY priority");
while($row = $result1->fetch_array()) {
$catid=$row['insert_id'];
$category=$row['name'];
?>
<option value="<?php echo $catid ?>"<?php if ($catid==$id) { echo " selected"; }?>> 
&raquo; <?php echo $category ?>
</option>
<?php } ?>
</select>

&nbsp; &nbsp; &nbsp; &nbsp;
<?php echo $admintype ?>
&nbsp; &nbsp;
      <span title="<?php echo $admintype1 ?>" class="icon fa-list"></span>
      <input type="radio" name="typec" value="1"<?php if ($typec1==1) { echo " checked"; }?>>
      &nbsp; &nbsp; 
      <span title="<?php echo $admintype2 ?>" class="icon fa-list-alt color1"></span>
      <input type="radio" name="typec" value="2"<?php if ($typec1==2) { echo " checked"; }?>>

<?php } else { ?>
<input type="hidden" name="parent" value="0"> 
<input type="hidden" name="typec" value="1"> 
<?php } ?>      
        </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 
if  (isset($_POST['submit'])) {
$name = $mysqli->real_escape_string(stripslashes($_REQUEST["name$langid"]));
$name = strip_tags($name);
$name = trim($name);

$page=preg_replace('/[^\p{L}\p{N}\s]/u', ' ', $name);
$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 categories 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);
$text = preg_replace('/\s+/', ' ',$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);

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

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

$result = $mysqli->query("SELECT priority FROM categories WHERE type<3 AND level=$level AND parent=$parent AND insert_id!=$insertid AND lang_id=$lang ORDER BY priority desc LIMIT 1");
$row = $result->fetch_array(); 
$pid=$row['priority'];
$priorityid=$pid + 10;

$mysqli->query("INSERT INTO categories (insert_id, lang_id, page, name, text, title, description, keywords, type, publish, priority, level, parent) VALUES ('$insertid', '$langid', '$page', '$name', '$text', '$title', '$description', '$keywords', '$typec', '$publish', '$priorityid', '$level', '$parent')");
?>
<meta http-equiv="refresh" content="0;URL=add-category.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 ?>" 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"></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 ?>" 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"></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"></textarea></td>
    </tr>
    </table>
</div>
<?php } ?>

<hr>
<table>
    <tr>
      <td class="tabletd1">&nbsp;</td> 
      <td class="tabletd2"><span class="icon fa-image" title="<?php echo $adminimg ?>"></span></td>
      <td>
        <input name="upload" type="file" size="50" title="upload photo .jpg">   
        </td>
    </tr>
    <tr>
      <td>&nbsp;</td> 
      <td><span class="icon fa-eye" title="<?php echo $adminpublish ?>"></span></td>
      <td><input type="hidden" name="publish" value="no"> 
        <input type="checkbox" name="publish" value="yes" checked></td>
    </tr>
    </table>
    
<!--UPLOAD --> 
<?php
if  ( isset($_POST['submit']) AND ($_FILES['upload']['tmp_name'] != "" ) ) {

	    $file_tmp =$_FILES['upload']['tmp_name'];
	   
	    $result10 = $mysqli->query("SELECT insert_id FROM categories WHERE lang_id=$lang ORDER BY id desc LIMIT 1");
		$row = $result10->fetch_array(); 
		$uploadid=$row['insert_id'];
		
		$uploaddir = $filepath.'categories/';
		$uploadname = $uploadid.'.jpg'; 
	
		copy($file_tmp,$uploaddir.$uploadname);
		$mysqli->query("UPDATE categories 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>  

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

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

</body>
</html>