Index: units/users/users_config.php =================================================================== --- units/users/users_config.php (revision 14094) +++ units/users/users_config.php (working copy) @@ -415,6 +415,12 @@ 'formatter' => 'kOptionsFormatter', 'options_sql' => 'SELECT %1$s FROM ' . TABLE_PREFIX . 'PortalGroup WHERE Enabled = 1 AND FrontRegistration = 1', 'option_key_field' => 'GroupId', 'option_title_field' => 'Name', 'default' => 0, ), + '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 14094) +++ 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); + } } } @@ -1267,6 +1272,20 @@ $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_subscriber = $this->GetGroupInfo($object->GetID()); + if ($currently_subscriber && !$object->GetDBField('SubscribeToMailing')) { + // wants to unsubscribe + $this->RemoveSubscriberGroup($object->GetID()); + } + elseif ($object->GetDBField('SubscribeToMailing')) { + // wants to subscribe + $this->AddSubscriberGroup($object->GetID(), 0); + } + } + if (!$this->Application->isAdmin || $object->IsTempTable()) { return ; } @@ -1572,6 +1591,9 @@ /* @var $cs_helper kCountryStatesHelper */ $cs_helper->PopulateStates($event, 'State', 'Country'); + + // get user subscription status + $object->SetDBField('SubscribeToMailing', $this->GetGroupInfo($object->GetID())? 1 : 0); } /**