<?php



include("asl.php");
/*
error_reporting(E_ALL);
ini_set('display_errors', '1');
*/
?>



<!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');

        }
    </style>


</head>

<body dir="rtl" align="center">
    <div align="center">
        <?php
        include("jdf.php");

        date_default_timezone_set('Asia/Tehran');



        function sendphoto($address, $chatid, $key, $caption)
        {
            $bot_url    = "https://api.telegram.org/bot5652771393:AAFaZE4m01EfmQQ9vCsQzNld0HdnfEWEGZ4/";
            $url        = $bot_url . "sendPhoto?chat_id=$chatid&caption=" . $caption;

            $post_fields = array(
                'chat_id'   => "$chatid",
                'photo'     => 'https://teleaccmanager.telegramtools.io/dev/carbot/panel/upload/' . $address
            );

            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
            $output = curl_exec($ch);
            //   print $output;
        }



        function convert($string)
        {
            $persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
            $arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];

            $num = range(0, 9);
            $convertedPersianNums = str_replace($persian, $num, $string);
            $englishNumbersOnly = str_replace($arabic, $num, $convertedPersianNums);

            return $englishNumbersOnly;
        }



        //   import_request_variables("p" , "a_");


        //old import
        function checkarray($summerarray, $mainkey, $mainarray)
        {
            if (in_array($mainkey, $summerarray)) {
                unset($mainarray["$mainkey"]);
                return $mainarray;
            } else {
                return "ok";
            }
        }

        $summerarray = array();
        $artest = $_POST;
        foreach ($artest as $postinfo) {

            $ar_mainkey = array_search($postinfo, $artest);
            if (checkarray($summerarray, $ar_mainkey, $artest) != "ok") {
                $artest = checkarray($summerarray, $ar_mainkey, $artest);
                $ar_mainkey = array_search($postinfo, $artest);
            }
            ${'a_' . $ar_mainkey} = $postinfo;
            $summerarray[] = $ar_mainkey;
        }
        //old import


        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) {
        } else {





            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");
            exit();
        }










        if (isset($_POST['insert_car'])) {


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

                print("<hr /> UPLOADING FILES <hr />");

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

                $formats = array('jpg', 'JPG', 'gif', 'GIF', 'png', 'PNG', 'RAR', 'rar', 'ZIP', 'zip', 'mp4', '3gp', 'mov', 'jpeg', 'JPEG');
                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"];
            } else {
                $namemyfile = 'no_file';
            }







            $sql = "insert into cars (name,brand,model,image,information) values ('" . $_POST['name'] . "','" . $_POST['brand'] . "','" . $_POST['model'] . "','" . $namemyfile . "','" . $_POST['information'] . "')";
            $conn->exec($sql);


            $sql = "select * from elam where brand='" . $_POST['brand'] . "'  and model='" . $_POST['model'] . "' ";
            $stmt = $conn->prepare($sql);
            $stmt->execute();
            $stmt->setFetchMode(PDO::FETCH_ASSOC);
            $getter = $stmt->fetchAll();
            $numrowfusers = $stmt->rowCount();
            $caption = "
" . $_POST['name'] . "
" . $_POST['information'] . "
                    ";


            foreach ($getter as $singleGetter) {




                sendphoto($namemyfile, $singleGetter['chatid'], '',  urlencode($caption));
            }

            sendphoto($namemyfile, '@ahptest6', '',  urlencode($caption));

            print("<script>alert('انجام شد');</script>");
        } elseif (isset($_POST['delete_car'])) {
            $sql = "delete from cars  where id='" . $_POST['id'] . "' ";
            $conn->query($sql);
            print("<script>alert(' حذف شد');</script>");
        }


        ?>

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

                </table>



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

                <br />
                <div id="fish">




                    <h5 class='gray'>◄ افزودن ماشین</h5>




                    <form method='post' enctype='multipart/form-data' action="#">
                        <input type='hidden' name='user' value="<?php echo $a_user  ?>" />
                        <input type='hidden' name='pass' value="<?php echo $a_pass  ?>" class='font' />
                        <table style='width:100%'>
                            <tr>
                                <th class='th'>عنوان</th>
                                <th class='th'>عکس</th>

                            </tr>

                            <tr>
                                <td class='td'><input type='text' name='name' placeholder='' class='font' /></td>
                                <td class='td'><input type="file" id="file" name="myfile" /></td>

                            </tr>


                            <tr>
                                <th class='th'>کارخانه</th>
                                <th class='th'>مدل</th>

                            </tr>

                            <tr>
                                <td class='td'>

                                    <select name="brand">





                                        <?php
                                        $sql = "select * from brands ";
                                        $stmt = $conn->prepare($sql);
                                        $stmt->execute();
                                        $stmt->setFetchMode(PDO::FETCH_ASSOC);
                                        $getter = $stmt->fetchAll();
                                        $numrowfusers = $stmt->rowCount();

                                        foreach ($getter as $singleGetter) {
                                            print(" <option value='" . $singleGetter['name'] . "'>" . $singleGetter['name'] . "</option>");
                                        }




                                        ?>
                                    </select>


                                </td>
                                <td class='td'>

                                    <select name="model">





                                        <?php
                                        $sql = "select * from models ";
                                        $stmt = $conn->prepare($sql);
                                        $stmt->execute();
                                        $stmt->setFetchMode(PDO::FETCH_ASSOC);
                                        $getter = $stmt->fetchAll();
                                        $numrowfusers = $stmt->rowCount();

                                        foreach ($getter as $singleGetter) {
                                            print(" <option value='" . $singleGetter['name'] . "'>" . $singleGetter['name'] . "</option>");
                                        }




                                        ?>
                                    </select>

                                </td>

                            </tr>



                            <tr>
                                <th colspan="3" class='th'>توضیحات</th>
                            </tr>

                            <tr>
                                <td colspan="3" class='td'><textarea type='text' name='information' placeholder='' class='font' style='width:90%'></textarea></td>

                            </tr>





                            <tr>
                                <td colspan="3" class='td'><input type='submit' name='insert_car' value='ثبت' class='font' /></td>

                            </tr>

                        </table>
                    </form>



                    <table style='width:95%'>
                        <tr>
                            <th class='th'>لیست ماشین ها</th>
                        </tr>
                        <tr>





                            <?php


                            $stmt = $conn->prepare("SELECT * FROM cars");
                            $stmt->execute();

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

                            $k = $stmt->fetchAll();
                            $num = $stmt->rowCount();

                            print " <h5 class='gray'>◄ تعداد  ها: $num</h5>";

                            foreach ($k as $v) {


                                print "
        <tr>
         <td align='center' class='td'  >
          نام : 
         " . $v['name'] . "

         <br />
       
         " . $v['information'] . "

         <br />
         <form method='post'>
         "; ?>

                                <input type='hidden' name='user' value="<?php echo $a_user  ?>" />
                                <input type='hidden' name='pass' value="<?php echo $a_pass  ?>" class='font' />
                            <?php print "
         <input type='hidden' name='id'  value='" . $v['id'] . "'/>
         <input class='font' type='submit'  name='delete_car'  value='حذف'/>

         </form>
         
        
         </td>
        </tr>

        
        ";
                            }

                            ?>










                        </tr>



                    </table>





















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

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






                </div>



















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




        <a style="text-decoration:none ;" href="http://ahpbot.ir" target="_blank" class="gray">طراحی شده توسط ahpbot</a>
    </div>

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

</html>