Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Seeking applications ...
Author Message
kenno
Worker
Worker



Joined: Jul 26, 2009
Posts: 117
Location: Scunthorpe, UK

PostPosted: Thu Dec 15, 2011 3:02 pm Reply with quote

Can anyone help with what I am hoping is a simple task for an experienced coder.

I have a block what I want to use on my site which advises members who are in a particular group of there member number and expiry time, as written below.

Quote:
My membership number
967

You are a paid member of the site

Your membership will expire in:

4 days


The problem is the member number is added manually and sometimes can take a few days to be added so users ask immediately they have no number.
The results in that number area is blank until the number is added, I am wanting to add a generic comment in there when there is no number present but as soon as a number is added for it the comment not to show and just have the number.


Code:
<?php


/************************************************************************/
/* PHP-NUKE: Web Portal System                                          */
/* ===========================                                          */
/*                                                                      */
/* Copyright (c) 2001 by Francisco Burzi (fbc@mandrakesoft.com)         */
/* http://phpnuke.org                                                   */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/************************************************************************/
/* Additional code clean-up, performance enhancements, and W3C and      */
/* XHTML compliance fixes by Raven and Montego.                         */
/************************************************************************/

if ( !defined('BLOCK_FILE') ) {
    Header('Location: ../index.php');
    die();
}

global $prefix, $db, $sitename, $subscription_url, $user, $cookie, $nukeurl, $user_prefix;

if (paid()) {
    cookiedecode($user);
   
   
   //set user number
   $content = '';
   $sql_user_num = "SELECT user_member_membernumber FROM ".$user_prefix."_users WHERE user_id='".intval($cookie[0])."'";
   $result_user_num = $db->sql_query($sql_user_num);
   $row_user_num = $db->sql_fetchrow($result_user_num);
   
   $content .= '<center>My membership number<br><strong>'.$row_user_num['user_member_membernumber'].'</strong></center><br>';
   
   
    $sql = 'SELECT * FROM '.$prefix.'_subscriptions WHERE userid='.intval($cookie[0]);
    $query = $db->sql_query($sql);
    $row = $db->sql_fetchrow($query);
    if (!empty($subscription_url)) {
        $content .= '<center>'._YOUARE.' a <a href="'.$subscription_url.'">'._PAIDMEMBER.'</a> '._OF.' '.$sitename.'<br />';
    } else {
        $content .= '<center>'._YOUARE.' a '._PAIDMEMBER.' '._OF.' '.$sitename.'<br />';
    }


    // $diff = $row['subscription_expire']-time();
    // $yearDiff = floor($diff/60/60/24/365);
    // $diff -= $yearDiff*60*60*24*365;
    // if ($yearDiff < 1) {
    //     $diff = $row['subscription_expire']-time();
    // }
    // $daysDiff = floor($diff/60/60/24);
    // $diff -= $daysDiff*60*60*24;
    // $hrsDiff = floor($diff/60/60);
    // $diff -= $hrsDiff*60*60;
    // $minsDiff = floor($diff/60);
    // $diff -= $minsDiff*60;
    // $secsDiff = $diff;
    // if ($yearDiff < 1) {
    //      $rest = $daysDiff.' '._SBDAYS.'<br />'.$hrsDiff.' '._SBHOURS.'<br />'.$minsDiff.' '._SBMINUTES.'<br />'.$secsDiff.' '._SBSECONDS;
    // } elseif ($yearDiff == 1) {
    //      $rest = $yearDiff.' '._SBYEAR.'<br />'.$daysDiff.' '._SBDAYS.'<br />'.$hrsDiff.' '._SBHOURS.'<br />'.$minsDiff.' '._SBMINUTES.'<br />'.$secsDiff.' '._SBSECONDS;
    // } elseif ($yearDiff > 1) {
    //      $rest = $yearDiff.' '._SBYEARS.'<br />'.$daysDiff.' '._SBDAYS.'<br />'.$hrsDiff.' '._SBHOURS.'<br />'.$minsDiff.' '._SBMINUTES.'<br />'.$secsDiff.' '._SBSECONDS;
    // }
    // $content .= '<br /><b>'._PAIDMEMBEREXPIREIN.'<br /><br /><font color="#FF0000">'.$rest.'</font></b></center>';

    $diff = $row['subscription_expire']-time();
    $yearDiff = floor($diff/60/60/24/365);
    $diff -= $yearDiff*60*60*24*365;
    if ($yearDiff < 1) {
        $diff = $row['subscription_expire']-time();
    }
    $daysDiff = floor($diff/60/60/24);
    $diff -= $daysDiff*60*60*24;
    $hrsDiff = floor($diff/60/60);
    $diff -= $hrsDiff*60*60;
    $minsDiff = floor($diff/60);
    $diff -= $minsDiff*60;
    $secsDiff = $diff;
    if ($yearDiff < 1) {
         $rest = $daysDiff.' '._SBDAYS.'<br />'.$hrsDiff.' '._SBHOURS.'<br />'.$minsDiff.' '._SBMINUTES.'<br />'.$secsDiff.' '._SBSECONDS;
     } elseif ($yearDiff == 1) {
         $rest = $yearDiff.' '._SBYEAR.'<br />'.$daysDiff.' '._SBDAYS.'<br />'.$hrsDiff.' '._SBHOURS.'<br />'.$minsDiff.' '._SBMINUTES.'<br />'.$secsDiff.' '._SBSECONDS;
    } elseif ($yearDiff > 1) {
         $rest = $yearDiff.' '._SBYEARS.'<br />'.$daysDiff.' '._SBDAYS.'<br />'.$hrsDiff.' '._SBHOURS.'<br />'.$minsDiff.' '._SBMINUTES.'<br />'.$secsDiff.' '._SBSECONDS;
    }
   
   if($yearDiff >1 or $yearDiff ==1)
   {
    $content .= '<br /><b>'._PAIDMEMBEREXPIREIN.'<br /><br /><font color="#FF0000">'.$yearDiff.' years</font></b></center>';      
   }else{
    $content .= '<br /><b>'._PAIDMEMBEREXPIREIN.'<br /><br /><font color="#FF0000">'.$daysDiff.' days</font></b></center>';
   }

} else {
    if (empty($subscription_url)) { //RN - if this is empty, it creates a XHTML validation issue
        $temp_url = $nukeurl;
    } else {
        $temp_url = $subscription_url;
    }
    $content .= '<center>'._NOTSUB.' '.$sitename.' '._SUBFROM.' <a href="'.$temp_url.'">'._HERE.'</a> '._NOW.'</center>';
}

?>


Any help or pointers in the right direction would be greatly appreciated

Thanks Mark
 
View user's profile Send private message
fkelly
Former Moderator in Good Standing



Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Fri Dec 16, 2011 8:01 am Reply with quote

Just do an is_empty on $row_user_num['user_member_membernumber']. If it's empty then change what you load into $content for that member. Something like:

[code] if(empty)$row_user_num['user_member_membernumber'])) {
$content = 'You don't have a user number yet, please check back in a few days' } else {$content = ... }

It appears you've modified the user table. You will have to take care with upcoming upgrades of RN. Generally I would recommend creating a separate table along the lines of usernumber table which would just have the fields username and usernumber. That way any upgrades would not affect it. I realize the horse may be out of that barn by now and your approach should work, it just makes upgrades a bit dicier.
 
View user's profile Send private message Visit poster's website
Guardian2003
Site Admin



Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam

PostPosted: Fri Dec 16, 2011 10:01 am Reply with quote

Or instead of using the empty() function you could use
Code:


if ($row_user_number['user_member_membernumber'] >0 ) {
$content .= 'fail message';
} else {
$content .= 'the membership number';
}

This is assuming that your using an auto-increment field or 1 is the lowest number
 
View user's profile Send private message Send e-mail
fkelly







PostPosted: Fri Dec 16, 2011 10:12 am Reply with quote

Userid is already set as the primary key and auto incremented in the users table. So I don't think the new user_member_membernumber field could also be auto-increment. Still, you would want to check what values are in there. If you are storing something else besides null or zero when the field is empty then the empty function won't work. Use some other kind of test ... the concept is the same, if the field hasn't been set put a message into the $content variable.
 
kenno







PostPosted: Fri Dec 16, 2011 5:06 pm Reply with quote

fkelly wrote:
Just do an is_empty on $row_user_num['user_member_membernumber']. If it's empty then change what you load into $content for that member. Something like:

Code:
 if(empty)$row_user_num['user_member_membernumber'])) {

$content = 'You don't have a user number yet, please check back in a few days' } else {$content = ... }


It appears you've modified the user table. You will have to take care with upcoming upgrades of RN. Generally I would recommend creating a separate table along the lines of usernumber table which would just have the fields username and usernumber. That way any upgrades would not affect it. I realize the horse may be out of that barn by now and your approach should work, it just makes upgrades a bit dicier.


Thanks for your replies guys, I appreciate it.

Yes the user tables had already been modified when I started helping this site out and moved it across from php-nuke with the help of a friend.
We may have to look into creating a seperate table for the number, will have to see how we get on with upgrading to 2.5 when it is released.

Just going back to this block, so to add that is_empty, where exactly would I add this, to which part of the block ?


Code:
   //set user number

   $content = '';
   $sql_user_num = "SELECT user_member_membernumber FROM ".$user_prefix."_users WHERE user_id='".intval($cookie[0])."'";
   $result_user_num = $db->sql_query($sql_user_num);
   $row_user_num = $db->sql_fetchrow($result_user_num);
   
   $content .= '<center>My membership number<br><strong>'.$row_user_num['user_member_membernumber'].'if(empty)$row_user_num['user_member_membernumber'])) {
$content = 'You don't have a user number yet, please check back in a few days' } else {$content = ... }</strong></center><br>';



Would that work or am I way off track with this, what is the "else {$content = ... " is the code supposed to go before the original section

Can you tell I am more of what I would call a copy and paster Laughing , but I really do want to learn this type of thing more and try and gain a better understanding

Thanks Mark
 
fkelly







PostPosted: Sat Dec 17, 2011 10:32 am Reply with quote

Code:
 $content .= '<center>My membership number<br><strong>'.$row_user_num['user_member_membernumber'].'if(empty)$row_user_num['user_member_membernumber'])) {

$content = 'You don't have a user number yet, please check back in a few days' } else {$content = ... }</strong></center><br>';


First, the html centering code is deprecated so we don't recommend using it. Style="text-align: center" will do.

Next, I'd recommend that you fill the contents of $content inside of an if statement. Something along the lines of:

Code:
if (empty($row_user_num['user_member_membernumber'] {

$content .= 'you do not have a user number yet, please check back in a few days' }
else { $content .= 'My membership number '. $row_user_num['user_member_membernumber' }


I can't properly format this in the bb editor nor syntax check it. You would want to load up $content with your style first along the lines of:

$content .= '<style="text-align: center>' and close out the style something like
$content .= '</style>' when you are done with the portion you want centered.

Re. coding skills, I hate to say it but if you are going to maintain custom code then you need to learn it. I suspect that all of us "coders" make several efforts at getting syntax and layout of our code right in our local test systems using a PHP editor of some sort before we get it right. Trying to write code in a bb editor is almost impossible.
 
kenno







PostPosted: Sun Dec 18, 2011 6:58 am Reply with quote

fkelly

I appreciate all your help, I know I need to learn the code and how to edit and maintain it correctly

I have a test site where I test this and have been running my code through an online syntax checker, then refering to google for assitance on that particular error, I have been trying for hours with this, but I need to learn the basics of coding which I am trying to do.

Ignoring the centering for now this is the code I have for the section of the file I need this for but I am getting unexpected T_IF error which points me to missing something before this or at the end of the previous line.
Sorry for coming back here but I am struggling to find the answer myself

Code:
  36:     $content .= 'My membership number'.$row_user_num['user_member_membernumber'].

  37:     if (empty($row_user_num['user_member_membernumber']{$content .= 'You do not have a member number yet, please check back in a few days'
  38:     }else {
  39:     $content .= 'My membership number '. $row_user_num['user_member_membernumber'] }';
 
fkelly







PostPosted: Sun Dec 18, 2011 8:16 am Reply with quote

Playing the PHP parser for a minute, it looks to me like you have several problems with that code. You are enclosing the data you are assigning to content in single quotes. That's right. But then you have single quotes surrounding user_member_membernumber and that will get the parser confused. I think. I think you'd need to say something like \'user_member_membernumber\' (thus escaping the single quotes) in order to unconfuse things. Also line 36 in your code should probably be:

$content = '';

When you first assign something to the variable you want to use = instead of .=.

So, there are two places where you need the escape characters (\) before single quotes (four occurrences). Also, in that last else (line 3Cool you have the closing brace inside the single quote. It needs to be '} not '}. Otherwise the closing brace on your else gets interpreted literally and your logic will fail.

If you get a good PHP editor like PHPED, it will highlight syntax issues for you as you go plus run a syntax check at the end that is more informative than many of the PHP generated error messages you will see.
 
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Sun Dec 18, 2011 12:31 pm Reply with quote

fkelly, it is fine to do something like this:

Code:


$content .= 'My membership number' . $row_user_num['user_member_membernumber'] . 'some text here';

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
fkelly







PostPosted: Sun Dec 18, 2011 1:03 pm Reply with quote

Parser failure.
 
Palbin







PostPosted: Sun Dec 18, 2011 1:26 pm Reply with quote

This parses fine:
Code:


<?PHP

$row_user_num['user_member_membernumber'] = '000000';

$content = 'My membership number' . $row_user_num['user_member_membernumber'] . ' [some text here]';

echo $content;

?>
 
fkelly







PostPosted: Sun Dec 18, 2011 1:55 pm Reply with quote

I meant a parser error on my part. Sorry, I have been busy creating my own bugs in a module I am writing for the bike club and haven't had time to pay sufficient attention to this Still in Kenno's code we were discussing earlier I would think he would want to make line 36 be $content = ''.
 
kenno







PostPosted: Sun Dec 18, 2011 2:14 pm Reply with quote

I am still trying here haha, I will get there with this in the end hopefully.

fkelly, what did you mean by this

Quote:
Also, in that last else (line 3Cool you have the closing brace inside the single quote. It needs to be '} not '}.


Code:
  36:     $content ="; 'My membership number'.$row_user_num\'user_member_membernumber\'.';

  37:     if (empty($row_user_num'user_member_membernumber'{$content .= 'You do not have a member number yet, please check back in a few days'
  38:     } else {
  39:     $content .= 'My membership number '. $row_user_num\'user_member_membernumber\' }";
 
spasticdonkey
RavenNuke(tm) Development Team



Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA

PostPosted: Sun Dec 18, 2011 3:55 pm Reply with quote

I think you are just getting caught with some syntax problems. Try something like this:

Code:
$thenum = $row_user_num['user_member_membernumber'];

if ($thenum > 0){
   $thenum = '<div style="font-weight:bold;font-size:200%">' . $thenum . '</div>';
   }else{
   $thenum = ' is pending. Please check back in a few days.';
}
$content .= 'Your membership number' . $thenum;
 
View user's profile Send private message Visit poster's website
fkelly







PostPosted: Sun Dec 18, 2011 5:06 pm Reply with quote

Thanks SpasticDonkey. Kenno: that code Spast. posted will be easier to deal with and maintain. I apologize for being in a rush earlier and making syntax mistakes as result.

Just for purposes of clarity to make clear how single quotes work, back a while ago you posted:

Code:
else {  $content .= 'My membership number '. $row_user_num['user_member_membernumber'] }';



I missed the single quote after "membership number" and thus made the mistake of telling you that you had to insert escape characters before the following single quotes. Palbin caught that and corrected it. However, if you look at the end of the line you will see that closing single quote comes AFTER the brace. I was originally thinking that having }' would embed the} in the data that you are assigning to $content. Looking again it appears to me that instead ... since you terminated the previous single string area before that the brace would be okay (it would terminate the else logic) but you'd be left with a stray single quote (the one before the semi-colon). That would probably cause problems down below in your code.

One of the reasons that many developers work with a product such as PHPED is that it automatically catches and highlights errors such as this, as you type, so you aren't left trying to decipher cryptic PHP generated errors at run time. It's kind of like of having a spell checker for your code.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Seeking applications ...

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©