<?

$sahifa_id = $_SERVER['REQUEST_URI'];
$sahifa_id = str_replace('/users/imtihon/', '', $sahifa_id);

if ($sahifa_id > 0) {

$sorov_bolim = mysql_query("SELECT * FROM `exams` WHERE `catid` = $sahifa_id");
$imtihon_bolim = mysql_fetch_assoc(mysql_query("SELECT * FROM `exam_category` WHERE `catid` = $sahifa_id"));


?>

          <br />  
<div class="container ">
    <div class="row">
        <div class="col-md-17 col-xs-17">
            <div class="news-list__posts">
                    <?
                        $yangilik_query = mysql_query("SELECT COUNT(*) FROM `yangiliklar`");
                        $total = mysql_result($yangilik_query, 0);
                        $yangilik_query = mysql_query("SELECT * FROM `yangiliklar` ORDER BY `vaqt` DESC ");
                        $i = 0;
                        if ($yangilik = mysql_fetch_array($yangilik_query)) {
                            $matn = $yangilik['matn'];
                         echo '
                            
                            <h1 class="h1">' .$imtihon_bolim['catname']. '</h1>';
                            while ($bolim = mysql_fetch_assoc($sorov_bolim)) {
                            echo '
                            
                            <div class="news-item ">
                                            <img style="float: left;margin-right: 10px;margin-top: 4px;" src="/assets/images/' .$sahifa_id. '.png" />
                                <div class="news-item__title">
                                    <a class="link link_no-decoration" href="/users/takeexam/' .$bolim['examid']. '">' .$bolim['examname']. '</a>
                                </div>
                                <div class="news-item__date">
                                    Vaqt: ' .$bolim['duration']. 'daqiqa / 
                                            Testlar: ' .$bolim['questions']. ' / 
                                            O\'tish balli ' .$bolim['passmark']. '%
                                </div>
                            </div>
                            
                            ';
                        }
                        }
                        ?>
            </div>
        </div>
        <div class="col-md-7 col-xs-7">
        <?
            $session = get_session_details();
            $loggeduser = (object)$session->userdetails;
            $userid = $loggeduser->userid;

            $foydalanuvchi_query = mysql_query("SELECT * FROM `users` WHERE `user_id` = '{$userid}'");
            $user = mysql_fetch_assoc($foydalanuvchi_query);
        ?>
                <div class="news-list__press">
                    <div class="news-list__press__background"></div>
                    <?
                        if (!file_exists(('' .base_url(). '' .$user['avatar']. ''))) {
                            echo '<img class="news-list__press__logotype"  src="' .base_url(). '' .$user['avatar']. '"  />';
                        } else {
                            echo 'berasm';
                        }
                        ?>
                    <div class="news-list__press__contacts">
                        <div class="news-list__press__contacts__mail">
                            <h3 class="h3 h3_margin-0px">
                                <?php
                                   echo $user['firstname']. ' ' .$user['lastname'];
                                ?>
                            </h3>
                            <p class="paragraph paragraph_color-grey paragraph_without-line-height paragraph_top-10 paragraph_font-size-14"><?=$user['joylashuv'];?></p>
                            <img src="<?=base_url();?>assets/images/black-email.png" alt="Email">
                            <a href="mailto:<?=$user['email'];?>" class="news-list__press__contacts__mail__link"><?=$user['email'];?></a>
                        </div>
                    </div>
                </div>
                <br />
        </div>
    </div>
</div>

<?

} else {
    echo '
    <div class="photo-title">
        <span>
            Imtihon yo\'nalishlari
        </span>
    </div>';
    $bolim_query = mysql_query("SELECT * FROM `exam_category`");
    while ($bolim = mysql_fetch_assoc($bolim_query)) {
        $bolimlar_soni = mysql_result(mysql_query("SELECT count(*) FROM `exams` WHERE `catid` = {$bolim['catid']}"), 0);
    echo '
        <span class="block__item block__item_bottom my">
            <span class="w-table">
                <a class="w-table__column" href="/users/imtihon/' .$bolim['catid']. '">
                    <span class="w-table">
                        <img style="float: left;margin-right: 10px;margin-top: 4px;" src="/assets/images/' .$bolim['catid']. '.png" />
                        <span class="w-table__column w-table__column_wide w-social_my">
                            <span class="social__title">
                                ' .$bolim['catname']. '
                                <small class="gray">(' .$bolimlar_soni. ' bilet)</small>
                                <span class="block__title__arrow">
                                </span>
                            </span>
                        </span>
                    </span>
                </a>
            </span>
        </span>
    ';
    }
}
?>