<?php

 error_reporting(0);
include("include/config.php"); 


##########################################################################################
      
if(array_key_exists("update_admin_profile",$_REQUEST)){
    $admin_username = $_POST['admin_userNames'];
    echo $admin_username . "<br>";
    
    $sqlAssign1 = "select * from `admin_more_info` WHERE `user_name` = '$admin_username'";										
        $resultAssign1 = mysqli_query($conn, $sqlAssign1);											
        if (mysqli_num_rows($resultAssign1) > 0) {
        $i=1;
        while($rowAssign1 = mysqli_fetch_assoc($resultAssign1)) {
            $logo = $rowAssign1['logo_img'];
            $fav = $rowAssign1['fav_img'];
            $logo_sticky = $rowAssign1['logo_sticky'];
        }
    }
//    echo "update_admin_profile" . " $sqlAssign1 " . $username; die;
    
    $admin_wesite_name = $_POST['website_name'];
    $admin_owner_name = $_POST['owner_name'];
    $admin_phone = $_POST['phone'];
    $admin_phone_op = $_POST['phone_op'];
    $admin_email = $_POST['email'];
    $admin_email_op = $_POST['email_op'];
    $admin_address = $_POST['address'];
    $admin_about_us = mysqli_real_escape_string($conn,$_POST['ckeditor_about_us']);
    $admin_Mission = mysqli_real_escape_string($conn,$_POST['ckeditor_Mission']);
    $admin_Vision = mysqli_real_escape_string($conn,$_POST['ckeditor_Vision']);
    $admin_strength = mysqli_real_escape_string($conn,$_POST['ckeditor_strength']);
    
    @$fb_link = $_POST['fb_link'];
    @$youtube_link = $_POST['youtube_link'];
    @$instagram_link = $_POST['instagram_link'];
    @$linkedin_link = $_POST['linkedin_link'];
//    $admin_userName = $_POST['admin_userName'];

//    forlogo
            if(isset($_FILES['image_a']['name']))

                {

                    $fileName1 = time().$_FILES["image_a"]["name"];   

                    $fileTmpLoc1 = $_FILES["image_a"]["tmp_name"];

                    $fileType1 = $_FILES["image_a"]["type"];

                    $fileSize1 = $_FILES["image_a"]["size"];

                    $fileErrorMsg1 = $_FILES["image_a"]["error"];

                    $kaboom1 = explode(".", $fileName1);

                    $fileExt1 = end($kaboom1);



                    $moveResult1 = move_uploaded_file($fileTmpLoc1, "upload/$fileName1"); 

                }

    

            if(empty($_FILES['image_a']['name'])) 

                { 

                    $fileName1 = $logo; 

                }

//               for sticky logo
     

          if(isset($_FILES['image_c']['name']))

                {

                    $fileName21 = time().$_FILES["image_c"]["name"];   

                    $fileTmpLoc21 = $_FILES["image_c"]["tmp_name"];

                    $fileType21 = $_FILES["image_c"]["type"];

                    $fileSize21 = $_FILES["image_c"]["size"];

                    $fileErrorMsg21 = $_FILES["image_c"]["error"];

                    $kaboom21 = explode(".", $fileName21);

                    $fileExt2 = end($kaboom21);



                    $moveResult21 = move_uploaded_file($fileTmpLoc21, "upload/$fileName21"); 

                }

    

            if(empty($_FILES['image_c']['name'])) 

                { 

                    $fileName21 = $logo_sticky; 

                }
//for fav icon
            if(isset($_FILES['image_b']['name']))

                {

                    $fileName2 = time().$_FILES["image_b"]["name"];   

                    $fileTmpLoc2 = $_FILES["image_b"]["tmp_name"];

                    $fileType2 = $_FILES["image_b"]["type"];

                    $fileSize2 = $_FILES["image_b"]["size"];

                    $fileErrorMsg2 = $_FILES["image_b"]["error"];

                    $kaboom2 = explode(".", $fileName2);

                    $fileExt2 = end($kaboom2);



                    $moveResult2 = move_uploaded_file($fileTmpLoc2, "upload/$fileName2"); 

                }

    

            if(empty($_FILES['image_b']['name'])) 

                { 

                    $fileName2 = $fav; 

                }


         $query = "UPDATE `admin_more_info` SET `website_name` = '$admin_wesite_name',
                                        `phone` = '$admin_phone',
                                        `op_phone` = '$admin_phone_op',
                                        `email` = '$admin_email',
                                        `op_email` = '$admin_email_op',
                                        `address` = '$admin_address',
                                        `logo_img` = '$fileName1',
                                        `logo_sticky` = '$fileName21',
                                        `fav_img` = '$fileName2',
                                        `about_us` = '$admin_about_us',
                                        `mission` = '$admin_Mission',
                                        `vision` = '$admin_Vision',
                                        `strength` = '$admin_strength',
                                        `facebook` = '$fb_link',
                                        `youtube` = '$youtube_link',
                                        `linkedin` = '$linkedin_link',
                                        `insta` = '$instagram_link'
                                        where (`admin_more_info`.`user_name` = '$admin_username');";
    
//        echo $query; die;

    $query .= "UPDATE `user_login` SET `name` = '$admin_owner_name',
                                        `email` = '$admin_email',
                                        `phone` = '$admin_phone'
                                                                               
                                        where (`username` = '$admin_username');";
// echo $query; die;

 $result = mysqli_multi_query($conn, $query);

//           if (mysqli_query($conn, $query)) {
    if($result){
				header("location:profile.php");
			} 
            
			else {
//				include('include/error-modal.php');
                echo "qu faild to update data";
			}
			mysqli_close($conn);

    }      
###################################################################################

?>