<?php
include "include/db.php";
include "include/adminauth.php";
include "header.php";
    
if(isset($_REQUEST['cl_id'])){
    if(strlen($_REQUEST['cl_id']) > 0){
        $url_client_id = $_REQUEST['cl_id'];
        if($url_client_id != 0){
           $query_check_client = "SELECT * FROM client WHERE client_id = $url_client_id AND is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";
            $run_check_client = mysqli_query($conn, $query_check_client);
            if(mysqli_num_rows($run_check_client)!=1){
                $url_client_id = 0;
            }
        }else{
            $url_client_id = 0;
        }   
           
    }else{
        $url_client_id = 0;
    }
}else{
    $url_client_id = 0;
}
$maps_name = "";
$cat_name = "";
$description = "";
$photo_req = "";
$crew_pay = "";
$client_allow_price = "";
$min_bid_price = "";
$maps_uom = "";
$ref_photo = "";

if($conn){ 
    if(isset($_REQUEST['addgroupverify']) && isset($_REQUEST['maps_name_child']) && isset($_REQUEST['maps_name_parent'])){
        $maps_name_parent = $_REQUEST['maps_name_parent'];
        $maps_name_child = $_REQUEST['maps_name_child'];
        $time = date("Y-m-d H:i:s");

        $query_maps_group_add_check = "SELECT * FROM maps_group WHERE (parent_id = $maps_name_parent AND sub_id = $maps_name_child AND is_approve = 1  AND is_delete IS NULL) OR (parent_id = $maps_name_parent AND sub_id = $maps_name_child AND is_approve = 0  AND is_delete IS NULL)";   

        $run_maps_group_add_check = mysqli_query($conn, $query_maps_group_add_check);
            if(mysqli_num_rows($run_maps_group_add_check)==0){
                $query_maps_group_add = "INSERT INTO maps_group SET id = NULL, parent_id = $maps_name_parent, sub_id = $maps_name_child, is_approve = 1,  admin_id = $admin_id,approve_time = '$time',  create_time = '$time'";

                $run_maps_group_add = mysqli_query($conn, $query_maps_group_add);
                if(mysqli_affected_rows($conn)==1){
                    $successmessage = "MAPS Group item added";
                }else{
                    $message = "It couldn't be added due to technical reasons. Try Again!";
                }
            }else{
                $message = "The child item is already related to the Parent item. Check again.";
            }           
        

    }
    
    if(isset($_REQUEST['addnewpricelist']) && isset($_REQUEST['maps_client_list_id']) && isset($_REQUEST['maps_ext_client_list_id'])){
        if(strlen($_REQUEST['maps_client_list_id']) >0 && strlen($_REQUEST['maps_ext_client_list_id']) >0){ 
            $maps_ext_client_list_id = $_REQUEST['maps_ext_client_list_id'];
            $maps_client_list_id = $_REQUEST['maps_client_list_id'];

            $price_list_maps_check = "SELECT * FROM client WHERE client_id = $maps_client_list_id AND is_approve=1 AND is_list = 1";
            $run_price_list_maps_check = mysqli_query($conn, $price_list_maps_check);

            if(mysqli_num_rows($run_price_list_maps_check) < 1 ){
                $row_price_list_maps_check = mysqli_fetch_array($conn, $run_price_list_maps_check);
                $new_client_name = $row_price_list_maps_check['client_name'];
                if($maps_ext_client_list_id != 0){
                    $price_list_maps_check1 = "SELECT * FROM client WHERE client_id = $maps_ext_client_list_id AND is_approve=1 AND is_list = 1";
                    $run_price_list_maps_check1 = mysqli_query($conn, $price_list_maps_check1);
                    $is_exist_old = mysqli_num_rows($run_price_list_maps_check1);
                    if($is_exist_old > 0){
                        $iis_exist_old = 'yes';
                    }
                }                

                if(isset($iis_exist_old) || $maps_ext_client_list_id == 0){
                    if($maps_ext_client_list_id != 0){
                        $row_price_list_maps_check1 = mysqli_fetch_array($run_price_list_maps_check1);
                        $old_client_name = $row_price_list_maps_check1['client_name'];
                    }else{
                        $old_client_name = 'Main Price List';
                    }    
                    $price_list_maps_extract = "SELECT * FROM maps WHERE client_id = $maps_ext_client_list_id AND maps_is_delete IS NULL AND maps_approved = 1";
                    $run_price_list_maps_extract = mysqli_query($conn, $price_list_maps_extract);
                        if(mysqli_num_rows($run_price_list_maps_extract) > 0){
                            $check11 = mysqli_num_rows($run_price_list_maps_extract);
                            $check111 = 0;

                            while($row_price_list_maps_extract = mysqli_fetch_array($run_price_list_maps_extract)){                                
                            $old_maps_id = $row_price_list_maps_extract['maps_id'];
                            $maps_approved = 1;
                            $time = date("Y-m-d H:i:s");
                          
                            $maps_created_time = $time;
                            $maps_approve_time = $time;
                            $maps_ref_pic = $row_price_list_maps_extract['maps_ref_pic'];
                            
                            $maps_act_pic = $row_price_list_maps_extract['maps_act_pic'];
                            $cat_id = $row_price_list_maps_extract['cat_id'];                    
                            $maps_name = $row_price_list_maps_extract['maps_name'];
                            $maps_desc = $row_price_list_maps_extract['maps_desc'];
                            $maps_client_allow_price = $row_price_list_maps_extract['maps_client_allow_price'];
                            $maps_min_bid_price =    $row_price_list_maps_extract['maps_min_bid_price'];
                            $maps_client_inv_price =    $row_price_list_maps_extract['maps_client_inv_price'];
                            $maps_crew_pay =    $row_price_list_maps_extract['maps_crew_pay'];
                            $maps_material_cost =    $row_price_list_maps_extract['maps_material_cost'];
                            $maps_material_unit_uom_id =    $row_price_list_maps_extract['maps_material_unit_uom_id'];
                            $maps_crew_unit_uom_id =    $row_price_list_maps_extract['maps_crew_unit_uom_id'];
                            if(strlen($maps_crew_unit_uom_id) != 0){
                               $import_maps_uom_value = 'yes';
                            }

                            $maps_material_units =    $row_price_list_maps_extract['maps_material_units'];
                            if(strlen($maps_material_units) == 0){
                                $maps_material_units =NULL;
                            }
                            $maps_crew_units =    $row_price_list_maps_extract['maps_crew_units'];
                            $maps_material_unit_price =    $row_price_list_maps_extract['maps_material_unit_price'];
                            $maps_crew_unit_price =    $row_price_list_maps_extract['maps_crew_unit_price'];
                            $client_discount_percent =    $row_price_list_maps_extract['client_discount_percent'];
                            $maps_work_time_uom_id =    $row_price_list_maps_extract['maps_work_time_uom_id'];
                            $maps_work_time_units =    $row_price_list_maps_extract['maps_work_time_units'];
                            $maps_photo_req =    $row_price_list_maps_extract['maps_photo_req'];
                          
                            $maps_is_parent = $row_price_list_maps_extract['maps_is_parent'];

                            $query_maps_group00 = "INSERT INTO maps SET client_id = $maps_client_list_id, admin_id = $admin_id, maps_approved = $maps_approved, maps_created_time = '$maps_created_time',maps_approve_time = '$maps_approve_time', cat_id = $cat_id, "; 
                            if(strlen($maps_ref_pic) == 0){
                                $query_maps_group01 = '';
                            }else{
                                $query_maps_group01 = "maps_ref_pic = '$maps_ref_pic', ";

                            }
                            if(strlen($maps_act_pic) == 0){
                                $query_maps_group02 =  '';
                            }else{
                                $query_maps_group02 = "maps_act_pic = '$maps_act_pic', ";

                            }
                            if(strlen($maps_desc) == 0){
                                $query_maps_group03 = '';
                            }else{
                                $query_maps_group03 = "maps_desc = '$maps_desc', ";

                            }
                            if(strlen($maps_client_allow_price) == 0){
                                $query_maps_group04 = '';
                            }else{
                                
                            $query_maps_group04 = "maps_client_allow_price = $maps_client_allow_price, ";

                            }
                            if(strlen($maps_min_bid_price) == 0){
                                $query_maps_group05 = '';
                            }else{
                                $query_maps_group05 = "maps_min_bid_price = $maps_min_bid_price, ";

                            }
                            if(strlen($maps_client_inv_price) == 0){
                                $query_maps_group06 = '';
                            }else{
                                $query_maps_group06 = "maps_client_inv_price = $maps_client_inv_price, ";

                            }
                            if(strlen($maps_crew_pay) == 0){
                                $query_maps_group07 = '';
                            }else{
                                $query_maps_group07 = "maps_crew_pay = $maps_crew_pay, ";

                            }
                            if(strlen($maps_material_cost) == 0){
                                $query_maps_group08 = '';
                            }else{
                                $query_maps_group08 = "maps_material_cost = $maps_material_cost, ";

                            }
                            if(strlen($maps_material_unit_uom_id) == 0){
                                $query_maps_group09 = '';
                            }else{
                                $query_maps_group09 = "maps_material_unit_uom_id = $maps_material_unit_uom_id, ";
                            }
                            if(strlen($maps_crew_unit_uom_id) == 0){
                                $query_maps_group10 = '';
                            }else{
                                $query_maps_group10 = "maps_crew_unit_uom_id = $maps_crew_unit_uom_id, ";
                            }
                            if(strlen($maps_material_units) == 0){
                                $query_maps_group11 = '';
                            }else{
                                $query_maps_group11 = "maps_material_units = $maps_material_units, ";

                            }
                            if(strlen($maps_crew_units) == 0){
                                $query_maps_group12 = '';
                            }else{
                                $query_maps_group12 = "maps_crew_units = $maps_crew_units, ";

                            }
                            if(strlen($maps_material_unit_price) == 0){
                                $query_maps_group13 = '';
                            }else{
                               
                            $query_maps_group13 = "maps_material_unit_price = $maps_material_unit_price, ";

                            }
                            if(strlen($maps_crew_unit_price) == 0){
                                $query_maps_group14 = '';
                            }else{
                                $query_maps_group14 = "maps_crew_unit_price = $maps_crew_unit_price, ";
                            }
                            if(strlen($client_discount_percent) == 0){
                                $query_maps_group15 = '';
                            }else{
                                $query_maps_group15 = "client_discount_percent = $client_discount_percent, ";
                            }
                            if(strlen($maps_work_time_units) == 0){
                                $query_maps_group16 = '';
                            }else{
                                $query_maps_group16 = "maps_work_time_units = $maps_work_time_units, ";
                            }
                            if(strlen($maps_work_time_uom_id) == 0){
                                $query_maps_group17 = '';
                            }else{
                                $query_maps_group17 = "maps_work_time_uom_id = $maps_work_time_uom_id, ";
                            }
                            if(strlen($maps_photo_req) == 0){
                                $query_maps_group18 = '';
                            }else{
                                $query_maps_group18 = "maps_photo_req = '$maps_photo_req', ";
                            }
                            if(strlen($maps_is_parent) == 0){
                                $query_maps_group19 ='';
                            }else{
                                $query_maps_group19 = "maps_is_parent = $maps_is_parent, ";
                            }                     
                            
                            $query_maps_group111 = "maps_name = '$maps_name'";                    
                            
                            $query_maps_group122 = $query_maps_group00. $query_maps_group01.$query_maps_group02.$query_maps_group03.$query_maps_group04.$query_maps_group05.$query_maps_group06.$query_maps_group07.$query_maps_group08.$query_maps_group09.$query_maps_group10.$query_maps_group11.$query_maps_group12.$query_maps_group13.$query_maps_group14.$query_maps_group15.$query_maps_group16.$query_maps_group17.$query_maps_group18.$query_maps_group19. $query_maps_group111;                           
                            
                                       

                            $run_maps_group12 = mysqli_query($conn, $query_maps_group122);
                            if(mysqli_affected_rows($conn)>0){ 
                                $check111 = $check111 + 1;
                                $new_maps_id = mysqli_insert_id($conn);
                                if($import_maps_uom_value == 'yes'){
                                    $query_import_maps_uom_value = "SELECT * FROM maps_uom_value WHERE maps_id = $old_maps_id";
                                    $run_import_maps_uom_value = mysqli_query($conn, $query_import_maps_uom_value);
                                    if(mysqli_num_rows($run_import_maps_uom_value) > 0){
                                        while($row_import_maps_uom_value = mysqli_fetch_array($run_import_maps_uom_value)){
                                            $import_uom_field_id = $row_import_maps_uom_value['uom_field_id'];
                                            $import_maps_uom_value_amount = $row_import_maps_uom_value['maps_uom_value_amount'];

                                            $query_import_maps_uom_value22 = "INSERT INTO maps_uom_value SET uom_field_id = $import_uom_field_id, maps_id = $new_maps_id, maps_uom_value_amount = '$import_maps_uom_value_amount'";

                                            $run_import_maps_uom_value22 = mysqli_query($conn, $query_import_maps_uom_value22);

                                        }

                                    }else{
                                       /*  $message = "Some Error. Code 0x00003"; */
                                    } 

                                }
                               

                            }else{
                                /* $message = "Some Error Code 0x00001"; */
                            } 

                          
                            
                        }

                        if($check11 == $check111){
                            
                               $queryqqq = "SELECT * FROM maps WHERE client_id = $maps_ext_client_list_id AND maps_is_delete IS NULL AND maps_approved = 1";
                               $runqqq = mysqli_query($conn, $queryqqq);

                               if(mysqli_num_rows($runqqq) > 0){
                                   while($rowqq = mysqli_fetch_array($runqqq)){
                                        $newer_id = $rowqq['maps_id'];
                                        $newer_name = $rowqq['maps_name'];

                                        $query_nan = "SELECT * FROM maps WHERE client_id =$maps_client_list_id AND maps_name = '$newer_name' AND maps_is_delete IS NULL AND maps_approved = 1";

                                        $run_nan = mysqli_query($conn, $query_nan);
                                        $row_nan = mysqli_fetch_array($run_nan);
                                        $newer_new_id = $row_nan['maps_id'];

                                        $query_import_maps_group_value = "SELECT * FROM maps_group WHERE parent_id = $newer_id AND is_delete IS NULL AND is_approve = 1";
                                        $run_import_maps_group_value = mysqli_query($conn, $query_import_maps_group_value);
                                if(mysqli_num_rows($run_import_maps_group_value) > 0){
                                    while($row_import_maps_group_value = mysqli_fetch_array($run_import_maps_group_value)){

                                        $sub_id = $row_import_maps_group_value['sub_id'];
                                        $query_nan11 = "SELECT * FROM maps WHERE maps_id = $sub_id AND maps_is_delete IS NULL AND maps_approved = 1";

                                        $run_nan11 = mysqli_query($conn, $query_nan11);
                                        $row_nan11 = mysqli_fetch_array($run_nan11);
                                        $newer_name_sub = $row_nan11['maps_name'];


                                        $query_nan1 = "SELECT * FROM maps WHERE client_id =$maps_client_list_id AND maps_name = '$newer_name_sub' AND maps_is_delete IS NULL AND maps_approved = 1";

                                        $run_nan1 = mysqli_query($conn, $query_nan1);
                                        $row_nan1 = mysqli_fetch_array($run_nan1);
                                        $newer_new_id_sub = $row_nan1['maps_id'];                     
                                      



                                        $query_import_maps_group_value22 = "INSERT INTO maps_group SET sub_id = $newer_new_id_sub, parent_id = $newer_new_id, admin_id = $admin_id, is_approve = 1, approve_time = '$time', create_time = '$time'";

                                        $run_import_maps_group_value22 = mysqli_query($conn, $query_import_maps_group_value22);

                                    }

                                }  
                                   }
                               }                               
                          
                            $query_import_final = "UPDATE client SET is_list = 1 WHERE client_id = $maps_client_list_id";
                            $run_import_final = mysqli_query($conn, $query_import_final);
                            if(mysqli_affected_rows($conn)==1){
                                $successmessage = "New Price List created with prices from $old_client_name. Choose client Price list from top tab"; 
                            }else{
                                $message= $message."Client import Failed. Code 0x00002";
                            }
                           
                        }else{
                            $message= $message."Client import Failed. Code 0x00001.";
                        }
                       

                    }else{
                        /* $message = "Some tech error."; */
                    }//if maps has parent import
                }else{
                     $message = "That client doest have a price list";
                }

            }else{
                 $message = "The client already has a price list";
            }
        }      

    }



    if(isset($_REQUEST['addnewpricelist']) && isset($_REQUEST['maps_client_list_id']) && isset($_REQUEST['maps_ext_client_list_id'])){
        if(strlen($_REQUEST['maps_client_list_id']) >0 && strlen($_REQUEST['maps_ext_client_list_id']) ==0){ 
            $maps_client_list_id = $_REQUEST['maps_client_list_id'];

            $price_list_maps_check = "SELECT * FROM client WHERE client_id = $maps_client_list_id AND is_approve=1 AND is_list = 1";
            $run_price_list_maps_check = mysqli_query($conn, $price_list_maps_check);

            if(mysqli_num_rows($run_price_list_maps_check) < 1 ){ 
                
             $query_import_final = "UPDATE client SET is_list = 1 WHERE client_id = $maps_client_list_id";
             $run_import_final = mysqli_query($conn, $query_import_final);
                if(mysqli_affected_rows($conn)==1){
                    $successmessage = "New Empty Price List created. Choose client Price list from top tab"; 
                }else{
                   /*  $message = "Some Error Code 90";  */
                }

        }else{
        $message = "The client already has a price list";
        }
    }    

} 


    if(isset($_REQUEST['editgroup'])){
        $maps_parent_id = $_REQUEST['editgroup'];

        $query_find_maps_name = "SELECT maps_name FROM maps WHERE maps_id = $maps_parent_id";
        $run_find_maps_name = mysqli_query($conn, $query_find_maps_name);

        if(mysqli_num_rows($run_find_maps_name) == 1){
            $row_find_maps_name = mysqli_fetch_array($run_find_maps_name);
            $maps_parent_name = $row_find_maps_name['maps_name'];

        }
    
    }

    
    if(isset($_REQUEST['conf-group-delete'])){
        $maps_delete_group_id = $_REQUEST['conf-group-delete'];
        $maps_delete_group_name = $_REQUEST['maps_name'];

        $query_delete_group = "UPDATE maps_group SET is_delete = 1 WHERE id = $maps_delete_group_id";
        $run_delete_group = mysqli_query($conn, $query_delete_group);

        if(mysqli_affected_rows($conn) == 1){
            $successmessage = "$maps_delete_group_name is deleted from the group.";

        }else{
            $message = "Couldn't be deleted. Try again.";
        }
    
    }


    if(isset($_REQUEST['conf-delete']) && isset($_REQUEST['maps_name'])){
        $maps_id = $_REQUEST['conf-delete'];
        $maps_name = $_REQUEST['maps_name'];
        $query = "UPDATE maps SET maps_is_delete = 1 WHERE maps_id = $maps_id";
        $run = mysqli_query($conn, $query);

        if(mysqli_affected_rows($conn)>0){
            $successmessage = "$maps_name is sucessfully Deleted from MAPS";

        }else{
            $message = 'There was a technical error. Try Again' ;
        }

    }
    
    if(isset($_REQUEST['conf-cat-delete']) && isset($_REQUEST['cat_name'])){
        $cat_id = $_REQUEST['conf-cat-delete'];
        $cat_name = $_REQUEST['cat_name'];
        $query = "UPDATE category SET cat_is_delete = 1 WHERE cat_id = $cat_id";
        $run = mysqli_query($conn, $query);

        if(mysqli_affected_rows($conn)>0){
            $successmessage = "$cat_name is sucessfully Deleted";

        }else{
            $message = 'There was a technical error. Try Again' ;
        }

    }

    if(isset($_REQUEST['editcat'])){
        $cat_id = $_REQUEST['editcat'];
        $query = "SELECT * FROM category WHERE cat_id = $cat_id AND cat_is_delete IS NULL"; 
        $run = mysqli_query($conn, $query);

        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){    
                $cat_name = $row['cat_name'];                
                $description = $row['cat_desc'];              
                

            }
        }
    }

      
    if(isset($_REQUEST['addgroupapprove'])){
        $groupapprove_id = $_REQUEST['addgroupapprove'];
        $time = date("Y-m-d H:i:s");

        $groupapprove_query = "UPDATE maps_group SET is_approve = 1, admin_id = $admin_id,approve_time = '$time' WHERE id = $groupapprove_id";

        $groupapprove_run = mysqli_query($conn, $groupapprove_query);

        if(mysqli_affected_rows($conn) > 0){
            $get_alert_id_query = "SELECT admin_alert_id, parent_id, sub_id FROM maps_group WHERE id = $groupapprove_id";
            $get_alert_id_run = mysqli_query($conn, $get_alert_id_query);
            if(mysqli_num_rows($get_alert_id_run) == 1){
                $row_admin_alert = mysqli_fetch_array($get_alert_id_run);
                $admin_alert_cat = $row_admin_alert['admin_alert_id']; 
               
                $alert_update_query = "UPDATE admin_alert SET admin_id = $admin_id, admin_alert_show = 1 WHERE admin_alert_id = $admin_alert_cat";

                $alert_update_run = mysqli_query($conn, $alert_update_query);

                $successmessage = "Group Addition Approved";

            }


        }

    }   
    
    if(isset($_REQUEST['addgroupdecline'])){
        $groupdecline_id = $_REQUEST['addgroupdecline'];
        $time = date("Y-m-d H:i:s");

        $groupapprove_query = "UPDATE maps_group SET is_approve = 2, admin_id = $admin_id,approve_time = '$time' WHERE id = $groupdecline_id";

        $groupapprove_run = mysqli_query($conn, $groupapprove_query);

        if(mysqli_affected_rows($conn) > 0){
            $get_alert_id_query = "SELECT admin_alert_id, parent_id, sub_id FROM maps_group WHERE id = $groupdecline_id";
            $get_alert_id_run = mysqli_query($conn, $get_alert_id_query);
            if(mysqli_num_rows($get_alert_id_run) == 1){
                $row_admin_alert = mysqli_fetch_array($get_alert_id_run);
                $admin_alert_cat = $row_admin_alert['admin_alert_id']; 
               
                $alert_update_query = "UPDATE admin_alert SET admin_id = $admin_id, admin_alert_show = 0 WHERE admin_alert_id = $admin_alert_cat";

                $alert_update_run = mysqli_query($conn, $alert_update_query);

                $successmessage = "Group Addition Declined";

            }


        }

    }   



    if(isset($_REQUEST['addcatapprove'])){
        $catapprove_id = $_REQUEST['addcatapprove'];
        $time = date("Y-m-d H:i:s");

        $catapprove_query = "UPDATE category SET cat_approved = 1, admin_id = $admin_id,cat_approve_time = '$time' WHERE cat_id = $catapprove_id";

        $catapprove_run = mysqli_query($conn, $catapprove_query);

        if(mysqli_affected_rows($conn) > 0){
            $get_alert_id_query = "SELECT admin_alert_id, cat_name FROM category WHERE cat_id = $catapprove_id";
            $get_alert_id_run = mysqli_query($conn, $get_alert_id_query);
            if(mysqli_num_rows($get_alert_id_run)==1){
                $row_admin_alert = mysqli_fetch_array($get_alert_id_run);
                $admin_alert_cat = $row_admin_alert['admin_alert_id']; 
                $cat_name = $row_admin_alert['cat_name']; 

                $alert_update_query = "UPDATE admin_alert SET admin_id = $admin_id, admin_alert_show = 1 WHERE admin_alert_id = $admin_alert_cat";
                $alert_update_run = mysqli_query($conn, $alert_update_query);
                $successmessage = "Category $cat_name Approved";

            }


        }

    }

    
    if(isset($_REQUEST['addcatdecline'])){
        $catapprove_id = $_REQUEST['addcatdecline'];
        $time = date("Y-m-d H:i:s");

        $catapprove_query = "UPDATE category SET cat_approved = 2, admin_id = $admin_id,cat_approve_time = '$time' WHERE cat_id = $catapprove_id";

        $catapprove_run = mysqli_query($conn, $catapprove_query);

        if(mysqli_affected_rows($conn) > 0){
            $get_alert_id_query = "SELECT admin_alert_id, cat_name FROM category WHERE cat_id = $catapprove_id";
            $get_alert_id_run = mysqli_query($conn, $get_alert_id_query);
            if(mysqli_num_rows($get_alert_id_run)==1){
                $row_admin_alert = mysqli_fetch_array($get_alert_id_run);
                $admin_alert_cat = $row_admin_alert['admin_alert_id']; 
                $cat_name = $row_admin_alert['cat_name']; 

                $alert_update_query = "UPDATE admin_alert SET admin_id = $admin_id, admin_alert_show = 0 WHERE admin_alert_id = $admin_alert_cat";
                $alert_update_run = mysqli_query($conn, $alert_update_query);
                $message = "Category $cat_name Declined";

            }


        }

    } 


    if(isset($_REQUEST['addmapsapprove'])){
        $catapprove_id = $_REQUEST['addmapsapprove'];
        $time = date("Y-m-d H:i:s");

        $catapprove_query = "UPDATE maps SET maps_approved = 1, admin_id = $admin_id,maps_approve_time = '$time' WHERE maps_id = $catapprove_id";

        $catapprove_run = mysqli_query($conn, $catapprove_query);

        if(mysqli_affected_rows($conn) > 0){
            $get_alert_id_query = "SELECT admin_alert_id, maps_name FROM maps WHERE maps_id = $catapprove_id";
            $get_alert_id_run = mysqli_query($conn, $get_alert_id_query);
            if(mysqli_num_rows($get_alert_id_run)==1){
                $row_admin_alert = mysqli_fetch_array($get_alert_id_run);
                $admin_alert_cat = $row_admin_alert['admin_alert_id']; 
                $cat_name = $row_admin_alert['maps_name']; 

                $alert_update_query = "UPDATE admin_alert SET admin_id = $admin_id, admin_alert_show = 1 WHERE admin_alert_id = $admin_alert_cat";
                $alert_update_run = mysqli_query($conn, $alert_update_query);
                $successmessage = "Item $cat_name Approved";

            }


        }

    }

    
    if(isset($_REQUEST['addmapsdecline'])){
        $catapprove_id = $_REQUEST['addmapsdecline'];
        $time = date("Y-m-d H:i:s");

        $catapprove_query = "UPDATE maps SET maps_approved = 2, admin_id = $admin_id,maps_approve_time = '$time' WHERE maps_id = $catapprove_id";

        $catapprove_run = mysqli_query($conn, $catapprove_query);

        if(mysqli_affected_rows($conn) > 0){
            $get_alert_id_query = "SELECT admin_alert_id, maps_name FROM maps WHERE maps_id = $catapprove_id";
            $get_alert_id_run = mysqli_query($conn, $get_alert_id_query);
            if(mysqli_num_rows($get_alert_id_run)==1){
                $row_admin_alert = mysqli_fetch_array($get_alert_id_run);
                $admin_alert_cat = $row_admin_alert['admin_alert_id']; 
                $cat_name = $row_admin_alert['maps_name']; 

                $alert_update_query = "UPDATE admin_alert SET admin_id = $admin_id, admin_alert_show = 0 WHERE admin_alert_id = $admin_alert_cat";
                $alert_update_run = mysqli_query($conn, $alert_update_query);
                $message = "Addition of Item $cat_name Declined";

            }


        }

    } 



    if(isset($_REQUEST['edit'])){
        $maps_id = $_REQUEST['edit'];
        $query = "SELECT * FROM maps LEFT JOIN category
        ON maps.cat_id = category.cat_id  WHERE maps.maps_id = $maps_id AND maps.maps_is_delete IS NULL ORDER BY category.cat_name"; 
        $run = mysqli_query($conn, $query);

        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){      
                $maps_id = $row['maps_id'];
                $ref_photo = $row['maps_ref_pic'];
                $cat_name = $row['cat_name'];
                $maps_name = $row['maps_name'];
                $description = $row['maps_desc'];
                $client_allow_price = $row['maps_client_allow_price'];
                $min_bid_price = $row['maps_min_bid_price'];
                $crew_pay = $row['maps_crew_pay'];
                $photo_req = $row['maps_photo_req'];
                $maps_uom_id =$row['maps_crew_unit_uom_id'];
                $cat_id = $row['cat_id'];
                if($maps_uom_id==NULL){
                    $maps_uom_id='';
                $maps_uom = '';

                }else{
                    $query22 = "SELECT uom_name FROM uom WHERE uom_id = $maps_uom_id";
                    $run22 = mysqli_query($conn, $query22);
    
                    $row22 = mysqli_fetch_array($run22);
    
                    $maps_uom = $row22['uom_name'];
                }
                

            }
        }
    }    
    
    if(isset($_REQUEST['editcatverify'])){ 
        $cat_id = $_REQUEST['editcatverify'];
        if(strlen($_REQUEST['cat_name'])>2){
            $cat_name = $_REQUEST['cat_name'];
        $time = date("Y-m-d H:i:s");

        $query_cat_verify_check = "SELECT * FROM category WHERE cat_name = '$cat_name' AND cat_id != $cat_id AND cat_is_delete IS NULL AND (cat_approved =0 OR cat_approved =1)";
        $run_cat_verify_check = mysqli_query($conn, $query_cat_verify_check);
        if(mysqli_num_rows($run_cat_verify_check)>0){
            $message = "Category Name used by another category. Use a different Name";
            $editcatfail = "yes";

        }else{
            $query_cat_verify = "UPDATE category SET cat_name = '$cat_name' WHERE cat_id = $cat_id";
            $run_cat_verify = mysqli_query($conn, $query_cat_verify);

            if(mysqli_affected_rows($conn)>0){
                $successmessage = "Category updated.";

            }else{
                $message = "Same Name entered";
                $editcatfail = "yes";
            }

        }       


        }else{
           $message = "Category Name should be more than 2 characters long";
           $editcatfail = "yes";
        }

    
    }

    if(isset($_REQUEST['addcatverify'])){             
        if(strlen($_REQUEST['cat_name'])>2){
        $cat_name = $_REQUEST['cat_name'];
        $time = date("Y-m-d H:i:s");
        $query_cat_verify_check = "SELECT * FROM category WHERE cat_name = '$cat_name' AND cat_is_delete IS NULL AND (cat_approved =0 OR cat_approved =1)";
        $run_cat_verify_check = mysqli_query($conn, $query_cat_verify_check);
        if(mysqli_num_rows($run_cat_verify_check)>0){
            $message = "Category Name Exists. Use a different Name";
            $addcatfail = "yes";
        }else{
            $query_cat_verify = "INSERT INTO category SET cat_id = NULL, cat_time = '$time', cat_name = '$cat_name',cat_approve_time ='$time', cat_approved = 1, admin_id = $admin_id";
            $run_cat_verify = mysqli_query($conn, $query_cat_verify);

            if(mysqli_affected_rows($conn)>0){
                $successmessage = "Category added.";

            }else{
                $message = "Technical Error Try Again";
                $addcatfail = "yes";
            }
        }
        
        }else{
           $message = "Category Name should be more than 2 characters long";
           $addcatfail = "yes";
        }

    }

    if(isset($_REQUEST['addverify'])){       

        $maps_name = $_REQUEST['maps_name'];
        $cat_id = $_REQUEST['cat_name'];
      
        $description = $_REQUEST['description'];
        $description = trim($description);
        $client_allow_price = $_REQUEST['client_allow_price'];
        $min_bid_price = $_REQUEST['min_bid_price'];
        $crew_pay = $_REQUEST['crew_pay'];
        $photo_req = $_REQUEST['photo_req'];
        $time = date("Y-m-d H:i:s");
        

        if(strlen($client_allow_price)== 0){
            $client_allow_price = NULL;

        }
        if(strlen($min_bid_price)== 0){
            $min_bid_price=NULL;

        }

        if(strlen($crew_pay)== 0){
            $crew_pay=NULL;

        }
        if(strlen($photo_req)== 0){
            $photo_req=NULL;

        }

        if(isset($_REQUEST['maps_uom'])){

            $maps_uom_id = $_REQUEST['maps_uom'];
            $query111 = "SELECT * FROM uom WHERE uom_id = $maps_uom_id";
             $run111 = mysqli_query($conn,$query111);
          
            
             if(mysqli_num_rows($run111)==1){

                 while($row = mysqli_fetch_array($run111)){
                    $maps_uom = $row['uom_name'];


                }

                

            }else{
                $maps_uom = "";
                $maps_uom_id = NULL;
            } 

        }else{
            $maps_uom = "";
            $maps_uom_id = NULL;

        }
        if(strlen($maps_name)>0){
            $query233 = "SELECT * FROM maps WHERE maps_name= '$maps_name' AND cat_id = $cat_id AND maps_desc = '$description' AND client_id = $url_client_id AND maps_is_delete IS NULL AND (maps_approved = 1 OR maps_approved = 0)";
            $run233 = mysqli_query($conn, $query233);


            if(mysqli_num_rows($run233)==0){
                if(strlen($cat_id)>0){
                
                    $query = "SELECT * FROM category WHERE cat_id = $cat_id";
                    $run = mysqli_query($conn,$query);
    
                    $row = mysqli_fetch_array($run);
                    $cat_name = $row['cat_name']; 
                    if(strlen($_FILES["ref_photo"]["name"])==0){
                        $ref_photo = NULL;
                        
                        $query77 = "INSERT INTO maps SET maps_id = NULL, maps_name = '$maps_name',maps_approve_time ='$time', client_id = $url_client_id, maps_approved = 1, admin_id = $admin_id,maps_created_time ='$time',";
    
                    if($maps_uom_id != NULL){
                    $query771= "maps_crew_unit_uom_id = $maps_uom_id,";
                    }  else{
                        $query771= "";
                    }
                   
                    $query772 = "maps_desc = '$description',";
                    
                    if($client_allow_price != NULL){
                        $query773 = "maps_client_allow_price = $client_allow_price,";
                    } else{
                        $query773 = "";
    
                    }
                    if($min_bid_price != NULL){
                        $query774 = "maps_min_bid_price = $min_bid_price,";
                    } else{
                        $query774 = "";
    
                    }
                    if($photo_req != NULL){
                        $query775 = "maps_photo_req = '$photo_req',";
                    } else{
                        $query775 = "";
                    }
                    if($crew_pay != NULL){
                        $query776 = "maps_crew_pay = $crew_pay,";
                    }     else{
                        $query776 = "";
                    }              
                                    $query777 = "cat_id = $cat_id";
                    $query778 = $query77.$query771.$query772.$query773.$query774.$query775.$query776.$query777;
                                        $run77 = mysqli_query($conn, $query778);
                                        if(mysqli_affected_rows($conn)>0){
                      $query_find_maps_id = "SELECT maps_id FROM maps WHERE maps_name = '$maps_name' AND client_id = $url_client_id AND maps_is_delete IS NULL";
                      $run_find_maps_id = mysqli_query($conn, $query_find_maps_id);
                      if(mysqli_num_rows($run_find_maps_id) == 1){
                          $row_find_maps_id = mysqli_fetch_array($run_find_maps_id);
                          $maps_id = $row_find_maps_id['maps_id'];
                                                     
                if(isset($_REQUEST['maps_uom_val1'])){
                    $maps_uom_val1 = $_REQUEST['maps_uom_val1'];

                    $query_uom_val1 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val1'";  
                    $run_uom_val1 = mysqli_query($conn, $query_uom_val1);
                    $row_uom_value1 = mysqli_fetch_array($run_uom_val1);
                    $uom_field_id1 = $row_uom_value1['uom_field_id'];
                    
                    $query_uom_amt1 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL,maps_uom_value_amount = '$maps_uom_val1' ,maps_id = $maps_id, uom_field_id = $uom_field_id1";
                    $run_uom_amt1 = mysqli_query($conn, $query_uom_amt1);

                }

                if(isset($_REQUEST['maps_uom_val2'])){
                    $maps_uom_val2 = $_REQUEST['maps_uom_val2'];

                    $query_uom_val2 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val2'";  
                    $run_uom_val2 = mysqli_query($conn, $query_uom_val2);
                    $row_uom_value2 = mysqli_fetch_array($run_uom_val2);
                    $uom_field_id2 = $row_uom_value2['uom_field_id'];
                    
                    $query_uom_amt2 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val2', maps_id = $maps_id, uom_field_id = $uom_field_id2";
                    $run_uom_amt2 = mysqli_query($conn, $query_uom_amt2);

                }

                if(isset($_REQUEST['maps_uom_val3'])){
                    $maps_uom_val3 = $_REQUEST['maps_uom_val3'];

                    $query_uom_val3 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val3'";  
                    $run_uom_val3 = mysqli_query($conn, $query_uom_val3);
                    $row_uom_value3 = mysqli_fetch_array($run_uom_val3);
                    $uom_field_id3 = $row_uom_value3['uom_field_id'];
                    
                    $query_uom_amt3 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val3', maps_id = $maps_id, uom_field_id = $uom_field_id3";
                    $run_uom_amt3 = mysqli_query($conn, $query_uom_amt3);

                }

                if(isset($_REQUEST['maps_uom_val4'])){
                    $maps_uom_val4 = $_REQUEST['maps_uom_val4'];

                    $query_uom_val4 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val4'";  
                    $run_uom_val4 = mysqli_query($conn, $query_uom_val4);
                    $row_uom_value4 = mysqli_fetch_array($run_uom_val4);
                    $uom_field_id4 = $row_uom_value4['uom_field_id'];
                    
                    $query_uom_amt4 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val4', maps_id = $maps_id, uom_field_id = $uom_field_id4";
                    $run_uom_amt4 = mysqli_query($conn, $query_uom_amt4);
                    
                }
                if(isset($_REQUEST['maps_uom_val5'])){
                    $maps_uom_val5 = $_REQUEST['maps_uom_val5'];

                    $query_uom_val5 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val5'";  
                    $run_uom_val5 = mysqli_query($conn, $query_uom_val5);
                    $row_uom_value5 = mysqli_fetch_array($run_uom_val5);
                    $uom_field_id5 = $row_uom_value5['uom_field_id'];
                    
                    $query_uom_amt5 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val5', maps_id = $maps_id, uom_field_id = $uom_field_id5";
                    $run_uom_amt5 = mysqli_query($conn, $query_uom_amt5);
                    
                }

                if(isset($_REQUEST['maps_uom_val6'])){
                    $maps_uom_val6 = $_REQUEST['maps_uom_val6'];

                    $query_uom_val6 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val6'";  
                    $run_uom_val6 = mysqli_query($conn, $query_uom_val6);
                    $row_uom_value6 = mysqli_fetch_array($run_uom_val6);
                    $uom_field_id6 = $row_uom_value6['uom_field_id'];
                    
                    $query_uom_amt6 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val6', maps_id = $maps_id, uom_field_id = $uom_field_id6";
                    $run_uom_amt6 = mysqli_query($conn, $query_uom_amt6);
                    
                }

                if(isset($_REQUEST['maps_uom_val7'])){
                    $maps_uom_val7 = $_REQUEST['maps_uom_val7'];

                    $query_uom_val7 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val7'";  
                    $run_uom_val7 = mysqli_query($conn, $query_uom_val7);
                    $row_uom_value7 = mysqli_fetch_array($run_uom_val7);
                    $uom_field_id7 = $row_uom_value7['uom_field_id'];
                    
                    $query_uom_amt7 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val7', maps_id = $maps_id, uom_field_id = $uom_field_id7";
                    $run_uom_amt7 = mysqli_query($conn, $query_uom_amt7);
                    
                }
                if(isset($_REQUEST['maps_uom_val8'])){
                    $maps_uom_val8 = $_REQUEST['maps_uom_val8'];

                    $query_uom_val8 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val8'";  
                    $run_uom_val8 = mysqli_query($conn, $query_uom_val8);
                    $row_uom_value8 = mysqli_fetch_array($run_uom_val8);
                    $uom_field_id8 = $row_uom_value8['uom_field_id'];
                    
                    $query_uom_amt8 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val8', maps_id = $maps_id, uom_field_id = $uom_field_id8";
                    $run_uom_amt8 = mysqli_query($conn, $query_uom_amt8);
                    
                }

                if(isset($_REQUEST['maps_uom_val9'])){
                    $maps_uom_val9 = $_REQUEST['maps_uom_val9'];

                    $query_uom_val9 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val9'";  
                    $run_uom_val9 = mysqli_query($conn, $query_uom_val9);
                    $row_uom_value9 = mysqli_fetch_array($run_uom_val9);
                    $uom_field_id9 = $row_uom_value9['uom_field_id'];
                    
                    $query_uom_amt9 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val9', maps_id = $maps_id, uom_field_id = $uom_field_id9";
                    $run_uom_amt9 = mysqli_query($conn, $query_uom_amt9);
                    
                }

            
                $successmessage = "Job Item Added";
                      }else{
                       /*  $message = "Some Error. Try Again Code 100"; */
    
                    }
                                            
                                        }else{
                                           /*  $message = "Some Error. Try Again Code x34"; */
    
                                        }
                    }else{
                        $uniqueId= time().'-'.mt_rand();
                        $temp = explode(".", $_FILES["ref_photo"]["name"]);
                        $ref_photo = $uniqueId . '.' . end($temp);
                        
                        
                        $query77 = "INSERT INTO maps SET maps_id = NULL, maps_name = '$maps_name',maps_created_time ='$time',maps_approve_time ='$time', client_id = $url_client_id, maps_approved = 1, admin_id = $admin_id, maps_ref_pic='$ref_photo',";
    
                        if($maps_uom_id != NULL){
                        $query771= "maps_crew_unit_uom_id = $maps_uom_id,";
                        }  else{
                            $query771= "";
                        }
                        
                        $query772 = "maps_desc = '$description',";
                        
                        if($client_allow_price != NULL){
                            $query773 = "maps_client_allow_price = $client_allow_price,";
                        } else{
                            $query773 = "";
        
                        }
                        if($min_bid_price != NULL){
                            $query774 = "maps_min_bid_price = $min_bid_price,";
                        } else{
                            $query774 = "";
        
                        }
                        if($photo_req != NULL){
                            $query775 = "maps_photo_req = '$photo_req',";
                        } else{
                            $query775 = "";
                        }
                        if($crew_pay != NULL){
                            $query776 = "maps_crew_pay = $crew_pay,";
                        }     else{
                            $query776 = "";
                        }              
                                        $query777 = "cat_id = $cat_id";
                        $query778 = $query77.$query771.$query772.$query773.$query774.$query775.$query776.$query777;
                        $run77 = mysqli_query($conn, $query778);
                        if(mysqli_affected_rows($conn)>0){
      $query_find_maps_id = "SELECT maps_id FROM maps WHERE maps_name = '$maps_name' AND client_id = $url_client_id AND maps_is_delete IS NULL";
      $run_find_maps_id = mysqli_query($conn, $query_find_maps_id);
      if(mysqli_num_rows($run_find_maps_id) == 1){
          $row_find_maps_id = mysqli_fetch_array($run_find_maps_id);
          $maps_id = $row_find_maps_id['maps_id'];
                                    
if(isset($_REQUEST['maps_uom_val1'])){                                              
                                                                         
                                      
                                          $maps_uom_val1 = $_REQUEST['maps_uom_val1'];
                      
                                          $query_uom_val1 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val1'";  
                                          $run_uom_val1 = mysqli_query($conn, $query_uom_val1);
                                          $row_uom_value1 = mysqli_fetch_array($run_uom_val1);
                                          $uom_field_id1 = $row_uom_value1['uom_field_id'];
                                          
                                          $query_uom_amt1 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL,maps_uom_value_amount = '$maps_uom_val1' ,maps_id = $maps_id, uom_field_id = $uom_field_id1";
                                          $run_uom_amt1 = mysqli_query($conn, $query_uom_amt1);
                      
                                      }
                      
                                      if(isset($_REQUEST['maps_uom_val2'])){
                                          $maps_uom_val2 = $_REQUEST['maps_uom_val2'];
                      
                                          $query_uom_val2 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val2'";  
                                          $run_uom_val2 = mysqli_query($conn, $query_uom_val2);
                                          $row_uom_value2 = mysqli_fetch_array($run_uom_val2);
                                          $uom_field_id2 = $row_uom_value2['uom_field_id'];
                                          
                                          $query_uom_amt2 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val2', maps_id = $maps_id, uom_field_id = $uom_field_id2";
                                          $run_uom_amt2 = mysqli_query($conn, $query_uom_amt2);
                      
                                      }
                      
                                      if(isset($_REQUEST['maps_uom_val3'])){
                                          $maps_uom_val3 = $_REQUEST['maps_uom_val3'];
                      
                                          $query_uom_val3 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val3'";  
                                          $run_uom_val3 = mysqli_query($conn, $query_uom_val3);
                                          $row_uom_value3 = mysqli_fetch_array($run_uom_val3);
                                          $uom_field_id3 = $row_uom_value3['uom_field_id'];
                                          
                                          $query_uom_amt3 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val3', maps_id = $maps_id, uom_field_id = $uom_field_id3";
                                          $run_uom_amt3 = mysqli_query($conn, $query_uom_amt3);
                      
                                      }
                      
                                      if(isset($_REQUEST['maps_uom_val4'])){
                                          $maps_uom_val4 = $_REQUEST['maps_uom_val4'];
                      
                                          $query_uom_val4 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val4'";  
                                          $run_uom_val4 = mysqli_query($conn, $query_uom_val4);
                                          $row_uom_value4 = mysqli_fetch_array($run_uom_val4);
                                          $uom_field_id4 = $row_uom_value4['uom_field_id'];
                                          
                                          $query_uom_amt4 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val4', maps_id = $maps_id, uom_field_id = $uom_field_id4";
                                          $run_uom_amt4 = mysqli_query($conn, $query_uom_amt4);
                                          
                                      }

                                      if(isset($_REQUEST['maps_uom_val5'])){
                                        $maps_uom_val5 = $_REQUEST['maps_uom_val5'];
                    
                                        $query_uom_val5 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val5'";  
                                        $run_uom_val5 = mysqli_query($conn, $query_uom_val5);
                                        $row_uom_value5 = mysqli_fetch_array($run_uom_val5);
                                        $uom_field_id5 = $row_uom_value5['uom_field_id'];
                                        
                                        $query_uom_amt5 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val5', maps_id = $maps_id, uom_field_id = $uom_field_id5";
                                        $run_uom_amt5 = mysqli_query($conn, $query_uom_amt5);
                                        
                                    }

                                    if(isset($_REQUEST['maps_uom_val6'])){
                                        $maps_uom_val6 = $_REQUEST['maps_uom_val6'];
                    
                                        $query_uom_val6 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val6'";  
                                        $run_uom_val6 = mysqli_query($conn, $query_uom_val6);
                                        $row_uom_value6 = mysqli_fetch_array($run_uom_val6);
                                        $uom_field_id6= $row_uom_value6['uom_field_id'];
                                        
                                        $query_uom_amt6 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val6', maps_id = $maps_id, uom_field_id = $uom_field_id6";
                                        $run_uom_amt6 = mysqli_query($conn, $query_uom_amt6);
                                        
                                    }

                                    if(isset($_REQUEST['maps_uom_val7'])){
                                        $maps_uom_val7 = $_REQUEST['maps_uom_val7'];
                    
                                        $query_uom_val7 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val7'";  
                                        $run_uom_val7 = mysqli_query($conn, $query_uom_val7);
                                        $row_uom_value7 = mysqli_fetch_array($run_uom_val7);
                                        $uom_field_id7 = $row_uom_value7['uom_field_id'];
                                        
                                        $query_uom_amt7 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val7', maps_id = $maps_id, uom_field_id = $uom_field_id7";
                                        $run_uom_amt7 = mysqli_query($conn, $query_uom_amt7);
                                        
                                    }

                                    if(isset($_REQUEST['maps_uom_val8'])){
                                        $maps_uom_val8 = $_REQUEST['maps_uom_val8'];
                    
                                        $query_uom_val8 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val8'";  
                                        $run_uom_val8 = mysqli_query($conn, $query_uom_val8);
                                        $row_uom_value8 = mysqli_fetch_array($run_uom_val8);
                                        $uom_field_id8= $row_uom_value4['uom_field_id'];
                                        
                                        $query_uom_amt8 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val8', maps_id = $maps_id, uom_field_id = $uom_field_id8";
                                        $run_uom_amt8 = mysqli_query($conn, $query_uom_amt8);
                                        
                                    }

                                    if(isset($_REQUEST['maps_uom_val9'])){
                                        $maps_uom_val9 = $_REQUEST['maps_uom_val9'];
                    
                                        $query_uom_val9 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val9'";  
                                        $run_uom_val9 = mysqli_query($conn, $query_uom_val9);
                                        $row_uom_value9 = mysqli_fetch_array($run_uom_val9);
                                        $uom_field_id9 = $row_uom_value9['uom_field_id'];
                                        
                                        $query_uom_amt9 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val9', maps_id = $maps_id, uom_field_id = $uom_field_id9";
                                        $run_uom_amt9 = mysqli_query($conn, $query_uom_amt9);
                                        
                                    }
                                    
                                    
                                    }
                                      

                                               $target_dir = getcwd().DIRECTORY_SEPARATOR. "maps_ref_image/";
                                                $target_file = $target_dir . $ref_photo;
                                                $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
                                    
                                                $check = getimagesize($_FILES["ref_photo"]["tmp_name"]);
                                                if($check !== false) {                                                  
                                                   
                                                        
                                    
                        if ($_FILES["ref_photo"]["size"] < 2024000) {
                                                            
                                                                    if($imageFileType == "jpg" || $imageFileType == "png" || $imageFileType == "jpeg") {
                                                                       
                                                                                if (move_uploaded_file($_FILES["ref_photo"]["tmp_name"], $target_file)) {
                                                                                    $successmessage = "Job Item Added";        
                                                                                } else {
                                                                                    $ref_photo = "";
                                                                                    $query_ref_photo_fail = "UPDATE maps SET maps_ref_pic = '$ref_photo' WHERE maps_id = $maps_id";
                                                                                    $run_ref_photo_fail = mysqli_query($conn, $query_ref_photo_fail);
                                                                                    $message =  "Reference Image upload has failed. Rest of details saved successfully. Upload it from edit item";
                                                                                    
                                                                               
                                                                                    }        
                                                                            
                                                                                   
                                                                    }else{
                                                                        $ref_photo = "";
                                                                        $query_ref_photo_fail = "UPDATE maps SET maps_ref_pic = '$ref_photo' WHERE maps_id = $maps_id";
                                                    $run_ref_photo_fail = mysqli_query($conn, $query_ref_photo_fail);
                                                                        $message =  "The file you upload should be JPG, JGEP or PNG";
                                                                        $addfail = "yes";
            

                                                                    }
                                                                 
                                                        }else{

                                                            $ref_photo = "";
                                                            $query_ref_photo_fail = "UPDATE maps SET maps_ref_pic = '$ref_photo' WHERE maps_id = $maps_id";
                                                    $run_ref_photo_fail = mysqli_query($conn, $query_ref_photo_fail);
                                                            $message =  "The file you have uploaded is too large. It should be smaller than 1024 KB";
                                                            $addfail = "yes";

                                                        }
                            
                                                    // Allow certain file formats
                                                   

                                    
                                                    
                                                
                                                } else {
                                                    $ref_photo = "";
                                                    $query_ref_photo_fail = "UPDATE maps SET maps_ref_pic = '$ref_photo' WHERE maps_id = $maps_id";
                                                    $run_ref_photo_fail = mysqli_query($conn, $query_ref_photo_fail);
                                                    
                                                    $message =  "The file you have uploaded is not an Image";
                                                    $addfail = "yes";
                            
                            
                                                    
                                                    
                                                 }
                                                
                                          




                                            }else{
                                               /*  $message = "Some Error. Try Again Code x 35"; */
        
                                            }
                                
                                
                                
                
                }
    
    
                }else{
                    $cat_name = "";
                    $cat_id = NULL;
                    $message =  "Category Name cannot be empty";
                    $add_fail = "yes";
    
                }
            }else{
                
                
                $query = "SELECT * FROM category WHERE cat_id = $cat_id";
                    $run = mysqli_query($conn,$query);
    
                    $row = mysqli_fetch_array($run);
                    $cat_name = $row['cat_name']; 
                    $message =  "Job Name $maps_name already Exists in $cat_name Category";
                $maps_name = "";
                $add_fail = "yes";

            }



            
         
    }else{
        $maps_name = "";
        $message =  "Job Name cannot be empty";
        $add_fail = "yes";


    }

       

    }

    if(isset($_REQUEST['editverify'])){
        $maps_id = $_REQUEST['editverify'];
        $maps_name = $_REQUEST['maps_name'];
        $cat_id = $_REQUEST['cat_name'];      
        $description = $_REQUEST['description'];
        $description = trim($description);
        $client_allow_price = $_REQUEST['client_allow_price'];
        $min_bid_price = $_REQUEST['min_bid_price'];
        $crew_pay = $_REQUEST['crew_pay'];
        $photo_req = $_REQUEST['photo_req'];
        $time = date("Y-m-d H:i:s");
        
        if(strlen($client_allow_price)== 0){
            $client_allow_price = NULL;
        }
        if(strlen($min_bid_price)== 0){
            $min_bid_price=NULL;
        }
        if(strlen($crew_pay)== 0){
            $crew_pay=NULL;
        }
        if(strlen($photo_req)== 0){
            $photo_req=NULL;
        }     

        if(strlen($_REQUEST['maps_uom'])>0){

            $maps_uom_id = $_REQUEST['maps_uom'];
            $query111 = "SELECT * FROM uom WHERE uom_id = $maps_uom_id";
             $run111 = mysqli_query($conn,$query111);
          
            
             if(mysqli_num_rows($run111)==1){

                while($row = mysqli_fetch_array($run111)){
                    $maps_uom = $row['uom_name'];
                }

                if(isset($_REQUEST['maps_uom_val1'])){
                    $maps_uom_val1 = $_REQUEST['maps_uom_val1'];

                    $query_uom_val1 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val1'";  
                    $run_uom_val1 = mysqli_query($conn, $query_uom_val1);
                    $row_uom_value1 = mysqli_fetch_array($run_uom_val1);
                    $uom_field_id1 = $row_uom_value1['uom_field_id'];
                    
                    $query_uom_search = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id1";
                    $run_uom_search = mysqli_query($conn, $query_uom_search);
                    if(mysqli_num_rows($run_uom_search)>0){
                        $query_uom_amt1 = "UPDATE maps_uom_value SET maps_uom_value_amount = '$maps_uom_val1' WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id1";
                        $run_uom_amt1 = mysqli_query($conn, $query_uom_amt1);
                    }else{
                        $query_uom_amt1 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL,maps_uom_value_amount = '$maps_uom_val1' ,maps_id = $maps_id, uom_field_id = $uom_field_id1";
                    $run_uom_amt1 = mysqli_query($conn, $query_uom_amt1);
                    }                   

                }

                if(isset($_REQUEST['maps_uom_val2'])){
                    $maps_uom_val2 = $_REQUEST['maps_uom_val2'];

                    $query_uom_val2 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val2'";  
                    $run_uom_val2 = mysqli_query($conn, $query_uom_val2);
                    $row_uom_value2 = mysqli_fetch_array($run_uom_val2);
                    $uom_field_id2 = $row_uom_value2['uom_field_id'];
                    
                    $query_uom_search = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id2";
                    $run_uom_search = mysqli_query($conn, $query_uom_search);
                    if(mysqli_num_rows($run_uom_search)>0){
                        $query_uom_amt2 = "UPDATE maps_uom_value SET maps_uom_value_amount = '$maps_uom_val2' WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id2";
                        $run_uom_amt2 = mysqli_query($conn, $query_uom_amt2);
                }else{
                    $query_uom_amt2 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val2', maps_id = $maps_id, uom_field_id = $uom_field_id2";
                    $run_uom_amt2 = mysqli_query($conn, $query_uom_amt2);

                }

                }

                if(isset($_REQUEST['maps_uom_val3'])){
                    $maps_uom_val3 = $_REQUEST['maps_uom_val3'];

                    $query_uom_val3 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val3'";  
                    $run_uom_val3 = mysqli_query($conn, $query_uom_val3);
                    $row_uom_value3 = mysqli_fetch_array($run_uom_val3);
                    $uom_field_id3 = $row_uom_value3['uom_field_id'];

                    $query_uom_search = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id3";
                    $run_uom_search = mysqli_query($conn, $query_uom_search);
                    if(mysqli_num_rows($run_uom_search)>0){
                    
                        $query_uom_amt3 = "UPDATE maps_uom_value SET maps_uom_value_amount = '$maps_uom_val3' WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id3";
                        $run_uom_amt3 = mysqli_query($conn, $query_uom_amt3);
                    }else{
                        $query_uom_amt3 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val3', maps_id = $maps_id, uom_field_id = $uom_field_id3";
                    $run_uom_amt3 = mysqli_query($conn, $query_uom_amt3);
    
                    }    

                }

                if(isset($_REQUEST['maps_uom_val4'])){
                    $maps_uom_val4 = $_REQUEST['maps_uom_val4'];

                    $query_uom_val4 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val4'";  
                    $run_uom_val4 = mysqli_query($conn, $query_uom_val4);
                    $row_uom_value4 = mysqli_fetch_array($run_uom_val4);
                    $uom_field_id4 = $row_uom_value4['uom_field_id'];
                    
                    $query_uom_search = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id4";
                    $run_uom_search = mysqli_query($conn, $query_uom_search);
                    if(mysqli_num_rows($run_uom_search)>0){
                        $query_uom_amt4 = "UPDATE maps_uom_value SET maps_uom_value_amount = '$maps_uom_val4' WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id4";
                        $run_uom_amt4 = mysqli_query($conn, $query_uom_amt4);
                    }else{
                        $query_uom_amt4 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val4', maps_id = $maps_id, uom_field_id = $uom_field_id4";
                    $run_uom_amt4 = mysqli_query($conn, $query_uom_amt4);
    
                    }     

                }

                if(isset($_REQUEST['maps_uom_val5'])){
                    $maps_uom_val5 = $_REQUEST['maps_uom_val5'];

                    $query_uom_val5 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val5'";  
                    $run_uom_val5 = mysqli_query($conn, $query_uom_val5);
                    $row_uom_value5 = mysqli_fetch_array($run_uom_val5);
                    $uom_field_id5 = $row_uom_value5['uom_field_id'];
                    
                    $query_uom_search = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id5";
                    $run_uom_search = mysqli_query($conn, $query_uom_search);
                    if(mysqli_num_rows($run_uom_search)>0){
                        $query_uom_amt5 = "UPDATE maps_uom_value SET maps_uom_value_amount = '$maps_uom_val5' WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id5";
                        $run_uom_amt5 = mysqli_query($conn, $query_uom_amt5);
                    }else{
                        $query_uom_amt5 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val5', maps_id = $maps_id, uom_field_id = $uom_field_id5";
                    $run_uom_amt5 = mysqli_query($conn, $query_uom_amt5);
    
                    }     

                }

                if(isset($_REQUEST['maps_uom_val6'])){
                    $maps_uom_val6 = $_REQUEST['maps_uom_val6'];

                    $query_uom_val6 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val6'";  
                    $run_uom_val6 = mysqli_query($conn, $query_uom_val6);
                    $row_uom_value6 = mysqli_fetch_array($run_uom_val6);
                    $uom_field_id6 = $row_uom_value6['uom_field_id'];
                    
                    $query_uom_search = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id6";
                    $run_uom_search = mysqli_query($conn, $query_uom_search);
                    if(mysqli_num_rows($run_uom_search)>0){
                        $query_uom_amt6 = "UPDATE maps_uom_value SET maps_uom_value_amount = '$maps_uom_val6' WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id6";
                        $run_uom_amt6 = mysqli_query($conn, $query_uom_amt6);
                    }else{
                        $query_uom_amt6 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val6', maps_id = $maps_id, uom_field_id = $uom_field_id6";
                    $run_uom_amt6 = mysqli_query($conn, $query_uom_amt6);
    
                    }     

                }

                if(isset($_REQUEST['maps_uom_val7'])){
                    $maps_uom_val7 = $_REQUEST['maps_uom_val7'];

                    $query_uom_val7 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val7'";  
                    $run_uom_val7 = mysqli_query($conn, $query_uom_val7);
                    $row_uom_value7 = mysqli_fetch_array($run_uom_val7);
                    $uom_field_id7 = $row_uom_value7['uom_field_id'];
                    
                    $query_uom_search = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id7";
                    $run_uom_search = mysqli_query($conn, $query_uom_search);
                    if(mysqli_num_rows($run_uom_search)>0){
                        $query_uom_amt7 = "UPDATE maps_uom_value SET maps_uom_value_amount = '$maps_uom_val7' WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id7";
                        $run_uom_amt7 = mysqli_query($conn, $query_uom_amt7);
                    }else{
                        $query_uom_amt7 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val7', maps_id = $maps_id, uom_field_id = $uom_field_id7";
                    $run_uom_amt7 = mysqli_query($conn, $query_uom_amt7);
    
                    }     

                }

                if(isset($_REQUEST['maps_uom_val8'])){
                    $maps_uom_val8 = $_REQUEST['maps_uom_val8'];

                    $query_uom_val8 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val8'";  
                    $run_uom_val8 = mysqli_query($conn, $query_uom_val8);
                    $row_uom_value8 = mysqli_fetch_array($run_uom_val8);
                    $uom_field_id8 = $row_uom_value8['uom_field_id'];
                    
                    $query_uom_search = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id8";
                    $run_uom_search = mysqli_query($conn, $query_uom_search);
                    if(mysqli_num_rows($run_uom_search)>0){
                        $query_uom_amt8 = "UPDATE maps_uom_value SET maps_uom_value_amount = '$maps_uom_val8' WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id8";
                        $run_uom_amt8 = mysqli_query($conn, $query_uom_amt8);
                    }else{
                        $query_uom_amt8 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val8', maps_id = $maps_id, uom_field_id = $uom_field_id8";
                    $run_uom_amt8 = mysqli_query($conn, $query_uom_amt8);
    
                    }     

                }

                if(isset($_REQUEST['maps_uom_val9'])){
                    $maps_uom_val9 = $_REQUEST['maps_uom_val9'];

                    $query_uom_val9 = "SELECT * FROM uom_field WHERE uom_id = $maps_uom_id AND uom_field_name = 'maps_uom_val9'";  
                    $run_uom_val9 = mysqli_query($conn, $query_uom_val9);
                    $row_uom_value9 = mysqli_fetch_array($run_uom_val9);
                    $uom_field_id9 = $row_uom_value9['uom_field_id'];
                    
                    $query_uom_search = "SELECT * FROM maps_uom_value WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id9";
                    $run_uom_search = mysqli_query($conn, $query_uom_search);
                    if(mysqli_num_rows($run_uom_search)>0){
                        $query_uom_amt9 = "UPDATE maps_uom_value SET maps_uom_value_amount = '$maps_uom_val9' WHERE maps_id = $maps_id AND uom_field_id = $uom_field_id9";
                        $run_uom_amt9 = mysqli_query($conn, $query_uom_amt9);
                    }else{
                        $query_uom_amt9 = "INSERT INTO maps_uom_value SET maps_uom_value_id = NULL, maps_uom_value_amount = '$maps_uom_val9', maps_id = $maps_id, uom_field_id = $uom_field_id9";
                    $run_uom_amt9 = mysqli_query($conn, $query_uom_amt9);
    
                    }     

                }
       

            }else{
                $maps_uom = "";
                $maps_uom_id = NULL;
            } 

        }else{
            $maps_uom = "";
            $maps_uom_id = NULL;

        }
       if(strlen($maps_name)>0){
        $maps_desc2 = "";
          $query233 = "SELECT * FROM maps WHERE maps_id= $maps_id";
            $run233 = mysqli_query($conn, $query233); 
            if(mysqli_num_rows($run233)==1){ 
                while($row = mysqli_fetch_array($run233)){
                    $maps_desc2 = $row['maps_desc'];
                }

            }
            $maps_name_error ="";
           
            if($maps_desc2 != $description){
                $query2333 = "SELECT * FROM maps WHERE client_id = $url_client_id AND maps_name= '$maps_name' AND maps_desc = '$description' AND cat_id = $cat_id AND maps_is_delete IS NULL";
                $run2333 = mysqli_query($conn, $query2333);    
    
                if(mysqli_num_rows($run2333)==1){
                 $maps_name_error = "error";
                }
            }

            if($maps_name_error != "error"){
                if(strlen($cat_id)>0){
                
                    $query = "SELECT * FROM category WHERE cat_id = $cat_id";
                    $run = mysqli_query($conn,$query);
    
                    $row = mysqli_fetch_array($run);
                    $cat_name = $row['cat_name']; 
                    if(strlen($_FILES["ref_photo"]["name"])==0){
                        $ref_photo = NULL;
                        
                        $query77 = "UPDATE maps SET maps_name = '$maps_name',";
    
                    if($maps_uom_id != NULL){
                    $query771= "maps_crew_unit_uom_id = $maps_uom_id,";
                    }  else{
                        $query771= "maps_crew_unit_uom_id = NULL,";
                    }
                    
                    $query772 = "maps_desc = '$description',";
                    
                    if($client_allow_price != NULL){
                        $query773 = "maps_client_allow_price = $client_allow_price,";
                    } else{
                        $query773 = "";
    
                    }
                    if($min_bid_price != NULL){
                        $query774 = "maps_min_bid_price = $min_bid_price,";
                    } else{
                        $query774 = "";
    
                    }
                    if($photo_req != NULL){
                        $query775 = "maps_photo_req = '$photo_req',";
                    } else{
                        $query775 = "";
                    }
                    if($crew_pay != NULL){
                        $query776 = "maps_crew_pay = $crew_pay,";
                    }     else{
                        $query776 = "";
                    }              
                                    $query777 = "cat_id = $cat_id WHERE maps_id = $maps_id AND client_id = $url_client_id";
                    $query778 = $query77.$query771.$query772.$query773.$query774.$query775.$query776.$query777;
                                        $run77 = mysqli_query($conn, $query778);
                                        if($run77){
                                            $successmessage = "Job Item Edited";
                                        }else{
                                          /*   $message = "Some Error. Try Again. Code x 36";
     */
                                        }
                            
                            
                            
            
            
                    }else{
                        $uniqueId= time().'-'.mt_rand();
                        $temp = explode(".", $_FILES["ref_photo"]["name"]);
                        $ref_photo = $uniqueId . '.' . end($temp);
                        
                        
                        $query77 = "UPDATE maps SET maps_name = '$maps_name', maps_ref_pic='$ref_photo',";
    
                        if($maps_uom_id != NULL){
                        $query771= "maps_crew_unit_uom_id = $maps_uom_id,";
                        }  else{
                            $query771= "maps_crew_unit_uom_id = NULL,";
                        }
                        $query772 = "maps_desc = '$description',";
                        
                        if($client_allow_price != NULL){
                            $query773 = "maps_client_allow_price = $client_allow_price,";
                        } else{
                            $query773 = "";
        
                        }
                        if($min_bid_price != NULL){
                            $query774 = "maps_min_bid_price = $min_bid_price,";
                        } else{
                            $query774 = "";
        
                        }
                        if($photo_req != NULL){
                            $query775 = "maps_photo_req = '$photo_req',";
                        } else{
                            $query775 = "";
                        }
                        if($crew_pay != NULL){
                            $query776 = "maps_crew_pay = $crew_pay,";
                        }     else{
                            $query776 = "";
                        }              
                                        $query777 = "cat_id = $cat_id WHERE  maps_id = $maps_id AND client_id = $url_client_id";
                        $query778 = $query77.$query771.$query772.$query773.$query774.$query775.$query776.$query777;
                                            $run77 = mysqli_query($conn, $query778);
                                            if(mysqli_affected_rows($conn)>0){

                                               $target_dir = getcwd().DIRECTORY_SEPARATOR. "maps_ref_image/";
                                                $target_file = $target_dir . $ref_photo;
                                                $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
                                    
                                                $check = getimagesize($_FILES["ref_photo"]["tmp_name"]);
                                                if($check !== false) {                                                  
                                                   
                                                        
                                    
                        if ($_FILES["ref_photo"]["size"] < 2024000) {
                                                            
                                                                    if($imageFileType == "jpg" || $imageFileType == "png" || $imageFileType == "jpeg") {
                                                                       
                                                                                if (move_uploaded_file($_FILES["ref_photo"]["tmp_name"], $target_file)) {
                                                                                    $successmessage = "Job Item Added";        
                                                                                } else {
                                                                                    $ref_photo = "";
                                                                                    $query_ref_photo_fail = "UPDATE maps SET maps_ref_pic = '$ref_photo' WHERE maps_id = $maps_id";
                                                                                    $run_ref_photo_fail = mysqli_query($conn, $query_ref_photo_fail);

                                                                                    $message =  "Reference Image upload has failed. Rest of details saved successfully. Upload it from edit item";
                                                                                    
                                                                               
                                                                                    }        
                                                                            
                                                                                   
                                                                    }else{
                                                                        $ref_photo = "";
                                                                        $query_ref_photo_fail = "UPDATE maps SET maps_ref_pic = '$ref_photo' WHERE maps_id = $maps_id";
                                                    $run_ref_photo_fail = mysqli_query($conn, $query_ref_photo_fail);
                                                                        $message =  "The file you upload should be JPG, JGEP or PNG";
                                                                        $editfail = "yes";
            

                                                                    }
                                                                 
                                                        }else{

                                                            $ref_photo = "";
                                                            $query_ref_photo_fail = "UPDATE maps SET maps_ref_pic = '$ref_photo' WHERE maps_id = $maps_id";
                                                    $run_ref_photo_fail = mysqli_query($conn, $query_ref_photo_fail);
                                                            $message =  "The file you have uploaded is too large. It should be smaller than 1024 KB";
                                                            $editfail = "yes";

                                                        }
                            
                                                    // Allow certain file formats
                                                   

                                    
                                                    
                                                
                                                } else {
                                                    $ref_photo = "";
                                                    $query_ref_photo_fail = "UPDATE maps SET maps_ref_pic = '$ref_photo' WHERE maps_id = $maps_id";
                                                    $run_ref_photo_fail = mysqli_query($conn, $query_ref_photo_fail);
                                                    
                                                    $message =  "The file you have uploaded is not an Image";
                                                    $editfail = "yes";
                            
                            
                                                    
                                                    
                                                 }
                                                
                                          




                                            }else{
                                               /*  $message = "Some Error. Try Again Code 38"; */
        
                                            }
                                
                                
                                
                
                }
    
    
                }else{
                    $cat_name = "";
                    $cat_id = NULL;
                    $message =  "Category Name cannot be empty";
                    $editfail = "yes";
    
                }
            }else{
                
                
                $query = "SELECT * FROM category WHERE cat_id = $cat_id";
                    $run = mysqli_query($conn,$query);
    
                    $row = mysqli_fetch_array($run);
                    $cat_name = $row['cat_name']; 
                    $message =  "Job Name $maps_name already Exists in $cat_name Category";
                $editfail = "yes";

            }



            
         
    }else{
        $maps_name = "";
        $message =  "Job Name cannot be empty";
        $editfail = "yes";
    }




    }

    

}?>

<style>

.autocomplete-suggestions { border: 1px solid #999; background: #FFF; overflow: auto; }
.autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }
.autocomplete-selected { background: #F0F0F0; }
.autocomplete-suggestions strong { font-weight: normal; color: #3399FF; }
.autocomplete-group { padding: 2px 5px; }
.autocomplete-group strong { display: block; border-bottom: 1px solid #000; }
</style>
<div id="page-wrapper">

<button style='float:right;padding:2px;font-size:14px;margin-bottom:0px' class= 'btn btn-success' id = 'addVendorModal'>Import Item Excel</button>
<h3>Master Allowable Pricing Sheet (MAPS)</h3>

<!-- -->
<ul data-tabs>
<li><a <?php       
       
           if($url_client_id ==0){      
               
               echo "data-tabby-default";
               $client_id_tab_check = 'unset';
               
            }else{
                $client_id_tab_check = 'set';
            }    
            
            
            
            ?> href="#new00" id = "client_id_0">Main</a></li>

<?php
$query_client_find = "SELECT * FROM client WHERE is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";

$run_client_find = mysqli_query($conn, $query_client_find);

if(mysqli_num_rows($run_client_find)>0){   
   
 while($row_client_find = mysqli_fetch_array($run_client_find)){
    $client_id_t =  $row_client_find['client_id'];
    $client_id_tab = "client_id_" . $client_id_t;
    $client_alias = $row_client_find['client_alias'];?>
        <li><a <?php        
        if($client_id_tab_check == 'set'){
            if($client_id_t == $url_client_id){
                echo "data-tabby-default ";
                $client_id_tab_check = 'unset';
            }else{
                $client_id_tab_check = 'set';
            }           
        }       
            ?>href="#new<?php echo $client_id_t.$client_id_t ?>" id="<?php echo $client_id_tab ?>"><?php echo $client_alias ?></a></li>
    <?php 
   }
}
?>       
 
    <li><a href="#newListz" id="client_id_3">Create New List</a></li>
</ul>

        <!--  active div (div start)-->
<?php 

if($url_client_id == 0){
    echo '<div id="new00">'; 
}else{
    echo '<div id="new00">';
    echo '<div id="old00">';
    echo "<p>Loading</p>";
    echo '</div>';
    echo '</div>';
    $query_client_find = "SELECT * FROM client WHERE client_id < $url_client_id AND is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";

$run_client_find = mysqli_query($conn, $query_client_find);

if(mysqli_num_rows($run_client_find)>0){   
   
 while($row_client_find = mysqli_fetch_array($run_client_find)){
    $client_id_tab2 = $row_client_find['client_id'];

   ?>
        <div id="new<?php echo $client_id_tab2.$client_id_tab2?>">
        <div id="old<?php echo $client_id_tab2.$client_id_tab2?>">
        
        <p>Loading</p>
        </div>
        
        </div>
    <?php }
}

$query_client_find1 = "SELECT * FROM client WHERE client_id = $url_client_id AND is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";

$run_client_find1 = mysqli_query($conn, $query_client_find1);

if(mysqli_num_rows($run_client_find1)>0){   
   
 while($row_client_find1 = mysqli_fetch_array($run_client_find1)){
    $client_id_tab21 = $row_client_find1['client_id'];

   ?>
        <div id="new<?php echo $client_id_tab21.$client_id_tab21?>">
       
    <?php }
}

} 
?>
<!--   -->
<br>   
<?php 
                    if(isset($successmessage)){
                    echo '<div class="alert alert-success">
                    <strong>'. $successmessage .'</strong></div>';
                }               

                if(isset($message)){
                    echo '<div class="alert alert-danger">
                    <strong>'. $message .'</strong>
                  </div>';
                }
                    ?>              
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                <!-- <div class="col-lg-12"> -->
                <h3>
        <?php if(isset($_REQUEST['new']) ||isset($add_fail)){
            
            echo "Add a Product to MAPS List<a style = 'float:right;' class='btn btn-warning' href='MAPS-sheet.php?cl_id=$url_client_id'>Cancel</a>";

        }          
            else if(isset($_REQUEST['edit']) ||isset($editfail) ||isset($addfail)){
              echo "Change Details for $maps_name<a style = 'float:right;' class='btn btn-warning' href='MAPS-sheet.php?cl_id=$url_client_id'>Cancel</a>";
        }elseif(isset($_REQUEST['delete'])){
            $id= $_REQUEST['delete'];
            $query = "SELECT maps_name FROM maps WHERE maps_id = $id";
            $run = mysqli_query($conn, $query);
            $row = mysqli_fetch_array($run);
            $maps_name = $row['maps_name'];
            echo "Do you want to delete $maps_name?<a style = 'float:right;' class='btn btn-warning' href='MAPS-sheet.php?cl_id=$url_client_id'>Cancel</a><br><br><a style = '' class='btn btn-danger' href='MAPS-sheet.php?conf-delete=$id&maps_name=$maps_name&cl_id=$url_client_id'>Yes Delete</a>";
        }elseif(isset($_REQUEST['editgroup'])&& isset($_REQUEST['deletegroup'])){
            $id2 = $_REQUEST['editgroup'];
            $maps_group_id= $_REQUEST['deletegroup'];
            $id= $_REQUEST['maps_id_group_delete'];            
            $query = "SELECT maps_name FROM maps WHERE maps_id = $id";
            $run = mysqli_query($conn, $query);
            $row = mysqli_fetch_array($run);
            $maps_name = $row['maps_name'];
            echo "Do you want to delete $maps_name from this group?<a style = 'float:right;' class='btn btn-warning' href='MAPS-sheet.php?cl_id=$url_client_id'>Cancel</a> <br><br><a style = '' class='btn btn-danger' href='MAPS-sheet.php?cl_id=$url_client_id&conf-group-delete=$maps_group_id&maps_name=$maps_name&editgroup=$id2'>Yes Delete</a>";

        }elseif(isset($_REQUEST['deletecat'])){
            $id= $_REQUEST['deletecat'];
            $query = "SELECT cat_name FROM category WHERE cat_id = $id";
            $run = mysqli_query($conn, $query);
            $row = mysqli_fetch_array($run);
            $cat_name = $row['cat_name'];

            $query_delete_cat_check = "SELECT  * FROM maps WHERE cat_id = $id AND maps_is_delete IS NULL";
            $run_delete_cat_check = mysqli_query($conn, $query_delete_cat_check);

            if(mysqli_num_rows($run_delete_cat_check)>0){
                $num_products = mysqli_num_rows($run_delete_cat_check);
                echo "$cat_name cannot be deleted it is used in $num_products Products. To delete this category delete the products using this category first.";
                echo '<br>';
                echo '<br>';
                echo "<a href='MAPS-sheet.php?newcat=&cl_id=$url_client_id' class='btn btn-success' role='button'>Add Category</a>&nbsp &nbsp<a href='MAPS-sheet.php?new=&cl_id=$url_client_id' class='btn btn-success' role='button'>Manage Products</a>";

            }else{
                echo "Do you want to delete $cat_name category?<a style = 'float:right;' class='btn btn-warning' href='MAPS-sheet.php?cat=&cl_id=$url_client_id'>Cancel</a><br><br><a style = '' class='btn btn-danger' href='MAPS-sheet.php?conf-cat-delete=$id&cat_name=$cat_name&cl_id=$url_client_id'>Yes Delete</a>";
            }
            
            
        }elseif(isset($_REQUEST['newcat']) ||isset($addcatfail)){
            echo "Add a Category to MAPS<a style = 'float:right;' class='btn btn-warning' href='MAPS-sheet.php?cat=&cl_id=$url_client_id'>Cancel</a>";
            
        }elseif(isset($_REQUEST['newgroup']) ||isset($addgroupfail)){
            echo "Create a MAPS product group<a style = 'float:right;' class='btn btn-warning' href='MAPS-sheet.php?group=&cl_id=$url_client_id'>Cancel</a>";
            
        }elseif(isset($_REQUEST['editcat'])||isset($editcatfail)){
            echo "Change Details for $cat_name<a style = 'float:right;' class='btn btn-warning' href='MAPS-sheet.php?cat=&cl_id=$url_client_id'>Cancel</a>";
            
        }elseif(isset($_REQUEST['editgroup'])){
            echo "Change Items under $maps_parent_name<a style = 'float:right;' class='btn btn-warning' href='MAPS-sheet.php?group=&cl_id=$url_client_id'>Cancel</a>";
            
        }elseif(isset($_REQUEST['cat']) || isset($_REQUEST['conf-cat-delete'])|| isset($_REQUEST['editcatverify'])|| isset($_REQUEST['addcatverify'])){
            echo "<a href='MAPS-sheet.php?newcat=&cl_id=$url_client_id' class='btn btn-success' role='button'>Add Category</a>&nbsp &nbsp<a href='MAPS-sheet.php?cl_id=$url_client_id' class='btn btn-success' role='button'>Manage Products</a>";
            
        }elseif(isset($_REQUEST['group'])|| isset($_REQUEST['editgroupverify'])|| isset($_REQUEST['addgroupverify'])){
            echo "<a href='MAPS-sheet.php?newgroup=&cl_id=$url_client_id' class='btn btn-success' role='button'>Create Product Group</a>&nbsp &nbsp<a href='MAPS-sheet.php?cl_id=$url_client_id' class='btn btn-success' role='button'>Back to Products</a>
            ";
            
        }else{
            echo "<a href='MAPS-sheet.php?new=&cl_id=$url_client_id' class='btn btn-success' role='button'>Add Product</a>&nbsp &nbsp<a href='MAPS-sheet.php?group=&cl_id=$url_client_id' class='btn btn-success' role='button'>Product Groups</a>&nbsp &nbsp<a href='MAPS-sheet.php?cat=&cl_id=$url_client_id' class='btn btn-success' role='button'>Manage Categories</a>";
           
        } ?> </h3>
        </div>                                                               

             

               <?php 
               if(isset($_REQUEST['edit']) || isset($editfail)|| isset($addfail)){
                   echo '<div class="panel-body">                      
                   <div class = "row">          
            
                        
      <div class="col-lg-12">';
                echo "<form action = 'MAPS-sheet.php?editverify=$maps_id&cl_id=$url_client_id' method = 'POST' class = 'form-group' enctype = 'multipart/form-data'>";
                echo "<input type = 'hidden' name='maps_id' id='maps_id' value='$maps_id' >";
               }else if(isset($_REQUEST['new']) || isset($add_fail)){
                echo '<div class="panel-body">                      
                   <div class = "row">                       
                        
      <div class="col-lg-12">';
                echo "<form action = 'MAPS-sheet.php?addverify=&cl_id=$url_client_id' method = 'POST' class = 'form-group' enctype = 'multipart/form-data'>";
               }else if(isset($_REQUEST['newcat']) || isset($addcatfail)){
                echo '<div class="panel-body">                      
                   <div class = "row">                       
                        
      <div class="col-lg-12">';
                echo "<form action = 'MAPS-sheet.php?addcatverify=&cl_id=$url_client_id' method = 'POST' class = 'form-group' enctype = 'multipart/form-data'>";

               }else if(isset($_REQUEST['editcat']) || isset($editcatfail)){
                echo '<div class="panel-body">                      
                   <div class = "row">                       
                        
      <div class="col-lg-12">';
                echo "<form action = 'MAPS-sheet.php?editcatverify=$cat_id&cl_id=$url_client_id' method = 'POST' class = 'form-group' enctype = 'multipart/form-data'>";
                echo "<input type = 'hidden' name='cat_id' id='cat_id' value='$cat_id' >";
               }else if(isset($_REQUEST['newgroup'])){
                echo '<div class="panel-body">                      
                   <div class = "row">                       
                        
      <div class="col-lg-12">';
                echo "<form action = 'MAPS-sheet.php?addgroupverify=&cl_id=$url_client_id' method = 'POST' class = 'form-group' enctype = 'multipart/form-data'>";

               }                 
               
               ?>
               
<?php
if(isset($_REQUEST['editgroup'])){ 
    echo '<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz2">
    <thead>
        <tr>
        <th>Delete</th>
                
             
             
                <th>
                Group Items

                </th>
               
            
            </tr>
        </thead>
        <tbody>';            
             $query_maps_group1 = "SELECT * FROM maps_group WHERE parent_id = $maps_parent_id AND is_delete IS NULL AND is_approve = 1"; 
             $run_maps_group1 = mysqli_query($conn, $query_maps_group1);
             if(mysqli_num_rows($run_maps_group1)>0){                                            
 
                 while($row1 = mysqli_fetch_array($run_maps_group1)){
                     $sub_id1 = $row1['sub_id'];
                     $maps_group_id1 = $row1['id'];                    
                     
                     $query_maps11 = "SELECT maps_name FROM maps WHERE maps_id = $sub_id1"; 
                     $run_maps11 = mysqli_query($conn, $query_maps11); 
                     if(mysqli_num_rows($run_maps11) == 1){
                         foreach($run_maps11 as $mappss1){
                             $sub_NAME1 = $mappss1['maps_name'];   
                             echo '<tr class="odd gradeX" >';
                             echo '<td><a href="MAPS-sheet.php?editgroup='.$maps_parent_id. '&deletegroup='.$maps_group_id1.'&maps_id_group_delete='. $sub_id1.'&cl_id='.$url_client_id.'" >Delete</a>                            
                             </td>';              
                          
                             echo '<td>';                                  
                             echo $sub_NAME1;  
                             echo '</td>'; 
                             
                             echo '</tr>';                               
                             
                         }
                     }                    
                 }

                 echo '</tbody></table>';                
                
             }     

    ?>

    <?php    
}
    ?>

               <?php
if(isset($_REQUEST['newgroup'])){
    ?> 
    <div class="row">

<div class="form-group col-lg-6">
<label for="cat_name_parent">Choose Category of Parent Item</label>     
     
            <select name="cat_name_parent" id="cat_name_parent" onChange="getParentItemValue();" required autofocus >

 <?php              
             echo '<option value="" disabled="disabled" selected="selected">Select Category </option>';         

                 
               $query00 = "SELECT * FROM category WHERE cat_is_delete IS NULL AND cat_approved = 1";
               $run00 = mysqli_query($conn,$query00);

               if(mysqli_num_rows($run00)>0){
                while($row00 = mysqli_fetch_array($run00)){                     
                    echo "<option value='".$row00['cat_id']."'>". $row00['cat_name']."</option>";                
                }
               }  
               ?>

    </select>
</div>
<div id="maps_group_parent_name" class="form-group col-lg-6">

</div>

    </div>
<div class="row">

<div class="form-group col-lg-6">
<div id = "hiddenCatInput" style = "display:none">
<label for="cat_name_child">Choose Category of Child Item</label>     
     
            <select name="cat_name_child" id="cat_name_child" onChange="getChildItemValue();" required>

 <?php              
             echo '<option value="" disabled="disabled" selected="selected">Select Category </option>';         

                 
               $query00 = "SELECT * FROM category WHERE cat_is_delete IS NULL AND cat_approved = 1";
               $run00 = mysqli_query($conn,$query00);

               if(mysqli_num_rows($run00)>0){
                while($row00 = mysqli_fetch_array($run00)){                     
                    echo "<option value='".$row00['cat_id']."'>". $row00['cat_name']."</option>";                
                }
               }  
               ?>

    </select>
</div>

</div>
<div id="maps_group_child_name" class="form-group col-lg-6">

</div>

    </div>
    <div class = "row"  id = "hiddenSubmitGroup" style = "display:none">
                
                <div class = "form-group col-lg-6">
                <?php 
                 if(isset($_REQUEST['newgroup']) || isset($addgroupfail)){
                     echo '<input type="submit" name = "submit" value = "Add Item Group" class="btn btn-success">';
                   }
                   ?>
                </div>
                
                
                <div class = "form-group col-lg-6">
                </div>
     
                </div><!-- row inside form -->

    </form>
           </div><!-- col 12  -->
           </div><!-- row  -->
</div><!-- panel body -->  

<?php
}

if(isset($_REQUEST['editcat']) || isset($editcatfail) || isset($_REQUEST['newcat']) || isset($addcatfail)){
?>  
<?php  ?>       

<div class="row">

<div class="form-group col-lg-6">
<label for="maps_name">Category Name</label>

     
       <input type='text' class='form-control' name='cat_name' id='cat_name' value='<?php echo $cat_name?>' required>
</div>
<div class="form-group col-lg-6">
       
</div>

    </div><!--  -->
         
              
            <div class = "row">
                
           <div class = "form-group col-lg-6">
           <?php 
              if(isset($_REQUEST['editcat']) || isset($editcatfail)){
                  echo '<input type="submit" name = "submit" value = "Edit Category" class="btn btn-success">';

            }else if(isset($_REQUEST['newcat']) || isset($addcatfail)){
                echo '<input type="submit" name = "submit" value = "Add Category" class="btn btn-success">';
              }
              ?>
           </div>
           
           
           <div class = "form-group col-lg-6">
           </div>

           </div><!-- row inside form -->
               
           
            
           </form>
           </div><!-- col 12  -->
           </div><!-- row  -->
</div><!-- panel body -->             
           <?php  }   ?>
<!-- panel-body  -->

   <?php

if(isset($_REQUEST['edit']) || isset($editfail) || isset($_REQUEST['new']) || isset($addfail) || isset($add_fail)){
?>  
<?php  ?>
<div class="row">

      <div class="form-group col-lg-6">
      <?php 
               if(strlen($ref_photo)>3){
                echo '<label for="ref_photo">Change Reference Photo</label><br>';
                echo "<img src = 'maps_ref_image.php?i=".$ref_photo."' height = '100px' width = '150px'><br><br>";

               }else{
                echo '<label for="ref_photo">Upload Reference Photo</label>';

               }
               
        ?>

                           <!-- <input class="upload-file" data-max-size="1024" type="file" name="ref_photo" id="ref_photo"> -->
                           <br>


            <!--                <label class="btn btn-primary" for = "ref_photo">
    Browse --><input class="btn btn-success" data-max-size="1024" accept="image/*" type="file" name="ref_photo" id="ref_photo" ><!-- </label> -->
    </div>
    <div class="form-group col-lg-6">
             
    </div>
    
          </div><!--  -->

          <div class="row">

<div class="form-group col-lg-6">
<label for="cat_name">Category</label>     
     
            <select name="cat_name" id="cat_name" required autofocus>

 <?php 
               if(strlen($cat_name)>0){
                  
                echo "<option value = '$cat_id' selected='selected'>$cat_name</option>";

               }else{
                   echo '    <option value="" disabled="disabled" selected="selected">Select Category </option>
                   ';               

               }   
               $query00 = "SELECT * FROM category WHERE cat_is_delete IS NULL AND cat_approved = 1";
               $run00 = mysqli_query($conn,$query00);

               if(mysqli_num_rows($run00)>0){
                while($row00 = mysqli_fetch_array($run00)){
                     if(!($cat_name == $row00['cat_name'])){ 
                    echo "<option value='".$row00['cat_id']."'>". $row00['cat_name']."</option>";
                     }
                }
               }  
               ?>

    </select>
</div>
<div class="form-group col-lg-6">
       
</div>

    </div>
    <!--  -->

<div class="row">

<div class="form-group col-lg-6">
<label for="maps_name">Job Task</label>

     
       <input type='text' class='form-control' name='maps_name' id='maps_name' value='<?php echo $maps_name?>' required>
</div>
<div class="form-group col-lg-6">
       
</div>

    </div><!--  -->
<div class="row">

      <div class="form-group col-lg-6">
      <label for="description">Job Description</label>

            <textarea rows="5" name="description" class = "form-control" id="description" placeholder=""  maxlength="5000"><?php echo $description; ?></textarea>
    </div>

    <div class="form-group col-lg-6">
    <label for="photo_req">Picture Requirement</label>
    <textarea rows="5" name="photo_req" class = "form-control" id="photo_req" placeholder=""  maxlength="5000"><?php echo $photo_req; ?></textarea>
    </div>
    
          </div><!--  -->

          <div class="row" id = "UOMsetDeleteRow">

<div class="form-group col-lg-4">
<label for="client_allow_price">Client Allowable Price</label>

     
       <input type='text' class='form-control' name='client_allow_price' id='client_allow_price' value='<?php echo $client_allow_price?>'>
</div>
<div class="form-group col-lg-4">
<label for="min_bid_price">Minimum Bid Price</label>

     
<input type='text' class='form-control' name='min_bid_price' id='min_bid_price' value='<?php echo $min_bid_price?>' >
</div>
<div class="form-group col-lg-4">
<label for="crew_pay">Crew Pay</label>

     
<input type='text' class='form-control' name='crew_pay' id='crew_pay' value='<?php echo $crew_pay?>' >

</div>
    </div><!--  -->

 <div class="row">

<div class="form-group col-lg-6">
<label for="maps_uom">UOM</label>     
     
            <select name="maps_uom" id="maps_uom" class="maps_uom" onChange="getUOMvalue();">

 <?php 
               if(strlen($maps_uom)>0){
                  
                echo "<option value = '$maps_uom_id' selected='selected'>$maps_uom</option>";
                
                
               }else{
                   echo '    <option value="" disabled="disabled" selected="selected">Select UOM </option>
                   ';               

               }   
               $query00 = "SELECT * FROM uom WHERE uom_is_delete IS NULL";
               $run00 = mysqli_query($conn,$query00);

               if(mysqli_num_rows($run00)>0){
                while($row00 = mysqli_fetch_array($run00)){
                     if(!($maps_uom == $row00['uom_name'])){ 
                    echo "<option value='".$row00['uom_id']."'>". $row00['uom_name']."</option>";
                     }
                }
               }  
               ?>
               <option value="">Each </option>

    </select>
</div>
<div class="form-group col-lg-6">
       
</div>

    </div>

    <div class = "row">
    <div class="form-group col-lg-6" id = "displayUOMvalueForm">
       
</div>
    <div class = "form-group col-lg-6">
    </div>
    </div>
              
            <div class = "row">
                
           <div class = "form-group col-lg-6">
          
          
<?php
if(isset($_REQUEST['edit']) || isset($editfail)|| isset($addfail)){
                  echo '<input type="submit" name = "submit" value = "Edit Product" class="btn btn-success">';

            }else if(isset($_REQUEST['new']) || isset($add_fail)){
                echo '<input type="submit" name = "submit" value = "Add Product" class="btn btn-success">';
              }
              ?>
           </div>
           
           
           <div class = "form-group col-lg-6">
           </div>

           </div><!-- row inside form -->
               
           
            
           </form>
           </div><!-- col 12  -->
           </div><!-- row  -->
</div><!-- panel body -->             
           <?php  }   ?>
<!-- panel-body  -->
            </div> <!-- panel panel-default -->
       </div> <!--  col lg 12-->
   </div> <!-- row -->
   <?php
if(isset($_REQUEST['group']) || isset($_REQUEST['newgroup'])|| isset($_REQUEST['editgroup'])|| isset($editgroupfail)|| isset($addgroupfail)||  isset($_REQUEST['editgroupverify'])|| isset($_REQUEST['addgroupverify'])){ ?>
    <div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
        <div class="panel-body">

                        <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz">
                                <thead>
                                    <tr>
                                    <th>
                                               Edit Group
                                            </th>
                                            
                                         
                                            <th>
                                            Main Item

                                            </th>
                                            <th>
                                            Sub Items

                                            </th>
                                           
                                        
                                        </tr>
                                    </thead>
                                    <tbody>
<?php
if($conn){
   $query_maps = "SELECT * FROM maps WHERE client_id = $url_client_id AND maps_is_delete IS NULL AND maps_approved = 1 ORDER BY maps_name"; 

   $run_maps = mysqli_query($conn, $query_maps); 
   if(mysqli_num_rows($run_maps)>0){
       foreach($run_maps as $mapps){
            $maps_ID = $mapps['maps_id'];
            $maps_NAME = $mapps['maps_name'];
            $query_maps_group = "SELECT * FROM maps_group WHERE parent_id = $maps_ID AND is_delete IS NULL AND is_approve = 1"; 
            $run_maps_group = mysqli_query($conn, $query_maps_group);
            if(mysqli_num_rows($run_maps_group)>0){
                echo '<tr class="odd gradeX">';
                echo '<td><a href="MAPS-sheet.php?editgroup='.$maps_ID.'&cl_id='.$url_client_id.'">Edit</a></td>';             
                echo '<td>' .$maps_NAME. '</td>';
                echo '<td>';                                 

                while($row = mysqli_fetch_array($run_maps_group)){
                    $sub_id = $row['sub_id'];
                    $query_maps1 = "SELECT maps_name FROM maps WHERE maps_id = $sub_id"; 
                    $run_maps1 = mysqli_query($conn, $query_maps1); 
                    if(mysqli_num_rows($run_maps1) == 1){
                        foreach($run_maps1 as $mappss){
                            $sub_NAME = $mappss['maps_name'];                           
                            echo $sub_NAME. ", ";                                   
                            
                        }
                    }                    
                }
                echo '</td>';  
                echo '</tr>';
               
            }
        }

   }


   
}
?>
                                        
                                        </tbody>                                    
                                </table>                                    
                                </div><!-- panel-body  -->
             </div> <!-- panel panel-default -->
        </div> <!--  col lg 12-->
    </div> <!-- row -->
    <div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
        <div class="panel-body">

                        <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz2">
                                <thead>
                                    <tr>
                                    <th>
                                               Approve / Decline
                                            </th>
                                            <th>
                                            Main Item

                                            </th>
                                            <th>
                                            Sub Item

                                            </th>
                                            <th>
Added by                                                </th>
                                            
                                        
                                           
                                        
                                        </tr>
                                    </thead>
                                    <tbody>
<?php
if($conn){
    $query_maps = "SELECT * FROM maps WHERE client_id = $url_client_id AND maps_is_delete IS NULL AND maps_approved = 1 ORDER BY maps_name"; 
 
    $run_maps = mysqli_query($conn, $query_maps); 
    if(mysqli_num_rows($run_maps)>0){
        foreach($run_maps as $mapps){
             $maps_ID = $mapps['maps_id'];
             $maps_NAME = $mapps['maps_name'];
             $query_maps_group = "SELECT * FROM maps_group WHERE parent_id = $maps_ID AND is_delete IS NULL AND is_approve = 0"; 
             $run_maps_group = mysqli_query($conn, $query_maps_group);
             if(mysqli_num_rows($run_maps_group)>0){                                            
 
                 while($row = mysqli_fetch_array($run_maps_group)){
                     $sub_id = $row['sub_id'];
                     $maps_group_id = $row['id'];
                     $EMP_id = $row['employee_id'];
                     $query111 = "SELECT employee_fname,employee_lname FROM employee WHERE employee_id = $EMP_id";
                     $run111 = mysqli_query($conn, $query111);
                     $row111 = mysqli_fetch_array($run111);            
                     $EMP_name = $row111['employee_fname'] .' '.$row111['employee_lname'];
                     $query_maps1 = "SELECT maps_name FROM maps WHERE maps_id = $sub_id"; 
                     $run_maps1 = mysqli_query($conn, $query_maps1); 
                     if(mysqli_num_rows($run_maps1) == 1){
                         foreach($run_maps1 as $mappss){
                             $sub_NAME = $mappss['maps_name'];   
                             echo '<tr class="odd gradeX" style = "background-color:#ffbb96">';
                             echo '<td><a href="MAPS-sheet.php?group=&addgroupapprove='.$maps_group_id.'&cl_id='.$url_client_id.'" class = "btn btn-success">Approve</a><br><a href="MAPS-sheet.php?group=&addgroupdecline='.$maps_group_id.'&cl_id='.$url_client_id.'" class = "btn btn-danger">Decline&nbsp</a></td>';              
                             echo '<td>' .$maps_NAME. '</td>';
                             echo '<td>';                                  
                             echo $sub_NAME;  
                             echo '</td>'; 
                             echo '<td>';                            
                             echo $EMP_name;  
                             echo '</td>'; 
                             echo '</tr>';                               
                             
                         }
                     }                    
                 }
                 
                
             }
         }
 
    }
    
 } 
?>
                                        
                                        </tbody>                                    
                                </table>                                    
                                       </div><!-- panel-body  -->
             </div> <!-- panel panel-default -->
        </div> <!--  col lg 12-->
    </div> <!-- row -->  
<?php
}elseif(isset($_REQUEST['cat']) || isset($_REQUEST['newcat'])|| isset($_REQUEST['editcat'])|| isset($_REQUEST['deletecat'])|| isset($_REQUEST['conf-cat-delete'])|| isset($editcatfail)|| isset($addcatfail)|| isset($deletecatfail)|| isset($_REQUEST['editcatverify'])|| isset($_REQUEST['addcatverify'])){
?>     
     <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">

                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz">
                                    <thead>
                                        <tr>
                                        <th>
                                                   Edit / Delete Row
                                                </th>
                                                
                                             
                                                <th>
                                                Category Name

                                                </th>
                                            
                                               
                                            
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
    if($conn){
        
       $query = "SELECT * FROM category WHERE cat_is_delete IS NULL AND cat_approved = 1 ORDER BY cat_name"; 
        $run = mysqli_query($conn, $query);
        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){   
                $cat_id = $row['cat_id'];
                $cat_name = $row['cat_name'];               
                $description = $row['cat_desc'];      
                echo '<tr class="odd gradeX">';
                echo '<td><a href="MAPS-sheet.php?editcat='.$cat_id.'&cl_id='.$url_client_id.'">Edit</a><br><a href="MAPS-sheet.php?deletecat='.$cat_id.'&cl_id='.$url_client_id.'">Delete</a></td>';                
                
                echo '<td>' .$cat_name. '</td>';
                                  
                echo '</tr>';
            }
        }
    }
?>
                                            
                                            </tbody>                                    
                                    </table>                                    
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->
        <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">

                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz2">
                                    <thead>
                                        <tr>
                                        <th>
                                                   Approve / Decline
                                                </th><th>
                                                Category Name

                                                </th>
                                                <th>
Added by                                                </th>
                                                
                                            
                                               
                                            
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
    if($conn){
        
       $query = "SELECT * FROM category WHERE cat_is_delete IS NULL AND cat_approved = 0 ORDER BY cat_id DESC"; 
        $run = mysqli_query($conn, $query);
        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){   
                $cat_id = $row['cat_id'];
                $cat_name = $row['cat_name'];               
                $description = $row['cat_desc'];
                $empl_id =   $row['employee_id'];
                $query111 = "SELECT employee_fname,employee_lname FROM employee WHERE employee_id = $empl_id";
                $run111 = mysqli_query($conn, $query111);
                if(mysqli_num_rows($run111) >0){
                    $row111 = mysqli_fetch_array($run111);
                
                    $emp_name = $row111['employee_fname'] .' '.$row111['employee_lname'];
                   
                }  
                echo '<tr class="odd gradeX" style = "background-color:#ffbb96">';
                echo '<td><a href="MAPS-sheet.php?cat=&addcatapprove='.$cat_id.'&cl_id='.$url_client_id.'" class = "btn btn-success">Approve</a><br><a href="MAPS-sheet.php?cat=&addcatdecline='.$cat_id.'&cl_id='.$url_client_id.'" class = "btn btn-danger">Decline&nbsp</a></td>'; 
                              
                echo '<td>' .$cat_name. '</td>';
                echo '<td>' .$emp_name. '</td>'; 
                                  
                echo '</tr>';
            }
        }
    }
?>
                                            
                                            </tbody>                                    
                                    </table>                                    
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->   
        
        
        
        
        <?php  }else{   ?>   
        


     <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz-MAPS-sheet">
                                    <thead>
                                        <tr>
                                        <th>
                                                   Edit / Delete Row
                                                </th>
                                                <th>
                                                Reference Photo
                                                </th>
                                                <th>
                                                Category

                                                </th>
                                                <th>
                                                Job Task     
                                                </th>                                                
                                               
                                                <th>
                                                Description
                                                </th>
                                                <th>
Client Allowable Price                                                </th>
                                               
                                            <th>Minimum Bid Price</th>
                                            <th>Crew Pay</th>
                                            <th>UOM</th>
                                            <th>Photo Requirements</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
                                            </tbody>
                                    
                                    </table>
                                    
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->
        
        <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
            <div class="panel-body">
                            <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-bidwiz2">
                                    <thead>
                                        <tr>
                                        <th>
                                            Approve / Decline
                                                </th>
                                                <th>
                                                Job Task     
                                                </th>
                                                <th>
                                                Reference Photo
                                                </th>
                                                <th>
                                                Category
                                                </th>                                              
                                                <th>
                                                Description
                                                </th>
                                                <th>
Client Allowable Price                                                </th>
                                               
                                            <th>Minimum Bid Price</th>
                                            <th>Crew Pay</th>
                                            <th>UOM</th>
                                            <th>Photo Requirements</th>
                                            <th>
Added by                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
<?php
    if($conn){        
       $query = "SELECT * FROM maps LEFT JOIN category
        ON maps.cat_id = category.cat_id  WHERE maps.maps_is_delete IS NULL AND maps.client_id = $url_client_id AND maps.maps_approved = 0 ORDER BY category.cat_name"; 
        $run = mysqli_query($conn, $query);
        if(mysqli_num_rows($run)>0){
            while($row = mysqli_fetch_array($run)){
                $maps_id = $row['maps_id'];
                $ref_photo = $row['maps_ref_pic'];
                $cat_name = $row['cat_name'];
                $maps_name = $row['maps_name'];
                $description = $row['maps_desc'];
                $client_allow_price = $row['maps_client_allow_price'];
                $min_bid_price = $row['maps_min_bid_price'];
                $crew_pay = $row['maps_crew_pay'];
                $photo_req = $row['maps_photo_req'];
                $maps_uom =$row['maps_crew_unit_uom_id'];
                $query_emp = "SELECT * FROM maps WHERE maps_id = $maps_id"; 
                $run_emp = mysqli_query($conn, $query_emp);
                $row_emp = mysqli_fetch_array($run_emp);
                $empl_id =  $row_emp['employee_id'];
                $query111 = "SELECT employee_fname,employee_lname FROM employee WHERE employee_id = $empl_id";
                $run111 = mysqli_query($conn, $query111);
                if(mysqli_num_rows($run111) >0){
                    $row111 = mysqli_fetch_array($run111);                
                    $emp_name = $row111['employee_fname'] .' '.$row111['employee_lname'];
                   
                }  
if($maps_uom == NULL){

}else{
    $query22 = "SELECT uom_name FROM uom WHERE uom_id = $maps_uom";
                
    $run22 = mysqli_query($conn, $query22);
if(mysqli_num_rows($run22)==1){
$row22 = mysqli_fetch_array($run22);

$maps_uom = $row22['uom_name'];
}

}                                  
                

                echo '<tr class="odd gradeX" style = "background-color:#ffbb96">';
                echo '<td><a href="MAPS-sheet.php?addmapsapprove='.$maps_id.'&cl_id='.$url_client_id .'" class = "btn btn-success">Approve</a><br><a href="MAPS-sheet.php?addmapsdecline='.$maps_id.'&cl_id='.$url_client_id .'" class = "btn btn-danger">Decline&nbsp</a></td>'; 
                echo '<td>' .$maps_name. '</td>';
                echo '<td><img src = "maps_ref_image.php?i='.$ref_photo.'" height = "80px" width = "120px">'. '</td>';
                echo '<td>' .$cat_name. '</td>';
                echo '<td>' .$description. '</td>';
                echo '<td>' .$client_allow_price. '</td>';
                echo '<td>' .$min_bid_price. '</td>';
                echo '<td>' .$crew_pay. '</td>';                
                echo '<td>' .$maps_uom. '</td>';
                echo '<td>' .$photo_req. '</td>';
                echo '<td>' .$emp_name. '</td>';               
                echo '</tr>';
            }
        }

    }

?>
                                            
                                            </tbody>
                                    
                                    </table>
                                    
                                    </div><!-- panel-body  -->
                 </div> <!-- panel panel-default -->
            </div> <!--  col lg 12-->
        </div> <!-- row -->
        <?php  }   ?>
        <!--  -->
<?php
if($url_client_id == 0){?>
 </div>
  <!--  active div (div end)-->
<?php
   $query_client_find3 = "SELECT * FROM client WHERE client_id > $url_client_id AND is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";

   $run_client_find3 = mysqli_query($conn, $query_client_find3);

   if(mysqli_num_rows($run_client_find3)>0){   
   
       while($row_client_find3 = mysqli_fetch_array($run_client_find3)){
           $client_id_tab23 = $row_client_find3['client_id'];?>
           <div id="new<?php echo $client_id_tab23.$client_id_tab23?>">
           <div id="old<?php echo $client_id_tab23.$client_id_tab23?>">
           
           <p>Loading</p>
           </div>
           
           </div>
<?php }

   }


    }else{
        echo "</div><!--  active div (div end)-->";
        
        $query_client_find3 = "SELECT * FROM client WHERE client_id > $url_client_id AND is_approve = 1 AND client_is_delete IS NULL AND is_list = 1";

        $run_client_find3 = mysqli_query($conn, $query_client_find3);

        if(mysqli_num_rows($run_client_find3)>0){   
        
            while($row_client_find3 = mysqli_fetch_array($run_client_find3)){
                $client_id_tab23 = $row_client_find3['client_id'];?>
                <div id="new<?php echo $client_id_tab23.$client_id_tab23?>">
                <div id="old<?php echo $client_id_tab23.$client_id_tab23?>">
                
                <p>Loading</p>
                </div>
                
                </div>
    <?php }
    
        }
    } 
?> 


<div id="newListz">
<?php 
                    if(isset($successmessage)){
                    echo '<div class="alert alert-success">
                    <strong>'. $successmessage .'</strong></div>';
                }               

                if(isset($message)){
                    echo '<div class="alert alert-danger">
                    <strong>'. $message .'</strong>
                  </div>';
                }
                    ?>  
    <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3>Make a New MAPS for Client</h3>
                    </div>
                    <div class="panel-body">                      
                        <div class = "row">                       
                            <div class="col-lg-12">
                                <form action = 'MAPS-sheet.php?addnewpricelist=#newListz' method = 'POST' class = 'form-group' enctype = 'multipart/form-data'>
                                <div class="row">

                                    <div class="form-group col-lg-6">
                                        <label for="maps_client_list_id">Choose Client</label>  
     
                                            <select name="maps_client_list_id" id="maps_client_list_id">
                                              <option value="" disabled = "disabled" selected = "selected">Select New Client</option>
                

               <?php    
               $query00 = "SELECT * FROM client WHERE is_approve = 1 AND client_is_delete IS NULL AND is_list IS NULL ORDER BY client_name";
               $run00 = mysqli_query($conn,$query00);

               if(mysqli_num_rows($run00)>0){
                while($row00 = mysqli_fetch_array($run00)){
                    echo "<option value='".$row00['client_id']."'>". $row00['client_name']."</option>";
                }
               }  
               ?>

    </select>
</div>
<div class="form-group col-lg-6">
       
</div>

    </div>

    <div class = "row">
        <div class="form-group col-lg-6">
        <label for="maps_ext_client_list_id">Choose Existing Price List</label>  
     
     <select name="maps_ext_client_list_id" id="maps_ext_client_list_id">
       <option value="" disabled = "disabled" selected = "selected">Existing Price List</option>
       <option value="0">Main Price List</option>

<?php    
$query00 = "SELECT * FROM client WHERE is_approve = 1 AND client_is_delete IS NULL AND is_list = 1 ORDER BY client_name";
$run00 = mysqli_query($conn,$query00);

if(mysqli_num_rows($run00)>0){
while($row00 = mysqli_fetch_array($run00)){
echo "<option value='".$row00['client_id']."'>". $row00['client_name']."</option>";
}
}  
?>

<option value="">Empty Price List</option>

</select>
        
        </div>
        <div class = "form-group col-lg-6">
        </div>
    </div>              
            <div class = "row">                
                <div class = "form-group col-lg-6">
                        <input type="submit" name = "submit" value = "Create List" class="btn btn-success">
                </div>                         
                <div class = "form-group col-lg-6">
                </div>
           </div><!-- row inside form -->

                                <form>
                            </div>
                        </div><!-- <div id="newListz"> --> 
                    </div>
                </div>
            </div>
    </div>
</div><!-- <div id="newListz"> --> 
<!-- Modal -->
<div id="vendorModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Upload Item Excel</h4>
      </div>
      <div class="modal-body">
      <div class="alert alert-danger" role="alert" id = 'vendor-alert' style='display:none'>
    <p id='danger_text'></p> 
 </div>
 <div class="alert alert-info" role="alert" id = 'vendor-alert-warning' style='display:none'>
    <p id='danger_text_warning'>Excel is uploading.</p> 
 </div>

<div class="alert alert-success" role="alert" id = 'vendor-alert-success' style='display:none'>
 <p id='danger_text1'>
</p> </div>
<form id="bid_item_excel" enctype="multipart/form-data">
<div class = "row">
        
        <div class = "form-group col-lg-6">
        <label for="price_list">Choose Client:</label>

        <input type='text' class='form-control' name='price_list' id='price_list'>
        <input type='hidden' class='form-control' name='price_list1' id='price_list1'>
        </div>
    
    
        <div class = "form-group col-lg-6">
        <a href="excels/items.xlsx" download class="btn btn-danger" style = 'float:right;'>
                       Line Item Excel Format
                   </a>                   

        </div>
       
        </div> 
<div class = "row">
        
        <div class = "form-group col-lg-6">
        <label for="fileToUpload1">Choose Excel to upload</label>

        <input type="file" class="upload-file" name="fileToUpload1" id="fileToUpload1">
        </div>
    
    
        <div class = "form-group col-lg-6">
                    

        </div>
       
        </div> 
       
    </form>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>

    </div> <!--  page wrapper -->
                              
       
        <script>
    var deleteLinks = document.querySelectorAll('.delete');

for (var i = 0; i < deleteLinks.length; i++) {
  deleteLinks[i].addEventListener('click', function(event) {
	  event.preventDefault();

	  var choice = confirm(this.getAttribute('data-confirm'));

	  if (choice) {
	    window.location.href = this.getAttribute('href');
	  }
  });
}
    </script>
    <script>
    function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#upload')
                        .attr('src', e.target.result)
                        .width(600)
                        .height(300);
                };

                reader.readAsDataURL(input.files[0]);
            }
        }
    </script>
<?php  include "footer.php";   ?>