<?php
include_once("../../../mainfile.php");
include_once(XOOPS_ROOT_PATH."/modules/newbb_plus/xoops_version.php");
include_once(XOOPS_ROOT_PATH."/modules/newbb_plus/config.php");

function get_current_version()
{
        global $db;
        $xoopsModule = XoopsModule::getByDirname('newbb_plus');

        $sql = 'select version from '.$db->prefix('modules').' WHERE mid='.$xoopsModule->mid();
        if($result = $db->query($sql))
        {
                if($db->num_rows($result) == 1)
                {
                        $row = $db->fetch_object($result);
                        return $row->version;
                }
        }
        return '';
}

$cur_ver = get_current_version();
$new_ver = sprintf('%.02f',$modversion['version']);

echo "<h3>Newbb Plus Updater</h3>";
echo "<hr>";
echo "Current Version: ".$cur_ver."<br>";
echo "New Version: ".$new_ver."<br>";

$updater = 'update_'.$cur_ver.'_'.$new_ver.'.php';
if (file_exists($updater))
{
        include ($updater);
        $xoopsModule = XoopsModule::getByDirname('newbb_plus');
        $xoopsModule->update();
}
else
{
        echo "<h3>No updater available for these versions!</h3>";
        die();
}
echo "<hr>";
echo "<h3>Update Complete!</h3>";
echo "<h3><font color='#ff0000'>The '_update' directory should now be removed.</font></h3>";
?>