<?php



include("asl.php");



     // import_request_variables("g" , "a_");
      
      
      
        
     function sendmessage($text,$chatid,$keys){

     $send = "https://api.telegram.org/bot6395431401:AAH3VXdiFjRzP--O04rRweqciUe0V6Q1TmA/sendmessage?chat_id=$chatid&text=$text";
     $sended = file_get_contents($send);
     return $sended;
     print$sended;
     }
     
     
     
     $a_pass = $_GET["pass"];
$a_user= $_GET["user"];
$a_mykey= $_GET["mykey"];
$a_answer= $_GET["answer"];
$a_myarakeys= $_GET["myarakeys"];
$a_newuser= $_GET["newuser"];
$a_newpass= $_GET["newpass"];
$a_noa= $_GET["noa"];
$a_shenase= $_GET["shenase"];
$a_chatid= $_GET["chatid"];
$a_text= $_GET["text"];
$a_pfrom= $_GET["pfrom"];
$a_pto= $_GET["pto"];
$a_phone= $_GET["phone"];


try {
    $conn = new PDO("mysql:host=$servername;dbname=$mydb", $username, $password ,  array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
    // set the PDO error mode to exception

    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }




              $sql = "select * from admin";
              $stmt =   $conn->prepare($sql);
              $stmt->execute();

                        $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
                         $show =$stmt->fetch()  ;

              $user = $show["user"];
              $pass= $show["pass"];


              $getpass= hash_hmac('md5',$a_pass , salt);


                 if($user == $a_user && $pass == $getpass){
                 
      
               
               
               
              $sql = "select * from user where phone like \"%$a_phone\"  ";
              $stmt =   $conn->prepare($sql);
              $stmt->execute();

                        $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
                         $show =$stmt->fetch()  ;
                         
                         $num=$stmt->rowCount();
                         
                         
                         if($num==0){
                         print"[شماره تلفن پیدا نشد]";
                         }
                         else{
                        print $show["chatid"];
                         
                         }

              $chatid = $show["chatid"];
              
              
              
   //           sendmessage(urlencode($a_text),$chatid,$keys);
              
                          $sql = "insert into messages (chatid,text) values (\"$chatid\",\"$a_text\")";
            $conn->exec($sql);

                 }
                 else{
print"[یوزرنیم یا پسورد اشتباه است]";
                 }
                 
                 
                 
                 ?> 