<?php
$protected = ($this->currentBook->type == '3' && !$model->isNewRecord);

cs()->registerScriptFile(Yii::app()->baseUrl . '/js/autosizeInput/jquery.autosize.input.js', CClientScript::POS_HEAD);
Yii::app()->clientScript->registerScript('autosizeInputs', '$("#addressDetail input").autosizeInput({"space":0});', CClientScript::POS_READY);
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'addressbookaddresses-form',
    'action' => isset($_REQUEST["id"]) ? $this->createUrl('manageAddress', array("id"=>$_REQUEST["id"])) : $this->createUrl('manageAddress'),
    'enableAjaxValidation' => true,
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
        'afterValidate' => 'js:aftValidate'
    ),
    'type' => 'horizontal',
    'htmlOptions' => array(
        'enctype' => 'multipart/form-data',
    ),
        ));

echo CHtml::checkBox('deleteImg', false, array('style' => 'display:none'));
echo $form->hiddenField($model, 'id');
echo $form->hiddenField($model, 'contact_owner', array('value' => Yii::app()->user->sudoUser));
echo $form->hiddenField($model, 'contact_tid', array('value' => $bookId));

$addressImageClass = '';
$addressImageStyle = '';
// set preview image
if (!empty($model->contact_jpegphoto)) {
    $url = $model->getPhotoUrl(80);
    $addressImageStyle = "background-image:url('" . $url . "')";
    $addressImageClass = 'active';
}
$this->renderPartial("addressTabs/addressHeader", array(
    'model' => $model,
    'form' => $form,
    'addressImageClass' => $addressImageClass,
    "addressImageStyle" => $addressImageStyle,
    "protected" => $protected,
        ), false, false);
?>


<div id="contactDetail">

    <?php if ($writePermissions == true) {
        ?>
        <ul id="editButtons" class="nav nav-pills">
            <li id="saveAlias"><a href="" rel="tooltip" title="<?php echo __('GLOBAL_SAVE_BUTTON'); ?>"  data-translation-target="SAVE_ALIAS" data-translation-id="GLOBAL_SAVE_BUTTON"><i class="icon-save "></i> </a></li>
            <li id="editToggle"><a href="" rel="tooltip" title="<?php echo Yii::t("zii", "Update"); ?>"><i class="icon-pencil "></i> </a></li>
            <?php
            if (!$protected) {
                echo '<li id="deleteButton" class=""><a data-toggle="tab" href="" rel="tooltip" title=' . Yii::t("zii", "Delete") . '><i class="icon-trash"></i> </a></li>';
            }
            ?>
        </ul>
        <?php
    }



    /* FIXME : implement me ... 
      cs()->registerScriptFile(Yii::app()->baseUrl . '/js/qrcodejs/qrcode.min.js', CClientScript::POS_HEAD);
      ob_start();

      echo '<div id="qrCode"></div>';
      $js = '
      var contact = "' . $model->vCardString . '";

      var qrcode = new QRCode("qrCode", {
      text: contact,
      width: 256,
      height: 256,
      colorDark : "#000000",
      colorLight : "#ffffff",
      correctLevel : QRCode.CorrectLevel.H
      });';
      Yii::app()->clientScript->registerScript('qrCode', $js, CClientScript::POS_READY);
      // End export tab buffer
      $exportTab = ob_get_clean();
     */
    $this->widget('bootstrap.widgets.TbTabs', array(
        'type' => 'tabs',
        'tabs' => array(
            array(
                'label' => __('ADDRESSESS_FORM_HEADER_GENERAL'),
                'content' => $this->renderPartial("addressTabs/generalTab", array('model' => $model, 'form' => $form, 'protected' => $protected), true, false),
                'active' => true,
                'icon' => 'info'
            ),
            array(
                'label' => __('ADDRESSESS_FORM_HEADER_ADDRESSESS'),
                'content' => $this->renderPartial("addressTabs/addressesTab", array('model' => $model, 'form' => $form), true, false),
                'icon' => 'map-marker'
            ),
            array(
                'label' => __("ADDRESSESS_FORM_HEADER_BUSINESS"),
                'icon' => 'building',
                'content' => $this->renderPartial("addressTabs/companyTab", array('model' => $model, 'form' => $form), true, false)
            ),
            array(
                'label' => __("ADDRESSESS_FORM_HEADER_SOCIAL"),
                'icon' => 'globe',
                'content' => $this->renderPartial("addressTabs/socialNetworksTab", array('model' => $model, 'form' => $form), true, false)
            ),
            array(
                'label' => __("ADDRESSESS_FORM_HEADER_LAST_CONTACT"),
                'icon' => 'phone',
                'content' => $this->renderPartial("addressTabs/lastContactTab", array('model' => $model, 'form' => $form), true, false),
                'id' => 'lastContactTab',
                'linkOptions' => array('id' => 'lastContactTabHeader')
            ),
        /* FIXME : implement me ...
          array(
          'label'=>'Export',
          'content'=> $exportTab,
          'icon' => 'qrcode'
          ),
         */
        ),
        'htmlOptions' => array('data-translation-target' => 'ADDRESSESS_FORM_HEADER_TRANSLATIONS'),
    ));
    
    if (Yii::app()->user->translateMode) {
        echo '<i data-translation-target="ADDRESSESS_FORM_HEADER_TRANSLATIONS" data-translation-id="ADDRESSESS_FORM_HEADER_GENERAL"></i>';
        echo '<i data-translation-target="ADDRESSESS_FORM_HEADER_TRANSLATIONS" data-translation-id="ADDRESSESS_FORM_HEADER_ADDRESSESS"></i>';
        echo '<i data-translation-target="ADDRESSESS_FORM_HEADER_TRANSLATIONS" data-translation-id="ADDRESSESS_FORM_HEADER_BUSINESS"></i>';
        echo '<i data-translation-target="ADDRESSESS_FORM_HEADER_TRANSLATIONS" data-translation-id="ADDRESSESS_FORM_HEADER_SOURCE"></i>';
        echo '<i data-translation-target="ADDRESSESS_FORM_HEADER_TRANSLATIONS" data-translation-id="ADDRESSESS_FORM_HEADER_SOCIAL"></i>';
        echo '<i data-translation-target="ADDRESSESS_FORM_HEADER_TRANSLATIONS" data-translation-id="ADDRESSESS_FORM_HEADER_LAST_CONTACT"></i>';
        echo '<i data-translation-target="ADDRESSESS_FORM_HEADER_TRANSLATIONS" data-translation-id="ADDRESSESS_FORM_HEADER_PRIVATE"></i>';
        echo '<i data-translation-target="ADDRESSESS_FORM_HEADER_TRANSLATIONS" data-translation-id="ADDRESSESS_FORM_HEADER_RINGTONE"></i>';

        echo '<i data-translation-target="ADDRESSESS_MODEL_CONTACT_TYPES" data-translation-id="ADDRESSESS_MODEL_CONTACT_TYPE"></i>';
        echo '<i data-translation-target="ADDRESSESS_MODEL_CONTACT_TYPES" data-translation-id="CONTACT_TYPE_MODEL_ADDRESSES_CONTACT_TYPE_VIP"></i>';
        echo '<i data-translation-target="ADDRESSESS_MODEL_CONTACT_TYPES" data-translation-id="CONTACT_TYPE_MODEL_ADDRESSES_CONTACT_TYPE_VIF"></i>';
        echo '<i data-translation-target="ADDRESSESS_MODEL_CONTACT_TYPES" data-translation-id="CONTACT_TYPE_MODEL_ADDRESSES_CONTACT_TYPE_OFFICE"></i>';
        echo '<i data-translation-target="ADDRESSESS_MODEL_CONTACT_TYPES" data-translation-id="CONTACT_TYPE_MODEL_ADDRESSES_CONTACT_TYPE_FAMILY"></i>';
        echo '<i data-translation-target="ADDRESSESS_MODEL_CONTACT_TYPES" data-translation-id="CONTACT_TYPE_MODEL_ADDRESSES_CONTACT_TYPE_FRIENDS"></i>';
        echo '<i data-translation-target="ADDRESSESS_MODEL_CONTACT_TYPES" data-translation-id="CONTACT_TYPE_MODEL_ADDRESSES_CONTACT_TYPE_CUSTOMERS"></i>';
        echo '<i data-translation-target="ADDRESSESS_MODEL_CONTACT_TYPES" data-translation-id="ADDRESSES_MODEL_ADD_NEW_CONTACT_TYPE"></i>';
        
        echo '<i data-translation-target="SAVE_ALIAS" data-translation-id="ADDESSBOOKADDRESSES_NO_WRITE_PERMISSIONS_MESSAGE"></i>';
        

        foreach (range(0, AddressSourceType::TOTAL) as $source) {

            echo '<i data-translation-target="ADDRESSESS_MODEL_SOURCE_TYPES" data-translation-id="' . AddressSourceType::getSourceName($source, false) . '"></i>';
        }
    }
    ?>
</div>
<?php
echo CHtml::submitButton('Save', array('id' => 'addressookSaveButton', 'style' => 'display:none'));

$this->endWidget();
?>
<div class="alert-block  alert-error" id="errorList" style="display:none"></div>
