<?php
include("config.php");
include("functions.php");
if(!empty($_FILES['image'])){
    $up=uploadFile('image',array('jpg','jpeg','png','gif'));
    if($up !='0'){
        $msg=base_url().$up;
        $to=$_SESSION["from"];
        $send=send($to,$msg,'image');
        exit($send);
    }else{
        exit("2");
    }
}
if(!empty($_FILES['video'])){
    $up=uploadFile('video',array('mp4','m4p','wmv','avi'));
    if($up !='0'){
        $msg=base_url().$up;
        $to=$_SESSION["from"];
        $send=send($to,$msg,'video');
        exit($send);
    }else{
        exit("2");
    }
}
if(!empty($_FILES['audio'])){
    $up=uploadFile('audio',array('mp3','aac','wma','m4a','mpga'));
    if($up !='0'){
        $msg=base_url().$up;
        $to=$_SESSION["from"];
        $send=send($to,$msg,'audio');
        exit($send);
    }else{
        exit("2");
    }
}
if(!empty($_FILES['document'])){
    $up=uploadFile('document',array());
    if($up !='0'){
        $msg=base_url().$up;
        $to=$_SESSION["from"];
        $send=send($to,$msg,'document');
        exit($send);
    }else{
        exit("2");
    }
}
if(!empty($_POST['lat']) && !empty($_POST['lng'])){
    $msg=$lat=$lng='';
    $lat=$_POST['lat'];
    $lng=$_POST['lng'];
    $to=$_SESSION["from"];
    $send=send($to,$msg,'location',$lat,$lng);
    exit($send);
}
if(!empty($_POST["message"]) ){
    $msg=$_POST["message"];
    $to=$_SESSION["from"];
    $send=send($to,$msg);
    exit($send);
}
if(!empty($_POST["to-1"])  && !empty($_POST["date-1"]) && !empty($_POST["time-1"]) && !empty($_POST["msg-1"])){
    $to=$_POST["to-1"];
    $date=$_POST["date-1"];
    $time=$_POST["time-1"];
    $msg=$_POST["msg-1"];
    if(preg_match('/{date}/', $msg)){
        $msg=str_replace("{date}",$date,$msg);
    }
    if(preg_match('/{time}/', $msg)){
        $msg=str_replace("{time}",$time,$msg);
    }
    $send=send($to,$msg);
    exit($send);
}
if(!empty($_POST["to-2"])  && !empty($_POST["confirm-number-2"]) && !empty($_POST["msg-2"])){
    $to=$_POST["to-2"];
    $confirm=$_POST["confirm-number-2"];
    $msg=$_POST["msg-2"];
    if(preg_match('/{confirmation-number}/', $msg)){
        $msg=str_replace("{confirmation-number}",$confirm,$msg);
    }
    $send=send($to,$msg);
    exit($send);
}
if(!empty($_POST["to-3"])  && !empty($_POST["code"]) && !empty($_POST["msg-3"])){
    $to=$_POST["to-3"];
    $code=$_POST["code"];
    $msg=$_POST["msg-3"];
    if(preg_match('/{code}/', $msg)){
        $msg=str_replace("{code}",$code,$msg);
    }
    $send=send($to,$msg);
    exit($send);
}
if(!empty($_POST["to-4"]) && !empty($_POST["msg-4"])){
    $to=$_POST["to-4"];
    $msg=$_POST["msg-4"];
    $send=send($to,$msg);
    exit($send);
}
exit("2");

