<?php 
require_once "connect.php";
require_once "transliterate.php";
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>UPDATE ITEMS</title>
<style type="text/css">
@import url('../sf/font-awesome.min.css');
html, 
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height:130%;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
 color: #555555;
 background: #ffffff;
 margin: 0;
}
a { color: #25c4eb !important; }
.button {
display: inline-block;
padding: 10px 30px;
*margin-left: .3em;
font-size: 20px;
text-align: center;
cursor: pointer;
color: #ffffff;
text-decoration: none;
 background-color: #fc6344;
*background-color: #fc6344;
-webkit-border-radius: 3px;
 -moz-border-radius: 3px;
border-radius: 3px;
border: none;
*zoom: 1;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
}
.button:hover,
.button:focus,
.button:active,
.button.active {
background-color: #9bd161;
}
.icon {
font-family: FontAwesome;
text-decoration: none;
}
.icon:before {
display: inline-block;
text-decoration: none;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing:antialiased;
-moz-osx-font-smoothing:grayscale;
}
.icon > .label {
display: none;
}
.icstyle {
font-size: 30px;	
}
</style>
</head>

<body>

<div style="padding: 50px; text-align:center;">

<div style="padding: 10px; text-align:center;">
<a href="."><span class="icon icstyle fa-home"></span></a>
&nbsp; &nbsp; &nbsp; &nbsp; 
<a href="updateitems.php"><span class="icon icstyle fa-refresh"></span></a>
</div>
<hr>

<div style="font-size: 24px; padding-top: 100px; padding-bottom: 50px;">UPDATE ITEMS</div>

<?php
$resulttr = $mysqli->query("SELECT * FROM items");
while($row = $resulttr->fetch_array()) {	
$id=$row['id'];
$name=$row['name'];

if  (isset($_POST['submit'])) {

$pagea=transliterate($name);
setlocale(LC_ALL, 'en_GB'); 
$pageb = iconv("UTF-8", "ASCII//TRANSLIT", $pagea); 
$pagec=preg_replace("/[^a-zA-Z0-9- ]/", "", $pageb);
$paged=strtolower(preg_replace('/\s+/', '-', $pagec));
$page = preg_replace('/-{2,}/','-',$paged);

$mysqli->query("UPDATE items SET page='$page' WHERE id=$id");
}?>

<?php } ?>

<form name="forma" method="post" action="">
<button type="submit" name="submit" class="button"><span class="icon fa-check"></span> UPDATE PAGE NAMES</button>
</form>

<hr>

<?php
if  (isset($_POST['submit2'])) {
	
$result = $mysqli->query("SELECT * FROM items");
while ($row = $result->fetch_assoc()) {
$id=$row['id'];
$imageid=$row['imageid'];

 
  if(file_exists("./".$filepath."items/".$imageid." - Copy.jpg")){
    rename($filepath."items/".$imageid." - Copy.jpg",$filepath."items/".$id.".jpg");
  }


}
}?>

<form name="forma2" method="post" action="">
<button type="submit" name="submit2" class="button"><span class="icon fa-check"></span> UPDATE IMAGE NAMES</button>
</form>

</div>


</body>
</html>
