<?php
	session_start();
	include"../../connect/db.php"; 
?> 
 <?php
 $chap = $_SESSION['chap'];
        csrf_verify();
 	if( isset($_POST['amount2']) ){
       

 		$amount2 = mysqli_real_escape_string($mysqli,$_POST['amount2']);
 		
         $target_dir = "../../chairman/checkuploads/".$chap."/";
         $img_loc = "checkuploads/".$chap."/";
         $target_file = $target_dir . basename($_FILES["profile-pic"]["name"]);
         $target_file2 = $target_dir . basename($_FILES["profile-pic2"]["name"]);  
         $img = basename($_FILES["profile-pic"]["name"])."|".basename($_FILES["profile-pic2"]["name"]);
         $uploadOk = 1;
         $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
         $imageFileType2 = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
         // Define the directory paths
$target_dir = "../../chairman/checkuploads/" . $chap . "/";
if (!is_dir($target_dir)) {
    mkdir($target_dir, 0777, true); // Create directory with permissions and recursive option
}
         // Check if image file is a actual image or fake image
         if(isset($_POST["submit"])) {
             $check = getimagesize($_FILES["profile-pic"]["tmp_name"]);
             if($check !== false) {
                 $uploadOk = 1;
             } else {
                 echo "File is not an image.";
                 exit();
                 $uploadOk = 0;
             }
         }
         // Check file size
         if ($_FILES["profile-pic"]["size"] > 5000000) {
             echo "Sorry, your file is too large.";
             exit();
             $uploadOk = 0;
         }
         // Allow certain file formats
         if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
         && $imageFileType != "gif" ) {
             echo "Not allowed";
             exit();
             $uploadOk = 0;
         }
          // Allow certain file formats
          if($imageFileType2 != "jpg" && $imageFileType2 != "png" && $imageFileType2 != "jpeg"
          && $imageFileType2 != "gif" ) {
              echo "Not allowed";
              exit();
              $uploadOk = 0;
          }
         // Check if $uploadOk is set to 0 by an error
         if ($uploadOk == 0) {
             echo "Sorry, your file was not uploaded.";
             exit();

         // if everything is ok, try to upload file
         } else {
            //  mkdir($target_dir);
            if (move_uploaded_file($_FILES["profile-pic"]["tmp_name"], $target_file2)) {


             if (move_uploaded_file($_FILES["profile-pic2"]["tmp_name"], $target_file)) {


                $seed = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); // and any other characters
                shuffle($seed); // probably optional since array_is randomized; this may be redundant
                $rand = '';
                foreach (array_rand($seed, 7) as $k) $rand .= $seed[$k];								            
                $transId =  $rand; 
                $d_o_t = date("Y-m-d");	


                $sql = mysqli_query($mysqli,"SELECT * FROM users WHERE email = '$chap' ");
	
                $row = mysqli_fetch_assoc($sql);

                $currency = $row['usercurrency'];
                $account_num = $row['account_num'];

                $kay = mysqli_query($mysqli, "INSERT INTO transactions (trans_id, user, description, date, type, status, img, amount,scope) 
                VALUES ('$transId', '$account_num', 'Check deposit of $currency$amount2', '$d_o_t', 'Credit','Pending', '$img', '$amount2','Check Deposit')");

                 if($kay){

                echo"success";
                         
                 }
                 else{
                     echo mysqli_error($mysqli);
                 }


             }
             else {
                 echo "Signup error";
                 exit();
             }
            }
            else {
                echo "Signup error";
                exit();
            }


    }
} 	

 ?>