Ejemplo n.º 1
0
function run_upgrade()
{
    global $db_prefix;
    $info['name'] = 'tea_api';
    $info['esam'] = 'esam_api';
    $cs['GLOBAL_REQUIRED_API'] = array('tea_regreq', 1);
    $cs['DISPLAY_EVE_NAME'] = array('tea_usecharname', 1);
    $cs['ADD_CORP_TICKER'] = array('tea_custom_name', 1);
    $cs['DISPLAY_EVE_PORTRAIT'] = array('tea_avatar_enabled', 1);
    //$cs['DISPLAY_CORP_TITLES'] = array('tea_regreq', 1);
    $check = esamup_check_table($db_prefix . $info['name']);
    $esam = esamup_check_table($db_prefix . $info['esam']);
    if ($check && $esam) {
        // settings
        $settings = esamup_select("SELECT NAME, VALUE FROM " . $db_prefix . "esam_settings");
        if (!empty($settings)) {
            foreach ($settings as $s) {
                if (isset($cs[$s[0]]) && $s[1] == 'true') {
                    esamup_query("\n\t\t\t\t\t\tREPLACE INTO " . $db_prefix . "settings\n\t\t\t\t\t\t\t(variable, value)\n\t\t\t\t\t\tVALUES \n\t\t\t\t\t\t('" . $cs[$s[0]][0] . "', '" . $cs[$s[0]][1] . "')");
                }
            }
        }
        // api's
        $apis = esamup_select("SELECT ID_MEMBER, USER_ID, API_KEY FROM " . $db_prefix . "esam_api");
        if (!empty($apis)) {
            foreach ($apis as $api) {
                esamup_query("\n\t\t\t\t\tREPLACE INTO " . $db_prefix . "tea_api\n\t\t\t\t\t\t(ID_MEMBER, userid, api)\n\t\t\t\t\tVALUES \n\t\t\t\t\t('" . $api[0] . "', '" . $api[1] . "', '" . $api[2] . "')");
            }
        }
        // rules
        $rules = esamup_select("SELECT ID_RULE, TYPE, ROLE, ROLE_ID, GROUP_ID, TITLE, SKILL_ID, SKILL_LVL FROM " . $db_prefix . "esam_rules");
        if (!empty($rules)) {
            global $sourcedir;
            require_once $sourcedir . '/TEA_SkillDump.php';
            $skills = getSkillArray();
            foreach ($rules as $rule) {
                $type = NULL;
                $value = NULL;
                $extra = NULL;
                $id = esamup_select("SELECT ruleid FROM " . $db_prefix . "tea_rules ORDER BY ruleid DESC LIMIT 1");
                if (!empty($id)) {
                    $id = $id[0][0] + 1;
                } else {
                    $id = 1;
                }
                // elseif(is_numeric($_POST['id']))
                // {
                // $id = $_POST['id'];
                // $exists = TRUE;
                // }
                // else
                // die("error id");
                $andor = 'AND';
                //if($andor != "AND" && $andor != "OR")
                //	die("andor must be AND or OR");
                $name = 'ESAM RULE ' . $rule[0];
                //	if($_POST['main'] == "main")
                //		$main = 1;
                //	else
                $main = 0;
                switch (strtoupper($rule[1])) {
                    case 'P':
                        // pilot rule, ignore entire rule
                        continue 2;
                    case 'C':
                        $type = "corp";
                        $value = $rule[3];
                        break;
                    case 'A':
                        $type = "alliance";
                        $value = $rule[3];
                        break;
                    case 'F':
                        $type = "militia";
                        switch ($rule[3]) {
                            case 500001:
                                $value = 'Caldari State';
                                break;
                            case 500002:
                                $value = 'Minmatar Republic';
                                break;
                            case 500003:
                                $value = 'Amarr Empire';
                                break;
                            case 500004:
                                $value = 'Gallente Federation';
                                break;
                        }
                        break;
                    default:
                        continue 2;
                }
                //	if(isset($types[$_POST['type']]))
                //		$type = $_POST['type'];
                //	else
                //		die("Unknown Type");
                //	if($type == "corp" || $type == "alliance" || $type == "skill" || $type == "role" || $type == "title" || $type == "militia")
                //		$value = mysql_real_escape_string($_POST['value']);
                //	if($type == "skill")
                $extra = '';
                //	if(isset($groups[$_POST['group']]))
                $group = $rule[4];
                //	elseif(!$exists)
                //		die("Invalid Group");
                //if(!$exists)
                esamup_query("INSERT INTO " . $db_prefix . "tea_rules (ruleid, name, main, `group`, andor) VALUES ({$id}, '{$name}', {$main}, {$group}, '{$andor}')");
                esamup_query("INSERT INTO " . $db_prefix . "tea_conditions (ruleid, type, value, extra) VALUES ({$id}, '{$type}', '{$value}', '{$extra}')");
                //if(!isset($types[$_POST['type']]))
                //	error
                //elseif(!is_numeric($_POST['id']) && $_POST['id'] != "new")
                //	error
                //elseif(!is_numeric($_POST['group']))
                //	error
                if ($rule[2] == 'roleDirector') {
                    $type = 'role';
                    $value = 'Director';
                    $extra = '';
                    esamup_query("INSERT INTO " . $db_prefix . "tea_conditions (ruleid, type, value, extra) VALUES ({$id}, '{$type}', '{$value}', '{$extra}')");
                }
                if ($rule[5] != 'null' && !empty($rule[5])) {
                    $type = 'title';
                    $value = $rule[5];
                    $extra = '';
                    esamup_query("INSERT INTO " . $db_prefix . "tea_conditions (ruleid, type, value, extra) VALUES ({$id}, '{$type}', '{$value}', '{$extra}')");
                }
                if (!empty($rule[6])) {
                    $type = 'skill';
                    $value = $skills[$rule[6]];
                    $extra = $rule[7];
                    esamup_query("INSERT INTO " . $db_prefix . "tea_conditions (ruleid, type, value, extra) VALUES ({$id}, '{$type}', '{$value}', '{$extra}')");
                }
            }
        }
    }
}
Ejemplo n.º 2
0
$tables[12]["id"] = "INT DEFAULT NULL AUTO_INCREMENT";
$tables[12]["smf"] = "INT DEFAULT 0";
$tables[12]["jabber"] = "VARCHAR(255) DEFAULT NULL";
$tables[12]["nf"] = "VARCHAR(255) DEFAULT NULL";
$info[13]['name'] = 'tea_jabber_groups';
$info[13]['primary'] = 'id';
$tables[13]["id"] = "VARCHAR(50) DEFAULT NULL";
$tables[13]["value"] = "INT(1) DEFAULT 1";
global $db_prefix;
require "esam_upgrade.php";
$esaminfo['old'] = 'eve_api';
$esaminfo['name'] = 'tea_api';
$esaminfo['esam'] = 'esam_api';
$checkold = esamup_check_table($db_prefix . $esaminfo['old']);
$check = esamup_check_table($db_prefix . $esaminfo['name']);
$esam = esamup_check_table($db_prefix . $esaminfo['esam']);
if (!$checkold && !$check && $esam) {
    $esamupgrade = TRUE;
}
foreach ($tables as $i => $table) {
    $checkold = tea_check_table($db_prefix . $info[$i]['old'], $table);
    $check = tea_check_table($db_prefix . $info[$i]['name'], $table);
    if (($checkold[0] || !$checkold[0] && $checkold[1]) && !$check[0] && !$check[1]) {
        // if old table exists regardless of if needs changing and new doesnt then rename
        tea_query("RENAME TABLE " . $db_prefix . $info[$i]['old'] . " TO " . $db_prefix . $info[$i]['name']);
    }
    $check = tea_check_table($db_prefix . $info[$i]['name'], $table);
    if (!$check[0]) {
        if ($check[1]) {
            foreach ($check[1] as $f) {
                tea_query("ALTER TABLE " . $db_prefix . $info[$i]['name'] . " ADD " . $f . " " . $table[$f]);