<?php
  // ===================================== //
  // ========= User Operation ============ //
  // ===================================== //
  if (isset($_POST['userAdd'])) {
    // password encode
    $passEncode = md5(sha1($_POST["password"]));
    // 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/');
    }
    $addData=$db->prepare("INSERT INTO user SET
      firstname=:firstname,
      lastname=:lastname,
      email=:email,
      password=:password,
      image=:image,
      user_status=:user_status
      ");
    $insert=$addData->execute(array(
      'firstname'   => $_POST["firstname"],
      'lastname'    => $_POST["lastname"],
      'email'       => $_POST["email"],
      'password'    => $passEncode,
      'image'       => $vtpath,
      'user_status' => 1
    ));
    if($insert){
      Header("Location:../usersList?status=success");
    }else{
      Header("Location:../usersList?status=error");
    }
  }

  // ===================================== //
  // ========= Bank Operation ============ //
  // ===================================== //
  if (isset($_POST['banksAdd'])) {
    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["account_name"])) {
      $accname = "";
    }else{
      $accname = $_POST["account_name"];
    }
    if (empty($_POST["branch_code"])) {
      $branchcode = "";
    }else{
      $branchcode = $_POST["branch_code"];
    }
    if (empty($_POST["account_number"])) {
      $accnumber = "";
    }else{
      $accnumber = $_POST["account_number"];
    }
    if (empty($_POST["bank_iban"])) {
      $bankiban = "";
    }else{
      $bankiban = $_POST["bank_iban"];
    }

    if ($_POST['bank_name'] == "") {
      Header("Location:../banksAdd?status=titleEmptyError");
    }else{
      // Add Database
      $addData=$db->prepare("INSERT INTO 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
      ");
      $insert=$addData->execute(array(
        'bank_name'      => $_POST["bank_name"],
        'account_name'   => $accname,
        'branch_code'    => $branchcode,
        'account_number' => $accnumber,
        'bank_iban'      => $bankiban,
        'order_sort'     => $order_sort,
        'status'         => $status
      ));
      if($insert){
        Header("Location:../banksList?status=success");
      }else{
        Header("Location:../banksList?status=error");
      }
    }
  }

  // ===================================== //
  // ===== Branch Dealer Operation ======= //
  // ===================================== //
  if (isset($_POST['branchDealerAdd'])) {
    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["type"])) {
      $type = 0;
    }else{
      $type = $_POST["type"];
    }
    if (empty($_POST["email"])) {
      $email = "";
    }else{
      $email = $_POST["email"];
    }
    if (empty($_POST["phone"])) {
      $phone = "";
    }else{
      $phone = $_POST["phone"];
    }
    if (empty($_POST["map"])) {
      $map = "";
    }else{
      $map = $_POST["map"];
    }
    if ($_POST['name'] == "") {
      Header("Location:../branchDealerAdd?status=titleEmptyError");
    }else{
      // Add Database
      $addData=$db->prepare("INSERT INTO branchdealer SET
        type=:type,
        name=:name,
        email=:email,
        phone=:phone,
        map=:map,
        status=:status,
        order_sort=:order_sort
      ");
      $insert=$addData->execute(array(
        'type'       => $type,
        'name'       => $_POST["name"],
        'email'      => $email,
        'phone'      => $phone,
        'map'        => $map,
        'status'     => $status,
        'order_sort' => $order_sort
      ));
      if($insert){
        Header("Location:../branchDealerList?status=success");
      }else{
        Header("Location:../branchDealerList?status=error");
      }
    }
  }

  // ===================================== //
  // ========= Catalog Operation ========= //
  // ===================================== //
  if (isset($_POST['catalogAdd'])) {
    $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"];
    }
    if ($_POST['name'] == ""){
      Header("Location:../catalogAdd?status=titleEmptyError");
    }else{
      if ($_FILES['link']['size'] > 0) {
        // file 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 = "";
      }
      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 = "";
      }
      $addData=$db->prepare("INSERT INTO catalog SET
        link=:link,
        name=:name,
        image=:image,
        status=:status,
        order_sort=:order_sort,
        language=:language
        ");
      $insert=$addData->execute(array(
        'link'         => $vtpath,
        'name'         => $_POST["name"],
        'image'        => $vtpath2,
        'status'       => $status,
        'order_sort'   => $order_sort,
        'language'     => $_POST["language_id"]
      ));
      if($insert){
        Header("Location:../catalogList?status=success");
      }else{
        Header("Location:../catalogList?status=error");
      }
    }
  }

  // ===================================== //
  // ========= Counter Operation ========= //
  // ===================================== //
  if (isset($_POST['counterAdd'])) {
    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 = 1;
    }else{
      $count = $_POST["count"];
    }
    // Add Database
    $addData=$db->prepare("INSERT INTO counter SET
      icon=:icon,
      name=:name,
      count=:count,
      status=:status,
      order_sort=:order_sort,
      language=:language
    ");
    $insert=$addData->execute(array(
      'icon'           => $_POST["icon"],
      'name'           => $_POST["name"],
      'count'          => $count,
      'status'         => $status,
      'order_sort'     => $order_sort,
      'language'       => $_POST["language_id"]
    ));
    if($insert){
      Header("Location:../counterList?status=success");
    }else{
      Header("Location:../counterList?status=error");
    }
  }

  // ===================================== //
  // ==== Customer Comments Operation ==== //
  // ===================================== //
  if (isset($_POST['customerCommentAdd'])) {
    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["name"])) {
      $name = "";
    }else{
      $name = $_POST["name"];
    }
    if (empty($_POST["mission"])) {
      $mission = "";
    }else{
      $mission = $_POST["mission"];
    }
    if (empty($_POST["comment"])) {
      $comment = "";
    }else{
      $comment = $_POST["comment"];
    }
    // Add Database
    $addData=$db->prepare("INSERT INTO comments SET
      name=:name,
      mission=:mission,
      comment=:comment,
      status=:status,
      order_sort=:order_sort,
      language=:language
    ");
    $insert=$addData->execute(array(
      'name'           => $name,
      'mission'        => $mission,
      'comment'        => $comment,
      'status'         => $status,
      'order_sort'     => $order_sort,
      'language'       => $_POST["language_id"]
    ));
    if($insert){
      Header("Location:../customerCommentList?status=success");
    }else{
      Header("Location:../customerCommentList?status=error");
    }
  }

  // ===================================== //
  // ========= Document Operation ======== //
  // ===================================== //
  if (isset($_POST['documentAdd'])) {
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    if ($_POST['name'] == ""){
      Header("Location:../documentList?status=titleEmptyError");
    }else{
      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 = "";
      }
      $addData=$db->prepare("INSERT INTO document SET
        image=:image,
        name=:name,
        status=:status,
        order_sort=:order_sort,
        language=:language
        ");
      $insert=$addData->execute(array(
        'image'        => $vtpath,
        'name'         => $_POST["name"],
        'status'       => $status,
        'order_sort'   => $order_sort,
        'language'     => $_POST["language_id"]
      ));
      if($insert){
        Header("Location:../documentList?status=success");
      }else{
        Header("Location:../documentList?status=error");
      }
    }
  }

  // ===================================== //
  // ========= Faqs Operation ============ //
  // ===================================== //
  if (isset($_POST['faqsAdd'])) {
    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["content"])) {
      $content = 0;
    }else{
      $content = $_POST["content"];
    }
    $post_type = "post_faqs";
    $banner = "";
    $seo_title = "";
    $seo_keywords = "";
    $seo_description = "";
    $seo_url = "";
    $template = "";
    $categories = 0;
    if ($_POST['title'] == ""){
      Header("Location:../faqsAdd?status=titleEmptyError");
    }else{
      // Add Database
      $addData=$db->prepare("INSERT INTO posts SET
        post_type=:post_type,
        categories=:categories,
        banner=:banner,
        title=:title,
        content=:content,
        seo_title=:seo_title,
        seo_keywords=:seo_keywords,
        seo_description=:seo_description,
        seo_url=:seo_url,
        order_sort=:order_sort,
        language=:language,
        template=:template,
        status=:status,
        home_status=:home_status
      ");
      $insert=$addData->execute(array(
        'post_type'       => $post_type,
        'categories'      => $categories,
        'banner'          => $banner,
        'title'           => $_POST["title"],
        'content'         => $content,
        'seo_title'       => $seo_title,
        'seo_keywords'    => $seo_keywords,
        'seo_description' => $seo_description,
        'seo_url'         => $seo_url,
        'template'        => $template,
        'order_sort'      => $order_sort,
        'language'        => $_POST["language_id"],
        'status'          => $status,
        'home_status'     => 0
      ));
      if($insert){
        Header("Location:../faqsList?status=success");
      }else{
        Header("Location:../faqsList?status=error");
      }
    }
  }

  // ===================================== //
  // ========= Language Operation ======== //
  // ===================================== //
  if (isset($_POST['langAdd'])) {
    $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"];
    }
    $rowControl = $db->prepare("SELECT * FROM language WHERE country_code=:country_code");
    $rowControl->execute(array(
      'country_code' =>$_POST['country_code']
    ));
    if($rowControl->rowCount()){
      Header("Location:../languageAdd?status=langError");
    }else{
      $addData=$db->prepare("INSERT INTO language SET
        country_code=:country_code,
        status=:status,
        order_sort=:order_sort
        ");
      $insert=$addData->execute(array(
        'country_code'    => $_POST["country_code"],
        'status'          => $status,
        'order_sort'      => $order_sort
      ));
      if($insert){
          touch("../lang/". $_POST['country_code'].".php");
          $file = fopen("../lang/". $_POST['country_code'].".php", 'w');
          fwrite($file, $_POST['docs']);
          fclose($file);
        Header("Location:../languageList?status=success");
      }else{
        Header("Location:../languageList?status=error");
      }
    }
  }

  // ===================================== //
  // ========= Notice Operation ========== //
  // ===================================== //
  if (isset($_POST['noticesAdd'])) {
    // 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"];
    }
    if (empty($_POST["content"])) {
      $content = "";
    }else{
      $content = $_POST["content"];
    }
    if (empty($_POST["seo_title"])) {
      $seo_title = "";
    }else{
      $seo_title = $_POST["seo_title"];
    }
    if (empty($_POST["seo_keywords"])) {
      $seo_keywords = "";
    }else{
      $seo_keywords = $_POST["seo_keywords"];
    }
    if (empty($_POST["seo_description"])) {
      $seo_description = "";
    }else{
      $seo_description = $_POST["seo_description"];
    }
    $post_type = 'post_notices';
    $template = '';
    $categories = 0;
    $rowControl = $db->prepare("SELECT * FROM posts WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../noticesAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../noticesAdd?status=titleEmptyError");
      }else{
        // 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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO posts SET
          post_type=:post_type,
          categories=:categories,
          banner=:banner,
          title=:title,
          content=:content,
          seo_title=:seo_title,
          seo_keywords=:seo_keywords,
          seo_description=:seo_description,
          seo_url=:seo_url,
          status=:status,
          home_status=:home_status,
          order_sort=:order_sort,
          template=:template,
          language=:language
        ");
        $insert=$addData->execute(array(
          'post_type'        => $post_type,
          'categories'       => $categories,
          'banner'           => $vtpath,
          'title'            => $_POST["title"],
          'content'          => $content,
          'seo_title'        => $seo_title,
          'seo_keywords'     => $seo_keywords,
          'seo_description'  => $seo_description,
          'seo_url'          => $seoUrl,
          'status'           => $status,
          'home_status'      => 0,
          'order_sort'       => $order_sort,
          'template'         => $template,
          'language'         => $_POST["language_id"]
        ));
        if($insert){
          Header("Location:../noticesList?status=success");
        }else{
          Header("Location:../noticesList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ========= Pages Operation =========== //
  // ===================================== //
  if (isset($_POST['pagesAdd'])) {
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    if (empty($_POST["content"])) {
      $content = "";
    }else{
      $content = $_POST["content"];
    }
    if (empty($_POST["seo_title"])) {
      $seo_title = "";
    }else{
      $seo_title = $_POST["seo_title"];
    }
    if (empty($_POST["seo_keywords"])) {
      $seo_keywords = "";
    }else{
      $seo_keywords = $_POST["seo_keywords"];
    }
    if (empty($_POST["seo_description"])) {
      $seo_description = "";
    }else{
      $seo_description = $_POST["seo_description"];
    }
    $post_type = "post_page";
    $status = 1;
    $order_sort = 1;
    $categories = 0;
    $rowControl = $db->prepare("SELECT * FROM posts WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../pagesAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../pagesAdd?status=titleEmptyError");
      }else{
        // 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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO posts SET
          post_type=:post_type,
          categories=:categories,
          banner=:banner,
          title=:title,
          content=:content,
          seo_title=:seo_title,
          seo_keywords=:seo_keywords,
          seo_description=:seo_description,
          dates=:dates,
          seo_url=:seo_url,
          status=:status,
          home_status=:home_status,
          order_sort=:order_sort,
          template=:template,
          language=:language
        ");
        $insert=$addData->execute(array(
          'post_type'        => $post_type,
          'categories'       => $categories,
          'banner'           => $vtpath,
          'title'            => $_POST['title'],
          'content'          => $content,
          'seo_title'        => $seo_title,
          'seo_keywords'     => $seo_keywords,
          'seo_description'  => $seo_description,
          'dates'            => $_POST['dates'],
          'seo_url'          => $seoUrl,
          'status'           => $status,
          'home_status'      => 0,
          'order_sort'       => $order_sort,
          'template'         => $_POST['template'],
          'language'         => $_POST['language_id']
        ));
        if($insert){
          Header("Location:../pagesList?status=success");
        }else{
          Header("Location:../pagesList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ========= Person Operation ========== //
  // ===================================== //
  if (isset($_POST['personSocialAdd'])) {
    $status;
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    $addData=$db->prepare("INSERT INTO person_social SET
      icon=:icon,
      personel_id=:personel_id,
      link=:link,
      status=:status
      ");
    $insert=$addData->execute(array(
      'icon'         => $_POST["icon"],
      'personel_id'  => $_POST["personel_id"],
      'link'         => $_POST["link"],
      'status'       => $status
    ));
    if($insert){
      Header("Location:../personSocialList?status=success");
    }else{
      Header("Location:../personSocialList?status=error");
    }
  }
  if (isset($_POST['personAdd'])) {
    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["mission"])) {
      $mission = "";
    }else{
      $mission = $_POST["mission"];
    }
    if (empty($_POST["email"])) {
      $email = "";
    }else{
      $email = $_POST["email"];
    }
    if (empty($_POST["phone"])) {
      $phone = "";
    }else{
      $phone = $_POST["phone"];
    }
    if ($_POST['name'] == ""){
      Header("Location:../personAdd?status=titleEmptyError");
    }else{
      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 = "";
      }
      $addData=$db->prepare("INSERT INTO person SET
        banner=:banner,
        name=:name,
        mission=:mission,
        email=:email,
        phone=:phone,
        status=:status,
        order_sort=:order_sort
        ");
      $insert=$addData->execute(array(
        'banner'     => $vtpath,
        'name'       => $_POST["name"],
        'mission'    => $mission,
        'email'      => $email,
        'phone'      => $phone,
        'status'     => $status,
        'order_sort' => $order_sort
      ));
      if($insert){
        Header("Location:../personList?status=success");
      }else{
        Header("Location:../personList?status=error");
      }
    }
  }

  // ===================================== //
  // ========= Reference Operation ======= //
  // ===================================== //
  if (isset($_POST['referenceAdd'])) {
    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["categories"])) {
      $categories = 0;
    }else{
      $categories = $_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 ='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/');
      }
    }else{
      $vtpath = "";
    }
    // Add Database
    $addData=$db->prepare("INSERT INTO reference SET
      banner=:banner,
      categories=:categories,
      name=:name,
      link=:link,
      status=:status,
      order_sort=:order_sort,
      language=:language
    ");
    $insert=$addData->execute(array(
      'banner'       => $vtpath,
      'categories'   => $categories,
      'name'         => $_POST["name"],
      'link'         => $_POST["link"],
      'status'       => $status,
      'order_sort'   => $order_sort,
      'language'     => $_POST["language_id"]
    ));
    if($insert){
      Header("Location:../referenceList?status=success");
    }else{
      Header("Location:../referenceList?status=error");
    }
  }

  // ===================================== //
  // ========= Services Operation ======== //
  // ===================================== //
  if (isset($_POST['servicesAdd'])) {
    // 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"];
    }
    if (empty($_POST["content"])) {
      $content = "";
    }else{
      $content = $_POST["content"];
    }
    if (empty($_POST["seo_title"])) {
      $seo_title = "";
    }else{
      $seo_title = $_POST["seo_title"];
    }
    if (empty($_POST["seo_keywords"])) {
      $seo_keywords = "";
    }else{
      $seo_keywords = $_POST["seo_keywords"];
    }
    if (empty($_POST["seo_description"])) {
      $seo_description = "";
    }else{
      $seo_description = $_POST["seo_description"];
    }
    $post_type = 'post_services';
    $template = '';
    $categories = 0;
    $rowControl = $db->prepare("SELECT * FROM posts WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../servicesAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../servicesAdd?status=titleEmptyError");
      }else{
        // 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 500x333
            $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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO posts SET
          post_type=:post_type,
          categories=:categories,
          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,
          template=:template,
          language=:language
        ");
        $insert=$addData->execute(array(
          'post_type'        => $post_type,
          'categories'       => $categories,
          'banner'           => $vtpath,
          'title'            => $_POST["title"],
          'content'          => $content,
          'seo_title'        => $seo_title,
          'seo_keywords'     => $seo_keywords,
          'seo_description'  => $seo_description,
          'seo_url'          => $seoUrl,
          'status'           => $status,
          'order_sort'       => $order_sort,
          'template'         => $template,
          'language'         => $_POST["language_id"]
        ));
        if($insert){
          Header("Location:../servicesList?status=success");
        }else{
          Header("Location:../servicesList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ========= Slider Operation ========== //
  // ===================================== //
  if (isset($_POST['sliderAdd'])) {
    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/');
      }
    }else{
      $vtpath = "";
    }
    // Add Database
    $addData=$db->prepare("INSERT INTO slider SET
      banner=:banner,
      title=:title,
      content=:content,
      link=:link,
      status=:status,
      order_sort=:order_sort,
      language=:language
    ");
    $insert=$addData->execute(array(
      'banner'        => $vtpath,
      'title'         => $_POST["title"],
      'content'       => $_POST["content"],
      'link'          => $_POST["link"],
      'status'        => $status,
      'order_sort'    => $order_sort,
      'language'      => $_POST["language_id"]
    ));
    if($insert){
      Header("Location:../sliderList?status=success");
    }else{
      Header("Location:../sliderList?status=error");
    }
  }

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

  // ===================================== //
  // == Reference Categories Operation === //
  // ===================================== //
  if (isset($_POST['referenceCategoriesAdd'])) {
     $seoUrl = "";
     $seo_title = "";
     $categories_type = 'reference_categories';
     $seo_keywords = "";
     $seo_description = "";
     $vtpath = "";
     $categories_top_id = 99999;
    // 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"];
    }
    if ($_POST['title'] == "") {
      Header("Location:../referenceCategoriesAdd?status=titleEmptyError");
    }else{
      // Add Database
      $addData=$db->prepare("INSERT INTO categories SET
        categories_type=:categories_type,
        categories_top_id=:categories_top_id,
        banner=:banner,
        title=:title,
        seo_title=:seo_title,
        seo_keywords=:seo_keywords,
        seo_description=:seo_description,
        seo_url=:seo_url,
        status=:status,
        order_sort=:order_sort,
        language=:language
      ");
      $insert=$addData->execute(array(
        'categories_type'   => $categories_type,
        'categories_top_id' => $categories_top_id,
        'banner'            => $vtpath,
        'title'             => $_POST["title"],
        'seo_title'         => $seo_title,
        'seo_keywords'      => $seo_keywords,
        'seo_description'   => $seo_description,
        'seo_url'           => $seoUrl,
        'status'            => $status,
        'order_sort'        => $order_sort,
        'language'          => $_POST["language_id"]
      ));
      if($insert){
        Header("Location:../referenceCategoriesList?status=success");
      }else{
        Header("Location:../referenceCategoriesList?status=error");
      }
    }
  }

  // ===================================== //
  // ==== Project Categories Operation === //
  // ===================================== //
  if (isset($_POST['projectCategoriesAdd'])) {
    // categories type control
    $categories_type = 'project_categories';
    $categories_top_id = 99999;
    // 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"];
    }
    $rowControl = $db->prepare("SELECT * FROM categories WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../projectCategoriesAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../projectCategoriesAdd?status=titleEmptyError");
      }else{
        // 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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO categories SET
          categories_type=:categories_type,
          categories_top_id=:categories_top_id,
          banner=:banner,
          title=:title,
          seo_title=:seo_title,
          seo_keywords=:seo_keywords,
          seo_description=:seo_description,
          seo_url=:seo_url,
          status=:status,
          order_sort=:order_sort,
          language=:language
        ");
        $insert=$addData->execute(array(
          'categories_type'   => $categories_type,
          'categories_top_id' => $categories_top_id,
          'banner'            => $vtpath,
          'title'             => $_POST["title"],
          'seo_title'         => $seo_title,
          'seo_keywords'      => $seo_keywords,
          'seo_description'   => $seo_description,
          'seo_url'           => $seoUrl,
          'status'            => $status,
          'order_sort'        => $order_sort,
          'language'          => $_POST["language_id"]
        ));
        if($insert){
          Header("Location:../projectCategoriesList?status=success");
        }else{
          Header("Location:../projectCategoriesList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ==== Post Categories Operation ====== //
  // ===================================== //
  if (isset($_POST['postCategoriesAdd'])) {
    // categories type control
    $categories_type ='post_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"];
    }
    $rowControl = $db->prepare("SELECT * FROM categories WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../postCategoriesAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../postCategoriesAdd?status=titleEmptyError");
      }else{
        // 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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO categories SET
          categories_type=:categories_type,
          categories_top_id=:categories_top_id,
          banner=:banner,
          title=:title,
          seo_title=:seo_title,
          seo_keywords=:seo_keywords,
          seo_description=:seo_description,
          seo_url=:seo_url,
          status=:status,
          order_sort=:order_sort,
          language=:language
        ");
        $insert=$addData->execute(array(
          'categories_type'   => $categories_type,
          'categories_top_id' => $_POST["categories_top_id"],
          'banner'            => $vtpath,
          'title'             => $_POST["title"],
          'seo_title'         => $seo_title,
          'seo_keywords'      => $seo_keywords,
          'seo_description'   => $seo_description,
          'seo_url'           => $seoUrl,
          'status'            => $status,
          'order_sort'        => $order_sort,
          'language'          => $_POST["language_id"]
        ));
        if($insert){
          Header("Location:../postCategoriesList?status=success");
        }else{
          Header("Location:../postCategoriesList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ===== Packet Categories Operation === //
  // ===================================== //
  if (isset($_POST['packetCategoriesAdd'])) {
     $seoUrl = "";
     $seo_title = "";
     $categories_type = 'packet_categories';
     $seo_keywords = "";
     $seo_description = "";
     $vtpath = "";
     $categories_top_id = 99999;
    // 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"];
    }
    if ($_POST['title'] == "") {
      Header("Location:../packetCategoriesAdd?status=titleEmptyError");
    }else{
      // Add Database
      $addData=$db->prepare("INSERT INTO categories SET
        categories_type=:categories_type,
        categories_top_id=:categories_top_id,
        banner=:banner,
        title=:title,
        seo_title=:seo_title,
        seo_keywords=:seo_keywords,
        seo_description=:seo_description,
        seo_url=:seo_url,
        status=:status,
        order_sort=:order_sort,
        language=:language
      ");
      $insert=$addData->execute(array(
        'categories_type'   => $categories_type,
        'categories_top_id' => $categories_top_id,
        'banner'            => $vtpath,
        'title'             => $_POST["title"],
        'seo_title'         => $seo_title,
        'seo_keywords'      => $seo_keywords,
        'seo_description'   => $seo_description,
        'seo_url'           => $seoUrl,
        'status'            => $status,
        'order_sort'        => $order_sort,
        'language'          => $_POST["language_id"]
      ));
      if($insert){
        Header("Location:../packetCategoriesList?status=success");
      }else{
        Header("Location:../packetCategoriesList?status=error");
      }
    }
  }

  // ===================================== //
  // ==== Product Categories Operation === //
  // ===================================== //
  if (isset($_POST['productCategoriesAdd'])) {
    // 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"];
    }
    $rowControl = $db->prepare("SELECT * FROM categories WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../productCategoriesAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../productCategoriesAdd?status=titleEmptyError");
      }else{
        // 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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO categories SET
          categories_type=:categories_type,
          categories_top_id=:categories_top_id,
          banner=:banner,
          title=:title,
          seo_title=:seo_title,
          seo_keywords=:seo_keywords,
          seo_description=:seo_description,
          seo_url=:seo_url,
          status=:status,
          order_sort=:order_sort,
          language=:language
        ");
        $insert=$addData->execute(array(
          'categories_type'   => $categories_type,
          'categories_top_id' => $_POST["categories_top_id"],
          'banner'            => $vtpath,
          'title'             => $_POST["title"],
          'seo_title'         => $seo_title,
          'seo_keywords'      => $seo_keywords,
          'seo_description'   => $seo_description,
          'seo_url'           => $seoUrl,
          'status'            => $status,
          'order_sort'        => $order_sort,
          'language'          => $_POST["language_id"]
        ));
        if($insert){
          Header("Location:../productCategoriesList?status=success");
        }else{
          Header("Location:../productCategoriesList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ========= Project Operation ========= //
  // ===================================== //
  if (isset($_POST['projectAdd'])) {
    // 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"];
    }
    // categories type control
    $categories = $_POST['categories'];
    // 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"]);
    $post_type = 'post_projects';
    $template = '';
    $rowControl = $db->prepare("SELECT * FROM posts WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../projectAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../projectAdd?status=titleEmptyError");
      }else{
        // 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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO posts SET
          post_type=:post_type,
          categories=:categories,
          banner=:banner,
          title=:title,
          content=:content,
          dates=:dates,
          seo_url=:seo_url,
          seo_title=:seo_title,
          seo_keywords=:seo_keywords,
          seo_description=:seo_description,
          status=:status,
          home_status=:home_status,
          order_sort=:order_sort,
          template=:template,
          language=:language
        ");
        $insert=$addData->execute(array(
          'post_type'        => $post_type,
          'categories'       => $categoriesAdd,
          'banner'           => $vtpath,
          'title'            => $_POST["title"],
          'content'          => $_POST["content"],
          'dates'            => $_POST["dates"],
          'seo_url'          => $seoUrl,
          'seo_title'        => $seo_title,
          'seo_keywords'     => $seo_keywords,
          'seo_description'  => $seo_description,
          'status'           => $status,
          'home_status'      => 0,
          'order_sort'       => $order_sort,
          'template'         => $template,
          'language'         => $_POST["language_id"]
        ));
        if($insert){
         $projectPostId=$db->lastInsertId();
         // Project Table Add
         $projectAdd=$db->prepare("INSERT INTO projects SET
           project_post_id=:project_post_id,
           start_date=:start_date,
           end_date=:end_date,
           website=:website,
           video=:video,
           maps=:maps
         ");
         $projectInsert=$projectAdd->execute(array(
           'project_post_id'  => $projectPostId,
           'start_date'       => $startdate,
           'end_date'         => $finishdate,
           'website'          => $website,
           'video'            => $video,
           'maps'             => $maps
         ));
         if ($projectInsert){
           Header("Location:../projectList?status=success");
         }else{
           Header("Location:../projectList?status=error");
         }
        }else{
          Header("Location:../projectList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ========= Post Operation ============ //
  // ===================================== //
  if (isset($_POST['postAdd'])) {
    // seo url control
    if (!$_POST["seo_url"]) {
      $seoUrl = $_POST['prefix'] . seo($_POST["title"]);
    }else {
      $seoUrl = $_POST['prefix'] . seo($_POST["seo_url"]);
    }
    // post_type control
    $post_type = "post_post";
    // 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"]);
    $template = "";
    $rowControl = $db->prepare("SELECT * FROM posts WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../postAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../postAdd?status=titleEmptyError");
      }else{
        // 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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO posts SET
          post_type=:post_type,
          categories=:categories,
          banner=:banner,
          title=:title,
          content=:content,
          seo_title=:seo_title,
          seo_keywords=:seo_keywords,
          seo_description=:seo_description,
          dates=:dates,
          seo_url=:seo_url,
          status=:status,
          home_status=:home_status,
          order_sort=:order_sort,
          template=:template,
          language=:language
        ");
        $insert=$addData->execute(array(
          'post_type'        => $post_type,
          'categories'       => $categoriesAdd,
          'banner'           => $vtpath,
          'title'            => $_POST['title'],
          'content'          => $_POST['content'],
          'seo_title'        => $seo_title,
          'seo_keywords'     => $seo_keywords,
          'seo_description'  => $seo_description,
          'dates'            => $_POST['dates'],
          'seo_url'          => $seoUrl,
          'status'           => $status,
          'home_status'      => 0,
          'order_sort'       => $order_sort,
          'template'         => $template,
          'language'         => $_POST['language_id']
        ));
        if($insert){
          Header("Location:../postList?status=success");
        }else{
          Header("Location:../postList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ===== Packet Features Operation ===== //
  // ===================================== //
  if (isset($_POST['packetFeatureAdd'])) {
    // order sort control
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    $title = $_POST["title"];
    $rowControl = $db->prepare("SELECT * FROM packet_features WHERE title=:title");
    $rowControl->execute(array(
      'title' => $title
    ));
    if($rowControl->rowCount()){
      Header("Location:../packetFeatureAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../packetFeatureAdd?status=titleEmptyError");
      }else{
        // Add Database
        $addData=$db->prepare("INSERT INTO packet_features SET
          title=:title,
          order_sort=:order_sort,
          language=:language
        ");
        $insert=$addData->execute(array(
          'title'           => $_POST['title'],
          'order_sort'      => $order_sort,
          'language'        => $_POST['language_id']
        ));
        if($insert){
          Header("Location:../packetFeaturesList?status=success");
        }else{
          Header("Location:../packetFeaturesList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ========= Packets Operation ========= //
  // ===================================== //
  if (isset($_POST['packetAdd'])) {
    // 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"];
    }
    // categories control
    if (empty($_POST["categories"])) {
      $categories = 0;
    }else{
      $categories = $_POST["categories"];
    }
    $title = $_POST["title"];
    $featuresadd = implode(",",$_POST["features"]);
    if ($_POST['title'] == "") {
      Header("Location:../packetAdd?status=titleEmptyError");
    }else{
      // Add Database
      $addData=$db->prepare("INSERT INTO packets SET
        categories=:categories,
        title=:title,
        features=:features,
        price=:price,
        option_type=:option_type,
        currency=:currency,
        suggested=:suggested,
        status=:status,
        order_sort=:order_sort,
        language=:language
      ");
      $insert=$addData->execute(array(
      'categories'    => $categories,
      'title'         => $title,
      'features'      => $featuresadd,
      'price'         => $price,
      'option_type'   => $_POST["option_type"],
      'currency'      => $_POST["currency"],
      'suggested'     => $suggested,
      'status'        => $status,
      'order_sort'    => $order_sort,
      'language'      => $_POST["language_id"]
      ));
      if($insert){
        Header("Location:../packetList?status=success");
      }else{
        Header("Location:../packetList?status=error");
      }
    }
  }

  // ===================================== //
  // ========= Product Operation ========= //
  // ===================================== //
  if (isset($_POST['productAdd'])) {
    // 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"];
    }
    // categories control
    if (empty($_POST["categories"])) {
      $categories = 0;
    }else{
      $categories = $_POST["categories"];
    }
    $post_type = 'post_products';
    $template = '';
    $rowControl = $db->prepare("SELECT * FROM posts WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../productAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../productAdd?status=titleEmptyError");
      }else{
        // 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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO posts SET
          post_type=:post_type,
          banner=:banner,
          categories=:categories,
          title=:title,
          content=:content,
          seo_url=:seo_url,
          dates=:dates,
          seo_title=:seo_title,
          seo_keywords=:seo_keywords,
          seo_description=:seo_description,
          status=:status,
          home_status=:home_status,
          order_sort=:order_sort,
          template=:template,
          language=:language
        ");
        $insert=$addData->execute(array(
          'post_type'       => $post_type,
          'banner'          => $vtpath,
          'categories'      => $categories,
          'title'           => $_POST['title'],
          'content'         => $_POST['content'],
          'seo_url'         => $seoUrl,
          'dates'           => $_POST['dates'],
          'seo_title'       => $_POST['seo_title'],
          'seo_keywords'    => $_POST['seo_keywords'],
          'seo_description' => $_POST['seo_description'],
          'status'          => $status,
          'home_status'     => 0,
          'order_sort'      => $order_sort,
          'template'        => $template,
          'language'        => $_POST['language_id']
        ));
        if($insert){
          $productPostId=$db->lastInsertId();
          // Project Table Add
          $productAdd=$db->prepare("INSERT INTO products SET
            product_post_id=:product_post_id,
            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
          ");
          $productInsert=$productAdd->execute(array(
            'product_post_id'  => $productPostId,
            '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 ($productInsert){
            Header("Location:../productList?status=success");
          }else{
            Header("Location:../productList?status=error");
          }
        }else{
          Header("Location:../productList?status=error");
        }
      }
    }
  }

  // ===================================== //
  // ======== iGallery Operation ========= //
  // ===================================== //
  if (isset($_POST['GalleryAdd'])) {
    // 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"];
    }
    if (empty($_POST["content"])) {
      $content = "";
    }else{
      $content = $_POST["content"];
    }
    if (empty($_POST["seo_title"])) {
      $seo_title = "";
    }else{
      $seo_title = $_POST["seo_title"];
    }
    if (empty($_POST["seo_keywords"])) {
      $seo_keywords = "";
    }else{
      $seo_keywords = $_POST["seo_keywords"];
    }
    if (empty($_POST["seo_description"])) {
      $seo_description = "";
    }else{
      $seo_description = $_POST["seo_description"];
    }
    $iframe = "";
    $post_type = "post_Gallery";
    $template = "";
    $categories = "";
    $rowControl = $db->prepare("SELECT * FROM posts WHERE seo_url=:seo_url");
    $rowControl->execute(array(
      'seo_url' =>$seoUrl
    ));
    if($rowControl->rowCount()){
      Header("Location:../GalleryAdd?status=seoUrlError");
    }else{
      if ($_POST['title'] == "") {
        Header("Location:../GalleryAdd?status=titleEmptyError");
      }else{
        // 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->image_resize = true;
            $image->image_x = 1024;
            $image->image_y = 768;
            $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/');
          }
        }else{
          $vtpath = "";
        }
        // Add Database
        $addData=$db->prepare("INSERT INTO posts SET
          post_type=:post_type,
          categories=:categories,
          banner=:banner,
          title=:title,
          content=:content,
          seo_title=:seo_title,
          seo_keywords=:seo_keywords,
          seo_description=:seo_description,
          seo_url=:seo_url,
          dates=:dates,
          status=:status,
          home_status=:home_status,
          order_sort=:order_sort,
          template=:template,
          language=:language
        ");
        $insert=$addData->execute(array(
          'post_type'        => $post_type,
          'categories'       => $categories,
          'banner'           => $vtpath,
          'title'            => $_POST['title'],
          'content'          => $_POST['content'],
          'seo_title'        => $seo_title,
          'seo_keywords'     => $seo_keywords,
          'seo_description'  => $seo_description,
          'seo_url'          => $seoUrl,
          'dates'            => $_POST['dates'],
          'status'           => $status,
          'home_status'      => 0,
          'order_sort'       => $order_sort,
          'template'         => $template,
          'language'         => $_POST['language_id']
        ));
        if($insert){
          Header("Location:../GalleryList?status=success");
        }else{
          Header("Location:../GalleryList?status=error");
        }
      }
    }
  }
  // ===================================== //
  // ========= Menu Operation ============ //
  // ===================================== //
  if (isset($_POST['menuAdd'])) {
    // 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"];
    }
    // Add Database
    $addData=$db->prepare("INSERT INTO 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,
      language=:language
    ");
    $insert=$addData->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,
      'language'      => $_POST['language_id']
    ));
    if($insert){
      Header("Location:../menuList?status=success");
    }else{
      Header("Location:../menuList?status=error");
    }
  }

  // ===================================== //
  // ========= Skills Operation ========== //
  // ===================================== //
  if (isset($_POST['skillAdd'])) {
    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
    $addData=$db->prepare("INSERT INTO skills SET
      title=:title,
      count=:count,
      status=:status,
      order_sort=:order_sort,
      language=:language
    ");
    $insert=$addData->execute(array(
      'title'          => $_POST["title"],
      'count'          => $count,
      'status'         => $status,
      'order_sort'     => $order_sort,
      'language'       => $_POST["language_id"]
    ));
    if($insert){
      Header("Location:../skillList?status=success");
    }else{
      Header("Location:../skillList?status=error");
    }
  }

  // ===================================== //
  // ======== Proccess Operation ========= //
  // ===================================== //
  if (isset($_POST['proccessAdd'])) {
    if (empty($_POST['status'])) {
      $status = 0;
    }else {
      $status = 1;
    }
    if (empty($_POST["order_sort"])) {
      $order_sort = 0;
    }else{
      $order_sort = $_POST["order_sort"];
    }
    $post_type = "post_proccess";
    $categories = 99999;
    $seo_title = "";
    $seo_keywords = "";
    $seo_description = "";
    $seo_url = "";
    $template = "";
    if ($_POST['title'] == ""){
      Header("Location:../proccessAdd?status=titleEmptyError");
    }else{
      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 = "";
      }
      $addData=$db->prepare("INSERT INTO posts SET
        post_type=:post_type,
        categories=:categories,
        banner=:banner,
        title=:title,
        content=:content,
        seo_title=:seo_title,
        seo_keywords=:seo_keywords,
        seo_description=:seo_description,
        seo_url=:seo_url,
        dates=:dates,
        status=:status,
        order_sort=:order_sort,
        template=:template,
        home_status=:home_status,
        language=:language
        ");
      $insert=$addData->execute(array(
        'post_type'       => $post_type,
        'categories'      => $categories,
        'banner'          => $vtpath,
        'title'           => $_POST['title'],
          'content'         => $_POST['content'],
          'seo_title'       => $seo_title,
        'seo_keywords'    => $seo_keywords,
        'seo_description' => $seo_description,
        'seo_url'         => $seo_url,
        'dates'           => $_POST['dates'],
        'status'          => $status,
        'order_sort'      => $order_sort,
        'template'        => $template,
        'home_status'     => 0,
        'language'        => $_POST['language_id']
      ));
      if($insert){
        Header("Location:../proccessList?status=success");
      }else{
        Header("Location:../proccessList?status=error");
      }
    }
  }
?>
