Can't separate user packages to assign differing block_vars

Hey guys,

I’m pretty new to PHP, but I guess that’s OK here. I have wanted to learn PHP and MySQL for quite some time and I have taken a few classes about both but I am just getting into the coding part for real. So I am glad to have a place where I won’t be made fun of (unlike some others who will remain nameless because I’m better than that).

I want to learn because I am tired of losing good programmers that work for me to other projects or any other thing that comes along. I want to start something and finish it. So here I am. Sorry for the intro…

Today I am working with one of the projects that my last programmer left for me. It is a simple CMS system that is a hybrid of various open source php scripts and I had him create it for me to allow me to do some advanced website creation using interactivity (backoffice functions) on sites that needed it. It contains a newsletter module, an ecommerce module, a profile module, a registration module, etc. However, now that I do not have access to this programmer any longer I have to do what I can myself.

Today’s problem involves one of the functions of this CMS that because I do not know PHP as well as I will if I keep at it I am not finding the answer. This CMS designates users according to packages that can be created in an admin panel function and once created are global package types that can be referred to in order to designate display functionality of content dependent upon what user package type is logged in. The previous developer created a script that sits in my index.php file which combines the admin and superadmin package types into using a single designator of ToggleAdmin to toggle an active section of the webpage for that custom content. What I want it to do is to separate out admin from superadmin and have two separate terms that allow for one OR the other and not both to be active in a single session (because only one user package type can be logged in at one time. However when I tried to create a version of code that I thought should do the trick all I ended up doing was getting both active at the same time. So obviously I was not doing something correctly.

Here is the code. You will notice that the combined functionality code is commented out and my attempt is not commented out.

[php] if (empty($_SESSION[‘user’])) {
$template->assign_block_vars(‘ToggleNotLoggedIn’, array());
} else {
$template->assign_block_vars(‘ToggleLoggedIn’, array());
}

// if ($GLOBALS[‘ActiveUser’][‘packagedata’][‘admin’] || $GLOBALS[‘ActiveUser’][‘packagedata’][‘superadmin’]) {
// $template->assign_block_vars(‘ToggleAdmin’, array());
// }
if ($GLOBALS[‘ActiveUser’][‘packagedata’][‘admin’]) {
$template->assign_block_vars(‘ToggleAdmin’, array());
}
if ($GLOBALS[‘ActiveUser’][‘packagedata’][‘superadmin’]) {
$template->assign_block_vars(‘ToggleSuperAdmin’, array());
}[/php]

Here is the HTML that places it on the actual webpage so you can see the toggle function at work:

[code]



	<!-- BEGIN ToggleLoggedIn -->
			
		<p>Welcome  to your resource center admin panel.  To access administration functions of the resource center (edit categories and resources) click on the "Administration" link in the top navigation menu.  Thank you.</p>
	<!-- END ToggleLoggedIn -->
	<!-- BEGIN ToggleAdmin -->
		<p>Test, this is to see if A works</p>
	<!-- END ToggleAdmin -->
	<!-- BEGIN ToggleSuperAdmin -->
		<p>Test, this is to see if SA works</p>
	<!-- END ToggleSuperAdmin -->
	<!-- BEGIN Personal -->
		<p>{Personal.firstname}</p>
	<!-- END Personal -->
</td>
<td valign="top" align="center" width="320"><br></b>
	<table align="center" width="310" cellpadding="0" cellspacing="0">
		<tr><td width="310">	
			<h1>FEATURED MCU NETWORK PARTNER</h1>	
			<table cellpadding="0" cellspacing="0">
				<tr><td width="135" align="center"><img src="../images/uep.jpg">
				</td>
				<td>
					<p>This is where a featured Network Parter description would go.  This section is capable of full HTML/CSS/PHP/Javascript formatting.</p>
				</td></tr>
			</table>
		</td></tr>
	</table>
</td></tr>
[/code]

Can you look this over and let me know what I am doing wrong? All I want is for one or the other to be active at a time and to be able to create other package designations based upon other package types that will be created in the future, hopefully be me :slight_smile:

Thanks a million and I look forward to haunting the place and getting to know you all and most of all finally getting better at PHP and MySQl and starting my dream of taking my ideas from conception to reality without always losing my coder because I will be the coder!

Benjamin

Well, Ben, looking at the code quickly, it does appear that you have it correct. My guess is that the login area
where the user level is created may be the problem. What I mean is that you have two values in the package

$GLOBALS[‘ActiveUser’][‘packagedata’][‘admin’]
$GLOBALS[‘ActiveUser’][‘packagedata’][‘superadmin’]

These are most likely created when the user logs into the site. These are set in that area, not in the code
you showed us. My guess is that in that code, the value of BOTH of these are set. Therefore, both of the
user levels for are made active. And, in your code, you check for each of them, but, as both are active, then
both are displayed. I would guess you need to look in the code that sets the above and fix them. Normally
when a site logs in a user, it runs a query against the database to see what user level they are allowed to
use. Then, it stores it somewhere. I suspect in that area it is loading the two items above for either of the
two admin levels. You would need to fix that part.

Hope this makes sense. Let us know…

Hi Ernie,

Thanks and you are correct. I learned a tremendous amount in the hours since I posted this (just reading and reading and reading ad infinitum the code). Apparently the two were hard coded package data columns in the database table that are manually set to active or inactive and referred to using globals. In the case of this there were two interesting things. First, the Admin was set to active with admin only. Second the Super Admin was set to active with both admin and superadmin. Third there was no column in the table for basic such that Basic could be listed as active for basic but not admin or superadmin. So what I did was to manually create (like he did) a column in the table called basic and set that to 1 for active. That worked. Then I Admin to be active for admin but not superadmin or basic and Super Admin to be active for superadmin but not admin or basic. I know it all sounds convoluted but it really is a neat tool that allows some pretty great customization for a hand coder to create more flexible interactivity than wordpress or joomla or elgg can give me (user packages and such as well as some affiliate functionality). At the end of the day I think I chose to create what I needed as I went along and each new function became a module that I could toggle on or off for whatever site I created. Also another thing about it that is cool is when it comes to customizing the look I have separated the look from the code and created a header body (template system) and footer set up that allows for literally any template to be cut and pasted into them with just a novice understanding of code. I can make this look like anything or I can create anything from scratch look wise and the functionality of the php fits in no matter what. Pretty cool. So while it seems awkward, it really isnt from the perspective of a hand coder who wants as much flexibility as possible when building a site. I think it would be a very popular simple CMS if I could ever get it finished. It still needs an install module and it could use a few upgrades like a real dashboard for the admin and the users (right now it used a module listing for admin and a “home” page for the user. Anyhoo, thanks for the insight. I am looking forward to learning PHP no matter what and I really appreciate that you guys let even the most novice of us in to learn the trade. If I am ever in a hurry on a project and I need some help are there coders on here who work for fee and if so how do I find out and find out what their fees are? At some point I am going to need help on this project after we secure funding and will need to build a team of coders two or three to really take both this simple CMS and the project to the next level. its a big project so I have to keep it under wraps at this point but it has an immediate market that we are tapping. So I will keep you all posted. Peace out guys and gals!

Ben, sounds like I steered you into the correct area! Good for you to solve it. I marked this thread solved.

Also, once you get to the point to hire a programmer to help you, there are many here. Rates are almost
always negotiable. We have an area to post for-hire notices once you get to that point. If you post there,
you can give possible programmers an idea of what you might need, your budget, etc. Then, you can talk
to various programmers here who can help you.

Well, looks like you learned a lot. Always a nice warm feeling to solve a programming puzzle…

Sponsor our Newsletter | Privacy Policy | Terms of Service