<?php
   // ===================================== //
   // ========= User Operation ============ //
   // ===================================== //
   if (isset($_POST['userUpdate'])) {
     $passEncode = md5(sha1($_POST["password"]));
     if ($_POST['password'] != 0) {
       $editData=$db->prepare("UPDATE user SET
         firstname=:firstname,
         lastname=:lastname,
         email=:email,
         password=:password
         WHERE user_id={$_POST['user_id']}");
       $update=$editData->execute(array(
         'firstname'    => $_POST["firstname"],
         'lastname'     => $_POST["lastname"],
         'email'        => $_POST["email"],
         'password'     => $passEncode
       ));
       if($update){
         Header("Location:../usersList?status=success");
       }else{
         Header("Location:../usersList?status=error");
       }
     }else{
       $editData=$db->prepare("UPDATE user SET
         firstname=:firstname,
         lastname=:lastname,
         email=:email
         WHERE user_id={$_POST['user_id']}");
       $update=$editData->execute(array(
         'firstname'    => $_POST["firstname"],
         'lastname'     => $_POST["lastname"],
         'email'        => $_POST["email"]
       ));
       if($update){
         Header("Location:../usersList?status=success");
       }else{
         Header("Location:../usersList?status=error");
       }
     }
   }
   if(isset($_POST['userImageUpdate'])){
     if ($_FILES['upload_image']['size'] > 0) {
       // Image Upload
       $image = new Upload($_FILES['upload_image']);
       $uploads_dir = '../uploads';
       @$name = $_FILES['upload_image']["name"];
       $extension = uzanti($name);
       $uniqnumber1 = rand(20000,32000);
       $uniqnumber2 = rand(20000,32000);
       $uniqname = $uniqnumber1.$uniqnumber2;
       $imagepath ='user_image_'.$uniqname;
       $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
       if($image->uploaded){
         $image->file_new_name_body = $imagepath;
         $image->allowed = array ('image/*');
         $image->Process('../uploads/');
       }
       $editData=$db->prepare("UPDATE user SET
         image=:image
         WHERE user_id={$_POST['user_id']}");
       $update=$editData->execute(array(
         'image'    =>  $vtpath
       ));
       if($update){
         $x = explode("/", $_POST['image']);
         mkdir('dnmdizini', 7777);
         unlink("../uploads/". $x[1]);
         rmdir('dnmdizini');
         Header("Location:../index.php?page=usersEdit&user_id={$_POST['user_id']}");
       }else{
         Header("Location:../usersList?status=error");
       }
     }else {
       Header("Location:../usersList?status=error");
     }
   }

  // ===================================== //
  // ========= Bank Operation ============ //
  // ===================================== //
  if (isset($_POST['banksUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Add Database
    $editData=$db->prepare("UPDATE banks SET
      bank_name=:bank_name,
      account_name=:account_name,
      branch_code=:branch_code,
      account_number=:account_number,
      bank_iban=:bank_iban,
      order_sort=:order_sort,
      status=:status
    WHERE bank_id={$_POST['bank_id']}");
    $update=$editData->execute(array(
      'bank_name'      => $_POST["bank_name"],
      'account_name'   => $_POST["account_name"],
      'branch_code'    => $_POST["branch_code"],
      'account_number' => $_POST["account_number"],
      'bank_iban'      => $_POST["bank_iban"],
      'order_sort'     => $order_sort,
      'status'         => $status
    ));
    if($update){
      Header("Location:../banksList?status=success");
    }else{
      Header("Location:../banksList?status=error");
    }
  }

  // ===================================== //
  // ===== Branch Dealer Operation ======= //
  // ===================================== //
  if (isset($_POST['branchDealerEdit'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Add Database
    $editData=$db->prepare("UPDATE branchdealer SET
      type=:type,
      name=:name,
      email=:email,
      phone=:phone,
      map=:map,
      status=:status,
      order_sort=:order_sort
    WHERE bd_id={$_POST['bd_id']}");
    $update=$editData->execute(array(
      'type'       => $_POST["type"],
      'name'       => $_POST["name"],
      'email'      => $_POST["email"],
      'phone'      => $_POST["phone"],
      'map'        => $_POST["map"],
      'status'     => $status,
      'order_sort' => $order_sort
    ));
    if($update){
      Header("Location:../branchDealerList?status=success");
    }else{
      Header("Location:../branchDealerList?status=error");
    }
  }

  // ===================================== //
  // ========= Catalog Operation ========= //
  // ===================================== //
  if (isset($_POST['catalogUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Control
    if ($_FILES['link']['size'] > 0) {
      // Image Upload
      $image = new Upload($_FILES['link']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['link']['name'];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='catalog_file_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('application/pdf');
        $image->Process('../uploads/');
      }
    }else{
      $vtpath = $_POST['link'];
    }
    if ($_FILES['image']['size'] > 0) {
      // Image Upload
      $image = new Upload($_FILES['image']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['image']['name'];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='catalog_image_'.$uniqname;
      $vtpath2 = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->image_resize = true;
        $image->image_x = 300;
        $image->image_y = 300;
        $image->Process('../uploads/');
      }
    }else{
      $vtpath2 = $_POST['image'];
    }
    // Edit Sql
    $editData=$db->prepare("UPDATE catalog SET
      link=:link,
      name=:name,
      image=:image,
      status=:status,
      order_sort=:order_sort
      WHERE catalog_id={$_POST['catalog_id']}");
    $update=$editData->execute(array(
      'link'         => $vtpath,
      'name'         => $_POST["name"],
      'image'        => $vtpath2,
      'status'       => $status,
      'order_sort'   => $order_sort
    ));
    if($update){
      if ($_FILES['link']['size'] > 0){
        $x = explode("/", $_POST['link']);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        rmdir('dnmdizini');
      }
      if ($_FILES['image']['size'] > 0){
        $x = explode("/", $_POST['image']);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        rmdir('dnmdizini');
      }
      Header("Location:../catalogList?status=success");
    }else{
      Header("Location:../catalogList?status=error");
    }
  }

  // ===================================== //
  // ========= Counter Operation ========= //
  // ===================================== //
  if (isset($_POST['counterUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Add Database
    $editData=$db->prepare("UPDATE counter SET
      icon=:icon,
      name=:name,
      count=:count,
      status=:status,
      order_sort=:order_sort
    WHERE counter_id={$_POST['counter_id']}");
    $update=$editData->execute(array(
      'icon'           => $_POST["icon"],
      'name'           => $_POST["name"],
      'count'          => $_POST["count"],
      'status'         => $status,
      'order_sort'     => $order_sort
    ));
    if($update){
      Header("Location:../counterList?status=success");
    }else{
      Header("Location:../counterList?status=error");
    }
  }

  // ===================================== //
  // ==== Customer Comments Operation ==== //
  // ===================================== //
  if (isset($_POST['customerCommentUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Add Database
    $editData=$db->prepare("UPDATE comments SET
      name=:name,
      mission=:mission,
      comment=:comment,
      status=:status,
      order_sort=:order_sort
    WHERE comment_id={$_POST['comment_id']}");
    $update=$editData->execute(array(
      'name'           => $_POST["name"],
      'mission'        => $_POST["mission"],
      'comment'        => $_POST["comment"],
      'status'         => $status,
      'order_sort'     => $order_sort
    ));
    if($update){
      Header("Location:../customerCommentList?status=success");
    }else{
      Header("Location:../customerCommentList?status=error");
    }
  }

  // ===================================== //
  // ========= Document Operation ======== //
  // ===================================== //
  if (isset($_POST['documentUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Control
    if ($_FILES['image']['size'] > 0) {
      // Image Upload
      $image = new Upload($_FILES['image']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['image']['name'];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='document_image_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->image_resize = true;
        $image->image_x = 1024;
        $image->image_y = 768;
        $image->Process('../uploads/');
      }
    }else{
      $vtpath = $_POST['image'];
    }
    // Edit Sql
    $editData=$db->prepare("UPDATE document SET
      name=:name,
      image=:image,
      status=:status,
      order_sort=:order_sort
      WHERE document_id={$_POST['document_id']}");
    $update=$editData->execute(array(
      'image'        => $vtpath,
      'name'         => $_POST["name"],
      'status'       => $status,
      'order_sort'   => $order_sort
    ));
    if($update){
      if ($_FILES['image']['size'] > 0){
        $x = explode("/", $_POST['image']);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        rmdir('dnmdizini');
      }
      Header("Location:../documentList?status=success");
    }else{
      Header("Location:../documentList?status=error");
    }
  }

  // ===================================== //
  // ========= Faqs Operation ============ //
  // ===================================== //
  if (isset($_POST['faqsUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Add Database
    $editData=$db->prepare("UPDATE posts SET
      title=:title,
      content=:content,
      order_sort=:order_sort,
      status=:status
    WHERE post_id={$_POST['post_id']}");
    $update=$editData->execute(array(
      'title'           => $_POST["title"],
      'content'         => $_POST["content"],
      'order_sort'      => $order_sort,
      'status'          => $status
    ));
    if($update){
      Header("Location:../faqsList?status=success");
    }else{
      Header("Location:../faqsList?status=error");
    }
  }

  // ===================================== //
  // ========= General Operation ========= //
  // ===================================== //
  if(isset($_POST['siteLogoUpdate'])){
    if ($_FILES['upload_image']['size'] > 0) {
      // Image Upload
      $image = new Upload($_FILES['upload_image']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['upload_image']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='site_logo_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $editData=$db->prepare("UPDATE general_setting SET
        site_logo=:site_logo
        WHERE general_id=1");
      $update=$editData->execute(array(
        'site_logo'    =>  $vtpath
      ));
      if($update){
        $x = explode("/", $_POST['image']);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        rmdir('dnmdizini');
        Header("Location:../generalEdit?status=success");
      }else{
        Header("Location:../generalEdit?status=error");
      }
    }else {
      Header("Location:../generalEdit?status=error");
    }
  }
  if(isset($_POST['siteLogo2Update'])){
    if ($_FILES['upload_image2']['size'] > 0) {
      // Image Upload
      $image = new Upload($_FILES['upload_image2']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['upload_image2']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='site_logo_2_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $editData=$db->prepare("UPDATE general_setting SET
        site_logo_2=:site_logo_2
        WHERE general_id=1");
      $update=$editData->execute(array(
        'site_logo_2'    =>  $vtpath
      ));
      if($update){
        $x = explode("/", $_POST['image']);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        rmdir('dnmdizini');
        Header("Location:../generalEdit?status=success");
      }else{
        Header("Location:../generalEdit?status=error");
      }
    }else {
      Header("Location:../generalEdit?status=error");
    }
  }
  if(isset($_POST['siteFavicoUpdate'])){
    if ($_FILES['upload_image']['size'] > 0) {
      // Image Upload
      $image = new Upload($_FILES['upload_image']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['upload_image']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='site_favico_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->image_resize = true;
        $image->image_ratio_crop = true;
        $image->image_x = 16;
        $image->image_y = 16;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $editData=$db->prepare("UPDATE general_setting SET
        site_favico=:site_favico
        WHERE general_id=1");
      $update=$editData->execute(array(
        'site_favico'    =>  $vtpath
      ));
      if($update){
        $x = explode("/", $_POST['image']);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        rmdir('dnmdizini');
        Header("Location:../generalEdit?status=success");
      }else{
        Header("Location:../generalEdit?status=error");
      }
    }else {
      Header("Location:../generalEdit?status=error");
    }
  }
  if(isset($_POST['siteGeneralUpdate'])){
    $editData=$db->prepare("UPDATE general_setting SET
      site_language=:site_language,
      site_url=:site_url,
      site_title=:site_title,
      site_keyw=:site_keyw,
      site_desc=:site_desc,
      site_author=:site_author,
      site_copyright=:site_copyright,
      site_email=:site_email,
      work_time=:work_time,
      contact_land_phone=:contact_land_phone,
      contact_mobile_phone=:contact_mobile_phone,
      contact_fax=:contact_fax,
      contact_adress=:contact_adress,
      site_smtphost=:site_smtphost,
      site_smtpport=:site_smtpport,
      site_smtpuser=:site_smtpuser,
      site_smtppassword=:site_smtppassword,
      site_analytics=:site_analytics,
      site_webmastertools=:site_webmastertools,
      site_maps=:site_maps,
      site_recap_sitekey=:site_recap_sitekey,
      site_recap_secretkey=:site_recap_secretkey
      WHERE general_id=1");
    $update=$editData->execute(array(
      'site_language'           =>  $_POST['site_language'],
      'site_url'                =>  $_POST['site_url'],
      'site_title'              =>  $_POST['site_title'],
      'site_keyw'               =>  $_POST['site_keyw'],
      'site_desc'               =>  $_POST['site_desc'],
      'site_author'             =>  $_POST['site_author'],
      'site_copyright'          =>  $_POST['site_copyright'],
      'site_email'              =>  $_POST['site_email'],
      'work_time'               =>  $_POST['work_time'],
      'contact_land_phone'      =>  $_POST['contact_land_phone'],
      'contact_mobile_phone'    =>  $_POST['contact_mobile_phone'],
      'contact_fax'             =>  $_POST['contact_fax'],
      'contact_adress'          =>  $_POST['contact_adress'],
      'site_smtphost'           =>  $_POST['site_smtphost'],
      'site_smtpport'           =>  $_POST['site_smtpport'],
      'site_smtpuser'           =>  $_POST['site_smtpuser'],
      'site_smtppassword'       =>  $_POST['site_smtppassword'],
      'site_analytics'          =>  $_POST['site_analytics'],
      'site_webmastertools'     =>  $_POST['site_webmastertools'],
      'site_maps'               =>  $_POST['site_maps'],
      'site_recap_sitekey'      =>  $_POST['site_recap_sitekey'],
      'site_recap_secretkey'    =>  $_POST['site_recap_secretkey']
    ));
    if($update){
      Header("Location:../generalEdit?status=success");
    }else{
      Header("Location:../generalEdit?status=error");
    }
  }

  // ===================================== //
  // ========= Language Operation ======== //
  // ===================================== //
  if (isset($_POST['langUpdate'])) {
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    $editData=$db->prepare("UPDATE language SET
      country_code=:country_code,
      status=:status,
      order_sort=:order_sort
      WHERE language_id={$_POST['language_id']}");
    $update=$editData->execute(array(
      'country_code'    => $_POST["country_code"],
      'status'          => $status,
      'order_sort'      => $order_sort
    ));
    if($update){
      file_put_contents("../lang/". $_POST['country_code'].".php", $_POST['docs']);
      Header("Location:../languageList?status=success");
    }else{
      Header("Location:../languageList?status=error");
    }
  }

  // ===================================== //
  // ========= Notice Operation ========== //
  // ===================================== //
  if (isset($_POST['noticesUpdate'])) {
    // seo url control
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='notice_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-270x300';
        $image->image_resize = true;
        $image->image_x = 270;
        $image->image_y = 300;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $x = explode("/", $_POST['isset_banner']);
      $y = explode('.', $x[1]);
      mkdir('dnmdizini', 7777);
      unlink("../uploads/". $x[1]);
      unlink("../uploads/".$y[0].'-270x300'.'.'.$y[1]);
      rmdir('dnmdizini');
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE posts SET
      banner=:banner,
      title=:title,
      content=:content,
      seo_url=:seo_url,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      status=:status,
      order_sort=:order_sort,
      seo_url=:seo_url
    WHERE post_id={$_POST['post_id']}");
    $update=$editData->execute(array(
      'banner'           => $vtpath,
      'title'            => $_POST["title"],
      'content'          => $_POST["content"],
      'seo_url'          => $seoUrl,
      'seo_title'        => $_POST["seo_title"],
      'seo_keywords'     => $_POST["seo_keywords"],
      'seo_description'  => $_POST["seo_description"],
      'status'           => $status,
      'order_sort'       => $order_sort,
      'seo_url'          => $seoUrl
    ));
    if($update){
      Header("Location:../noticesList?status=success");
    }else{
      Header("Location:../noticesList?status=error");
    }
  }

  // ===================================== //
  // ========= Pages Operation =========== //
  // ===================================== //
  if (isset($_POST['pagesUpdate'])) {
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='pages_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-270x300';
        $image->image_resize = true;
        $image->image_x = 270;
        $image->image_y = 300;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $x = explode("/", $_POST['isset_banner']);
      $y = explode('.', $x[1]);
      mkdir('dnmdizini', 7777);
      unlink("../uploads/". $x[1]);
      unlink("../uploads/".$y[0].'-270x300'.'.'.$y[1]);
      rmdir('dnmdizini');
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE posts SET
      banner=:banner,
      title=:title,
      content=:content,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      seo_url=:seo_url,
      template=:template,
      language=:language
    WHERE post_id={$_POST['post_id']}");
    $update=$editData->execute(array(
      'banner'           => $vtpath,
      'title'            => $_POST["title"],
      'content'          => $_POST["content"],
      'seo_title'        => $_POST["seo_title"],
      'seo_keywords'     => $_POST["seo_keywords"],
      'seo_description'  => $_POST["seo_description"],
      'seo_url'          => $seoUrl,
      'template'         => $_POST["template"],
      'language'         => $_POST["language_id"]
    ));
    if($update){
      Header("Location:../pagesList?status=success");
    }else{
      Header("Location:../pagesList?status=error");
    }
  }

  // ===================================== //
  // ========= Person Operation ========== //
  // ===================================== //
  if (isset($_POST['personUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Control
    if ($_FILES['upload_image']['size'] > 0) {
      // Image Upload
      $image = new Upload($_FILES['upload_image']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['upload_image']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='person_image_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Sql
    $editData=$db->prepare("UPDATE person SET
      banner=:banner,
      name=:name,
      mission=:mission,
      email=:email,
      phone=:phone,
      status=:status,
      order_sort=:order_sort
      WHERE person_id={$_POST['person_id']}");
    $update=$editData->execute(array(
      'banner'     =>  $vtpath,
      'name'       =>  $_POST['name'],
      'mission'    =>  $_POST['mission'],
      'email'      =>  $_POST['email'],
      'phone'      =>  $_POST['phone'],
      'status'     =>  $status,
      'order_sort' =>  $order_sort
    ));
    if($update){
      if ($_FILES['upload_image']['size'] > 0){
        $x = explode("/", $_POST['isset_banner']);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        rmdir('dnmdizini');
      }
      Header("Location:../personList?status=success");
    }else{
      Header("Location:../personList?status=error");
    }
  }

  // ===================================== //
  // ========= Reference Operation ======= //
  // ===================================== //
  if (isset($_POST['referenceUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='reference_logo_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-200x100';
        $image->image_resize = true;
        $image->image_x = 200;
        $image->image_y = 100;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $x = explode("/", $_POST['isset_banner']);
      $y = explode('.', $x[1]);
      mkdir('dnmdizini', 7777);
      unlink("../uploads/". $x[1]);
      unlink("../uploads/".$y[0].'-200x100'.'.'.$y[1]);
      rmdir('dnmdizini');
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE reference SET
      banner=:banner,
      categories=:categories,
      name=:name,
      link=:link,
      status=:status,
      order_sort=:order_sort
    WHERE reference_id={$_POST['reference_id']}");
    $update=$editData->execute(array(
      'banner'       => $vtpath,
      'categories'   => $_POST["categories"],
      'name'         => $_POST["name"],
      'link'         => $_POST["link"],
      'status'       => $status,
      'order_sort'   => $order_sort
    ));
    if($update){
      Header("Location:../referenceList?status=success");
    }else{
      Header("Location:../referenceList?status=error");
    }
  }

  // ===================================== //
  // ========= Services Operation ======== //
  // ===================================== //
  if (isset($_POST['servicesUpdate'])) {
    // seo url control
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='services_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-500x333';
        $image->image_resize = true;
        $image->image_x = 500;
        $image->image_y = 333;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $x = explode("/", $_POST['isset_banner']);
      $y = explode('.', $x[1]);
      mkdir('dnmdizini', 7777);
      unlink("../uploads/". $x[1]);
      unlink("../uploads/".$y[0].'-500x333'.'.'.$y[1]);
      rmdir('dnmdizini');
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE posts SET
      banner=:banner,
      title=:title,
      content=:content,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      seo_url=:seo_url,
      status=:status,
      order_sort=:order_sort
    WHERE post_id={$_POST['post_id']}");
    $update=$editData->execute(array(
      'banner'           => $vtpath,
      'title'            => $_POST["title"],
      'content'          => $_POST["content"],
      'seo_title'        => $_POST["seo_title"],
      'seo_keywords'     => $_POST["seo_keywords"],
      'seo_description'  => $_POST["seo_description"],
      'seo_url'          => $seoUrl,
      'status'           => $status,
      'order_sort'       => $order_sort
    ));
    if($update){
      Header("Location:../servicesList?status=success");
    }else{
      Header("Location:../servicesList?status=error");
    }
  }

  // ===================================== //
  // ========= Slider Operation ========= //
  // ===================================== //
  if (isset($_POST['sliderUpdate'])) {
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='slider_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $x = explode("/", $_POST['isset_banner']);
      mkdir('dnmdizini', 7777);
      unlink("../uploads/". $x[1]);
      rmdir('dnmdizini');
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE slider SET
      banner=:banner,
      title=:title,
      content=:content,
      link=:link,
      status=:status,
      order_sort=:order_sort
    WHERE slider_id={$_POST['slider_id']}");
    $update=$editData->execute(array(
      'banner'        => $vtpath,
      'title'         => $_POST["title"],
      'content'       => $_POST["content"],
      'link'          => $_POST["link"],
      'status'        => $status,
      'order_sort'    => $order_sort
    ));
    if($update){
      Header("Location:../sliderList?status=success");
    }else{
      Header("Location:../sliderList?status=error");
    }
  }

  // ===================================== //
  // ========= Social Operation ========== //
  // ===================================== //
  if (isset($_POST['socialUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Add Database
    $editData=$db->prepare("UPDATE social SET
      icon=:icon,
      name=:name,
      link=:link,
      status=:status,
      order_sort=:order_sort
    WHERE social_id={$_POST['social_id']}");
    $update=$editData->execute(array(
      'icon'           => $_POST["icon"],
      'name'           => $_POST["name"],
      'link'           => $_POST["link"],
      'status'         => $status,
      'order_sort'     => $order_sort
    ));
    if($update){
      Header("Location:../socialList?status=success");
    }else{
      Header("Location:../socialList?status=error");
    }
  }

  // ===================================== //
  // == Reference Categories Operation === //
  // ===================================== //
  if (isset($_POST['referenceCategoriesUpdate'])) {
    // status control
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    // order sort control
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE categories SET
      title=:title,
      status=:status,
      order_sort=:order_sort
    WHERE categories_id={$_POST['categories_id']}");
    $update=$editData->execute(array(
      'title'             => $_POST["title"],
      'status'            => $status,
      'order_sort'        => $order_sort
    ));
    if($update){
      Header("Location:../referenceCategoriesList?status=success");
    }else{
      Header("Location:../referenceCategoriesList?status=error");
    }
  }

  // ===================================== //
  // ==== Project Categories Operation === //
  // ===================================== //
  if (isset($_POST['projectCategoriesUpdate'])) {
    $categories_type = 'project_categories';
    // seo url control
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    // status control
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    // order sort control
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath = $categories_type.'_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-270x300';
        $image->image_resize = true;
        $image->image_x = 270;
        $image->image_y = 300;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      if(isset($_POST['isset_banner'])){
        $x = explode("/", $_POST['isset_banner']);
        $y = explode('.', $x[1]);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        unlink("../uploads/".$y[0].'-270x300'.'.'.$y[1]);
        rmdir('dnmdizini');
      }
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE categories SET
      banner=:banner,
      title=:title,
      seo_url=:seo_url,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      status=:status,
      order_sort=:order_sort
    WHERE categories_id={$_POST['categories_id']}");
    $update=$editData->execute(array(
      'banner'            => $vtpath,
      'title'             => $_POST["title"],
      'seo_url'            => $seoUrl,
      'seo_title'         => $_POST["seo_title"],
      'seo_keywords'      => $_POST["seo_keywords"],
      'seo_description'   => $_POST["seo_description"],
      'status'            => $status,
      'order_sort'        => $order_sort
    ));
    if($update){
      Header("Location:../projectCategoriesList?status=success");
    }else{
      Header("Location:../projectCategoriesList?status=error");
    }
  }

  // ===================================== //
  // ==== Post Categories Operation ====== //
  // ===================================== //
  if (isset($_POST['postCategoriesUpdate'])) {
    // seo url control
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    // status control
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    // order sort control
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // seo_title control
    if (empty($_POST["seo_title"])) {
      $seo_title = "";
    }else{
      $seo_title = $_POST["seo_title"];
    }
    // seo keywords control
    if (empty($_POST["seo_keywords"])) {
      $seo_keywords = "";
    }else{
      $seo_keywords = $_POST["seo_keywords"];
    }
    // seo description control
    if (empty($_POST["seo_description"])) {
      $seo_description = "";
    }else{
      $seo_description = $_POST["seo_description"];
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath = $categories_type.'_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-270x300';
        $image->image_resize = true;
        $image->image_x = 270;
        $image->image_y = 300;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      if(isset($_POST['isset_banner'])){
        $x = explode("/", $_POST['isset_banner']);
        $y = explode('.', $x[1]);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        unlink("../uploads/".$y[0].'-270x300'.'.'.$y[1]);
        rmdir('dnmdizini');
      }
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE categories SET
      categories_top_id=:categories_top_id,
      banner=:banner,
      title=:title,
      seo_url=:seo_url,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      status=:status,
      order_sort=:order_sort
    WHERE categories_id={$_POST['categories_id']}");
    $update=$editData->execute(array(
      'categories_top_id' => $_POST['categories_top_id'],
      'banner'            => $vtpath,
      'title'             => $_POST["title"],
      'seo_url'           => $seoUrl,
      'seo_title'         => $seo_title,
      'seo_keywords'      => $seo_keywords,
      'seo_description'   => $seo_description,
      'status'            => $status,
      'order_sort'        => $order_sort
    ));
    if($update){
      Header("Location:../postCategoriesList?status=success");
    }else{
      Header("Location:../postCategoriesList?status=error");
    }
  }

  // ===================================== //
  // ===== Packet Categories Operation === //
  // ===================================== //
  if (isset($_POST['packetCategoriesUpdate'])) {
    // status control
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    // order sort control
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE categories SET
      title=:title,
      status=:status,
      order_sort=:order_sort
    WHERE categories_id={$_POST['categories_id']}");
    $update=$editData->execute(array(
      'title'             => $_POST["title"],
      'status'            => $status,
      'order_sort'        => $order_sort
    ));
    if($update){
      Header("Location:../packetCategoriesList?status=success");
    }else{
      Header("Location:../packetCategoriesList?status=error");
    }
  }

  // ===================================== //
  // ==== Product Categories Operation === //
  // ===================================== //
  if (isset($_POST['productCategoriesUpdate'])) {
    // categories type control
    $categories_type ='product_categories';
    // seo url control
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    // status control
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    // order sort control
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // seo_title control
    if (empty($_POST["seo_title"])) {
      $seo_title = "";
    }else{
      $seo_title = $_POST["seo_title"];
    }
    // seo keywords control
    if (empty($_POST["seo_keywords"])) {
      $seo_keywords = "";
    }else{
      $seo_keywords = $_POST["seo_keywords"];
    }
    // seo description control
    if (empty($_POST["seo_description"])) {
      $seo_description = "";
    }else{
      $seo_description = $_POST["seo_description"];
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath = $categories_type.'_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-270x300';
        $image->image_resize = true;
        $image->image_x = 270;
        $image->image_y = 300;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      if(isset($_POST['isset_banner'])){
        $x = explode("/", $_POST['isset_banner']);
        $y = explode('.', $x[1]);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        unlink("../uploads/".$y[0].'-270x300'.'.'.$y[1]);
        rmdir('dnmdizini');
      }
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE categories SET
      categories_top_id=:categories_top_id,
      banner=:banner,
      title=:title,
      seo_url=:seo_url,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      status=:status,
      order_sort=:order_sort
    WHERE categories_id={$_POST['categories_id']}");
    $update=$editData->execute(array(
      'categories_top_id' => $_POST['categories_top_id'],
      'banner'            => $vtpath,
      'title'             => $_POST["title"],
      'seo_url'           => $seoUrl,
      'seo_title'         => $seo_title,
      'seo_keywords'      => $seo_keywords,
      'seo_description'   => $seo_description,
      'status'            => $status,
      'order_sort'        => $order_sort
    ));
    if($update){
      Header("Location:../productCategoriesList?status=success");
    }else{
      Header("Location:../productCategoriesList?status=error");
    }
  }


  // ===================================== //
  // ========= Project Operation ========= //
  // ===================================== //
  if (isset($_POST['projectUpdate'])) {
    // seo url control
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    // status control
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    // order sort control
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // seo_title control
    if (empty($_POST["seo_title"])) {
      $seo_title = "";
    }else{
      $seo_title = $_POST["seo_title"];
    }
    // seo keywords control
    if (empty($_POST["seo_keywords"])) {
      $seo_keywords = "";
    }else{
      $seo_keywords = $_POST["seo_keywords"];
    }
    // seo description control
    if (empty($_POST["seo_description"])) {
      $seo_description = "";
    }else{
      $seo_description = $_POST["seo_description"];
    }
    // startdate Control
    if (empty($_POST["startdate"])) {
      $startdate = "";
    }else{
      $startdate = $_POST["startdate"];
    }
    // finishdate Control
    if (empty($_POST["finishdate"])) {
      $finishdate = "";
    }else{
      $finishdate = $_POST["finishdate"];
    }
    // website Control
    if (empty($_POST["website"])) {
      $website = "";
    }else{
      $website = $_POST["website"];
    }
    // video Control
    if (empty($_POST["video"])) {
      $video = "";
    }else{
      $video = $_POST["video"];
    }
    // maps Control
    if (empty($_POST["maps"])) {
      $maps = "";
    }else{
      $maps = $_POST["maps"];
    }
    $categoriesAdd = implode(",",$_POST["categories"]);
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath = 'project_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-500x333';
        $image->image_resize = true;
        $image->image_x = 500;
        $image->image_y = 333;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $x = explode("/", $_POST['isset_banner']);
      $y = explode('.', $x[1]);
      mkdir('dnmdizini', 7777);
      unlink("../uploads/". $x[1]);
      unlink("../uploads/".$y[0].'-500x333'.'.'.$y[1]);
      rmdir('dnmdizini');
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE posts SET
      banner=:banner,
      categories=:categories,
      title=:title,
      content=:content,
      seo_url=:seo_url,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      status=:status,
      order_sort=:order_sort
    WHERE post_id={$_POST['post_id']}");
    $update=$editData->execute(array(
      'banner'           => $vtpath,
      'categories'       => $categoriesAdd,
      'title'            => $_POST["title"],
      'content'          => $_POST["content"],
      'seo_url'          => $seoUrl,
      'seo_title'        => $seo_title,
      'seo_keywords'     => $seo_keywords,
      'seo_description'  => $seo_description,
      'status'           => $status,
      'order_sort'       => $order_sort
    ));
    if($update){
      // Edit Database
      $projectEdit=$db->prepare("UPDATE projects SET
        project_post_id=:project_post_id,
        start_date=:start_date,
        end_date=:end_date,
        website=:website,
        video=:video,
        maps=:maps
      WHERE project_post_id={$_POST['post_id']}");
      $projectUpdate=$projectEdit->execute(array(
        'project_post_id'  => $_POST['post_id'],
        'start_date'       => $startdate,
        'end_date'         => $finishdate,
        'website'          => $website,
        'video'            => $video,
        'maps'             => $maps
      ));
      if ($projectUpdate){
        Header("Location:../projectList?status=success");
      }else{
        Header("Location:../projectList?status=error");
      }
    }else{
      Header("Location:../projectList?status=error");
    }
  }
  if($_GET['projectHome']=="ok"){
    $editData=$db->prepare("UPDATE posts SET
      home_status=:home_status
      WHERE post_id={$_GET['post_id']}");
    $update=$editData->execute(array(
      'home_status' => $_GET['status']
    ));
    if($update){
      Header("Location:../projectList?status=success");
    }else{
      Header("Location:../projectList?status=error");
    }
  }

  // ===================================== //
  // ========= Post Operation ============ //
  // ===================================== //
  if (isset($_POST['postUpdate'])) {
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    // status control
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    // order sort control
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // seo_title control
    if (empty($_POST["seo_title"])) {
      $seo_title = "";
    }else{
      $seo_title = $_POST["seo_title"];
    }
    // seo keywords control
    if (empty($_POST["seo_keywords"])) {
      $seo_keywords = "";
    }else{
      $seo_keywords = $_POST["seo_keywords"];
    }
    // seo description control
    if (empty($_POST["seo_description"])) {
      $seo_description = "";
    }else{
      $seo_description = $_POST["seo_description"];
    }
    $categoriesAdd = implode(",",$_POST["categories"]);
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='post_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-500x333';
        $image->image_resize = true;
        $image->image_x = 500;
        $image->image_y = 333;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $x = explode("/", $_POST['isset_banner']);
      $y = explode('.', $x[1]);
      mkdir('dnmdizini', 7777);
      unlink("../uploads/". $x[1]);
      unlink("../uploads/".$y[0].'-500x333'.'.'.$y[1]);
      rmdir('dnmdizini');
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE posts SET
      categories=:categories,
      banner=:banner,
      title=:title,
      content=:content,
      seo_url=:seo_url,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      status=:status,
      order_sort=:order_sort
    WHERE post_id={$_POST['post_id']}");
    $update=$editData->execute(array(
      'categories'       => $categoriesAdd,
      'banner'           => $vtpath,
      'title'            => $_POST['title'],
      'content'          => $_POST['content'],
      'seo_url'          => $seoUrl,
      'seo_title'        => $seo_title,
      'seo_keywords'     => $seo_keywords,
      'seo_description'  => $seo_description,
      'status'           => $status,
      'order_sort'       => $order_sort
    ));
    if($update){
      Header("Location:../postList?status=success");
    }else{
      Header("Location:../postList?status=error");
    }
  }
  if($_GET['postHome']=="ok"){
    $editData=$db->prepare("UPDATE posts SET
      home_status=:home_status
      WHERE post_id={$_GET['post_id']}");
    $update=$editData->execute(array(
      'home_status' => $_GET['status']
    ));
    if($update){
      Header("Location:../postList?status=success");
    }else{
      Header("Location:../postList?status=error");
    }
  }
  // ===================================== //
  // ===== Packet Features Operation ===== //
  // ===================================== //
  if (isset($_POST['packetFeatureUpdate'])) {
    // order sort control
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE packet_features SET
      title=:title,
      order_sort=:order_sort
    WHERE feature_id={$_POST['feature_id']}");
    $update=$editData->execute(array(
      'title'           => $_POST['title'],
      'order_sort'      => $order_sort
    ));
    if($update){
      Header("Location:../packetFeaturesList?status=success");
    }else{
      Header("Location:../packetFeaturesList?status=error");
    }
  }

  // ===================================== //
  // ========= Packets Operation ========= //
  // ===================================== //
  if (isset($_POST['packetUpdate'])) {
    // suggested control
    if (empty($_POST["suggested"])) {
      $suggested = 0;
    }else{
      $suggested = 1;
    }
    // status control
    if (empty($_POST["status"])) {
      $status = 0;
    }else{
      $status = 1;
    }
    // order_sort control
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // price control
    if (empty($_POST["price"])) {
      $price = 0;
    }else{
      $price = $_POST["price"];
    }
    $title = $_POST["title"];
    $featuresadd = implode(",",$_POST["features"]);
    // Edit Database
    $editData=$db->prepare("UPDATE packets SET
      categories=:categories,
      title=:title,
      features=:features,
      price=:price,
      option_type=:option_type,
      currency=:currency,
      suggested=:suggested,
      status=:status,
      order_sort=:order_sort
    WHERE packet_id={$_POST['packet_id']}");
    $update=$editData->execute(array(
      'categories'    => $_POST["categories"],
      'title'         => $title,
      'features'      => $featuresadd,
      'price'         => $price,
      'option_type'   => $_POST["option_type"],
      'currency'      => $_POST["currency"],
      'suggested'     => $suggested,
      'status'        => $status,
      'order_sort'    => $order_sort
    ));
    if($update){
      Header("Location:../packetList?status=success");
    }else{
      Header("Location:../packetList?status=error");
    }
  }
  if($_GET['packOrderStatus']=="ok"){
    $editData=$db->prepare("UPDATE orders SET
      status=:status
      WHERE order_id={$_GET['order_id']}");
    $update=$editData->execute(array(
      'status' => $_GET['status']
    ));
    if($update){
      Header("Location:../packetOrderList?status=success");
    }else{
      Header("Location:../packetOrderList?status=error");
    }
  }

  // ===================================== //
  // ========= Product Operation ========= //
  // ===================================== //
  if (isset($_POST['productUpdate'])) {
    // seo url control
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    // status control
    if (empty($_POST["status"])) {
      $status = 0;
    }else{
      $status = 1;
    }
    // order_sort control
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath = 'product_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
        // Image resize 270x300
        $image->file_new_name_body = $imagepath.'-270x300';
        $image->image_resize = true;
        $image->image_x = 270;
        $image->image_y = 300;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
      $x = explode("/", $_POST['isset_banner']);
      $y = explode('.', $x[1]);
      mkdir('dnmdizini', 7777);
      unlink("../uploads/". $x[1]);
      unlink("../uploads/".$y[0].'-270x300'.'.'.$y[1]);
      rmdir('dnmdizini');
    }else{
      $vtpath = $_POST['isset_banner'];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE posts SET
      banner=:banner,
      categories=:categories,
      title=:title,
      content=:content,
      seo_url=:seo_url,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      status=:status,
      order_sort=:order_sort
    WHERE post_id={$_POST['post_id']}");
    $update=$editData->execute(array(
      'banner'           => $vtpath,
      'categories'       => $_POST["categories"],
      'title'            => $_POST["title"],
      'content'          => $_POST["content"],
      'seo_url'          => $seoUrl,
      'seo_title'        => $_POST["seo_title"],
      'seo_keywords'     => $_POST["seo_keywords"],
      'seo_description'  => $_POST["seo_description"],
      'status'           => $status,
      'order_sort'       => $order_sort
    ));
    if($update){
      // Edit Database
      $productEdit=$db->prepare("UPDATE products SET
        price=:price,
        discount_price=:discount_price,
        currency=:currency,
        product_code=:product_code,
        stock_number=:stock_number,
        vat=:vat,
        other_link=:other_link,
        video=:video,
        maps=:maps,
        order_sales=:order_sales
      WHERE product_post_id={$_POST['post_id']}");
      $productUpdate=$productEdit->execute(array(
        'price'           => $_POST["price"],
        'discount_price'  => $_POST["discount_price"],
        'currency'        => $_POST["currency"],
        'product_code'    => $_POST["product_code"],
        'stock_number'    => $_POST["stock_number"],
        'vat'             => $_POST["vat"],
        'other_link'      => $_POST["other_link"],
        'video'           => $_POST["video"],
        'maps'            => $_POST["maps"],
        'order_sales'     => $_POST["order_sales"]
      ));
      if ($productUpdate){
        Header("Location:../productList?status=success");
      }else{
        Header("Location:../productList?status=error");
      }
    }else{
      Header("Location:../productList?status=error");
    }
  }
  if($_GET['productHome']=="ok"){
    $editData=$db->prepare("UPDATE posts SET
      home_status=:home_status
      WHERE post_id={$_GET['post_id']}");
    $update=$editData->execute(array(
      'home_status' => $_GET['status']
    ));
    if($update){
      Header("Location:../productList?status=success");
    }else{
      Header("Location:../productList?status=error");
    }
  }
  if($_GET['orderStatus']=="ok"){
    $editData=$db->prepare("UPDATE orders SET
      status=:status
      WHERE order_id={$_GET['order_id']}");
    $update=$editData->execute(array(
      'status' => $_GET['status']
    ));
    if($update){
      Header("Location:../productOrderList?status=success");
    }else{
      Header("Location:../productOrderList?status=error");
    }
  }
  // ===================================== //
  // ======== iGallery Operation ========= //
  // ===================================== //
  if (isset($_POST['GalleryUpdate'])) {
    // seo url control
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Image Length Control
    if ($_FILES['banner']['size'] > 0){
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']["name"];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath = 'gallery_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
        if($image->uploaded){
          $image->file_new_name_body = $imagepath;
          $image->allowed = array ('image/*');
          $image->Process('../uploads/');
          // Image resize 270x300
          $image->file_new_name_body = $imagepath.'-270x300';
          $image->image_resize = true;
          $image->image_x = 270;
          $image->image_y = 300;
          $image->allowed = array ('image/*');
          $image->Process('../uploads/');
        }
        $x = explode("/", $_POST['isset_banner']);
        $y = explode('.', $x[1]);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        unlink("../uploads/".$y[0].'-270x300'.'.'.$y[1]);
        rmdir('dnmdizini');
      }else{
        $vtpath = $_POST['isset_banner'];
      }
    // Edit Sql
    $editData=$db->prepare("UPDATE posts SET
      banner=:banner,
      title=:title,
      content=:content,
      seo_url=:seo_url,
      seo_title=:seo_title,
      seo_keywords=:seo_keywords,
      seo_description=:seo_description,
      status=:status,
      order_sort=:order_sort
      WHERE post_id={$_POST['post_id']}");
    $update=$editData->execute(array(
      'banner'          => $vtpath,
      'title'           => $_POST['title'],
      'content'         => $_POST['content'],
      'seo_url'         => $seoUrl,
      'seo_title'       => $_POST['seo_title'],
      'seo_keywords'    => $_POST['seo_keywords'],
      'seo_description' => $_POST['seo_description'],
      'status'          => $status,
      'order_sort'      => $order_sort
    ));
    if($update){
      if ($_FILES['banner']['size'] > 0){
        $x = explode("/", $_POST['banner']);
        mkdir('dnmdizini', 7777);
        unlink("../uploads/". $x[1]);
        rmdir('dnmdizini');
      }
      Header("Location:../GalleryList?status=success");
    }else{
      Header("Location:../GalleryList?status=error");
    }
  }

  // ===================================== //
  // ========= Menu Operation ============ //
  // ===================================== //
  if (isset($_POST['menuUpdate'])) {
    // newtab kontrol
    if (empty($_POST["new_tab"])) {
      $new_tab = 0;
    }else{
      $new_tab = 1;
    }
    // footer_menu kontrol
    if (empty($_POST["footer_menu"])) {
      $footer_menu = 0;
    }else{
      $footer_menu = 1;
    }
    // status control
    if (empty($_POST["status"])) {
      $status = 0;
    }else{
      $status = 1;
    }
    // order_sort control
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    // Edit Database
    $editData=$db->prepare("UPDATE menu SET
      menu_top_id=:menu_top_id,
      title=:title,
      ready_link=:ready_link,
      link=:link,
      new_tab=:new_tab,
      footer_menu=:footer_menu,
      status=:status,
      order_sort=:order_sort
    WHERE menu_id={$_POST['menu_id']}");
    $update=$editData->execute(array(
      'menu_top_id'   => $_POST['menu_top_id'],
      'title'         => $_POST['title'],
      'ready_link'    => $_POST['ready_link'],
      'link'          => $_POST['link'],
      'new_tab'       => $new_tab,
      'footer_menu'   => $footer_menu,
      'status'        => $status,
      'order_sort'    => $order_sort
    ));
    if($update){
      Header("Location:../menuList?status=success");
    }else{
      Header("Location:../menuList?status=error");
    }
  }

  // ===================================== //
  // ========= Skills Operation ========== //
  // ===================================== //
  if (isset($_POST['skillUpdate'])) {
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    if (empty($_POST['count'])) {
      $count = 0;
    }else {
      $count = $_POST['count'];
    }
    // Add Database
    $editData=$db->prepare("UPDATE skills SET
      title=:title,
      count=:count,
      status=:status,
      order_sort=:order_sort
    WHERE skill_id={$_POST['skill_id']}");
    $update=$editData->execute(array(
      'title'          => $_POST["title"],
      'count'          => $count,
      'status'         => $status,
      'order_sort'     => $order_sort
    ));
    if($update){
      Header("Location:../skillList?status=success");
    }else{
      Header("Location:../skillList?status=error");
    }
  }

  // ===================================== //
  // ======== Proccess Operation ========= //
  // ===================================== //
  if (isset($_POST['proccessEdit'])) {
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    if ($_FILES['banner']['size'] > 0) {
      // Image Upload
      $image = new Upload($_FILES['banner']);
      $uploads_dir = '../uploads';
      @$name = $_FILES['banner']['name'];
      $extension = uzanti($name);
      $uniqnumber1 = rand(20000,32000);
      $uniqnumber2 = rand(20000,32000);
      $uniqname = $uniqnumber1.$uniqnumber2;
      $imagepath ='proccess_banner_'.$uniqname;
      $vtpath = substr($uploads_dir, 3)."/".$imagepath.".".$extension;
      if($image->uploaded){
        $image->file_new_name_body = $imagepath;
        $image->allowed = array ('image/*');
        $image->Process('../uploads/');
      }
    }else{
      $vtpath = "";
    }
    $editData=$db->prepare("UPDATE posts SET
      banner=:banner,
      title=:title,
      content=:content,
      status=:status,
      order_sort=:order_sort
      WHERE post_id={$_POST['post_id']}");
    $update=$editData->execute(array(
      'banner'          => $vtpath,
      'title'           => $_POST['title'],
      'content'         => $_POST['content'],
      'status'          => $status,
      'order_sort'      => $order_sort
    ));
    if($update){
      Header("Location:../proccessList?status=success");
    }else{
      Header("Location:../proccessList?status=error");
    }
  }

  // ===================================== //
  // ========= MODULES Operation ========= //
  // ===================================== //
  if (isset($_POST['modulUpdate'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $order_sort;
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    $module_name;
    if (empty($_POST["module_name"])) {
      $module_name = "";
    }else{
      $module_name = $_POST["module_name"];
    }
    // Add Database
    $editData=$db->prepare("UPDATE modules SET
      module_name=:module_name,
      order_sort=:order_sort,
      status=:status
    WHERE module_id={$_POST['module_id']}");
    $update=$editData->execute(array(
      'module_name'    => $module_name,
      'order_sort'     => $order_sort,
      'status'         => $status
    ));
    if($update){
      Header("Location:../modules?status=success");
    }else{
      Header("Location:../modules?status=error");
    }
  }
?>
