<?php
 /* @var $this BadgeController */
 /* @var $model Badge */
 /* @var $form CActiveForm */


 $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
             'id' => 'badge-form',
             'enableAjaxValidation' => false,
         ));


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

//Add New Badge 
 if ($model->isNewRecord)
 {
     echo $form->textFieldRow($model, 'number');

     echo $form->dropDownListRow($model, 'type_id', CHtml::listData(BadgeType::getAll('Active'), 'id', 'name'), array('empty' => Yii::t('default', 'Select Badge Type')));

     $model->status = 'Free';

     echo $form->dropDownListRow($model, 'status', array('Free' => Yii::t('default', 'Free'),
         'Deleted' => Yii::t('default', 'Deleted'),
         'Lost' => Yii::t('default', 'Lost'),
     ));
 }
//Update Badge
 else
 {
     //Update Scope
     //Update Free Badges
     if ($model->person_id == null)
     {
         echo $form->textFieldRow($model, 'number');

         echo $form->dropDownListRow($model, 'type_id', CHtml::listData(BadgeType::getAll('Active'), 'id', 'name'), array('empty' => Yii::t('default', 'Select Badge Type')));

         echo $form->dropDownListRow($model, 'status', array('Free' => Yii::t('default', 'Free'),
             'Deleted' => Yii::t('default', 'Deleted'),
             'Lost' => Yii::t('default', 'Lost'),
         ));
     }
     ////Update Assigned Badges
     else
     {
         echo $form->uneditableRow($model, 'number');

         echo $form->dropDownListRow($model, 'type_id', CHtml::listData(BadgeType::getAll('Active'), 'id', 'name'), array('empty' => Yii::t('default', 'Select Badge Type'), 'disabled' => 'disabled'));

         //Remove Active option when the badge is expired
         if ($model->isExpired())
         {
             echo $form->dropDownListRow($model, 'status', array(
                 'Inactive' => Yii::t('default', 'Inactive'),
                 'Deleted' => Yii::t('default', 'Deleted'),
                 'Lost' => Yii::t('default', 'Lost'),
             ));
         }
         else
         {
             echo $form->dropDownListRow($model, 'status', array('Active' => Yii::t('default', 'Active'),
                 'Inactive' => Yii::t('default', 'Inactive'),
                 'Deleted' => Yii::t('default', 'Deleted'),
                 'Lost' => Yii::t('default', 'Lost'),
             ));
         }
     }
 }
?>
<div class="actions">
    <?php echo CHtml::submitButton(Yii::t('default', 'Save'), array('class' => 'btn primary')); ?>
     &ensp;
    <?php
     if ($person_id == null)
     {
         echo CHtml::link(Yii::t('default', 'Cancel'), array('index'), array('class' => 'btn primary'));
     }
     else
     {
         echo CHtml::link(Yii::t('default', 'Cancel'), array('/person/manageBadges', 'id' => $person_id), array('class' => 'btn primary'));
     }
    ?>
</div>

<?php $this->endWidget(); ?>
