<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
?>
<?php echo $this->partial('_location.tpl', 'core', array('item' => $this->bizlist, 'modulename' => 'bizlist')); ?>

<script type="text/javascript">
  en4.core.runonce.add(function(){
    scriptJquery('#tags').selectize({
      maxItems: 10,
      valueField: 'label',
      labelField: 'label',
      searchField: 'label',
      create: true,
      load: function(query, callback) {
          if (!query.length) return callback();
          scriptJquery.ajax({
            url: '<?php echo $this->url(array('controller' => 'tag', 'action' => 'suggest'), 'default', true) ?>',
            data: { value: query },
            success: function (transformed) {
              callback(transformed);
            },
            error: function () {
                callback([]);
            }
          });
      }
    });
  });
  
  var modulename = 'bizlist';
  var category_id = '<?php echo $this->category_id; ?>';
  var subcat_id = '<?php echo $this->subcat_id; ?>';
  var subsubcat_id = '<?php echo $this->subsubcat_id; ?>';

  en4.core.runonce.add(function() {
    if(category_id && category_id != 0) {
      showSubCategory(category_id, subcat_id);
    } else {
      if(scriptJquery('#category_id').val()) {
        showSubCategory(scriptJquery('#category_id').val());
      } else {
        if(document.getElementById('subcat_id-wrapper'))
          document.getElementById('subcat_id-wrapper').style.display = "none";
      }
    }

    if(subsubcat_id) {
      if(subcat_id && subcat_id != 0) {
        showSubSubCategory(subcat_id, subsubcat_id);
      } else {
        if(document.getElementById('subsubcat_id-wrapper'))
          document.getElementById('subsubcat_id-wrapper').style.display = "none";
      }
    } else if(subcat_id) {
      showSubSubCategory(subcat_id);
    }
    else {
      if(document.getElementById('subsubcat_id-wrapper'))
        document.getElementById('subsubcat_id-wrapper').style.display = "none";
    }
  });
</script>

<?php
  /* Include the common user-end field switching javascript */
  echo $this->partial('_jsSwitch.tpl', 'fields', array(
//'topLevelId' => (int) @$this->topLevelId,
//'topLevelValue' => (int) @$this->topLevelValue
))
?>
<div class="layout_middle">
  <div class="generic_layout_container">
      <div class="headline">
        <h2>
          <?php echo $this->translate('Business Listings');?>
        </h2>
        <div class="tabs">
          <?php
            // Render the menu
            echo $this->navigation()
          ->menu()
          ->setContainer($this->navigation)
          ->render();
          ?>
        </div>
     </div>
  </div>
  <?php echo $this->partial('_approved_tip.tpl', 'core', array('item' => $this->subject())); ?>
  <div class="generic_layout_container layout_core_content">
    <div class="bizlist_form global_form_wrap">
      <form action="<?php echo $this->escape($this->form->getAction()) ?>" enctype="multipart/form-data" method="<?php echo $this->escape($this->form->getMethod()) ?>" class="global_form form_submit_ajax">
        <div>
          <div>
          <h3>
            <?php echo $this->translate($this->form->getTitle()) ?>
          </h3>

          <div class="form-elements">
            <?php echo $this->form->getDecorator('FormErrors')->setElement($this->form)->render("");?>
            <?php echo $this->form->title; ?>
            <?php echo $this->form->tags; ?>
            <?php if(Engine_Api::_()->getApi('settings', 'core')->getSetting('bizlist.enable.location', 0) && Engine_Api::_()->getApi('settings', 'core')->getSetting('enableglocation', 0)) { ?>
            <?php echo $this->form->location; ?>
            <?php } ?>
            <?php if($this->form->category_id) echo $this->form->category_id; ?>
            <?php if($this->form->subcat_id) echo $this->form->subcat_id; ?>
            <?php if($this->form->subsubcat_id) echo $this->form->subsubcat_id; ?>
						<?php echo $this->form->aidescription; ?>
						<?php echo $this->form->is_draftwithapi; ?>
            <?php echo $this->form->body; ?>
            <?php echo $this->form->photo; ?>
            <?php echo $this->form->getSubForm('fields'); ?>
            <?php if($this->form->networks) echo $this->form->networks; ?>
            <?php if($this->form->auth_view) echo $this->form->auth_view; ?>
            <?php if($this->form->auth_comment) echo $this->form->auth_comment; ?>
            <?php if(Engine_Api::_()->getApi('settings', 'core')->getSetting('bizlist.enable.location', 0) && Engine_Api::_()->getApi('settings', 'core')->getSetting('enableglocation', 0)) { ?>
              <?php if($this->form->lat) echo $this->form->lat; ?>
              <?php if($this->form->lng) echo $this->form->lng; ?>
              <?php if($this->form->city) echo $this->form->city; ?>
              <?php if($this->form->state) echo $this->form->state; ?>
              <?php if($this->form->country) echo $this->form->country; ?>
              <?php if($this->form->zip) echo $this->form->zip; ?>
            <?php } ?>
          </div>

          <?php echo $this->form->bizlist_id; ?>
          <div class="form-wrapper">
            <div class="form-label">&nbsp;</div>
            <div class="form-element">
              <ul class="editphotos">
                <?php foreach( $this->paginator as $photo ): ?>
                <li class="row d-flex align-items-start justify-content-start">
                  <div class="col-5 col-md-4">
                    <div class="editphotos_photo">
                      <?php echo $this->itemPhoto($photo, 'thumb.normal')  ?> 
                    </div>
                    </div>
                  <div class="col-7 col-md-8">
                    <div class="editphotos_info d-flex justify-content-start flex-wrap gap-2">
                      <?php
                        $key = $photo->getGuid();
                        echo $this->form->getSubForm($key)->render($this);
                      ?>
                      <div class="editphotos_label">
                        <input type="radio" name="cover" value="<?php echo $photo->getIdentity() ?>" <?php if( $this->bizlist->photo_id == $photo->file_id ): ?> checked="checked"<?php endif; ?> />
                        <label><?php echo $this->translate('Main Photo');?></label>
                      </div>
                    </div>
                  </div>
                </li>
                <?php endforeach; ?>
              </ul>
            </div>
          </div>
          <div class="form-wrapper">
            <div class="form-label">&nbsp;</div>
            <div class="form-element">
              <?php echo $this->form->execute->render(); ?>
              </div>
            </div>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
<script type="application/javascript">
  en4.core.runonce.add(function() {
    scriptJquery('.bizlist_photos').each(function(){
      tinymce.execCommand('mceRemoveEditor',true, scriptJquery(this).attr('id'));
    });
  });
</script>
<?php if( $this->paginator->count() > 0 ): ?>
<br />
<?php echo $this->paginationControl($this->paginator); ?>
<?php endif; ?>
