Index: branches/RC/kernel/include/portaluser.php =================================================================== diff -u -N -r9465 -r10889 --- branches/RC/kernel/include/portaluser.php (.../portaluser.php) (revision 9465) +++ branches/RC/kernel/include/portaluser.php (.../portaluser.php) (revision 10889) @@ -2,10 +2,10 @@ RegisterPrefix("clsPortalUser","user","kernel/include/portaluser.php"); -class clsPortalUser extends clsItem +class clsPortalUser extends clsItem { var $Vars; //contains the PersistantSessionData for the user - var $VarsLoaded; + var $VarsLoaded; var $PrimeGroup; function clsPortalUser($UserId=NULL) @@ -37,7 +37,7 @@ } return $ret; } - + function Update($UpdatedBy = null, $modificationDate = null) { $ret = parent::Update($UpdatedBy, $modificationDate); @@ -49,49 +49,49 @@ } return $ret; } - + function Delete() { global $objGroups, $objFavorites, $objModules, $objSession; - + $g = $objGroups->GetPersonalGroup($this->Get("Login")); if (is_object($g)) $g->Delete(); - + $objFavorites->DeleteUser($this->Get("PortalUserId")); //delete favorites $user_id = $this->Get("PortalUserId"); - + $ret = parent::Delete(); - + if($ret) { - + if ($objModules->ModuleInstalled('In-Link')) { // clean user visits in LinkVisits table $sql = 'DELETE FROM '.GetTablePrefix().'LinkVisits WHERE PortalUserId = '.$user_id; $this->adodbConnection->Execute($sql); } - + if ($this->isLiveTable()) { $application =& kApplication::Instance(); $sync_manager =& $application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize'); $sync_manager->performAction('deleteUser', $this->Data); } } - + return $ret; } function RemoveFromAllGroups() { $sql = "DELETE FROM ".GetTablePrefix()."UserGroup WHERE PortaluserId=".$this->Get("PortalUserId"); - $this->adodbConnection->Execute($sql); - } - + $this->adodbConnection->Execute($sql); + } + function RemoveFromGroup($GroupId) { $sql = "DELETE FROM ".GetTablePrefix()."UserGroup WHERE PortaluserId=".$this->Get("PortalUserId"); $sql .= " AND GroupId=$GroupId"; - $this->adodbConnection->Execute($sql); + $this->adodbConnection->Execute($sql); } - + function PrimaryGroup($ReturnField = "GroupId") { global $objGroups; @@ -105,7 +105,7 @@ $this->PrimeGroup =& $objGroups->GetItem($this->Get("GroupId")); } else - { + { $this->PrimeGroup = new clsPortalGroup(); $sql = "SELECT * FROM ".GetTablePrefix()."UserGroup INNER JOIN ".GetTablePrefix()."PortalGroup ON (".GetTablePrefix()."UserGroup.GroupId=".GetTablePrefix()."PortalGroup.GroupId) WHERE PrimaryGroup = 1 AND PortalUserId=".$this->Get("PortalUserId"); //echo $sql; @@ -118,7 +118,7 @@ $ret = $this->PrimeGroup->Get($ReturnField); return $ret; } - + function SetPrimaryGroup($GroupId) { if($this->IsInGroup($GroupId)) @@ -138,14 +138,14 @@ $ret = $this->adodbConnection->GetCol($sql); return $ret; } - + function IsInGroup($GroupId) { $groups = $this->GetGroupList(); if( $groups === false ) return false; return in_array($GroupId, $groups) ? true : false; } - + function GetPersonalGroup($CreateIfMissing = FALSE) { global $objGroups; @@ -184,13 +184,13 @@ $Errors->AddError("error.fieldIsRequired",'Login',"","",get_class($this),"Validate"); $dataValid = false; } - + if(!strlen($this->Get("Email"))) { $Errors->AddError("error.fieldIsRequired",'Email',"","",get_class($this),"Validate"); $dataValid = false; } - + return $dataValid; } @@ -214,7 +214,7 @@ { global $objGroups; - $GroupList = $this->GetGroupList(); + $GroupList = $this->GetGroupList(); for($i=0;$iGetItem($GroupList[$i]); @@ -224,22 +224,22 @@ } return $value; } - + function LoadPersistantVars() { global $objConfig; unset($this->Vars); $this->Vars = Array(); $user_id = $this->HasField('PortalUserId') ? $this->Get('PortalUserId') : 0; - + $sql = "SELECT VariableName, VariableValue FROM ".GetTablePrefix()."PersistantSessionData WHERE PortalUserId = ".(int)$user_id." ORDER BY PortalUserId ASC"; $result = $this->adodbConnection->Execute($sql); while ($result && !$result->EOF) { $data = $result->fields; $this->Vars[$data["VariableName"]] = $data["VariableValue"]; - + if( basename($_SERVER['PHP_SELF']) != 'edit_config.php' ) { $objConfig->Set($data["VariableName"], $data["VariableValue"], 1, 1); @@ -248,19 +248,19 @@ } $this->VarsLoaded = TRUE; } - + function SetPersistantVariable($variableName, $variableValue) { global $objConfig; if(!$this->VarsLoaded) $this->LoadPersistantVars(); - $userid = $this->Get("PortalUserId"); + $userid = $this->Get("PortalUserId"); $objConfig->Set($variableName,$variableValue,1); $fields = array_keys($this->Vars); - + if(strlen($variableValue)>0) - { + { if(in_array($variableName,$fields)) { $sql = "UPDATE ".GetTablePrefix()."PersistantSessionData SET VariableValue='$variableValue' WHERE VariableName='$variableName' AND PortalUserId=$userid"; @@ -269,26 +269,26 @@ $sql = "INSERT INTO ".GetTablePrefix()."PersistantSessionData (VariableName,VariableValue,PortalUserId) VALUES ('$variableName','$variableValue',$userid)"; } else - $sql = "DELETE FROM ".GetTablePrefix()."PersistantSessionData WHERE VariableName='$variableName' AND PortalUserId=$userid"; - + $sql = "DELETE FROM ".GetTablePrefix()."PersistantSessionData WHERE VariableName='$variableName' AND PortalUserId=$userid"; + $this->Vars[$variableName] = $variableValue; - + // echo "
SQL: $sql
"; - + $this->adodbConnection->Execute($sql); } function GetPersistantVariable($variableName) { global $objConfig, $objSession; - + if(!$this->VarsLoaded) { $this->LoadPersistantVars(); } $fields = array_keys($this->Vars); - + if(in_array($variableName,$fields)) { $val = $this->Vars[$variableName]; @@ -304,9 +304,9 @@ $val = ''; } } - + return $val; - } + } function GetAllPersistantVars() { @@ -318,7 +318,7 @@ } function GetIcon() - { + { } function StatusIcon() @@ -332,7 +332,7 @@ } else if($this->Get("Status")==2) - { + { $url .= "_pending"; } $url .= ".gif"; @@ -361,31 +361,31 @@ } function ParseObject($element) - { + { global $objConfig, $objUsers, $objCatList,$objSession, $var_list_update, $var_list, $m_var_list_update; //echo "
"; print_r($element); echo "
"; //echo "Tag Prefix: ".$this->TagPrefix." Element: ".$element->name."
"; $this->clsPortalUser(); if (strtolower($element->name) == 'touser') { $this->TagPrefix = "touser"; } - + $extra_attribs = ExtraAttributes($element->attributes); if(strtolower($element->name)==$this->TagPrefix) - { - $field = strtolower($element->attributes["_field"]); + { + $field = strtolower($element->attributes["_field"]); if(substr($field,0,3)=="pp_") { $perm = $objSession->GetPersistantVariable($field); if($perm) - { + { $field = substr($field,3); } else $field = ""; } switch($field) - { + { /* @field:user.login @description:User's login name @@ -399,10 +399,10 @@ break; case "lastname": $ret = $this->Get("LastName"); - break; + break; case "password": /* - @field:user.password + @field:user.password @description:User password */ /*$ret = $objSession->Get("password"); @@ -411,7 +411,7 @@ break; case "email": $ret = $this->Get("Email"); - break; + break; case "street": $ret = $this->Get("Street"); break; @@ -426,7 +426,7 @@ break; case "phone": $ret = $this->Get("Phone"); - break; + break; case "country": $ret = $this->Get("Country"); break; @@ -441,13 +441,13 @@ $groupfield="Name"; $ret = $this->PrimaryGroup($groupfield); break; - case "date": + case "date": /* @field:user.date @description:Returns the date/time the user was created @attrib:_tz:bool:Convert the date to the user's local time @attrib:_part::Returns part of the date. The following options are available: month,day,year,time_24hr,time_12hr - */ + */ $d = $this->Get("CreatedOn"); if($element->attributes["_tz"]) { @@ -460,22 +460,22 @@ $ret = ExtractDatePart($part,$d); } else - { + { if($d<=0) - { + { $ret = ""; } else $ret = LangDate($d); } - break; + break; case "dob": /* @field:user.dob @description:Returns the date/time of the users date of birth @attrib:_tz:bool:Convert the date to the user's local time @attrib:_part::Returns part of the date. The following options are available: month,day,year,time_24hr,time_12hr - */ + */ $d = $this->Get("dob"); if($element->attributes["_tz"]) { @@ -487,23 +487,23 @@ $ret = ExtractDatePart($part,$d); } else - { + { // if($d<=0) -// { +// { // $ret = ""; // } // else $ret = LangDate($d); } - break; + break; case "modified": /* @field:user.modified @description:Returns the date/time the user was last modified @attrib:_tz:bool:Convert the date to the user's local time @attrib:_part::Returns part of the date. The following options are available: month,day,year,time_24hr,time_12hr - */ + */ $d = $this->Get("Modified"); if($d<=0) $d = $this->Get("CreatedOn"); @@ -512,28 +512,28 @@ { $d = GetLocalTime($d,$objSession->Get("tz")); } - - $part = strtolower($element->GetAttributeByName('_part')); + + $part = strtolower($element->GetAttributeByName('_part')); if(strlen($part)) { $ret = ExtractDatePart($part,$d); } else - { + { if($d<=0) - { + { $ret = ""; } else $ret = LangDate($d); } break; - + case 'send_pm_link': $var_list_update['t'] = $element->GetAttributeByName('_Template'); $ret = HREF_Wrapper('', Array('ToUser' => $this->Get('Login') ) ); break; - + case "profile_link": /* @field:user.profile_link @@ -542,7 +542,7 @@ */ $t = $element->attributes["_template"]; if(strlen($t)) - { + { $var_list_update["t"] = $t; } else @@ -557,12 +557,12 @@ @description:link to add a user to the friends list @attrib:_template:tpl:Template link shoukd point to */ - if($element->attributes["_force"] || !$this->IsFriend($objSession->Get("PortalUserId")) && + if($element->attributes["_force"] || !$this->IsFriend($objSession->Get("PortalUserId")) && $this->Get("PortalUserId") != $objSession->Get("PortalUserId")) - { + { $t = $element->attributes["_template"]; if(strlen($t)) - { + { $var_list_update["t"] = $t; } else @@ -579,13 +579,13 @@ @field:user.del_friend_link @description:link to remove a user from the friends list @attrib:_template:tpl:Template link shoukd point to - */ - if($element->attributes["_force"] || $this->IsFriend($objSession->Get("PortalUserId")) && + */ + if($element->attributes["_force"] || $this->IsFriend($objSession->Get("PortalUserId")) && $this->Get("PortalUserId") != $objSession->Get("PortalUserId")) - { + { $t = $element->attributes["_template"]; if(strlen($t)) - { + { $var_list_update["t"] = $t; } else @@ -599,7 +599,7 @@ break; case "icon": $ret = $this->GetIcon(); - break; + break; case "image": /* @field:user.image @@ -608,11 +608,11 @@ @attrib:_name::Return the image with this name @attrib:_thumbnail:bool:If true, return the thumbnail version of the image @attrib:_imagetag:bool:If true, returns a complete image tag. exta html attributes are passed to the image tag - */ - $avatar = $element->attributes["_avatar"]; + */ + $avatar = $element->attributes["_avatar"]; $default = $element->attributes["_primary"]; $name = $element->attributes["_name"]; - if ($avatar) + if ($avatar) { $img = $this->GetAvatarImage(); } @@ -621,19 +621,19 @@ $img = $this->GetImageByName($name); // echo "
";print_r($img); echo "
"; } - elseif ($default) + elseif ($default) { $img = $this->GetDefaultImage(); } - + if($img) { if($element->attributes["_thumbnail"]) - { + { $url = $img->parsetag("thumb_url"); } else - $url = $img->parsetag("image_url"); + $url = $img->parsetag("image_url"); } else { @@ -643,7 +643,7 @@ if($element->attributes["_imagetag"]) { if(strlen($url)) - { + { $ret = ""; } else @@ -653,14 +653,14 @@ $ret = $url; break; - case "custom": + case "custom": /* @field:cat.custom @description:Returns a custom field @attrib:_customfield::field name to return @attrib:_default::default value - */ - $field = $element->attributes["_customfield"]; + */ + $field = $element->attributes["_customfield"]; $default = $element->attributes[" "]; $ret = $this->GetPersistantVariable($field); @@ -669,29 +669,29 @@ break; default: $ret = "Undefined:".$element->name; - break; + break; } } else { - $ret = $this->parsetag($element->name); + $ret = $this->parsetag($element->name); } - + return $ret; } function parsetag($tag) - { + { global $m_var_list_update, $var_list_update, $var_list, $objConfig; if(is_object($tag)) - { + { $tagname = $tag->name; } else - $tagname = $tag; - + $tagname = $tag; + switch($tagname) - { + { case "user_id": return $this->Get("ResourceId"); break; @@ -725,25 +725,25 @@ break; case "user_phone": return $this->Get("Phone"); - break; + break; case "user_street": return $this->Get("Street"); - break; + break; case "user_city": return $this->Get("City"); - break; + break; case "user_state": return $this->Get("State"); - break; + break; case "user_zip": return $this->Get("Zip"); - break; + break; case "user_country": return $this->Get("Country"); break; case "user_resourceid": return $this->Get("ResourceId"); - break; + break; case "user_icon": return $this->GetIcon(); break; @@ -767,7 +767,7 @@ break; } } - + /** * Sends EmailEvent to user * @@ -781,26 +781,26 @@ { $object =& $this->Application->recallObject('u', null, Array ('skip_autoload' => true)); /* @var $object kDBItem */ - + $object->Load($this->UniqueId()); - + $send_params = is_numeric($ToUserId) ? Array() : Array ('to_email' => $ToUserId, 'to_name' => $RecptName); $status = $this->Application->EmailEventUser($EventName, $ToUserId, $send_params); - $object->Load($this->Application->RecallVar('user_id')); + $object->Load($this->Application->RecallVar('user_id')); return $status; } function SendAdminEventMail($EventName,$LangId=NULL) { $object =& $this->Application->recallObject('u', null, Array ('skip_autoload' => true)); /* @var $object kDBItem */ - + $object->Load($this->UniqueId()); - + $status = $this->Application->EmailEventAdmin($EventName); $object->Load($this->Application->RecallVar('user_id')); return $status; - } + } } /* class clsPortalUser*/ @@ -818,7 +818,7 @@ $this->SetTable('live', GetTablePrefix().'PortalUser'); $this->Page = isset($_GET['lpn']) ? $_GET['lpn'] : 1; $this->EnablePaging = true; - $this->PerPageVar = "Perpage_User"; + $this->PerPageVar = "Perpage_User"; $this->AdminSearchFields = array("Login","FirstName","LastName","Email","Street","City", "State","Zip","Country","Phone"); } @@ -834,7 +834,7 @@ } else { - $var_list_update["t"] = $var_list["t"]; + $var_list_update["t"] = $var_list["t"]; } $o = ""; if($this->Page>1) @@ -847,7 +847,7 @@ $m_var_list_update["p"]=$this->Page+1; $next_url = HREF_Wrapper(); } - + for($p=1;$p<=$NumPages;$p++) { $t = template($link_template); @@ -916,57 +916,57 @@ $u = $this->GetUser($result->fields["PortalUserId"]); return $u; } - - function &Add_User($Login, $Password, $Email, $CreatedOn, $FirstName="", $LastName="", $Status=2, + + function &Add_User($Login, $Password, $Email, $CreatedOn, $FirstName="", $LastName="", $Status=2, $Phone="", $Street="", $City="", $State="", $Zip="", $Country="", $dob=0, $ip="", $CheckBanned=FALSE) { $u = new clsPortalUser(NULL); $u->tablename = $this->SourceTable; //echo "Creating User..
\n"; - $u->Set(array("Login", "Password", "FirstName", "LastName", "Email", "Status", - "Phone","Street", "City", "State", "Zip", "Country", "CreatedOn","dob"), - array($Login, $Password, $FirstName, $LastName, $Email, $Status, + $u->Set(array("Login", "Password", "FirstName", "LastName", "Email", "Status", + "Phone","Street", "City", "State", "Zip", "Country", "CreatedOn","dob"), + array($Login, $Password, $FirstName, $LastName, $Email, $Status, $Phone, $Street, $City, $State, $Zip, $Country, $CreatedOn, $dob)); - + $BrokenRule = $CheckBanned ? $u->CheckBanned() : false; - - if(!$BrokenRule) - { + + if(!$BrokenRule) + { $u->Create(); $this->processEvent($u, 'OnAfterItemCreate'); return $u; } - return $BrokenRule; + return $BrokenRule; /*md5($Password)*/ } function &Add_User_NEW($fields_hash, $check_banned = false) { $user = new clsPortalUser(NULL); $user->tablename = $this->SourceTable; - + foreach ($fields_hash as $field_name => $field_value) { $user->Set($field_name, $field_value); } - + $broken_rule = $check_banned ? $user->CheckBanned() : false; - if (!$BrokenRule) { + if (!$broken_rule) { $user->Create(); $this->processEvent($user, 'OnAfterItemCreate'); return $user; } - - return $BrokenRule; + + return $BrokenRule; } - + function &Edit_User_NEW($id, $fields_hash) - { + { $user =& $this->GetItem($id); - + if (!is_object($user)) { return $user; } - + $fields_hash['IsBanned'] = $user->Get('IsBanned'); if ($fields_hash['Status'] == 1) { $fields_hash['IsBanned'] = 0; @@ -975,44 +975,44 @@ if (isset($fields_hash['Password']) && !$fields_hash['Password']) { unset($fields_hash['Password']); } - + foreach ($fields_hash as $field_name => $field_value) { $user->Set($field_name, $field_value); } - + $user->Update(); $this->processEvent($user, 'OnAfterItemUpdate'); - - return $user; + + return $user; } - - function &Edit_User($UserId, $Login, $Password, $Email, $CreatedOn, $FirstName="", $LastName="", + + function &Edit_User($UserId, $Login, $Password, $Email, $CreatedOn, $FirstName="", $LastName="", $Status=2, $Phone="", $Street="", $City="", $State="", $Zip="", $Country="", $dob=0, $MinPwResetDelay=300) - { + { //echo "Editing User: [$UserId]
"; - + $u =& $this->GetItem($UserId); - + if(!$CreatedOn) $CreatedOn = $u->Get("CreatedOn"); - -// $u->debuglevel=1; - + +// $u->debuglevel=1; + if (is_object($u)) { $IsBanned = $u->Get('IsBanned'); if($Status == 1) $IsBanned = 0; - $u->Set(array("Login", "FirstName", "LastName", "Email", "Status", - "Phone", "Street", "City", "State", "Zip", "Country", "CreatedOn","dob","IsBanned", "MinPwResetDelay"), - array($Login, $FirstName, $LastName, $Email, $Status, + $u->Set(array("Login", "FirstName", "LastName", "Email", "Status", + "Phone", "Street", "City", "State", "Zip", "Country", "CreatedOn","dob","IsBanned", "MinPwResetDelay"), + array($Login, $FirstName, $LastName, $Email, $Status, $Phone, $Street, $City, $State, $Zip, $Country, $CreatedOn,$dob,$IsBanned,$MinPwResetDelay)); if(strlen($Password)) - $u->Set("Password",$Password); + $u->Set("Password",$Password); $u->Update(); } - + $this->processEvent($u, 'OnAfterItemUpdate'); - return $u; + return $u; } /** @@ -1026,22 +1026,22 @@ if ($user->UsingTempTable()) { return true; } - + $user_dummy =& $this->Application->recallObject('u.-item', null, Array('skip_autoload' => true)); $user_dummy->SetDBFieldsFromHash($user->Data); $user_dummy->setID($user->UniqueId()); - + $event = new kEvent('u.-item:'.$event_name); $event->setEventParam('id', $user_dummy->GetID() ); $this->Application->HandleEvent($event); } - + function Delete_User($UserId) { $u = $this->GetItemByField("ResourceId",$UserId); if(is_object($u)) { - $u->RemoveFromAllGroups(); + $u->RemoveFromAllGroups(); $u->Delete(); } } @@ -1092,7 +1092,7 @@ $utable = $this->SourceTable; $gtable = GetTablePrefix()."UserGroup"; $sql = "SELECT * FROM $utable LEFT JOIN $gtable ON ($utable.PortalUserId=$gtable.PortalUserId)"; - + if(isset($whereClause)) $sql = sprintf('%s WHERE %s',$sql,$whereClause); @@ -1102,7 +1102,7 @@ if(isset($limitClause)) $sql = sprintf('%s %s',$sql,$limitClause); - + return $this->Query_Item($sql); } @@ -1121,7 +1121,7 @@ if(isset($orderByClause)) $sql = sprintf('%s ORDER BY %s',$sql,$orderByClause); - + return $this->query_item($sql); } @@ -1140,33 +1140,33 @@ { return $this->UserCount("Status=2"); } - + function CountDisabled() { return $this->UserCount("Status=0"); } - + function CopyFromEditTable($idfield) { global $objSession; - + $this->Application->SetVar('u_mode', ''); $GLOBALS['_CopyFromEditTable']=1; - $edit_table = $objSession->GetEditTable($this->SourceTable); + $edit_table = $objSession->GetEditTable($this->SourceTable); $sql = "SELECT * FROM $edit_table"; $rs = $this->adodbConnection->Execute($sql); $user_dummy =& $this->Application->recallObject('u.-item', null, Array('skip_autoload' => true)); - + $item_ids = Array(); while ($rs && !$rs->EOF) { - $data = $rs->fields; + $data = $rs->fields; $c = new $this->classname; $c->SetFromArray($data); $c->idfield = $idfield; $c->Dirty(); $user_dummy->SetDBFieldsFromHash($data); - + if ($c->Get($idfield) < 1) { $old_id = $c->Get($idfield); $c->UnsetIdField(); @@ -1181,28 +1181,28 @@ $event_name = 'OnAfterItemUpdate'; } $user_dummy->setID($c->UniqueId()); - + // process after hooks: begin $event = new kEvent('u.-item:'.$event_name); $event->setEventParam('id', $user_dummy->GetID() ); $this->Application->HandleEvent($event); // process after hooks: end - + $item_ids[] = $c->UniqueId(); - - unset($c); + + unset($c); $rs->MoveNext(); - } - @$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table"); + } + @$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table"); unset($GLOBALS['_CopyFromEditTable']); return $item_ids; } - + function PurgeEditTable() { parent::PurgeEditTable(); $sql = "DELETE FROM ".GetTablePrefix()."UserGroup WHERE PortalUserId=0"; $this->adodbConnection->Execute($sql); - } + } } /*clsUserManager*/ ?>