<?php
/* @var $this PersonController */
/* @var $model Person */

$this->breadcrumbs = array(
    yii::t('default', 'Persons') => array('/person/index'),
    yii::t('default', 'LDAP Person') => '',
    $model->name,
);



$this->widget('bootstrap.widgets.TbAlert');

// Check if there is badge have the LDAP badge number or not
$addAndAssignBadge = Badge::model()->findByAttributes(array('number' => $model->badge_number));
if ($addAndAssignBadge == null)
{
    $this->renderPartial('/badge/_selectBadgeType', array('badge_number' => $model->badge_number, 'person_id' => $model->id));
}




$this->widget('ext.bootstrap.widgets.TbDetailView', array(
    'type' => 'striped',
    'cssFile' => Yii::app()->request->baseUrl . '/css/general/CDetailView/' . Yii::app()->language . '/styles.css',
    'data' => $model,
    'attributes' => array(
        'name',
        'alias',
        'number',
        array(
            'type' => 'raw',
            'name' => 'type_id',
            'value' => $model->type->name,
        ),
        'mobile',
        'email',
        array(
            'type' => 'raw',
            'name' => 'department_id',
            'value' => $model->department->name,
        ),
        'manager',
        array(
            'type' => 'raw',
            'name' => 'is_manager',
            'value' => ($model->is_manager == 1) ? Yii::t('default', 'Yes') : Yii::t('default', 'No'),
        ),
        array(
            'type' => 'raw',
            'name' => 'is_food_manager',
            'value' => ($model->is_food_manager == 1) ? Yii::t('default', 'Yes') : Yii::t('default', 'No'),
        ),
        array(
            'type' => 'raw',
            'name' => 'receive_emails',
            'value' => ($model->receive_emails == 1) ? Yii::t('default', 'Yes') : Yii::t('default', 'No'),
        ),
        array(
            'name' => 'status',
            'value' => Yii::t('default', $model->status),
        ),
        array(
            'type' => 'raw',
            'label' => yii::t("default", 'Badge Number'),
            //Check first if there is badge number
            // Then check if this badge have been added to the system or not for adding it
            // Then check if this badge is free or not to assign it
            'value' => ($model->badge_number != 'N/A') ?
                    (($addAndAssignBadge === null) ?
                            ($model->badge_number . '  ' . CHtml::link(yii::t("default", 'Add and Assign'), '#selectBadgeType_modal', array('data-toggle' => 'modal'))) : (($addAndAssignBadge->status == 'Free') ?
                                    ($model->badge_number . '  ' . CHtml::link(yii::t("default", 'Assign Badge '), array('/badge/addAndAssign', 'badge_number' => $model->badge_number, 'person_id' => $model->id))) : ($model->badge_number))) : ($model->badge_number)
        ),
        array(
            'type' => 'raw',
            'label' => yii::t("default", 'POSs'),
            'value' => CHtml::link(yii::t("default", 'Manage'), array('/personPos/create', 'personId' => $model->id)) . Person::model()->getAllPOSs($model->personPoses)
        ),
        array(
            'type' => 'raw',
            'label' => yii::t("default", 'Assigned Badges'),
            'value' => CHtml::link(yii::t("default", 'Manage'), array('/person/manageBadges', 'id' => $model->id))
        ),
    ),
));


$this->widget('ext.bootstrap.widgets.TbGridView', array(
    'id' => 'badge-grid',
    'type' => 'striped',
    'dataProvider' => $badges->search(false),
    'summaryText' => '',
    'filter' => $badges,
    'columns' => array(
        'number',
        array(
            'name' => 'type_id',
            'value' => '$data->type->name',
            'filter' => CHtml::listData(BadgeType::getAll(), 'id', 'name')
        ),
        'activation_start_date',
        'activation_end_date',
        'max_served_meals',
        array(
            'name' => 'status',
            'type' => 'html',
            'filter' => array('Free' => Yii::t('default', 'Free'),
                'Active' => Yii::t('default', 'Active'),
                'Inactive' => Yii::t('default', 'Inactive'),
                'Deleted' => Yii::t('default', 'Deleted'),
                'Lost' => Yii::t('default', 'Lost'),
            ),
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
    ),
));
?>
<br />
<?php echo CHtml::link(Yii::t('default', 'Back'), array('/person/index'), array('class' => 'btn primary')); ?>
