<?php
/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 * @category   BL
 * @package    BL_CustomGrid
 * @copyright  Copyright (c) 2012 Benoît Leulliette <benoit.leulliette@gmail.com>
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
?>
<?php if ($websites = $this->getWebsites()): ?>
  <select name="<?php echo $this->getSelectName() ?>" id="<?php echo $this->getSelectId() ?>" class="<?php echo $this->getSelectClassNames() ?>">
  <?php if ($this->hasUseGridOption()): ?>
      <option value=""><?php echo $this->htmlEscape($this->getUseGridLabel()) ?></option>
  <?php endif ?>
  <?php if ($this->hasDefaultOption()): ?>
      <option value="0"<?php if ($this->hasStoreId() && ($this->getStoreId() == 0)): ?> selected="selected"<?php endif ?>><?php echo $this->htmlEscape($this->getDefaultStoreName()) ?></option>
  <?php endif ?>
      <?php foreach ($websites as $website): ?>
          <?php $showWebsite=false; ?>
          <?php foreach ($website->getGroups() as $group): ?>
              <?php $showGroup=false; ?>
              <?php foreach ($this->getStores($group) as $store): ?>
                  <?php if ($showWebsite == false): ?>
                      <?php $showWebsite = true; ?>
                      <optgroup label="<?php echo $this->htmlEscape($website->getName()) ?>"></optgroup>
                  <?php endif ?>
                  <?php if ($showGroup == false): ?>
                      <?php $showGroup = true; ?>
                      <optgroup label="&nbsp;&nbsp;&nbsp;<?php echo $this->htmlEscape($group->getName()) ?>">
                  <?php endif ?>
                  <option value="<?php echo $store->getId() ?>"<?php if ($this->getStoreId() == $store->getId()): ?> selected="selected"<?php endif ?>>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $this->htmlEscape($store->getName()) ?></option>
              <?php endforeach ?>
              <?php if ($showGroup): ?>
                  </optgroup>
              <?php endif ?>
          <?php endforeach ?>
      <?php endforeach ?>
  </select>
<?php endif ?>