<?php
namespace App\Controllers;
SESSION_START();
use \Core\View;
use \Core\Inputs;
use \Core\Userlog;
use \Core\Menu;
use \Core\Form;
use App\Models\Homem;
use App\Email\Emails;
class Exams extends \Core\Controller
{
    public static function testc()
    {
        $papertime =1200;
        echo '<div id="timer"></div>';
        echo '<input type="text" id="timervalue" name="timervalue">';
        echo '<script src="/hindu/assets/word/jquery.min.js" ></script>';
        if(!isset($_COOKIE['mytimer1']))
        {
            echo '<script  type="text/javascript">
                    var seconds = '.$papertime.';
                    document.getElementById("timer").innerHTML = secondsToHms(seconds);
                    document.getElementById("timervalue").value = secondsToHms(seconds);
                    var a = secondsToHms(seconds);
                    document.cookie = "mytimer1 ="+a;
                    function secondsToHms(d) 
                    {
                        d = Number(d);
                        var h = Math.floor(d / 3600);
                        var m = Math.floor(d % 3600 / 60);
                        var s = Math.floor(d % 3600 % 60);
                        var hDisplay = h > 0 ? h + ":" : "";
                        var mDisplay = m > 0 ? m + ":" : "";
                        var sDisplay = s > 0 ? s + "" : "";
                        var timervalue = hDisplay + mDisplay + sDisplay; 
                        return hDisplay + mDisplay + sDisplay; 
                    }
                </script>';
        }
        else
        {
            echo '<script  type="text/javascript">
            $(document).ready(function () {
                    setInterval(function () {
                        var b=getCookie("mytimer1");
                        document.getElementById("timer").innerHTML = b;
                        document.getElementById("timervalue").value = b;
                        console.log(getlatesttimervalue(b));
                        var a = parseInt(getlatesttimervalue(b));
                        a--;
                        var c = secondsToHms(a);
                        document.cookie = "mytimer1 ="+c;
                    }, 1000);
                });
                function secondsToHms(d) 
                {
                    d = Number(d);
                    var h = Math.floor(d / 3600);
                    var m = Math.floor(d % 3600 / 60);
                    var s = Math.floor(d % 3600 % 60);
                    var hDisplay = h > 0 ? h + ":" : "";
                    var mDisplay = m > 0 ? m + ":" : "";
                    var sDisplay = s > 0 ? s + "" : "";
                    var timervalue = hDisplay + mDisplay + sDisplay; 
                    return hDisplay + mDisplay + sDisplay; 
                }
                function getCookie(name) {
                    var v = document.cookie.match("(^|;) ?" + name + "=([^;]*)(;|$)");
                    return v ? v[2] : null;
                }
                function getlatesttimervalue(a)
                {
                    var timearray = a.split(":");
                    if(timearray.length == 3)
                    {
                        if(timearray[0] == "" || timearray[0] == null){timearray[0] = 0;}
                        if(timearray[1] == "" || timearray[1] == null){timearray[1] = 0;}
                        if(timearray[2] == "" || timearray[2] == null){timearray[2] = 0;}
                        var time1 = timearray[0]*60*60; 
                        var time2 = timearray[1]*60; 
                        var time3 = timearray[2]; 
                        var time =parseInt(time1)+parseInt(time2)+parseInt(time3);
                    }
                    if(timearray.length == 2)
                    {
                        if(timearray[0] == "" || timearray[0] == null){timearray[0] = 0;}
                        if(timearray[1] == "" || timearray[1] == null){timearray[1] = 0;}
                        var time1 = timearray[0]*60; 
                        var time2 = timearray[1]; 
                        var time=parseInt(time1) + parseInt(time2);
                    }
                    if(timearray.length == 1)
                    {
                        if(timearray[0] == "" || timearray[0] == null){timearray[0] = 0;}
                        var time1 = timearray[0]; 
                        var time= parseInt(time1);
                    }
                    return time;
                }
                </script>';
        }
    }
}