Ejemplo n.º 1
0
function mysupport_upgrade()
{
    global $mybb, $db, $cache;
    $mysupport_cache = $cache->read("mysupport");
    $old_version = $mysupport_cache['version'];
    // legacy
    if (!$old_version) {
        $old_version = $cache->read("mysupport_version");
    }
    // only need to run through this if the version has actually changed
    if (!empty($old_version) && $old_version < MYSUPPORT_VERSION) {
        // reimport the settings to add any new ones and refresh the current ones
        mysupport_import_settings();
        // remove the current templates, but only the master versions
        mysupport_do_templates(0, true);
        // re-import the master templates
        mysupport_do_templates(1);
        // add any new table columns that don't already exist
        mysupport_table_columns(1);
        mysupport_stylesheet(2);
        $deleted_settings = array();
        $deleted_templates = array();
        // go through each upgrade process; versions are only listed here if there were changes FROM that version to the next
        // it will go through the ones it needs to and make the changes it needs
        if ($old_version <= 0.3) {
            // made some mistakes with the original table column additions, 3 of the fields weren't long enough... I do apologise
            $db->modify_column("threads", "statusuid", "INT(10) NOT NULL DEFAULT '0'");
            $db->modify_column("users", "deniedsupportreason", "INT(5) NOT NULL DEFAULT '0'");
            $db->modify_column("users", "deniedsupportuid", "INT(10) NOT NULL DEFAULT '0'");
            // maybe 255 isn't big enough for this after all
            $db->modify_column("mysupport", "description", "VARCHAR(500) NOT NULL");
        }
        if ($old_version <= 0.4) {
            mysupport_insert_task();
            mysupport_stylesheet(1);
            mysupport_recount_technical_threads();
            $query = $db->simple_select("threads", "DISTINCT assign", "assign != '0'");
            while ($user = $db->fetch_field($query, "assign")) {
                mysupport_recount_assigned_threads($user);
            }
            // there's just a 'mysupport' cache now with other things in it
            $db->delete_query("datacache", "title = 'mysupport_version'");
            // cache priorities and support denial reasons
            mysupport_cache("priorities");
            mysupport_cache("deniedreasons");
            // we need to update the setting of what to log, to include putting threads on hold, but don't change which actions may have logging disabled
            if ($mybb->settings['mysupportmodlog']) {
                $mybb->settings['mysupportmodlog'] .= ",";
            }
            $mybb->settings['mysupportmodlog'] .= "12";
            $update = array("value" => $db->escape_string($mybb->settings['mysupportmodlog']));
            $db->update_query("settings", $update, "name = 'mysupportmodlog'");
            rebuild_settings();
        }
        if (!empty($deleted_settings)) {
            $deleted_settings = "'" . implode("','", array_map($db->escape_string, $deleted_settings)) . "'";
            // have to use $db->escape_string above instead of around $deleted_settings directly because otherwise it escapes the ' around the names, which are important
            $db->delete_query("settings", "name IN ({$deleted_settings})");
            mysupport_update_setting_orders();
            rebuild_settings();
        }
        if (!empty($deleted_templates)) {
            $deleted_templates = "'" . implode("','", array_map($db->escape_string, $deleted_templates)) . "'";
            // have to use $db->escape_string above instead of around $deleted_templates directly because otherwise it escapes the ' around the names, which are important
            $db->delete_query("templates", "title IN ({$deleted_templates})");
        }
        // now we can update the cache with the new version
        mysupport_cache("version");
        // rebuild the forums and usergroups caches in case anything's changed
        $cache->update_forums();
        $cache->update_usergroups();
    }
}
Ejemplo n.º 2
0
/**
 * Change who a thread is assigned to.
 *
 * @param array Information about the thread.
 * @param int The UID of who we're assigning it to now.
 * @param bool If this is changing the assigned user of multiple threads.
**/
function mysupport_change_assign($thread_info, $assign, $multiple = false)
{
    global $mybb, $db, $lang;
    if ($multiple) {
        $fid = -1;
        $tid = -1;
        $old_assign = -1;
    } else {
        $fid = intval($thread_info['fid']);
        $tid = intval($thread_info['tid']);
        $old_assign = intval($thread_info['assign']);
    }
    // this'll be the same wherever so set this here
    if ($multiple) {
        $tids = implode(",", array_map("intval", $thread_info));
        $where_sql = "tid IN (" . $db->escape_string($tids) . ")";
    } else {
        $where_sql = "tid = '" . intval($tid) . "'";
    }
    // because we can assign a thread to somebody if it's already assigned to somebody else, we need to get a list of all the users who have been assigned the threads we're dealing with, so we can recount the number of assigned threads for all these users after the assignment has been chnaged
    $query = $db->simple_select("threads", "DISTINCT assign", $where_sql . " AND assign != '0'");
    $assign_users = array($assign => $assign);
    while ($user = $db->fetch_field($query, "assign")) {
        $assign_users[$user] = $user;
    }
    // if we're unassigning it
    if ($assign == "-1") {
        $update = array("assign" => 0, "assignuid" => 0);
        // remove the assignment on the thread
        $db->update_query("threads", $update, $where_sql);
        // get information on who it was assigned to
        $user = get_user($old_assign);
        if ($multiple) {
            mysupport_mod_log_action(6, $lang->sprintf($lang->unassigned_from_success_multi, count($thread_info)));
            mysupport_redirect_message($lang->sprintf($lang->unassigned_from_success_multi, count($thread_info)));
        } else {
            mysupport_mod_log_action(6, $lang->sprintf($lang->unassigned_from_success, $user['username']));
            mysupport_redirect_message($lang->sprintf($lang->unassigned_from_success, htmlspecialchars_uni($user['username'])));
        }
    } else {
        $update = array("assign" => intval($assign), "assignuid" => intval($mybb->user['uid']));
        if ($multiple) {
            // when assigning via the form in a thread, you can't assign a thread if it's solved
            // here, it's not as easy to check for that; instead, only assign a thread if it isn't solved
            $where_sql .= " AND status != '1'";
        }
        // assign the thread
        $db->update_query("threads", $update, $where_sql);
        $user = get_user($assign);
        $username = $db->escape_string($user['username']);
        if ($mybb->settings['mysupportassignpm'] == 1) {
            // send the PM
            mysupport_send_assign_pm($assign, $fid, $tid);
        }
        if ($mybb->settings['mysupportassignsubscribe'] == 1) {
            if ($multiple) {
                $tids = $thread_info;
            } else {
                $tids = array($thread_info['tid']);
            }
            foreach ($tids as $tid) {
                $query = $db->simple_select("threadsubscriptions", "*", "uid = '{$assign}' AND tid = '{$tid}'");
                // only do this if they're not already subscribed
                if ($db->num_rows($query) == 0) {
                    if ($user['subscriptionmethod'] == 2) {
                        $subscription_method = 2;
                    } else {
                        $subscription_method = 1;
                    }
                    require_once MYBB_ROOT . "inc/functions_user.php";
                    add_subscribed_thread($tid, $subscription_method, $assign);
                }
            }
        }
        if ($multiple) {
            mysupport_mod_log_action(5, $lang->sprintf($lang->assigned_to_success_multi, count($thread_info), $user['username']));
            mysupport_redirect_message($lang->sprintf($lang->assigned_to_success_multi, count($thread_info), htmlspecialchars_uni($user['username'])));
        } else {
            mysupport_mod_log_action(5, $lang->sprintf($lang->assigned_to_success, $username));
            mysupport_redirect_message($lang->sprintf($lang->assigned_to_success, htmlspecialchars_uni($username)));
        }
    }
    foreach ($assign_users as $user) {
        mysupport_recount_assigned_threads($user);
    }
}