Index: trunk/kernel/units/permissions/permissions_tag_processor.php =================================================================== diff -u -N --- trunk/kernel/units/permissions/permissions_tag_processor.php (revision 0) +++ trunk/kernel/units/permissions/permissions_tag_processor.php (revision 4612) @@ -0,0 +1,64 @@ +Application->recallObject('SectionsHelper'); + $section_data =& $sections_helper->getSectionData($section_name); + + return array_search($params['perm_name'], $section_data['permissions']) !== false; + } + + function HasAdvancedPermissions($params) + { + $section_name = $params['section_name']; + + $sections_helper =& $this->Application->recallObject('SectionsHelper'); + $section_data =& $sections_helper->getSectionData($section_name); + + $ret = false; + foreach ($section_data['permissions'] as $perm_name) { + if (preg_match('/^advanced:(.*)/', $perm_name)) { + $ret = true; + break; + } + } + return $ret; + } + + function PermissionValue($params) + { + $section_name = $params['section_name']; + + $sections_helper =& $this->Application->recallObject('SectionsHelper'); + $section_data =& $sections_helper->getSectionData($section_name); + $perm_name = $params['perm_name']; + + $permissions_helper =& $this->Application->recallObject('PermissionsHelper'); + if (!$permissions_helper->isOldPermission($section_name, $perm_name)) { + $perm_name = $section_name.'.'.$perm_name; + } + + return $permissions_helper->getPermissionValue($perm_name); + } + + function LoadPermissions($params) + { + $permissions_helper =& $this->Application->recallObject('PermissionsHelper'); + $prefix_parts = explode('-', $this->Prefix, 2); + $permissions_helper->LoadPermissions($prefix_parts[0]); + } + + function LevelIndicator($params) + { + return $params['level'] * $params['multiply']; + } + + } + +?> \ No newline at end of file Index: trunk/core/units/user_groups/user_groups_config.php =================================================================== diff -u -N --- trunk/core/units/user_groups/user_groups_config.php (revision 0) +++ trunk/core/units/user_groups/user_groups_config.php (revision 4612) @@ -0,0 +1,94 @@ + Array( + 'g-ug' => Array( + 'ParentPrefix' => 'g', + 'ForeignKey' => 'GroupId', + 'ParentTableKey' => 'GroupId', + ), + + 'u-ug' => Array( + 'ParentPrefix' => 'u', + 'ForeignKey' => 'PortalUserId', + 'ParentTableKey' => 'PortalUserId', + ), + + ), + + 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'InpDBEventHandler','file'=>'','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'), + 'AutoLoad' => true, + + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + + 'IDField' => 'GroupId', + 'StatusField' => Array('UserStatus'), + + '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 AND %1$s.PrimaryGroup = 1 + LEFT JOIN '.TABLE_PREFIX.'PortalUser u ON u.PortalUserId = %1$s.PortalUserId'), + + 'ItemSQLs' => Array( ''=>' SELECT %1$s.* %2$s FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId AND %1$s.PrimaryGroup = 1 + LEFT JOIN '.TABLE_PREFIX.'PortalUser u ON u.PortalUserId = %1$s.PortalUserId'), + + 'AutoDelete' => true, + 'AutoClone' => true, + + 'CalculatedFields' => Array( + '' => Array( + 'Login' => 'u.Login', + 'FirstName' => 'u.FirstName', + 'LastName' => 'u.LastName', + 'Email' => 'u.Email', + 'PrimaryGroup' => 'g.Name', + 'CreatedOn' => 'u.CreatedOn', + 'UserStatus' => 'u.Status' + ), + ), + + 'Fields' => Array( + 'PortalUserId' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'GroupId' => Array(), + 'MembershipExpires' => Array('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => ''), + 'PrimaryGroup' => Array('type' => 'int','not_null' => '1','default' => '1'), + 'ExpirationReminderSent' => Array('type' => 'int','not_null' => '1','default' => '0'), + ), + + 'VirtualFields' => Array( + 'Login' => Array('type' => 'string'), + 'FirstName' => Array('type' => 'string'), + 'LastName' => Array('type' => 'string'), + 'Email' => Array('type' => 'string'), + 'PrimaryGroup' => Array('type' => 'string'), + 'CreatedOn' => Array('type' => 'int', 'formatter' => 'kDateFormatter', 'not_null' => 1, 'default' => '#NOW#'), + 'UserStatus' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array(1 => 'la_Enabled', 0 => 'la_Disabled', 2 => 'la_Pending'), 'use_phrases' => 1, 'not_null' => '1','default' => 2), + ), + + + 'Grids' => Array( + 'Default' => Array( + 'Icons' => Array(0 => 'icon16_user_disabled.gif', 1 => 'icon16_user.gif', 2 => 'icon16_user_pending.gif'), + 'Fields' => Array( + 'Login' => Array('title' => 'la_col_Username', 'data_block' => 'grid_checkbox_td'), + 'LastName' => Array( 'title'=>'la_col_LastName'), + 'FirstName' => Array( 'title'=>'la_col_FirstName'), + 'Email' => Array( 'title'=>'la_col_Email'), + 'PrimaryGroup' => Array( 'title'=>'la_col_PrimaryGroup'), + 'CreatedOn_formatted' => Array('title' => 'la_col_CreatedOn', 'sort_field' => 'CreatedOn'), + ), + ), + ), + + ); + +?> \ No newline at end of file Index: trunk/core/units/permissions/permissions_tag_processor.php =================================================================== diff -u -N --- trunk/core/units/permissions/permissions_tag_processor.php (revision 0) +++ trunk/core/units/permissions/permissions_tag_processor.php (revision 4612) @@ -0,0 +1,64 @@ +Application->recallObject('SectionsHelper'); + $section_data =& $sections_helper->getSectionData($section_name); + + return array_search($params['perm_name'], $section_data['permissions']) !== false; + } + + function HasAdvancedPermissions($params) + { + $section_name = $params['section_name']; + + $sections_helper =& $this->Application->recallObject('SectionsHelper'); + $section_data =& $sections_helper->getSectionData($section_name); + + $ret = false; + foreach ($section_data['permissions'] as $perm_name) { + if (preg_match('/^advanced:(.*)/', $perm_name)) { + $ret = true; + break; + } + } + return $ret; + } + + function PermissionValue($params) + { + $section_name = $params['section_name']; + + $sections_helper =& $this->Application->recallObject('SectionsHelper'); + $section_data =& $sections_helper->getSectionData($section_name); + $perm_name = $params['perm_name']; + + $permissions_helper =& $this->Application->recallObject('PermissionsHelper'); + if (!$permissions_helper->isOldPermission($section_name, $perm_name)) { + $perm_name = $section_name.'.'.$perm_name; + } + + return $permissions_helper->getPermissionValue($perm_name); + } + + function LoadPermissions($params) + { + $permissions_helper =& $this->Application->recallObject('PermissionsHelper'); + $prefix_parts = explode('-', $this->Prefix, 2); + $permissions_helper->LoadPermissions($prefix_parts[0]); + } + + function LevelIndicator($params) + { + return $params['level'] * $params['multiply']; + } + + } + +?> \ No newline at end of file Index: trunk/kernel/units/user_groups/user_groups_config.php =================================================================== diff -u -N --- trunk/kernel/units/user_groups/user_groups_config.php (revision 0) +++ trunk/kernel/units/user_groups/user_groups_config.php (revision 4612) @@ -0,0 +1,94 @@ + Array( + 'g-ug' => Array( + 'ParentPrefix' => 'g', + 'ForeignKey' => 'GroupId', + 'ParentTableKey' => 'GroupId', + ), + + 'u-ug' => Array( + 'ParentPrefix' => 'u', + 'ForeignKey' => 'PortalUserId', + 'ParentTableKey' => 'PortalUserId', + ), + + ), + + 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'InpDBEventHandler','file'=>'','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'), + 'AutoLoad' => true, + + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + + 'IDField' => 'GroupId', + 'StatusField' => Array('UserStatus'), + + '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 AND %1$s.PrimaryGroup = 1 + LEFT JOIN '.TABLE_PREFIX.'PortalUser u ON u.PortalUserId = %1$s.PortalUserId'), + + 'ItemSQLs' => Array( ''=>' SELECT %1$s.* %2$s FROM %1$s + LEFT JOIN '.TABLE_PREFIX.'PortalGroup g ON %1$s.GroupId = g.GroupId AND %1$s.PrimaryGroup = 1 + LEFT JOIN '.TABLE_PREFIX.'PortalUser u ON u.PortalUserId = %1$s.PortalUserId'), + + 'AutoDelete' => true, + 'AutoClone' => true, + + 'CalculatedFields' => Array( + '' => Array( + 'Login' => 'u.Login', + 'FirstName' => 'u.FirstName', + 'LastName' => 'u.LastName', + 'Email' => 'u.Email', + 'PrimaryGroup' => 'g.Name', + 'CreatedOn' => 'u.CreatedOn', + 'UserStatus' => 'u.Status' + ), + ), + + 'Fields' => Array( + 'PortalUserId' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'GroupId' => Array(), + 'MembershipExpires' => Array('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => ''), + 'PrimaryGroup' => Array('type' => 'int','not_null' => '1','default' => '1'), + 'ExpirationReminderSent' => Array('type' => 'int','not_null' => '1','default' => '0'), + ), + + 'VirtualFields' => Array( + 'Login' => Array('type' => 'string'), + 'FirstName' => Array('type' => 'string'), + 'LastName' => Array('type' => 'string'), + 'Email' => Array('type' => 'string'), + 'PrimaryGroup' => Array('type' => 'string'), + 'CreatedOn' => Array('type' => 'int', 'formatter' => 'kDateFormatter', 'not_null' => 1, 'default' => '#NOW#'), + 'UserStatus' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array(1 => 'la_Enabled', 0 => 'la_Disabled', 2 => 'la_Pending'), 'use_phrases' => 1, 'not_null' => '1','default' => 2), + ), + + + 'Grids' => Array( + 'Default' => Array( + 'Icons' => Array(0 => 'icon16_user_disabled.gif', 1 => 'icon16_user.gif', 2 => 'icon16_user_pending.gif'), + 'Fields' => Array( + 'Login' => Array('title' => 'la_col_Username', 'data_block' => 'grid_checkbox_td'), + 'LastName' => Array( 'title'=>'la_col_LastName'), + 'FirstName' => Array( 'title'=>'la_col_FirstName'), + 'Email' => Array( 'title'=>'la_col_Email'), + 'PrimaryGroup' => Array( 'title'=>'la_col_PrimaryGroup'), + 'CreatedOn_formatted' => Array('title' => 'la_col_CreatedOn', 'sort_field' => 'CreatedOn'), + ), + ), + ), + + ); + +?> \ No newline at end of file Index: trunk/kernel/units/permissions/permissions_event_handler.php =================================================================== diff -u -N --- trunk/kernel/units/permissions/permissions_event_handler.php (revision 0) +++ trunk/kernel/units/permissions/permissions_event_handler.php (revision 4612) @@ -0,0 +1,79 @@ +Application->GetVar($event->getPrefixSpecial(true)); + if (!$permissions) { + return false; + } + + $object =& $event->getObject( Array('skip_autoload' => true) ); + $group_id = $this->Application->GetVar('g_id'); + $permissions_helper =& $this->Application->recallObject('PermissionsHelper'); + $permissions_helper->LoadPermissions('g'); + + $delete_ids = Array(); + $create_sql = Array(); + $create_mask = '(%s,%s,'.$group_id.',%s,1,0)'; + + $new_id = (int)$this->Conn->GetOne('SELECT MIN('.$object->IDField.') FROM '.$object->TableName); + if($new_id > 0) $new_id = 0; + --$new_id; + + foreach ($permissions as $section_name => $section_permissions) { + foreach ($section_permissions as $perm_name => $perm_value) { + + if (!$permissions_helper->isOldPermission($section_name, $perm_name)) { + $perm_name = $section_name.'.'.$perm_name; + } + + $db_perm_value = $permissions_helper->getPermissionValue($perm_name); + if ($db_perm_value == 1 && $perm_value == 0) { + // permission was disabled => delete it's record + $delete_ids[] = $permissions_helper->getPermissionID($perm_name); + } + elseif ($db_perm_value == 0 && $perm_value == 1) { + // permission was enabled => created it's record + $create_sql[] = sprintf($create_mask, $new_id--, $this->Conn->qstr($perm_name), $this->Conn->qstr($perm_value)); + } + // permission state was not changed in all other cases + } + } + + if ($delete_ids) { + $delete_sql = ' DELETE FROM '.$object->TableName.' + WHERE '.$object->IDField.' IN ('.implode(',', $delete_ids).')'; + $this->Conn->Query($delete_sql); + } + + if ($create_sql) { + $create_sql = ' INSERT INTO '.$object->TableName.' + VALUES '.implode(',', $create_sql); + $this->Conn->Query($create_sql); + } + + if ($delete_ids || $create_sql) { + $object->setModifiedFlag(); + } + + if ($this->Application->GetVar('advanced_save') == 1) { + // advanced permission popup [save button] + $this->finalizePopup($event); +// $event->redirect = 'incs/just_close'; + } + elseif ($this->Application->GetVar('section_name') != '') { + // save simple permissions before opening advanced permission popup + $event->redirect = false; + } + + } +} + +?> \ No newline at end of file Index: trunk/core/units/permissions/permissions_config.php =================================================================== diff -u -N --- trunk/core/units/permissions/permissions_config.php (revision 0) +++ trunk/core/units/permissions/permissions_config.php (revision 4612) @@ -0,0 +1,74 @@ + Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'PermissionsEventHandler','file'=>'permissions_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'PermissionsTagProcessor','file'=>'permissions_tag_processor.php','build_event'=>'OnBuild'), + 'AutoLoad' => true, + + 'Hooks' => Array( + Array( + 'Mode' => hAFTER, + 'Conditional' => true, + 'HookToPrefix' => '#PARENT#', + 'HookToSpecial' => '*', + 'HookToEvent' => Array('OnPreSave'), + 'DoPrefix' => '', + 'DoSpecial' => '*', + 'DoEvent' => 'OnSavePermissions', + ), + ), + + 'Clones' => Array( + 'c-perm' => Array( + 'Constrain' => 'Type = 0', // non-system + 'ParentPrefix' => 'c', + 'ForeignKey' => 'CatId', + 'ParentTableKey' => 'CategoryId', + ), + + 'g-perm' => Array( + 'Constrain' => 'Type = 1', // system + 'ParentPrefix' => 'g', + 'ForeignKey' => 'GroupId', + 'ParentTableKey' => 'GroupId', + ), + ), + + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + + 'IDField' => 'PermissionId', + + 'StatusField' => Array('PermissionValue'), + + 'TitleField' => 'Permission', + + 'TableName' => TABLE_PREFIX.'Permissions', + + 'AutoDelete' => true, + 'AutoClone' => true, + + 'ListSQLs' => Array('' => 'SELECT %1$s.* %2$s FROM %1$s'), + 'ItemSQLs' => Array('' => 'SELECT %1$s.* %2$s FROM %1$s'), + + 'ListSortings' => Array( + '' => Array( + 'Sorting' => Array('Permission' => 'asc'), + ) + ), + 'Fields' => Array( + 'PermissionId' => Array(), + 'Permission' => Array('type' => 'string','not_null' => '1','default' => ''), + 'GroupId' => Array('type' => 'int','default' => '0'), + 'PermissionValue' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'Type' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'CatId' => Array('type' => 'int','not_null' => '1','default' => '0'), + ), + ); + +?> \ No newline at end of file Index: trunk/core/units/permissions/permissions_event_handler.php =================================================================== diff -u -N --- trunk/core/units/permissions/permissions_event_handler.php (revision 0) +++ trunk/core/units/permissions/permissions_event_handler.php (revision 4612) @@ -0,0 +1,79 @@ +Application->GetVar($event->getPrefixSpecial(true)); + if (!$permissions) { + return false; + } + + $object =& $event->getObject( Array('skip_autoload' => true) ); + $group_id = $this->Application->GetVar('g_id'); + $permissions_helper =& $this->Application->recallObject('PermissionsHelper'); + $permissions_helper->LoadPermissions('g'); + + $delete_ids = Array(); + $create_sql = Array(); + $create_mask = '(%s,%s,'.$group_id.',%s,1,0)'; + + $new_id = (int)$this->Conn->GetOne('SELECT MIN('.$object->IDField.') FROM '.$object->TableName); + if($new_id > 0) $new_id = 0; + --$new_id; + + foreach ($permissions as $section_name => $section_permissions) { + foreach ($section_permissions as $perm_name => $perm_value) { + + if (!$permissions_helper->isOldPermission($section_name, $perm_name)) { + $perm_name = $section_name.'.'.$perm_name; + } + + $db_perm_value = $permissions_helper->getPermissionValue($perm_name); + if ($db_perm_value == 1 && $perm_value == 0) { + // permission was disabled => delete it's record + $delete_ids[] = $permissions_helper->getPermissionID($perm_name); + } + elseif ($db_perm_value == 0 && $perm_value == 1) { + // permission was enabled => created it's record + $create_sql[] = sprintf($create_mask, $new_id--, $this->Conn->qstr($perm_name), $this->Conn->qstr($perm_value)); + } + // permission state was not changed in all other cases + } + } + + if ($delete_ids) { + $delete_sql = ' DELETE FROM '.$object->TableName.' + WHERE '.$object->IDField.' IN ('.implode(',', $delete_ids).')'; + $this->Conn->Query($delete_sql); + } + + if ($create_sql) { + $create_sql = ' INSERT INTO '.$object->TableName.' + VALUES '.implode(',', $create_sql); + $this->Conn->Query($create_sql); + } + + if ($delete_ids || $create_sql) { + $object->setModifiedFlag(); + } + + if ($this->Application->GetVar('advanced_save') == 1) { + // advanced permission popup [save button] + $this->finalizePopup($event); +// $event->redirect = 'incs/just_close'; + } + elseif ($this->Application->GetVar('section_name') != '') { + // save simple permissions before opening advanced permission popup + $event->redirect = false; + } + + } +} + +?> \ No newline at end of file Index: trunk/kernel/units/permissions/permissions_config.php =================================================================== diff -u -N --- trunk/kernel/units/permissions/permissions_config.php (revision 0) +++ trunk/kernel/units/permissions/permissions_config.php (revision 4612) @@ -0,0 +1,74 @@ + Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'), + 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'), + 'EventHandlerClass' => Array('class'=>'PermissionsEventHandler','file'=>'permissions_event_handler.php','build_event'=>'OnBuild'), + 'TagProcessorClass' => Array('class'=>'PermissionsTagProcessor','file'=>'permissions_tag_processor.php','build_event'=>'OnBuild'), + 'AutoLoad' => true, + + 'Hooks' => Array( + Array( + 'Mode' => hAFTER, + 'Conditional' => true, + 'HookToPrefix' => '#PARENT#', + 'HookToSpecial' => '*', + 'HookToEvent' => Array('OnPreSave'), + 'DoPrefix' => '', + 'DoSpecial' => '*', + 'DoEvent' => 'OnSavePermissions', + ), + ), + + 'Clones' => Array( + 'c-perm' => Array( + 'Constrain' => 'Type = 0', // non-system + 'ParentPrefix' => 'c', + 'ForeignKey' => 'CatId', + 'ParentTableKey' => 'CategoryId', + ), + + 'g-perm' => Array( + 'Constrain' => 'Type = 1', // system + 'ParentPrefix' => 'g', + 'ForeignKey' => 'GroupId', + 'ParentTableKey' => 'GroupId', + ), + ), + + 'QueryString' => Array( + 1 => 'id', + 2 => 'page', + 3 => 'event', + ), + + 'IDField' => 'PermissionId', + + 'StatusField' => Array('PermissionValue'), + + 'TitleField' => 'Permission', + + 'TableName' => TABLE_PREFIX.'Permissions', + + 'AutoDelete' => true, + 'AutoClone' => true, + + 'ListSQLs' => Array('' => 'SELECT %1$s.* %2$s FROM %1$s'), + 'ItemSQLs' => Array('' => 'SELECT %1$s.* %2$s FROM %1$s'), + + 'ListSortings' => Array( + '' => Array( + 'Sorting' => Array('Permission' => 'asc'), + ) + ), + 'Fields' => Array( + 'PermissionId' => Array(), + 'Permission' => Array('type' => 'string','not_null' => '1','default' => ''), + 'GroupId' => Array('type' => 'int','default' => '0'), + 'PermissionValue' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'Type' => Array('type' => 'int','not_null' => '1','default' => '0'), + 'CatId' => Array('type' => 'int','not_null' => '1','default' => '0'), + ), + ); + +?> \ No newline at end of file