Hide/Show content based on product id

Discussion in 'Customization & add-ons' started by ehassler, Aug 25, 2006.

  1. ehassler

    ehassler New Member

    Joined:
    Aug 25, 2006
    Messages:
    2
    I'm running several aMember 2.3.6 installations... They're great. Anyway, here's what I'd like to do: On the member.html page I'd like the option show or hide some content based on which product the logged-in member has subscribed to. What's the syntax for that? It seems like it'd be a fairly simple {if} statement, but I don't know what the product variables are. I'm no php whiz, mainly a designer... I really need help tonight, so if anyone's online I'd totally appreciate the help. Alex, remember me? I have four "goget" sites.

    Thanks.
  2. ehassler

    ehassler New Member

    Joined:
    Aug 25, 2006
    Messages:
    2
    OK. I found a very similar question posed on this forum, to which alex suggested using:

    {if in_array(5, $_SESSION['_amember_product_ids'])}
    your code here
    {/if}

    I tried that, but got the following error:
    Fatal error: Smarty error: [in member.html line 9]: syntax error: unbalanced parenthesis in if statement (Smarty_Compiler.class.php, line 1232)

    I'm not a php programmer, so I don't really see unbalanced parenthesis there. Any help?
  3. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    It really should not happen here. Could you try to just copy/paste this


    {if in_array(5, $_SESSION['_amember_product_ids'])}
    your code here
    {/if}

    ?
  4. patrick_6

    patrick_6 New Member

    Joined:
    Aug 22, 2006
    Messages:
    9
    i get the same error Alex. I need this to work for something with my site too.
  5. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    Please copy/paste your member.html and exact error message.
  6. patrick_6

    patrick_6 New Member

    Joined:
    Aug 22, 2006
    Messages:
    9
    Here is the error:

    ERROR [256] Smarty error: [in member.html line 45]: syntax error: unbalanced parenthesis in if statement (Smarty_Compiler.class.php, line 1232) in line 1102 of file /home/mysite/public_html/members/smarty/Smarty.class.php


    Here is the code for member.html :

    Code:
    {assign var="title" value=$smarty.const._TPL_MEMBER_TITLE}
    {include file="header2.html"}
     <div id="FlashMov"><img src="../../images/first-class-menu.jpg" alt="Members Only"  width="800" height="252" border="0" usemap="#Map"/>
    </div>
     <div id="PageBar">
     <img src="http://www.mysite.com/images/members-bar.gif" alt="Please Login" width="800" height="41" /></div> 
      <div id="InsideBigWhite">
       <div style="margin-left:50px;margin-right:50px;height:auto;padding-top:10px;border-bottom:1px #3399CC dashed" align="left" class="ContactFormText">
    <table width="100%"><tr><td style="width: 50%; vertical-align: top;">
      <p>
        <!-- display links to protected areas for customer -->
        {if $smarty.session._amember_products}{* Customer have active subscriptions, display it if config allows *}  </p>
      <p class="FirstL">Welcome, {$smarty.session._amember_user.name_f}!</p>
      <h3>#_TPL_MEMBER_SUBSCR#</h3>
        <table><tr><td><ul> <!-- table to align subscriptions -->
        {foreach from=$member_products item=p}
        <li>
        {if $p.url gt "" }
            <!--<a href="{$p.url}">-->{$p.title}<!--</a>-->
        {else}
            <b>{$p.title}</b>
        {/if}    </li>
        {foreach from=$p.add_urls item=t key=url}  
            <li><!--<a href="{$url}">-->{$t}<!--</a>--></li>
        {/foreach}
        {/foreach}
        </ul></td></tr></table>
    {else}{* Customer doesn't have any active subscriptions *}
        <h3>#_TPL_MEMBER_NO_SUBSCR#</h3>    
        #_TPL_MEMBER_USE|<i>|</i>#<br /> 
        #_TPL_MEMBER_ORDER_SUBSCR#<br />
    {/if}
    <table><tr><td>
    {foreach from=$left_member_links item=t key=u}
        <li> <a href="{$u|escape}">{$t}</a></li>
    {/foreach}
    </td></tr></table>
    <p class="readyText">Please use the buttons above to access the other pages of the membership section. </p>
    <p>We are adding to mysite.com every day. You may find that some things aren't complete. Please be patient as we continually add and improve. Please <a href="http://www.mysite.com/contact.php">contact us</a> if you have a specific question or suggestion. </p></td>
    </tr>
    </table>
    </div>
    </div>
    <map name="Map" id="Map"><area shape="rect" coords="87,89,201,176" href="first-class/ask-expert.php" alt="Ask an Expert" />
    [COLOR="Red"]{if in_array(5, $_SESSION['_amember_product_ids'])}
    <area shape="rect" coords="213,88,327,175" href="first-class/powercalls/" alt="Power Call Info" />
    {else}<area shape="rect" coords="213,88,327,175" href="http://www.mysite.com/power-calls.php" alt="Power Call Info" />
    {/if}[/COLOR]
    <area shape="rect" coords="340,88,453,176" href="first-class/documents.php" alt="Documents" />
    <area shape="rect" coords="467,88,581,175" href="first-class/make-money.php" />
    </map>
    <!-- end of display links to protected areas for customer -->
    {include file="footer.html"}
    
    Thanks Alex!
  7. patrick_6

    patrick_6 New Member

    Joined:
    Aug 22, 2006
    Messages:
    9
    **bumping Thread**
  8. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    Sorry for late response.
    Seems to be a bug in Smarty code.
    replace
    {if in_array(5, $_SESSION['_amember_product_ids']) }
    to
    {if in_array(5, $_SESSION[_amember_product_ids]) }
  9. patrick_6

    patrick_6 New Member

    Joined:
    Aug 22, 2006
    Messages:
    9
    it works now, except I get this error right below it. Is there a way to hide the error?

    WARNING: in_array() [function.in-array]: Wrong datatype for second argument in line 70 of file SmartyNoWrite.class.php(216) : eval()'d code
  10. patrick_6

    patrick_6 New Member

    Joined:
    Aug 22, 2006
    Messages:
    9
    ACTUALLY, its not working. I thought it was because I was trying someone without that product, but when I tried someone using that product it didn't work. Any ideas? I copied and pasted it exactly as you have it.
  11. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    Please try
    {if in_array(5, $smarty.session._amember_product_ids) }
  12. patrick_6

    patrick_6 New Member

    Joined:
    Aug 22, 2006
    Messages:
    9
    there you go! It works now. Thanks for the support!
  13. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    542

    I just tried that and this is the error I got:

    Parse error: parse error, unexpected T_STRING, expecting '('

    on that exact line...

    help?!
  14. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    542
    wait, I added that to my .php file... that might be the problem (me = idiot. smarty codes go into html)

    then again, when I added it to the .html template for that .php file, here's the error I got:

    WARNING: in_array(): Wrong datatype for second argument in line 16 of file SmartyNoWrite.class.php(216) : eval()'d code
  15. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    Please contact us via helpdesk and e-mail your file with error message.
  16. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    542
    actually, I added this instead:

    {if $smarty.session._amember_user.status==1}
    ...
    {/if}

    and it took care of the problem, somewhat... it checks if the user has an active/paid subscription (and since I've only got one product here, it's good for now)

    however, how would I add a condition to that statement to check if the user accessing page is an admin too... since admins don't have any active subscriptions, and I'd need to give them access to this page as well.
  17. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    Add admin as a user and add him lifetime subscriptions in aMember CP.
  18. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    542
    how would I do that and end up linking an existing user in admin table to a new user in members table?

    would that happen by simply adding a new user with the same username as admin (can't be that easy)?
  19. alex

    alex Administrator Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,020
    SURE!

    aMember stores admin and user records 100% sepearately, there is no relation. It is better from security point of view.
  20. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    542
    it is... but the problem is when I have 2 different tables and 2 separate users.

    if i have an admin "webmaster" and user "webmaster" with lifetime subscription, they are two separate users and there is no way for me to link the user one to the admin one (unless I'm missing something here).

    or is there a certain setting in smarty like $smarty.session._amember_admin.status that checks if the user logged in is admin or something?

    as it is, creating another user with the same name as the admin didn't do the trick... and i don't have an option to create a regular user from an admin, so... any other ideas?

Share This Page