<?php include('../../config/setup.php');?>
<?php

// create
if(isset($_POST['certificate_add'])){

    $title = $_POST['certificate_title'];
    $addsugcatephoto=$_FILES['certificate_img']['name'];
    $addsubphoto="../../../img/certificate/".$addsugcatephoto;
    move_uploaded_file($_FILES["certificate_img"]["tmp_name"],$addsubphoto);
    $maincate=date('Y-m-d');
    $addsubcate=mysqli_query($config,"INSERT INTO certificate_master(certificate_title,certificate_img)
                                    VALUES('$title','$addsugcatephoto')");	
    if($addsubcate==false)
    {
        
        echo "<script>window.location.href='../certificate.php?erro=0';</script>".mysqli_error();	 
    }
    else{
        
        echo "<script>window.location.href='../certificate.php';</script>";	 

        
    }	

}

// update content
if(isset($_POST['certificate_pro']))
    {  $qid = $_POST['certificate_id'];
        $title = $_POST['certificate_title'];
    $sql = "UPDATE certificate_master SET certificate_title = '$title' WHERE certificate_id = '$qid' ";

    if($config->query($sql) == false)
    {
    echo mysqli_error();	 
    }
    else{
        
        echo "<script>window.location.href='../certificate.php?msg=100';</script>";	 
        
    }

}

// update image
if(isset($_POST['certificate_image'])){

    $cid = $_POST['certificate_id'];
    $subimage=$_FILES['certificate_img']['name'];
    $subcatephoto="../../../img/certificate/".$subimage;
    move_uploaded_file($_FILES["certificate_img"]["tmp_name"],$subcatephoto);
    $imageediton=date('Y-m-d'); 
    $sql = "UPDATE certificate_master SET certificate_img='$subimage' WHERE certificate_id = '$cid' ";

    $update_service_photo=mysqli_query($config,$sql);
    if($update_service_photo==false)
    {
    echo "<script>window.location.href='../certificate.php?erro=0';</script>".mysqli_error();	 
    }
    else{
        echo "<script>window.location.href='../certificate.php?msg=100';</script>";	 
    }

}

// delete
if($_GET['delprocat']==700){
    $cid = $_GET['delcertid'];
    $promo_delete=mysqli_query($config,"delete from certificate_master where certificate_id='$cid'");
    if($promo_delete==false)
    {
    echo "<script>window.location.href='../certificate.php?erro=0';</script>".mysqli_error();	 
    }
    else{
        
        echo "<script>window.location.href='../certificate.php?delmsg=101';</script>";	 
    }
}


?>
