<?php
/**
 * Created by PhpStorm.
 * User: freuddebian
 * Date: 08/10/18
 * Time: 11:56
 */

require_once ('../database/Requester.php');

$tag="";

$postdata = file_get_contents("php://input");
$request=null;

if(isset($postdata)) {
    $request = json_decode($postdata);
}

if(isset($request)){

}
function askCredit($request){
    $requester=new Requester(null);
    $demand = $requester->storeCreditAsk($codeMembre, $codeParrain,$montant);
    $usr= $requester->getUser($phone)[0];

    if ($demand) {


        $subject = "Nouvelle demande de crédit";

        $email = $usr['email'];
        $message = "Bonjour,\n\nVotre demande de crédit a été envoyée.\nNumero de telephone :
             $phone \n\n\nCordialement,\nL'équipe Ilink.";
        $from = "noreply@ilink.com";
        $headers = "From:" . $from;
        $name = "ilink";
        mail($email, $subject, $message, $headers);
        // Start Sending SMS
        $sms = $client->account->messages->create(

        // the number we are sending to - Any phone number
            $phone,

            array(
                // Step 6: Change the 'From' number below to be a valid Twilio number
                // that you've purchased
                'from' => $sender_number,


                // the sms body
                'body' => $message
            )
        );
        // Stop Sending SMS


        //smtpmailer($email,$from,$name,$subject,$message);
        $response["success"] = 1;
        echo json_encode($response);
    } else {
        // user failed to store
        $response["error"] = 1;
        $response["error_msg"] = "La demande n'a pas pu être envoyée!";
        echo json_encode($response);

    }
}
