vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How to pass users pw through email? (https://vborg.vbsupport.ru/showthread.php?t=285376)

Simon Lloyd 08-28-2012 04:45 AM

The error isn't in misc.php it's in one of your plugin's, misc.php is called when one of yourplugins doesn't give a result.

John Lester 08-28-2012 04:02 PM

I know it's not in misc.php and the only plugin is the mod I'm working on. What I don't understand about the error is ... what exactly is it looking for?

I mean there are no ` in the mod, so is it looking for ]' or ']' or ']'' or ] ?

--------------- Added [DATE]1346177661[/DATE] at [TIME]1346177661[/TIME] ---------------

Found the elusive missing ] :D

Simon Lloyd 08-28-2012 06:32 PM

Good man :), i know what it's like, you look so hard for so long you get code blind and can't see the nose in front of you!

John Lester 08-28-2012 07:50 PM

Well it's my own fault. I had two copies of the xml, one was the master copy and the other was used to work on. I accidentally deleted the master copy instead of the borked working copy :D

So now I'm still using the borked working copy (for some reason it keeps giving me the error that I'm already unsubscribed even though I'm not), but once I get it unborked it will become the new master.

John Lester 09-16-2012 10:06 PM

I'm still stuck on the existing subscribe threads. I'm unable to get a working loop done. Just wanted to update those that are following this, it's not forgotten it's just stalled :D

John Lester 09-25-2012 10:10 PM

I need a fresh set of eyes to help me find out why this code is returning a parse error (or tell me how screwed up the code itself is as I'm just not getting this stupid loop thing :( ) Since the rest of the queries start with $unsubscribe does this one have to use it as well? I was understanding that the loop variable should be different but as I said before I'm obviously not getting it :D

Another related question, in order to get around the email error being returned with this query, would I use another JOIN statement to add the email to the insert query? If so which one?

Code:

  if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
  $thead_sub =    $db->query_read("
                                SELECT NULL,
                                      userid,
                                      threadid,
                                      emailupdate,
                                      folderid,
                                      canview
                                FROM ".TABLE_PREFIX."subscribethread
                                WHERE userid = '$id'
                                AND emailupdate IN (1, 2, 3)
                                AND usergroupid NOT IN (5, 6, 7)");
                              }
  $thread_sub = array();
    while($row = mysql_fetch_assoc($thread_sub))
          $db->query("
                INSERT INTO ".TABLE_PREFIX."unsub_subscribethread LEFT JOIN user ON (user.usergroupid = user.usergroupid)
                SELECT NULL,
                      userid,
                      threadid,
                      emailupdate,
                      folderid,
                      canview
                FROM ".TABLE_PREFIX."subscribethread
                WHERE userid = '$id'
                AND emailupdate IN (1, 2, 3)
                AND usergroupid NOT IN (5, 6, 7)");
          }


nerbert 09-25-2012 10:19 PM

Quote:

Originally Posted by John Lester (Post 2368554)
I need a fresh set of eyes to help me find out why this code is returning a parse error (or tell me how screwed up the code itself is as I'm just not getting this stupid loop thing :( ) Since the rest of the queries start with $unsubscribe does this one have to use it as well? I was understanding that the loop variable should be different but as I said before I'm obviously not getting it :D

Another related question, in order to get around the email error being returned with this query, would I use another JOIN statement to add the email to the insert query? If so which one?

Missing curlies

Code:

  if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
  {
  $thead_sub =    $db->query_read("
                                SELECT NULL,
                                      userid,
                                      threadid,
                                      emailupdate,
                                      folderid,
                                      canview
                                FROM ".TABLE_PREFIX."subscribethread
                                WHERE userid = '$id'
                                AND emailupdate IN (1, 2, 3)
                                AND usergroupid NOT IN (5, 6, 7)");
  }
  $thread_sub = array();
    while($row = mysql_fetch_assoc($thread_sub))
    {
          $db->query("
                INSERT INTO ".TABLE_PREFIX."unsub_subscribethread LEFT JOIN user ON (user.usergroupid = user.usergroupid)
                SELECT NULL,
                      userid,
                      threadid,
                      emailupdate,
                      folderid,
                      canview
                FROM ".TABLE_PREFIX."subscribethread
                WHERE userid = '$id'
                AND emailupdate IN (1, 2, 3)
                AND usergroupid NOT IN (5, 6, 7)");
          }

[/QUOTE]

John Lester 09-26-2012 04:09 PM

Oh my .... how silly of me :D Thanks nerbet :)

John Lester 10-01-2012 03:00 PM

Ok so I'm still having trouble with the stupid looping through the subscribethread table and decided that I needed to exclude the mods, supermods, and admins from having their subscriptions or usergroups (that code isn't shown here) changed.

However I'm a bit confused on how to do this. I need to LEFT JOIN the usergroupid from the user table, but the following code spits out a syntax error and I'm not seeing it.

Code:

        // If you selected to backup existing thread subscriptions this code will be executed.
        if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
          {
            // Copy users existing thread subscriptions to the unsub_subscribethread table except for mods, admins, and supermods
            $db->query("
                INSERT INTO ".TABLE_PREFIX."unsub_subscribethread LEFT JOIN user ON (user.userid = user.usergroupid)
                SELECT NULL,
                      userid,
                      threadid,
                      emailupdate,
                      folderid,
                      canview
                FROM ".TABLE_PREFIX."subscribethread
                WHERE userid = '$id'
                AND emailupdate IN (1, 2, 3)
                AND usergroupid NOT IN (5, 6, 7)");
          }


Simon Lloyd 10-01-2012 04:25 PM

Other than spacings around TABLE_PREFIX it seems fine (altough i haven't checked the tables...etc it calls)
PHP Code:

// If you selected to backup existing thread subscriptions this code will be executed.
        
if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
          {
            
// Copy users existing thread subscriptions to the unsub_subscribethread table except for mods, admins, and supermods
            
$db->query("
                INSERT INTO " 
.TABLE_PREFIX"unsub_subscribethread LEFT JOIN user ON (user.userid = user.usergroupid)
                SELECT NULL,
                       userid,
                       threadid,
                       emailupdate,
                       folderid,
                       canview
                FROM " 
.TABLE_PREFIX"subscribethread
                WHERE userid = '
$id'
                AND emailupdate IN (1, 2, 3)
                AND usergroupid NOT IN (5, 6, 7)"
);
          } 

--------------- Added [DATE]1349116350[/DATE] at [TIME]1349116350[/TIME] ---------------

This should help with your syntax (remember to only use the query part rather than the whole php :)) http://developer.mimer.com/validator...dex.tml#parser

kh99 10-01-2012 07:21 PM

Are you getting an sql syntax error or a php syntax error?

You're trying to select the rows from subscribethread for only one user so you really only need to check the usergroupid and either do the query or not. If you don't have the usergroupid for that user available then you do save one query by combining it like that, but since this is for something that is executed rarely compared to everything going on on the forum, it might be a better idea to do two separate queries and have the code be less complicated.

Having said all that, the way you have it is doing a join to the UPDATE query, but the WHERE goes with the select, so it will probably tell you that there's no column named 'usergroupid'. Maybe you should do this instead:

Code:

INSERT INTO " .TABLE_PREFIX. "unsub_subscribethread AS unsub_subscribethread
                SELECT NULL,
                      userid,
                      threadid,
                      emailupdate,
                      folderid,
                      canview
                FROM " .TABLE_PREFIX. "subscribethread
                LEFT JOIN " .TABLE_PREFIX. "user AS user ON (user.userid = unsub_subscribethread.userid)
                WHERE userid = '$id'
                AND emailupdate IN (1, 2, 3)
                AND usergroupid NOT IN (5, 6, 7)


John Lester 10-02-2012 03:44 AM

Hmmm so it would be better to run the check before executing any of the queries (I was planning on excluding those user groups from each query) instead of building the conditional into the query? I suppose I should go a step further and create a setting to allow admins to exclude certain user groups, what do you guys think?

My thinking was that since the subscribethread table doesn't have the usergroupid column, that I needed to call if from the user table. But I don't see why you went with user.userid = unsub_subscribethread.userid?

I'm pretty much stalling on this due to the fact that I just can't seem to wrap my head around the proper loop. I've done some reading and I've searched for examples, but nothing I have found seems to have "clicked" with my brain yet :D

kh99 10-02-2012 09:05 AM

Quote:

Originally Posted by John Lester (Post 2370122)
Hmmm so it would be better to run the check before executing any of the queries (I was planning on excluding those user groups from each query) instead of building the conditional into the query? I suppose I should go a step further and create a setting to allow admins to exclude certain user groups, what do you guys think?

Yeah, something like that sounds better to me.

Quote:

My thinking was that since the subscribethread table doesn't have the usergroupid column, that I needed to call if from the user table. But I don't see why you went with user.userid = unsub_subscribethread.userid?
When you do a join with an 'ON', the condition in the ON needs to be true for the rows that get joined. In your case, it needs to compare userids so the parts of the joined rows are for the same user (otherwise the results don't make a lot of sense). The 'ON' doesn't affect which columns appear in the results.


Quote:

I'm pretty much stalling on this due to the fact that I just can't seem to wrap my head around the proper loop. I've done some reading and I've searched for examples, but nothing I have found seems to have "clicked" with my brain yet :D
I'm sorry I dumped this on you. I keep hoping maybe I'll get back to it, but instead I just keep piling up other mods that are half done. :) But I can certainly help with things like getting loops to work if you want.

John Lester 10-03-2012 02:01 PM

Don't worry about dumping this on me, I'll eventually either figure out the loop or ask you to figure it out for me :D

Your reason for editing the post has me intrigued ;)

Now back to the JOIN statement just for clarification since I'm almost done setting up the exclude user groups settings :)

user.userid = unsub_subscribethread.userid ... I thought that this would only pull the userid from the user table, hence my confusion. The entire point of joining the user table was to grab the usergroupid for use in checking user groups in the query. I am assuming that is how JOIN works (grabbing only the column listed in the ()'s ) but I also assumed that I would be done with this mod by now :D

kh99 10-03-2012 02:38 PM

Quote:

Originally Posted by John Lester (Post 2370503)
Your reason for editing the post has me intrigued ;)

Yeah, that's my way of saying I made so many typos or other mistakes that part of it was almost unreadable.


Quote:

user.userid = unsub_subscribethread.userid ... I thought that this would only pull the userid from the user table, hence my confusion. The entire point of joining the user table was to grab the usergroupid for use in checking user groups in the query. I am assuming that is how JOIN works (grabbing only the column listed in the ()'s ) but I also assumed that I would be done with this mod by now :D
You're really creating a "virtual" table that you're selecting from, and the ON is just instructions on how to do that. You still need to list any columns you want returned (from either table) after SELECT. I didn't list user.usegroupid in the code I posted above because I only used it in the WHERE and didn't think there was any need to include it in the returned data.

John Lester 10-03-2012 04:15 PM

AH I see what happened here, you were referring to the code I pasted (#86) showing a failed attempt at looping :D

I should've mentioned that I scrapped that bit of code and my question regarding the LEFT JOIN was for the code in post #89 :)

But it's a moot point now, I get the gist of what you were saying in regards to the LEFT JOIN :)

John Lester 10-22-2012 05:59 PM

I'm getting a parse error when I have this code un-commented, I suspect it's the LEFT JOIN but then again what do I know :D

I'm trying to join the user table to pull the email column so the mod doesn't return the email error if there is no email column in the table.

Code:

    // If you selected to change existing thread subscriptions this code will be executed
    if ($vbulletin->options['advanced_unsubscribe_link_existing_thread_sub'])
      {
        // Sets existing thread subscriptions to through control panel only
        $db->query{"
                  UPDATE " .TABLE_PREFIX. "subscribethread
                  LEFT JOIN " .TABLE_PREFIX. "user AS user ON (user.email = user.userid)
                  SET emailupdate = 0
                  WHERE emailupdate IN (1,2,3)
                  AND userid = $id
                  AND email= '" . $db->escape_string($email) . "'");
      }


squidsk 10-22-2012 06:02 PM

Your ON clause is wrong, one of the fields needs to be from the subscribethread table.

John Lester 10-22-2012 07:42 PM

Thanks for replying squid :) I changed the ON clause and still have a parse error :(

Code:

    // If you selected to change existing thread subscriptions this code will be executed
    if ($vbulletin->options['advanced_unsubscribe_link_existing_thread_sub'])
      {
        // Sets existing thread subscriptions to through control panel only
        $db->query{"
                  UPDATE " .TABLE_PREFIX. "subscribethread
                  LEFT JOIN " .TABLE_PREFIX. "user AS user ON (subscribethread.userid = user.email)
                  SET emailupdate = 0
                  WHERE emailupdate IN (1,2,3)
                  AND userid = $id
                  AND email= '" . $db->escape_string($email) . "'");
      }

Tried using this as well and get a parse error.

Code:

(user.email = subscribethread.userid)
If I comment out the block of code the mod works fine.

squidsk 10-23-2012 01:12 AM

Quote:

Originally Posted by John Lester (Post 2375147)
Thanks for replying squid :) I changed the ON clause and still have a parse error :(

Code:

    // If you selected to change existing thread subscriptions this code will be executed
    if ($vbulletin->options['advanced_unsubscribe_link_existing_thread_sub'])
      {
        // Sets existing thread subscriptions to through control panel only
        $db->query{"
                  UPDATE " .TABLE_PREFIX. "subscribethread
                  LEFT JOIN " .TABLE_PREFIX. "user AS user ON (subscribethread.userid = user.email)
                  SET emailupdate = 0
                  WHERE emailupdate IN (1,2,3)
                  AND userid = $id
                  AND email= '" . $db->escape_string($email) . "'");
      }

Tried using this as well and get a parse error.

Code:

(user.email = subscribethread.userid)
If I comment out the block of code the mod works fine.

Shouldn't the ON block be:

Code:

ON user.userid = subscribethread.userid
You can't compare an email to a userid.

John Lester 10-23-2012 02:37 AM

Dangit ... I knew I didn't fully understand the JOINs ...

The subscribethread table doesn't have an email column, but if I JOIN the user table I don't have to mention the email table (in the JOIN) in order to use it in the UPDATE ... WHERE as long as the userid from the user table matches the userid from subscribethread table?

squidsk 10-23-2012 01:37 PM

Quote:

Originally Posted by John Lester (Post 2375224)
Dangit ... I knew I didn't fully understand the JOINs ...

The subscribethread table doesn't have an email column, but if I JOIN the user table I don't have to mention the email table (in the JOIN) in order to use it in the UPDATE ... WHERE as long as the userid from the user table matches the userid from subscribethread table?

What's the point of the email address in the query? Since you have a users userid, in the $id variable, that will uniquely identify everything you need to update the appropriate stuff in the subscriptionthread table.

If what I understand you want to achieve why not use the following query:

PHP Code:

 $db->query("UPDATE " .TABLE_PREFIX"subscribethread
                   SET emailupdate = 0
                   WHERE emailupdate IN (1,2,3)
                   AND userid = 
$id"); 

Also note two things, first your $db->query should use () not {} and have a ; at the end, and also an update query can only be applied to a table and not a join.

John Lester 10-23-2012 04:22 PM

Ok so JOINs can't be used in an UPDATE? I don't recall reading that anywhere :(

The reason I'm trying to include the email field is that if I don't it trips an error further along the mod about not inputting a valid email and doesn't complete the query.

Code:

        // If an email isn't entered or is invalid show this error
        if (empty($unsubscribe['email']))
        {
            eval(standard_error(fetch_error('advanced_unsubscribe_link_error_unsubscribed', $vbulletin->options['contactuslink'])));
        }

How I understand that code it checks each query for an email address and if the query doesn't have one it spits out the error. I have a couple of ideas about how to get around that (move the code so it comes before the queries that don't have email fields, or just not use it :D ) but not sure if there's a better way.

I do use ( for the $db->queries and they do have the ; at the end :)

John Lester 11-05-2012 08:55 PM

Ok so I sorta started working on this again, and I can't figure out what's wrong here. I'm trying to copy the rows from subscribethread to unsub_subscribethread *yes it does exist*. Yes the option is selected in the ACP. The mod runs but doesn't spit out ANY errors, it also doesn't copy the rows :(

This is the select query I'm using

Code:

  $unsubscribe = $db->query_read("SELECT NULL, userid, threadid, emailupdate, folderid, canview FROM " .TABLE_PREFIX. "subscribethread WHERE userid = '$id' AND emailupdate IN (1, 2,3)");
This is the code inside of the function


Code:

    // If you selected to backup existing thread subscriptions this code will be exectued.
    if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
        {
        // Copies existing thread subscriptions to the unsub_subscribethread table.
          $db->query("
                    INSERT INTO " .TABLE_PREFIX. "unsub_subscribethread
                    SELECT NULL,
                          userid,
                          threadid,
                          emailupdate,
                          folderid,
                          canview
                    FROM " .TABLE_PREFIX. "subscribethread
                    WHERE userid = '$id'
                    AND emailupdate IN (1, 2, 3)");
        }

If I run this query in phpmyadmin it works ...

Code:

                    INSERT INTO unsub_subscribethread
                    SELECT NULL,
                          userid,
                          threadid,
                          emailupdate,
                          folderid,
                          canview
                    FROM subscribethread
                    WHERE userid = 1
                    AND emailupdate IN (1, 2, 3)


kh99 11-05-2012 09:15 PM

Are you sure $id has the right value?

TheSupportForum 11-05-2012 09:19 PM

Quote:

Originally Posted by John Lester (Post 2378697)
Ok so I sorta started working on this again, and I can't figure out what's wrong here. I'm trying to copy the rows from subscribethread to unsub_subscribethread *yes it does exist*. Yes the option is selected in the ACP. The mod runs but doesn't spit out ANY errors, it also doesn't copy the rows :(

This is the select query I'm using

Code:

  $unsubscribe = $db->query_read("SELECT NULL, userid, threadid, emailupdate, folderid, canview FROM " .TABLE_PREFIX. "subscribethread WHERE userid = '$id' AND emailupdate IN (1, 2,3)");
This is the code inside of the function

for example where is

Code:

    // If you selected to backup existing thread subscriptions this code will be exectued.
    if ($vbulletin->options['advanced_unsubscribe_link_thread_sub_backup'])
        {
        // Copies existing thread subscriptions to the unsub_subscribethread table.
          $db->query("
                    INSERT INTO " .TABLE_PREFIX. "unsub_subscribethread
                    SELECT NULL,
                          userid,
                          threadid,
                          emailupdate,
                          folderid,
                          canview
                    FROM " .TABLE_PREFIX. "subscribethread
                    WHERE userid = '$id'
                    AND emailupdate IN (1, 2, 3)");
        }

If I run this query in phpmyadmin it works ...

Code:

                    INSERT INTO unsub_subscribethread
                    SELECT NULL,
                          userid,
                          threadid,
                          emailupdate,
                          folderid,
                          canview
                    FROM subscribethread
                    WHERE userid = 1
                    AND emailupdate IN (1, 2, 3)



you havent registered the variable


$unsubscribe

here is an example of how to do so

$templater = vB_Template::create('unsubscribe');
$templater->register('$unsubscribe', $unsubscribe);
$template_hook[forumhome_wgo_pos2] .= $templater->render();

you will then need to call $unsubscribe in a template which will display the content from the query remembering to change the $template_hook

you will then need to place {vb:raw unsubscribe}
in template unsubscribe

as long as you place the correct hook location with the correct template hook the query will show in the hook location you selected

John Lester 11-06-2012 06:46 AM

1 Attachment(s)
Oh great now I'm even more confused ... this mod uses misc.php?do=unsubscribe as the url. In the mod a basic template is "built" and all of the other code executes fine (so far). I have a few more select queries structured like the one I posted earlier ... they seem to work just fine.

So now I'm wondering ... is the mod even executing those select queries? If it's working as is now (aside from the code in question) do I still need to tie it into a hook?

Keep in mind I'm a complete novice at this, all I'm doing is added options to an existing mod (that was marked as reusable and updated for 4.x by kh99).

Just for shits n giggles I'm going to attach what I have so far, if someone would be kind enough to look at it and tell me if there's a better way to go about doing this I might as well find out now and switch gears :D


All times are GMT. The time now is 06:24 PM.

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.02430 seconds
  • Memory Usage 1,894KB
  • 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
  • (17)bbcode_code_printable
  • (2)bbcode_php_printable
  • (9)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (27)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete