<?php

ini_set('display_errors', 0);


include("asl.php");


?>



<!DOCTYPE HTML>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html ; charset=utf-8" />
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="persian" />

    <title>پنل اختصاصی ربات تلگرام گروه توسعه دهندگان AHP</title>


    <link rel="Stylesheet" type="text/css" href="style.css" />

    <style>
        @font-face {
            font-family: 'amir';
            src: url('font/BKoodakBold.ttf')format('truetype'),
                url('font/BKoodakBold.eot')format('eot'),
                url('font/BKoodakBold.woff')format('woff');

        }

        .font {
            font-family: amir;
        }
    </style>



</head>

<body dir="rtl" align="center">
    <div align="center">
        <?php
        /*
     // import_request_variables("p" , "a_");
error_reporting(E_ALL);
ini_set('display_errors', '1');
*/

        $a_pass = $_POST["pass"];
        $a_user = $_POST["user"];
        $a_mykey = $_POST["mykey"];
        $a_answer = $_POST["answer"];
        $a_myarakeys = $_POST["myarakeys"];
        $a_newuser = $_POST["newuser"];
        $a_newpass = $_POST["newpass"];
        $a_noa = $_POST["noa"];
        $a_shenase = $_POST["shenase"];

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

            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        } catch (PDOException $e) {
            echo "Connection failed: " . $e->getMessage();
        }


        function sendmessage($text, $chatid, $keys)
        {


            $send = "https://api.telegram.org/bot7960487515:AAEMtNS9awV-szQA5J1wC40a_bADwghlakU/sendmessage?chat_id=$chatid&text=$text&parse_mode=Html&reply_markup=$keys";
            //$sended = file_get_contents($send);
        


            $c = curl_init($send);
            curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
            //curl_setopt(... other options you want...)
        
            curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
            //curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
        
            $sended = curl_exec($c);

            if (curl_error($c)) {
                die(curl_error($c));
            }

            // Get the status code
            $status = curl_getinfo($c, CURLINFO_HTTP_CODE);

            curl_close($c);



            $decodeData = json_decode($sended, true);
            $id_message = $decodeData['result']['message_id'];

            return $id_message;


            print $sended;
        }


        $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) {






            if ($a_noa == "inserttodb") {




                if (!$_FILES['myfile']['name'] == "" && $_FILES["myfile"]["error"] == 0) {




                    $ext = end(explode('.', $_FILES['myfile']['name']));

                    $formats = array('jpg', 'JPG', 'gif', 'GIF', 'png', 'PNG', 'RAR', 'rar', 'ZIP', 'zip', 'mp4', '3gp', 'mov', 'pdf');

                    if ($ext == "jpg" || $ext == "JPG" || $ext == "png" || $ext == "PNG") {
                        $themyfiletype = "pic";
                    } elseif ($ext == "mp4" || $ext == "mov" || $ext == "" || $ext == "") {
                        $themyfiletype = "video";
                    } elseif ($ext == "pdf") {
                        $themyfiletype = "pdf";
                    }

                    if (!in_array($ext, $formats)) {

                        print "<p style='color:green' >پسوند معتبر برای آپلود نیست</p>";
                    } elseif (file_exists('upload/' . $_FILES["myfile"]["name"])) {
                        print "<p style='color:green' >متاسفیم این فایل قبلا اپلود شده لطفا نام ان را تغییر دهید</p>";
                    } elseif (536870912 < $_FILES["myfile"]["size"]) {


                        print "<p style='color:green' >سایز فایل باید کمتر از نیم گیگ باشد</p>";
                    } else {
                        $path = "upload/" . $_FILES["myfile"]["name"];
                        move_uploaded_file($_FILES["myfile"]["tmp_name"], $path);
                        print "
        <span class='green' >
        اپلود با موفقیت انجام 
        شد
        </span>
        ";
                    }
                    $namemyfile = $_FILES["myfile"]["name"];
                }


                $shenase = time() . rand(0, 1);
                echo "<p style='color:green' >دستورات ذخیره شد</p>";

                if ($namemyfile == "" ||  $namemyfile == " ") {
                    /* $sql = "INSERT INTO layertwo (mykey,answer,ispic,picture,myarakeys,shenase,key_type) VALUES ('$a_mykey', '$a_answer','','', '$a_myarakeys','$shenase','" . $_POST['key_type'] . "')";
                    $conn->exec($sql);
 */
try {
    if($_POST['key_type'] == NULL){
        $_POST['key_type'] = 'normal';
    }
    // Prepare statement
    $stmt = $conn->prepare("INSERT INTO layertwo (mykey, answer, ispic, picture, myarakeys, shenase, key_type) VALUES (:mykey, :answer, '', '', :myarakeys, :shenase, :key_type)");

    // Bind parameters
    $stmt->bindParam(':mykey', $a_mykey);
    $stmt->bindParam(':answer', $a_answer);
    //$stmt->bindParam(':ispic', ''); // Assuming you have these variables
    //$stmt->bindParam(':picture', ''); // Assuming you have these variables
    $stmt->bindParam(':myarakeys', $a_myarakeys);
    $stmt->bindParam(':shenase', $shenase);
    $stmt->bindParam(':key_type', $_POST['key_type']);

    // Execute the statement
    $stmt->execute();
} catch(PDOException $e) {
    echo "Error: " . $e->getMessage();
}

                } else {
                    try {

                        if(!isset($_POST['key_type'])){
                            $_POST['key_type'] = 'normal';
                        }
                        $sql = "INSERT INTO layertwo (mykey,answer,ispic,picture,myarakeys,shenase,key_type) VALUES ('$a_mykey', '$a_answer',\"$themyfiletype\",\"$namemyfile\", '$a_myarakeys','$shenase','" . $_POST['key_type'] . "')";
                        $conn->exec($sql); 
                } catch(PDOException $e) {
                    echo "Error: " . $e->getMessage();
                }
                }
            }















            if (isset($_POST['channel1'])) {
                $sql = "update admin set channel1 = '" . $_POST['channel1'] . "'  , channel2 = '" . $_POST['channel2'] . "'  , text = '" . $_POST['mytext'] . "'  ";
                $conn->exec($sql);
                echo "<p style='color:green' >اپدیت انجام شد</p>";
            }






            if ($a_newuser == "") {
            } else {

                $newpass = hash_hmac('md5', $a_newpass, 'salt');
                $sql = "update admin set user = \"$a_newuser\"  , pass=\"$newpass\"  ";
                $conn->exec($sql);
                echo "<p style='color:green' >يوزرنيم و پسورد با موفقيت به روز رساني شد لطفا از پنل خارج شده مجددا وارد شويد</p>";




                function redirect($url)
                {
                    if (!headers_sent()) {
                        header('Location: ' . $url);
                        exit;
                    } else {
                        echo '<script type="text/javascript">';
                        echo 'window.location.href="' . $url . '";';
                        echo '</script>';
                        echo '<noscript>';
                        echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
                        echo '</noscript>';
                        exit;
                    }
                }

                redirect("enter.php");
            }











            if ($a_noa == 'deletemain') {
            } elseif ($a_noa == 'deletekey') {

                $sql = "delete from  layertwo  where mykey='$a_mykey' ";
                $conn->exec($sql);
                echo "<p style='color:green' >حذف شد !</p>";
            } elseif ($a_noa == "editkey") {

                /* $sql = "update  layertwo  set mykey='$a_mykey',answer='$a_answer',myarakeys='$a_myarakeys' where shenase='$a_shenase' ";
                $conn->exec($sql); */
                $sql = "UPDATE layertwo SET mykey = :mykey, answer = :answer, myarakeys = :myarakeys WHERE shenase = :shenase";
                $statement = $conn->prepare($sql);

                // Bind the values to the placeholders
                $statement->bindValue(':mykey', "$a_mykey");
                $statement->bindValue(':answer', "$a_answer");
                $statement->bindValue(':myarakeys', "$a_myarakeys");
                $statement->bindValue(':shenase', "$a_shenase");

                // Execute the query
                $statement->execute();


                echo "<p style='color:green' >دستورات اپدیت شد</p>";
            }
        } else {



            echo "<p style='color:red' >يوزرنيم و يا پسورد اشتباه وارد شده </p><br />
                      <a href='enter.php' target='_blank' >بازگشت به صفحه ی ورود</a>
              
                      ";



            function redirect($url)
            {
                if (!headers_sent()) {
                    header('Location: ' . $url);
                    exit;
                } else {
                    echo '<script type="text/javascript">';
                    echo 'window.location.href="' . $url . '";';
                    echo '</script>';
                    echo '<noscript>';
                    echo '<meta http-equiv="refresh" content="0;url=' . $url . '" />';
                    echo '</noscript>';
                    exit;
                }
            }

            redirect("enter.php");
        }


        if ($a_noa == "sending") {


            $a_ifrom = $_POST['ifrom']; 
            $a_ito = $_POST['ito'];
            $a_info = $_POST['info'];

            $stmt = $conn->prepare("SELECT * FROM user LIMIT $a_ifrom, $a_ito");
            
            $stmt->execute();

            // set the resulting array to associative
            $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);

            $l = $stmt->fetchAll();

            $forwork = ($a_ito - $a_ifrom) + 2;

            for ($i = 0; $i < $forwork; $i++) {
                
                // print"in $i  \\\ ".$l[$i]["chatid"]."<br />";
        
                if ($namemyfile == "" || $namemyfile == " ") {
                    sendmessage(urlencode("$a_info"), $l[$i]["chatid"], "");
                } else {
                    sendphoto($namemyfile, $l[$i]["chatid"], "", urlencode("$a_info"));
                }
                //sendmessage($text,'80433998',$key);
            }

        }




        ?>

        <h1 class="white">پنل ربات تلگرام AHP</h1>
        <br></br>
        <h4 class="white">پنل اختصاصی ربات تلگرام نسخه1</h4>
        <div id="content" align="right">
            <div id="content-content">
                <table>
                    <tr>
                        <td><img class="radius" src="panel/images/user.png" /></td>
                        <td class="gray" valign="bottom">خوش آمدید <?php print $userse; ?></td>

                        <td>
                            <form target="_blank" method='post' action='users.php'>


                                <input type='submit' style='width:100%' class='font' value='نمایش کاربران' />
                                <input type='hidden' name='user' value="<?php echo $a_user  ?>" />
                                <input type='hidden' name='pass' value="<?php echo $a_pass  ?>" class='font' />
                            </form>
                        </td>




                        <td>
                            <form target="_blank" method='post' action='mahsool.php'>


                                <input type='submit' style='width:100%' class='font' value='افزودن محصول' />
                                <input type='hidden' name='user' value="<?php echo $a_user  ?>" />
                                <input type='hidden' name='pass' value="<?php echo $a_pass  ?>" class='font' />
                            </form>
                        </td>




                    </tr>

                </table>



                <br />
                <br />
                <a href="https://telegram.me/mr_zarif_test_bot" target="_blank">
                    <input class='button-blue' style="width:725px;" type="button" value="رفتن به داخل ربات" />
                </a>

                <br />



                <h5 class='gray'>◄ ارسال خبر جدید</h5>

                    <form method='post' enctype='multipart/form-data' action='index.php'>
                        <table>
                            <tr>

                                <th class='th'>از </th>
                                <th class='th'>تا </th>
                                <th class='th'>متن برای ارسال</th>





                            </tr>
                            <tr>
                                <td align='center' class='td'><input placeholder="از " type='text' name='ifrom' class='font' /> </td>
                                <td align='center' class='td'><input placeholder="تا " type='text' name='ito' class='font' /> </td>
                                <td align='center' class='td'><textarea name="info" style='height:200px'></textarea>
                                </td>


                            </tr>


                            <tr>

                                <td>
                                    <input type='hidden' name='user' value="<?php echo $a_user ?>" />
                                    <input type='hidden' name='pass' value="<?php echo $a_pass ?>" />

                                    <input type='hidden' name='noa' value='sending' /><input type='submit' class='font' value='ارسال' />
                                </td>

                            </tr>

                        </table>
                    </form>














                    <hr />
                    <hr />
                    <hr />

                    <br />
                    <br />
                    <br />
                    <br />



                <div id="fish">

                    <table>


                        <h5 class='gray'>◄ افزودن دستور جدید</h5>

                        <form enctype='multipart/form-data' method='post' action='index.php'>
                            <table>
                                <tr>
                                    <th class='th'>دستور</th>
                                    <th class='th' colspan="2">پاسخ</th>


                                </tr>
                                <tr>
                                    <td align='center' class='td'><input placeholder="دستور" type='text' name='mykey' class='font' /> </td>
                                    <td align='center' class='td'><textarea placeholder="پاسخ" name="answer" cols="65" rows="25"></textarea>
                                        <br />





                                        <input type='hidden' name='user' value="<?php echo $a_user  ?>" />
                                        <input type='hidden' name='pass' value="<?php echo $a_pass  ?>" class='font' />


                                        <input type='hidden' name='noa' value="inserttodb" />
                                    </td>




                                </tr>

                                <tr>

                                    <td colspan='2'>

                                        <textarea placeholder="دکمه ها" name="myarakeys" style='width:100%;height:50px'></textarea>
                                        <input type='file' name='myfile' />
                                    </td>

                                </tr>

                                <tr>

                                    <td>



                                        <input type="checkbox" id='vehicle1' name="key_type" value="glass">
                                        <label for="vehicle1">دکمه شیشه ای</label><br>


                                        <input type='submit' class='font' value='افزودن' />
                                    </td>

                                </tr>

                            </table>
                        </form>


                    </table>

                    <br />
                    <br />
                    <br />
                    <br />








                    <hr />
                    <hr />
                    <hr />

                    <br />
                    <br />
                    <br />
                    <br />



                    <form method='post' action='index.php'>
                        <table>
                            <tr>
                                <th class='th'>يوزرنيم جديد </th>
                                <th class='th' colspan="2">پسورد جديد</th>


                            </tr>
                            <tr>
                                <td align='center' class='td'><input placeholder="يوزرنيم" type='text' name='newuser' class='font' /> </td>
                                <td align='center' class='td'><input placeholder="پسورد" name="newpass" type="password" class="font" />
                                    <input type='hidden' name='user' value="<?php echo $a_user  ?>" />
                                    <input type='hidden' name='pass' value="<?php echo $a_pass  ?>" />
                                </td>




                            </tr>


                            <tr>

                                <td> <input type='submit' class='font' value='تغيير' /> </td>

                            </tr>

                        </table>
                    </form>

                    <hr />
                    <hr />






                    <hr />
                    <hr />
                    <hr />

                    <br />
                    <br />
                    <br />
                    <br />


<!-- 
                    <form method='post' action='index.php'>
                        <table>
                            <tr>
                                <th class='th'>لینک کانال اول </th>
                                <th class='th'>لینک کانال دوم</th>
                                <th class='th'>متن</th>


                            </tr>
                            <tr>
                                <td align='center' class='td'><input placeholder="لینک کانال اول" type='text' name='channel1' class='font' /> </td>
                                <td align='center' class='td'><input placeholder="لینک کانال دوم" name="channel2" type="text" class="font" />
                                    <input type='hidden' name='user' value="<?php echo $a_user  ?>" />
                                    <input type='hidden' name='pass' value="<?php echo $a_pass  ?>" />
                                </td>

                                <td align='center' class='td'><input placeholder="متن" name="mytext" type="text" class="font" />
                                    <input type='hidden' name='user' value="<?php echo $a_user  ?>" />
                                    <input type='hidden' name='pass' value="<?php echo $a_pass  ?>" />
                                </td>




                            </tr>


                            <tr>

                                <td> <input type='submit' class='font' value='تغيير' /> </td>

                            </tr>

                        </table>
                    </form> -->

                    <hr />
                    <hr />












                    <h3>دستور ها</h3>
                    <table>

                        <tr>

                            <th class='th'>

                                دستور | پاسخ | کلید ها
                            </th>



                            <th class='th'>

                                حذف
                            </th>


                        </tr>



                        <?php


                        $stmt = $conn->prepare("SELECT * FROM layertwo  ");
                        $stmt->execute();
                        $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
                        $k = $stmt->fetchAll();

                        foreach ($k as $s) {

                            $mykey = $s["mykey"];
                            $answer = $s["answer"];
                            $myarakeys = $s["myarakeys"];
                            $shenase = $s["shenase"];

                            print "
    
    <tr>
    <td class='td'>

<form method='post' action='index.php' >

<input  type='text' style='width:400px;' name='mykey' value='$mykey'  />

<br />
<input  type='text' style='width:400px;' name='answer' value='$answer'  />
<br />

<input  type='text' style='width:400px;' name='myarakeys' value='$myarakeys'  />
<br/ >




<br />



<input  type='hidden' name='shenase' value='$shenase'  />
<input  type='hidden' name='noa' value='editkey'  />
<input  type='hidden' name='user' value='$a_user'  />
        <input  type='hidden' name='pass' value='$a_pass' class='font'  />
        <input  type='submit'  value='ویرایش'  />
        </form>
    </td>
    
    
          <td class='td' >
    <form method='post' action='index.php' >
    <input  type='hidden' name='user' value='$a_user' />
        <input  type='hidden' name='pass' value='$a_pass' class='font'  />
        <input  type='hidden' name='noa' value='deletekey' class='font'  />
        <input  type='hidden' name='mykey' value='$mykey' class='font'  />
        <input  type='submit'  value='حذف کن' class='font'  />
    </form>
    </td>
    
    </tr>
    ";
                        }


                        ?>
                    </table>

                </div>





















                <br />
                <br />



                <?php


if(isset($_POST['usernames'])){
    $sql = "update admin set usernames = '".$_POST['usernames']."'  ";
    $conn->exec($sql);
    print("اپدیت انجام شد");
}

        $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"];
        $phone_list=$show["usernames"];



?>




        <a style="text-decoration:none ;" href="http://ahpbot.com" target="_blank" class="gray">طراحي شده توسط تيم توسعه دهندگان AHP</a>
    </div>

    <?php
    $conn = null;
    ?>
</body>

</html>