PHP class issue/Session issue -
i'm trying create object , store in session variable can access on different pages.
i'm having issue properties in object getting on written inexplicably. getmenu method seems displaying wrong property. cannot figure out why, maybe here @ glance know.
here user.class.php:
<?php /** * created phpstorm. * user: * date: 6/26/14 * time: 2:55 pm */ class user{ private $company; private $username; private $menutype; private $viewstate; private $gridtype; public function setgrid($gridtype){ $this->gridtype = $gridtype; } public function getgrid(){ if($this->gridtype='salesgrid'){ include 'gridview.php'; }elseif($this->gridtype='truckinggrid'){ include 'lactiveloadview.php'; } } public function setcompany($company){ $this->company = $company; } public function getcompany(){ return $this->company; } public function setusername($username){ $this->username = $username; } public function getusername(){ return $this->username; } public function setmenu($menutype){ $this->menutype = $menutype; } public function getmenu(){ if($this->menutype='salesmenu'){ $x = <<< 'menu' <button id='carriereditor' class='alignright' onclick="location.href='gridmanager.php?action=alert'">alerts</button> <button id='carriereditor' class='alignright' onclick="location.href='gridmanager.php?action=carrier'">carriers</button> <button id='vendoreditor' class='alignright' onclick="location.href='gridmanager.php?action=vendor'">vendors</button> <button id='producteditor' class='alignright' onclick="location.href='gridmanager.php?action=product'">products</button> <button id='customereditor' class='alignright' onclick="location.href='gridmanager.php?action=customer'">customer</button> <button id='home' class='alignright' onclick="location.href='index.php'">home</button> menu; echo $x; } elseif($this->menutype='truckingmenu'){ $x = <<< 'menu' <button id='generatenewload' onclick=\"location.href='index.php?viewstate=newload'\">generate new load</button> <button id='openloads' onclick=\"location.href='index.php?viewstate=all'\">open loads</button> <button id='viewtoday' class='alignleft' onclick=\"location.href='index.php?viewstate=today'\">today</button> <button id='viewtomorrow' class='alignleft' onclick=\"location.href='index.php?viewstate=tomorrow'\">tomorrow</button> <button id='viewweek' class='alignleft 'onclick=\"location.href='index.php?viewstate=week'\">week</button> <button id='trackingloads' onclick=\"location.href='index.php?viewstate=tracking'\">tracking loads</button> <button id='closedloads' onclick=\"location.href='index.php?viewstate=completed'\">closed loads</button> <button id='deliveryrequest' class='alignright'>delivery request</button> <button id='bolgenerator' class='alignright'>manage bols</button> <button id='managecontacts' class='alignright' onclick=\"location.href='gridmanager.php?action=contacts'\">manage contacts</button> <button id='btnemailblast' class='alignright' >email blast</button> menu; echo $x; } } public function setviewstate($viewstate){ $this->viewstate = $viewstate; } public function getviewstate(){ return $this->$viewstate; } }
my authentication page:
if ($adldap->authenticate($user, $pass)){ session_start(); $_session['loggedinuser'] = $user; //build array after calling in ingroup method in /src/adldap. in array store key group name , value boolean value. $logintype = array("administration" => $adldap->user()->ingroup($user, "ny-it"), "sales" => $adldap->user()->ingroup($user, "acl-sales"), "trucking" => $adldap->user()->ingroup($user, "acl-sales_abridged"), "phsales" => $adldap->user()->ingroup($user, "acl-ph-sales"), "hbroccoli" => $adldap->user()->ingroup($user, "acl-sales_broccoli")); //loop through array, if true value comes up, assign session , redirect correct page //$userprops = new user(); // $company = $_session['userobject']->getcompany(); // if (!$_session['userobject'] instanceof user) // $_session['userobject'] = new user(); $usersession = new user(); foreach ($logintype $val) { if ($logintype['administration'] == true) { $usersession->setcompany('administrators'); $usersession->setmenu('salesmenu'); $usersession->setusername($user); $usersession->setgrid('salesgrid'); $usersession->setviewstate('all'); $_session['userobject']=$usersession; $_session['company'] = "administrators"; header('location: index.php?alerts=null'); } elseif ($logintype['sales'] == true) { $usersession->setcompany('sales'); $usersession->setmenu('salesmenu'); $usersession->setusername($user); $usersession->setviewstate('all'); $usersession->setgrid('salesgrid'); $_session['userobject']=$usersession; $_session['company'] = "sales"; header('location: index.php?alerts=null'); } elseif ($logintype['trucking'] == true) { $usersession->setcompany('trucking'); $usersession->setmenu('truckingmenu'); $usersession->setusername($user); $usersession->setviewstate('all'); $usersession->setgrid('truckinggrid'); $_session['userobject']=$usersession; $_session['company'] = "trucking"; header('location: index.php?alerts=null'); } elseif ($logintype['phsales'] == true) { $_session['company'] = "ph sales"; header('location: cmanager.php'); } elseif ($logintype['hbroccoli'] == true) { $_session['company'] = "hbroccoli"; header('location: index.php?alerts=null'); } else { header('location: login.php?alerts=na'); } } } else{ header('location: login.php?alerts=na'); // non authenticated used }
then here case examples: var dump of object on load expose this:
object(user)[1] private 'company' => string 'trucking' (length=14) private 'username' => string 'gpigb' (length=5) private 'menutype' => string 'truckingmenu' (length=12) private 'viewstate' => string 'all' (length=3) private 'gridtype' => string 'truckinggrid' (length=12)
if call of methods in class stored in session variable properties of methods written on wrong data reason.
$x = $_session['userobject']; $x->getmenu();
vardump of object shows:
object(user)[1] private 'company' => string 'trucking' (length=14) private 'username' => string 'gpigb' (length=5) private 'menutype' => string 'salesmenu' (length=9) private 'viewstate' => string 'all' (length=3) private 'gridtype' => string 'truckinggrid' (length=12)
see how menu type shows 'salesmenu'? never called setmenu method change it, yet has. gives?
please help
in user.class.php
file assigning (=
) menutype
class/object variable rather comparing (==
) it.
if($this->menutype='salesmenu'){ ... } elseif($this->menutype='truckingmenu'){ ....
should be:
if($this->menutype == 'salesmenu'){ ... } elseif($this->menutype == 'truckingmenu'){ ....
you're overwritting gridtype
variable in getgrid()
function.
Comments
Post a Comment