Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1032819
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jun 19, 8:37 AM
Size
114 KB
Mime Type
text/x-diff
Expires
Sat, Jun 21, 8:37 AM (25 m, 14 s)
Engine
blob
Format
Raw Data
Handle
667349
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/unlabeled/unlabeled-1.64.2/kernel/units/users/users_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.64.2/kernel/units/users/users_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.64.2/kernel/units/users/users_event_handler.php (revision 6140)
@@ -0,0 +1,1033 @@
+<?php
+
+ class UsersEventHandler extends InpDBEventHandler
+ {
+ /**
+ * Allows to override standart permission mapping
+ *
+ */
+ function mapPermissions()
+ {
+ parent::mapPermissions();
+ $permissions = Array(
+ // admin
+ 'OnSetPersistantVariable' => Array('self' => 'view'), // because setting to logged in user only
+
+ // front
+ 'OnRefreshForm' => Array('self' => true),
+
+ 'OnForgotPassword' => Array('self' => true),
+ 'OnResetPassword' => Array('self' => true),
+ 'OnResetPasswordConfirmed' => Array('self' => true),
+
+ 'OnSubscribeQuery' => Array('self' => true),
+ 'OnSubscribeUser' => Array('self' => true),
+
+ 'OnRecommend' => Array('self' => true),
+ );
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Checks permissions of user
+ *
+ * @param kEvent $event
+ */
+ function CheckPermission(&$event)
+ {
+ if ($event->Name == 'OnLogin' || $event->Name == 'OnLogout') {
+ // permission is checked in OnLogin event directly
+ return true;
+ }
+
+ if (!$this->Application->IsAdmin()) {
+ $user_id = $this->Application->GetVar('u_id');
+ $items_info = $this->Application->GetVar($event->getPrefixSpecial(true));
+
+ if ($event->Name == 'OnCreate' && $user_id == -2) {
+ // "Guest" can create new users
+ return true;
+ }
+
+ if ($event->Name == 'OnUpdate' && $user_id > 0) {
+ $user_dummy =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true));
+ foreach ($items_info as $id => $field_values) {
+ if ($id != $user_id) {
+ // registered users can update their record only
+ return false;
+ }
+
+ $user_dummy->Load($id);
+ $status_field = array_shift($this->Application->getUnitOption($event->Prefix, 'StatusField'));
+
+ if ($user_dummy->GetDBField($status_field) != STATUS_ACTIVE) {
+ // not active user is not allowed to update his record (he could not activate himself manually)
+ return false;
+ }
+
+ if (isset($field_values[$status_field]) && $user_dummy->GetDBField($status_field) != $field_values[$status_field]) {
+ // user can't change status by himself
+ return false;
+ }
+ }
+ return true;
+ }
+
+ if ($event->Name == 'OnUpdate' && $user_id <= 0) {
+ // guests are not allowed to update their record, because they don't have it :)
+ return false;
+ }
+ }
+
+ return parent::CheckPermission($event);
+ }
+
+ function OnSessionExpire()
+ {
+ if( $this->Application->IsAdmin() ) {
+ $this->Application->Redirect('index', Array('expired' => 1), '', 'index.php');
+ }
+ else {
+ $http_query =& $this->Application->recallObject('HTTPQuery');
+ $get = $http_query->getRedirectParams();
+
+ $t = $this->Application->GetVar('t');
+ $get['js_redirect'] = $this->Application->ConfigValue('UseJSRedirect');
+ $this->Application->Redirect($t ? $t : 'index', $get);
+ }
+ }
+
+ /**
+ * Checks user data and logs it in if allowed
+ *
+ * @param kEvent $event
+ */
+ function OnLogin(&$event)
+ {
+ $object =& $this->Application->recallObject('u', null, Array('skip_autoload' => true));
+
+ $password = $this->Application->GetVar('password');
+ if(!$password)
+ {
+ $object->SetError('ValidateLogin', 'blank_password', 'lu_blank_password');
+ $event->status = erFAIL;
+ return false;
+ }
+
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ list($login_field, $submit_field) = $email_as_login && !$this->Application->IsAdmin() ? Array('Email', 'email') : Array('Login', 'login');
+ $login_value = $this->Application->GetVar($submit_field);
+
+ if ($this->Application->IsAdmin() && ($login_value == 'root')) {
+ // logging in "root" (admin only)
+ $root_password = $this->Application->ConfigValue('RootPass');
+ if ($root_password != md5($password)) {
+ $object->SetError('ValidateLogin', 'invalid_password', 'lu_invalid_password');
+ $event->status = erFAIL;
+ return false;
+ }
+ elseif ($this->checkLoginPermission($login_value)) {
+ $user_id = -1;
+ $object->Load($user_id);
+ $object->SetDBField('Login', $login_value);
+
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', $user_id);
+// $session->SetField('GroupList', implode(',', $groups) );
+ $this->Application->SetVar('u_id', $user_id);
+ $this->Application->StoreVar('user_id', $user_id);
+
+ $this->processLoginRedirect($event, $password);
+ return true;
+ }
+ else {
+ $object->SetError('ValidateLogin', 'invalid_license', 'la_invalid_license');
+ $event->status = erFAIL;
+ return false;
+ }
+ }
+
+ /*$sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (%s = %s) AND (Password = MD5(%s))';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $login_field, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );*/
+
+ $sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (Email = %1$s OR Login = %1$s) AND (Password = MD5(%2$s))';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );
+
+ if ($user_id) {
+ $object->Load($user_id);
+ if ($object->GetDBField('Status') == STATUS_ACTIVE) {
+ $groups = $object->getMembershipGroups(true);
+ if(!$groups) $groups = Array();
+ array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') );
+ $this->Application->StoreVar( 'UserGroups', implode(',', $groups) );
+
+ if ($this->checkLoginPermission($login_value)) {
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', $user_id);
+ $session->SetField('GroupList', implode(',', $groups) );
+ $this->Application->SetVar('u_id', $user_id);
+ $this->Application->StoreVar('user_id', $user_id);
+ $this->Application->setVisitField('PortalUserId', $user_id);
+
+ $this_login = (int)$object->getPersistantVar('ThisLogin');
+ $object->setPersistantVar('LastLogin', $this_login);
+ $object->setPersistantVar('ThisLogin', adodb_mktime());
+ }
+ else {
+ $object->Load(-2);
+ $object->SetError('ValidateLogin', 'no_permission', 'lu_no_permissions');
+ $event->status = erFAIL;
+ }
+
+ $this->processLoginRedirect($event, $password);
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('pending_disabled_template');
+ }
+ }
+ else
+ {
+ $object->SetID(-2);
+ $object->SetError('ValidateLogin', 'invalid_password', 'lu_invalid_password');
+ $event->status = erFAIL;
+ }
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param string $user_name
+ * @return bool
+ */
+ function checkLoginPermission($user_name)
+ {
+ $ret = true;
+ if ($this->Application->IsAdmin()) {
+ $modules_helper =& $this->Application->recallObject('ModulesHelper');
+ if ($user_name != 'root') {
+ // root is virtual user, so allow him to login to admin in any case
+ $ret = $this->Application->CheckPermission('ADMIN', 1);
+ }
+ $ret = $ret && $modules_helper->checkLogin();
+ }
+ else {
+ $ret = $this->Application->CheckPermission('LOGIN', 1);
+ }
+ return $ret;
+ }
+
+ /**
+ * Process all required data and redirect logged-in user
+ *
+ * @param kEvent $event
+ */
+ function processLoginRedirect(&$event, $password)
+ {
+ $object =& $event->getObject();
+
+ $next_template = $this->Application->GetVar('next_template');
+ if ($next_template == '_ses_redirect') {
+ $location = $this->Application->BaseURL().$this->Application->RecallVar($next_template);
+ if( $this->Application->isDebugMode() && constOn('DBG_REDIRECT') )
+ {
+ $this->Application->Debugger->appendTrace();
+ echo "<b>Debug output above!!!</b> Proceed to redirect: <a href=\"$location\">$location</a><br>";
+ }
+ else {
+ header('Location: '.$location);
+ }
+
+ $session =& $this->Application->recallObject('Session');
+ $session->SaveData();
+ exit;
+ }
+
+ if ($next_template) {
+ $event->redirect = $next_template;
+ }
+
+ if ($this->Application->ConfigValue('UseJSRedirect')) {
+ $event->SetRedirectParam('js_redirect', 1);
+ }
+
+ $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LoginUser', $object->GetDBField('Login'), $password);
+ }
+
+ /**
+ * Called when user logs in using old in-portal
+ *
+ * @param kEvent $event
+ */
+ function OnInpLogin(&$event)
+ {
+ $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LoginUser', $event->getEventParam('user'), $event->getEventParam('pass') );
+
+ if ($event->redirect && is_string($event->redirect)) {
+ // some real template specified instead of true
+ $this->Application->Redirect($event->redirect, $event->redirect_params);
+ }
+ }
+
+ /**
+ * Called when user logs in using old in-portal
+ *
+ * @param kEvent $event
+ */
+ function OnInpLogout(&$event)
+ {
+ $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LogoutUser');
+ }
+
+ function OnLogout(&$event)
+ {
+ $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LogoutUser');
+
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', -2);
+ $this->Application->SetVar('u_id', -2);
+ $this->Application->StoreVar('user_id', -2);
+ $object =& $this->Application->recallObject('u');
+ $object->Load(-2);
+
+ $this->Application->DestroySession();
+
+ $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup');
+ $session->SetField('GroupList', $group_list);
+ $this->Application->StoreVar('UserGroups', $group_list);
+
+ if ($this->Application->ConfigValue('UseJSRedirect')) {
+ $event->SetRedirectParam('js_redirect', 1);
+ }
+ }
+
+ /**
+ * Prefill states dropdown with correct values
+ *
+ * @param kEvent $event
+ * @access public
+ */
+ function OnPrepareStates(&$event)
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->PopulateStates($event, 'State', 'Country');
+
+ $object =& $event->getObject();
+
+ if( $object->isRequired('Country') && $cs_helper->CountryHasStates( $object->GetDBField('Country') ) ) $object->setRequired('State', true);
+ $object->setLogin();
+ }
+
+ /**
+ * Redirects user after succesfull registration to confirmation template (on Front only)
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemCreate(&$event)
+ {
+ $is_subscriber = $this->Application->GetVar('IsSubscriber');
+ if(!$is_subscriber)
+ {
+ $object =& $event->getObject();
+
+ $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
+ SET PrimaryGroup = 0
+ WHERE PortalUserId = '.$object->GetDBField('PortalUserId');
+ $this->Conn->Query($sql);
+
+ $group_id = $this->Application->ConfigValue('User_NewGroup');
+
+ $sql = 'REPLACE INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,1)';
+ $this->Conn->Query( sprintf($sql, $object->GetID(), $group_id) );
+ }
+ }
+
+ /**
+ * Login user if possible, if not then redirect to corresponding template
+ *
+ * @param kEvent $event
+ */
+ function autoLoginUser(&$event)
+ {
+ $object =& $event->getObject();
+ $this->Application->SetVar('u_id', $object->GetID() );
+
+ if($object->GetDBField('Status') == STATUS_ACTIVE)
+ {
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
+
+ $this->Application->SetVar($submit_field, $object->GetDBField($login_field) );
+ $this->Application->SetVar('password', $object->GetDBField('Password_plain') );
+
+ $event->CallSubEvent('OnLogin');
+ }
+ }
+
+
+ /**
+ * When creating user & user with such email exists then force to use OnUpdate insted of ?
+ *
+ * @param kEvent $event
+ */
+ function OnSubstituteSubscriber(&$event)
+ {
+ $ret = false;
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
+ if($items_info)
+ {
+ list($id, $field_values) = each($items_info);
+ $user_email = $field_values['Email'];
+ if($user_email)
+ {
+ // check if is subscriber
+ $verify_user =& $this->Application->recallObject('u.verify', null, Array('skup_autoload' => true) );
+ $verify_user->Load($user_email, 'Email');
+ if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() )
+ {
+ $items_info = Array( $verify_user->GetDBField('PortalUserId') => $field_values );
+ $this->Application->SetVar($event->getPrefixSpecial(true), $items_info);
+ $ret = true;
+ }
+ }
+ }
+
+ if( isset($event->MasterEvent) )
+ {
+ $event->MasterEvent->setEventParam('is_subscriber_only', $ret);
+ }
+ else
+ {
+ $event->setEventParam('is_subscriber_only', $ret);
+ }
+ }
+
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ * @return bool
+ */
+ function isSubscriberOnly(&$event)
+ {
+ $event->CallSubEvent('OnSubstituteSubscriber');
+ $is_subscriber = false;
+ if( $event->getEventParam('is_subscriber_only') )
+ {
+ $is_subscriber = true;
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $this->OnUpdate($event);
+ if($event->status == erSUCCESS)
+ {
+ $this->OnAfterItemCreate($event);
+ $object->SendEmailEvents();
+ if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect) $this->autoLoginUser($event);
+ }
+ }
+ return $is_subscriber;
+ }
+
+ /**
+ * Creates new user
+ *
+ * @param kEvent $event
+ */
+ function OnCreate(&$event)
+ {
+ if( !$this->Application->IsAdmin() ) $this->setUserStatus($event);
+
+ if( !$this->isSubscriberOnly($event) )
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->CheckStateField($event, 'State', 'Country');
+
+ parent::OnCreate($event);
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+
+ $this->Application->SetVar('u_id', $object->getID() );
+
+ $this->setNextTemplate($event);
+
+ if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect)
+ {
+ $object->SendEmailEvents();
+ $this->autoLoginUser($event);
+ }
+ }
+ }
+
+ /**
+ * Set's new user status based on config options
+ *
+ * @param kEvent $event
+ */
+ function setUserStatus(&$event)
+ {
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+
+ $new_users_allowed = $this->Application->ConfigValue('User_Allow_New');
+ // 1 - Instant, 2 - Not Allowed, 3 - Pending
+
+ switch ($new_users_allowed)
+ {
+ case 1: // Instant
+ $object->SetDBField('Status', 1);
+ $next_template = $this->Application->GetVar('registration_confirm_template');
+ if($next_template) $event->redirect = $next_template;
+ break;
+
+ case 3: // Pending
+ $next_template = $this->Application->GetVar('registration_confirm_pending_template');
+ if($next_template) $event->redirect = $next_template;
+ $object->SetDBField('Status', 2);
+ break;
+
+ case 2: // Not Allowed
+ $object->SetDBField('Status', 0);
+ break;
+ }
+
+ /*if ($object->GetDBField('PaidMember') == 1) {
+ $this->Application->HandleEvent($add_to_cart, 'ord:OnAddToCart');
+ $event->redirect = 'in-commerce/checkout/shop_cart';
+ } */
+
+ }
+
+
+
+
+ /**
+ * Set's new unique resource id to user
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemCreate(&$event)
+ {
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ $object =& $event->getObject();
+ if ($email_as_login) {
+ $object->Fields['Email']['error_msgs']['unique'] = $this->Application->Phrase('lu_user_and_email_already_exist');
+ }
+
+ }
+
+ /**
+ * Set's new unique resource id to user
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemValidate(&$event)
+ {
+ $object =& $event->getObject();
+ $resource_id = $object->GetDBField('ResourceId');
+ if (!$resource_id)
+ {
+ $object->SetDBField('ResourceId', $this->Application->NextResourceId() );
+ }
+ }
+
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnRecommend(&$event){
+
+ $friend_email = $this->Application->GetVar('friend_email');
+ $friend_name = $this->Application->GetVar('friend_email');
+
+ if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $friend_email))
+ {
+
+ $send_params = array();
+ $send_params['to_email']=$friend_email;
+ $send_params['to_name']=$friend_name;
+
+ $user_id = $this->Application->GetVar('u_id');
+ $email_event = &$this->Application->EmailEventUser('SITE.SUGGEST', $user_id, $send_params);
+
+ if ($email_event->status == erSUCCESS){
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+ else {
+// $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+// $event->redirect = $this->Application->GetVar('template_fail');
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['send_error'] = $this->Application->Phrase('lu_email_send_error');
+ $object->FieldErrors['Email']['pseudo'] = 'send_error';
+ $event->status = erFAIL;
+
+ }
+ }
+ else {
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
+ $object->FieldErrors['Email']['pseudo'] = 'invalid_email';
+ $event->status = erFAIL;
+ }
+
+
+ }
+
+ /**
+ * Saves address changes and mades no redirect
+ *
+ * @param kEvent $event
+ */
+ function OnUpdateAddress(&$event)
+ {
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+
+ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
+ if($items_info)
+ {
+ list($id,$field_values) = each($items_info);
+ if($id > 0) $object->Load($id);
+ $object->SetFieldsFromHash($field_values);
+ $object->setID($id);
+ $object->Validate();
+ }
+
+ $event->redirect = false;
+ }
+
+ function OnSubscribeQuery(&$event){
+
+ $user_email = $this->Application->GetVar('subscriber_email');
+ if ( preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email) ){
+
+ $object = &$this->Application->recallObject($this->Prefix.'.subscriber', null, Array('skip_autoload' => true));
+
+ $this->Application->StoreVar('SubscriberEmail', $user_email);
+
+ if( $object->Load(array('Email'=>$user_email)) ){
+ $group_info = $this->GetGroupInfo($object->GetID());
+ if($group_info){
+ $event->redirect = $this->Application->GetVar('unsubscribe_template');
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('subscribe_template');
+ }
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('subscribe_template');
+ $this->Application->StoreVar('SubscriberEmail', $user_email);
+ }
+
+ }
+ else {
+
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
+ $object->FieldErrors['SubscribeEmail']['pseudo'] = 'invalid_email';
+ $event->status = erFAIL;
+
+ }
+
+
+ //subscribe_query_ok_template
+ }
+
+ function OnSubscribeUser(&$event){
+
+ $object = &$this->Application->recallObject($this->Prefix.'.subscriber', Array('skip_autoload' => true));
+
+ $user_email = $this->Application->RecallVar('SubscriberEmail');
+
+ if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email)){
+
+ if($object->Load(array('Email'=>$user_email))){
+
+ $group_info = $this->GetGroupInfo($object->GetID());
+
+ if ($group_info){
+ if ($event->getEventParam('no_unsubscribe')) return;
+
+ if ($group_info['PrimaryGroup']){
+ // delete user
+ $object->Delete();
+ }
+ else {
+ $this->RemoveSubscriberGroup($object->GetID());
+ }
+
+ $event->redirect = $this->Application->GetVar('unsubscribe_ok_template');
+
+ }
+ else {
+ $this->AddSubscriberGroup($object->GetID(), 0);
+ $event->redirect = $this->Application->GetVar('subscribe_ok_template');
+ }
+
+
+ }
+ else {
+
+ $object->SetField('Email', $user_email);
+ $object->SetField('Login', $user_email);
+ $object->SetDBField('dob', 1);
+ $object->SetDBField('dob_date', 1);
+ $object->SetDBField('dob_time', 1);
+ $ip = getenv('HTTP_X_FORWARDED_FOR')?getenv('HTTP_X_FORWARDED_FOR'):getenv('REMOTE_ADDR');
+ $object->SetDBField('ip', $ip);
+
+ $this->Application->SetVar('IsSubscriber', 1);
+
+ if ($object->Create()) {
+
+ $this->AddSubscriberGroup($object->GetID(), 1);
+ $event->redirect = $this->Application->GetVar('subscribe_ok_template');
+ }
+
+ $this->Application->SetVar('IsSubscriber', 0);
+ }
+ }
+ else {
+ // error handling here
+ $event->redirect = $this->Application->GetVar('subscribe_fail_template');
+ }
+
+
+ }
+
+ function AddSubscriberGroup($user_id, $is_primary){
+
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+ $sql = 'INSERT INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,'.$is_primary.')';
+ $this->Conn->Query( sprintf($sql, $user_id, $group_id) );
+ $this->Application->EmailEventAdmin('USER.SUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.SUBSCRIBE', $user_id);
+
+ }
+
+ function RemoveSubscriberGroup($user_id){
+
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$user_id.' AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup');
+ $this->Conn->Query($sql);
+ $this->Application->EmailEventAdmin('USER.UNSUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.UNSUBSCRIBE', $user_id);
+
+ }
+
+ function GetGroupInfo($user_id){
+
+ $group_info = $this->Conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'UserGroup
+ WHERE PortalUserId='.$user_id.'
+ AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup'));
+ return $group_info;
+
+ }
+
+ function OnForgotPassword(&$event){
+
+ $user_object = &$this->Application->recallObject('u.forgot', null, Array('skip_autoload' => true));
+ $user_current_object = &$this->Application->recallObject('u');
+
+ $username = $this->Application->GetVar('username');
+ $email = $this->Application->GetVar('email');
+ $found = false;
+ $allow_reset = true;
+
+ if( strlen($username) )
+ {
+ if( $user_object->Load(array('Login'=>$username)) )
+ $found = ($user_object->GetDBField("Login")==$username && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
+ }
+ else if( strlen($email) )
+ {
+ if( $user_object->Load(array('Email'=>$email)) )
+ $found = ($user_object->GetDBField("Email")==$email && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
+ }
+
+ if( $user_object->isLoaded() )
+ {
+ $PwResetConfirm = $user_object->GetDBField('PwResetConfirm');
+ $PwRequestTime = $user_object->GetDBField('PwRequestTime');
+ $PassResetTime = $user_object->GetDBField('PassResetTime');
+ //$MinPwResetDelay = $user_object->GetDBField('MinPwResetDelay');
+ $MinPwResetDelay = $this->Application->ConfigValue('Users_AllowReset');
+
+ $allow_reset = (strlen($PwResetConfirm) ?
+ adodb_mktime() > $PwRequestTime + $MinPwResetDelay :
+ adodb_mktime() > $PassResetTime + $MinPwResetDelay);
+ }
+
+ if($found && $allow_reset)
+ {
+ $this->Application->StoreVar('tmp_user_id', $user_object->GetDBField("PortalUserId"));
+ $this->Application->StoreVar('tmp_email', $user_object->GetDBField("Email"));
+ $this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
+
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+ else
+ {
+ if(!strlen($username) && !strlen($email))
+ {
+ $user_current_object->ErrorMsgs['forgotpw_nodata'] = $this->Application->Phrase('lu_ferror_forgotpw_nodata');
+ $user_current_object->FieldErrors['Login']['pseudo'] = 'forgotpw_nodata';
+ $user_current_object->FieldErrors['Email']['pseudo'] = 'forgotpw_nodata';
+ }
+ else
+ {
+ if($allow_reset)
+ {
+ if( strlen($username) ){
+ $user_current_object->ErrorMsgs['unknown_username'] = $this->Application->Phrase('lu_ferror_unknown_username');
+ $user_current_object->FieldErrors['Login']['pseudo']='unknown_username';
+ }
+ if( strlen($email) ){
+ $user_current_object->ErrorMsgs['unknown_email'] = $this->Application->Phrase('lu_ferror_unknown_email');
+ $user_current_object->FieldErrors['Email']['pseudo']='unknown_email';
+ }
+ }
+ else
+ {
+ $user_current_object->ErrorMsgs['reset_denied'] = $this->Application->Phrase('lu_ferror_reset_denied');
+ if( strlen($username) ){
+ $user_current_object->FieldErrors['Login']['pseudo']='reset_denied';
+ }
+ if( strlen($email) ){
+ $user_current_object->FieldErrors['Email']['pseudo']='reset_denied';
+ }
+ }
+ }
+
+ if($user_current_object->FieldErrors){
+ $event->redirect = false;
+ }
+ }
+
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnResetPassword(&$event){
+
+ $user_object = &$this->Application->recallObject('u.forgot');
+
+ if($user_object->Load($this->Application->RecallVar('tmp_user_id'))){
+
+ $this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
+ $event->redirect = $this->Application->GetVar('template_success');
+
+ $mod_object =& $this->Application->recallObject('mod.'.'In-Commerce');
+ $m_cat_id = $mod_object->GetDBField('RootCat');
+ $event->SetRedirectParam('pass', 'm');
+ //$event->SetRedirectParam('m_cat_id', $m_cat_id);
+ $this->Application->SetVar('m_cat_id', $m_cat_id);
+
+
+ }
+
+ }
+
+ function OnResetPasswordConfirmed(&$event){
+
+ $passed_key = $this->Application->GetVar('user_key');
+
+ $user_object = &$this->Application->recallObject('u.forgot');
+ $user_current_object = &$this->Application->recallObject('u');
+
+ if (strlen(trim($passed_key)) == 0) {
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = false;
+
+ $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
+ }
+
+
+ if($user_object->Load(array('PwResetConfirm'=>$passed_key)))
+ {
+ $exp_time = $user_object->GetDBField('PwRequestTime') + 3600;
+ $user_object->SetDBField("PwResetConfirm", '');
+ $user_object->SetDBField("PwRequestTime", 0);
+ if ( $exp_time > adodb_mktime() )
+ {
+ //$m_var_list_update['codevalidationresult'] = 'lu_resetpw_confirm_text';
+ $newpw = makepassword4();
+
+ $this->Application->StoreVar('password', $newpw);
+
+ $user_object->SetDBField("Password",$newpw);
+ $user_object->SetDBField("PassResetTime", adodb_mktime());
+ $user_object->SetDBField("PwResetConfirm", '');
+ $user_object->SetDBField("PwRequestTime", 0);
+ $user_object->Update();
+
+ $this->Application->SetVar('ForgottenPassword', $newpw);
+
+ $email_event_user = &$this->Application->EmailEventUser('INCOMMERCEUSER.PSWD', $user_object->GetDBField('PortalUserId'));
+ $email_event_admin = &$this->Application->EmailEventAdmin('INCOMMERCEUSER.PSWD');
+
+ $this->Application->DeleteVar('ForgottenPassword');
+
+ if ($email_event_user->status == erSUCCESS){
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+
+ $user_object->SetDBField("Password",md5($newpw));
+ $user_object->Update();
+
+ } else {
+ $user_current_object->ErrorMsgs['code_expired'] = $this->Application->Phrase('lu_code_expired');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_expired';
+ $event->redirect = false;
+
+ }
+ } else {
+ $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
+ $event->redirect = false;
+
+ }
+ }
+
+ function OnUpdate(&$event)
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->CheckStateField($event, 'State', 'Country');
+
+ parent::OnUpdate($event);
+
+ $this->setNextTemplate($event);
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function setNextTemplate(&$event)
+ {
+ if( !$this->Application->IsAdmin() )
+ {
+ $event->redirect_params['opener'] = 's';
+ $object =& $event->getObject();
+ if($object->GetDBField('Status') == STATUS_ACTIVE)
+ {
+ $next_template = $this->Application->GetVar('next_template');
+ if($next_template) $event->redirect = $next_template;
+ }
+ }
+ }
+
+
+
+ /**
+ * Delete users from groups if their membership is expired
+ *
+ * @param kEvent $event
+ */
+ function OnCheckExpiredMembership(&$event)
+ {
+ // send pre-expiration reminders: begin
+ $pre_expiration = adodb_mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24;
+ $sql = 'SELECT PortalUserId, GroupId
+ FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (ExpirationReminderSent = 0) AND (MembershipExpires < '.$pre_expiration.')';
+
+ $skip_clause = $event->getEventParam('skip_clause');
+ if ($skip_clause) {
+ $sql .= ' AND !('.implode(') AND !(', $skip_clause).')';
+ }
+
+ $records = $this->Conn->Query($sql);
+ if ($records) {
+ $conditions = Array();
+ foreach ($records as $record) {
+ $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRATION.NOTICE', $record['PortalUserId']);
+ $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRATION.NOTICE');
+ $conditions[] = '(PortalUserId = '.$record['PortalUserId'].' AND GroupId = '.$record['GroupId'].')';
+ }
+ $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
+ SET ExpirationReminderSent = 1
+ WHERE '.implode(' OR ', $conditions);
+ $this->Conn->Query($sql);
+ }
+ // send pre-expiration reminders: end
+
+ // remove users from groups with expired membership: begin
+ $sql = 'SELECT PortalUserId
+ FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
+ $user_ids = $this->Conn->GetCol($sql);
+ if ($user_ids) {
+ foreach ($user_ids as $id) {
+ $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRED', $id);
+ $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRED');
+ }
+ }
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
+ $this->Conn->Query($sql);
+ // remove users from groups with expired membership: end
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnRefreshForm(&$event)
+ {
+ $event->redirect = false;
+ $item_info = $this->Application->GetVar($event->Prefix_Special);
+ list($id, $fields) = each($item_info);
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object->setID($id);
+ $object->IgnoreValidation = true;
+ $object->SetFieldsFromHash($fields);
+ }
+
+ /**
+ * Sets persistant variable
+ *
+ * @param kEvent $event
+ */
+ function OnSetPersistantVariable(&$event)
+ {
+ $object =& $event->getObject();
+
+ $field = $this->Application->GetVar('field');
+ $value = $this->Application->GetVar('value');
+ $object->setPersistantVar($field, $value);
+
+ $force_tab = $this->Application->GetVar('SetTab');
+ if ($force_tab) {
+ $this->Application->StoreVar('force_tab', $force_tab);
+ }
+ }
+
+ /**
+ * Overwritten to return user from order by special .ord
+ *
+ * @param kEvent $event
+ */
+ function getPassedId(&$event)
+ {
+ if ($event->Special == 'ord') {
+ $order =& $this->Application->recallObject('ord');
+ return $order->GetDBField('PortalUserId');
+ }
+ return parent::getPassedID($event);
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.64.2/kernel/units/users/users_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.64
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.64.2/core/kernel/db/db_tag_processor.php
===================================================================
--- branches/unlabeled/unlabeled-1.64.2/core/kernel/db/db_tag_processor.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.64.2/core/kernel/db/db_tag_processor.php (revision 6140)
@@ -0,0 +1,1580 @@
+<?php
+
+class kDBTagProcessor extends TagProcessor {
+
+ /**
+ * Description
+ *
+ * @var kDBConnection
+ * @access public
+ */
+ var $Conn;
+
+ function kDBTagProcessor()
+ {
+ parent::kBase();
+ $this->Conn =& $this->Application->GetADODBConnection();
+ }
+
+
+ /**
+ * Returns true if "new" button was pressed in toolbar
+ *
+ * @param Array $params
+ * @return bool
+ */
+ function IsNewMode($params)
+ {
+ $object =& $this->getObject($params);
+ return $object->GetID() <= 0;
+ }
+
+ /**
+ * Returns view menu name for current prefix
+ *
+ * @param Array $params
+ * @return string
+ */
+ function GetItemName($params)
+ {
+ $item_name = $this->Application->getUnitOption($this->Prefix, 'ViewMenuPhrase');
+ return $this->Application->Phrase($item_name);
+ }
+
+ function ViewMenu($params)
+ {
+ $block_params = $params;
+ unset($block_params['block']);
+ $block_params['name'] = $params['block'];
+
+ $list =& $this->GetList($params);
+ $block_params['PrefixSpecial'] = $list->getPrefixSpecial();
+ return $this->Application->ParseBlock($block_params);
+ }
+
+ function SearchKeyword($params)
+ {
+ $list =& $this->GetList($params);
+ return $this->Application->RecallVar($list->getPrefixSpecial().'_search_keyword');
+ }
+
+ /**
+ * Draw filter menu content (for ViewMenu) based on filters defined in config
+ *
+ * @param Array $params
+ * @return string
+ */
+ function DrawFilterMenu($params)
+ {
+ $block_params = $this->prepareTagParams($params);
+ $block_params['name'] = $params['spearator_block'];
+ $separator = $this->Application->ParseBlock($block_params);
+ $filter_menu = $this->Application->getUnitOption($this->Prefix,'FilterMenu');
+ if(!$filter_menu)
+ {
+ trigger_error('<span class="debug_error">no filters defined</span> for prefix <b>'.$this->Prefix.'</b>, but <b>DrawFilterMenu</b> tag used', E_USER_WARNING);
+ return '';
+ }
+
+ // Params: label, filter_action, filter_status
+ $block_params['name'] = $params['item_block'];
+
+ $view_filter = $this->Application->RecallVar($this->getPrefixSpecial().'_view_filter');
+ if($view_filter === false)
+ {
+ $event_params = Array('prefix'=>$this->Prefix,'special'=>$this->Special,'name'=>'OnRemoveFilters');
+ $this->Application->HandleEvent( new kEvent($event_params) );
+ $view_filter = $this->Application->RecallVar($this->getPrefixSpecial().'_view_filter');
+ }
+ $view_filter = unserialize($view_filter);
+
+ $filters = Array();
+ $prefix_special = $this->getPrefixSpecial();
+
+ foreach ($filter_menu['Filters'] as $filter_key => $filter_params) {
+ $group_params = isset($filter_params['group_id']) ? $filter_menu['Groups'][ $filter_params['group_id'] ] : Array();
+ if (!isset($group_params['element_type'])) {
+ $group_params['element_type'] = 'checkbox';
+ }
+
+ if (!$filter_params) {
+ $filters[] = $separator;
+ continue;
+ }
+
+ $block_params['label'] = addslashes( $this->Application->Phrase($filter_params['label']) );
+ if (getArrayValue($view_filter,$filter_key)) {
+ $submit = 0;
+ $status = $group_params['element_type'] == 'checkbox' ? 1 : 2;
+ }
+ else {
+ $submit = 1;
+ $status = 0;
+ }
+ $block_params['filter_action'] = 'set_filter("'.$prefix_special.'","'.$filter_key.'","'.$submit.'",'.$params['ajax'].');';
+ $block_params['filter_status'] = $status; // 1 - checkbox, 2 - radio, 0 - no image
+ $filters[] = $this->Application->ParseBlock($block_params);
+ }
+
+
+ return implode('', $filters);
+ }
+
+ function IterateGridFields($params)
+ {
+ $mode = $params['mode'];
+ $def_block = $params['block'];
+
+ $grids = $this->Application->getUnitOption($this->Prefix,'Grids');
+ $grid_config = $grids[$params['grid']]['Fields'];
+
+ $std_params['pass_params']='true';
+ $std_params['PrefixSpecial']=$this->getPrefixSpecial();
+
+ $o = '';
+ foreach ($grid_config as $field => $options) {
+ $block_params = Array();
+ $block_params['name'] = isset($options[$mode.'_block']) ? $options[$mode.'_block'] : $def_block;
+ $block_params['field'] = $field;
+ $block_params['sort_field'] = isset($options['sort_field']) ? $options['sort_field'] : $field;
+ $block_params = array_merge($std_params, $block_params, $options);
+ $o.= $this->Application->ParseBlock($block_params, 1);
+ }
+ return $o;
+ }
+
+ function GridFieldsCount($params)
+ {
+ $grids = $this->Application->getUnitOption($this->Prefix, 'Grids');
+ $grid_config = $grids[$params['grid']]['Fields'];
+
+ return count($grid_config);
+ }
+
+ /**
+ * Prints list content using block specified
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function PrintList($params)
+ {
+ $list =& $this->GetList($params);
+ $id_field = $this->Application->getUnitOption($this->Prefix,'IDField');
+
+ $list->Query();
+ $o = '';
+ $list->GoFirst();
+
+ $block_params=$this->prepareTagParams($params);
+ $block_params['name'] = $this->SelectParam($params, 'render_as,block');
+ $block_params['pass_params'] = 'true';
+
+ while (!$list->EOL())
+ {
+ $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); // for edit/delete links using GET
+ $o.= $this->Application->ParseBlock($block_params, 1);
+ $list->GoNext();
+ }
+
+ $this->Application->SetVar( $this->getPrefixSpecial().'_id', '');
+ return $o;
+ }
+
+ function InitList($params)
+ {
+ $list_name = isset($params['list_name']) ? $params['list_name'] : '';
+
+ $names_mapping = $this->Application->GetVar('NamesToSpecialMapping');
+
+ if( !getArrayValue($names_mapping, $this->Prefix, $list_name) )
+ {
+ $list =& $this->GetList($params);
+ }
+ }
+
+ function BuildListSpecial($params)
+ {
+ return $this->Special;
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param Array $params
+ * @return kDBList
+ */
+ function &GetList($params)
+ {
+ $list_name = $this->SelectParam($params, 'list_name,name');
+ if (!$list_name) {
+ $list_name = $this->Application->Parser->GetParam('list_name');
+ }
+
+ $requery = getArrayValue($params, 'requery');
+ if ($list_name && !$requery){
+ $names_mapping = $this->Application->GetVar('NamesToSpecialMapping');
+
+ $special = getArrayValue($names_mapping, $this->Prefix, $list_name);
+ if(!$special)
+ {
+ $special = $this->BuildListSpecial($params);
+ }
+ }
+ else
+ {
+ $special = $this->BuildListSpecial($params);
+ }
+
+ $prefix_special = rtrim($this->Prefix.'.'.$special, '.');
+ $params['skip_counting'] = true;
+ $list =& $this->Application->recallObject( $prefix_special, $this->Prefix.'_List', $params);
+ if ($requery) {
+ $this->Application->HandleEvent($an_event, $prefix_special.':OnListBuild', $params);
+ }
+ $list->Query($requery);
+ $this->Special = $special;
+
+ if ($list_name) {
+ $names_mapping[$this->Prefix][$list_name] = $special;
+ $this->Application->SetVar('NamesToSpecialMapping', $names_mapping);
+ }
+
+ return $list;
+ }
+
+ function ListMarker($params)
+ {
+ $list =& $this->GetList($params);
+ $ret = $list->getPrefixSpecial();
+ if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/');
+ return $ret;
+ }
+
+ function SubmitName($params)
+ {
+ $list =& $this->GetList($params);
+
+ $prefix_special = $list->getPrefixSpecial();
+
+ return 'events['.$prefix_special.']['.$params['event'].']';
+ }
+
+
+ function CombinedSortingDropDownName($params)
+ {
+ $list =& $this->GetList($params);
+ $prefix_special = $list->getPrefixSpecial();
+
+ return $prefix_special.'_CombinedSorting';
+ }
+
+ function SortingSelected($params)
+ {
+ $list =& $this->GetList($params);
+ $user_sorting_start = $this->getUserSortIndex();
+
+ $sorting = strtolower($list->GetOrderField($user_sorting_start).'|'.$list->GetOrderDirection($user_sorting_start));
+
+ if ($sorting == strtolower($params['sorting'])) return $params['selected'];
+ }
+
+
+
+ /**
+ * Prints list content using block specified
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function PrintList2($params)
+ {
+ $per_page = $this->SelectParam($params, 'per_page,max_items');
+ if ($per_page !== false) $params['per_page'] = $per_page;
+
+ $list =& $this->GetList($params);
+ $o = '';
+
+ $direction = (isset($params['direction']) && $params['direction']=="H")?"H":"V";
+ $columns = (isset($params['columns'])) ? $params['columns'] : 1;
+
+ $id_field = (isset($params['id_field'])) ? $params['id_field'] : $this->Application->getUnitOption($this->Prefix, 'IDField');
+
+ if ($columns>1 && $direction=="V") {
+ $list->Records = $this->LinearToVertical($list->Records, $columns, $list->GetPerPage());
+ $list->SelectedCount=count($list->Records);
+ ksort($list->Records); // this is issued twice, maybe need to be removed
+ }
+
+ $list->GoFirst();
+
+ $block_params=$this->prepareTagParams($params);
+ $block_params['name']=$this->SelectParam($params, 'render_as,block');
+ $block_params['pass_params']='true';
+ $block_params['column_width'] = 100 / $columns;
+ $block_start_row_params = $this->prepareTagParams($params);
+ $block_start_row_params['name'] = $this->SelectParam($params, 'row_start_render_as,block_row_start,row_start_block');
+
+ $block_end_row_params=$this->prepareTagParams($params);
+ $block_end_row_params['name'] = $this->SelectParam($params, 'row_end_render_as,block_row_end,row_end_block');
+
+ $block_empty_cell_params = $this->prepareTagParams($params);
+ $block_empty_cell_params['name'] = $this->SelectParam($params, 'empty_cell_render_as,block_empty_cell,empty_cell_block');
+
+ $i=0;
+
+ $backup_id=$this->Application->GetVar($this->Prefix."_id");
+ $displayed = array();
+ $column_number = 1;
+
+ $cache_mod_rw = $this->Application->getUnitOption($this->Prefix, 'CacheModRewrite') && $this->Application->RewriteURLs();
+
+ while (!$list->EOL())
+ {
+ $this->Application->SetVar( $this->getPrefixSpecial().'_id', $list->GetDBField($id_field) ); // for edit/delete links using GET
+ $this->Application->SetVar( $this->Prefix.'_id', $list->GetDBField($id_field) );
+
+ if ($cache_mod_rw) {
+ $this->Application->setCache('filenames', $this->Prefix.'_'.$list->GetDBField($id_field), $list->GetDBField('Filename'));
+ $this->Application->setCache('filenames', 'c_'.$list->GetDBField('CategoryId'), $list->GetDBField('CategoryFilename'));
+ }
+
+ if ($i % $columns == 0) {
+ // record in this iteration is first in row, then open row
+ $column_number = 1;
+ $o.= $block_start_row_params['name'] ?
+ $this->Application->ParseBlock($block_start_row_params, 1) :
+ (!isset($params['no_table']) ? '<tr>' : '');
+ }
+ else {
+ $column_number++;
+ }
+
+ $block_params['column_number'] = $column_number;
+ $o.= $this->Application->ParseBlock($block_params, 1);
+ array_push($displayed, $list->GetDBField($id_field));
+
+ if (($i+1) % $columns == 0) {
+ // record in next iteration is first in row too, then close this row
+ $o.= $block_end_row_params['name'] ?
+ $this->Application->ParseBlock($block_end_row_params, 1) :
+ (!isset($params['no_table']) ? '<tr>' : '');
+ }
+
+ $list->GoNext();
+ $i++;
+ }
+
+ // append empty cells in place of missing cells in last row
+ while ($i % $columns != 0) {
+ // until next cell will be in new row append empty cells
+ $o .= $block_empty_cell_params['name'] ? $this->Application->ParseBlock($block_empty_cell_params, 1) : '<td> </td>';
+
+ if (($i+1) % $columns == 0) {
+ // record in next iteration is first in row too, then close this row
+ $o .= $block_end_row_params['name'] ? $this->Application->ParseBlock($block_end_row_params, 1) : '</tr>';
+ }
+ $i++;
+ }
+
+ $cur_displayed = $this->Application->GetVar($this->Prefix.'_displayed_ids');
+ if (!$cur_displayed) {
+ $cur_displayed = Array();
+ }
+ else {
+ $cur_displayed = explode(',', $cur_displayed);
+ }
+
+ $displayed = array_unique(array_merge($displayed, $cur_displayed));
+ $this->Application->SetVar($this->Prefix.'_displayed_ids', implode(',',$displayed));
+
+ $this->Application->SetVar( $this->Prefix.'_id', $backup_id);
+ $this->Application->SetVar( $this->getPrefixSpecial().'_id', '');
+
+ if (isset($params['more_link_render_as'])) {
+ $block_params = $params;
+ $params['render_as'] = $params['more_link_render_as'];
+ $o .= $this->MoreLink($params);
+ }
+
+ return $o;
+ }
+
+ function MoreLink($params)
+ {
+ $per_page = $this->SelectParam($params, 'per_page,max_items');
+ if ($per_page !== false) $params['per_page'] = $per_page;
+ $list =& $this->GetList($params);
+ if ($list->PerPage < $list->RecordsCount) {
+ $block_params = array();
+ $block_params['name'] = $this->SelectParam($params, 'render_as,block');
+ return $this->Application->ParseBlock($block_params, 1);
+ }
+ }
+
+ function NotLastItem($params)
+ {
+ $object =& $this->getList($params); // maybe we should use $this->GetList($params) instead
+ return ($object->CurrentIndex < min($object->PerPage == -1 ? $object->RecordsCount : $object->PerPage, $object->RecordsCount) - 1);
+ }
+
+ function PageLink($params)
+ {
+ $t = isset($params['template']) ? $param['template'] : '';
+ if (!$t) $t = $this->Application->GetVar('t');
+
+ if (isset($params['page'])) {
+ $this->Application->SetVar($this->getPrefixSpecial().'_Page', $params['page']);
+ }
+
+// $http_query =& $this->Application->recallObject('HTTPQuery');
+// $get = $http_query->getRedirectParams();
+ $pass = Array('pass' => 'm,'.$this->getPrefixSpecial());
+// $pass = array_merge($get, $pass);
+
+ return $this->Application->HREF($t, '', $pass);
+ }
+
+ function ColumnWidth($params)
+ {
+ $columns = $this->Application->Parser->GetParam('columns');
+ return round(100/$columns).'%';
+ }
+
+ /**
+ * Append prefix and special to tag
+ * params (get them from tagname) like
+ * they were really passed as params
+ *
+ * @param Array $tag_params
+ * @return Array
+ * @access protected
+ */
+ function prepareTagParams($tag_params = Array())
+ {
+ /*if (isset($tag_params['list_name'])) {
+ $list =& $this->GetList($tag_params);
+ $this->Init($list->Prefix, $list->Special);
+ }*/
+
+ $ret = $tag_params;
+ $ret['Prefix'] = $this->Prefix;
+ $ret['Special'] = $this->Special;
+ $ret['PrefixSpecial'] = $this->getPrefixSpecial();
+ return $ret;
+ }
+
+ function GetISO($currency)
+ {
+ if ($currency == 'selected') {
+ $iso = $this->Application->RecallVar('curr_iso');
+ }
+ elseif ($currency == 'primary' || $currency == '') {
+ $iso = $this->Application->GetPrimaryCurrency();
+ }
+ else { //explicit currency
+ $iso = $currency;
+ }
+ return $iso;
+ }
+
+ function ConvertCurrency($value, $iso)
+ {
+ $converter =& $this->Application->recallObject('kCurrencyRates');
+ // convery primary currency to selected (if they are the same, converter will just return)
+ $value = $converter->Convert($value, 'PRIMARY', $iso);
+ return $value;
+ }
+
+ function AddCurrencySymbol($value, $iso)
+ {
+ $currency =& $this->Application->recallObject('curr.-'.$iso, null, Array('skip_autoload' => true));
+ if( !$currency->isLoaded() ) $currency->Load($iso, 'ISO');
+
+ $symbol = $currency->GetDBField('Symbol');
+ if (!$symbol) $symbol = $currency->GetDBField('ISO').' ';
+ if ($currency->GetDBField('SymbolPosition') == 0) {
+ $value = $symbol.$value;
+ }
+ if ($currency->GetDBField('SymbolPosition') == 1) {
+ $value = $value.$symbol;
+ }
+ return $value;
+ }
+
+ /**
+ * Get's requested field value
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Field($params)
+ {
+ $field = $this->SelectParam($params, 'name,field');
+
+ if( !$this->Application->IsAdmin() ) $params['no_special'] = 'no_special';
+
+ $object =& $this->getObject($params);
+
+ if ( $this->HasParam($params, 'db') )
+ {
+ $value = $object->GetDBField($field);
+ }
+ else
+ {
+ if( $this->HasParam($params, 'currency') )
+ {
+ $iso = $this->GetISO($params['currency']);
+ $original = $object->GetDBField($field);
+ $value = $this->ConvertCurrency($original, $iso);
+ $object->SetDBField($field, $value);
+ $object->Fields[$field]['converted'] = true;
+ }
+
+ $format = getArrayValue($params, 'format');
+ if( !$format || $format == '$format' )
+ {
+ $format = null;
+ }
+ else
+ {
+ if(preg_match("/_regional_(.*)/", $format, $regs))
+ {
+ $lang =& $this->Application->recallObject('lang.current');
+ $format = $lang->GetDBField($regs[1]);
+ }
+ }
+ $value = $object->GetField($field, $format);
+
+ if( $this->SelectParam($params, 'negative') )
+ {
+ if(strpos($value, '-') === 0)
+ {
+ $value = substr($value, 1);
+ }
+ else
+ {
+ $value = '-'.$value;
+ }
+ }
+
+ if( $this->HasParam($params, 'currency') )
+ {
+ $value = $this->AddCurrencySymbol($value, $iso);
+ $params['no_special'] = 1;
+ }
+ }
+
+ if( !$this->HasParam($params, 'no_special') ) $value = htmlspecialchars($value);
+ if( getArrayValue($params,'checked' ) ) $value = ($value == ( isset($params['value']) ? $params['value'] : 1)) ? 'checked' : '';
+ if( getArrayValue($params,'as_label') ) $value = $this->Application->Phrase($value);
+
+ $first_chars = $this->SelectParam($params,'first_chars,cut_first');
+ if($first_chars)
+ {
+ $needs_cut = strlen($value) > $first_chars;
+ $value = substr($value,0,$first_chars);
+ if($needs_cut) $value .= ' ...';
+ }
+ if( getArrayValue($params,'nl2br' ) ) $value = nl2br($value);
+
+ if ($value != '') $this->Application->Parser->DataExists = true;
+
+ if( $this->HasParam($params, 'currency') )
+ {
+ //restoring value in original currency, for other Field tags to work properly
+ $object->SetDBField($field, $original);
+ }
+
+ return $value;
+ }
+
+ function SetField($params)
+ {
+ // <inp2:SetField field="Value" src=p:cust_{$custom_name}"/>
+
+ $object =& $this->getObject($params);
+ $dst_field = $this->SelectParam($params, 'name,field');
+
+ list($prefix_special, $src_field) = explode(':', $params['src']);
+ $src_object =& $this->Application->recallObject($prefix_special);
+ $object->SetDBField($dst_field, $src_object->GetDBField($src_field));
+ }
+
+ /**
+ * Checks if parameter is passed
+ * Note: works like Tag and line simple method too
+ *
+ * @param Array $params
+ * @param string $param_name
+ * @return bool
+ */
+ function HasParam($params, $param_name = null)
+ {
+ if( !isset($param_name) )
+ {
+ $param_name = $this->SelectParam($params, 'name');
+ $params = $this->Application->Parser->Params;
+ }
+ $value = getArrayValue($params, $param_name);
+ return $value && ($value != '$'.$param_name);
+ }
+
+ function PhraseField($params)
+ {
+ $field_label = $this->Field($params);
+ $translation = $this->Application->Phrase( $field_label );
+ return $translation;
+ }
+
+ function Error($params)
+ {
+ $field = $this->SelectParam($params, 'name,field');
+ $object =& $this->getObject($params);
+ $msg = $object->GetErrorMsg($field, false);
+ return $msg;
+ }
+
+ function HasError($params)
+ {
+ if ($params['field'] == 'any')
+ {
+ $object =& $this->getObject($params);
+
+ $skip_fields = getArrayValue($params, 'except');
+ $skip_fields = $skip_fields ? explode(',', $skip_fields) : Array();
+
+ return $object->HasErrors($skip_fields);
+ }
+ else
+ {
+ $fields = $this->SelectParam($params, 'field,fields');
+ $fields = explode(',', $fields);
+ $res = false;
+ foreach($fields as $field)
+ {
+ $params['field'] = $field;
+ $res = $res || ($this->Error($params) != '');
+ }
+ return $res;
+ }
+ }
+
+ function IsRequired($params)
+ {
+ $field = $params['field'];
+ $object =& $this->getObject($params);;
+
+ $options = $object->GetFieldOptions($field);
+ return getArrayValue($options,'required');
+ }
+
+ function PredefinedOptions($params)
+ {
+ $field = $params['field'];
+ $object =& $this->getObject($params);
+
+ $value = $object->GetDBField($field);
+ $options = $object->GetFieldOptions($field);
+ if( $this->HasParam($params,'has_empty') )
+ {
+ $empty_value = getArrayValue($params, 'empty_value');
+ if($empty_value === false) $empty_value = '';
+ $options['options'] = array_merge_recursive2( Array($empty_value => ''), $options['options'] );
+ }
+
+ $block_params = $this->prepareTagParams($params);
+
+ $block_params['name'] = $this->SelectParam($params, 'render_as,block');
+ $block_params['field'] = $params['field'];
+ $block_params['pass_params'] = 'true';
+ $block_params['field_name'] = $this->InputName($params);
+ $block_params['PrefixSpecial'] = $this->getPrefixSpecial();
+
+ $selected_param_name = getArrayValue($params,'selected_param');
+ if(!$selected_param_name) $selected_param_name = $params['selected'];
+ $selected = $params['selected'];
+
+ $o = '';
+ if( $this->HasParam($params,'no_empty') && !getArrayValue($options['options'],'') ) array_shift($options['options']);
+
+ if( strpos($value, '|') !== false )
+ {
+ // multiple selection checkboxes
+ $value = explode('|', substr($value, 1, -1) );
+ foreach ($options['options'] as $key => $val)
+ {
+ $block_params['key'] = $key;
+ $block_params['option'] = $val;
+ $block_params[$selected_param_name] = ( in_array($key, $value) ? ' '.$selected : '');
+ $o .= $this->Application->ParseBlock($block_params, 1);
+ }
+ }
+ else
+ {
+ // single selection radio or checkboxes
+ foreach ($options['options'] as $key => $val)
+ {
+ $block_params['key'] = $key;
+ $block_params['option'] = $val;
+ $block_params[$selected_param_name] = ( $key == $value ? ' '.$selected : '');
+ $o .= $this->Application->ParseBlock($block_params, 1);
+ }
+ }
+ return $o;
+ }
+
+ function PredefinedSearchOptions($params)
+ {
+ $object =& $this->getObject($params);
+ $field = $params['field'];
+ $saved_value = $object->GetDBField($field);
+
+ $custom_filters = $this->Application->RecallVar( $this->getPrefixSpecial().'_custom_filters');
+ if ($custom_filters) {
+ $custom_filters = unserialize($custom_filters);
+ $append = getArrayValue($params, 'type') ? '_'.$params['type'] : '';
+ $object->SetDBField($field, $custom_filters[$field.$append]);
+ }
+ else {
+ $object->SetDBField($field, '');
+ }
+ $ret = $this->PredefinedOptions($params);
+ $object->SetDBField($field, $saved_value);
+ return $ret;
+ }
+
+ function Format($params)
+ {
+ $field = $this->SelectParam($params, 'name,field');
+ $object =& $this->getObject($params);
+
+ $options = $object->GetFieldOptions($field);
+
+ $format = $options[ $this->SelectParam($params, 'input_format') ? 'input_format' : 'format' ];
+
+ $formatter_class = getArrayValue($options,'formatter');
+ if($formatter_class)
+ {
+ $formatter =& $this->Application->recallObject($formatter_class);
+ $human_format = getArrayValue($params,'human');
+ $edit_size = getArrayValue($params,'edit_size');
+ $sample = getArrayValue($params,'sample');
+ if($sample)
+ {
+ return $formatter->GetSample($field, $options, $object);
+ }
+ elseif($human_format || $edit_size)
+ {
+ $format = $formatter->HumanFormat($format);
+ return $edit_size ? strlen($format) : $format;
+ }
+ }
+
+ return $format;
+ }
+
+ /**
+ * Print grid pagination using
+ * block names specified
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function PrintPages($params)
+ {
+ $list =& $this->GetList($params);
+ $prefix_special = $list->getPrefixSpecial();
+ $total_pages = $list->GetTotalPages();
+
+ if ($total_pages > 1) $this->Application->Parser->DataExists = true;
+
+ if($total_pages == 0) $total_pages = 1; // display 1st page as selected in case if we have no pages at all
+ $o = '';
+
+ // what are these 2 lines for?
+ $this->Application->SetVar($prefix_special.'_event','');
+ $this->Application->SetVar($prefix_special.'_id','');
+
+ $current_page = $list->Page; // $this->Application->RecallVar($prefix_special.'_Page');
+
+ $block_params = $this->prepareTagParams($params);
+
+ $split = ( isset($params['split'] ) ? $params['split'] : 10 );
+
+ $split_start = $current_page - ceil($split/2);
+ if ($split_start < 1){
+ $split_start = 1;
+ }
+ $split_end = $split_start + $split-1;
+
+ if ($split_end > $total_pages) {
+ $split_end = $total_pages;
+ $split_start = max($split_end - $split + 1, 1);
+ }
+
+ if ($current_page > 1){
+ $prev_block_params = $this->prepareTagParams();
+
+ if ($total_pages > $split){
+ $prev_block_params['page'] = max($current_page-$split, 1);
+ $prev_block_params['name'] = $this->SelectParam($params, 'prev_page_split_render_as,prev_page_split_block');
+ if ($prev_block_params['name']){
+ $o .= $this->Application->ParseBlock($prev_block_params, 1);
+ }
+ }
+
+ $prev_block_params['name'] = 'page';
+ $prev_block_params['page'] = $current_page-1;
+ $prev_block_params['name'] = $this->SelectParam($params, 'prev_page_render_as,block_prev_page,prev_page_block');
+ if ($prev_block_params['name']) {
+ $this->Application->SetVar($this->getPrefixSpecial().'_Page', $current_page-1);
+ $o .= $this->Application->ParseBlock($prev_block_params, 1);
+ }
+ }
+ else {
+ if ( $no_prev_page_block = $this->SelectParam($params, 'no_prev_page_render_as,block_no_prev_page') ) {
+ $block_params['name'] = $no_prev_page_block;
+ $o .= $this->Application->ParseBlock($block_params, 1);
+ }
+ }
+
+ $separator_params['name'] = $this->SelectParam($params, 'separator_render_as,block_separator');
+ for ($i = $split_start; $i <= $split_end; $i++)
+ {
+ if ($i == $current_page) {
+ $block = $this->SelectParam($params, 'current_render_as,active_render_as,block_current,active_block');
+ }
+ else {
+ $block = $this->SelectParam($params, 'link_render_as,inactive_render_as,block_link,inactive_block');
+ }
+
+ $block_params['name'] = $block;
+ $block_params['page'] = $i;
+ $this->Application->SetVar($this->getPrefixSpecial().'_Page', $i);
+ $o .= $this->Application->ParseBlock($block_params, 1);
+
+ if ($this->SelectParam($params, 'separator_render_as,block_separator')
+ && $i < $split_end)
+ {
+ $o .= $this->Application->ParseBlock($separator_params, 1);
+ }
+ }
+
+ if ($current_page < $total_pages){
+ $next_block_params = $this->prepareTagParams();
+ $next_block_params['page']=$current_page+1;
+ $next_block_params['name'] = $this->SelectParam($params, 'next_page_render_as,block_next_page,next_page_block');
+ if ($next_block_params['name']){
+ $this->Application->SetVar($this->getPrefixSpecial().'_Page', $current_page+1);
+ $o .= $this->Application->ParseBlock($next_block_params, 1);
+ }
+ if ($total_pages > $split){
+ $next_block_params['page']=min($current_page+$split, $total_pages);
+ $next_block_params['name'] = $this->SelectParam($params, 'next_page_split_render_as,next_page_split_block');
+ if ($next_block_params['name']){
+ $o .= $this->Application->ParseBlock($next_block_params, 1);
+ }
+ }
+ }
+
+ $this->Application->SetVar($this->getPrefixSpecial().'_Page', $current_page);
+ return $o;
+ }
+
+ /**
+ * Print grid pagination using
+ * block names specified
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function PaginationBar($params)
+ {
+ return $this->PrintPages($params);
+ }
+
+
+ /**
+ * Returns field name (processed by kMultiLanguage formatter
+ * if required) and item's id from it's IDField or field required
+ *
+ * @param Array $params
+ * @return Array (id,field)
+ * @access private
+ */
+ function prepareInputName($params)
+ {
+ $field = $this->SelectParam($params, 'name,field');
+ $object =& $this->getObject($params);
+
+ $formatter_class = getArrayValue($object->Fields, $field, 'formatter');
+ if ($formatter_class == 'kMultiLanguage')
+ {
+ $formatter =& $this->Application->recallObject($formatter_class);
+ $field = $formatter->LangFieldName($field);
+ }
+
+ $id_field = getArrayValue($params, 'IdField');
+ $id = $id_field ? $object->GetDBField($id_field) : $object->GetID();
+
+ return Array($id, $field);
+ }
+
+
+ /**
+ * Returns input field name to
+ * be placed on form (for correct
+ * event processing)
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function InputName($params)
+ {
+ list($id, $field) = $this->prepareInputName($params);
+
+ $ret = $this->getPrefixSpecial().'['.$id.']['.$field.']';
+ if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/');
+ return $ret;
+ }
+
+ /**
+ * Allows to override various field options through hidden fields with specific names in submit.
+ * This tag generates this special names
+ *
+ * @param Array $params
+ * @return string
+ * @author Alex
+ */
+ function FieldModifier($params)
+ {
+ list($id, $field) = $this->prepareInputName($params);
+
+ $ret = 'field_modifiers['.$this->getPrefixSpecial().']['.$field.']['.$params['type'].']';
+ if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/');
+ return $ret;
+ }
+
+ /**
+ * Returns index where 1st changable sorting field begins
+ *
+ * @return int
+ * @access private
+ */
+ function getUserSortIndex()
+ {
+ $list_sortings = $this->Application->getUnitOption($this->Prefix, 'ListSortings');
+ $sorting_prefix = getArrayValue($list_sortings, $this->Special) ? $this->Special : '';
+
+ $user_sorting_start = 0;
+ if ( $forced_sorting = getArrayValue($list_sortings, $sorting_prefix, 'ForcedSorting') ) {
+ $user_sorting_start = count($forced_sorting);
+ }
+ return $user_sorting_start;
+ }
+
+ /**
+ * Returns order direction for given field
+ *
+ *
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Order($params)
+ {
+ $field = $params['field'];
+ $user_sorting_start = $this->getUserSortIndex();
+
+ $list =& $this->GetList($params);
+
+ if ($list->GetOrderField($user_sorting_start) == $field)
+ {
+ return strtolower($list->GetOrderDirection($user_sorting_start));
+ }
+ elseif($list->GetOrderField($user_sorting_start+1) == $field)
+ {
+ return '2_'.strtolower($list->GetOrderDirection($user_sorting_start+1));
+ }
+ else
+ {
+ return 'no';
+ }
+ }
+
+ /**
+ * Get's information of sorting field at "pos" position,
+ * like sorting field name (type="field") or sorting direction (type="direction")
+ *
+ * @param Array $params
+ * @return mixed
+ */
+ function OrderInfo($params)
+ {
+ $user_sorting_start = $this->getUserSortIndex() + --$params['pos'];
+ $list =& $this->GetList($params);
+// $object =& $this->Application->recallObject( $this->getPrefixSpecial() );
+
+ if($params['type'] == 'field') return $list->GetOrderField($user_sorting_start);
+ if($params['type'] == 'direction') return $list->GetOrderDirection($user_sorting_start);
+ }
+
+ /**
+ * Checks if sorting field/direction matches passed field/direction parameter
+ *
+ * @param Array $params
+ * @return bool
+ */
+ function IsOrder($params)
+ {
+ $params['type'] = isset($params['field']) ? 'field' : 'direction';
+ $value = $this->OrderInfo($params);
+
+ if( isset($params['field']) ) return $params['field'] == $value;
+ if( isset($params['direction']) ) return $params['direction'] == $value;
+ }
+
+ /**
+ * Returns list perpage
+ *
+ * @param Array $params
+ * @return int
+ */
+ function PerPage($params)
+ {
+ $object =& $this->getObject($params);
+ return $object->PerPage;
+ }
+
+ /**
+ * Checks if list perpage matches value specified
+ *
+ * @param Array $params
+ * @return bool
+ */
+ function PerPageEquals($params)
+ {
+ $object =& $this->getObject($params);
+ return $object->PerPage == $params['value'];
+ }
+
+ function SaveEvent($params)
+ {
+ // SaveEvent is set during OnItemBuild, but we may need it before any other tag calls OnItemBuild
+ $object =& $this->getObject($params);
+ return $this->Application->GetVar($this->getPrefixSpecial().'_SaveEvent');
+ }
+
+ function NextId($params)
+ {
+ $object =& $this->getObject($params);
+ $ids = explode(',', $this->Application->RecallVar($this->getPrefixSpecial().'_selected_ids'));
+
+ $cur_id = $object->GetID();
+
+ $i = array_search($cur_id, $ids);
+ if ($i !== false) {
+ return $i < count($ids) - 1 ? $ids[$i + 1] : '';
+ }
+ return '';
+ }
+
+ function PrevId($params)
+ {
+ $object =& $this->getObject($params);
+ $ids = explode(',', $this->Application->RecallVar($this->getPrefixSpecial().'_selected_ids'));
+
+ $cur_id = $object->GetID();
+
+ $i = array_search($cur_id, $ids);
+ if ($i !== false) {
+ return $i > 0 ? $ids[$i - 1] : '';
+ }
+ return '';
+ }
+
+ function IsSingle($params)
+ {
+ return ($this->NextId($params) === '' && $this->PrevId($params) === '');
+ }
+
+ function IsLast($params)
+ {
+ return ($this->NextId($params) === '');
+ }
+
+ function IsFirst($params)
+ {
+ return ($this->PrevId($params) === '');
+ }
+
+ /**
+ * Checks if field value is equal to proposed one
+ *
+ * @param Array $params
+ * @return bool
+ */
+ function FieldEquals($params)
+ {
+ $object =& $this->getObject($params);
+ $ret = $object->GetDBField($this->SelectParam($params, 'name,field')) == $params['value'];
+// if( getArrayValue($params,'inverse') ) $ret = !$ret;
+ return $ret;
+ }
+
+ function ItemIcon($params)
+ {
+ $object =& $this->getObject($params);
+
+ $grids = $this->Application->getUnitOption($this->Prefix,'Grids');
+ $icons =& $grids[ $params['grid'] ]['Icons'];
+
+ $key = '';
+ $status_fields = $this->Application->getUnitOption($this->Prefix,'StatusField');
+ if(!$status_fields) return $icons['default'];
+
+ foreach($status_fields as $status_field)
+ {
+ $key .= $object->GetDBField($status_field).'_';
+ }
+ $key = rtrim($key,'_');
+ $value = ($key !== false) ? $key : 'default';
+
+ return isset($icons[$value]) ? $icons[$value] : $icons['default'];
+ }
+
+ /**
+ * Generates bluebar title + initializes prefixes used on page
+ *
+ * @param Array $params
+ * @return string
+ */
+ function SectionTitle($params)
+ {
+ $preset_name = replaceModuleSection($params['title_preset']);
+ $title_presets = $this->Application->getUnitOption($this->Prefix,'TitlePresets');
+ $title_info = getArrayValue($title_presets, $preset_name);
+ if($title_info === false) return str_replace('#preset_name#', $preset_name, $params['title']);
+
+ if( getArrayValue($title_presets,'default') )
+ {
+ // use default labels + custom labels specified in preset used
+ $title_info = array_merge_recursive2($title_presets['default'], $title_info);
+ }
+
+ $title = $title_info['format'];
+
+ // 1. get objects in use for title construction
+ $objects = Array();
+ $object_status = Array();
+ $status_labels = Array();
+
+ $prefixes = getArrayValue($title_info,'prefixes');
+ $all_tag_params = getArrayValue($title_info,'tag_params');
+ if($prefixes)
+ {
+ $tag_params = Array();
+ foreach($prefixes as $prefix_special)
+ {
+ $prefix_data = $this->Application->processPrefix($prefix_special);
+ $prefix_data['prefix_special'] = rtrim($prefix_data['prefix_special'],'.');
+
+ if($all_tag_params)
+ {
+ $tag_params = getArrayValue($all_tag_params, $prefix_data['prefix_special']);
+ if(!$tag_params) $tag_params = Array();
+ }
+
+ $tag_params = array_merge_recursive2($params, $tag_params);
+ $objects[ $prefix_data['prefix_special'] ] =& $this->Application->recallObject($prefix_data['prefix_special'], $prefix_data['prefix'], $tag_params);
+ $object_status[ $prefix_data['prefix_special'] ] = $objects[ $prefix_data['prefix_special'] ]->IsNewItem() ? 'new' : 'edit';
+
+ // a. set object's status field (adding item/editing item) for each object in title
+ if( getArrayValue($title_info[ $object_status[ $prefix_data['prefix_special'] ].'_status_labels' ],$prefix_data['prefix_special']) )
+ {
+ $status_labels[ $prefix_data['prefix_special'] ] = $title_info[ $object_status[ $prefix_data['prefix_special'] ].'_status_labels' ][ $prefix_data['prefix_special'] ];
+ $title = str_replace('#'.$prefix_data['prefix_special'].'_status#', $status_labels[ $prefix_data['prefix_special'] ], $title);
+ }
+
+ // b. setting object's titlefield value (in titlebar ONLY) to default in case if object beeing created with no titlefield filled in
+ if( $object_status[ $prefix_data['prefix_special'] ] == 'new' )
+ {
+ $new_value = $this->getInfo( $objects[ $prefix_data['prefix_special'] ], 'titlefield' );
+ if(!$new_value && getArrayValue($title_info['new_titlefield'],$prefix_data['prefix_special']) ) $new_value = $this->Application->Phrase($title_info['new_titlefield'][ $prefix_data['prefix_special'] ]);
+ $title = str_replace('#'.$prefix_data['prefix_special'].'_titlefield#', $new_value, $title);
+ }
+ }
+ }
+
+ // 2. replace phrases if any found in format string
+ $title = $this->Application->ReplaceLanguageTags($title,false);
+
+ // 3. find and replace any replacement vars
+ preg_match_all('/#(.*_.*)#/Uis',$title,$rets);
+ if($rets[1])
+ {
+ $replacement_vars = array_keys( array_flip($rets[1]) );
+ foreach($replacement_vars as $replacement_var)
+ {
+ $var_info = explode('_',$replacement_var,2);
+ $object =& $objects[ $var_info[0] ];
+ $new_value = $this->getInfo($object,$var_info[1]);
+ $title = str_replace('#'.$replacement_var.'#', $new_value, $title);
+ }
+ }
+
+ $cut_first = getArrayValue($params,'cut_first');
+ if( $cut_first && strlen($title) > $cut_first && !preg_match('/<a href="(.*)">(.*)<\/a>/',$title) ) $title = substr($title, 0, $cut_first).' ...';
+
+ return $title;
+ }
+
+ function getInfo(&$object, $info_type)
+ {
+ switch ($info_type)
+ {
+ case 'titlefield':
+ $field = $this->Application->getUnitOption($object->Prefix,'TitleField');
+ return $field !== false ? $object->GetField($field) : 'TitleField Missing';
+ break;
+
+ case 'recordcount':
+ $of_phrase = $this->Application->Phrase('la_of');
+ return $object->NoFilterCount != $object->RecordsCount ? $object->RecordsCount.' '.$of_phrase.' '.$object->NoFilterCount : $object->RecordsCount;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Parses block depending on its element type.
+ * For radio and select elements values are taken from 'value_list_field' in key1=value1,key2=value2
+ * format. key=value can be substituted by <SQL>SELECT f1 AS OptionName, f2 AS OptionValue... FROM <PREFIX>TableName </SQL>
+ * where prefix is TABLE_PREFIX
+ *
+ * @param Array $params
+ * @return string
+ */
+ function ConfigFormElement($params)
+ {
+ $object =& $this->getObject($params);
+ $field = $params['field'];
+
+ $helper =& $this->Application->recallObject('InpCustomFieldsHelper');
+
+ $element_type = $object->GetDBField($params['element_type_field']);
+
+ if($element_type == 'label') $element_type = 'text';
+ $params['name'] = $params['blocks_prefix'].$element_type;
+
+ switch ($element_type) {
+ case 'select':
+ case 'radio':
+ $field_options = $object->GetFieldOptions($field, 'options');
+ $field_options['options'] = $helper->GetValuesHash( $object->GetDBField($params['value_list_field']) );
+ $object->SetFieldOptions($field, $field_options);
+ break;
+
+ case 'text':
+ case 'textarea':
+ $params['field_params'] = $helper->ParseConfigSQL($object->GetDBField($params['value_list_field']));
+ break;
+
+ case 'password':
+ case 'checkbox':
+ default:
+ break;
+ }
+ return $this->Application->ParseBlock($params, 1);
+ }
+
+ /**
+ * Get's requested custom field value
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function CustomField($params)
+ {
+ $params['name'] = 'cust_'.$this->SelectParam($params, 'name,field');
+ return $this->Field($params);
+ }
+
+ function CustomFieldLabel($params)
+ {
+ $object =& $this->getObject($params);
+
+ $field = $this->SelectParam($params, 'name,field');
+
+ $sql = 'SELECT FieldLabel
+ FROM '.$this->Application->getUnitOption('cf', 'TableName').'
+ WHERE FieldName = '.$this->Conn->qstr($field);
+ return $this->Application->Phrase($this->Conn->GetOne($sql));
+ }
+
+ /**
+ * transposes 1-dimensional array elements for vertical alignment according to given columns and per_page parameters
+ *
+ * @param array $arr
+ * @param int $columns
+ * @param int $per_page
+ * @return array
+ */
+ function LinearToVertical(&$arr, $columns, $per_page)
+ {
+ $rows = $columns;
+ // in case if after applying per_page limit record count less then
+ // can fill requrested column count, then fill as much as we can
+ $cols = min(ceil($per_page / $columns), ceil(count($arr) / $columns));
+ $imatrix = array();
+ for ($row = 0; $row < $rows; $row++) {
+ for ($col = 0; $col < $cols; $col++) {
+ $source_index = $row * $cols + $col;
+ if (!isset($arr[$source_index])) {
+ // in case if source array element count is less then element count in one row
+ continue;
+ }
+ $imatrix[$col * $rows + $row] = $arr[$source_index];
+ }
+ }
+
+ ksort($imatrix);
+ reset($imatrix);
+ return $imatrix;
+ }
+
+ /**
+ * If data was modfied & is in TempTables mode, then parse block with name passed;
+ * remove modification mark if not in TempTables mode
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ * @author Alexey
+ */
+ function SaveWarning($params)
+ {
+ $main_prefix = getArrayValue($params, 'main_prefix');
+ if ($main_prefix && $main_prefix != '$main_prefix') {
+ $top_prefix = $main_prefix;
+ }
+ else {
+ $top_prefix = $this->Application->GetTopmostPrefix($this->Prefix);
+ }
+
+ $temp_tables = $this->Application->GetVar($top_prefix.'_mode') == 't';
+ $modified = $this->Application->RecallVar($top_prefix.'_modified');
+
+ if ($temp_tables && $modified) {
+ $block_params = $this->prepareTagParams($params);
+ $block_params['name'] = $this->SelectParam($params, 'render_as,name');
+ $block_params['edit_mode'] = $temp_tables ? 1 : 0;
+ return $this->Application->ParseBlock($block_params);
+ }
+ $this->Application->RemoveVar($top_prefix.'_modified');
+ return '';
+ }
+
+ /**
+ * Returns list record count queries (on all pages)
+ *
+ * @param Array $params
+ * @return int
+ */
+ function TotalRecords($params)
+ {
+ $list =& $this->GetList($params);
+ if (!$list->Counted) $list->CountRecs();
+ return $list->RecordsCount;
+ }
+
+ /**
+ * Range filter field name
+ *
+ * @param Array $params
+ * @return string
+ */
+ function SearchInputName($params)
+ {
+ $field = $this->SelectParam($params, 'field,name');
+ $append = getArrayValue($params, 'type') ? '_'.$params['type'] : '';
+
+ return 'custom_filters['.$this->getPrefixSpecial().']['.$field.$append.']';
+ }
+
+ /**
+ * Return range filter field value
+ *
+ * @param Array $params
+ * @return string
+ */
+ function SearchField($params) // RangeValue
+ {
+ $field = $this->SelectParam($params, 'field,name');
+
+ $custom_filters = $this->Application->RecallVar($this->getPrefixSpecial().'_custom_filters');
+ $custom_filters = $custom_filters ? unserialize($custom_filters) : Array();
+
+ $append = getArrayValue($params, 'type');
+
+ return getArrayValue($custom_filters, $field.( $append ? '_'.$append : '') );
+ }
+
+ function SearchFormat($params)
+ {
+ $field = $params['field'];
+ $object =& $this->GetList($params);
+
+ $options = $object->GetFieldOptions($field);
+
+ $format = $options[ $this->SelectParam($params, 'input_format') ? 'input_format' : 'format' ];
+
+ $formatter_class = getArrayValue($options,'formatter');
+ if($formatter_class)
+ {
+ $formatter =& $this->Application->recallObject($formatter_class);
+ $human_format = getArrayValue($params,'human');
+ $edit_size = getArrayValue($params,'edit_size');
+ $sample = getArrayValue($params,'sample');
+ if($sample)
+ {
+ return $formatter->GetSample($field, $options, $object);
+ }
+ elseif($human_format || $edit_size)
+ {
+ $format = $formatter->HumanFormat($format);
+ return $edit_size ? strlen($format) : $format;
+ }
+ }
+
+ return $format;
+ }
+
+ /**
+ * Returns error of range field
+ *
+ * @param unknown_type $params
+ * @return unknown
+ */
+ function SearchError($params)
+ {
+ $field = $this->SelectParam($params, 'field,name');
+
+ $error_var_name = $this->getPrefixSpecial().'_'.$field.'_'.$params['type'].'_error';
+ $error_msg = $this->Application->RecallVar($error_var_name);
+ if($error_msg)
+ {
+ $this->Application->StoreVar($error_var_name, '');
+ }
+
+ $object =& $this->Application->recallObject($this->Prefix.'.'.$this->Special.'-item', null, Array('skip_autoload' => true));
+ return $object->ErrorMsgs[$error_msg];
+ }
+
+ /**
+ * Returns templates path for module, which is gathered from prefix module
+ *
+ * @param Array $params
+ * @return string
+ * @author Alex
+ */
+ function ModulePath($params)
+ {
+ $force_module = getArrayValue($params, 'module');
+ if ($force_module) {
+ if ($force_module == '#session#') {
+ $force_module = $this->Application->RecallVar('module');
+ }
+ else {
+ $force_module = strtolower($force_module);
+ }
+
+ $module_folder = trim( $this->Application->findModule('Name', $force_module, 'Path'), '/');
+ }
+ else {
+ $module_folder = $this->Application->getUnitOption($this->Prefix, 'ModuleFolder');
+ }
+ return '../../'.$module_folder.'/admin_templates/';
+ }
+
+ /**
+ * Returns object used in tag processor
+ *
+ * @access public
+ * @return kDBBase
+ */
+ function &getObject($params = Array())
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ return $object;
+ }
+
+ /**
+ * Checks if object propery value matches value passed
+ *
+ * @param Array $params
+ * @return bool
+ */
+ function PropertyEquals($params)
+ {
+ $object =& $this->getObject($params);
+ $property_name = $this->SelectParam($params, 'name,var,property');
+ return $object->$property_name == $params['value'];
+ }
+
+ /**
+ * Group list records by header, saves internal order in group
+ *
+ * @param Array $records
+ * @param string $heading_field
+ */
+ function groupRecords(&$records, $heading_field)
+ {
+ $sorted = Array();
+ $i = 0; $record_count = count($records);
+ while ($i < $record_count) {
+ $sorted[ $records[$i][$heading_field] ][] = $records[$i];
+ $i++;
+ }
+
+ $records = Array();
+ foreach ($sorted as $heading => $heading_records) {
+ $records = array_merge_recursive($records, $heading_records);
+ }
+ }
+
+ function DisplayOriginal($params)
+ {
+ return false;
+ }
+
+ function MultipleEditing($params)
+ {
+ $selected_ids = $this->Application->RecallVar($this->getPrefixSpecial().'_selected_ids');
+ $ret = '';
+ if ($selected_ids) {
+ $selected_ids = explode(',', $selected_ids);
+ $object =& $this->getObject( array_merge_recursive2($params, Array('skip_autoload' => true)) );
+ $params['name'] = $params['render_as'];
+ foreach ($selected_ids as $id) {
+ $object->Load($id);
+ $ret .= $this->Application->ParseBlock($params);
+ }
+ }
+
+ return $ret;
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.64.2/core/kernel/db/db_tag_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.64
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.64.2/core/units/users/users_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.64.2/core/units/users/users_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.64.2/core/units/users/users_event_handler.php (revision 6140)
@@ -0,0 +1,1033 @@
+<?php
+
+ class UsersEventHandler extends InpDBEventHandler
+ {
+ /**
+ * Allows to override standart permission mapping
+ *
+ */
+ function mapPermissions()
+ {
+ parent::mapPermissions();
+ $permissions = Array(
+ // admin
+ 'OnSetPersistantVariable' => Array('self' => 'view'), // because setting to logged in user only
+
+ // front
+ 'OnRefreshForm' => Array('self' => true),
+
+ 'OnForgotPassword' => Array('self' => true),
+ 'OnResetPassword' => Array('self' => true),
+ 'OnResetPasswordConfirmed' => Array('self' => true),
+
+ 'OnSubscribeQuery' => Array('self' => true),
+ 'OnSubscribeUser' => Array('self' => true),
+
+ 'OnRecommend' => Array('self' => true),
+ );
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Checks permissions of user
+ *
+ * @param kEvent $event
+ */
+ function CheckPermission(&$event)
+ {
+ if ($event->Name == 'OnLogin' || $event->Name == 'OnLogout') {
+ // permission is checked in OnLogin event directly
+ return true;
+ }
+
+ if (!$this->Application->IsAdmin()) {
+ $user_id = $this->Application->GetVar('u_id');
+ $items_info = $this->Application->GetVar($event->getPrefixSpecial(true));
+
+ if ($event->Name == 'OnCreate' && $user_id == -2) {
+ // "Guest" can create new users
+ return true;
+ }
+
+ if ($event->Name == 'OnUpdate' && $user_id > 0) {
+ $user_dummy =& $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true));
+ foreach ($items_info as $id => $field_values) {
+ if ($id != $user_id) {
+ // registered users can update their record only
+ return false;
+ }
+
+ $user_dummy->Load($id);
+ $status_field = array_shift($this->Application->getUnitOption($event->Prefix, 'StatusField'));
+
+ if ($user_dummy->GetDBField($status_field) != STATUS_ACTIVE) {
+ // not active user is not allowed to update his record (he could not activate himself manually)
+ return false;
+ }
+
+ if (isset($field_values[$status_field]) && $user_dummy->GetDBField($status_field) != $field_values[$status_field]) {
+ // user can't change status by himself
+ return false;
+ }
+ }
+ return true;
+ }
+
+ if ($event->Name == 'OnUpdate' && $user_id <= 0) {
+ // guests are not allowed to update their record, because they don't have it :)
+ return false;
+ }
+ }
+
+ return parent::CheckPermission($event);
+ }
+
+ function OnSessionExpire()
+ {
+ if( $this->Application->IsAdmin() ) {
+ $this->Application->Redirect('index', Array('expired' => 1), '', 'index.php');
+ }
+ else {
+ $http_query =& $this->Application->recallObject('HTTPQuery');
+ $get = $http_query->getRedirectParams();
+
+ $t = $this->Application->GetVar('t');
+ $get['js_redirect'] = $this->Application->ConfigValue('UseJSRedirect');
+ $this->Application->Redirect($t ? $t : 'index', $get);
+ }
+ }
+
+ /**
+ * Checks user data and logs it in if allowed
+ *
+ * @param kEvent $event
+ */
+ function OnLogin(&$event)
+ {
+ $object =& $this->Application->recallObject('u', null, Array('skip_autoload' => true));
+
+ $password = $this->Application->GetVar('password');
+ if(!$password)
+ {
+ $object->SetError('ValidateLogin', 'blank_password', 'lu_blank_password');
+ $event->status = erFAIL;
+ return false;
+ }
+
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ list($login_field, $submit_field) = $email_as_login && !$this->Application->IsAdmin() ? Array('Email', 'email') : Array('Login', 'login');
+ $login_value = $this->Application->GetVar($submit_field);
+
+ if ($this->Application->IsAdmin() && ($login_value == 'root')) {
+ // logging in "root" (admin only)
+ $root_password = $this->Application->ConfigValue('RootPass');
+ if ($root_password != md5($password)) {
+ $object->SetError('ValidateLogin', 'invalid_password', 'lu_invalid_password');
+ $event->status = erFAIL;
+ return false;
+ }
+ elseif ($this->checkLoginPermission($login_value)) {
+ $user_id = -1;
+ $object->Load($user_id);
+ $object->SetDBField('Login', $login_value);
+
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', $user_id);
+// $session->SetField('GroupList', implode(',', $groups) );
+ $this->Application->SetVar('u_id', $user_id);
+ $this->Application->StoreVar('user_id', $user_id);
+
+ $this->processLoginRedirect($event, $password);
+ return true;
+ }
+ else {
+ $object->SetError('ValidateLogin', 'invalid_license', 'la_invalid_license');
+ $event->status = erFAIL;
+ return false;
+ }
+ }
+
+ /*$sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (%s = %s) AND (Password = MD5(%s))';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $login_field, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );*/
+
+ $sql = 'SELECT PortalUserId FROM '.$object->TableName.' WHERE (Email = %1$s OR Login = %1$s) AND (Password = MD5(%2$s))';
+ $user_id = $this->Conn->GetOne( sprintf($sql, $this->Conn->qstr($login_value), $this->Conn->qstr($password) ) );
+
+ if ($user_id) {
+ $object->Load($user_id);
+ if ($object->GetDBField('Status') == STATUS_ACTIVE) {
+ $groups = $object->getMembershipGroups(true);
+ if(!$groups) $groups = Array();
+ array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') );
+ $this->Application->StoreVar( 'UserGroups', implode(',', $groups) );
+
+ if ($this->checkLoginPermission($login_value)) {
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', $user_id);
+ $session->SetField('GroupList', implode(',', $groups) );
+ $this->Application->SetVar('u_id', $user_id);
+ $this->Application->StoreVar('user_id', $user_id);
+ $this->Application->setVisitField('PortalUserId', $user_id);
+
+ $this_login = (int)$object->getPersistantVar('ThisLogin');
+ $object->setPersistantVar('LastLogin', $this_login);
+ $object->setPersistantVar('ThisLogin', adodb_mktime());
+ }
+ else {
+ $object->Load(-2);
+ $object->SetError('ValidateLogin', 'no_permission', 'lu_no_permissions');
+ $event->status = erFAIL;
+ }
+
+ $this->processLoginRedirect($event, $password);
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('pending_disabled_template');
+ }
+ }
+ else
+ {
+ $object->SetID(-2);
+ $object->SetError('ValidateLogin', 'invalid_password', 'lu_invalid_password');
+ $event->status = erFAIL;
+ }
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param string $user_name
+ * @return bool
+ */
+ function checkLoginPermission($user_name)
+ {
+ $ret = true;
+ if ($this->Application->IsAdmin()) {
+ $modules_helper =& $this->Application->recallObject('ModulesHelper');
+ if ($user_name != 'root') {
+ // root is virtual user, so allow him to login to admin in any case
+ $ret = $this->Application->CheckPermission('ADMIN', 1);
+ }
+ $ret = $ret && $modules_helper->checkLogin();
+ }
+ else {
+ $ret = $this->Application->CheckPermission('LOGIN', 1);
+ }
+ return $ret;
+ }
+
+ /**
+ * Process all required data and redirect logged-in user
+ *
+ * @param kEvent $event
+ */
+ function processLoginRedirect(&$event, $password)
+ {
+ $object =& $event->getObject();
+
+ $next_template = $this->Application->GetVar('next_template');
+ if ($next_template == '_ses_redirect') {
+ $location = $this->Application->BaseURL().$this->Application->RecallVar($next_template);
+ if( $this->Application->isDebugMode() && constOn('DBG_REDIRECT') )
+ {
+ $this->Application->Debugger->appendTrace();
+ echo "<b>Debug output above!!!</b> Proceed to redirect: <a href=\"$location\">$location</a><br>";
+ }
+ else {
+ header('Location: '.$location);
+ }
+
+ $session =& $this->Application->recallObject('Session');
+ $session->SaveData();
+ exit;
+ }
+
+ if ($next_template) {
+ $event->redirect = $next_template;
+ }
+
+ if ($this->Application->ConfigValue('UseJSRedirect')) {
+ $event->SetRedirectParam('js_redirect', 1);
+ }
+
+ $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LoginUser', $object->GetDBField('Login'), $password);
+ }
+
+ /**
+ * Called when user logs in using old in-portal
+ *
+ * @param kEvent $event
+ */
+ function OnInpLogin(&$event)
+ {
+ $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LoginUser', $event->getEventParam('user'), $event->getEventParam('pass') );
+
+ if ($event->redirect && is_string($event->redirect)) {
+ // some real template specified instead of true
+ $this->Application->Redirect($event->redirect, $event->redirect_params);
+ }
+ }
+
+ /**
+ * Called when user logs in using old in-portal
+ *
+ * @param kEvent $event
+ */
+ function OnInpLogout(&$event)
+ {
+ $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LogoutUser');
+ }
+
+ function OnLogout(&$event)
+ {
+ $sync_manager =& $this->Application->recallObjectP('UsersSyncronizeManager', null, Array(), 'InPortalSyncronize');
+ $sync_manager->performAction('LogoutUser');
+
+ $session =& $this->Application->recallObject('Session');
+ $session->SetField('PortalUserId', -2);
+ $this->Application->SetVar('u_id', -2);
+ $this->Application->StoreVar('user_id', -2);
+ $object =& $this->Application->recallObject('u');
+ $object->Load(-2);
+
+ $this->Application->DestroySession();
+
+ $group_list = $this->Application->ConfigValue('User_GuestGroup').','.$this->Application->ConfigValue('User_LoggedInGroup');
+ $session->SetField('GroupList', $group_list);
+ $this->Application->StoreVar('UserGroups', $group_list);
+
+ if ($this->Application->ConfigValue('UseJSRedirect')) {
+ $event->SetRedirectParam('js_redirect', 1);
+ }
+ }
+
+ /**
+ * Prefill states dropdown with correct values
+ *
+ * @param kEvent $event
+ * @access public
+ */
+ function OnPrepareStates(&$event)
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->PopulateStates($event, 'State', 'Country');
+
+ $object =& $event->getObject();
+
+ if( $object->isRequired('Country') && $cs_helper->CountryHasStates( $object->GetDBField('Country') ) ) $object->setRequired('State', true);
+ $object->setLogin();
+ }
+
+ /**
+ * Redirects user after succesfull registration to confirmation template (on Front only)
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemCreate(&$event)
+ {
+ $is_subscriber = $this->Application->GetVar('IsSubscriber');
+ if(!$is_subscriber)
+ {
+ $object =& $event->getObject();
+
+ $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
+ SET PrimaryGroup = 0
+ WHERE PortalUserId = '.$object->GetDBField('PortalUserId');
+ $this->Conn->Query($sql);
+
+ $group_id = $this->Application->ConfigValue('User_NewGroup');
+
+ $sql = 'REPLACE INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,1)';
+ $this->Conn->Query( sprintf($sql, $object->GetID(), $group_id) );
+ }
+ }
+
+ /**
+ * Login user if possible, if not then redirect to corresponding template
+ *
+ * @param kEvent $event
+ */
+ function autoLoginUser(&$event)
+ {
+ $object =& $event->getObject();
+ $this->Application->SetVar('u_id', $object->GetID() );
+
+ if($object->GetDBField('Status') == STATUS_ACTIVE)
+ {
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ list($login_field, $submit_field) = $email_as_login ? Array('Email', 'email') : Array('Login', 'login');
+
+ $this->Application->SetVar($submit_field, $object->GetDBField($login_field) );
+ $this->Application->SetVar('password', $object->GetDBField('Password_plain') );
+
+ $event->CallSubEvent('OnLogin');
+ }
+ }
+
+
+ /**
+ * When creating user & user with such email exists then force to use OnUpdate insted of ?
+ *
+ * @param kEvent $event
+ */
+ function OnSubstituteSubscriber(&$event)
+ {
+ $ret = false;
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
+ if($items_info)
+ {
+ list($id, $field_values) = each($items_info);
+ $user_email = $field_values['Email'];
+ if($user_email)
+ {
+ // check if is subscriber
+ $verify_user =& $this->Application->recallObject('u.verify', null, Array('skup_autoload' => true) );
+ $verify_user->Load($user_email, 'Email');
+ if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() )
+ {
+ $items_info = Array( $verify_user->GetDBField('PortalUserId') => $field_values );
+ $this->Application->SetVar($event->getPrefixSpecial(true), $items_info);
+ $ret = true;
+ }
+ }
+ }
+
+ if( isset($event->MasterEvent) )
+ {
+ $event->MasterEvent->setEventParam('is_subscriber_only', $ret);
+ }
+ else
+ {
+ $event->setEventParam('is_subscriber_only', $ret);
+ }
+ }
+
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ * @return bool
+ */
+ function isSubscriberOnly(&$event)
+ {
+ $event->CallSubEvent('OnSubstituteSubscriber');
+ $is_subscriber = false;
+ if( $event->getEventParam('is_subscriber_only') )
+ {
+ $is_subscriber = true;
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $this->OnUpdate($event);
+ if($event->status == erSUCCESS)
+ {
+ $this->OnAfterItemCreate($event);
+ $object->SendEmailEvents();
+ if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect) $this->autoLoginUser($event);
+ }
+ }
+ return $is_subscriber;
+ }
+
+ /**
+ * Creates new user
+ *
+ * @param kEvent $event
+ */
+ function OnCreate(&$event)
+ {
+ if( !$this->Application->IsAdmin() ) $this->setUserStatus($event);
+
+ if( !$this->isSubscriberOnly($event) )
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->CheckStateField($event, 'State', 'Country');
+
+ parent::OnCreate($event);
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+
+ $this->Application->SetVar('u_id', $object->getID() );
+
+ $this->setNextTemplate($event);
+
+ if( !$this->Application->IsAdmin() && ($event->status == erSUCCESS) && $event->redirect)
+ {
+ $object->SendEmailEvents();
+ $this->autoLoginUser($event);
+ }
+ }
+ }
+
+ /**
+ * Set's new user status based on config options
+ *
+ * @param kEvent $event
+ */
+ function setUserStatus(&$event)
+ {
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+
+ $new_users_allowed = $this->Application->ConfigValue('User_Allow_New');
+ // 1 - Instant, 2 - Not Allowed, 3 - Pending
+
+ switch ($new_users_allowed)
+ {
+ case 1: // Instant
+ $object->SetDBField('Status', 1);
+ $next_template = $this->Application->GetVar('registration_confirm_template');
+ if($next_template) $event->redirect = $next_template;
+ break;
+
+ case 3: // Pending
+ $next_template = $this->Application->GetVar('registration_confirm_pending_template');
+ if($next_template) $event->redirect = $next_template;
+ $object->SetDBField('Status', 2);
+ break;
+
+ case 2: // Not Allowed
+ $object->SetDBField('Status', 0);
+ break;
+ }
+
+ /*if ($object->GetDBField('PaidMember') == 1) {
+ $this->Application->HandleEvent($add_to_cart, 'ord:OnAddToCart');
+ $event->redirect = 'in-commerce/checkout/shop_cart';
+ } */
+
+ }
+
+
+
+
+ /**
+ * Set's new unique resource id to user
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeItemCreate(&$event)
+ {
+ $email_as_login = $this->Application->ConfigValue('Email_As_Login');
+ $object =& $event->getObject();
+ if ($email_as_login) {
+ $object->Fields['Email']['error_msgs']['unique'] = $this->Application->Phrase('lu_user_and_email_already_exist');
+ }
+
+ }
+
+ /**
+ * Set's new unique resource id to user
+ *
+ * @param kEvent $event
+ */
+ function OnAfterItemValidate(&$event)
+ {
+ $object =& $event->getObject();
+ $resource_id = $object->GetDBField('ResourceId');
+ if (!$resource_id)
+ {
+ $object->SetDBField('ResourceId', $this->Application->NextResourceId() );
+ }
+ }
+
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnRecommend(&$event){
+
+ $friend_email = $this->Application->GetVar('friend_email');
+ $friend_name = $this->Application->GetVar('friend_email');
+
+ if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $friend_email))
+ {
+
+ $send_params = array();
+ $send_params['to_email']=$friend_email;
+ $send_params['to_name']=$friend_name;
+
+ $user_id = $this->Application->GetVar('u_id');
+ $email_event = &$this->Application->EmailEventUser('SITE.SUGGEST', $user_id, $send_params);
+
+ if ($email_event->status == erSUCCESS){
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+ else {
+// $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+// $event->redirect = $this->Application->GetVar('template_fail');
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['send_error'] = $this->Application->Phrase('lu_email_send_error');
+ $object->FieldErrors['Email']['pseudo'] = 'send_error';
+ $event->status = erFAIL;
+
+ }
+ }
+ else {
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
+ $object->FieldErrors['Email']['pseudo'] = 'invalid_email';
+ $event->status = erFAIL;
+ }
+
+
+ }
+
+ /**
+ * Saves address changes and mades no redirect
+ *
+ * @param kEvent $event
+ */
+ function OnUpdateAddress(&$event)
+ {
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+
+ $items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
+ if($items_info)
+ {
+ list($id,$field_values) = each($items_info);
+ if($id > 0) $object->Load($id);
+ $object->SetFieldsFromHash($field_values);
+ $object->setID($id);
+ $object->Validate();
+ }
+
+ $event->redirect = false;
+ }
+
+ function OnSubscribeQuery(&$event){
+
+ $user_email = $this->Application->GetVar('subscriber_email');
+ if ( preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email) ){
+
+ $object = &$this->Application->recallObject($this->Prefix.'.subscriber', null, Array('skip_autoload' => true));
+
+ $this->Application->StoreVar('SubscriberEmail', $user_email);
+
+ if( $object->Load(array('Email'=>$user_email)) ){
+ $group_info = $this->GetGroupInfo($object->GetID());
+ if($group_info){
+ $event->redirect = $this->Application->GetVar('unsubscribe_template');
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('subscribe_template');
+ }
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('subscribe_template');
+ $this->Application->StoreVar('SubscriberEmail', $user_email);
+ }
+
+ }
+ else {
+
+ $object =& $this->Application->recallObject('u');
+ $object->ErrorMsgs['invalid_email'] = $this->Application->Phrase('lu_InvalidEmail');
+ $object->FieldErrors['SubscribeEmail']['pseudo'] = 'invalid_email';
+ $event->status = erFAIL;
+
+ }
+
+
+ //subscribe_query_ok_template
+ }
+
+ function OnSubscribeUser(&$event){
+
+ $object = &$this->Application->recallObject($this->Prefix.'.subscriber', Array('skip_autoload' => true));
+
+ $user_email = $this->Application->RecallVar('SubscriberEmail');
+
+ if (preg_match("/^[_a-zA-Z0-9-\.]+@[a-zA-Z0-9-\.]+\.[a-z]{2,4}$/", $user_email)){
+
+ if($object->Load(array('Email'=>$user_email))){
+
+ $group_info = $this->GetGroupInfo($object->GetID());
+
+ if ($group_info){
+ if ($event->getEventParam('no_unsubscribe')) return;
+
+ if ($group_info['PrimaryGroup']){
+ // delete user
+ $object->Delete();
+ }
+ else {
+ $this->RemoveSubscriberGroup($object->GetID());
+ }
+
+ $event->redirect = $this->Application->GetVar('unsubscribe_ok_template');
+
+ }
+ else {
+ $this->AddSubscriberGroup($object->GetID(), 0);
+ $event->redirect = $this->Application->GetVar('subscribe_ok_template');
+ }
+
+
+ }
+ else {
+
+ $object->SetField('Email', $user_email);
+ $object->SetField('Login', $user_email);
+ $object->SetDBField('dob', 1);
+ $object->SetDBField('dob_date', 1);
+ $object->SetDBField('dob_time', 1);
+ $ip = getenv('HTTP_X_FORWARDED_FOR')?getenv('HTTP_X_FORWARDED_FOR'):getenv('REMOTE_ADDR');
+ $object->SetDBField('ip', $ip);
+
+ $this->Application->SetVar('IsSubscriber', 1);
+
+ if ($object->Create()) {
+
+ $this->AddSubscriberGroup($object->GetID(), 1);
+ $event->redirect = $this->Application->GetVar('subscribe_ok_template');
+ }
+
+ $this->Application->SetVar('IsSubscriber', 0);
+ }
+ }
+ else {
+ // error handling here
+ $event->redirect = $this->Application->GetVar('subscribe_fail_template');
+ }
+
+
+ }
+
+ function AddSubscriberGroup($user_id, $is_primary){
+
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+ $sql = 'INSERT INTO '.TABLE_PREFIX.'UserGroup(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,'.$is_primary.')';
+ $this->Conn->Query( sprintf($sql, $user_id, $group_id) );
+ $this->Application->EmailEventAdmin('USER.SUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.SUBSCRIBE', $user_id);
+
+ }
+
+ function RemoveSubscriberGroup($user_id){
+
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$user_id.' AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup');
+ $this->Conn->Query($sql);
+ $this->Application->EmailEventAdmin('USER.UNSUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.UNSUBSCRIBE', $user_id);
+
+ }
+
+ function GetGroupInfo($user_id){
+
+ $group_info = $this->Conn->GetRow('SELECT * FROM '.TABLE_PREFIX.'UserGroup
+ WHERE PortalUserId='.$user_id.'
+ AND GroupId='.$this->Application->ConfigValue('User_SubscriberGroup'));
+ return $group_info;
+
+ }
+
+ function OnForgotPassword(&$event){
+
+ $user_object = &$this->Application->recallObject('u.forgot', null, Array('skip_autoload' => true));
+ $user_current_object = &$this->Application->recallObject('u');
+
+ $username = $this->Application->GetVar('username');
+ $email = $this->Application->GetVar('email');
+ $found = false;
+ $allow_reset = true;
+
+ if( strlen($username) )
+ {
+ if( $user_object->Load(array('Login'=>$username)) )
+ $found = ($user_object->GetDBField("Login")==$username && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
+ }
+ else if( strlen($email) )
+ {
+ if( $user_object->Load(array('Email'=>$email)) )
+ $found = ($user_object->GetDBField("Email")==$email && $user_object->GetDBField("Status")==1) && strlen($user_object->GetDBField("Password"));
+ }
+
+ if( $user_object->isLoaded() )
+ {
+ $PwResetConfirm = $user_object->GetDBField('PwResetConfirm');
+ $PwRequestTime = $user_object->GetDBField('PwRequestTime');
+ $PassResetTime = $user_object->GetDBField('PassResetTime');
+ //$MinPwResetDelay = $user_object->GetDBField('MinPwResetDelay');
+ $MinPwResetDelay = $this->Application->ConfigValue('Users_AllowReset');
+
+ $allow_reset = (strlen($PwResetConfirm) ?
+ adodb_mktime() > $PwRequestTime + $MinPwResetDelay :
+ adodb_mktime() > $PassResetTime + $MinPwResetDelay);
+ }
+
+ if($found && $allow_reset)
+ {
+ $this->Application->StoreVar('tmp_user_id', $user_object->GetDBField("PortalUserId"));
+ $this->Application->StoreVar('tmp_email', $user_object->GetDBField("Email"));
+ $this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
+
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+ else
+ {
+ if(!strlen($username) && !strlen($email))
+ {
+ $user_current_object->ErrorMsgs['forgotpw_nodata'] = $this->Application->Phrase('lu_ferror_forgotpw_nodata');
+ $user_current_object->FieldErrors['Login']['pseudo'] = 'forgotpw_nodata';
+ $user_current_object->FieldErrors['Email']['pseudo'] = 'forgotpw_nodata';
+ }
+ else
+ {
+ if($allow_reset)
+ {
+ if( strlen($username) ){
+ $user_current_object->ErrorMsgs['unknown_username'] = $this->Application->Phrase('lu_ferror_unknown_username');
+ $user_current_object->FieldErrors['Login']['pseudo']='unknown_username';
+ }
+ if( strlen($email) ){
+ $user_current_object->ErrorMsgs['unknown_email'] = $this->Application->Phrase('lu_ferror_unknown_email');
+ $user_current_object->FieldErrors['Email']['pseudo']='unknown_email';
+ }
+ }
+ else
+ {
+ $user_current_object->ErrorMsgs['reset_denied'] = $this->Application->Phrase('lu_ferror_reset_denied');
+ if( strlen($username) ){
+ $user_current_object->FieldErrors['Login']['pseudo']='reset_denied';
+ }
+ if( strlen($email) ){
+ $user_current_object->FieldErrors['Email']['pseudo']='reset_denied';
+ }
+ }
+ }
+
+ if($user_current_object->FieldErrors){
+ $event->redirect = false;
+ }
+ }
+
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnResetPassword(&$event){
+
+ $user_object = &$this->Application->recallObject('u.forgot');
+
+ if($user_object->Load($this->Application->RecallVar('tmp_user_id'))){
+
+ $this->Application->EmailEventUser('INCOMMERCEUSER.PSWDC', $user_object->GetDBField("PortalUserId"));
+ $event->redirect = $this->Application->GetVar('template_success');
+
+ $mod_object =& $this->Application->recallObject('mod.'.'In-Commerce');
+ $m_cat_id = $mod_object->GetDBField('RootCat');
+ $event->SetRedirectParam('pass', 'm');
+ //$event->SetRedirectParam('m_cat_id', $m_cat_id);
+ $this->Application->SetVar('m_cat_id', $m_cat_id);
+
+
+ }
+
+ }
+
+ function OnResetPasswordConfirmed(&$event){
+
+ $passed_key = $this->Application->GetVar('user_key');
+
+ $user_object = &$this->Application->recallObject('u.forgot');
+ $user_current_object = &$this->Application->recallObject('u');
+
+ if (strlen(trim($passed_key)) == 0) {
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = false;
+
+ $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
+ }
+
+
+ if($user_object->Load(array('PwResetConfirm'=>$passed_key)))
+ {
+ $exp_time = $user_object->GetDBField('PwRequestTime') + 3600;
+ $user_object->SetDBField("PwResetConfirm", '');
+ $user_object->SetDBField("PwRequestTime", 0);
+ if ( $exp_time > adodb_mktime() )
+ {
+ //$m_var_list_update['codevalidationresult'] = 'lu_resetpw_confirm_text';
+ $newpw = makepassword4();
+
+ $this->Application->StoreVar('password', $newpw);
+
+ $user_object->SetDBField("Password",$newpw);
+ $user_object->SetDBField("PassResetTime", adodb_mktime());
+ $user_object->SetDBField("PwResetConfirm", '');
+ $user_object->SetDBField("PwRequestTime", 0);
+ $user_object->Update();
+
+ $this->Application->SetVar('ForgottenPassword', $newpw);
+
+ $email_event_user = &$this->Application->EmailEventUser('INCOMMERCEUSER.PSWD', $user_object->GetDBField('PortalUserId'));
+ $email_event_admin = &$this->Application->EmailEventAdmin('INCOMMERCEUSER.PSWD');
+
+ $this->Application->DeleteVar('ForgottenPassword');
+
+ if ($email_event_user->status == erSUCCESS){
+ $event->redirect_params = array('opener' => 's', 'pass' => 'all');
+ $event->redirect = $this->Application->GetVar('template_success');
+ }
+
+ $user_object->SetDBField("Password",md5($newpw));
+ $user_object->Update();
+
+ } else {
+ $user_current_object->ErrorMsgs['code_expired'] = $this->Application->Phrase('lu_code_expired');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_expired';
+ $event->redirect = false;
+
+ }
+ } else {
+ $user_current_object->ErrorMsgs['code_is_not_valid'] = $this->Application->Phrase('lu_code_is_not_valid');
+ $user_current_object->FieldErrors['PwResetConfirm']['pseudo'] = 'code_is_not_valid';
+ $event->redirect = false;
+
+ }
+ }
+
+ function OnUpdate(&$event)
+ {
+ $cs_helper =& $this->Application->recallObject('CountryStatesHelper');
+ $cs_helper->CheckStateField($event, 'State', 'Country');
+
+ parent::OnUpdate($event);
+
+ $this->setNextTemplate($event);
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function setNextTemplate(&$event)
+ {
+ if( !$this->Application->IsAdmin() )
+ {
+ $event->redirect_params['opener'] = 's';
+ $object =& $event->getObject();
+ if($object->GetDBField('Status') == STATUS_ACTIVE)
+ {
+ $next_template = $this->Application->GetVar('next_template');
+ if($next_template) $event->redirect = $next_template;
+ }
+ }
+ }
+
+
+
+ /**
+ * Delete users from groups if their membership is expired
+ *
+ * @param kEvent $event
+ */
+ function OnCheckExpiredMembership(&$event)
+ {
+ // send pre-expiration reminders: begin
+ $pre_expiration = adodb_mktime() + $this->Application->ConfigValue('User_MembershipExpirationReminder') * 3600 * 24;
+ $sql = 'SELECT PortalUserId, GroupId
+ FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (ExpirationReminderSent = 0) AND (MembershipExpires < '.$pre_expiration.')';
+
+ $skip_clause = $event->getEventParam('skip_clause');
+ if ($skip_clause) {
+ $sql .= ' AND !('.implode(') AND !(', $skip_clause).')';
+ }
+
+ $records = $this->Conn->Query($sql);
+ if ($records) {
+ $conditions = Array();
+ foreach ($records as $record) {
+ $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRATION.NOTICE', $record['PortalUserId']);
+ $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRATION.NOTICE');
+ $conditions[] = '(PortalUserId = '.$record['PortalUserId'].' AND GroupId = '.$record['GroupId'].')';
+ }
+ $sql = 'UPDATE '.TABLE_PREFIX.'UserGroup
+ SET ExpirationReminderSent = 1
+ WHERE '.implode(' OR ', $conditions);
+ $this->Conn->Query($sql);
+ }
+ // send pre-expiration reminders: end
+
+ // remove users from groups with expired membership: begin
+ $sql = 'SELECT PortalUserId
+ FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
+ $user_ids = $this->Conn->GetCol($sql);
+ if ($user_ids) {
+ foreach ($user_ids as $id) {
+ $email_event_user =& $this->Application->EmailEventUser('USER.MEMBERSHIP.EXPIRED', $id);
+ $email_event_admin =& $this->Application->EmailEventAdmin('USER.MEMBERSHIP.EXPIRED');
+ }
+ }
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'UserGroup
+ WHERE (MembershipExpires IS NOT NULL) AND (MembershipExpires < '.adodb_mktime().')';
+ $this->Conn->Query($sql);
+ // remove users from groups with expired membership: end
+ }
+
+ /**
+ * Enter description here...
+ *
+ * @param kEvent $event
+ */
+ function OnRefreshForm(&$event)
+ {
+ $event->redirect = false;
+ $item_info = $this->Application->GetVar($event->Prefix_Special);
+ list($id, $fields) = each($item_info);
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $object->setID($id);
+ $object->IgnoreValidation = true;
+ $object->SetFieldsFromHash($fields);
+ }
+
+ /**
+ * Sets persistant variable
+ *
+ * @param kEvent $event
+ */
+ function OnSetPersistantVariable(&$event)
+ {
+ $object =& $event->getObject();
+
+ $field = $this->Application->GetVar('field');
+ $value = $this->Application->GetVar('value');
+ $object->setPersistantVar($field, $value);
+
+ $force_tab = $this->Application->GetVar('SetTab');
+ if ($force_tab) {
+ $this->Application->StoreVar('force_tab', $force_tab);
+ }
+ }
+
+ /**
+ * Overwritten to return user from order by special .ord
+ *
+ * @param kEvent $event
+ */
+ function getPassedId(&$event)
+ {
+ if ($event->Special == 'ord') {
+ $order =& $this->Application->recallObject('ord');
+ return $order->GetDBField('PortalUserId');
+ }
+ return parent::getPassedID($event);
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.64.2/core/units/users/users_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.64
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Event Timeline
Log In to Comment