<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Varien
 * @package    Varien_Object
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php echo $this->template('header.phtml') ?>

<div class="bar-head">
    <h4>Install New Extensions</h4>
</div>
<ul class="bare-list">
<li><span class="step-count">1</span> &nbsp; Search for modules via <a href="http://connect.magentocommerce.com/" target="Magento_Connect">Magento Connect</a>.</li>
<li><span class="step-count">2</span> &nbsp;
    <form action="<?php echo $this->url('pearInstallPackagePost')?>" method="post" target="pear_iframe" onsubmit="onSubmit()">
        <label for="uri">Paste extension key to install:</label> <input id="install_package_id" name="install_package_id" style="width:300px"/>
        <button type="submit">Install</button>
    </form></li>
</ul>

<br/><br/>

<div class="bar-head">
    <h4>Manage Existing Extensions</h4>
    <?php if (empty($_GET['updates'])): ?>
        <span class="f-right"><button type="button" class="f-right" onclick="location.href = location.href.replace(/(\?|$)/, '?updates=yes&')">Check for Upgrades</button></span>
    <?php endif; ?>
</div>
<?php $packages = $this->get('pear')->getAllPackages(); $i = 0; $cnt = count($packages); ?>
<?php foreach ($packages as $channel=>$pkgs): ?>

<form id="pear_packages_<?php echo $i ?>" class="pear-packages" action="<?php echo $this->url('pearPackagesPost')?>" method="post" target="pear_iframe" onsubmit="return onSubmit()">

    <button type="submit" class="f-right">Commit Changes</button>
    <h2 class="page-head">Channel: <?php echo $channel ?></h2>
    <span class="f-right"><label for="clean_sessions">Clear all sessions after successfull install or upgrade: <input type="checkbox" id="clean_sessions"/></label></span>
    <div class="clear"></div>

    <table cellspacing="0">
        <thead>
            <tr>
                <th class="first">Package Name</th>
                <th>Installed</th>
                <?php if (!empty($_GET['updates'])): ?><th>Available</th><?php endif; ?>
                <th>Actions</th>
                <th class="last">Summary</th>
            </tr>
        </thead>
        <tbody>
        <?php foreach ($pkgs as $pkgName=>$pkg): ?>
            <tr class="<?php echo $pkg['status']?>">
                <td class="first"><?php echo $pkgName?></td>
                <td><?php echo $pkg['local_version'].' ('.$pkg['local_state'].')'?>&nbsp;</td>
                <?php if (!empty($_GET['updates'])): ?><td><?php echo $pkg['upgrade_latest']?>&nbsp;</td><?php endif; ?>
                <td><select class="select" name="actions[<?php echo $channel.'|'.$pkgName ?>]">
                    <option selected="selected"></option>
                    <?php if(isset($pkg['actions']) && is_array($pkg['actions'])): ?>
                        <?php foreach ($pkg['actions'] as $k=>$v): ?>
                        <option value="<?php echo $k ?>"><?php echo $v ?></option>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </select>
                </td>
                <td class="last"><?php echo $pkg['summary']?></td>
            </tr>
        <?php endforeach; /*channel*/ ?>
        </tbody>
    </table>
    <div class="clear"></div>

    <div class="form-btn-set">
        <button type="submit" class="f-right">Commit Changes</button>
        <?php if (!empty($_GET['updates'])): ?>
        <p class="f-left a-left">
            <span style="background:#f6f6f6;padding:0 5px;">&nbsp;</span> &nbsp;Installed<br/>
            <span style="background:#fcfbbb;padding:0 5px;">&nbsp;</span> &nbsp;Upgrade Available<br/>
        </p>
        <?php endif; ?>
    </div>
</form>
<script type="text/javascript">
$$('#pear_packages_'+<?php echo $i?>+' select').each(function(el){el.value=''});
</script>
<?php if (++$i != $cnt): ?><div class="divider"></div><?php endif ?>
<br/>
<?php endforeach; /*all packages*/ ?>


<?php echo $this->template('pear/iframe.phtml') ?>

<a name="pear_iframe_result"></a>
<div id="pear_iframe_success" style="display:none">
    <?php $this->set('messages', array('success'=>array('Procedure completed. Please check the output frame for useful information and refresh the page to see changes.'))) ?>
    <?php echo $this->template('messages.phtml') ?>
    <button onclick="location.reload()">Refresh</button>
</div>
<div id="pear_iframe_failure" style="display:none">
    <?php $this->set('messages', array('error'=>array('Please check the output frame for errors and refresh the page to retry changes.'))) ?>
    <?php echo $this->template('messages.phtml') ?>
    <button onclick="location.reload()">Refresh</button>
</div>

<?php echo $this->template('footer.phtml') ?>
