DragonPrime - LoGD Resource Community

Coding Support => Coding Support Desk => Topic started by: Megan|SaraBeth on May 19, 2018, 11:53:12 PM



Title: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Megan|SaraBeth on May 19, 2018, 11:53:12 PM
I want each of the tabs other than the MOTD one, which I have called Kinks, to turn red when there is a new one. I tried to get help and it just didnt work and the person swears it will work this way and its not. I have tested it multiple times. I'll put the code below and someone can tell me where we messed up. Thanks!

Code:
$a=translate_inline("Kinks");
$b=translate_inline("Contests & Events");
$c=translate_inline("Polls");

if ($session['needtoviewcontest'] == 1)
$highlight_contests = "<a href='motd.php?op=contest' style='color:red'>$b</a>";
else
$highlight_contests = "<a href='motd.php?op=contest'>`r$b</a>";

if ($session['user']['needtoviewpolls'] == 1)
$highlight_polls = "<a href='motd.php?op=poll' style='color:red'>$c</a>";
else
$highlight_polls = "<a href='motd.php?op=poll'>`L$c</a>";

if ($session['user']['needtoviewchangelog'] == 1)
$changelog = "<a href='motd.php?op=changelog' style='color:red'>Server Updates/Enhancements</a>";
else
$changelog = "<a href='motd.php?op=changelog'>`4Server Updates/Enhancements</a>";

output("<center><big><a href='motd.php'>`5$a</a> | $highlight_contests | $highlight_polls | $changelog</big></center><br>",true);


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Aeolus on May 20, 2018, 01:17:19 AM
You're using to $session['needtoviewcontest'], $session['user']['needtoviewpolls'] and $session['user']['needtoviewchangelog'] check if you need to highlight the links.

Do these variables exist? Do needtoviewpolls and needtoviewchangelog exist in the accounts table, and therefore the $session['user'] array? Are you setting $session['needtoviewcontest']? How?


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Stephen.Kise on May 20, 2018, 08:07:03 AM
I want each of the tabs other than the MOTD one, which I have called Kinks, to turn red when there is a new one. I tried to get help and it just didnt work and the person swears it will work this way and its not. I have tested it multiple times. I'll put the code below and someone can tell me where we messed up. Thanks!

Code:
$a=translate_inline("Kinks");
$b=translate_inline("Contests & Events");
$c=translate_inline("Polls");

if ($session['needtoviewcontest'] == 1)
$highlight_contests = "<a href='motd.php?op=contest' style='color:red'>$b</a>";
else
$highlight_contests = "<a href='motd.php?op=contest'>`r$b</a>";

if ($session['user']['needtoviewpolls'] == 1)
$highlight_polls = "<a href='motd.php?op=poll' style='color:red'>$c</a>";
else
$highlight_polls = "<a href='motd.php?op=poll'>`L$c</a>";

if ($session['user']['needtoviewchangelog'] == 1)
$changelog = "<a href='motd.php?op=changelog' style='color:red'>Server Updates/Enhancements</a>";
else
$changelog = "<a href='motd.php?op=changelog'>`4Server Updates/Enhancements</a>";

output("<center><big><a href='motd.php'>`5$a</a> | $highlight_contests | $highlight_polls | $changelog</big></center><br>",true);

You don't have an opening tag. PHP requires <?php at the start of each page. As Aeolus has said, there is probably an accounts table issue. There seems to be some confusion here as to what you are trying to do, between your developers. The status of the polls and changelogs is stored on the account, but the contest status is stored in the session. This would mean that the contest is probably changing with each login. There are no setters here for any of the contests, polls, or changelogs here - so we cannot help you properly. You need to include the other parts of this code, because this is clearly not where the issue lies, except for maybe the $session['needtoviewcontest'] not being a saved variable.

Also, it seems as if the changelog will be perpetually red, since the LotGD color code for red is `4 and you have style='color:red' in the if statement.


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Megan|SaraBeth on May 20, 2018, 12:56:27 PM
To better answer all questions I have attached both the main folder motd file and the lib folder one. Please point me to where we went wrong.


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Aeolus on May 21, 2018, 02:50:04 AM
To better answer all questions I have attached both the main folder motd file and the lib folder one. Please point me to where we went wrong.

We've already told you. TL;DR: You're not setting the session variables, differing in that some of which are session variables and some of which are account variables (why they are session/account variables in the first place, I don't know), and you're setting the changelog to `4 (red) if there's no changes to view.


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Megan|SaraBeth on May 22, 2018, 04:35:23 AM
So how would I set the variables to fix this? I tried other things to fix it like copying how the pageparts did it for the main MoTD link on the page header and changing the link appropriately and that didnt work. I also tried adding global $session and that didnt work.


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Aeolus on May 22, 2018, 07:31:51 AM
You need to understand what you're doing. You can't code by trial and error, and copying. That's how you break things and end up with terrible code.

You need a pref or an accounts parameter that gets set to false for everyone whenever a new item is posted. If it's false for you, it turns red. You can then set it to true when it's viewed.

Do $session['needtoviewcontest'], $session['user']['needtoviewpolls'] and $session['user']['needtoviewchangelog'] exist? Do the variables themselves exist, as well as in the accounts table (for the latter two)?


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Megan|SaraBeth on May 22, 2018, 01:17:01 PM
If you saw the code you would see in each case that this code is there.

$session['user']['needtoviewcontest']=false;

The only one its not there for is the changelog. The changelog case has this.

$session['user']['seenupdates'] = TRUE;

As for the latter, the only user account thing in changelog is for pulling the poster's name just like in the lib file all the user things are for who the poster is. With the polls this is the only user account thing.

$session['user']['lastmotd']=$row['motddate'];


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Aeolus on May 22, 2018, 05:50:20 PM
Wow, I'm confused... You have both $session['needtoviewcontest'] and $session['user']['needtoviewcontest']? And opposing "need to view" and "have seen" variables? What happened to consistency...

When are those updated to the OTHER case? When is needtoviewcontest set to true, and seenupdates set to false? If those parameters aren't in the accounts table, then how do they exist in $session['user']?


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Megan|SaraBeth on May 24, 2018, 08:15:57 PM
Contests and polls are set to true with this in their respective spots in the lib/motd.php

db_query("UDPATE accounts SET needtoviewcontest=1");

Seenupdates is not set to false and I wouldnt know where to set it.  Im thinking the first $session without ['user'] needs it. Im lost really as how to fix this.


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Stephen.Kise on May 26, 2018, 11:08:14 AM
Seenupdates is not set to false and I wouldnt know where to set it.  Im thinking the first $session without ['user'] needs it. Im lost really as how to fix this.

The status of the polls and changelogs is stored on the account, but the contest status is stored in the session. [...] maybe the $session['needtoviewcontest'] not being a saved variable.


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Megan|SaraBeth on May 26, 2018, 03:40:16 PM
After looking at the code and taking into account what y'all said, We have found that my db prefix was missing and there was a spelling error. It has been fixed now. Thank you for the guidance.


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Aeolus on May 26, 2018, 05:05:41 PM
You're welcome. Still doesn't explain why you're using $session['needtoviewcontest'] instead of $session['user']['needtoviewcontest'].


Title: Re: Tabs on MOTD Header To Turn Red When New MOTD
Post by: Megan|SaraBeth on May 26, 2018, 07:17:58 PM
Its been changed to that as well.

© 2018 DragonPrime - LoGD Resource Community
Email Talisman: talisman -at- gmail.com
&oeXs)2U7=V BmܲV.U e=;p\}eG )Jj} C5EH7ˤH=j } mo|*Ŋw{drV_@IV>/- TFQJ׀̀Ve}l1,V O iNYx͘$e$;
Forums: Powered by SMF 1.1.21 | SMF © 2006-2007, Simple Machines