/* This will execute when in MODX */
    $language = $modx->getOption('language', $scriptProperties, 'en', true);
    $modx->lexicon->load($language . ':upgrademodx:default');
    /* Return empty string if user shouldn't see widget */
    $groups = $modx->getOption('groups', $scriptProperties, 'Administrator', true);
    if (strpos($groups, ',') !== false) {
        $groups = explode(',', $groups);
    }
    if (!$modx->user->isMember($groups)) {
        return '';
    }
}
$props = $scriptProperties;
$corePath = $modx->getOption('ugm.core_path', $props, $modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/upgrademodx/');
require_once $corePath . 'model/upgrademodx.class.php';
$upgrade = new UpgradeMODX($modx);
$upgrade->init($props);
/* See if user has submitted the form. If so, create the upgrade script and launch it */
if (isset($_POST['UpgradeMODX'])) {
    $upgrade->writeScriptFile();
    /* Log out all users before launching the form */
    $sessionTable = $modx->getTableName('modSession');
    if ($modx->query("TRUNCATE TABLE {$sessionTable}") == false) {
        $flushed = false;
    } else {
        $modx->user->endSession();
    }
    $modx->sendRedirect(MODX_BASE_URL . 'upgrade.php');
}
/* Set the method */
$forceFopen = $modx->getOption('forceFopen', $props, false, true);
            fwrite($fp, $fileContent);
            fclose($fp);
            /* Log out all users before launching the form */
            $sessionTable = $modx->getTableName('modSession');
            if ($modx->query("TRUNCATE TABLE {$sessionTable}") == false) {
                $flushed = false;
            } else {
                $modx->user->endSession();
            }
            $modx->sendRedirect(MODX_BASE_URL . 'upgrade.php');
        }
    } else {
        return $modx->lexicon('ugm_could_not_open') . ' ' . MODX_BASE_PATH . 'upgrade.php' . ' ' . $modx->lexicon('ugm_for_writing');
    }
}
$upgrade = new UpgradeMODX($modx);
$props = $scriptProperties;
$lastCheck = $modx->getOption('lastCheck', $props);
$interval = $modx->getOption('interval', $props);
if (empty($lastCheck)) {
    $lastCheck = '2015-08-17 00:00:004';
}
if (!($lastCheck && $interval)) {
    return '<p style="color:red">' . $modx->lexicon('ugm_missing_properties') . '</p>';
}
$hideWhenNoUpGrade = $modx->getOption('hideWhenNoUpgrade', $props);
$plOnly = $modx->getOption('plOnly', $props);
$versionsToShow = $modx->getOption('versionsToShow', $props, 5);
$currentVersion = $modx->getOption('settings_version');
if ($upgrade->timeToCheck($lastCheck, $interval)) {
    $upgradeAvailable = $upgrade->upgradeAvailable($currentVersion, $plOnly, $versionsToShow);