vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   code help (https://vborg.vbsupport.ru/showthread.php?t=96035)

Mythotical 09-11-2005 03:47 AM

code help
 
Ok I managed to get alot of this ported hack working, but when I go into my admincp->users->my admin account->Add Linked Accounts to (user)

I then enter the userid to link to, a list of all accounts show up, that doesn't bother me, I click on (Link) which then is supposed to link the 2 accounts together but instead it does nothing, its supposed to give a message stating the accounts were linked.

Any ideas what could be wrong?

I am providing the code that I had to use and the qas.php file. If you wish to look over it and provide better feedback, please do. It suggested I check that 'u' is being converted to 'userid' but I have no clue what I'm looking for when it comes to that.

global.php add in code:
HTML Code:

# Quick Account Switch v1.2
unset($account_master); // empty markup for good measure
if ($bbuserinfo['userid']) // verify we are logged on
{
        if ($bbuserinfo['qas']) // slave or master account defined?
        {
                $qas = unserialize($bbuserinfo['qas']);
                foreach ($qas as $qas_acct => $qas_acct_value)
                {
                        if ('m'==$qas_acct_value['type']) // we are a master account to this slave account
                        {
                                $account_master .= "<tr><td class=\"vbmenu_option\"><a href=\"login.php?do=switch&id=$qas_acct_value[userid]\">" . base64_decode($qas_acct_value['username']) ."</a></td></tr>";
                        }
                        else // we are a slave account to this master account
                        {
                                $qasmast=fetch_userinfo($qas_acct_value['userid'], 0); // get master account's QAS details
                                // add master account at the top of the list
                                $account_master .= "<tr><td class=\"vbmenu_option\"><a href=\"login.php?do=switch&id=$qasmast[userid]\">$qasmast[username]</a></td></tr>";
                                // add all slaves except myself
                                $qas2 = unserialize($qasmast['qas']);
                                foreach ($qas2 as $qas_acct2 => $qas_acct_value2)
                                {
                                        if ($qas_acct_value2['userid'] != $bbuserinfo['userid']) // if I'm not this slave
                                        {
                                                $account_master .= "<tr><td class=\"vbmenu_option\"><a href=\"login.php?do=switch&id=$qas_acct_value2[userid]\">" . base64_decode($qas_acct_value2['username']) . "</a></td></tr>";
                                        }
                                }
                        }
                }
        }
}
# /Quick Account Switch v1.2

login.php add in code:
HTML Code:

// ##### start do switch # Quick Account Switch v1.2 #####
if ($_REQUEST['do'] == 'switch')
{
        globalize($_REQUEST, array('url' => STR, 'userid' => INT));
        $allow_switch = false;

        if (($bbuserinfo['userid']) && $_REQUEST['id']) {
                $id_from = $bbuserinfo['userid'];
                $id_to = $_REQUEST['id'];
                if ($bbuserinfo['qas']) // slave or master account defined?
                {
                        $qas = unserialize($bbuserinfo['qas']);
                        foreach ($qas as $qas_acct => $qas_acct_value)
                        {
                                if ('m'==$qas_acct_value['type']) // we are a master account to this slave account
                                {
                                        if ($id_to == $qas_acct_value['userid']) $allow_switch = true;
                                }
                                else // we are a slave account to this master account
                                {
                                        if ($id_to == $qas_acct_value['userid'])
                                        { // are we switching to the master account?
                                                $allow_switch = true;
                                        }
                                        else
                                        { // check the slaves
                                                $qasmast=fetch_userinfo($qas_acct_value['userid'], 0); // get master account's QAS details
                                                // allow switching to all but myself, since that's futile
                                                $qas2 = unserialize($qasmast['qas']);
                                                foreach ($qas2 as $qas_acct2 => $qas_acct_value2)
                                                {
                                                        if ($qas_acct_value2['userid'] != $bbuserinfo['userid']) // if I'm not this slave
                                                        {
                                                                if ($id_to == $qas_acct_value2['userid']) $allow_switch = true;
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }
       
        if ($logintype === 'cplogin' OR $logintype === 'modcplogin') $allow_switch = false;

        if ($allow_switch == false)
        {
                eval(print_standard_error('logout_missing_userid'));
        } else {

                // clear all cookies beginning with COOKIE_PREFIX
                $prefix_length = strlen(COOKIE_PREFIX);
                foreach ($_COOKIE AS $key => $val)
                {
                        $index = strpos($key, COOKIE_PREFIX);
                        if ($index == 0 AND $index !== false)
                        {
                                $key = substr($key, $prefix_length);
                                if (trim($key) == '')
                                {
                                        continue;
                                }
                                if ($key != 'sessionhash') vbsetcookie($key, '', 1);
                        }
                }

                if ($bbuserinfo['userid'] != 0 AND $bbuserinfo['userid'] != -1)
                {
                        $DB_site->query("
                                UPDATE " . TABLE_PREFIX . "user
                                SET lastactivity = " . (TIMENOW - $vboptions['cookietimeout']) . ",
                                        lastvisit = " . TIMENOW . "
                                WHERE userid = $bbuserinfo[userid]
                        ");

                        // make sure any other of this user's sessions are deleted (in case they ended up with more than one)
                        $DB_site->query("DELETE FROM " . TABLE_PREFIX . "session WHERE userid = $bbuserinfo[userid]");
                }
                // clear current sessionhash
                $DB_site->query("DELETE FROM " . TABLE_PREFIX . "session WHERE sessionhash = '" . addslashes($session['dbsessionhash']) . "'");

                // so much for logging out, lets login the assumed user
                $bbuserinfo = $DB_site->query_first("SELECT userid, usergroupid, membergroupids, username, password, salt FROM " . TABLE_PREFIX . "user WHERE userid = '" . $id_to . "'");

                vbsetcookie('userid', $bbuserinfo['userid']);
                // *** put your license code here or it'll not work *** you can find it at the top of this file (login.php)
                // the format is Lxxxxxxx, where 'xxxxxxx' is a set of numbers/letters, 0-9, a-f.
                // replace <*** your license code ***> in the next line with this code, between the single quotes.
                vbsetcookie('password', md5($bbuserinfo['password'] . '<*** your license code ***>'));

                exec_unstrike_user($bbuserinfo['username']);

                $DB_site->query("DELETE FROM " . TABLE_PREFIX . "session WHERE sessionhash = '" . addslashes($session['dbsessionhash']) . "'");

                $session['sessionhash'] = fetch_sessionhash();
                $session['dbsessionhash'] = $session['sessionhash'];
                $DB_site->query("
                        INSERT INTO " . TABLE_PREFIX . "session
                                (sessionhash, userid, host, idhash, lastactivity, styleid, loggedin, bypass, useragent)
                        VALUES
                                ('" . addslashes($session['sessionhash']) . "', " . intval($bbuserinfo['userid']) . ", '" . addslashes(SESSION_HOST) . "', '" . addslashes(SESSION_IDHASH) . "', " . TIMENOW . ", $session[styleid], 1, " . iif ($logintype === 'cplogin', 1, 0) . ", '" . addslashes(USER_AGENT) . "')
                ");
                vbsetcookie('sessionhash', $session['sessionhash'], 0);

                if ($nosessionhash == 1)
                { // if user is working through cookies, blank out the sessionhash
                        $shash = $session['sessionhash'] = '';
                        $surl = $session['sessionurl'] = '';
                        $surlJS = $session['sessionurl_js'] = '';
                }
                else
                {
                        $shash = $session['sessionhash'];
                        $surl = $session['sessionurl'] = 's=' . $session['sessionhash'] . '&amp;';
                        $surlJS = $session['sessionurl_js'] = 's=' . $session['sessionhash'] . '&';
                }

                if ($url == 'login.php' OR $url == "$vboptions[forumhome].php" OR strpos($url, 'do=logout') !== false)
                {
                        $url = "$vboptions[forumhome].php?$surl";
                }
                else
                {
                        $url = fetch_replaced_session_url($url);
                }

                $postvars = construct_hidden_var_fields($postvars);

                $temp = strpos($url, '?');
                if ($temp)
                {
                        $formfile = substr($url, 0, $temp);
                }
                else
                {
                        $formfile = $url;
                }

                eval(print_standard_redirect('redirect_login'));
        }
}

admincp/user.php add in code:
HTML Code:

// Quick Account Switch 1.2 - Start
        $qas_is_slave=false;
        print_table_header($vbphrase['qas_version']);
        if (!empty($user['qas']))
        {
                $qas = unserialize($user['qas']);
                foreach ($qas as $qas_acct => $qas_acct_value)
                {
                        if ('m'==$qas_acct_value['type']) // we are a master account to this slave account
                        {
                                $qas_link = "(<a href=\"user.php?$session[sessionurl]&do=edit&u=$qas_acct_value[userid]\">$vbphrase[profile]</a>)";
                                // parameters: u2 (slave),  u (master)
                                $qas_link .= " (<a href=\"qas.php?$session[sessionurl]&do=qasunlink&u=$user[userid]&u2=$qas_acct_value[userid]\">$vbphrase[qas_unlink]</a>)";
                                print_label_row($vbphrase['qas_master_to'] . ' ' . base64_decode($qas_acct_value['username']), $qas_link);
                        }
                        else // we are a slave account to this master account
                        {
                                $qas_link = "(<a href=\"user.php?$session[sessionurl]&do=edit&u=$qas_acct_value[userid]\">$vbphrase[profile]</a>)";
                                $qas_link .= " (<a href=\"qas.php?$session[sessionurl]&do=qasunlink&u=$qas_acct_value[userid]&u2=$user[userid]\">$vbphrase[qas_unlink]</a>)";
                                print_label_row($vbphrase['qas_slave_to'] . ' ' . base64_decode($qas_acct_value['username']), $qas_link);
                                $qas_is_slave = true;
                        }
                }
        }
        else
        {
                print_label_row($vbphrase['qas_no_accounts'], '', '', 'top', 'noslaves');
        }
        if (!$qas_is_slave)
        {
                $qas_link = " <a href=\"qas.php?$session[sessionurl]&do=qaslink&u=$user[userid]\">$vbphrase[qas_add_to] $user[username]</a>";
                print_description_row($qas_link);
        }
        print_table_break('', $INNERTABLEWIDTH);
       
        // Quick Account Switch 1.2 - End

Any help much appreciated and Marco, if you can help that would be great.

Cheers and thanks
Myth

Andreas 09-11-2005 03:58 AM

Have you asked Ianomed for Permission?

Marco van Herwaarden 09-11-2005 04:00 AM

First what i notice is that you still have references to vB3.0 variables, such as $bbuserinfo (this should be $vbulletin->userinfo), and $DB_site ($vbulletin->db).

Mythotical 09-11-2005 04:00 AM

Tried but no go, he is MIA, his partner said ok to it as long as credit was pointed back to Ianomed so that is what I'm doing.

Marco, I was told to change $DB_site to $db only. Am I wrong in doing that?

Ok changed what you suggested Marco and still same problem. I am just wondering why its not inserting the information into the database once I click on (Link) right next to the username. I providing a screenshot of where the link is.

Hope you can see the image clear enough.

Andreas 09-11-2005 04:20 AM

$db is fine in global context.
Did you actually do anything with this Code?
Looks like 100% 3.0 ...

Mythotical 09-11-2005 04:22 AM

That is one of my small problems, I have been changing the code over to 3.5 as much as possible, that is why I posted up the code and the file as I need to know what has to be changed in it to match 3.5 as I pretty much have come to a dead in. No more errors when entering the linking section but now it just doesn't want to enter the information into the database.

But if I have $vbulletin->db I'm still ok, right?

Andreas 09-11-2005 04:27 AM

I wonder how you ported anything without knowing the basics ...

$vboptions = $vbulletin->options
$DB_site = $db (Or $vbulletin->db, it's the same anyway)
$bbuserinfo = $vbulletin->userinfo
$session = $vbulletin->session->vars
addslashes() = $db->escape_string()
globalize = $vbulletin->input->clean_array_gpc, the Types have also changed
print_standard_error() = standard_error(fetch_error())

Change all that, check if there are errors - and then ask again :)

Mythotical 09-11-2005 04:29 AM

LOL

Kirby, I managed to port by just trying certain things, getting errors, and changing to other things. But now its becoming a bit trickier.

Ok going to check those now.

Quick on globalize, should that be $vbulletin->input->clean_array_gpc or $vbulletin->input->clean_gpc ?

Ok done, found quite a few spots I missed for $DB_site

No errors just that its still not inserting info into the database.

Well I'm off to bed to sleep a bit, I will look forward to seeing you reply.

Thanks Kirby and Marco.

Cheers
Myth (Steve)

EDIT: Ok no go as of yet, not sure what else needs to be checked. Anyone that can list what has changed since 3.0.x then I can easily go through and double check my work.


All times are GMT. The time now is 04:46 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01801 seconds
  • Memory Usage 1,804KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_html_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete