<?php
$data = Page::model()->findAll();
$options = array();
$multilangual = Yii::app()->options->get("I18N_MULTILINGUAL", 0);

if ($data) {
    foreach ($data as $item) {
        $params = array('slug' => $item->slug);
        if ($multilangual) {
            $params["lang"] = $item->language;
        }
        $url = $this->createUrl('/page/view', $params);
        $url = $options[$url] = $item->title;
    }
}
Yii::app()->clientScript->registerScript('select-page-button', '
    

jQuery("#select-page-button").on("click",function(){

        var $panel  = $("#pages-tabs").find("> .ui-widget-content[aria-hidden=false]");
        if($panel.length !==  0){
            
            var $select = $panel.find("select");
            var selectedPage = $select.val();
            if(selectedPage!=undefined&& selectedPage.length>0)
            {
                jQuery("#SliderImages_link").val(selectedPage);
            }
            else{
                var $input = $panel.find("input[type=\"hidden\"]");
                var selectedPage = $input.val();
                if(selectedPage!=undefined&& selectedPage.length>0)
                {
                    jQuery("#SliderImages_link").val(selectedPage);
                }
            }
            jQuery("#select-page-dialog").dialog("close");
        }
        

   
});'
);
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'select-page-dialog',
    'options' => array(
        'title' => "<div class='widget-header widget-header-small'><h4 class='smaller'><i class='icon-list'></i> " . Yii::t('admin', 'Select Link Source:') . "</h4></div>",
        'width' => 700,
        'closeText' => '',
        'height' => 400,
        'autoOpen' => false,
        'modal' => true,
    ),
));
?>

<div class="col-xs-12">
    <div class="space"></div>

    <?php
    $staticPages = array(
        'Home Page' => array('/site/index',),
        'Contact Page' => array('/site/contact'),
        'Albums Index' => array('/album/index'),
        'Articles Index' => array('/article/index'),
    );
    $activeLocales = FlexLocale::getActiveLocales();
    $staticPagesData = array();
    if ($multilangual && count($activeLocales)) {
        foreach ($staticPages as $key => $params) {
            $route = array_shift($params);
            foreach ($activeLocales as $localeKey => $localeValue) {
                $params['lang'] = $localeKey;
                $url = $this->createUrl($route, $params);
                $staticPagesData[$url] = "$key - $localeValue";
            }
        }
    } else {
        foreach ($staticPages as $key => $params) {
            $route = array_shift($params);
            $url = $this->createUrl($route, $params);
            $staticPagesData[$url] = $key;
        }
    }

    echo CHtml::hiddenField('sender_id', '', array('id' => 'sender_id'));


    $categories = '<div class="form-group">
                        <label class="col-md-3 control-label required" for="select-category-select">
                            ' . Yii::t("admin", "Select Category") . '
                        </label>
                        <div class="col-md-5 controls">
                            ' . CHtml::dropDownList(false, $model->link, MenuItem::stripBaseUrl(Category::model()->getUrlList()), array('empty' => '', 'id' => 'select-page-select', 'class' => 'form-control input-60')) . '
                        </div>
                    </div><div class="clearfix clear"></div>';

    $dynamicPages = '<div class="form-group">
                        <label class="col-md-3 control-label required" for="select-page-select">
                            ' . Yii::t("admin", "Select Page") . '
                        </label>
                        <div class="col-md-5 controls">
                            ' . CHtml::dropDownList(false, $model->link, MenuItem::stripBaseUrl($options), array('empty' => '', 'id' => 'select-page-select', 'class' => 'form-control input-60')) . '
                        </div>
                    </div><div class="clearfix clear"></div>';
    $staticPages = '<div class="form-group">
                        <label class="col-md-3 control-label required" for="select-staticpage-select">
                            ' . Yii::t("admin", "Select Page") . '
                        </label>
                        <div class="col-md-5 controls">
                            ' . CHtml::dropDownList(false, $model->link, MenuItem::stripBaseUrl($staticPagesData), array('empty' => '', 'id' => 'select-statocpage-select', 'class' => 'form-control input-60')) . '
                        </div>
                    </div><div class="clearfix clear"></div>';
    $articlePages = '<div class="form-group">
                        <label class="col-md-3 control-label required" for="select-staticpage-select">
                            ' . Yii::t("admin", "Type Article Title") . '
                        </label>
                        <div class="col-md-5 controls">
                            ' . CHtml::hiddenField(false, '', array('id' => 'hidden-article-single')) . $this->widget('CAutoComplete', array(
                'id' => 'article-single',
                'name' => 'article_single',
                'url' => array('/admin/article/suggestLink'),
                'max' => 100,
                'minChars' => 2,
                'delay' => 100,
                'methodChain' => '.result(function(event,item){$("#hidden-article-single").val(item[1]);})',
                'htmlOptions' => array('size' => '40')
                    ), true) . '
                        </div>
                    </div><div class="clearfix clear"></div>';
    $this->widget('zii.widgets.jui.CJuiTabs', array(
        'id' => 'pages-tabs',
        'tabs' => array(
            Yii::t('admin', 'Dynamic Page') => $dynamicPages,
            Yii::t('admin', 'Categories') => $categories,
            Yii::t('admin', 'Static Page') => $staticPages,
            Yii::t('admin', 'Article') => $articlePages,
        ),
    ));
    ?>

    <div class="clearfix clear"></div>
    <?php
    echo TbHtml::formActions(array(TbHtml::button('<i class="icon-ok"></i>' . Yii::t('admin', 'Select'), array('color' => TbHtml::BUTTON_COLOR_PRIMARY, 'id' => 'select-page-button')),));
    ?>

    <div class="clearfix clear"></div>
</div>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>