<?php

session_start();
require_once "main_includes/main_class.php";
$obj = new main_front_class();
if (isset($_GET['val']) && $_GET['val'] != "") {
    $result = $obj->attach_records($_GET['val'], $_GET['table'], $_GET['field']);
}
if (isset($_POST['save'])) {
    if ($_FILES['file']['size'] != 0) {
        $name = $_FILES['file']['name'];
        $tmp_name = $_FILES['file']['tmp_name'];
        $ext = $obj->getExtension($name);
        $newName = $obj->nameGen();
        $finalName = $newName . "." . $ext;
        move_uploaded_file($tmp_name, "attachements/tender_attach/" . $finalName);
    } else {
        $finalName = 0;
        $name = 0;
    }
    $result = $obj->Update_Tender_Attachements($_POST['titles'], $_POST['other_title'], $finalName, $name, $_POST['id_firm_attachement']);
    if ($result == 1) {
        ?>
        <script>
       window.location="tender_old_attachemsnts_record.php?val=<?php 
        echo $_GET['val'];
        ?>
&table=<?php 
        echo $_GET['table'];
        ?>
&field=<?php 
}
$product_details = $obj->attach_records_products($_GET['id'], 'tender_firm_product', 'tender_id');
$attachments = $obj->attach_records($_GET['id'], 'tender_attachments', 'tender_id');
$result_attachment = $obj->AttachementsInTenderRate($_GET['id']);
//$result_tender_bid_attachemnsts = $obj->common_fetch_attachement('tender_bid_attachements','tender_id',$_GET['id']);
$result_tender_bid_attachemnsts = $obj->attach_recordsXYZ($_GET['id'], 'tender_bid_attachements', 'tender_id');
if ($tender_details['firm_status'] == 1 && $tender_details['status'] != 0) {
    $result_attachment_all = $obj->AttachementsInTenderRateWithoutLimit($_GET['id']);
}
if (isset($_POST['submit_uploaded']) && $_POST['key'] == $_SESSION['key']) {
    $finalName = array();
    $name = array();
    for ($i = 0; $i < sizeof($_FILES['files']); $i++) {
        $name[$i] = $_FILES['files']['name'][$i];
        $tmp_name = $_FILES['files']['tmp_name'][$i];
        $ext = $obj->getExtension($name[$i]);
        $newName = $obj->nameGen();
        $finalName[$i] = $newName . "." . $ext;
        move_uploaded_file($tmp_name, "attachements/Rate_On_Print/" . $finalName[$i]);
    }
    $result2 = $obj->store_printed_firms_X($_GET['id'], 'tender_rate_attachements', $finalName, $name, $_SESSION['pin_id'], $_SESSION['pin_table']);
    ?>
  <script type="text/javascript">
	window.location="tender_quot_new.php?id=<?php 
    echo $_GET['id'];
    ?>
&val=<?php 
    echo $_GET['val'];
    ?>
";
		</script>
    $result = $obj->common_fetchdata('officer', $_GET['val']);
    $office_name_id = $obj->Common_name_id('office', 'office_code', $result['officer_office']);
    $result_attachment = $obj->common_fetch_attachement('officer_attachments', 'officer_id', $_GET['val']);
}
include "main_includes/simpleimage.php";
$thumb = new SimpleImage();
if (isset($_POST['submit']) && $_POST['key'] == $_SESSION['key']) {
    //----PIC UPLAOD------------------------
    if ($_FILES['officer_photo']['name'] != "") {
        //explode()---break a string in to array
        $alloweExts = array("jpg", "jpeg", "gif", "png");
        $extension = end(explode(".", $_FILES['officer_photo']['name']));
        if ($_FILES['officer_photo']['type'] == "image/jpg" || $_FILES['officer_photo']['type'] == "image/jpeg" || $_FILES['officer_photo']['type'] == "image/gif" || $_FILES['officer_photo']['type'] == "image/png" || $_FILES['officer_photo']['size'] != 0 && in_array($extension, $alloweExts)) {
            $img_orig_name = $_FILES['officer_photo']['name'];
            $img_new_name = $obj->nameGen();
            $img_extn = $obj->getExtension($img_orig_name);
            $img_final_name = $img_new_name . "." . $img_extn;
            move_uploaded_file($_FILES['officer_photo']['tmp_name'], "photo/officer/main/" . $img_final_name);
            $thumb->load("photo/officer/main/" . $img_final_name);
            $thumb->resize(190, 180);
            $thumb->save("photo/officer/thumb/" . $img_final_name);
        }
    } else {
        $img_final_name = "no_pic.jpg";
    }
    //-------PIC UPLAOD END-----------------
    //----ATTACHEMENTS-------
    $finalName = array();
    $name = array();
    for ($i = 0; $i < sizeof($_POST['titles']); $i++) {
        $name[$i] = $_FILES['files']['name'][$i];