<?php
    include('../loginsession.php');
    error_reporting(E_ALL);
    $filename = __FILE__;  //---Nama file saat ini
    if (strlen(__FILE__) > 48) {$filename = substr(__FILE__, 48);}
    $save = mysqli_query($conn, "INSERT INTO novia_abc_user_logs (userid,filename) VALUES ('$userini_id','$filename')");
//-------------

    $item = "";
    $urutan = "";
	if(isset($_POST['item'])) $item = $_POST['item'];
	if(isset($_POST['urutan'])) $urutan = $_POST['urutan'];
	if(isset($_POST['submit']) && $item != ""  && $urutan != ""){
		$insert = mysqli_query($conn, "INSERT INTO novia_abc_routine_item (item,urutan) VALUES ('$item','$urutan')");
		if ($insert) {
            echo "<script>document.location='routine_edit.php'</script>";
		}
	}
	
    $eitem = "";
    $eurutan = "";
    $id = "";
	if(isset($_POST['eitem'])) $eitem = $_POST['eitem'];
	if(isset($_POST['eurutan'])) $eurutan = $_POST['eurutan'];
	if(isset($_POST['id'])) $id = $_POST['id'];
	if(isset($_POST['update']) && $eitem != ""  && $eurutan != ""){
		$update = mysqli_query($conn, "UPDATE novia_abc_routine_item SET item='$eitem', urutan='$eurutan' WHERE id = '$id'");
		if ($update) {
            echo "<script>document.location='routine_edit.php'</script>";
		}
	}	
	
	$idh = "";
	if(isset($_POST['idh'])) $idh = $_POST['idh'];
	if(isset($_POST['delete'])){
	    $delete = mysqli_query($conn, "DELETE FROM novia_abc_routine_item WHERE id = '$idh'");
	    if ($delete){
    	    echo "<script>document.location='routine_edit.php'</script>";
	    }
	}
	
	if(isset($_POST['deletetable'])){
	    $deletetable = mysqli_query($conn,"TRUNCATE TABLE novia_abc_routine");
	    if ($deletetable){
    	    $increment = mysqli_query($conn,"ALTER TABLE novia_abc_routine AUTO_INCREMENT = 1");
    	    if($increment){
    	        echo "<script>document.location='routine_edit.php'</script>";
    	    }
	    }
	}
	if(isset($_POST['ai'])) $ai = $_POST['ai'];
	if(isset($_POST['autoincrement']) && $ai != ""){
	    $autoincrement = mysqli_query($conn,"ALTER TABLE novia_abc_routine_item AUTO_INCREMENT = $ai");
	    if ($autoincrement){
    	    echo "<script>document.location='routine_edit.php'</script>";
	    }
	    if (!$autoincrement){
    	    echo "<script>document.location='../administrasi.php'</script>";
	    }
	}
$conn->close();