Attached Files |
user_group_storage_core.patch [^] (44,053 bytes) 2011-07-07 10:51
[Show Content]
Index: admin/system_presets/simple/user_groups_g-ug.php
===================================================================
--- admin/system_presets/simple/user_groups_g-ug.php (revision 14260)
+++ admin/system_presets/simple/user_groups_g-ug.php (working copy)
@@ -19,7 +19,7 @@
// fields to hide
$hidden_fields = Array (
- /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+ /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to hide
@@ -29,7 +29,7 @@
// fields to make required
$required_fields = Array (
-/* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+/* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to make required
Index: admin/system_presets/simple/user_groups_u-ug.php
===================================================================
--- admin/system_presets/simple/user_groups_u-ug.php (revision 14260)
+++ admin/system_presets/simple/user_groups_u-ug.php (working copy)
@@ -19,7 +19,7 @@
// fields to hide
$hidden_fields = Array (
- /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+ /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to hide
@@ -29,7 +29,7 @@
// fields to make required
$required_fields = Array (
- /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+ /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to make required
Index: core/admin_templates/users/admins_edit.tpl
===================================================================
--- core/admin_templates/users/admins_edit.tpl (revision 14260)
+++ core/admin_templates/users/admins_edit.tpl (working copy)
@@ -60,7 +60,9 @@
<inp2:u_SaveWarning name="grid_save_warning"/>
<inp2:u_ErrorWarning name="form_error_warning"/>
-<input type="hidden" name="user_group" value="11"/>
+<inp2:m_RenderElement name="inp_edit_hidden" prefix="u" field="UserType"/>
+<inp2:m_RenderElement name="inp_edit_hidden" prefix="u" field="PrimaryGroupId"/>
+
<div id="scroll_container">
<table class="edit-form">
<inp2:m_RenderElement name="inp_id_label" prefix="u" field="PortalUserId" title="la_fld_Id"/>
Index: core/admin_templates/users/admins_list.tpl
===================================================================
--- core/admin_templates/users/admins_list.tpl (revision 14260)
+++ core/admin_templates/users/admins_list.tpl (working copy)
@@ -10,21 +10,22 @@
//do not rename - this function is used in default grid for double click!
function edit()
{
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
std_edit_item('u.admins', 'users/admins_edit');
}
var a_toolbar = new ToolBar();
a_toolbar.AddButton( new ToolBarButton('new_item', '<inp2:m_phrase label="la_ToolTip_Add" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('user_type', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
std_precreate_item('u.admins', 'users/admins_edit')
} ) );
a_toolbar.AddButton( new ToolBarButton('edit', '<inp2:m_phrase label="la_ToolTip_Edit" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_Edit" escape="1"/>', edit) );
a_toolbar.AddButton( new ToolBarButton('delete', '<inp2:m_phrase label="la_ToolTip_Delete" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
std_delete_items('u.admins')
} ) );
@@ -33,7 +34,7 @@
a_toolbar.AddButton( new ToolBarButton('clone', '<inp2:m_phrase label="la_ToolTip_CloneUser" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_CloneUser" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
submit_event('u.admins', 'OnMassCloneUsers');
} ) );
@@ -42,7 +43,7 @@
a_toolbar.AddButton( new ToolBarButton('refresh', '<inp2:m_phrase label="la_ToolTip_ResetSettings" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_ResetSettings" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
submit_event('u.admins', 'OnMassResetSettings');
} ) );
Index: core/admin_templates/users/users_list.tpl
===================================================================
--- core/admin_templates/users/users_list.tpl (revision 14260)
+++ core/admin_templates/users/users_list.tpl (working copy)
@@ -30,7 +30,7 @@
/*a_toolbar.AddButton (
new ToolBarButton(
- 'primary_user_group',
+ 'setprimary',
'<inp2:m_phrase label="la_ToolTip_PrimaryGroup" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_SetPrimary" escape="1"/>',
function() {
openSelector('u.regular', '<inp2:m_Link t="users/group_selector" pass="m,u"/>', 'PrimaryGroupId', '800x600', 'OnSaveSelected');
@@ -93,6 +93,6 @@
<inp2:m_RenderElement name="grid" PrefixSpecial="u.regular" IdField="PortalUserId" grid="RegularUsers"/>
<script type="text/javascript">
- Grids['u.regular'].SetDependantToolbarButtons( new Array('edit', 'delete', 'e-mail', 'approve', 'decline') );
+ Grids['u.regular'].SetDependantToolbarButtons( new Array('edit', 'delete', 'setprimary', 'e-mail', 'approve', 'decline') );
</script>
<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: core/install/install_schema.sql
===================================================================
--- core/install/install_schema.sql (revision 14260)
+++ core/install/install_schema.sql (working copy)
@@ -265,6 +265,8 @@
MinPwResetDelay int(11) NOT NULL DEFAULT '1800',
AdminLanguage int(11) DEFAULT NULL,
DisplayToPublic text,
+ UserType tinyint(4) NOT NULL,
+ PrimaryGroupId int(11) DEFAULT NULL,
PRIMARY KEY (PortalUserId),
UNIQUE KEY ResourceId (ResourceId),
UNIQUE KEY Login (Login),
@@ -273,7 +275,8 @@
KEY Modified (Modified),
KEY dob (dob),
KEY IsBanned (IsBanned),
- KEY AdminLanguage (AdminLanguage)
+ KEY AdminLanguage (AdminLanguage),
+ KEY UserType (UserType)
);
CREATE TABLE PortalUserCustomData (
@@ -328,14 +331,12 @@
);
CREATE TABLE UserGroup (
- PortalUserId int(11) NOT NULL default '0',
- GroupId int(11) NOT NULL default '0',
- MembershipExpires int(10) unsigned default NULL,
- PrimaryGroup tinyint(4) NOT NULL default '1',
- ExpirationReminderSent tinyint(4) NOT NULL default '0',
- PRIMARY KEY (PortalUserId,GroupId),
+ PortalUserId int(11) NOT NULL DEFAULT '0',
+ GroupId int(11) NOT NULL DEFAULT '0',
+ MembershipExpires int(10) unsigned DEFAULT NULL,
+ ExpirationReminderSent tinyint(4) NOT NULL DEFAULT '0',
+ PRIMARY KEY (PortalUserId,GroupId),
KEY GroupId (GroupId),
- KEY PrimaryGroup (PrimaryGroup),
KEY MembershipExpires (MembershipExpires),
KEY ExpirationReminderSent (ExpirationReminderSent)
);
Index: core/install/upgrades.sql
===================================================================
--- core/install/upgrades.sql (revision 14260)
+++ core/install/upgrades.sql (working copy)
@@ -1993,4 +1993,17 @@
SET l<%PRIMARY_LANGUAGE%>_Translation = 'Use Cron to run Agents'
WHERE PhraseKey = 'LA_USECRONFORREGULAREVENT' AND l<%PRIMARY_LANGUAGE%>_Translation = 'Use Cron for Running Regular Events';
-# ===== v 5.1.1 =====
\ No newline at end of file
+# ===== v 5.1.1 =====
+
+# ===== v 5.2.0-B1 =====
+ALTER TABLE PortalUser
+ ADD UserType TINYINT NOT NULL,
+ ADD PrimaryGroupId INT NULL,
+ ADD INDEX (UserType);
+
+UPDATE PortalUser u
+SET u.PrimaryGroupId = (SELECT ug.GroupId FROM <%TABLE_PREFIX%>UserGroup ug WHERE ug.PortalUserId = u.PortalUserId AND ug.PrimaryGroup = 1);
+
+UPDATE PortalUser u SET u.UserType = IF(u.PrimaryGroupId = 11, 1, 0);
+
+ALTER TABLE UserGroup DROP PrimaryGroup;
\ No newline at end of file
Index: core/kernel/constants.php
===================================================================
--- core/kernel/constants.php (revision 14428)
+++ core/kernel/constants.php (working copy)
@@ -156,4 +156,9 @@
define('reAFTER', 2);
define('hBEFORE', 1);
- define('hAFTER', 2);
\ No newline at end of file
+ define('hAFTER', 2);
+
+ class UserType {
+ const USER = 0;
+ const ADMIN = 1;
+ }
\ No newline at end of file
Index: core/kernel/utility/event.php
===================================================================
--- core/kernel/utility/event.php (revision 14260)
+++ core/kernel/utility/event.php (working copy)
@@ -277,16 +277,16 @@
*/
public function CallSubEvent($name)
{
- if ( strpos($name, ':') === false ) {
- // PrefixSpecial not specified -> use from current event
- $name = $this->getPrefixSpecial() . ':' . $name;
- }
+ if ( strpos($name, ':') === false ) {
+ // PrefixSpecial not specified -> use from current event
+ $name = $this->getPrefixSpecial() . ':' . $name;
+ }
- $child_event = new kEvent($name);
- $child_event->copyFrom($this, true);
+ $child_event = new kEvent($name);
+ $child_event->copyFrom($this, true);
- $this->Application->HandleEvent($child_event);
- $this->copyFrom($child_event);
+ $this->Application->HandleEvent($child_event);
+ $this->copyFrom($child_event);
$this->specificParams = $child_event->specificParams;
}
Index: core/units/user_groups/user_groups_config.php
===================================================================
--- core/units/user_groups/user_groups_config.php (revision 14260)
+++ core/units/user_groups/user_groups_config.php (working copy)
@@ -38,6 +38,7 @@
'' => Array(
'UserName' => 'CONCAT(u.LastName, \' \', u.FirstName)',
'UserLogin' => 'u.Login',
+ 'PrimaryGroup' => 'IF(u.PrimaryGroupId = %1$s.GroupId, 1, 0)',
),
),
'VirtualFields' => Array (
@@ -83,12 +84,11 @@
'TitleField' => 'GroupName',
'TableName' => TABLE_PREFIX.'UserGroup',
- 'ListSQLs' => Array( ''=>' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId'),
+ 'ListSQLs' => Array( ''=>' SELECT %1$s.* %2$s
+ FROM %1$s
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUser u ON %1$s.PortalUserId = u.PortalUserId'),
- 'ItemSQLs' => Array( ''=>' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId'),
-
'AutoDelete' => true,
'AutoClone' => false,
@@ -96,6 +96,7 @@
'' => Array(
'GroupName' => 'g.Name',
'GroupDescription' => 'g.Description',
+ 'PrimaryGroup' => 'IF(u.PrimaryGroupId = %1$s.GroupId, 1, 0)',
),
),
@@ -103,13 +104,17 @@
'PortalUserId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
'GroupId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
'MembershipExpires' => Array('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => null),
- 'PrimaryGroup' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 1),
'ExpirationReminderSent' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
),
'VirtualFields' => Array (
'GroupName' => Array('type' => 'string', 'default' => ''),
'GroupDescription' => Array('type' => 'string', 'default' => ''),
+ 'PrimaryGroup' => Array(
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 1
+ ),
),
Index: core/units/user_groups/user_groups_eh.php
===================================================================
--- core/units/user_groups/user_groups_eh.php (revision 14260)
+++ core/units/user_groups/user_groups_eh.php (working copy)
@@ -24,35 +24,37 @@
function OnProcessSelected(&$event)
{
if ($event->Prefix == 'u-ug') {
- $new_groups = $this->Application->GetVar('g');
- if (!$new_groups) {
- return ;
- }
+ $new_groups = $this->Application->GetVar('g');
+ if (!$new_groups) {
+ return ;
+ }
- $new_groups = array_keys($new_groups);
+ $new_groups = array_keys($new_groups);
- // don't insert duplicate group membership record
- $user_id = $this->Application->GetVar('u_id');
- $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:u');
- $sql = 'SELECT GroupId
- FROM '.$table_name.'
- WHERE PortalUserId = '.(int)$user_id;
- $old_groups = $this->Conn->GetCol($sql);
+ // don't insert duplicate group membership record
+ $user_id = $this->Application->GetVar('u_id');
+ $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:u');
- $new_groups = array_diff($new_groups, $old_groups);
- if ($new_groups) {
- foreach ($new_groups as $new_group) {
- $fields_hash = Array (
- 'GroupId' => $new_group,
- 'PortalUserId' => $user_id,
- 'PrimaryGroup' => 0,
- );
- $this->Conn->doInsert($fields_hash, $table_name);
+ $sql = 'SELECT GroupId
+ FROM '.$table_name.'
+ WHERE PortalUserId = '.(int)$user_id;
+ $old_groups = $this->Conn->GetCol($sql);
+
+ $new_groups = array_diff($new_groups, $old_groups);
+
+ if ($new_groups) {
+ foreach ($new_groups as $new_group) {
+ $fields_hash = Array (
+ 'GroupId' => $new_group,
+ 'PortalUserId' => $user_id,
+ );
+ $this->Conn->doInsert($fields_hash, $table_name);
+ }
}
}
- }
- if ($event->Prefix == 'g-ug') {
+ elseif ($event->Prefix == 'g-ug') {
$new_users = $this->Application->GetVar('u');
+
if (!$new_users) {
return ;
}
@@ -62,18 +64,19 @@
// don't insert duplicate group membership record
$group_id = $this->Application->GetVar('g_id');
$table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g');
+
$sql = 'SELECT PortalUserId
FROM ' . $table_name . '
WHERE GroupId = ' . (int)$group_id;
$old_users = $this->Conn->GetCol($sql);
$new_users = array_diff($new_users, $old_users);
+
if ($new_users) {
foreach ($new_users as $new_user) {
$fields_hash = Array (
'GroupId' => $group_id,
'PortalUserId' => $new_user,
- 'PrimaryGroup' => 0,
);
$this->Conn->doInsert($fields_hash, $table_name);
}
@@ -92,20 +95,13 @@
function OnSetPrimary(&$event)
{
$ids = $this->StoreSelectedIDs($event);
+
if ($ids) {
- $id = array_shift($ids);
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $user_id = $this->Application->GetVar('u_id');
+ $user =& $this->Application->recallObject('u');
+ /* @var $user kDBItem */
- $sql = 'UPDATE ' . $object->TableName . '
- SET PrimaryGroup = 0
- WHERE PortalUserId = ' . (int)$user_id;
- $this->Conn->Query($sql);
-
- $sql = 'UPDATE ' . $object->TableName . '
- SET PrimaryGroup = 1
- WHERE ' . $object->IDField . ' = ' . $id . ' AND PortalUserId = ' . (int)$user_id;
- $this->Conn->Query($sql);
+ $user->SetDBField('PrimaryGroupId', array_shift($ids));
+ $user->Update();
}
$this->clearSelectedIDs($event);
@@ -120,26 +116,36 @@
{
if ($event->Name == 'OnMassDelete' && $type == 'before') {
$ids = $event->getEventParam('ids');
+
if ($ids) {
$object =& $event->getObject( Array('skip_autoload' => true) );
if ($event->Prefix == 'u-ug') {
- $user_id = $this->Application->GetVar('u_id');
- $sql = 'SELECT '.$object->IDField.'
- FROM '.$object->TableName.'
- WHERE '.$object->IDField.' IN ('.implode(',', $ids).') AND PortalUserId = '.(int)$user_id.' AND PrimaryGroup = 0';
- $ids = $this->Conn->GetCol($sql);
+ // allow deleting non-primary group of current user ($ids - groups)
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . $this->Application->GetTempName(TABLE_PREFIX . 'PortalUser', 'prefix:u') . '
+ WHERE PortalUserId = ' . (int)$this->Application->GetVar('u_id');
+ $primary_group_id = (int)$this->Conn->GetOne($sql);
+
+ $index = array_search($primary_group_id, $ids);
+
+ if ($index !== false) {
+ unset($ids[$index]);
+ $event->setEventParam('ids', $ids);
+ }
}
elseif ($event->Prefix == 'g-ug') {
- $group_id = $this->Application->GetVar('g_id');
- $sql = 'SELECT '.$object->IDField.'
- FROM '.$object->TableName.'
- WHERE '.$object->IDField.' IN ('.implode(',', $ids).') AND GroupId = '.(int)$group_id.' AND PrimaryGroup = 0';
- $ids = $this->Conn->GetCol($sql);
+ // allow deleting users from group record, then it's not their primary group ($ids - users)
+ $group_id = (int)$this->Application->GetVar('g_id');
+
+ $sql = 'SELECT PortalUserId
+ FROM ' . TABLE_PREFIX . 'PortalUser' . '
+ WHERE PortalUserId IN (' . implode(',', $ids) . ') AND PrimaryGroupId = ' . $group_id;
+ $exclude_users = $this->Conn->GetCol($sql);
+
+ $event->setEventParam('ids', array_diff($ids, $exclude_users));
}
- $event->setEventParam('ids', $ids);
}
}
}
-
}
\ No newline at end of file
Index: core/units/users/users_config.php
===================================================================
--- core/units/users/users_config.php (revision 14260)
+++ core/units/users/users_config.php (working copy)
@@ -134,7 +134,7 @@
'users_list' => Array (
'prefixes' => Array ('u_List'), 'format' => "!la_title_Users!",
- 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'e-mail', 'export', 'view', 'dbl-click'),
+ 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'setprimary', 'approve', 'decline', 'e-mail', 'export', 'view', 'dbl-click'),
),
'users_edit' => Array (
@@ -286,20 +286,17 @@
'TableName' => TABLE_PREFIX.'PortalUser',
'ListSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'UserGroup ug ON %1$s.PortalUserId = ug.PortalUserId AND ug.PrimaryGroup = 1
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON ug.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.PrimaryGroupId = g.GroupId
LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId',
'online' => ' SELECT %1$s.* %2$s FROM %1$s
LEFT JOIN '.TABLE_PREFIX.'UserSession s ON s.PortalUserId = %1$s.PortalUserId
- LEFT JOIN '.TABLE_PREFIX.'UserGroup ug ON %1$s.PortalUserId = ug.PortalUserId AND ug.PrimaryGroup = 1
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON ug.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.PrimaryGroupId = g.GroupId
LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId',
),
'ItemSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'UserGroup ug ON %1$s.PortalUserId = ug.PortalUserId AND ug.PrimaryGroup = 1
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON ug.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.PrimaryGroupId = g.GroupId
LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId',
),
@@ -401,6 +398,16 @@
), 'use_phrases' => 1, 'multiple' => 1,
'default' => NULL
),
+ 'UserType' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'la_opt_UserTypeUser', 1 => 'la_opt_UserTypeAdmin'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 0
+ ),
+ 'PrimaryGroupId' => Array (
+ 'type' => 'int',
+ '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' => NULL
+ ),
),
'VirtualFields' => Array(
@@ -410,11 +417,6 @@
'RootPassword' => Array('type' => 'string', 'formatter' => 'kPasswordFormatter', 'encryption_method' => 'md5', 'verify_field' => 'VerifyRootPassword', 'skip_empty' => 1, 'default' => md5('') ),
'FullName' => Array ('type' => 'string', 'default' => ''),
- 'UserGroup' => Array (
- 'type' => 'int',
- '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,
- ),
),
'Grids' => Array(
Index: core/units/users/users_event_handler.php
===================================================================
--- core/units/users/users_event_handler.php (revision 14434)
+++ core/units/users/users_event_handler.php (working copy)
@@ -27,7 +27,8 @@
// admin
'OnSetPersistantVariable' => Array('self' => 'view'), // because setting to logged in user only
'OnUpdateRootPassword' => Array('self' => true),
- 'OnUpdatePassword' => Array('self' => true),
+ 'OnUpdatePassword' => Array('self' => true),
+ 'OnSaveSelected' => Array ('self' => 'view'),
// front
'OnRefreshForm' => Array('self' => true),
@@ -59,12 +60,12 @@
$object =& $event->getObject();
/* @var $object kDBList */
- if ($event->Special == 'admins') {
- $object->addFilter('primary_filter', 'ug.GroupId = 11');
+ if ($event->Special == 'regular') {
+ $object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::USER);
}
- if ($event->Special == 'regular') {
- $object->addFilter('primary_filter', 'ug.GroupId <> 11 OR ug.GroupId IS NULL');
+ if ($event->Special == 'admins') {
+ $object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::ADMIN);
}
if (!$this->Application->isAdminUser) {
@@ -77,16 +78,16 @@
if ($event->Special == 'group') {
$group_id = $this->Application->GetVar('g_id');
+
if ($group_id !== false) {
// show only users, that user doesn't belong to current group
- $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g');
$sql = 'SELECT PortalUserId
- FROM ' . $table_name . '
+ FROM ' . $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g') . '
WHERE GroupId = ' . (int)$group_id;
$user_ids = $this->Conn->GetCol($sql);
-// array_push($user_ids); // Guest & Everyone groups are set dynamically
+
if ($user_ids) {
- $object->addFilter('already_member_filter', '%1$s.PortalUserId NOT IN ('.implode(',', $user_ids).')');
+ $object->addFilter('already_member_filter', '%1$s.PortalUserId NOT IN (' . implode(',', $user_ids) . ')');
}
}
}
@@ -298,46 +299,24 @@
{
$this->saveUserImages($event);
- if ($this->Application->GetVar('skip_set_primary')) return;
- $is_subscriber = $this->Application->GetVar('IsSubscriber');
- if(!$is_subscriber)
- {
- $object =& $event->getObject();
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
- $ug_table = TABLE_PREFIX.'UserGroup';
- if ($object->IsTempTable()) {
- $ug_table = $this->Application->GetTempName($ug_table, 'prefix:'.$event->Prefix);
- }
+ $primary_group_id = $object->GetDBField('PrimaryGroupId');
- $sql = 'UPDATE '.$ug_table.'
- SET PrimaryGroup = 0
- WHERE PortalUserId = '.$object->GetDBField('PortalUserId');
- $this->Conn->Query($sql);
+ if ($primary_group_id) {
+ $ug_table = TABLE_PREFIX . 'UserGroup';
- // set primary group to user
- if ($this->Application->isAdminUser && $this->Application->GetVar('user_group')) {
- // while in admin you can set any group for new users
- $group_id = $this->Application->GetVar('user_group');
+ if ( $object->IsTempTable() ) {
+ $ug_table = $this->Application->GetTempName($ug_table, 'prefix:' . $event->Prefix);
}
- else {
- $group_id = $object->GetDBField('UserGroup');
- if ($group_id) {
- // check, that group is allowed for Front-End
- $sql = 'SELECT GroupId
- FROM ' . TABLE_PREFIX . 'PortalGroup
- WHERE GroupId = ' . (int)$group_id . ' AND FrontRegistration = 1';
- $group_id = $this->Conn->GetOne($sql);
- }
+ $fields_hash = Array (
+ 'PortalUserId' => $object->GetID(),
+ 'GroupId' => $primary_group_id,
+ );
- if (!$group_id) {
- // when group not selected -> use default group
- $group_id = $this->Application->ConfigValue('User_NewGroup');
- }
- }
-
- $sql = 'REPLACE INTO '.$ug_table.'(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,1)';
- $this->Conn->Query( sprintf($sql, $object->GetID(), $group_id) );
+ $this->Conn->doInsert($fields_hash, $ug_table, 'REPLACE');
}
}
@@ -369,18 +348,19 @@
{
$ret = false;
$object =& $event->getObject( Array('skip_autoload' => true) );
+
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- if($items_info)
- {
+
+ if ($items_info) {
list($id, $field_values) = each($items_info);
$user_email = isset($field_values['Email']) ? $field_values['Email'] : false;
- if($user_email)
- {
+
+ if ($user_email) {
// check if is subscriber
$verify_user =& $this->Application->recallObject('u.verify', null, Array('skip_autoload' => true) );
$verify_user->Load($user_email, 'Email');
- if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() )
- {
+
+ 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;
@@ -388,12 +368,10 @@
}
}
- if( isset($event->MasterEvent) )
- {
+ if ( isset($event->MasterEvent) ) {
$event->MasterEvent->setEventParam('is_subscriber_only', $ret);
}
- else
- {
+ else {
$event->setEventParam('is_subscriber_only', $ret);
}
}
@@ -443,18 +421,20 @@
$this->setUserStatus($event);
}
- if (!$this->isSubscriberOnly($event)) {
+ if ( !$this->isSubscriberOnly($event) ) {
$object =& $event->getObject( Array('skip_autoload' => true) );
/* @var $object kDBItem */
- if ($this->Application->ConfigValue('User_Password_Auto')) {
- $pass = kUtil::generatePassword(rand(5,8));
+
+ if ( $this->Application->ConfigValue('User_Password_Auto') ) {
+ $pass = kUtil::generatePassword( rand(5, 8) );
$object->SetField('Password', $pass);
$object->SetField('VerifyPassword', $pass);
- $this->Application->SetVar('user_password',$pass);
+ $this->Application->SetVar('user_password', $pass);
}
+
parent::OnCreate($event);
- $this->Application->SetVar('u.current_id', $object->getID() ); // for affil:OnRegisterAffiliate after hook
+ $this->Application->SetVar('u.current_id', $object->getID()); // for affil:OnRegisterAffiliate after hook
$this->setNextTemplate($event);
@@ -512,7 +492,7 @@
$cs_helper =& $this->Application->recallObject('CountryStatesHelper');
/* @var $cs_helper kCountryStatesHelper */
- if (!$this->isSubscriberOnly($event, true)) {
+ if ( !$this->isSubscriberOnly($event, true) ) {
$cs_helper->CheckStateField($event, 'State', 'Country');
}
else {
@@ -531,6 +511,7 @@
}
$object->setLogin();
+ $this->setUserGroup($object);
$user_helper =& $this->Application->recallObject('UserHelper');
/* @var $user_helper UserHelper */
@@ -542,6 +523,38 @@
}
/**
+ * Sets primary group of the user
+ *
+ * @param kDBItem $object
+ */
+ function setUserGroup(&$object)
+ {
+ if ($object->Special == 'subscriber') {
+ $object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_SubscriberGroup'));
+
+ return ;
+ }
+
+ // set primary group to user
+ if ( !$this->Application->isAdminUser ) {
+ $group_id = $object->GetDBField('PrimaryGroupId');
+
+ if ($group_id) {
+ // check, that group is allowed for Front-End
+ $sql = 'SELECT GroupId
+ FROM ' . TABLE_PREFIX . 'PortalGroup
+ WHERE GroupId = ' . (int)$group_id . ' AND FrontRegistration = 1';
+ $group_id = $this->Conn->GetOne($sql);
+ }
+
+ if (!$group_id) {
+ // when group not selected OR not allowed -> use default group
+ $object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_NewGroup'));
+ }
+ }
+ }
+
+ /**
* Set's new unique resource id to user
*
* @param kEvent $event
@@ -549,10 +562,12 @@
function OnAfterItemValidate(&$event)
{
$object =& $event->getObject();
+ /* @var $object kDBItem */
+
$resource_id = $object->GetDBField('ResourceId');
- if (!$resource_id)
- {
- $object->SetDBField('ResourceId', $this->Application->NextResourceId() );
+
+ if (!$resource_id) {
+ $object->SetDBField('ResourceId', $this->Application->NextResourceId());
}
}
@@ -654,21 +669,24 @@
function OnSubscribeQuery(&$event)
{
$user_email = $this->Application->GetVar('subscriber_email');
- if (preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email)) {
- $object =& $this->Application->recallObject($this->Prefix.'.subscriber', null, Array('skip_autoload' => true));
+ if ( preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email) ) {
+ $object =& $this->Application->recallObject($this->Prefix . '.subscriber', null, Array('skip_autoload' => true));
/* @var $object UsersItem */
- $this->Application->StoreVar('SubscriberEmail', $user_email);
+ $object->Load($user_email, 'Email');
+ $event->SetRedirectParam('subscriber_email', $user_email);
- $object->Load($user_email, 'Email');
- if ($object->isLoaded()) {
- $group_info = $this->GetGroupInfo($object->GetID());
- $event->redirect = $this->Application->GetVar($group_info ? 'unsubscribe_template' : 'subscribe_template');
+ if ( $object->isLoaded() ) {
+ if ( $this->isSubscribed($object) ) {
+ $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 {
@@ -688,75 +706,83 @@
*/
function OnSubscribeUser(&$event)
{
- $object = &$this->Application->recallObject($this->Prefix.'.subscriber', null, Array('skip_autoload' => true));
+ $object = &$this->Application->recallObject($this->Prefix . '.subscriber', null, Array('skip_autoload' => true));
/* @var $object UsersItem */
- $user_email = $this->Application->RecallVar('SubscriberEmail');
- if (preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email)) {
+ $user_email = $this->Application->GetVar('subscriber_email');
+
+ if ( preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email) ) {
$this->RemoveRequiredFields($object);
$object->Load($user_email, 'Email');
- if ($object->isLoaded()) {
- $group_info = $this->GetGroupInfo($object->GetID());
+ if ( $object->isLoaded() ) {
+ if ( $this->isSubscribed($object) ) {
+ if ( $event->getEventParam('no_unsubscribe') ) {
+ // for customization code from FormsEventHandler
+ return ;
+ }
- if ($group_info){
- if ($event->getEventParam('no_unsubscribe')) return;
-
- if ($group_info['PrimaryGroup']){
+ if ( $object->isSubscriberOnly() ) {
$this->Application->SetVar($object->getPrefixSpecial(true) . '_id', $object->GetID());
$delete_event = new kEvent($object->getPrefixSpecial() . ':OnDelete');
$this->Application->HandleEvent($delete_event);
}
else {
- $this->RemoveSubscriberGroup($object->GetID());
+ $this->RemoveSubscriberGroup( $object->GetID() );
}
$event->redirect = $this->Application->GetVar('unsubscribe_ok_template');
}
else {
- $this->AddSubscriberGroup($object->GetID(), 0);
+ $this->AddSubscriberGroup($object);
$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);
+ $object->SetDBField('Email', $user_email);
+ $object->SetDBField('Login', $user_email);
$object->SetDBField('Status', STATUS_ACTIVE); // make user subscriber Active by default
- $ip = getenv('HTTP_X_FORWARDED_FOR')?getenv('HTTP_X_FORWARDED_FOR'):getenv('REMOTE_ADDR');
- $object->SetDBField('ip', $ip);
+ $object->SetDBField('ip', $_SERVER['REMOTE_ADDR']);
- $this->Application->SetVar('IsSubscriber', 1);
-
- if ($object->Create()) {
- $this->AddSubscriberGroup($object->GetID(), 1);
+ if ( $object->Create() ) {
+ $this->AddSubscriberGroup($object);
$event->redirect = $this->Application->GetVar('subscribe_ok_template');
}
-
- $this->Application->SetVar('IsSubscriber', 0);
}
}
}
- function AddSubscriberGroup($user_id, $is_primary)
+ /**
+ * Adding user to subscribers group
+ *
+ * @param UsersItem $object
+ */
+ function AddSubscriberGroup(&$object)
{
- $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) );
+ if ( !$object->isSubscriberOnly() ) {
+ $fields_hash = Array (
+ 'PortalUserId' => $object->GetID(),
+ 'GroupId' => $this->Application->ConfigValue('User_SubscriberGroup'),
+ );
+ $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'UserGroup');
+ }
+
$this->Application->EmailEventAdmin('USER.SUBSCRIBE');
- $this->Application->EmailEventUser('USER.SUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.SUBSCRIBE', $object->GetID());
}
+ /**
+ * Removing user from subscribers group
+ *
+ * @param int $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');
+ WHERE PortalUserId = ' . $user_id . ' AND GroupId = ' . $group_id;
$this->Conn->Query($sql);
$this->Application->EmailEventAdmin('USER.UNSUBSCRIBE');
@@ -764,17 +790,20 @@
}
/**
- * Allows to detect user subscription status (subscribed or not)
+ * Checks user subscription status
*
- * @param int $user_id
+ * @param kDBItem $object
* @return bool
*/
- function GetGroupInfo($user_id)
+ function isSubscribed(&$object)
{
- $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'UserGroup
- WHERE (PortalUserId = ' . $user_id . ')
- AND (GroupId = ' . $this->Application->ConfigValue('User_SubscriberGroup') . ')';
- return $this->Conn->GetRow($sql);
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+
+ $sql = 'SELECT GroupId
+ FROM ' . TABLE_PREFIX . 'UserGroup
+ WHERE (PortalUserId = ' . $object->GetID() . ') AND (GroupId = ' . $group_id . ')';
+
+ return $this->Conn->GetOne($sql);
}
function OnForgotPassword(&$event)
@@ -1384,17 +1413,16 @@
$first_country = $this->Application->ConfigValue('User_Default_Registration_Country');
}
+ $fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
+
if ($first_country) {
// update user country dropdown sql
- $fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
$fields['Country']['options_sql'] = preg_replace('/ORDER BY (.*)/', 'ORDER BY IF (CountryStateId = '.$first_country.', 1, 0) DESC, \\1', $fields['Country']['options_sql']);
- $this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
}
// 2. set default user registration group
- $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields');
- $virtual_fields['UserGroup']['default'] = $this->Application->ConfigValue('User_NewGroup');
- $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields);
+ $fields['PrimaryGroupId']['default'] = $this->Application->ConfigValue('User_NewGroup');
+ $this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
// 3. allow avatar upload on Front-End
$file_helper =& $this->Application->recallObject('FileHelper');
@@ -1441,13 +1469,11 @@
return;
}
- $event->status=kEvent::erSUCCESS;
- $ids = $this->StoreSelectedIDs($event);
-
- $this->Application->SetVar('skip_set_primary', 1); // otherwise it will default primary group, search for skip_set_primary above
$temp_handler =& $this->Application->recallObject($event->Prefix.'_TempHandler', 'kTempTablesHandler');
/* @var $temp_handler kTempTablesHandler */
- $cloned_users = $temp_handler->CloneItems($event->Prefix, '', $ids);
+
+ $ids = $this->StoreSelectedIDs($event);
+ $temp_handler->CloneItems($event->Prefix, '', $ids);
$this->clearSelectedIDs($event);
}
@@ -1460,30 +1486,15 @@
{
$object =& $event->getObject();
/* @var $object kDBItem */
- $object->setRequired('Password', 0);
- $object->setRequired('VerifyPassword', 0);
- $object->SetDBField('Password', rand(100000000, 999999999));
- $object->SetDBField('CreatedOn', adodb_mktime());
- $object->SetDBField('ResourceId', false); // this will reset it
- // change email cause it should be unique
- $object->NameCopy(array(), $object->GetID(), 'Email', 'copy%1$s.%2$s');
+ $password = kUtil::generatePassword();
+ $object->SetField('Password', $password);
+ $object->SetField('VerifyPassword', $password);
- $object->UpdateFormattersSubFields();
- }
+ $object->SetDBField('ResourceId', 0); // this will reset it
- /**
- * Copy user groups after copying user
- *
- * @param kEvent $event
- */
- function OnAfterClone(&$event)
- {
- $id = $event->getEventParam('id');
- $original_id = $event->getEventParam('original_id');
-
- $sql = 'INSERT '.TABLE_PREFIX."UserGroup SELECT $id, GroupId, MembershipExpires, PrimaryGroup, 0 FROM ".TABLE_PREFIX."UserGroup WHERE PortalUserId = $original_id";
- $this->Conn->Query($sql);
+ // change email because it should be unique
+ $object->NameCopy(Array (), $object->GetID(), 'Email', 'copy%1$s.%2$s');
}
/**
@@ -1496,11 +1507,11 @@
$this->StoreSelectedIDs($event);
// remove current ID, otherwise group selector will use it in filters
- $this->Application->DeleteVar($event->getPrefixSpecial(true).'_id');
+ $this->Application->DeleteVar($event->getPrefixSpecial(true) . '_id');
}
/**
- * Adds selected link to listing
+ * Sets primary group of selected users
*
* @param kEvent $event
*/
@@ -1524,34 +1535,27 @@
$table_name = $this->Application->getUnitOption('ug', 'TableName');
+ // 1. mark group as primary
+ $sql = 'UPDATE ' . TABLE_PREFIX . 'PortalUser
+ SET PrimaryGroupId = ' . $primary_group_id . '
+ WHERE PortalUserId IN (' . implode(',', $user_ids) . ')';
+ $this->Conn->Query($sql);
+
$sql = 'SELECT PortalUserId
- FROM '.$table_name.'
- WHERE (GroupId = '.$primary_group_id.') AND (PortalUserId IN ('.implode(',', $user_ids).'))';
+ FROM ' . $table_name . '
+ WHERE (GroupId = ' . $primary_group_id . ') AND (PortalUserId IN (' . implode(',', $user_ids) . '))';
$existing_members = $this->Conn->GetCol($sql);
- // 1. reset primary group mark
- $sql = 'UPDATE '.$table_name.'
- SET PrimaryGroup = 0
- WHERE PortalUserId IN ('.implode(',', $user_ids).')';
- $this->Conn->Query($sql);
+ // 2. add new members to a group
+ $new_members = array_diff($user_ids, $existing_members);
- foreach ($user_ids as $user_id) {
- if (in_array($user_id, $existing_members)) {
- // 2. already member of that group -> just make primary
- $sql = 'UPDATE '.$table_name.'
- SET PrimaryGroup = 1
- WHERE (PortalUserId = '.$user_id.') AND (GroupId = '.$primary_group_id.')';
- $this->Conn->Query($sql);
- }
- else {
- // 3. not member of that group -> make member & make primary
- $fields_hash = Array (
- 'GroupId' => $primary_group_id,
- 'PortalUserId' => $user_id,
- 'PrimaryGroup' => 1,
- );
- $this->Conn->doInsert($fields_hash, $table_name);
- }
+ foreach ($new_members as $user_id) {
+ $fields_hash = Array (
+ 'GroupId' => $primary_group_id,
+ 'PortalUserId' => $user_id,
+ );
+
+ $this->Conn->doInsert($fields_hash, $table_name);
}
}
@@ -1608,6 +1612,19 @@
parent::OnPreCreate($event);
if ($event->status == kEvent::erSUCCESS) {
+ $user_type = $this->Application->GetVar('user_type');
+
+ if ($user_type) {
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $object->SetDBField('UserType', $user_type);
+
+ if ( $user_type == UserType::ADMIN ) {
+ $object->SetDBField('PrimaryGroupId', 11);
+ }
+ }
+
$this->_makePasswordRequired($event);
}
}
Index: core/units/users/users_item.php
===================================================================
--- core/units/users/users_item.php (revision 14432)
+++ core/units/users/users_item.php (working copy)
@@ -31,7 +31,7 @@
$sql = 'SELECT GroupId
FROM ' . TABLE_PREFIX . 'UserGroup
WHERE (PortalUserId = ' . $this->GetID() . ') AND ( (MembershipExpires IS NULL) OR ( MembershipExpires >= UNIX_TIMESTAMP() ) )
- ORDER BY PrimaryGroup DESC';
+ ORDER BY IF(GroupId = ' . $this->GetDBField('PrimaryGroupId') . ', 1, 0) DESC';
return $this->Conn->GetCol($sql);
}
@@ -69,15 +69,14 @@
}
}
+ /**
+ * Checks that user is subscriber only
+ *
+ * @return bool
+ */
function isSubscriberOnly()
{
- $subscribers_group_id = $this->Application->ConfigValue('User_SubscriberGroup');
- $sql = 'SELECT PortalUserId
- FROM '.TABLE_PREFIX.'UserGroup
- WHERE GroupId = '.$subscribers_group_id.' AND
- PortalUserId = '.$this->GetDBField('PortalUserId').' AND
- PrimaryGroup = 1';
- return $this->Conn->GetOne($sql) == $this->GetDBField('PortalUserId');
+ return $this->GetDBField('PrimaryGroupId') == $this->Application->ConfigValue('User_SubscriberGroup');
}
function Create($force_id=false, $system_create=false)
user_group_storage_modules.patch [^] (8,127 bytes) 2011-07-07 10:51
[Show Content]
Index: in-commerce/units/orders/order_calculator.php
===================================================================
--- in-commerce/units/orders/order_calculator.php (revision 14260)
+++ in-commerce/units/orders/order_calculator.php (working copy)
@@ -786,9 +786,9 @@
protected function getUserPrimaryGroup($user_id)
{
if ($user_id > 0) {
- $sql = 'SELECT GroupId
- FROM ' . TABLE_PREFIX . 'UserGroup
- WHERE PortalUserId = ' . $user_id . ' AND PrimaryGroup = 1';
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . TABLE_PREFIX . 'PortalUser
+ WHERE PortalUserId = ' . $user_id;
return $this->Conn->GetOne($sql);
}
Index: in-commerce/units/pricing/pricing_event_handler.php
===================================================================
--- in-commerce/units/pricing/pricing_event_handler.php (revision 14260)
+++ in-commerce/units/pricing/pricing_event_handler.php (working copy)
@@ -422,28 +422,34 @@
return ;
}
- $user_groups = $this->Application->RecallVar('UserGroups');
+ if ( $this->Application->ConfigValue('Comm_PriceBracketCalculation') == 1 ) {
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . TABLE_PREFIX . 'PortalUser
+ WHERE PortalUserId = ' . $this->Application->GetVar('u_id');
+ $pricing_group = $this->Conn->GetOne($sql);
- $pricing_method = $this->Application->ConfigValue('Comm_PriceBracketCalculation');
- if ($pricing_method == 1) {
- $primary_group = $this->Conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$this->Application->GetVar('u_id').' AND PrimaryGroup=1');
- $pricing_group = $primary_group;
if ($pricing_group) {
- $pricing_for_group_exists = $this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'ProductsPricing WHERE ProductId='.$this->Application->GetVar('p_id').' AND GroupId='.$primary_group.' AND Price IS NOT NULL');
+ $sql = 'SELECT COUNT(*)
+ FROM ' . TABLE_PREFIX . 'ProductsPricing
+ WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND GroupId = ' . $pricing_group . ' AND Price IS NOT NULL';
+ $pricing_for_group_exists = $this->Conn->GetOne($sql);
}
- if ($pricing_group && $pricing_for_group_exists > 0) {
- $pricing_group = $primary_group;
- }
- else {
+
+ if ( !$pricing_group || !$pricing_for_group_exists ) {
$pricing_group = $this->Application->ConfigValue('User_LoggedInGroup');
}
-
-
}
else {
+ $user_groups = $this->Application->RecallVar('UserGroups');
+
//$cheapest_group = $this->Conn->GetOne('SELECT GroupId FROM '.$object->TableName.' WHERE ProductId='.$this->Application->GetVar('p_id').' AND Price IS NOT NULL AND GroupId IN ('.$user_groups.') AND MinQty = 1 GROUP BY GroupId ORDER BY Price ASC');
- $effective_brackets = $this->Conn->Query('SELECT PriceId, Price, GroupId FROM '.$object->TableName.'
- WHERE ProductId='.$this->Application->GetVar('p_id').' AND Price IS NOT NULL AND GroupId IN ('.$user_groups.') ORDER BY GroupId ASC, MinQty ASC', 'PriceId');
+
+ $sql = 'SELECT PriceId, Price, GroupId
+ FROM ' . $object->TableName . '
+ WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND Price IS NOT NULL AND GroupId IN (' . $user_groups . ')
+ ORDER BY GroupId ASC, MinQty ASC';
+ $effective_brackets = $this->Conn->Query($sql, 'PriceId');
+
$group_prices = array();
$min_price = -1;
$cheapest_group = 0;
Index: in-commerce/units/products/products_event_handler.php
===================================================================
--- in-commerce/units/products/products_event_handler.php (revision 14260)
+++ in-commerce/units/products/products_event_handler.php (working copy)
@@ -770,44 +770,47 @@
$field_values = $event->getEventParam('field_values');
$item_data = unserialize($field_values['ItemData']);
- if (!getArrayValue($item_data,'PortalGroupId')) {
+ if ( !getArrayValue($item_data,'PortalGroupId') ) {
// is subscription product, but no group defined in it's properties
trigger_error('Invalid product <b>'.$field_values['ProductName'].'</b> (id: '.$field_values['ProductId'].')', E_USER_WARNING);
return false;
}
- $order_table = $this->Application->getUnitOption('ord', 'TableName');
- $order_idfield = $this->Application->getUnitOption('ord', 'IDField');
- $sql = 'SELECT PortalUserId FROM %s WHERE %s = %s';
- $user_id = $this->Conn->GetOne( sprintf($sql, $order_table, $order_idfield, $field_values['OrderId']) );
+ $sql = 'SELECT PortalUserId
+ FROM ' . $this->Application->getUnitOption('ord', 'TableName') . '
+ WHERE ' . $this->Application->getUnitOption('ord', 'IDField') . ' = ' . $field_values['OrderId'];
+ $user_id = $this->Conn->GetOne($sql);
$group_id = $item_data['PortalGroupId'];
$duration = $item_data['Duration'];
- $sql = 'SELECT * FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId = %s';
- $user_groups = $this->Conn->Query( sprintf($sql, $user_id), 'GroupId' );
+ $sql = 'SELECT *
+ FROM ' . TABLE_PREFIX . 'UserGroup
+ WHERE PortalUserId = ' . $user_id;
+ $user_groups = $this->Conn->Query($sql, 'GroupId');
- $sql = 'REPLACE INTO '.TABLE_PREFIX.'UserGroup (PortalUserId,GroupId,MembershipExpires,PrimaryGroup) VALUES (%s,%s,%s,%s)';
- if( !isset($user_groups[$group_id]) )
- {
- $primary_group = count($user_groups) == 0 ? 1 : 0;
+ if ( !isset($user_groups[$group_id]) ) {
$expire = adodb_mktime() + $duration;
}
else {
- $primary_group = $user_groups[$group_id]['PrimaryGroup'];
$expire = $user_groups[$group_id]['MembershipExpires'];
$expire = $expire < adodb_mktime() ? adodb_mktime() + $duration : $expire + $duration;
}
-/*
- // Customization healtheconomics.org
+ /*// Customization healtheconomics.org
if ($item_data['DurationType'] == 2) {
$expire = $item_data['AccessExpiration'];
}
- // Customization healtheconomics.org --
-*/
- $this->Conn->Query( sprintf($sql, $user_id, $group_id, $expire, $primary_group) );
+ // Customization healtheconomics.org --*/
+ $fields_hash = Array (
+ 'PortalUserId' => $user_id,
+ 'GroupId' => $group_id,
+ 'MembershipExpires' => $expire,
+ );
+
+ $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'UserGroup', 'REPLACE');
+
$sub_order =& $this->Application->recallObject('ord.-sub'.$event->getEventParam('next_sub_number'), 'ord');
$sub_order->SetDBField('IsRecurringBilling', getArrayValue($item_data, 'IsRecurringBilling') ? 1 : 0);
$sub_order->SetDBField('GroupId', $group_id);
@@ -815,8 +818,6 @@
$sub_order->SetDBField('NextCharge_time', $expire);
}
-
-
function OnDownloadableApprove(&$event)
{
$field_values = $event->getEventParam('field_values');
@@ -1000,7 +1001,7 @@
parent::OnAfterItemLoad($event);
$object =& $event->getObject();
- /* @var $object kDBItem */
+ /* @var $object ProductsItem */
$a_pricing = $object->getPrimaryPricing();
if (!$a_pricing) {
@@ -1266,22 +1267,22 @@
$user_id = $this->Application->RecallVar('user_id');
- $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields');
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . TABLE_PREFIX . 'PortalUser
+ WHERE PortalUserId = ' . $user_id;
+ $primary_group_id = $this->Conn->GetOne($sql);
- $sql = 'SELECT GroupId
- FROM ' . TABLE_PREFIX . 'UserGroup
- WHERE PrimaryGroup = 1 AND PortalUserId = ' . $user_id;
- $primary_group = $this->Conn->GetOne($sql);
-
- if (!$primary_group) {
+ if (!$primary_group_id) {
return;
}
$sub_select = ' SELECT pp.Price
FROM ' . TABLE_PREFIX . 'ProductsPricing AS pp
- WHERE pp.ProductId = %1$s.ProductId AND GroupId = ' . $primary_group . '
+ WHERE pp.ProductId = %1$s.ProductId AND GroupId = ' . $primary_group_id . '
ORDER BY MinQty
LIMIT 0,1';
+
+ $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields');
$calculated_fields['']['Price'] = 'IFNULL((' . $sub_select . '), ' . $calculated_fields['']['Price'] . ')';
$this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields);
}
user_group_storage_themes.patch [^] (2,534 bytes) 2011-07-07 10:51
[Show Content]
Index: advanced/platform/login/register.tpl
===================================================================
--- advanced/platform/login/register.tpl (revision 14260)
+++ advanced/platform/login/register.tpl (working copy)
@@ -78,7 +78,7 @@
<inp2:m_RenderElement name="inp_edit_box" prefix="u" field="Zip" title="lu_fld_Zip" style="width:55px" />
<inp2:m_if check="m_GetConfig" name="AllowSelectGroupOnFront">
- <inp2:m_RenderElement name="inp_edit_options" prefix="u" field="UserGroup" has_empty="1" title="lu_fld_UserGroup" />
+ <inp2:m_RenderElement name="inp_edit_options" prefix="u" field="PrimaryGroupId" title="lu_fld_UserGroup" />
</inp2:m_if>
<inp2:m_RenderElement name="inp_edit_options" prefix="u" field="Country" title="lu_fld_Country" has_empty="1" is_last="1"/>
Index: advanced/platform/mailing_list/subscribe.tpl
===================================================================
--- advanced/platform/mailing_list/subscribe.tpl (revision 14260)
+++ advanced/platform/mailing_list/subscribe.tpl (working copy)
@@ -44,6 +44,7 @@
<input class="button" name="events[u][OnSubscribeUser]" type="submit" value="<inp2:m_Phrase label="lu_btn_Yes" no_editing="1"/>" />
<input class="button" type="button" value="<inp2:m_Phrase label="lu_btn_No" no_editing="1"/>" onclick="redirect('<inp2:m_Link template="index"/>');" />
<input type="hidden" name="subscribe_ok_template" value="platform/mailing_list/subscribe_ok"/>
+ <input type="hidden" name="subscriber_email" value="<inp2:m_Get name='subscriber_email' html_escape='1'/>"/>
</form>
</inp2:m_RenderElement>
</div>
Index: advanced/platform/mailing_list/unsubscribe.tpl
===================================================================
--- advanced/platform/mailing_list/unsubscribe.tpl (revision 14260)
+++ advanced/platform/mailing_list/unsubscribe.tpl (working copy)
@@ -44,6 +44,7 @@
<input class="button" name="events[u][OnSubscribeUser]" type="submit" value="<inp2:m_Phrase label="lu_btn_Yes" no_editing="1"/>" />
<input class="button" type="button" value="<inp2:m_Phrase label="lu_btn_No" no_editing="1"/>" onclick="redirect('<inp2:m_Link template="index"/>');" />
<input type="hidden" name="unsubscribe_ok_template" value="platform/mailing_list/unsubscribe_ok"/>
+ <input type="hidden" name="subscriber_email" value="<inp2:m_Get name='subscriber_email' html_escape='1'/>"/>
</form>
</inp2:m_RenderElement>
</div>
user_group_storage_core_v2.patch [^] (50,490 bytes) 2011-07-07 12:59
[Show Content]
Index: admin/system_presets/simple/user_groups_g-ug.php
===================================================================
--- admin/system_presets/simple/user_groups_g-ug.php (revision 14434)
+++ admin/system_presets/simple/user_groups_g-ug.php (working copy)
@@ -19,7 +19,7 @@
// fields to hide
$hidden_fields = Array (
- /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+ /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to hide
@@ -29,7 +29,7 @@
// fields to make required
$required_fields = Array (
-/* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+/* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to make required
Index: admin/system_presets/simple/user_groups_u-ug.php
===================================================================
--- admin/system_presets/simple/user_groups_u-ug.php (revision 14434)
+++ admin/system_presets/simple/user_groups_u-ug.php (working copy)
@@ -19,7 +19,7 @@
// fields to hide
$hidden_fields = Array (
- /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+ /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to hide
@@ -29,7 +29,7 @@
// fields to make required
$required_fields = Array (
- /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+ /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to make required
Index: core/admin_templates/users/admins_edit.tpl
===================================================================
--- core/admin_templates/users/admins_edit.tpl (revision 14434)
+++ core/admin_templates/users/admins_edit.tpl (working copy)
@@ -60,7 +60,9 @@
<inp2:u_SaveWarning name="grid_save_warning"/>
<inp2:u_ErrorWarning name="form_error_warning"/>
-<input type="hidden" name="user_group" value="11"/>
+<inp2:m_RenderElement name="inp_edit_hidden" prefix="u" field="UserType"/>
+<inp2:m_RenderElement name="inp_edit_hidden" prefix="u" field="PrimaryGroupId"/>
+
<div id="scroll_container">
<table class="edit-form">
<inp2:m_RenderElement name="inp_id_label" prefix="u" field="PortalUserId" title="la_fld_Id"/>
Index: core/admin_templates/users/admins_list.tpl
===================================================================
--- core/admin_templates/users/admins_list.tpl (revision 14434)
+++ core/admin_templates/users/admins_list.tpl (working copy)
@@ -10,21 +10,22 @@
//do not rename - this function is used in default grid for double click!
function edit()
{
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
std_edit_item('u.admins', 'users/admins_edit');
}
var a_toolbar = new ToolBar();
a_toolbar.AddButton( new ToolBarButton('new_item', '<inp2:m_phrase label="la_ToolTip_Add" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('user_type', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
std_precreate_item('u.admins', 'users/admins_edit')
} ) );
a_toolbar.AddButton( new ToolBarButton('edit', '<inp2:m_phrase label="la_ToolTip_Edit" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_Edit" escape="1"/>', edit) );
a_toolbar.AddButton( new ToolBarButton('delete', '<inp2:m_phrase label="la_ToolTip_Delete" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
std_delete_items('u.admins')
} ) );
@@ -33,7 +34,7 @@
a_toolbar.AddButton( new ToolBarButton('clone', '<inp2:m_phrase label="la_ToolTip_CloneUser" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_CloneUser" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
submit_event('u.admins', 'OnMassCloneUsers');
} ) );
@@ -42,7 +43,7 @@
a_toolbar.AddButton( new ToolBarButton('refresh', '<inp2:m_phrase label="la_ToolTip_ResetSettings" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_ResetSettings" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
submit_event('u.admins', 'OnMassResetSettings');
} ) );
Index: core/admin_templates/users/users_list.tpl
===================================================================
--- core/admin_templates/users/users_list.tpl (revision 14434)
+++ core/admin_templates/users/users_list.tpl (working copy)
@@ -30,7 +30,7 @@
/*a_toolbar.AddButton (
new ToolBarButton(
- 'primary_user_group',
+ 'setprimary',
'<inp2:m_phrase label="la_ToolTip_PrimaryGroup" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_SetPrimary" escape="1"/>',
function() {
openSelector('u.regular', '<inp2:m_Link t="users/group_selector" pass="m,u"/>', 'PrimaryGroupId', '800x600', 'OnSaveSelected');
@@ -93,6 +93,6 @@
<inp2:m_RenderElement name="grid" PrefixSpecial="u.regular" IdField="PortalUserId" grid="RegularUsers"/>
<script type="text/javascript">
- Grids['u.regular'].SetDependantToolbarButtons( new Array('edit', 'delete', 'e-mail', 'approve', 'decline') );
+ Grids['u.regular'].SetDependantToolbarButtons( new Array('edit', 'delete', 'setprimary', 'e-mail', 'approve', 'decline') );
</script>
<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: core/install/english.lang
===================================================================
--- core/install/english.lang (revision 14434)
+++ core/install/english.lang (working copy)
@@ -1499,8 +1499,9 @@
<PHRASE Label="la_Unchanged" Module="Core" Type="1">VW5jaGFuZ2Vk</PHRASE>
<PHRASE Label="la_Unicode" Module="Core" Type="1">VW5pY29kZQ==</PHRASE>
<PHRASE Label="la_updating_config" Module="Core" Type="1">VXBkYXRpbmcgQ29uZmlndXJhdGlvbg==</PHRASE>
- <PHRASE Label="la_Upload" Module="Core" Type="1">VXBsb2Fk</PHRASE>
+ <PHRASE Label="la_Upload" Module="Core" Type="1">VXBsb2Fk</PHRASE>
<PHRASE Label="la_UseCronForRegularEvent" Module="Core" Type="1">VXNlIENyb24gdG8gcnVuIEFnZW50cw==</PHRASE>
+ <PHRASE Label="la_users_admin_group" Module="Core" Type="1">QXNzaWduIGFkbWluaXN0cmF0b3JzIHRvIGdyb3Vw</PHRASE>
<PHRASE Label="la_users_allow_new" Module="Core" Type="1">QWxsb3cgbmV3IHVzZXIgcmVnaXN0cmF0aW9u</PHRASE>
<PHRASE Label="la_users_assign_all_to" Module="Core" Type="1">QXNzaWduIEFsbCBVc2VycyBUbyBHcm91cA==</PHRASE>
<PHRASE Label="la_users_guest_group" Module="Core" Type="1">QXNzaWduIHVzZXJzIG5vdCBsb2dnZWQgaW4gdG8gZ3JvdXA=</PHRASE>
Index: core/install/install_data.sql
===================================================================
--- core/install/install_data.sql (revision 14434)
+++ core/install/install_data.sql (working copy)
@@ -109,9 +109,10 @@
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'User_LoggedInGroup', '15', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_users_assign_all_to', 'select', NULL, '0=lu_none||<SQL+>SELECT GroupId as OptionValue, Name as OptionName FROM <PREFIX>PortalGroup WHERE Enabled=1 AND Personal=0</SQL>', 10.09, 0, 1, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'User_GuestGroup', '14', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_users_guest_group', 'select', NULL, '0=lu_none||<SQL+>SELECT GroupId as OptionValue, Name as OptionName FROM <PREFIX>PortalGroup WHERE Enabled=1 AND Personal=0</SQL>', 10.1, 0, 1, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'User_SubscriberGroup', '12', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_users_subscriber_group', 'select', NULL, '0=lu_none||<SQL+>SELECT GroupId as OptionValue, Name as OptionName FROM <PREFIX>PortalGroup WHERE Enabled=1 AND Personal=0</SQL>', 10.11, 0, 1, NULL);
-INSERT INTO ConfigurationValues VALUES(DEFAULT, 'User_Default_Registration_Country', '', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_config_DefaultRegistrationCountry', 'select', NULL, '=+||<SQL+>SELECT l%3$s_Name AS OptionName, CountryStateId AS OptionValue FROM <PREFIX>CountryStates WHERE Type = 1 ORDER BY OptionName</SQL>', 10.12, 0, 0, NULL);
-INSERT INTO ConfigurationValues VALUES(DEFAULT, 'AllowSelectGroupOnFront', '0', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_config_AllowSelectGroupOnFront', 'checkbox', NULL, NULL, 10.13, 0, 0, NULL);
-INSERT INTO ConfigurationValues VALUES(DEFAULT, 'DefaultSettingsUserId', '-1', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_prompt_DefaultUserId', 'text', NULL, NULL, 10.14, 0, 0, NULL);
+INSERT INTO ConfigurationValues VALUES(DEFAULT, 'User_AdminGroup', '11', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_users_admin_group', 'select', NULL, '0=lu_none||<SQL+>SELECT GroupId as OptionValue, Name as OptionName FROM <PREFIX>PortalGroup WHERE Enabled=1 AND Personal=0</SQL>', 10.12, 0, 1, NULL);
+INSERT INTO ConfigurationValues VALUES(DEFAULT, 'User_Default_Registration_Country', '', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_config_DefaultRegistrationCountry', 'select', NULL, '=+||<SQL+>SELECT l%3$s_Name AS OptionName, CountryStateId AS OptionValue FROM <PREFIX>CountryStates WHERE Type = 1 ORDER BY OptionName</SQL>', 10.13, 0, 0, NULL);
+INSERT INTO ConfigurationValues VALUES(DEFAULT, 'AllowSelectGroupOnFront', '0', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_config_AllowSelectGroupOnFront', 'checkbox', NULL, NULL, 10.14, 0, 0, NULL);
+INSERT INTO ConfigurationValues VALUES(DEFAULT, 'DefaultSettingsUserId', '-1', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_prompt_DefaultUserId', 'text', NULL, NULL, 10.15, 0, 0, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'User_Votes_Deny', '5', 'In-Portal:Users', 'in-portal:configure_users', 'la_Text_Restrictions', 'la_users_votes_deny', 'text', '', '', 20.01, 0, 1, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'User_Review_Deny', '5', 'In-Portal:Users', 'in-portal:configure_users', 'la_Text_Restrictions', 'la_users_review_deny', 'text', '', '', 20.02, 0, 1, NULL);
INSERT INTO ConfigurationValues VALUES(DEFAULT, 'u_MaxImageCount', '5', 'In-Portal:Users', 'in-portal:configure_users', 'la_section_ImageSettings', 'la_config_MaxImageCount', 'text', '', '', 30.01, 0, 0, NULL);
Index: core/install/install_schema.sql
===================================================================
--- core/install/install_schema.sql (revision 14434)
+++ core/install/install_schema.sql (working copy)
@@ -265,6 +265,8 @@
MinPwResetDelay int(11) NOT NULL DEFAULT '1800',
AdminLanguage int(11) DEFAULT NULL,
DisplayToPublic text,
+ UserType tinyint(4) NOT NULL,
+ PrimaryGroupId int(11) DEFAULT NULL,
PRIMARY KEY (PortalUserId),
UNIQUE KEY ResourceId (ResourceId),
UNIQUE KEY Login (Login),
@@ -273,7 +275,8 @@
KEY Modified (Modified),
KEY dob (dob),
KEY IsBanned (IsBanned),
- KEY AdminLanguage (AdminLanguage)
+ KEY AdminLanguage (AdminLanguage),
+ KEY UserType (UserType)
);
CREATE TABLE PortalUserCustomData (
@@ -328,14 +331,12 @@
);
CREATE TABLE UserGroup (
- PortalUserId int(11) NOT NULL default '0',
- GroupId int(11) NOT NULL default '0',
- MembershipExpires int(10) unsigned default NULL,
- PrimaryGroup tinyint(4) NOT NULL default '1',
- ExpirationReminderSent tinyint(4) NOT NULL default '0',
- PRIMARY KEY (PortalUserId,GroupId),
+ PortalUserId int(11) NOT NULL DEFAULT '0',
+ GroupId int(11) NOT NULL DEFAULT '0',
+ MembershipExpires int(10) unsigned DEFAULT NULL,
+ ExpirationReminderSent tinyint(4) NOT NULL DEFAULT '0',
+ PRIMARY KEY (PortalUserId,GroupId),
KEY GroupId (GroupId),
- KEY PrimaryGroup (PrimaryGroup),
KEY MembershipExpires (MembershipExpires),
KEY ExpirationReminderSent (ExpirationReminderSent)
);
Index: core/install/upgrades.sql
===================================================================
--- core/install/upgrades.sql (revision 14434)
+++ core/install/upgrades.sql (working copy)
@@ -1993,4 +1993,23 @@
SET l<%PRIMARY_LANGUAGE%>_Translation = 'Use Cron to run Agents'
WHERE PhraseKey = 'LA_USECRONFORREGULAREVENT' AND l<%PRIMARY_LANGUAGE%>_Translation = 'Use Cron for Running Regular Events';
-# ===== v 5.1.1 =====
\ No newline at end of file
+# ===== v 5.1.1 =====
+
+# ===== v 5.2.0-B1 =====
+ALTER TABLE PortalUser
+ ADD UserType TINYINT NOT NULL,
+ ADD PrimaryGroupId INT NULL,
+ ADD INDEX (UserType);
+
+UPDATE PortalUser u
+SET u.PrimaryGroupId = (SELECT ug.GroupId FROM <%TABLE_PREFIX%>UserGroup ug WHERE ug.PortalUserId = u.PortalUserId AND ug.PrimaryGroup = 1);
+
+UPDATE PortalUser u SET u.UserType = IF(u.PrimaryGroupId = 11, 1, 0);
+
+ALTER TABLE UserGroup DROP PrimaryGroup;
+
+UPDATE ConfigurationValues
+SET DisplayOrder = DisplayOrder + 0.01
+WHERE `ModuleOwner` = 'In-Portal:Users' AND `Section` = 'in-portal:configure_users' AND DisplayOrder BETWEEN 10.12 AND 20.00;
+
+INSERT INTO ConfigurationValues VALUES(DEFAULT, 'User_AdminGroup', '11', 'In-Portal:Users', 'in-portal:configure_users', 'la_title_General', 'la_users_admin_group', 'select', NULL, '0=lu_none||<SQL+>SELECT GroupId as OptionValue, Name as OptionName FROM <PREFIX>PortalGroup WHERE Enabled=1 AND Personal=0</SQL>', 10.12, 0, 1, NULL);
\ No newline at end of file
Index: core/kernel/constants.php
===================================================================
--- core/kernel/constants.php (revision 14434)
+++ core/kernel/constants.php (working copy)
@@ -156,4 +156,9 @@
define('reAFTER', 2);
define('hBEFORE', 1);
- define('hAFTER', 2);
\ No newline at end of file
+ define('hAFTER', 2);
+
+ class UserType {
+ const USER = 0;
+ const ADMIN = 1;
+ }
\ No newline at end of file
Index: core/kernel/utility/event.php
===================================================================
--- core/kernel/utility/event.php (revision 14434)
+++ core/kernel/utility/event.php (working copy)
@@ -277,16 +277,16 @@
*/
public function CallSubEvent($name)
{
- if ( strpos($name, ':') === false ) {
- // PrefixSpecial not specified -> use from current event
- $name = $this->getPrefixSpecial() . ':' . $name;
- }
+ if ( strpos($name, ':') === false ) {
+ // PrefixSpecial not specified -> use from current event
+ $name = $this->getPrefixSpecial() . ':' . $name;
+ }
- $child_event = new kEvent($name);
- $child_event->copyFrom($this, true);
+ $child_event = new kEvent($name);
+ $child_event->copyFrom($this, true);
- $this->Application->HandleEvent($child_event);
- $this->copyFrom($child_event);
+ $this->Application->HandleEvent($child_event);
+ $this->copyFrom($child_event);
$this->specificParams = $child_event->specificParams;
}
Index: core/units/helpers/user_helper.php
===================================================================
--- core/units/helpers/user_helper.php (revision 14434)
+++ core/units/helpers/user_helper.php (working copy)
@@ -188,6 +188,13 @@
$groups = Array();
}
+ if ( $object->GetDBField('UserType') == UserType::USER ) {
+ array_push($groups, $this->Application->ConfigValue('User_NewGroup') );
+ }
+ elseif ( $object->GetDBField('UserType') == UserType::ADMIN ) {
+ array_push($groups, $this->Application->ConfigValue('User_AdminGroup') );
+ }
+
// store groups, because kApplication::CheckPermission will use them!
array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') );
$this->Application->StoreVar( 'UserGroups', implode(',', $groups) );
Index: core/units/user_groups/user_groups_config.php
===================================================================
--- core/units/user_groups/user_groups_config.php (revision 14434)
+++ core/units/user_groups/user_groups_config.php (working copy)
@@ -38,6 +38,7 @@
'' => Array(
'UserName' => 'CONCAT(u.LastName, \' \', u.FirstName)',
'UserLogin' => 'u.Login',
+ 'PrimaryGroup' => 'IF(u.PrimaryGroupId = %1$s.GroupId, 1, 0)',
),
),
'VirtualFields' => Array (
@@ -83,12 +84,11 @@
'TitleField' => 'GroupName',
'TableName' => TABLE_PREFIX.'UserGroup',
- 'ListSQLs' => Array( ''=>' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId'),
+ 'ListSQLs' => Array( ''=>' SELECT %1$s.* %2$s
+ FROM %1$s
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUser u ON %1$s.PortalUserId = u.PortalUserId'),
- 'ItemSQLs' => Array( ''=>' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId'),
-
'AutoDelete' => true,
'AutoClone' => false,
@@ -96,6 +96,7 @@
'' => Array(
'GroupName' => 'g.Name',
'GroupDescription' => 'g.Description',
+ 'PrimaryGroup' => 'IF(u.PrimaryGroupId = %1$s.GroupId, 1, 0)',
),
),
@@ -103,13 +104,17 @@
'PortalUserId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
'GroupId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
'MembershipExpires' => Array('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => null),
- 'PrimaryGroup' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 1),
'ExpirationReminderSent' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
),
'VirtualFields' => Array (
'GroupName' => Array('type' => 'string', 'default' => ''),
'GroupDescription' => Array('type' => 'string', 'default' => ''),
+ 'PrimaryGroup' => Array(
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 1
+ ),
),
Index: core/units/user_groups/user_groups_eh.php
===================================================================
--- core/units/user_groups/user_groups_eh.php (revision 14434)
+++ core/units/user_groups/user_groups_eh.php (working copy)
@@ -24,35 +24,37 @@
function OnProcessSelected(&$event)
{
if ($event->Prefix == 'u-ug') {
- $new_groups = $this->Application->GetVar('g');
- if (!$new_groups) {
- return ;
- }
+ $new_groups = $this->Application->GetVar('g');
+ if (!$new_groups) {
+ return ;
+ }
- $new_groups = array_keys($new_groups);
+ $new_groups = array_keys($new_groups);
- // don't insert duplicate group membership record
- $user_id = $this->Application->GetVar('u_id');
- $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:u');
- $sql = 'SELECT GroupId
- FROM '.$table_name.'
- WHERE PortalUserId = '.(int)$user_id;
- $old_groups = $this->Conn->GetCol($sql);
+ // don't insert duplicate group membership record
+ $user_id = $this->Application->GetVar('u_id');
+ $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:u');
- $new_groups = array_diff($new_groups, $old_groups);
- if ($new_groups) {
- foreach ($new_groups as $new_group) {
- $fields_hash = Array (
- 'GroupId' => $new_group,
- 'PortalUserId' => $user_id,
- 'PrimaryGroup' => 0,
- );
- $this->Conn->doInsert($fields_hash, $table_name);
+ $sql = 'SELECT GroupId
+ FROM '.$table_name.'
+ WHERE PortalUserId = '.(int)$user_id;
+ $old_groups = $this->Conn->GetCol($sql);
+
+ $new_groups = array_diff($new_groups, $old_groups);
+
+ if ($new_groups) {
+ foreach ($new_groups as $new_group) {
+ $fields_hash = Array (
+ 'GroupId' => $new_group,
+ 'PortalUserId' => $user_id,
+ );
+ $this->Conn->doInsert($fields_hash, $table_name);
+ }
}
}
- }
- if ($event->Prefix == 'g-ug') {
+ elseif ($event->Prefix == 'g-ug') {
$new_users = $this->Application->GetVar('u');
+
if (!$new_users) {
return ;
}
@@ -62,18 +64,19 @@
// don't insert duplicate group membership record
$group_id = $this->Application->GetVar('g_id');
$table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g');
+
$sql = 'SELECT PortalUserId
FROM ' . $table_name . '
WHERE GroupId = ' . (int)$group_id;
$old_users = $this->Conn->GetCol($sql);
$new_users = array_diff($new_users, $old_users);
+
if ($new_users) {
foreach ($new_users as $new_user) {
$fields_hash = Array (
'GroupId' => $group_id,
'PortalUserId' => $new_user,
- 'PrimaryGroup' => 0,
);
$this->Conn->doInsert($fields_hash, $table_name);
}
@@ -92,20 +95,13 @@
function OnSetPrimary(&$event)
{
$ids = $this->StoreSelectedIDs($event);
+
if ($ids) {
- $id = array_shift($ids);
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $user_id = $this->Application->GetVar('u_id');
+ $user =& $this->Application->recallObject('u');
+ /* @var $user kDBItem */
- $sql = 'UPDATE ' . $object->TableName . '
- SET PrimaryGroup = 0
- WHERE PortalUserId = ' . (int)$user_id;
- $this->Conn->Query($sql);
-
- $sql = 'UPDATE ' . $object->TableName . '
- SET PrimaryGroup = 1
- WHERE ' . $object->IDField . ' = ' . $id . ' AND PortalUserId = ' . (int)$user_id;
- $this->Conn->Query($sql);
+ $user->SetDBField('PrimaryGroupId', array_shift($ids));
+ $user->Update();
}
$this->clearSelectedIDs($event);
@@ -120,26 +116,36 @@
{
if ($event->Name == 'OnMassDelete' && $type == 'before') {
$ids = $event->getEventParam('ids');
+
if ($ids) {
$object =& $event->getObject( Array('skip_autoload' => true) );
if ($event->Prefix == 'u-ug') {
- $user_id = $this->Application->GetVar('u_id');
- $sql = 'SELECT '.$object->IDField.'
- FROM '.$object->TableName.'
- WHERE '.$object->IDField.' IN ('.implode(',', $ids).') AND PortalUserId = '.(int)$user_id.' AND PrimaryGroup = 0';
- $ids = $this->Conn->GetCol($sql);
+ // allow deleting non-primary group of current user ($ids - groups)
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . $this->Application->GetTempName(TABLE_PREFIX . 'PortalUser', 'prefix:u') . '
+ WHERE PortalUserId = ' . (int)$this->Application->GetVar('u_id');
+ $primary_group_id = (int)$this->Conn->GetOne($sql);
+
+ $index = array_search($primary_group_id, $ids);
+
+ if ($index !== false) {
+ unset($ids[$index]);
+ $event->setEventParam('ids', $ids);
+ }
}
elseif ($event->Prefix == 'g-ug') {
- $group_id = $this->Application->GetVar('g_id');
- $sql = 'SELECT '.$object->IDField.'
- FROM '.$object->TableName.'
- WHERE '.$object->IDField.' IN ('.implode(',', $ids).') AND GroupId = '.(int)$group_id.' AND PrimaryGroup = 0';
- $ids = $this->Conn->GetCol($sql);
+ // allow deleting users from group record, then it's not their primary group ($ids - users)
+ $group_id = (int)$this->Application->GetVar('g_id');
+
+ $sql = 'SELECT PortalUserId
+ FROM ' . TABLE_PREFIX . 'PortalUser' . '
+ WHERE PortalUserId IN (' . implode(',', $ids) . ') AND PrimaryGroupId = ' . $group_id;
+ $exclude_users = $this->Conn->GetCol($sql);
+
+ $event->setEventParam('ids', array_diff($ids, $exclude_users));
}
- $event->setEventParam('ids', $ids);
}
}
}
-
}
\ No newline at end of file
Index: core/units/users/users_config.php
===================================================================
--- core/units/users/users_config.php (revision 14434)
+++ core/units/users/users_config.php (working copy)
@@ -134,7 +134,7 @@
'users_list' => Array (
'prefixes' => Array ('u_List'), 'format' => "!la_title_Users!",
- 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'e-mail', 'export', 'view', 'dbl-click'),
+ 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'setprimary', 'approve', 'decline', 'e-mail', 'export', 'view', 'dbl-click'),
),
'users_edit' => Array (
@@ -286,20 +286,17 @@
'TableName' => TABLE_PREFIX.'PortalUser',
'ListSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'UserGroup ug ON %1$s.PortalUserId = ug.PortalUserId AND ug.PrimaryGroup = 1
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON ug.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.PrimaryGroupId = g.GroupId
LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId',
'online' => ' SELECT %1$s.* %2$s FROM %1$s
LEFT JOIN '.TABLE_PREFIX.'UserSession s ON s.PortalUserId = %1$s.PortalUserId
- LEFT JOIN '.TABLE_PREFIX.'UserGroup ug ON %1$s.PortalUserId = ug.PortalUserId AND ug.PrimaryGroup = 1
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON ug.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.PrimaryGroupId = g.GroupId
LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId',
),
'ItemSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'UserGroup ug ON %1$s.PortalUserId = ug.PortalUserId AND ug.PrimaryGroup = 1
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON ug.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.PrimaryGroupId = g.GroupId
LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId',
),
@@ -401,6 +398,16 @@
), 'use_phrases' => 1, 'multiple' => 1,
'default' => NULL
),
+ 'UserType' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'la_opt_UserTypeUser', 1 => 'la_opt_UserTypeAdmin'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 0
+ ),
+ 'PrimaryGroupId' => Array (
+ 'type' => 'int',
+ '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' => NULL
+ ),
),
'VirtualFields' => Array(
@@ -410,11 +417,6 @@
'RootPassword' => Array('type' => 'string', 'formatter' => 'kPasswordFormatter', 'encryption_method' => 'md5', 'verify_field' => 'VerifyRootPassword', 'skip_empty' => 1, 'default' => md5('') ),
'FullName' => Array ('type' => 'string', 'default' => ''),
- 'UserGroup' => Array (
- 'type' => 'int',
- '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,
- ),
),
'Grids' => Array(
Index: core/units/users/users_event_handler.php
===================================================================
--- core/units/users/users_event_handler.php (revision 14434)
+++ core/units/users/users_event_handler.php (working copy)
@@ -27,7 +27,8 @@
// admin
'OnSetPersistantVariable' => Array('self' => 'view'), // because setting to logged in user only
'OnUpdateRootPassword' => Array('self' => true),
- 'OnUpdatePassword' => Array('self' => true),
+ 'OnUpdatePassword' => Array('self' => true),
+ 'OnSaveSelected' => Array ('self' => 'view'),
// front
'OnRefreshForm' => Array('self' => true),
@@ -59,12 +60,12 @@
$object =& $event->getObject();
/* @var $object kDBList */
- if ($event->Special == 'admins') {
- $object->addFilter('primary_filter', 'ug.GroupId = 11');
+ if ($event->Special == 'regular') {
+ $object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::USER);
}
- if ($event->Special == 'regular') {
- $object->addFilter('primary_filter', 'ug.GroupId <> 11 OR ug.GroupId IS NULL');
+ if ($event->Special == 'admins') {
+ $object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::ADMIN);
}
if (!$this->Application->isAdminUser) {
@@ -77,16 +78,16 @@
if ($event->Special == 'group') {
$group_id = $this->Application->GetVar('g_id');
+
if ($group_id !== false) {
// show only users, that user doesn't belong to current group
- $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g');
$sql = 'SELECT PortalUserId
- FROM ' . $table_name . '
+ FROM ' . $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g') . '
WHERE GroupId = ' . (int)$group_id;
$user_ids = $this->Conn->GetCol($sql);
-// array_push($user_ids); // Guest & Everyone groups are set dynamically
+
if ($user_ids) {
- $object->addFilter('already_member_filter', '%1$s.PortalUserId NOT IN ('.implode(',', $user_ids).')');
+ $object->addFilter('already_member_filter', '%1$s.PortalUserId NOT IN (' . implode(',', $user_ids) . ')');
}
}
}
@@ -298,46 +299,24 @@
{
$this->saveUserImages($event);
- if ($this->Application->GetVar('skip_set_primary')) return;
- $is_subscriber = $this->Application->GetVar('IsSubscriber');
- if(!$is_subscriber)
- {
- $object =& $event->getObject();
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
- $ug_table = TABLE_PREFIX.'UserGroup';
- if ($object->IsTempTable()) {
- $ug_table = $this->Application->GetTempName($ug_table, 'prefix:'.$event->Prefix);
- }
+ $primary_group_id = $object->GetDBField('PrimaryGroupId');
- $sql = 'UPDATE '.$ug_table.'
- SET PrimaryGroup = 0
- WHERE PortalUserId = '.$object->GetDBField('PortalUserId');
- $this->Conn->Query($sql);
+ if ($primary_group_id) {
+ $ug_table = TABLE_PREFIX . 'UserGroup';
- // set primary group to user
- if ($this->Application->isAdminUser && $this->Application->GetVar('user_group')) {
- // while in admin you can set any group for new users
- $group_id = $this->Application->GetVar('user_group');
+ if ( $object->IsTempTable() ) {
+ $ug_table = $this->Application->GetTempName($ug_table, 'prefix:' . $event->Prefix);
}
- else {
- $group_id = $object->GetDBField('UserGroup');
- if ($group_id) {
- // check, that group is allowed for Front-End
- $sql = 'SELECT GroupId
- FROM ' . TABLE_PREFIX . 'PortalGroup
- WHERE GroupId = ' . (int)$group_id . ' AND FrontRegistration = 1';
- $group_id = $this->Conn->GetOne($sql);
- }
+ $fields_hash = Array (
+ 'PortalUserId' => $object->GetID(),
+ 'GroupId' => $primary_group_id,
+ );
- if (!$group_id) {
- // when group not selected -> use default group
- $group_id = $this->Application->ConfigValue('User_NewGroup');
- }
- }
-
- $sql = 'REPLACE INTO '.$ug_table.'(PortalUserId,GroupId,PrimaryGroup) VALUES (%s,%s,1)';
- $this->Conn->Query( sprintf($sql, $object->GetID(), $group_id) );
+ $this->Conn->doInsert($fields_hash, $ug_table, 'REPLACE');
}
}
@@ -369,18 +348,19 @@
{
$ret = false;
$object =& $event->getObject( Array('skip_autoload' => true) );
+
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- if($items_info)
- {
+
+ if ($items_info) {
list($id, $field_values) = each($items_info);
$user_email = isset($field_values['Email']) ? $field_values['Email'] : false;
- if($user_email)
- {
+
+ if ($user_email) {
// check if is subscriber
$verify_user =& $this->Application->recallObject('u.verify', null, Array('skip_autoload' => true) );
$verify_user->Load($user_email, 'Email');
- if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() )
- {
+
+ 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;
@@ -388,12 +368,10 @@
}
}
- if( isset($event->MasterEvent) )
- {
+ if ( isset($event->MasterEvent) ) {
$event->MasterEvent->setEventParam('is_subscriber_only', $ret);
}
- else
- {
+ else {
$event->setEventParam('is_subscriber_only', $ret);
}
}
@@ -443,18 +421,20 @@
$this->setUserStatus($event);
}
- if (!$this->isSubscriberOnly($event)) {
+ if ( !$this->isSubscriberOnly($event) ) {
$object =& $event->getObject( Array('skip_autoload' => true) );
/* @var $object kDBItem */
- if ($this->Application->ConfigValue('User_Password_Auto')) {
- $pass = kUtil::generatePassword(rand(5,8));
+
+ if ( $this->Application->ConfigValue('User_Password_Auto') ) {
+ $pass = kUtil::generatePassword( rand(5, 8) );
$object->SetField('Password', $pass);
$object->SetField('VerifyPassword', $pass);
- $this->Application->SetVar('user_password',$pass);
+ $this->Application->SetVar('user_password', $pass);
}
+
parent::OnCreate($event);
- $this->Application->SetVar('u.current_id', $object->getID() ); // for affil:OnRegisterAffiliate after hook
+ $this->Application->SetVar('u.current_id', $object->getID()); // for affil:OnRegisterAffiliate after hook
$this->setNextTemplate($event);
@@ -512,7 +492,7 @@
$cs_helper =& $this->Application->recallObject('CountryStatesHelper');
/* @var $cs_helper kCountryStatesHelper */
- if (!$this->isSubscriberOnly($event, true)) {
+ if ( !$this->isSubscriberOnly($event, true) ) {
$cs_helper->CheckStateField($event, 'State', 'Country');
}
else {
@@ -531,6 +511,7 @@
}
$object->setLogin();
+ $this->setUserGroup($object);
$user_helper =& $this->Application->recallObject('UserHelper');
/* @var $user_helper UserHelper */
@@ -542,6 +523,38 @@
}
/**
+ * Sets primary group of the user
+ *
+ * @param kDBItem $object
+ */
+ protected function setUserGroup(&$object)
+ {
+ if ($object->Special == 'subscriber') {
+ $object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_SubscriberGroup'));
+
+ return ;
+ }
+
+ // set primary group to user
+ if ( !$this->Application->isAdminUser ) {
+ $group_id = $object->GetDBField('PrimaryGroupId');
+
+ if ($group_id) {
+ // check, that group is allowed for Front-End
+ $sql = 'SELECT GroupId
+ FROM ' . TABLE_PREFIX . 'PortalGroup
+ WHERE GroupId = ' . (int)$group_id . ' AND FrontRegistration = 1';
+ $group_id = $this->Conn->GetOne($sql);
+ }
+
+ if (!$group_id) {
+ // when group not selected OR not allowed -> use default group
+ $object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_NewGroup'));
+ }
+ }
+ }
+
+ /**
* Set's new unique resource id to user
*
* @param kEvent $event
@@ -549,10 +562,12 @@
function OnAfterItemValidate(&$event)
{
$object =& $event->getObject();
+ /* @var $object kDBItem */
+
$resource_id = $object->GetDBField('ResourceId');
- if (!$resource_id)
- {
- $object->SetDBField('ResourceId', $this->Application->NextResourceId() );
+
+ if (!$resource_id) {
+ $object->SetDBField('ResourceId', $this->Application->NextResourceId());
}
}
@@ -654,21 +669,24 @@
function OnSubscribeQuery(&$event)
{
$user_email = $this->Application->GetVar('subscriber_email');
- if (preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email)) {
- $object =& $this->Application->recallObject($this->Prefix.'.subscriber', null, Array('skip_autoload' => true));
+ if ( preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email) ) {
+ $object =& $this->Application->recallObject($this->Prefix . '.subscriber', null, Array('skip_autoload' => true));
/* @var $object UsersItem */
- $this->Application->StoreVar('SubscriberEmail', $user_email);
+ $object->Load($user_email, 'Email');
+ $event->SetRedirectParam('subscriber_email', $user_email);
- $object->Load($user_email, 'Email');
- if ($object->isLoaded()) {
- $group_info = $this->GetGroupInfo($object->GetID());
- $event->redirect = $this->Application->GetVar($group_info ? 'unsubscribe_template' : 'subscribe_template');
+ if ( $object->isLoaded() ) {
+ if ( $this->isSubscribed($object) ) {
+ $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 {
@@ -688,75 +706,83 @@
*/
function OnSubscribeUser(&$event)
{
- $object = &$this->Application->recallObject($this->Prefix.'.subscriber', null, Array('skip_autoload' => true));
+ $object = &$this->Application->recallObject($this->Prefix . '.subscriber', null, Array('skip_autoload' => true));
/* @var $object UsersItem */
- $user_email = $this->Application->RecallVar('SubscriberEmail');
- if (preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email)) {
+ $user_email = $this->Application->GetVar('subscriber_email');
+
+ if ( preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email) ) {
$this->RemoveRequiredFields($object);
$object->Load($user_email, 'Email');
- if ($object->isLoaded()) {
- $group_info = $this->GetGroupInfo($object->GetID());
+ if ( $object->isLoaded() ) {
+ if ( $this->isSubscribed($object) ) {
+ if ( $event->getEventParam('no_unsubscribe') ) {
+ // for customization code from FormsEventHandler
+ return ;
+ }
- if ($group_info){
- if ($event->getEventParam('no_unsubscribe')) return;
-
- if ($group_info['PrimaryGroup']){
+ if ( $object->isSubscriberOnly() ) {
$this->Application->SetVar($object->getPrefixSpecial(true) . '_id', $object->GetID());
$delete_event = new kEvent($object->getPrefixSpecial() . ':OnDelete');
$this->Application->HandleEvent($delete_event);
}
else {
- $this->RemoveSubscriberGroup($object->GetID());
+ $this->RemoveSubscriberGroup( $object->GetID() );
}
$event->redirect = $this->Application->GetVar('unsubscribe_ok_template');
}
else {
- $this->AddSubscriberGroup($object->GetID(), 0);
+ $this->AddSubscriberGroup($object);
$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);
+ $object->SetDBField('Email', $user_email);
+ $object->SetDBField('Login', $user_email);
$object->SetDBField('Status', STATUS_ACTIVE); // make user subscriber Active by default
- $ip = getenv('HTTP_X_FORWARDED_FOR')?getenv('HTTP_X_FORWARDED_FOR'):getenv('REMOTE_ADDR');
- $object->SetDBField('ip', $ip);
+ $object->SetDBField('ip', $_SERVER['REMOTE_ADDR']);
- $this->Application->SetVar('IsSubscriber', 1);
-
- if ($object->Create()) {
- $this->AddSubscriberGroup($object->GetID(), 1);
+ if ( $object->Create() ) {
+ $this->AddSubscriberGroup($object);
$event->redirect = $this->Application->GetVar('subscribe_ok_template');
}
-
- $this->Application->SetVar('IsSubscriber', 0);
}
}
}
- function AddSubscriberGroup($user_id, $is_primary)
+ /**
+ * Adding user to subscribers group
+ *
+ * @param UsersItem $object
+ */
+ function AddSubscriberGroup(&$object)
{
- $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) );
+ if ( !$object->isSubscriberOnly() ) {
+ $fields_hash = Array (
+ 'PortalUserId' => $object->GetID(),
+ 'GroupId' => $this->Application->ConfigValue('User_SubscriberGroup'),
+ );
+ $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'UserGroup');
+ }
+
$this->Application->EmailEventAdmin('USER.SUBSCRIBE');
- $this->Application->EmailEventUser('USER.SUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.SUBSCRIBE', $object->GetID());
}
+ /**
+ * Removing user from subscribers group
+ *
+ * @param int $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');
+ WHERE PortalUserId = ' . $user_id . ' AND GroupId = ' . $group_id;
$this->Conn->Query($sql);
$this->Application->EmailEventAdmin('USER.UNSUBSCRIBE');
@@ -764,17 +790,20 @@
}
/**
- * Allows to detect user subscription status (subscribed or not)
+ * Checks user subscription status
*
- * @param int $user_id
+ * @param kDBItem $object
* @return bool
*/
- function GetGroupInfo($user_id)
+ function isSubscribed(&$object)
{
- $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'UserGroup
- WHERE (PortalUserId = ' . $user_id . ')
- AND (GroupId = ' . $this->Application->ConfigValue('User_SubscriberGroup') . ')';
- return $this->Conn->GetRow($sql);
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+
+ $sql = 'SELECT GroupId
+ FROM ' . TABLE_PREFIX . 'UserGroup
+ WHERE (PortalUserId = ' . $object->GetID() . ') AND (GroupId = ' . $group_id . ')';
+
+ return $this->Conn->GetOne($sql);
}
function OnForgotPassword(&$event)
@@ -1384,17 +1413,16 @@
$first_country = $this->Application->ConfigValue('User_Default_Registration_Country');
}
+ $fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
+
if ($first_country) {
// update user country dropdown sql
- $fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
$fields['Country']['options_sql'] = preg_replace('/ORDER BY (.*)/', 'ORDER BY IF (CountryStateId = '.$first_country.', 1, 0) DESC, \\1', $fields['Country']['options_sql']);
- $this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
}
// 2. set default user registration group
- $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields');
- $virtual_fields['UserGroup']['default'] = $this->Application->ConfigValue('User_NewGroup');
- $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields);
+ $fields['PrimaryGroupId']['default'] = $this->Application->ConfigValue('User_NewGroup');
+ $this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
// 3. allow avatar upload on Front-End
$file_helper =& $this->Application->recallObject('FileHelper');
@@ -1441,13 +1469,11 @@
return;
}
- $event->status=kEvent::erSUCCESS;
- $ids = $this->StoreSelectedIDs($event);
-
- $this->Application->SetVar('skip_set_primary', 1); // otherwise it will default primary group, search for skip_set_primary above
$temp_handler =& $this->Application->recallObject($event->Prefix.'_TempHandler', 'kTempTablesHandler');
/* @var $temp_handler kTempTablesHandler */
- $cloned_users = $temp_handler->CloneItems($event->Prefix, '', $ids);
+
+ $ids = $this->StoreSelectedIDs($event);
+ $temp_handler->CloneItems($event->Prefix, '', $ids);
$this->clearSelectedIDs($event);
}
@@ -1460,30 +1486,15 @@
{
$object =& $event->getObject();
/* @var $object kDBItem */
- $object->setRequired('Password', 0);
- $object->setRequired('VerifyPassword', 0);
- $object->SetDBField('Password', rand(100000000, 999999999));
- $object->SetDBField('CreatedOn', adodb_mktime());
- $object->SetDBField('ResourceId', false); // this will reset it
- // change email cause it should be unique
- $object->NameCopy(array(), $object->GetID(), 'Email', 'copy%1$s.%2$s');
+ $password = kUtil::generatePassword();
+ $object->SetField('Password', $password);
+ $object->SetField('VerifyPassword', $password);
- $object->UpdateFormattersSubFields();
- }
+ $object->SetDBField('ResourceId', 0); // this will reset it
- /**
- * Copy user groups after copying user
- *
- * @param kEvent $event
- */
- function OnAfterClone(&$event)
- {
- $id = $event->getEventParam('id');
- $original_id = $event->getEventParam('original_id');
-
- $sql = 'INSERT '.TABLE_PREFIX."UserGroup SELECT $id, GroupId, MembershipExpires, PrimaryGroup, 0 FROM ".TABLE_PREFIX."UserGroup WHERE PortalUserId = $original_id";
- $this->Conn->Query($sql);
+ // change email because it should be unique
+ $object->NameCopy(Array (), $object->GetID(), 'Email', 'copy%1$s.%2$s');
}
/**
@@ -1496,11 +1507,11 @@
$this->StoreSelectedIDs($event);
// remove current ID, otherwise group selector will use it in filters
- $this->Application->DeleteVar($event->getPrefixSpecial(true).'_id');
+ $this->Application->DeleteVar($event->getPrefixSpecial(true) . '_id');
}
/**
- * Adds selected link to listing
+ * Sets primary group of selected users
*
* @param kEvent $event
*/
@@ -1524,34 +1535,27 @@
$table_name = $this->Application->getUnitOption('ug', 'TableName');
+ // 1. mark group as primary
+ $sql = 'UPDATE ' . TABLE_PREFIX . 'PortalUser
+ SET PrimaryGroupId = ' . $primary_group_id . '
+ WHERE PortalUserId IN (' . implode(',', $user_ids) . ')';
+ $this->Conn->Query($sql);
+
$sql = 'SELECT PortalUserId
- FROM '.$table_name.'
- WHERE (GroupId = '.$primary_group_id.') AND (PortalUserId IN ('.implode(',', $user_ids).'))';
+ FROM ' . $table_name . '
+ WHERE (GroupId = ' . $primary_group_id . ') AND (PortalUserId IN (' . implode(',', $user_ids) . '))';
$existing_members = $this->Conn->GetCol($sql);
- // 1. reset primary group mark
- $sql = 'UPDATE '.$table_name.'
- SET PrimaryGroup = 0
- WHERE PortalUserId IN ('.implode(',', $user_ids).')';
- $this->Conn->Query($sql);
+ // 2. add new members to a group
+ $new_members = array_diff($user_ids, $existing_members);
- foreach ($user_ids as $user_id) {
- if (in_array($user_id, $existing_members)) {
- // 2. already member of that group -> just make primary
- $sql = 'UPDATE '.$table_name.'
- SET PrimaryGroup = 1
- WHERE (PortalUserId = '.$user_id.') AND (GroupId = '.$primary_group_id.')';
- $this->Conn->Query($sql);
- }
- else {
- // 3. not member of that group -> make member & make primary
- $fields_hash = Array (
- 'GroupId' => $primary_group_id,
- 'PortalUserId' => $user_id,
- 'PrimaryGroup' => 1,
- );
- $this->Conn->doInsert($fields_hash, $table_name);
- }
+ foreach ($new_members as $user_id) {
+ $fields_hash = Array (
+ 'GroupId' => $primary_group_id,
+ 'PortalUserId' => $user_id,
+ );
+
+ $this->Conn->doInsert($fields_hash, $table_name);
}
}
@@ -1608,6 +1612,19 @@
parent::OnPreCreate($event);
if ($event->status == kEvent::erSUCCESS) {
+ $user_type = $this->Application->GetVar('user_type');
+
+ if ($user_type) {
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+
+ $object->SetDBField('UserType', $user_type);
+
+ if ( $user_type == UserType::ADMIN ) {
+ $object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_AdminGroup'));
+ }
+ }
+
$this->_makePasswordRequired($event);
}
}
Index: core/units/users/users_item.php
===================================================================
--- core/units/users/users_item.php (revision 14434)
+++ core/units/users/users_item.php (working copy)
@@ -31,7 +31,7 @@
$sql = 'SELECT GroupId
FROM ' . TABLE_PREFIX . 'UserGroup
WHERE (PortalUserId = ' . $this->GetID() . ') AND ( (MembershipExpires IS NULL) OR ( MembershipExpires >= UNIX_TIMESTAMP() ) )
- ORDER BY PrimaryGroup DESC';
+ ORDER BY IF(GroupId = ' . $this->GetDBField('PrimaryGroupId') . ', 1, 0) DESC';
return $this->Conn->GetCol($sql);
}
@@ -69,15 +69,14 @@
}
}
+ /**
+ * Checks that user is subscriber only
+ *
+ * @return bool
+ */
function isSubscriberOnly()
{
- $subscribers_group_id = $this->Application->ConfigValue('User_SubscriberGroup');
- $sql = 'SELECT PortalUserId
- FROM '.TABLE_PREFIX.'UserGroup
- WHERE GroupId = '.$subscribers_group_id.' AND
- PortalUserId = '.$this->GetDBField('PortalUserId').' AND
- PrimaryGroup = 1';
- return $this->Conn->GetOne($sql) == $this->GetDBField('PortalUserId');
+ return $this->GetDBField('PrimaryGroupId') == $this->Application->ConfigValue('User_SubscriberGroup');
}
function Create($force_id=false, $system_create=false)
user_group_storage_core_v2_513.patch [^] (45,980 bytes) 2012-11-27 09:21
[Show Content]
Index: admin/system_presets/simple/user_groups_g-ug.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- admin/system_presets/simple/user_groups_g-ug.php (revision 5818)
+++ admin/system_presets/simple/user_groups_g-ug.php (revision )
@@ -18,7 +18,7 @@
// fields to hide
$hidden_fields = Array (
- /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+ /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to hide
@@ -28,7 +28,7 @@
// fields to make required
$required_fields = Array (
-/* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+/* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to make required
Index: core/units/users/users_config.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/units/users/users_config.php (revision 5818)
+++ core/units/users/users_config.php (revision )
@@ -135,7 +135,7 @@
'users_list' => Array (
'prefixes' => Array ('u_List'), 'format' => "!la_title_Users!",
- 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'approve', 'decline', 'e-mail', 'export', 'view', 'dbl-click'),
+ 'toolbar_buttons' => Array ('new_item', 'edit', 'delete', 'setprimary', 'approve', 'decline', 'e-mail', 'export', 'view', 'dbl-click'),
),
'users_edit' => Array (
@@ -287,22 +287,19 @@
'TableName' => TABLE_PREFIX.'PortalUser',
'ListSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'UserGroup ug ON %1$s.PortalUserId = ug.PortalUserId AND ug.PrimaryGroup = 1
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON ug.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.PrimaryGroupId = g.GroupId
LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId
LEFT JOIN '.TABLE_PREFIX.'%3$sImages img ON img.ResourceId = %1$s.ResourceId AND img.DefaultImg = 1',
'online' => ' SELECT %1$s.* %2$s FROM %1$s
LEFT JOIN '.TABLE_PREFIX.'UserSession s ON s.PortalUserId = %1$s.PortalUserId
- LEFT JOIN '.TABLE_PREFIX.'UserGroup ug ON %1$s.PortalUserId = ug.PortalUserId AND ug.PrimaryGroup = 1
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON ug.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.PrimaryGroupId = g.GroupId
LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId
LEFT JOIN '.TABLE_PREFIX.'%3$sImages img ON img.ResourceId = %1$s.ResourceId AND img.DefaultImg = 1',
),
'ItemSQLs' => Array( '' => ' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'UserGroup ug ON %1$s.PortalUserId = ug.PortalUserId AND ug.PrimaryGroup = 1
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON ug.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.PrimaryGroupId = g.GroupId
LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUserCustomData cust ON %1$s.ResourceId = cust.ResourceId
LEFT JOIN '.TABLE_PREFIX.'%3$sImages img ON img.ResourceId = %1$s.ResourceId AND img.DefaultImg = 1',
),
@@ -374,7 +371,7 @@
'type' => 'int',
'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
'not_null' => 1, 'default' => 0
- ),
+ ),
'Fax' => Array('type' => 'string', 'not_null' => 1, 'default' => ''),
'Street' => Array('type' => 'string', 'not_null' => 1, 'default' => ''),
'Street2' => Array('type' => 'string', 'not_null' => 1, 'default' => ''),
@@ -422,7 +419,17 @@
), 'use_phrases' => 1, 'multiple' => 1,
'default' => NULL
),
+ 'UserType' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (0 => 'la_opt_UserTypeUser', 1 => 'la_opt_UserTypeAdmin'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 0
- ),
+ ),
+ 'PrimaryGroupId' => Array (
+ 'type' => 'int',
+ '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' => NULL
+ ),
+ ),
'VirtualFields' => Array(
'ValidateLogin' => Array('type'=>'string','default'=>''),
@@ -431,11 +438,6 @@
'RootPassword' => Array('type' => 'string', 'formatter' => 'kPasswordFormatter', 'encryption_method' => 'md5', 'verify_field' => 'VerifyRootPassword', 'skip_empty' => 1, 'default' => md5('') ),
'FullName' => Array ('type' => 'string', 'default' => ''),
- 'UserGroup' => Array (
- 'type' => 'int',
- '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,
- ),
'AltName' => Array ('type' => 'string', 'default' => ''),
'SameImages' => Array ('type' => 'string', 'default' => ''),
'LocalThumb' => Array ('type' => 'string', 'default' => ''),
@@ -521,4 +523,4 @@
),
),
- );
\ No newline at end of file
+ );
Index: core/units/user_groups/user_groups_eh.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/units/user_groups/user_groups_eh.php (revision 5818)
+++ core/units/user_groups/user_groups_eh.php (revision )
@@ -25,35 +25,37 @@
function OnProcessSelected(&$event)
{
if ($event->Prefix == 'u-ug') {
- $new_groups = $this->Application->GetVar('g');
- if (!$new_groups) {
- return ;
- }
+ $new_groups = $this->Application->GetVar('g');
+ if (!$new_groups) {
+ return ;
+ }
- $new_groups = array_keys($new_groups);
+ $new_groups = array_keys($new_groups);
- // don't insert duplicate group membership record
- $user_id = $this->Application->GetVar('u_id');
- $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:u');
+ // don't insert duplicate group membership record
+ $user_id = $this->Application->GetVar('u_id');
+ $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:u');
+
- $sql = 'SELECT GroupId
- FROM '.$table_name.'
- WHERE PortalUserId = '.(int)$user_id;
- $old_groups = $this->Conn->GetCol($sql);
+ $sql = 'SELECT GroupId
+ FROM '.$table_name.'
+ WHERE PortalUserId = '.(int)$user_id;
+ $old_groups = $this->Conn->GetCol($sql);
- $new_groups = array_diff($new_groups, $old_groups);
+ $new_groups = array_diff($new_groups, $old_groups);
+
- if ($new_groups) {
- foreach ($new_groups as $new_group) {
- $fields_hash = Array (
- 'GroupId' => $new_group,
- 'PortalUserId' => $user_id,
+ if ($new_groups) {
+ foreach ($new_groups as $new_group) {
+ $fields_hash = Array (
+ 'GroupId' => $new_group,
+ 'PortalUserId' => $user_id,
- 'PrimaryGroup' => 0,
- );
- $this->Conn->doInsert($fields_hash, $table_name);
- }
- }
+ );
+ $this->Conn->doInsert($fields_hash, $table_name);
+ }
+ }
}
- if ($event->Prefix == 'g-ug') {
+ elseif ($event->Prefix == 'g-ug') {
$new_users = $this->Application->GetVar('u');
+
if (!$new_users) {
return ;
}
@@ -63,18 +65,19 @@
// don't insert duplicate group membership record
$group_id = $this->Application->GetVar('g_id');
$table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g');
+
$sql = 'SELECT PortalUserId
FROM ' . $table_name . '
WHERE GroupId = ' . (int)$group_id;
$old_users = $this->Conn->GetCol($sql);
$new_users = array_diff($new_users, $old_users);
+
if ($new_users) {
foreach ($new_users as $new_user) {
$fields_hash = Array (
'GroupId' => $group_id,
'PortalUserId' => $new_user,
- 'PrimaryGroup' => 0,
);
$this->Conn->doInsert($fields_hash, $table_name);
}
@@ -93,20 +96,13 @@
function OnSetPrimary(&$event)
{
$ids = $this->StoreSelectedIDs($event);
+
if ($ids) {
- $id = array_shift($ids);
- $object =& $event->getObject( Array('skip_autoload' => true) );
- $user_id = $this->Application->GetVar('u_id');
+ $user =& $this->Application->recallObject('u');
+ /* @var $user kDBItem */
- $sql = 'UPDATE ' . $object->TableName . '
- SET PrimaryGroup = 0
- WHERE PortalUserId = ' . (int)$user_id;
- $this->Conn->Query($sql);
-
- $sql = 'UPDATE ' . $object->TableName . '
- SET PrimaryGroup = 1
- WHERE ' . $object->IDField . ' = ' . $id . ' AND PortalUserId = ' . (int)$user_id;
- $this->Conn->Query($sql);
+ $user->SetDBField('PrimaryGroupId', array_shift($ids));
+ $user->Update();
}
$this->clearSelectedIDs($event);
@@ -121,26 +117,36 @@
{
if ($event->Name == 'OnMassDelete' && $type == 'before') {
$ids = $event->getEventParam('ids');
+
if ($ids) {
$object =& $event->getObject( Array('skip_autoload' => true) );
if ($event->Prefix == 'u-ug') {
- $user_id = $this->Application->GetVar('u_id');
- $sql = 'SELECT '.$object->IDField.'
- FROM '.$object->TableName.'
- WHERE '.$object->IDField.' IN ('.implode(',', $ids).') AND PortalUserId = '.(int)$user_id.' AND PrimaryGroup = 0';
- $ids = $this->Conn->GetCol($sql);
+ // allow deleting non-primary group of current user ($ids - groups)
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . $this->Application->GetTempName(TABLE_PREFIX . 'PortalUser', 'prefix:u') . '
+ WHERE PortalUserId = ' . (int)$this->Application->GetVar('u_id');
+ $primary_group_id = (int)$this->Conn->GetOne($sql);
+
+ $index = array_search($primary_group_id, $ids);
+
+ if ($index !== false) {
+ unset($ids[$index]);
+ $event->setEventParam('ids', $ids);
- }
+ }
+ }
elseif ($event->Prefix == 'g-ug') {
- $group_id = $this->Application->GetVar('g_id');
- $sql = 'SELECT '.$object->IDField.'
- FROM '.$object->TableName.'
- WHERE '.$object->IDField.' IN ('.implode(',', $ids).') AND GroupId = '.(int)$group_id.' AND PrimaryGroup = 0';
- $ids = $this->Conn->GetCol($sql);
+ // allow deleting users from group record, then it's not their primary group ($ids - users)
+ $group_id = (int)$this->Application->GetVar('g_id');
+
+ $sql = 'SELECT PortalUserId
+ FROM ' . TABLE_PREFIX . 'PortalUser' . '
+ WHERE PortalUserId IN (' . implode(',', $ids) . ') AND PrimaryGroupId = ' . $group_id;
+ $exclude_users = $this->Conn->GetCol($sql);
+
+ $event->setEventParam('ids', array_diff($ids, $exclude_users));
}
- $event->setEventParam('ids', $ids);
}
}
}
-
}
\ No newline at end of file
Index: core/admin_templates/users/users_list.tpl
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/admin_templates/users/users_list.tpl (revision 5818)
+++ core/admin_templates/users/users_list.tpl (revision )
@@ -30,7 +30,7 @@
/*a_toolbar.AddButton (
new ToolBarButton(
- 'primary_user_group',
+ 'setprimary',
'<inp2:m_phrase label="la_ToolTip_PrimaryGroup" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_SetPrimary" escape="1"/>',
function() {
openSelector('u.regular', '<inp2:m_Link t="users/group_selector" pass="m,u"/>', 'PrimaryGroupId', '800x600', 'OnSaveSelected');
@@ -93,6 +93,6 @@
<inp2:m_RenderElement name="grid" PrefixSpecial="u.regular" IdField="PortalUserId" grid="RegularUsers"/>
<script type="text/javascript">
- Grids['u.regular'].SetDependantToolbarButtons( new Array('edit', 'delete', 'e-mail', 'approve', 'decline') );
+ Grids['u.regular'].SetDependantToolbarButtons( new Array('edit', 'delete', 'setprimary', 'e-mail', 'approve', 'decline') );
</script>
<inp2:m_include t="incs/footer"/>
\ No newline at end of file
Index: core/units/users/users_item.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/units/users/users_item.php (revision 5818)
+++ core/units/users/users_item.php (revision )
@@ -32,7 +32,7 @@
$sql = 'SELECT GroupId
FROM ' . TABLE_PREFIX . 'UserGroup
WHERE (PortalUserId = ' . $this->GetID() . ') AND ( (MembershipExpires IS NULL) OR ( MembershipExpires >= UNIX_TIMESTAMP() ) )
- ORDER BY PrimaryGroup DESC';
+ ORDER BY IF(GroupId = ' . $this->GetDBField('PrimaryGroupId') . ', 1, 0) DESC';
return $this->Conn->GetCol($sql);
}
@@ -75,15 +75,14 @@
return $password;
}
+ /**
+ * Checks that user is subscriber only
+ *
+ * @return bool
+ */
function isSubscriberOnly()
{
- $subscribers_group_id = $this->Application->ConfigValue('User_SubscriberGroup');
- $sql = 'SELECT PortalUserId
- FROM '.TABLE_PREFIX.'UserGroup
- WHERE GroupId = '.$subscribers_group_id.' AND
- PortalUserId = '.$this->GetDBField('PortalUserId').' AND
- PrimaryGroup = 1';
- return $this->Conn->GetOne($sql) == $this->GetDBField('PortalUserId');
+ return $this->GetDBField('PrimaryGroupId') == $this->Application->ConfigValue('User_SubscriberGroup');
}
function Create($force_id=false, $system_create=false)
@@ -142,4 +141,4 @@
$this->SetDBField('LastName', $last_name);
}
- }
\ No newline at end of file
+ }
Index: core/units/users/users_event_handler.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/units/users/users_event_handler.php (revision 5818)
+++ core/units/users/users_event_handler.php (revision )
@@ -28,7 +28,8 @@
// admin
'OnSetPersistantVariable' => Array('self' => 'view'), // because setting to logged in user only
'OnUpdateRootPassword' => Array('self' => true),
- 'OnUpdatePassword' => Array('self' => true),
+ 'OnUpdatePassword' => Array('self' => true),
+ 'OnSaveSelected' => Array ('self' => 'view'),
// front
'OnRefreshForm' => Array('self' => true),
@@ -60,12 +61,12 @@
$object =& $event->getObject();
/* @var $object kDBList */
- if ($event->Special == 'admins') {
- $object->addFilter('primary_filter', 'ug.GroupId = 11');
+ if ($event->Special == 'regular') {
+ $object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::USER);
}
- if ($event->Special == 'regular') {
- $object->addFilter('primary_filter', 'ug.GroupId <> 11 OR ug.GroupId IS NULL');
+ if ($event->Special == 'admins') {
+ $object->addFilter('primary_filter', '%1$s.UserType = ' . UserType::ADMIN);
}
if (!$this->Application->isAdminUser) {
@@ -78,16 +79,16 @@
if ($event->Special == 'group') {
$group_id = $this->Application->GetVar('g_id');
+
if ($group_id !== false) {
// show only users, that user doesn't belong to current group
- $table_name = $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g');
$sql = 'SELECT PortalUserId
- FROM ' . $table_name . '
+ FROM ' . $this->Application->GetTempName(TABLE_PREFIX.'UserGroup', 'prefix:g') . '
WHERE GroupId = ' . (int)$group_id;
$user_ids = $this->Conn->GetCol($sql);
-// array_push($user_ids); // Guest & Everyone groups are set dynamically
+
if ($user_ids) {
- $object->addFilter('already_member_filter', '%1$s.PortalUserId NOT IN ('.implode(',', $user_ids).')');
+ $object->addFilter('already_member_filter', '%1$s.PortalUserId NOT IN (' . implode(',', $user_ids) . ')');
}
}
}
@@ -299,49 +300,27 @@
{
$this->saveUserImages($event);
- if ($this->Application->GetVar('skip_set_primary')) return;
- $is_subscriber = $this->Application->GetVar('IsSubscriber');
- if(!$is_subscriber)
- {
- $object =& $event->getObject();
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+ $primary_group_id = $object->GetDBField('PrimaryGroupId');
+
+ if ($primary_group_id) {
- $ug_table = TABLE_PREFIX.'UserGroup';
+ $ug_table = TABLE_PREFIX . 'UserGroup';
- if ($object->mode == 't') {
+
+ if ( $object->IsTempTable() ) {
- $ug_table = $this->Application->GetTempName($ug_table, 'prefix:'.$event->Prefix);
+ $ug_table = $this->Application->GetTempName($ug_table, 'prefix:' . $event->Prefix);
}
- $sql = 'UPDATE '.$ug_table.'
- SET PrimaryGroup = 0
- WHERE PortalUserId = '.$object->GetDBField('PortalUserId');
- $this->Conn->Query($sql);
+ $fields_hash = Array (
+ 'PortalUserId' => $object->GetID(),
+ 'GroupId' => $primary_group_id,
+ );
- // set primary group to user
- if ($this->Application->isAdminUser && $this->Application->GetVar('user_group')) {
- // while in admin you can set any group for new users
- $group_id = $this->Application->GetVar('user_group');
+ $this->Conn->doInsert($fields_hash, $ug_table, 'REPLACE');
- }
+ }
- else {
- $group_id = $object->GetDBField('UserGroup');
-
- if ($group_id) {
- // check, that group is allowed for Front-End
- $sql = 'SELECT GroupId
- FROM ' . TABLE_PREFIX . 'PortalGroup
- WHERE GroupId = ' . (int)$group_id . ' AND FrontRegistration = 1';
- $group_id = $this->Conn->GetOne($sql);
- }
+ }
- if (!$group_id) {
- // when group not selected -> use default group
- $group_id = $this->Application->ConfigValue('User_NewGroup');
- }
- }
-
- $sql = 'REPLACE INTO '.$ug_table.'(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
*
@@ -369,18 +348,19 @@
{
$ret = false;
$object =& $event->getObject( Array('skip_autoload' => true) );
+
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- if($items_info)
- {
+
+ if ($items_info) {
list($id, $field_values) = each($items_info);
$user_email = isset($field_values['Email']) ? $field_values['Email'] : false;
- if($user_email)
- {
+
+ if ($user_email) {
// check if is subscriber
$verify_user =& $this->Application->recallObject('u.verify', null, Array('skip_autoload' => true) );
$verify_user->Load($user_email, 'Email');
- if( $verify_user->isLoaded() && $verify_user->isSubscriberOnly() )
- {
+
+ 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;
@@ -388,12 +368,10 @@
}
}
- if( isset($event->MasterEvent) )
- {
+ if ( isset($event->MasterEvent) ) {
$event->MasterEvent->setEventParam('is_subscriber_only', $ret);
}
- else
- {
+ else {
$event->setEventParam('is_subscriber_only', $ret);
}
}
@@ -442,16 +420,18 @@
$this->setUserStatus($event);
}
- if (!$this->isSubscriberOnly($event)) {
+ if ( !$this->isSubscriberOnly($event) ) {
$object =& $event->getObject( Array('skip_autoload' => true) );
/* @var $object UsersItem */
+
- if ($this->Application->ConfigValue('User_Password_Auto')) {
+ if ( $this->Application->ConfigValue('User_Password_Auto') ) {
$password = $object->generatePassword( rand(5, 8) );
$this->Application->SetVar('user_password', $password);
}
+
parent::OnCreate($event);
- $this->Application->SetVar('u.current_id', $object->getID() ); // for affil:OnRegisterAffiliate after hook
+ $this->Application->SetVar('u.current_id', $object->getID()); // for affil:OnRegisterAffiliate after hook
$this->setNextTemplate($event);
@@ -509,10 +489,10 @@
$cs_helper =& $this->Application->recallObject('CountryStatesHelper');
/* @var $cs_helper kCountryStatesHelper */
- if (!$this->isSubscriberOnly($event, true)) {
+ if ( !$this->isSubscriberOnly($event, true) ) {
$cs_helper->CheckStateField($event, 'State', 'Country');
}
-
+
$this->_makePasswordRequired($event);
$cs_helper->PopulateStates($event, 'State', 'Country');
@@ -529,12 +509,46 @@
$user_helper =& $this->Application->recallObject('UserHelper');
/* @var $user_helper UserHelper */
+ $this->setUserGroup($object);
+
if (!$user_helper->checkBanRules($object)) {
$object->SetError('Login', 'banned');
}
}
/**
+ * Sets primary group of the user
+ *
+ * @param kDBItem $object
+ */
+ protected function setUserGroup(&$object)
+ {
+ if ($object->Special == 'subscriber') {
+ $object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_SubscriberGroup'));
+
+ return ;
+ }
+
+ // set primary group to user
+ if ( !$this->Application->isAdminUser ) {
+ $group_id = $object->GetDBField('PrimaryGroupId');
+
+ if ($group_id) {
+ // check, that group is allowed for Front-End
+ $sql = 'SELECT GroupId
+ FROM ' . TABLE_PREFIX . 'PortalGroup
+ WHERE GroupId = ' . (int)$group_id . ' AND FrontRegistration = 1';
+ $group_id = $this->Conn->GetOne($sql);
+ }
+
+ if (!$group_id) {
+ // when group not selected OR not allowed -> use default group
+ $object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_NewGroup'));
+ }
+ }
+ }
+
+ /**
* Set's new unique resource id to user
*
* @param kEvent $event
@@ -542,10 +556,12 @@
function OnAfterItemValidate(&$event)
{
$object =& $event->getObject();
+ /* @var $object kDBItem */
+
$resource_id = $object->GetDBField('ResourceId');
- if (!$resource_id)
- {
+
+ if (!$resource_id) {
- $object->SetDBField('ResourceId', $this->Application->NextResourceId() );
+ $object->SetDBField('ResourceId', $this->Application->NextResourceId());
}
}
@@ -646,24 +662,27 @@
function OnSubscribeQuery(&$event)
{
$user_email = $this->Application->GetVar('subscriber_email');
- if (preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email)) {
+ if ( preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email) ) {
- $object =& $this->Application->recallObject($this->Prefix.'.subscriber', null, Array('skip_autoload' => true));
+ $object =& $this->Application->recallObject($this->Prefix . '.subscriber', null, Array('skip_autoload' => true));
/* @var $object UsersItem */
- $this->Application->StoreVar('SubscriberEmail', $user_email);
-
$object->Load($user_email, 'Email');
+ $event->SetRedirectParam('subscriber_email', $user_email);
+
- if ($object->isLoaded()) {
+ if ( $object->isLoaded() ) {
- $group_info = $this->GetGroupInfo($object->GetID());
- $event->redirect = $this->Application->GetVar($group_info ? 'unsubscribe_template' : 'subscribe_template');
+ if ( $this->isSubscribed($object) ) {
+ $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 {
+ }
+ }
+ else {
+ $event->redirect = $this->Application->GetVar('subscribe_template');
+ }
+ }
+ else {
// used for error reporting only -> rewrite code + theme (by Alex)
$object =& $this->Application->recallObject('u', null, Array('skip_autoload' => true)); // TODO: change theme too
/* @var $object UsersItem */
@@ -680,73 +699,83 @@
*/
function OnSubscribeUser(&$event)
{
- $object = &$this->Application->recallObject($this->Prefix.'.subscriber', null, Array('skip_autoload' => true));
+ $object = &$this->Application->recallObject($this->Prefix . '.subscriber', null, Array('skip_autoload' => true));
/* @var $object UsersItem */
- $user_email = $this->Application->RecallVar('SubscriberEmail');
+ $user_email = $this->Application->GetVar('subscriber_email');
+
- if (preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email)) {
+ if ( preg_match('/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i', $user_email) ) {
$this->RemoveRequiredFields($object);
$object->Load($user_email, 'Email');
- if ($object->isLoaded()) {
+ if ( $object->isLoaded() ) {
- $group_info = $this->GetGroupInfo($object->GetID());
+ if ( $this->isSubscribed($object) ) {
+ if ( $event->getEventParam('no_unsubscribe') ) {
+ // for customization code from FormsEventHandler
+ return ;
+ }
- if ($group_info){
- if ($event->getEventParam('no_unsubscribe')) return;
-
- if ($group_info['PrimaryGroup']){
+ if ( $object->isSubscriberOnly() ) {
// delete user
$object->Delete();
}
else {
- $this->RemoveSubscriberGroup($object->GetID());
+ $this->RemoveSubscriberGroup( $object->GetID() );
}
$event->redirect = $this->Application->GetVar('unsubscribe_ok_template');
}
else {
- $this->AddSubscriberGroup($object->GetID(), 0);
+ $this->AddSubscriberGroup($object);
$event->redirect = $this->Application->GetVar('subscribe_ok_template');
}
}
else {
- $password = makepassword4();
- $object->SetField('Password', $password);
- $object->SetField('VerifyPassword', $password);
+ $object->generatePassword( rand(5, 8) );
$object->SetDBField('Email', $user_email);
$object->SetDBField('Login', $user_email);
$object->SetDBField('Status', STATUS_ACTIVE); // make user subscriber Active by default
$object->SetDBField('ip', $_SERVER['REMOTE_ADDR']);
- $this->Application->SetVar('IsSubscriber', 1);
-
- if ($object->Create()) {
+ if ( $object->Create() ) {
- $this->AddSubscriberGroup($object->GetID(), 1);
+ $this->AddSubscriberGroup($object);
$event->redirect = $this->Application->GetVar('subscribe_ok_template');
}
-
- $this->Application->SetVar('IsSubscriber', 0);
}
}
}
- function AddSubscriberGroup($user_id, $is_primary)
+ /**
+ * Adding user to subscribers group
+ *
+ * @param UsersItem $object
+ */
+ function AddSubscriberGroup(&$object)
{
- $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) );
+ if ( !$object->isSubscriberOnly() ) {
+ $fields_hash = Array (
+ 'PortalUserId' => $object->GetID(),
+ 'GroupId' => $this->Application->ConfigValue('User_SubscriberGroup'),
+ );
+ $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'UserGroup');
+ }
+
$this->Application->EmailEventAdmin('USER.SUBSCRIBE');
- $this->Application->EmailEventUser('USER.SUBSCRIBE', $user_id);
+ $this->Application->EmailEventUser('USER.SUBSCRIBE', $object->GetID());
}
+ /**
+ * Removing user from subscribers group
+ *
+ * @param int $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');
+ WHERE PortalUserId = ' . $user_id . ' AND GroupId = ' . $group_id;
$this->Conn->Query($sql);
$this->Application->EmailEventAdmin('USER.UNSUBSCRIBE');
@@ -754,17 +783,20 @@
}
/**
- * Allows to detect user subscription status (subscribed or not)
+ * Checks user subscription status
*
- * @param int $user_id
+ * @param kDBItem $object
* @return bool
*/
- function GetGroupInfo($user_id)
+ function isSubscribed(&$object)
{
- $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'UserGroup
- WHERE (PortalUserId = ' . $user_id . ')
- AND (GroupId = ' . $this->Application->ConfigValue('User_SubscriberGroup') . ')';
- return $this->Conn->GetRow($sql);
+ $group_id = $this->Application->ConfigValue('User_SubscriberGroup');
+
+ $sql = 'SELECT GroupId
+ FROM ' . TABLE_PREFIX . 'UserGroup
+ WHERE (PortalUserId = ' . $object->GetID() . ') AND (GroupId = ' . $group_id . ')';
+
+ return $this->Conn->GetOne($sql);
}
function OnForgotPassword(&$event)
@@ -896,12 +928,9 @@
if ($exp_time > adodb_mktime()) {
$newpw = $user_object->generatePassword();
-
+
$this->Application->StoreVar('password', $newpw);
- $user_object->SetField('Password', $newpw);
- $user_object->SetField('VerifyPassword', $newpw);
-
$user_object->SetDBField('PassResetTime', adodb_mktime());
$user_object->SetDBField('PwResetConfirm', '');
$user_object->SetDBField('PwRequestTime', 0);
@@ -1369,17 +1398,15 @@
$first_country = $this->Application->ConfigValue('User_Default_Registration_Country');
}
+ $fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
+
if ($first_country) {
// update user country dropdown sql
- $fields = $this->Application->getUnitOption($event->Prefix, 'Fields');
$fields['Country']['options_sql'] = preg_replace('/ORDER BY (.*)/', 'ORDER BY IF (CountryStateId = '.$first_country.', 1, 0) DESC, \\1', $fields['Country']['options_sql']);
- $this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
}
// 2. set default user registration group
- $virtual_fields = $this->Application->getUnitOption($event->Prefix, 'VirtualFields');
- $virtual_fields['UserGroup']['default'] = $this->Application->ConfigValue('User_NewGroup');
- $this->Application->setUnitOption($event->Prefix, 'VirtualFields', $virtual_fields);
+ $fields['PrimaryGroupId']['default'] = $this->Application->ConfigValue('User_NewGroup');
// 3. allow avatar upload on Front-End
$file_helper =& $this->Application->recallObject('FileHelper');
@@ -1410,12 +1437,13 @@
$this->Application->setUnitOption($event->Prefix, 'EditTabPresets', $edit_tab_presets);
}
}
-
+
if ( !$this->Application->ConfigValue('Email_As_Login') ) {
// Login becomes required only, when it's used in registration process
$fields['Login']['required'] = 1;
}
+
- $this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
+ $this->Application->setUnitOption($event->Prefix, 'Fields', $fields);
}
/**
@@ -1431,12 +1459,13 @@
}
$event->status=erSUCCESS;
- $ids = $this->StoreSelectedIDs($event);
$this->Application->SetVar('skip_set_primary', 1); // otherwise it will default primary group, search for skip_set_primary above
$temp_handler =& $this->Application->recallObject($event->Prefix.'_TempHandler', 'kTempTablesHandler');
/* @var $temp_handler kTempTablesHandler */
- $cloned_users = $temp_handler->CloneItems($event->Prefix, '', $ids);
+
+ $ids = $this->StoreSelectedIDs($event);
+ $temp_handler->CloneItems($event->Prefix, '', $ids);
$this->clearSelectedIDs($event);
}
@@ -1454,27 +1483,11 @@
$object->SetDBField('CreatedOn', adodb_mktime());
$object->SetDBField('ResourceId', 0); // this will reset it
- // change email cause it should be unique
- $object->NameCopy(array(), $object->GetID(), 'Email', 'copy%1$s.%2$s');
-
- $object->UpdateFormattersSubFields();
+ // change email because it should be unique
+ $object->NameCopy(Array (), $object->GetID(), 'Email', 'copy%1$s.%2$s');
}
/**
- * Copy user groups after copying user
- *
- * @param kEvent $event
- */
- function OnAfterClone(&$event)
- {
- $id = $event->getEventParam('id');
- $original_id = $event->getEventParam('original_id');
-
- $sql = 'INSERT '.TABLE_PREFIX."UserGroup SELECT $id, GroupId, MembershipExpires, PrimaryGroup, 0 FROM ".TABLE_PREFIX."UserGroup WHERE PortalUserId = $original_id";
- $this->Conn->Query($sql);
- }
-
- /**
* Saves selected ids to session
*
* @param kEvent $event
@@ -1484,11 +1497,11 @@
$this->StoreSelectedIDs($event);
// remove current ID, otherwise group selector will use it in filters
- $this->Application->DeleteVar($event->getPrefixSpecial(true).'_id');
+ $this->Application->DeleteVar($event->getPrefixSpecial(true) . '_id');
}
/**
- * Adds selected link to listing
+ * Sets primary group of selected users
*
* @param kEvent $event
*/
@@ -1512,36 +1525,29 @@
$table_name = $this->Application->getUnitOption('ug', 'TableName');
+ // 1. mark group as primary
+ $sql = 'UPDATE ' . TABLE_PREFIX . 'PortalUser
+ SET PrimaryGroupId = ' . $primary_group_id . '
+ WHERE PortalUserId IN (' . implode(',', $user_ids) . ')';
+ $this->Conn->Query($sql);
+
$sql = 'SELECT PortalUserId
- FROM '.$table_name.'
+ FROM ' . $table_name . '
- WHERE (GroupId = '.$primary_group_id.') AND (PortalUserId IN ('.implode(',', $user_ids).'))';
+ WHERE (GroupId = ' . $primary_group_id . ') AND (PortalUserId IN (' . implode(',', $user_ids) . '))';
$existing_members = $this->Conn->GetCol($sql);
- // 1. reset primary group mark
- $sql = 'UPDATE '.$table_name.'
- SET PrimaryGroup = 0
- WHERE PortalUserId IN ('.implode(',', $user_ids).')';
- $this->Conn->Query($sql);
+ // 2. add new members to a group
+ $new_members = array_diff($user_ids, $existing_members);
- foreach ($user_ids as $user_id) {
- if (in_array($user_id, $existing_members)) {
- // 2. already member of that group -> just make primary
- $sql = 'UPDATE '.$table_name.'
- SET PrimaryGroup = 1
- WHERE (PortalUserId = '.$user_id.') AND (GroupId = '.$primary_group_id.')';
- $this->Conn->Query($sql);
- }
- else {
- // 3. not member of that group -> make member & make primary
+ foreach ($new_members as $user_id) {
- $fields_hash = Array (
+ $fields_hash = Array (
- 'GroupId' => $primary_group_id,
+ 'GroupId' => $primary_group_id,
- 'PortalUserId' => $user_id,
+ 'PortalUserId' => $user_id,
- 'PrimaryGroup' => 1,
- );
+ );
+
- $this->Conn->doInsert($fields_hash, $table_name);
- }
- }
+ $this->Conn->doInsert($fields_hash, $table_name);
+ }
+ }
- }
/**
* Loads user images
@@ -1595,9 +1601,24 @@
{
parent::OnPreCreate($event);
- if ($event->status == erSUCCESS) {
- $this->_makePasswordRequired($event);
+ if ( $event->status != erSUCCESS ) {
+ return;
}
+
+ $object = $event->getObject();
+ /* @var $object kDBItem */
+
+ $user_type = $this->Application->GetVar('user_type');
+
+ if ( $user_type ) {
+ $object->SetDBField('UserType', $user_type);
+
+ if ( $user_type == UserType::ADMIN ) {
+ $object->SetDBField('PrimaryGroupId', $this->Application->ConfigValue('User_AdminGroup'));
+ }
+ }
+
+ $this->_makePasswordRequired($event);
}
/**
@@ -1671,4 +1692,4 @@
{
}
- }
+ }
\ No newline at end of file
Index: core/kernel/constants.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/kernel/constants.php (revision 5818)
+++ core/kernel/constants.php (revision )
@@ -176,4 +176,9 @@
define('RECIPIENT_TYPE_BCC', 3);
define('PAGE_TYPE_VIRTUAL', 1);
- define('PAGE_TYPE_TEMPLATE', 2);
\ No newline at end of file
+ define('PAGE_TYPE_TEMPLATE', 2);
+
+ class UserType {
+ const USER = 0;
+ const ADMIN = 1;
+ }
Index: core/admin_templates/users/admins_list.tpl
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/admin_templates/users/admins_list.tpl (revision 5818)
+++ core/admin_templates/users/admins_list.tpl (revision )
@@ -10,21 +10,22 @@
//do not rename - this function is used in default grid for double click!
function edit()
{
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
std_edit_item('u.admins', 'users/admins_edit');
}
var a_toolbar = new ToolBar();
a_toolbar.AddButton( new ToolBarButton('new_item', '<inp2:m_phrase label="la_ToolTip_Add" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('user_type', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
std_precreate_item('u.admins', 'users/admins_edit')
} ) );
a_toolbar.AddButton( new ToolBarButton('edit', '<inp2:m_phrase label="la_ToolTip_Edit" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_Edit" escape="1"/>', edit) );
a_toolbar.AddButton( new ToolBarButton('delete', '<inp2:m_phrase label="la_ToolTip_Delete" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
std_delete_items('u.admins')
} ) );
@@ -33,7 +34,7 @@
a_toolbar.AddButton( new ToolBarButton('clone', '<inp2:m_phrase label="la_ToolTip_CloneUser" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_CloneUser" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
submit_event('u.admins', 'OnMassCloneUsers');
} ) );
@@ -42,7 +43,7 @@
a_toolbar.AddButton( new ToolBarButton('refresh', '<inp2:m_phrase label="la_ToolTip_ResetSettings" escape="1"/>::<inp2:m_phrase label="la_ShortToolTip_ResetSettings" escape="1"/>',
function() {
- set_hidden_field('remove_specials[u.admins]', 1);
+ Application.SetVar('remove_specials[u.admins]', 1);
submit_event('u.admins', 'OnMassResetSettings');
} ) );
@@ -65,4 +66,4 @@
<script type="text/javascript">
Grids['u.admins'].SetDependantToolbarButtons( new Array('edit','delete','clone') );
</script>
-<inp2:m_include t="incs/footer"/>
\ No newline at end of file
+<inp2:m_include t="incs/footer"/>
Index: core/units/user_groups/user_groups_config.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/units/user_groups/user_groups_config.php (revision 5818)
+++ core/units/user_groups/user_groups_config.php (revision )
@@ -39,6 +39,7 @@
'' => Array(
'UserName' => 'CONCAT(u.LastName, \' \', u.FirstName)',
'UserLogin' => 'u.Login',
+ 'PrimaryGroup' => 'IF(u.PrimaryGroupId = %1$s.GroupId, 1, 0)',
),
),
'VirtualFields' => Array (
@@ -84,12 +85,11 @@
'TitleField' => 'GroupName',
'TableName' => TABLE_PREFIX.'UserGroup',
- 'ListSQLs' => Array( ''=>' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId'),
+ 'ListSQLs' => Array( ''=>' SELECT %1$s.* %2$s
+ FROM %1$s
+ LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId
+ LEFT JOIN '.TABLE_PREFIX.'%3$sPortalUser u ON %1$s.PortalUserId = u.PortalUserId'),
- 'ItemSQLs' => Array( ''=>' SELECT %1$s.* %2$s FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId'),
-
'AutoDelete' => true,
'AutoClone' => false,
@@ -97,6 +97,7 @@
'' => Array(
'GroupName' => 'g.Name',
'GroupDescription' => 'g.Description',
+ 'PrimaryGroup' => 'IF(u.PrimaryGroupId = %1$s.GroupId, 1, 0)',
),
),
@@ -104,13 +105,17 @@
'PortalUserId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
'GroupId' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
'MembershipExpires' => Array('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => null),
- 'PrimaryGroup' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1, 'not_null' => 1, 'default' => 1),
'ExpirationReminderSent' => Array('type' => 'int', 'not_null' => 1, 'default' => 0),
),
'VirtualFields' => Array (
'GroupName' => Array('type' => 'string', 'default' => ''),
'GroupDescription' => Array('type' => 'string', 'default' => ''),
+ 'PrimaryGroup' => Array(
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter', 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 1
+ ),
),
'Grids' => Array(
@@ -129,4 +134,4 @@
),
),
- );
\ No newline at end of file
+ );
Index: core/units/helpers/user_helper.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/units/helpers/user_helper.php (revision 5818)
+++ core/units/helpers/user_helper.php (revision )
@@ -189,6 +189,13 @@
$groups = Array();
}
+ if ( $object->GetDBField('UserType') == UserType::USER ) {
+ array_push($groups, $this->Application->ConfigValue('User_NewGroup') );
+ }
+ elseif ( $object->GetDBField('UserType') == UserType::ADMIN ) {
+ array_push($groups, $this->Application->ConfigValue('User_AdminGroup') );
+ }
+
// store groups, because kApplication::CheckPermission will use them!
array_push($groups, $this->Application->ConfigValue('User_LoggedInGroup') );
$this->Application->StoreVar( 'UserGroups', implode(',', $groups), true ); // true for optional
Index: core/admin_templates/users/admins_edit.tpl
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/admin_templates/users/admins_edit.tpl (revision 5818)
+++ core/admin_templates/users/admins_edit.tpl (revision )
@@ -60,7 +60,9 @@
<inp2:u_SaveWarning name="grid_save_warning"/>
<inp2:u_ErrorWarning name="form_error_warning"/>
-<input type="hidden" name="user_group" value="11"/>
+<inp2:m_RenderElement name="inp_edit_hidden" prefix="u" field="UserType"/>
+<inp2:m_RenderElement name="inp_edit_hidden" prefix="u" field="PrimaryGroupId"/>
+
<div id="scroll_container">
<table class="edit-form">
<inp2:m_RenderElement name="inp_id_label" prefix="u" field="PortalUserId" title="la_fld_Id"/>
@@ -74,4 +76,4 @@
</table>
</div>
-<inp2:m_include t="incs/footer"/>
\ No newline at end of file
+<inp2:m_include t="incs/footer"/>
Index: admin/system_presets/simple/user_groups_u-ug.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- admin/system_presets/simple/user_groups_u-ug.php (revision 5818)
+++ admin/system_presets/simple/user_groups_u-ug.php (revision )
@@ -18,7 +18,7 @@
// fields to hide
$hidden_fields = Array (
- /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+ /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to hide
@@ -28,7 +28,7 @@
// fields to make required
$required_fields = Array (
- /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'PrimaryGroup', 'ExpirationReminderSent', */
+ /* 'PortalUserId', 'GroupId', 'MembershipExpires', 'ExpirationReminderSent', */
);
// virtual fields to make required
Index: core/install/english.lang
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/install/english.lang (revision 5818)
+++ core/install/english.lang (revision )
@@ -1525,6 +1525,7 @@
<PHRASE Label="la_updating_config" Module="Core" Type="1">VXBkYXRpbmcgQ29uZmlndXJhdGlvbg==</PHRASE>
<PHRASE Label="la_Upload" Module="Core" Type="1">VXBsb2Fk</PHRASE>
<PHRASE Label="la_UseCronForRegularEvent" Module="Core" Type="1">VXNlIENyb24gdG8gcnVuIEFnZW50cw==</PHRASE>
+ <PHRASE Label="la_users_admin_group" Module="Core" Type="1">QXNzaWduIGFkbWluaXN0cmF0b3JzIHRvIGdyb3Vw</PHRASE>
<PHRASE Label="la_users_allow_new" Module="Core" Type="1">QWxsb3cgbmV3IHVzZXIgcmVnaXN0cmF0aW9u</PHRASE>
<PHRASE Label="la_users_assign_all_to" Module="Core" Type="1">QXNzaWduIEFsbCBVc2VycyBUbyBHcm91cA==</PHRASE>
<PHRASE Label="la_users_guest_group" Module="Core" Type="1">QXNzaWduIHVzZXJzIG5vdCBsb2dnZWQgaW4gdG8gZ3JvdXA=</PHRASE>
user_group_storage_modules_513.patch [^] (10,459 bytes) 2012-11-27 09:22
[Show Content]
Index: modules/in-commerce/units/products/products_event_handler.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- modules/in-commerce/units/products/products_event_handler.php (revision 5818)
+++ modules/in-commerce/units/products/products_event_handler.php (revision )
@@ -750,45 +750,48 @@
$field_values = $event->getEventParam('field_values');
$item_data = unserialize($field_values['ItemData']);
- if (!getArrayValue($item_data,'PortalGroupId')) {
+ if ( !getArrayValue($item_data,'PortalGroupId') ) {
// is subscription product, but no group defined in it's properties
trigger_error('Invalid product <b>'.$field_values['ProductName'].'</b> (id: '.$field_values['ProductId'].')', E_USER_WARNING);
return false;
}
- $order_table = $this->Application->getUnitOption('ord', 'TableName');
- $order_idfield = $this->Application->getUnitOption('ord', 'IDField');
- $sql = 'SELECT PortalUserId FROM %s WHERE %s = %s';
- $user_id = $this->Conn->GetOne( sprintf($sql, $order_table, $order_idfield, $field_values['OrderId']) );
+ $sql = 'SELECT PortalUserId
+ FROM ' . $this->Application->getUnitOption('ord', 'TableName') . '
+ WHERE ' . $this->Application->getUnitOption('ord', 'IDField') . ' = ' . $field_values['OrderId'];
+ $user_id = $this->Conn->GetOne($sql);
$group_id = $item_data['PortalGroupId'];
$duration = $item_data['Duration'];
- $sql = 'SELECT * FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId = %s';
- $user_groups = $this->Conn->Query( sprintf($sql, $user_id), 'GroupId' );
+ $sql = 'SELECT *
+ FROM ' . TABLE_PREFIX . 'UserGroup
+ WHERE PortalUserId = ' . $user_id;
+ $user_groups = $this->Conn->Query($sql, 'GroupId');
- $sql = 'REPLACE INTO '.TABLE_PREFIX.'UserGroup (PortalUserId,GroupId,MembershipExpires,PrimaryGroup) VALUES (%s,%s,%s,%s)';
- if( !isset($user_groups[$group_id]) )
- {
- $primary_group = count($user_groups) == 0 ? 1 : 0;
+ if ( !isset($user_groups[$group_id]) ) {
$expire = adodb_mktime() + $duration;
}
else {
- $primary_group = $user_groups[$group_id]['PrimaryGroup'];
$expire = $user_groups[$group_id]['MembershipExpires'];
$expire = $expire < adodb_mktime() ? adodb_mktime() + $duration : $expire + $duration;
}
-/*
- // Customization healtheconomics.org
+ /*// Customization healtheconomics.org
if ($item_data['DurationType'] == 2) {
$expire = $item_data['AccessExpiration'];
}
- // Customization healtheconomics.org --
-*/
- $this->Conn->Query( sprintf($sql, $user_id, $group_id, $expire, $primary_group) );
+ // Customization healtheconomics.org --*/
$sub_order =& $this->Application->recallObject('ord.-sub'.$event->getEventParam('next_sub_number'), 'ord');
+
+ $fields_hash = Array (
+ 'PortalUserId' => $user_id,
+ 'GroupId' => $group_id,
+ 'MembershipExpires' => $expire,
+ );
+
+ $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'UserGroup', 'REPLACE');
$sub_order->SetDBField('IsRecurringBilling', getArrayValue($item_data, 'IsRecurringBilling') ? 1 : 0);
$sub_order->SetDBField('GroupId', $group_id);
$sub_order->SetDBField('NextCharge_date', $expire);
@@ -975,7 +978,7 @@
parent::OnAfterItemLoad($event);
$object =& $event->getObject();
- /* @var $object kDBItem */
+ /* @var $object ProductsItem */
$a_pricing = $object->getPrimaryPricing();
if (!$a_pricing) {
@@ -1239,22 +1242,22 @@
$user_id = $this->Application->RecallVar('user_id');
- $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields');
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . TABLE_PREFIX . 'PortalUser
+ WHERE PortalUserId = ' . $user_id;
+ $primary_group_id = $this->Conn->GetOne($sql);
- $sql = 'SELECT GroupId
- FROM ' . TABLE_PREFIX . 'UserGroup
- WHERE PrimaryGroup = 1 AND PortalUserId = ' . $user_id;
- $primary_group = $this->Conn->GetOne($sql);
-
- if (!$primary_group) {
+ if (!$primary_group_id) {
return;
}
$sub_select = ' SELECT pp.Price
FROM ' . TABLE_PREFIX . 'ProductsPricing AS pp
- WHERE pp.ProductId = %1$s.ProductId AND GroupId = ' . $primary_group . '
+ WHERE pp.ProductId = %1$s.ProductId AND GroupId = ' . $primary_group_id . '
ORDER BY MinQty
LIMIT 0,1';
+
+ $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields');
$calculated_fields['']['Price'] = 'IFNULL((' . $sub_select . '), ' . $calculated_fields['']['Price'] . ')';
$this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields);
}
@@ -1305,4 +1308,4 @@
$this->Application->setUnitOption($event->MasterEvent->Prefix, 'Clones', $clones);
}
}
-}
\ No newline at end of file
+}
Index: modules/in-commerce/units/orders/orders_event_handler.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- modules/in-commerce/units/orders/orders_event_handler.php (revision 5818)
+++ modules/in-commerce/units/orders/orders_event_handler.php (revision )
@@ -3224,7 +3224,10 @@
$primary_group = $this->Application->ConfigValue('User_LoggedInGroup'); // actually this is Everyone
}
else {
- $primary_group = $this->Conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$user_id.' AND PrimaryGroup=1');
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . TABLE_PREFIX . 'PortalUser
+ WHERE PortalUserId = ' . $user_id;
+ $primary_group = $this->Conn->GetOne($sql);
}
$orderby_clause = 'ORDER BY (IF(GroupId='.$primary_group.',1,2)) ASC, pp.Price ASC';
}
\ No newline at end of file
Index: modules/in-commerce/units/pricing/pricing_event_handler.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- modules/in-commerce/units/pricing/pricing_event_handler.php (revision 5818)
+++ modules/in-commerce/units/pricing/pricing_event_handler.php (revision )
@@ -152,16 +152,16 @@
$this->Application->SetVar($event->getPrefixSpecial(true), $temp);
$event->CallSubEvent('OnPreSaveBrackets');
break;
-
- case 'OnDeleteBrackets':
+
+ case 'OnDeleteBrackets':
if ($group_id) {
$temp = ''; // delete all pricings from "pr_tang" var
-
- $sql = 'DELETE FROM ' . $bracket->TableName . '
+
+ $sql = 'DELETE FROM ' . $bracket->TableName . '
WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND GroupId = ' . $group_id;
$this->Conn->Query($sql);
- }
- break;
+ }
+ break;
default:
}
@@ -172,7 +172,7 @@
function OnPreSaveBrackets(&$event)
{
if( $this->Application->GetVar('pr_tang') ) {
-
+
$object =& $event->GetObject();
/* @var $object kDBItem */
@@ -180,20 +180,20 @@
$group_id = $this->Application->getVar('group_id');
$sql = 'SELECT PriceId
- FROM ' . $object->TableName . '
+ FROM ' . $object->TableName . '
WHERE ProductId = ' . $product_id . ' ' . ($group_id? 'AND GroupId = ' . $group_id : '');
$stored_ids = $this->Conn->GetCol($sql);
-
+
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) ); // get pr_tang var
uasort($items_info, 'pr_bracket_comp');
-
+
foreach ($items_info as $item_id => $values) {
if (in_array($item_id, $stored_ids)) { //if it's already exist
$object->SetDefaultValues();
$object->Load($item_id);
$object->SetFieldsFromHash($values);
-
+
if (!$object->Validate()) {
unset($stored_ids[array_search($item_id, $stored_ids)]);
$event->redirect = false;
@@ -428,27 +428,35 @@
return ;
}
- $user_groups = $this->Application->RecallVar('UserGroups');
+ if ( $this->Application->ConfigValue('Comm_PriceBracketCalculation') == 1 ) {
+ $sql = 'SELECT PrimaryGroupId
+ FROM ' . TABLE_PREFIX . 'PortalUser
+ WHERE PortalUserId = ' . $this->Application->GetVar('u_id');
+ $pricing_group = $this->Conn->GetOne($sql);
- $pricing_method = $this->Application->ConfigValue('Comm_PriceBracketCalculation');
- if ($pricing_method == 1) {
- $primary_group = $this->Conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'UserGroup WHERE PortalUserId='.$this->Application->GetVar('u_id').' AND PrimaryGroup=1');
- $pricing_group = $primary_group;
if ($pricing_group) {
- $pricing_for_group_exists = $this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'ProductsPricing WHERE ProductId='.$this->Application->GetVar('p_id').' AND GroupId='.$primary_group.' AND Price IS NOT NULL');
+ $sql = 'SELECT COUNT(*)
+ FROM ' . TABLE_PREFIX . 'ProductsPricing
+ WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND GroupId = ' . $pricing_group . ' AND Price IS NOT NULL';
+ $pricing_for_group_exists = $this->Conn->GetOne($sql);
}
- if ($pricing_group && $pricing_for_group_exists > 0) {
- $pricing_group = $primary_group;
- }
- else {
+
+ if ( !$pricing_group || !$pricing_for_group_exists ) {
$pricing_group = $this->Application->ConfigValue('User_LoggedInGroup');
}
}
else {
+ $user_groups = $this->Application->RecallVar('UserGroups');
+
//$cheapest_group = $this->Conn->GetOne('SELECT GroupId FROM '.$object->TableName.' WHERE ProductId='.$this->Application->GetVar('p_id').' AND Price IS NOT NULL AND GroupId IN ('.$user_groups.') AND MinQty = 1 GROUP BY GroupId ORDER BY Price ASC');
- $effective_brackets = $this->Conn->Query('SELECT PriceId, Price, GroupId FROM '.$object->TableName.'
- WHERE ProductId='.$this->Application->GetVar('p_id').' AND Price IS NOT NULL AND GroupId IN ('.$user_groups.') ORDER BY GroupId ASC, MinQty ASC', 'PriceId');
+
+ $sql = 'SELECT PriceId, Price, GroupId
+ FROM ' . $object->TableName . '
+ WHERE ProductId = ' . $this->Application->GetVar('p_id') . ' AND Price IS NOT NULL AND GroupId IN (' . $user_groups . ')
+ ORDER BY GroupId ASC, MinQty ASC';
+ $effective_brackets = $this->Conn->Query($sql, 'PriceId');
+
$group_prices = array();
$min_price = -1;
$cheapest_group = 0;
@@ -473,4 +481,4 @@
$object->addFilter('price_user_group', $object->TableName.'.GroupId='.$pricing_group);
}
-}
\ No newline at end of file
+}
|