<?php
Yii::setPathOfAlias('widgets', Yii::getPathOfAlias('application.extensions.widgets'));

$moduleID = '';
if (isset(Yii::app()->controller->module->id)) {
    $moduleID = Yii::app()->controller->module->id;
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="language" content="en" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <link rel="shortcut icon" href="<?php echo Yii::app()->request->baseUrl; ?>/favicon.png"></link>
        <title><?php echo cfg('PHONALISA_NAME') . ' ' . CHtml::encode($this->pageTitle); ?></title>
        <?php
        
        $baseUrl = Yii::app()->request->baseUrl;
        cs()->registerCssFile(Yii::app()->request->baseUrl . '/css/mobile.css');
        
        cs()->registerCssFile($baseUrl . '/js/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.css');
        cs()->registerCssFile($baseUrl . '/js/jquery.mobile-1.4.5/jquery.mobile.theme-1.4.5.min.css');
        cs()->registerCssFile($baseUrl . '/js/jquery.mobile-1.4.5/mobile-default.css');

        cs()->registerCoreScript("jquery");
        cs()->registerScriptFile($baseUrl . '/js/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js', CClientScript::POS_HEAD);
        cs()->registerScriptFile(
            $baseUrl . '/js/plWebSocket.js',
            CClientScript::POS_HEAD
        );
        $currentSudoUser = app()->user->sudoUserInstance;
        if ($currentSudoUser) {
            cs()->registerScript(
                'WebSocket',
                "var ws = $.WebSocket ('" . getWebSocketCTIUrl() . "', null, {
                user:'" . $currentSudoUser->name . "',
                pass:'" . $currentSudoUser->password . "',
                debug: true,
                logData: true
            });",
                CClientScript::POS_BEGIN
            );
        }

        ?>
    </head>
    <body>
        <div data-role="page">
            <div data-role="panel" id="mobileUserMonitor">
                <?php 
                    if ($this->module) {
                        $this->widget('widgets.UserMonitor.UserMonitor');
                    }
                ?>
            </div>
            <div data-role="header" data-position="fixed" id="mobileHeader">
                <a id="mobileUserMonitorToggleLink" href="#mobileUserMonitor">
                    <i class="icon-caret-right"></i>
                </a>
                <h1>
                    <?php
                    if ($moduleID !=='') {
                        echo __(ModuleManager::getModuleTranslationTag($moduleID));
                    } else {
                        echo 'Login';
                    }
                    ?>
                </h1>
                <?php if(!Yii::app()->user->isGuest) {?>
                <a id="mobileLogOut" href="/index.php?r=site/logout">
                    <i class="icon-signout"></i>
                </a>
                <?php }?>
            </div>

            <div data-role="content">
                <?php echo $content; ?>
            </div>

            <?php if ($moduleID) { ?>
                <div id="mobileFooter" data-role="footer" data-position="fixed">
                    <div data-role="navbar">
                        <ul>
                            <li>
                                <a rel="external" href="/index.php?r=homeUCItem" data-transition="slidefade" class="
                                <?php
                                if ($moduleID == 'homeUCItem') {
                                    echo 'ui-btn-active ui-state-persist';
                                }
                                ?>
                                   ">
                                    <i class="icon-dashboard">
                                        <br /><?php echo __(ModuleManager::getModuleTranslationTag('homeUCItem')) ?>
                                    </i>
                                </a>
                            </li>
                            <li>
                                <a rel="external" href="/index.php?r=addressbookAddresses" data-transition="slidefade" class="
                                <?php
                                if ($moduleID == 'addressbookAddresses') {
                                    echo 'ui-btn-active ui-state-persist';
                                }
                                ?>
                                   ">
                                    <i class="icon-book">
                                        <br /><?php echo __(ModuleManager::getModuleTranslationTag('addressbookAddresses')) ?>
                                    </i>
                                </a>
                            </li>
<!--                            <li>
                                <a href="/index.php?r=phonesettingsMyPhones" data-transition="slidefade" class="
                                <?php
//                                if ($moduleID == 'phonesettingsMyPhones') {
//                                    echo 'ui-btn-active ui-state-persist';
//                                }
                                ?>
                                   ">
                                    <i class="icon-cogs">
                                        <br /><?php //echo __(ModuleManager::getModuleTranslationTag('phonesettingsMyPhones')) ?>
                                    </i>
                                </a>
                            </li>-->
                        </ul>
                    </div>
                </div>
            <?php } else {
                ?>
                <button id="showNormalView" data-role="footer" data-position="fixed" style="padding: 8px;"><?php echo __("LOGIN_SHOW_NORMAL_VIEW"); ?></button>
                <?php
            } 
            ?>
            
        </div>
    </body>
    
<script>        
    $("body").on("panelbeforeopen", "#mobileUserMonitor",function(){
        $("#mobileUserMonitorToggleLink i").toggleClass("icon-caret-right");
        $("#mobileUserMonitorToggleLink i").toggleClass("icon-caret-left");
    });
$("body").on("panelbeforeclose", "#mobileUserMonitor",function(){
//    $("#mobileUserMonitor").on("panelbeforeclose",function(){
        $("#mobileUserMonitorToggleLink i").toggleClass("icon-caret-right");
        $("#mobileUserMonitorToggleLink i").toggleClass("icon-caret-left");
    });
</script>