<?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 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();



    }















    ?>

    <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>


                <?php
                
                if(isset($_POST['insert_game'])){
                    $date=$_POST['date'];
                    $time=$_POST['time'];
                    print("TIME IS ".$time." <hr />");
                    $exDate=explode("/",$date);
                    $exTime=explode(":",$time);
                    print_r($exTime);
                    print("Timestamp is : <br />");
                    $engDate=jalali_to_gregorian(1401,convert($exDate[1]),convert($exDate[0]));

                    print_r($engDate);
           
                        $timeStamp=mktime(convert($exTime[0]),convert($exTime[1]),0,$engDate[1],$engDate[2],$engDate[0]);
                    
                    

                    print("<hr />aval : <".$exTime[0]."> dovom : ".$exTime[1]."</hr />");
                    //$timeStamp=mktime(13,30,0,$engDate[1],$engDate[2],$engDate[0]);
                    
                    print("<br />time stamp : $timeStamp<br />");
                    $jdate=jdate("تاریخ y/m/d ساعت H:i:s", $timeStamp);
                    print($jdate);
                    print('here1');
                    $sql = "insert into games (team1,team2,start_time) values ('".$_POST['team1']."','".$_POST['team2']."','".$timeStamp."')";
                    $conn->exec($sql);
                    print('here2');
                    print("<script>alert('انجام شد');</script>");
                }
                elseif(isset($_POST['delete_game'])){
                    $sql = "delete from games  where id='".$_POST['id']."' ";
                    $conn->query($sql);
                    print("<script>alert('بازی حذف شد');</script>");
                }
                elseif(isset($_POST['edit_game'])){
        
                    $sql = "update games set winner='".$_POST['winner']."',team1_goal='".$_POST['team1_goal']."',team2_goal='".$_POST['team2_goal']."'  where id='".$_POST['id']."' ";
                    $conn->exec($sql);
                    print("<script>alert('بازی ویرایش شد');</script>");
                }


                ?>

                <form method='post' action="#">
                <input  type='hidden' name='user' value="<?php echo $a_user  ?>"  />
                <input  type='hidden' name='pass' value="<?php echo $a_pass  ?>" class='font'  />
                    <table > 
                        <tr>
                            <th class='th'  >تیم۱</th>
                            <th class='th'  >تیم۲</th>
                            <th class='th'  >تاریخ</th>
                            <th class='th'  >ساعت</th>
                            <th class='th'  >ثبت</th>
                        </tr>

                        <tr>
                            <td class='td'><input type='text' name='team1' placeholder='ایران' class='font' /></td>
                            <td class='td'><input type='text' name='team2' placeholder='قطر' class='font' /></td>
                            <td class='td'><input type='text' name='date' placeholder='21/7' class='font' /></td>
                            <td class='td'><input type='text' name='time' placeholder='21:22' class='font' /></td>
                            <td class='td'><input type='submit' name='insert_game' value='ثبت' class='font' /></td>
                        </tr>
                    </table>
                </form>





                <table style='width:95%'>
                    <tr>
                        <th class='th'  >بازی</th>
                    </tr>
                    <tr>





                        <?php


                        $stmt = $conn->prepare("SELECT * FROM games");
                        $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['team1']."
         <br />
         تیم ۲ : 
         ".$v['team2']."
         <br />
         شروع بازی  : 
         ".$jdate=jdate("تاریخ y/m/d ساعت H:i:s", $v['start_time'])."
         <br />
         <form method='post'  >
         برنده : (team1 or team2 or mosavi)
         <br />
         <input type='text'  name='winner'  placeholder='team1,team2' value='".$v['winner']."'  />
         <br />
         تعداد گل تیم ۱ : 
         <br />
         <input type='text'  name='team1_goal'  placeholder='1'  value='".$v['team1_goal']."' />
         <br />
         تعداد گل تیم ۲ : 
         <br />
         <input type='text'  name='team2_goal'  placeholder='0'  value='".$v['team2_goal']."' />
         <input type='hidden'  name='id'  value='".$v['id']."'/>
         <input type='submit'class='font' name='edit_game'  value='ثبت'/>
         <br />
         "; ?>
         
         <input  type='hidden' name='user' value="<?php echo $a_user  ?>"  />
         <input  type='hidden' name='pass' value="<?php echo $a_pass  ?>" class='font'  />
         <?php print"

         </form>

         <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_game'  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>