DragonPrime - LoGD Resource Community
Welcome Guest
  • Good afternoon, Guest.
    Please log in, or register.
  • May 20, 2013, 01:41:51 PM
Home Forums News Links Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
IRC Channels
Search

Pages: [1]   Go Down
  Print  
Author Topic: Staff List V2  (Read 371 times)
0 Members and 1 Guest are viewing this topic.
Eclypse ~ Xpert
Militia
**
Offline Offline

Posts: 75


View Profile
« on: August 10, 2012, 06:06:45 AM »

Hey there.

I'm relatively new to coding (I've only been able to make simple edits, really).

I am currently trying to edit the Staff List to the have a drop down box:

Code:
<?php
"position"=>"What position is is this user?,enum,0,Junior Moderator,1,Moderator,2,Senior Moderator,3,Junior Administrator,4,Administrator,5,Senior Administrator,6,None|6",
?>


The above works just fine.
However, based upon the position given (Jr. Mod, Mod, etc)
I want the rank (the number that decides how far up the list a Staffer is) to increase to a certain number based upon the position of the staff.
(Jr Mod being the lowest, Sr. Admin at the highest (Any position above can edit themselves to higher))

I can't seem to get it to work.. This is what I've been trying:

Code:
<?php
case "staffpositions":
if (get_module_userpref("position")) {
    if (module_userpref("position")) {
set_module_userpref("rank") = 10;
}
}else{}
break;
}
?>


Any help would be greatly appreciated! Smiley Remember, just learning xD
Logged

Senior Administrator, Coder, and Head of Staff

tynastera.com
isleofdarkness.com
Aeo
Mod God
*****
Offline Offline

Posts: 1079


Doctor.. Who?


View Profile WWW
« Reply #1 on: August 10, 2012, 06:21:13 AM »

However, based upon the position given (Jr. Mod, Mod, etc)
I want the rank (the number that decides how far up the list a Staffer is) to increase to a certain number based upon the position of the staff.
(Jr Mod being the lowest, Sr. Admin at the highest (Any position above can edit themselves to higher))

I can't seem to get it to work.. This is what I've been trying:

Code:
<?php
case "staffpositions":
if (get_module_userpref("position")) {
    if (module_userpref("position")) {
set_module_userpref("rank") = 10;
}
}else{}
break;
}
?>


To start with, this 'staffpositions'.. Where is the module hook for that?

And instead of:

Code:
<?php
if (get_module_userpref("position")) {
 if (
module_userpref("position")) {
set_module_userpref("rank") = 10;
?>

Try:

Code:
<?php
if (get_module_pref("position",$id)) {
 if (
get_module_pref("position",$id) == 1){
set_module_pref("rank",10,"ModuleNameRightHere",$id);
?>

Where $id is the Account ID of the user you're getting the module pref from.

I'm relatively new to coding (I've only been able to make simple edits, really).

We were all there once. xD I wish you luck in your adventures!
Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Eclypse ~ Xpert
Militia
**
Offline Offline

Posts: 75


View Profile
« Reply #2 on: August 10, 2012, 06:34:15 AM »

Thanks for the quick response! Smiley

I've tried what you've posted:

Code:
<?php
$sql 
"SELECT acctid from " db_prefix("accounts") . " where acctid=\"".$id."\"";
if (get_module_pref("position",$id)) {
if (get_module_pref("position",$id) == 1){
set_module_pref("rank",10,"stafflist",$id);
}
}
?>


Sadly, however, it did not work.
I haven't worked much with the sql code much, so maybe that is the problem?
The set_module_pref("rank") didn't increase either.
Logged

Senior Administrator, Coder, and Head of Staff

tynastera.com
isleofdarkness.com
Aeo
Mod God
*****
Offline Offline

Posts: 1079


Doctor.. Who?


View Profile WWW
« Reply #3 on: August 10, 2012, 06:44:50 AM »

The other option is this:

Set your preference $position to:

Code:
<?php
"position"=>"What position is is this user?,enum,0,None,1,Junior Moderator,2,Moderator,3,Senior Moderator,4,Junior Administrator,5,Administrator,6,Senior Administrator|0",
?>

I.E. So that the 'None' setting is set at 0.

Then try:

Code:
<?php
$mult 
get_module_pref("rank","stafflist",$id) * 10// Or whatever number you want this to be.
set_module_pref("rank",$mult,"stafflist",$id);
?>

Make sure you're getting $id correctly. Which, if you're in User Editor, it'd simply be:

Code:
<?php
$id 
httpget('id');
?>
Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Eclypse ~ Xpert
Militia
**
Offline Offline

Posts: 75


View Profile
« Reply #4 on: August 10, 2012, 02:50:08 PM »

Not really sure why the $mult is there. xD

But I did this:

Code:
<?php
$id 
httpget('id')
if (get_module_pref("position")) {
if (get_module_pref("position",1,$id)){
set_module_pref("rank",10,$id);
}
}
?>


Got an IF Error..

Seems like it doesn't increase the rank pref at all...

Thanks for your time!
Logged

Senior Administrator, Coder, and Head of Staff

tynastera.com
isleofdarkness.com
Aeo
Mod God
*****
Offline Offline

Posts: 1079


Doctor.. Who?


View Profile WWW
« Reply #5 on: August 10, 2012, 07:59:08 PM »

Not really sure why the $mult is there. xD

In case he wants to put something in between the 10 and the 20, or the 30 and the 40.. It was only an example. xD

But I did this:

Code:
<?php
$id 
httpget('id')
if (get_module_pref("position")) {
if (get_module_pref("position",1,$id)){
set_module_pref("rank",10,$id);
}
}
?>


Got an IF Error..

Seems like it doesn't increase the rank pref at all...

Because if you have a look at the third line:

Code:
if (get_module_pref("position",1,$id)){

with that ^, you're calling the module pref called 'position' from the module called '1'. Try:

Code:
if (get_module_pref("position","stafflist",$id)){
Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Afkamm
Mod God
*****
Offline Offline

Posts: 1563

MarcTheSlayer


View Profile WWW
« Reply #6 on: August 11, 2012, 02:40:21 AM »

The error is because there's no semicolon at the end of the 2nd line. You also have some other mistakes which wont produce errors, but just wont give any correct results.

It's important you know how functions get their arguments. Take get_module_pref()

If you go to the file /lib/modules.php and scroll down until you find the full function. Here are the first first lines of that.
Code:
<?php
function get_module_pref($name,$module=false,$user=false){
global $module_prefs,$mostrecentmodule,$session;
if ($module === false$module $mostrecentmodule;
if ($user===false) {
if(isset($session['user']['loggedin']) && $session['user']['loggedin']) $user $session['user']['acctid'];
else $user 0;
}

$name = The preference name. Must be entered.
$module = Name of the module. If left blank or false, then the current module name will be used.
$user = The acctid. If left blank then the acctid of the person currently running the code will be used.

If you're trying to get data from another player's preferences then it's important to include the module name or at the very least, FALSE, as that's what's expected before the acctid. Smiley

Code:
<?php
get_module_pref
('field'); // For this module for yourself. Module name and acctid are not needed.

get_module_pref('field'FALSE$acctid); // Get data from another player for current module.

get_module_pref('field''racehuman'$acctid); // Get data from another player for 'racehuman' module.


Hope this helps. Smiley
Logged

Eclypse ~ Xpert
Militia
**
Offline Offline

Posts: 75


View Profile
« Reply #7 on: August 11, 2012, 08:22:38 AM »

Thanks for your reply.

And yes, it did help with my understanding of the get_module_pref function. Smiley

I think my only problem is getting the "position" and then based upon the position changing the "rank" pref.

Code:
<?php
$id 
httpget('id')
if (get_module_pref("position"FALSE$id) = 1){
(set_module_pref("rank",10,"stafflist",$id));
}

The first line is getting the "position" pref 1 (which is Junior Mod position) and the second line is setting the module pref "rank" to 10..

At least, that's what I'm trying to do LOL



Logged

Senior Administrator, Coder, and Head of Staff

tynastera.com
isleofdarkness.com
Aeo
Mod God
*****
Offline Offline

Posts: 1079


Doctor.. Who?


View Profile WWW
« Reply #8 on: August 11, 2012, 08:39:33 AM »

Regarding your code:
Code:
<?php
$id 
httpget('id')
if (get_module_pref("position"FALSE$id) = 1){
(set_module_pref("rank",10,"stafflist",$id));
}

The first line is getting the "position" pref 1 (which is Junior Mod position) and the second line is setting the module pref "rank" to 10..

Don't use:
Code:
<?php
if (get_module_pref("position"FALSE$id) = 1){
?>

Use:
Code:
<?php
if (get_module_pref("position"FALSE$id) == 1){
?>

A single equals sign is used to assign a variable. (For example, $turnip = 13.) A double equals sign is used to check if a value is equal to the second value (For example, if ($turnip == 13)).
« Last Edit: August 11, 2012, 08:43:30 AM by Aeolus » Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Eclypse ~ Xpert
Militia
**
Offline Offline

Posts: 75


View Profile
« Reply #9 on: August 11, 2012, 08:49:00 AM »

Ah, fixed that. Thank you, again. Tongue

I keep getting this error, no matter what I edit:

Code:
Parse error: syntax error, unexpected T_IF in /home/a2312790/public_html/modules/stafflist.php on line 89

My code is now:

Code:
$id = httpget('id')
if (get_module_pref("position", FALSE, $id) == 1){
(set_module_pref("rank",10,"stafflist",$id));
}
Logged

Senior Administrator, Coder, and Head of Staff

tynastera.com
isleofdarkness.com
Aeo
Mod God
*****
Offline Offline

Posts: 1079


Doctor.. Who?


View Profile WWW
« Reply #10 on: August 11, 2012, 08:58:44 AM »

I'd remove the brackets around the line with the set_module_pref in it as well. And which line is line 89? Do you have any other code before that section of code?

* Edit: You need a semi-colon ( ; ) at the end of the line before the 'if' statement. i.e.:

Code:
$id = httpget('id')

Should be:

Code:
$id = httpget('id');

You need semi-colons at the end of every line. (If it's not an if, for, while, etc loop/statement.)
« Last Edit: August 11, 2012, 10:03:54 AM by Aeolus » Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Eclypse ~ Xpert
Militia
**
Offline Offline

Posts: 75


View Profile
« Reply #11 on: August 11, 2012, 10:17:45 AM »

Just cleaned it up a little bit..

This is the entire run function..

Code:
<?php
page_header
("Staff List");
global $session;

$from=httpget('from');
if ($from=="about"){
addnav("Return where you came","about.php");
}elseif ($from=="village"){
villagenav();
}

      
$sql "SELECT p1.userid, (p1.value+0) AS rank, p2.value AS sposition , p3.value AS rang , u.name, u.login, u.sex, u.laston, u.loggedin FROM ".db_prefix("accounts")." as u, ".db_prefix("module_userprefs")." as p1, ".db_prefix("module_userprefs")." as p2, ".db_prefix("module_userprefs")." as p3 WHERE (p1.value+0) > 0 AND p1.modulename='stafflist' AND p1.setting='rank' AND p1.userid=u.acctid AND p2.modulename='stafflist' AND p2.setting='position' AND p2.userid=u.acctid AND p3.modulename='stafflist' AND p3.setting='rang' AND p3.userid=u.acctid ORDER BY rank DESC, u.acctid ASC";
$result db_query_cached($sql"stafflist"100);
$count db_num_rows($result);

output("`c`b`@Staff List`0`b`c`n`n");

$id httpget('id')
if (get_module_pref("position",FALSE,$id) == 1){
(set_module_pref("rank","stafflist",10,$id));
}

if ($count>0){
$hname translate_inline("Name");
$hposition translate_inline("Position");
$hon translate_inline("Online");

rawoutput("<center>");
rawoutput("<table border='0' cellpadding='2' cellspacing='1' bgcolor='#999999'>");
rawoutput("<tr class='trhead'><td>$hname</td><td>$hposition</td><td>$hon</td>");
rawoutput("</tr>");
for($i=0;$i<$count;$i++){
$row db_fetch_assoc($result);
rawoutput("<tr class='".($i%2?"trdark":"trlight")."'><td>");
output_notl("`&%s`0"$row['name']);
output_notl("`#%s`0"$row['position']);
rawoutput("</td><td align='center'>");
$loggedin=(date("U") - strtotime($row['laston']) <
getsetting("LOGINTIMEOUT",900) && $row['loggedin']);
$on=translate_inline($loggedin?"`@Yes`0":"`\$No`0");
output_notl("%s",$on);
rawoutput("</td></tr>");
}
rawoutput("</table>");
rawoutput("</center>");
}else{
output("`c`@This server appears to not have any staff.");
output("Most likely, no one has been added to this list yet.`c");
}

$blurb=get_module_setting("blurb");
output_notl("`n`n`c`@%s`0`c"$blurb);
page_footer();
}
?>
Logged

Senior Administrator, Coder, and Head of Staff

tynastera.com
isleofdarkness.com
Aeo
Mod God
*****
Offline Offline

Posts: 1079


Doctor.. Who?


View Profile WWW
« Reply #12 on: August 11, 2012, 10:55:52 AM »

Take note of the edit I made to my last post.

* Edit: You need a semi-colon ( ; ) at the end of the line before the 'if' statement. i.e.:

Which Afkamm also mentioned earlier..

The error is because there's no semicolon at the end of the 2nd line.

And if the assignment of $id is simply in the run function, I'd personally use:

Code:
$id = $session['user']['acctid'];
« Last Edit: August 11, 2012, 10:59:57 AM by Aeolus » Logged


Time Lords Online - A Doctor Who RPG! Open Now!
~ My Modules: PM me if you'd like me to code something! Smiley ~
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Play LoGD on Dragonprime

Support Us
$100 raised this year
Your help is greatly appreciated!
Who's Online
19 Guests, 0 Users
DragonPrime LoGD
Recent Topics
Home Forums News Links Downloads Login Register Advanced Search