1
ralf57
Need a little help from modules developers
  • 2004/2/22 18:56

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Hi devs,
i'm tryin'g to port the "tplleaguestats" script into xoops.
I think that it wouldn't be difficult for an experienced coder but i'm a beginner
I faced two big problems:

1)Thew whole scipt(expecially the admin section) uses php sessions for admin authentication and this doesn't agree with XOOPS modules management.

Do i have to bypass or delete the sessions at all?
And if so,how can i do this?


2)The script retreives the MySQL connection data from a file on the server(user.php):
-----------------------
$host = 'localhost';
$user = 'root';
$password = '';
$txt_db_name = 'databasename';
----------------------

How can i change this and force the script to
retrieve the data from XOOPS database?

I know that these are annoing questions but very important for my work to go on.
Thanks in advance.

2
Mithrandir
Re: Need a little help from modules developers

On all pages include mainfile.php in the top and footer.php in the bottom and use the $xoopsUser functionality to determine whether a user is logged in or not.

Change all database queries to go through $xoopsDB->query instead of through the original method.

See how the existing modules are structured and go from there.

GL

3
ralf57
Re: Need a little help from modules developers
  • 2004/2/22 21:03

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Thank you mith,
i've understood what you said and i'll follow your suggestions.
I have another practical thing to ask you:
Please take a look at this piece of code and give me
a short explain and (possibly) tell me how can i move on...

__________________________________
//this piece stands in almost all the pages,
//and loads the db connection data.Can i delete it?
//

session_start();

include('admin/user.php');
$connection = mysql_connect("$host","$user","$password")
or die(mysql_error());
mysql_select_db("$txt_db_name",$connection)
or die(mysql_error());

//
//Includes preferences
//
$pref = mysql_query("SELECT * FROM tplls_preferences WHERE ID = '1'",$connection)
or die(mysql_error());
$pdata = mysql_fetch_array($pref);
mysql_free_result($pref);

$team_name = $pdata['teamname'];
$d_seasonid = $pdata['defaultseasonid'];
$show_all_or_one = $pdata['defaultshow'];
$show_table = $pdata['defaulttable'];
$language = $pdata['defaultlanguage'];
$for_win = $pdata['forwin'];
$for_draw = $pdata['fordraw'];
$for_lose = $pdata['forloss'];
$print_date = $pdata['printdate'];
$top_bg = $pdata['topoftable'];
$bg1 = $pdata['bg1'];
$bg2 = $pdata['bg2'];
$inside_c = $pdata['inside'];
$border_c = $pdata['bordercolour'];
$tb_width = $pdata['tablewidth'];
$accept_ml = $pdata['acceptmultilanguage'];

//
//Query to get last updated date and time
//
//Use site http://www.mysql.com/doc/en/Date_and_time_functions.html (DATE_FORMAT)
//to return date format that fits to your site
//
$updated_query = mysql_query("
SELECT DATE_FORMAT(last_updated, '%d.%m.%Y at %H:%i') AS last_updated FROM tplls_preferences WHERE ID = '1'", $connection)
or die(mysql_error());
$ludata = mysql_fetch_array($updated_query);
$last_update = $ludata['last_updated'];
mysql_free_result($updated_query);

//
//If session variables are registered
//What are these session variables?Are they necessary?

if(!session_is_registered('defaultlanguage') || !session_is_registered('defaultseasonid') || !session_is_registered('defaultshow') || !session_is_registered('defaulttable'))
{
$_SESSION['defaultlanguage'] = $language;
$_SESSION['defaultseasonid'] = $d_seasonid;
$_SESSION['defaultshow'] = $show_all_or_one;
$_SESSION['defaulttable'] = $show_table;
$defaultlanguage = $_SESSION['defaultlanguage'];
$defaultseasonid = $_SESSION['defaultseasonid'];
$defaultshow = $_SESSION['defaultshow'];
$defaulttable = $_SESSION['defaulttable'];
}
else
{
$defaultlanguage = $_SESSION['defaultlanguage'];
$defaultseasonid = $_SESSION['defaultseasonid'];
$defaultshow = $_SESSION['defaultshow'];
$defaulttable = $_SESSION['defaulttable'];
}

//
//Gets seasons and match types for dropdowns
//How can i replace this query with the XOOPS one?

$get_seasons = mysql_query("SELECT * FROM tplls_seasonnames WHERE SeasonPublish = '1' ORDER BY SeasonName",$connection)
or die(mysql_error());

//
//Sort by points, sort variable is not set
//
$sort = $_REQUEST['sort'];
if(!isset($sort))
{
$sort = 'pts';
}


?>

//
//INCLUDES HEADER.PHP
//
include('header.php');

//
//Includes languages
//
include('language.inc');

?>



___________________________________

I hope i won't bore you...
thanks again.

4
Mithrandir
Re: Need a little help from modules developers

OK, let's take a look
Quote:

// session_start();

//this is done in xoops, so what you want to do is just include the mainfile.php - I assume that this file is in a root/modules/somename folder

include ('../../mainfile.php');

//
//Includes preferences

//This is done automatically with a proper module, so let's take that afterwards

$updated_query = $xoopsDB->query("
SELECT DATE_FORMAT(last_updated, '%d.%m.%Y at %H:%i') AS last_updated FROM tplls_preferences WHERE ID = '1'");
$ludata = $xoops->fetchArray($updated_query);
$last_update = $ludata['last_updated'];
mysql_free_result($updated_query);

//
//If session variables are registered
//What are these session variables?Are they necessary?

//We'll deal with them as with the preferences or something

//Gets seasons and match types for dropdowns
//How can i replace this query with the XOOPS one?

$get_seasons = $xoopsDB->query("SELECT * FROM tplls_seasonnames WHERE SeasonPublish = '1' ORDER BY SeasonName");

//
//Sort by points, sort variable is not set
//
$sort = $_REQUEST['sort'];
if(!isset($sort))
{
$sort = 'pts';
}
//
//INCLUDES HEADER.PHP
//
include(XOOPS_ROOT_PATH.'/header.php');

//
//Includes languages - this is unnecessary
//

?>




I'll reply in a minute with the module structure

5
ralf57
Re: Need a little help from modules developers
  • 2004/2/22 22:30

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Thank you,in the meantime i'm going to apply the code you edited...

6
ralf57
Re: Need a little help from modules developers
  • 2004/2/22 23:08

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Hi mith,i've edited the file.
Now i have:
__________________

//session_start();

//include('admin/user.php');
//$connection = mysql_connect("$host","$user","$password")
//or die(mysql_error());
//mysql_select_db("$txt_db_name",$connection)
//or die(mysql_error());

include ('../../mainfile.php');

//
//Includes preferences
//
$pref = mysql_query("SELECT * FROM xoops_myleague_preferences WHERE ID = '1'")
or die(mysql_error());
$pdata = mysql_fetch_array($pref);
mysql_free_result($pref);

$team_name = $pdata['teamname'];
$d_seasonid = $pdata['defaultseasonid'];
$show_all_or_one = $pdata['defaultshow'];
$show_table = $pdata['defaulttable'];
$language = $pdata['defaultlanguage'];
$for_win = $pdata['forwin'];
$for_draw = $pdata['fordraw'];
$for_lose = $pdata['forloss'];
$print_date = $pdata['printdate'];
$top_bg = $pdata['topoftable'];
$bg1 = $pdata['bg1'];
$bg2 = $pdata['bg2'];
$inside_c = $pdata['inside'];
$border_c = $pdata['bordercolour'];
$tb_width = $pdata['tablewidth'];
$accept_ml = $pdata['acceptmultilanguage'];

//
//Query to get last updated date and time
//
//Use site http://www.mysql.com/doc/en/Date_and_time_functions.html (DATE_FORMAT)
//to return date format that fits to your site
//

$updated_query = $xoopsDB->query("
SELECT DATE_FORMAT(last_updated, '%d.%m.%Y at %H:%i') AS last_updated FROM xoops_myleague_preferences WHERE ID = '1'");
$ludata = $xoops->fetchArray($updated_query);
$last_update = $ludata['last_updated'];
mysql_free_result($updated_query);

//
//If session variables are registered
//
if(!session_is_registered('defaultlanguage') || !session_is_registered('defaultseasonid') || !session_is_registered('defaultshow') || !session_is_registered('defaulttable'))
{
$_SESSION['defaultlanguage'] = $language;
$_SESSION['defaultseasonid'] = $d_seasonid;
$_SESSION['defaultshow'] = $show_all_or_one;
$_SESSION['defaulttable'] = $show_table;
$defaultlanguage = $_SESSION['defaultlanguage'];
$defaultseasonid = $_SESSION['defaultseasonid'];
$defaultshow = $_SESSION['defaultshow'];
$defaulttable = $_SESSION['defaulttable'];
}
else
{
$defaultlanguage = $_SESSION['defaultlanguage'];
$defaultseasonid = $_SESSION['defaultseasonid'];
$defaultshow = $_SESSION['defaultshow'];
$defaulttable = $_SESSION['defaulttable'];
}

//
//Gets seasons and match types for dropdowns
//

$get_seasons = $xoopsDB->query("SELECT * FROM xoops_myleague_seasonnames WHERE SeasonPublish = '1' ORDER BY SeasonName");

//
//Sort by points, sort variable is not set
//
$sort = $_REQUEST['sort'];
if(!isset($sort))
{
$sort = 'pts';
}


?>

//
//INCLUDES HEADER.PHP
//
include(XOOPS_ROOT_PATH.'/header.php');

//
//Includes languages
//
//include('language.inc');

?>


______________________________________

Notice that i've added

"include ('../../footer.php');"

just before the end of file,was i right?



Btw i turned xoops's php debug on and it gives:
______________________
"Fatal error: Call to a member function on a non-object in c:\programmi\easyphp\www\xoops\modules\simpnews\index.php on line 75"
________________

Line 75 is:
_____________________
$ludata = $xoops->fetchArray($updated_query);
_______________________

Now remain the "includes preferences" and "session variables" matter;
what about this?

I stay tuned...


7
Mithrandir
Re: Need a little help from modules developers

$xoopsDB->fetchArray - not $xoops->fetchArray

It'll have to wait until tomorrow or Tuesday (very busy day tomorrow) before I can get back to you on the preferences thing, but look at an existing module's xoops_version.php - I recommend the news module, because it has a lot of comments explaining how the lines work.

It'll also require some re-thinking since your script seems to be able to remember the user's own preferences, but let's take that when we get to it.

What you should do, however, is to first get the xoops_version.php to work properly, so you can install the module through the administration menu.

For that to work, you mainly need to get the tables listed in a xoops_version.php file in your module's folder.

After that, you should weed out any mysql_xxxx function calls and change them to use the $xoopsDB->query and $xoopsDB->fetchArray functions instead.

So let's take it from there.

8
ralf57
Re: Need a little help from modules developers
  • 2004/2/22 23:29

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


thank you precious helper...
i'll follow your recommendations
and report any results to you tomorrow evening or tuesday at later.
good night.

9
Mithrandir
Re: Need a little help from modules developers

I'll have to wait until tomorrow before looking at this, sorry. (23 PM here and I need to go to bed rather early today - got way too little sleep last night)

10
ralf57
Re: Need a little help from modules developers
  • 2004/2/23 22:30

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Quote:

Mithrandir wrote:
I'll have to wait until tomorrow before looking at this, sorry. (23 PM here and I need to go to bed rather early today - got way too little sleep last night)


Ok,goodnight.
I'll be waiting 'til tomorrow too.

Login

Who's Online

1178 user(s) are online (58 user(s) are browsing Support Forums)


Members: 0


Guests: 1178


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits