Index: units/users/users_config.php =================================================================== --- units/users/users_config.php (revision 14318) +++ units/users/users_config.php (working copy) @@ -434,6 +434,13 @@ 'LocalImage' => Array ('type' => 'string', 'default' => ''), 'LocalPath' => Array ('type' => 'string', 'default' => ''), 'FullUrl' => Array ('type' => 'string', 'default' => ''), + + 'SubscribeToMailing' => Array ( + 'type' => 'int', + 'formatter' => 'kOptionsFormatter', + 'options' => Array(0 => 'lu_No', 1 => 'lu_Yes'), + 'use_phrases' => 1, 'default' => 0, + ), ), 'Grids' => Array( Index: units/users/users_event_handler.php =================================================================== --- units/users/users_event_handler.php (revision 14318) +++ units/users/users_event_handler.php (working copy) @@ -338,6 +338,11 @@ $sql = 'REPLACE INTO '.$ug_table.'(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,1)'; $this->Conn->Query( sprintf($sql, $object->GetID(), $group_id) ); + + // Front-End user selected to be subscribed to mailing + if (!$this->isAdmin && $object->GetDBField('SubscribeToMailing')) { + $this->AddSubscriberGroup($object->GetID(), 0); + } } } @@ -769,9 +774,11 @@ */ function GetGroupInfo($user_id) { - $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'UserGroup - WHERE (PortalUserId = ' . $user_id . ') - AND (GroupId = ' . $this->Application->ConfigValue('User_SubscriberGroup') . ')'; + $subscriber_group = $this->Application->ConfigValue('User_SubscriberGroup'); + + $sql = 'SELECT * + FROM ' . TABLE_PREFIX . 'UserGroup + WHERE (PortalUserId = ' . $user_id . ') AND (GroupId = ' . $subscriber_group . ')'; return $this->Conn->GetRow($sql); } @@ -1268,6 +1275,19 @@ $object =& $event->getObject(); /* @var $object UsersItem */ + // registered user selected to update his subscription status via profile on Front-End + if (!$this->Application->isAdmin && !$this->Application->GetVar('IsSubscriber')) + { + $currently_subscribed = $this->GetGroupInfo( $object->GetID() ); + + if ( $object->GetDBField('SubscribeToMailing') && !$currently_subscribed ) { + $this->AddSubscriberGroup($object->GetID(), 0); + } + elseif ( !$object->GetDBField('SubscribeToMailing') && $currently_subscribed ) { + $this->RemoveSubscriberGroup($object->GetID()); + } + } + if (!$this->Application->isAdmin || $object->IsTempTable()) { return ; } @@ -1573,6 +1593,9 @@ /* @var $cs_helper kCountryStatesHelper */ $cs_helper->PopulateStates($event, 'State', 'Country'); + + // get user subscription status + $object->SetDBField('SubscribeToMailing', $this->GetGroupInfo($object->GetID())? 1 : 0); } /**