<?php 
function G2J($datetime)
{
	require_once 'jdf.php';
	//Y-m-d H:i:s
	$datetime= explode(" ", $datetime);
	$date= $datetime[0];
	$date= explode("-", $date);
	$year= $date[0];
	$month= $date[1];
	$day= $date[2];
	$time= $datetime[1];
	$time= explode(":", $time);
	$hour= $time[0];
	$minute= $time[1];
	$second= $time[2];
	$date = gregorian_to_jalali($year,$month,$day);

	if ($date[1]<=6) 
			$timestamp = gmmktime($hour,$minute,$second,$month,$day,$year)-16200;
		else
			$timestamp = gmmktime($hour,$minute,$second,$month,$day,$year)-12600;
		return jdate("Y-m-d H:i:s", $timestamp);
}

function G2JDATE($date)
{
    require_once 'jdf.php';
    //Y-m-d H:i:s
    $date= explode("-", $date);
    $year= $date[0];
    $month= $date[1];
    $day= $date[2];
    $hour= 0;
    $minute= 0;
    $second= 0;
    $date = gregorian_to_jalali($year,$month,$day);

    if ($date[1]<=6) 
            $timestamp = gmmktime($hour,$minute,$second,$month,$day,$year)-16200;
        else
            $timestamp = gmmktime($hour,$minute,$second,$month,$day,$year)-12600;
        return jdate("Y-m-d", $timestamp);
}


function J2G($date)
{
    //1396-08-09
    require_once 'jdf.php';
    $date= explode("-", $date);
    $year= $date[0];
    $month= $date[1];
    $day= $date[2];
    $hour=0;
    $minute=0;
    $second=0;
    $date = jalali_to_gregorian ($hour,$minute,$second,$month,$day,$year);
    if ($date[1]<=6) 
            $timestamp = jmktime($hour,$minute,$second,$month,$day,$year)+16200;
        else
            $timestamp = jmktime($hour,$minute,$second,$month,$day,$year)+20000;
        return date("Y-m-d", $timestamp);

}
function Success($massage)
{
	echo '
	<div class="alert alert-success"><img src="./images/checked.png" width="25px">  '.$massage.'...</div>
	';
	// <div class="alert alert-success"><span class="glyphicon glyphicon-ok"></span>'.$massage.'</div>
}

function Failure($massage)
{
	echo '
	<div class="alert alert-danger"><img src="./images/error.png" width="25">  '.$massage.'!</div>
	';
}

function Hint($massage)
{
	echo '
	<div class="alert alert-info rtl col-md-4 col-md-push-4 text-center"><img src="./images/hint.png" width="25">  '.$massage.'</div>
	';
}

function admin_list_groups_checkbox($groups,$parent,$gid_array)
{
	global $theme;
    $has_childs = false;
    global $groupslist;

    foreach($groups as $key => $value)
    {
            if ($value['parent'] == $parent) 
            {               

                    if ($has_childs === false)
                    {
                        $has_childs = true;
                        echo '<ul style="list-style:none">';
                    }
                    if ($value['id']==1) 
                   
                    	echo '
                    	<li><input type="checkbox" name="gid['.$value['id'].']" value="1" '.(in_array($value['id'], $gid_array)?'checked="checked"':'').'> '.$value['name'];
                    else
                    	echo '<li style="border-right:1px black solid;">- <input type="checkbox" name="gid['.$value['id'].']" value="'.$value['id'].'" '.(in_array($value['id'], $gid_array)?'checked="checked"':'').'> '.$value['name'];

                    admin_list_groups_checkbox($groups,$key,$gid_array);
                    echo '
                    </li>
                    ';

            }
    }
    if ($has_childs === true) echo'
    	</ul>';
                    
}

function admin_list_groups_radio($groups,$parent,$gid_array)
{
	global $theme;
    $has_childs = false;
    global $groupslist;

    foreach($groups as $key => $value)
    {
            if ($value['parent'] == $parent) 
            {               

                    if ($has_childs === false)
                    {
                        $has_childs = true;
                        echo '<ul style="list-style:none">';
                    }
                    if ($value['id']==1) 
                   
                    	echo '
                    	<li><input type="radio" name="gid" value="1" '.($value['id']==1?'checked':'').' > '.$value['name'];
                    else
                    	echo '<li style="border-right:1px black solid;">- <input type="radio" name="gid" value="'.$value['id'].'"> '.$value['name'].'&nbsp;<a href="groups.php?op=add&gid='.$value['id'].'"><span class="green glyphicon glyphicon-edit"></span></a>&nbsp;<a onclick="return Sure();" href="groups.php?op=delete&gid='.$value['id'].'"><span class="red glyphicon glyphicon-minus-sign"></span></a>';

                    admin_list_groups_radio($groups,$key,$gid_array);
                    echo '
                    </li>
                    ';

            }
    }
    if ($has_childs === true) echo'
    	</ul>';
                    
}
 ?>