Ejemplo n.º 1
0
    /**
     * Main method, is called by p_master to run the module
     */
    public function main($mode, $id)
    {
        // Fetch all the data
        $fid = request_var('f', 0);
        $pid = request_var('prefixid', 0);
        $red = request_var('redirect', 'index.' . PHP_EXT);
        $tid = request_var('t', 0);
        $red = reapply_sid($red);
        // Get the prefix data
        $tree = $forums = array();
        sp_phpbb::$cache->obtain_prefix_forum_tree($tree, $forums);
        // Nothing for this forum
        if (empty($tree[$fid])) {
            return;
        }
        // Fetch the current data for this forum
        $sql = 'SELECT subject_prefix_id
			FROM ' . TOPICS_TABLE . '
			WHERE topic_id = ' . $tid;
        $result = sp_phpbb::$db->sql_query($sql);
        $_c_pid = sp_phpbb::$db->sql_fetchfield('subject_prefix_id', false, $result);
        sp_phpbb::$db->sql_freeresult($result);
        // No change
        if ($pid == $_c_pid) {
            meta_refresh(2, $red);
            trigger_error(sp_phpbb::$user->lang['PREFIX_NOT_CHANGED'] . '<br /><br />' . sprintf(sp_phpbb::$user->lang['RETURN_PAGE'], '<a href="' . $red . '">', '</a>'));
        }
        // The selected prefix can be used in this forum?
        if (!isset($tree[$fid][$pid]) && $pid > 0) {
            meta_refresh(2, $red);
            trigger_error(sp_phpbb::$user->lang['PREFIX_NOT_ALLOWED'] . '<br /><br />' . sprintf(sp_phpbb::$user->lang['RETURN_PAGE'], '<a href="' . $red . '">', '</a>'));
        }
        // Update
        $sql = 'UPDATE ' . TOPICS_TABLE . '
			SET subject_prefix_id = ' . $pid . '
			WHERE topic_id = ' . $tid;
        sp_phpbb::$db->sql_query($sql);
        if (sp_phpbb::$db->sql_affectedrows() == -1) {
            trigger_error('PREFIX_UPDATE_FAILED');
        } else {
            sp_cache::subject_prefix_quick_clear();
            meta_refresh(2, $red);
            trigger_error(sp_phpbb::$user->lang['PREFIX_UPDATED_SUCCESS'] . '<br /><br />' . sprintf(sp_phpbb::$user->lang['RETURN_PAGE'], '<a href="' . $red . '">', '</a>'));
        }
    }
Ejemplo n.º 2
0
    /**
     * Resyncronise the prefix tables.
     * * Make sure the prefix orders are incrementing numbers
     * * A prefix can't exist when its not linked to at least 1 forum
     *
     * @return void
     */
    public static function prefix_order_resync()
    {
        // First clear the cache, need to make sure we get the data as it is right now in the database
        sp_cache::subject_prefix_quick_clear();
        // Fetch the tree
        $tree = $forums = array();
        sp_phpbb::$cache->obtain_prefix_forum_tree($tree, $forums);
        sp_phpbb::$db->sql_transaction('begin');
        // Run through the tree and fix the ordering
        foreach ($tree as $fid => $data) {
            $next_order = 0;
            // Go through the data and check the order
            foreach ($data as $prefix) {
                // Order as expected?
                if ($prefix['prefix_order'] != $next_order) {
                    // Update the field
                    $sql = 'UPDATE ' . SUBJECT_PREFIX_FORUMS_TABLE . "\n\t\t\t\t\t\tSET prefix_order = {$next_order}\n\t\t\t\t\t\tWHERE prefix_id = {$prefix['prefix_id']}\n\t\t\t\t\t\t\tAND forum_id = {$fid}";
                    sp_phpbb::$db->sql_query($sql);
                }
                $next_order++;
            }
        }
        // Now remove all prefixes that aren't linked to a forum
        $pids = array();
        $sql = 'SELECT prefix_id
			FROM ' . SUBJECT_PREFIX_FORUMS_TABLE;
        $result = sp_phpbb::$db->sql_query($sql);
        while ($row = sp_phpbb::$db->sql_fetchrow($result)) {
            $pids[] = $row['prefix_id'];
        }
        sp_phpbb::$db->sql_freeresult($result);
        sp_phpbb::$db->sql_query('DELETE FROM ' . SUBJECT_PREFIX_TABLE . ' WHERE ' . sp_phpbb::$db->sql_in_set('prefix_id', $pids, true));
        sp_phpbb::$db->sql_transaction('commit');
        sp_cache::subject_prefix_quick_clear();
    }
Ejemplo n.º 3
0
            $order = $order - 1;
            // Update in the db
            sp_phpbb::$db->sql_query('UPDATE ' . SUBJECT_PREFIX_FORUMS_TABLE . ' SET prefix_order = ' . $order . ' WHERE prefix_id = ' . (int) $prefix);
        }
        // Tell the template we're good ^^
        $result = 'success';
        break;
        /*
        * Doesn't work correctly atm
        	case 'delete' :
        		$data = request_var('data', 'pf0_0');
        
        		// Strip "pf"
        		$data = substr($data, 3);
        
        		// Strip the ID
        		$parts = explode('_', $data);
        
        		sp_core::prefix_delete_forum((int) $parts[0], (int) $parts[1]);
        
        		// Tell the template we're good ^^
        		$result = 'success';
        	break;
        */
}
// Purge the cache
sp_cache::subject_prefix_quick_clear();
// echo the result
echo $result;
garbage_collection();
exit_handler();