Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

php + once-per-session cookie issue

php + once-per-session cookie issue

Hi, I'm trying to create a module that will show when someone is within 30 days of their expiration date in CBsubs.  CBsubs doesn't have this feature, so until they do, I want to build it with meta_mod.

This is my query:

Code:

<?php   


$ user = & JFactory::getUser();
$ db = & JFactory::getDBO();

$ query = "SELEC T b.expiry_date
  from #__cbsubs_subscriptions as b
  left join #__comprofiler as b on a.user_id = b.user_id
  where b.user_id=$user->id";

$ db->setQuery( $query );
$ result = $db->loadObjectList();

?>

It will find the expiry_date of the person logged in and set it as a variable.  I then need to have an if/then statement to show this text if the date is <30 days away: "Your membership expires on <expiry_date>! Click here to renew."  or "Your membership expires in <x> days!..."

Then use this code to show it once per session:

Code:

session_start();

$instance_name = "cbsubs_expiring";
if (!isset($_SESSION[$instance_name]) ||
$_SESSION[$instance_name] == false) {
$_SESSION[$instance_name] = true;

return 101;
}

Any help is appreciated.  I'll post what we find here on CBsubs pages where it will get a lot of use.

Edited By: thepiston
15-Feb-12 20:43:18

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: php + once-per-session cookie issue

Ok, try this. I've changed the loadObjectList to just loadResult, assuming that they only have one subscription?


if ($user->id > 0 ) {
  $db = & JFactory::getDBO();

  $query = "SELEC" . "T b.expiry_date
    from #__cbsubs_subscriptions as b
    left join #__comprofiler as a on a.user_id = b.user_id
    where b.user_id=" . (int)$user->id;

  $db->setQuery( $query );
  $result = $db->loadResult(); // prob in form 2010-08-03 00:41:21

  $target_ts = strtotime($result);
  $days_to_go = (int) (($target_ts - time()) / (24*60*60));

  if ($days_to_go < 30) {
    session_start();
    $instance_name = "cbsubs_expiring";
    if (!isset($_SESSION[$instance_name]) ||
      $_SESSION[$instance_name] == false) {

      $_SESSION[$instance_name] = true;
      $target_date = date("d/m/Y",$target_ts);
      $message = "Your membership expires on $target_date! Click here to renew."; // add a hyperlink
      echo $message;
    }
  }
}


In this case we're just displaying some text in a module, rather than MetaMod pulling in another module. But you could still pull in another module by returning a module id after displaying the message.

I haven't tested this but it looks like you can code PHP, so at least this will get you started.

Best regards,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: php + once-per-session cookie issue

cool, I'll try it soon.  The $result I think is a string though - does that matter?

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: php + once-per-session cookie issue

Yes, when you use loadResult() then it will be a string. The original example returned an array. In the example I am assuming that there's only one subscription, so a single returned string is what I would expect.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1666
Total Polls:
6
Total Posts:
5909
Dormant:
User Info:
 
Total Users:
10095
Newest User:
johnson58
Members Online:
0
Guests Online:
86

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked