Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Wed, Jun 18, 1:16 PM

in-portal

Index: branches/unlabeled/unlabeled-1.8.2/kernel/units/reviews/reviews_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.8.2/kernel/units/reviews/reviews_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.8.2/kernel/units/reviews/reviews_event_handler.php (revision 6796)
@@ -0,0 +1,188 @@
+<?php
+
+ class ReviewsEventHandler extends kDBEventHandler
+ {
+ /**
+ * Checks permissions of user
+ *
+ * @param kEvent $event
+ */
+ function CheckPermission(&$event)
+ {
+ if ($event->Name == 'OnAddReview') {
+ $item_prefix = $this->getPermPrefix($event);
+ $res = $this->Application->CheckPermission($item_prefix.'.REVIEW.PENDING', 0) || $this->Application->CheckPermission($item_prefix.'.REVIEW', 0);
+ if (!$res) {
+ $event->status = erPERM_FAIL;
+ }
+ return $res;
+ }
+
+ return parent::CheckPermission($event);
+ }
+
+ /**
+ * Returns prefix for permissions
+ *
+ * @param kEvent $event
+ */
+ function getPermPrefix(&$event)
+ {
+ $main_prefix = $this->Application->GetTopmostPrefix($event->Prefix);
+ // this will return LINK for l, ARTICLE for n, TOPIC for bb, PRODUCT for p
+ $item_prefix = $this->Application->getUnitOption($main_prefix, 'PermItemPrefix');
+
+ return $item_prefix;
+ }
+
+
+ /**
+ * Apply any custom changes to list's sql query
+ *
+ * @param kEvent $event
+ * @access protected
+ * @see OnListBuild
+ */
+ function SetCustomQuery(&$event)
+ {
+ $object =& $event->getObject();
+ switch ($event->Special)
+ {
+ case 'showall':
+ $object->clearFilters();
+ break;
+
+ case 'products':
+ $object->removeFilter('parent_filter'); // this is important
+ $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ // $object->addFilter('active', '%1$s.Status = 1');
+
+ /*$this->Application->setUnitOption('p', 'AutoLoad', true);
+ $product =& $this->Application->recallObject('p');
+ $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));*/
+ break;
+
+ case 'item':
+ $object->clearFilters();
+ $info = $object->getLinkedInfo();
+ $this->Application->setUnitOption($info['ParentPrefix'], 'AutoLoad', true);
+ $parent =& $this->Application->recallObject($info['ParentPrefix']);
+ $object->addFilter('item_reviews', '%1$s.ItemId = '.$parent->GetDBField('ResourceId'));
+ $object->addFilter('active', '%1$s.Status = 1');
+ break;
+
+ case 'product':
+ $object->clearFilters();
+ $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ $object->addFilter('active', '%1$s.Status = 1');
+ $this->Application->setUnitOption('p', 'AutoLoad', true);
+ $product =& $this->Application->recallObject('p');
+ $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));
+
+ break;
+ }
+
+ if($event->getEventParam('type') == 'current_user')
+ {
+ $user_id = $this->Application->GetVar('u_id') ? $this->Application->GetVar('u_id') : -2;
+ $ip = $_SERVER['REMOTE_ADDR'];
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $product_info = $object->getLinkedInfo();
+ $object->addFilter('current_item', '%1$s.ItemId = '.$product_info['ParentId']);
+ $object->addFilter('current_user', '%1$s.CreatedById = '.$user_id);
+ $object->addFilter('current_ip', '%1$s.IPAddress = "'.$ip.'"');
+
+ }
+ }
+
+ /**
+ * Adds review from front in case if user is logged in
+ *
+ * @param kEvent $event
+ */
+ function OnAddReview(&$event)
+ {
+ $user_id = ($this->Application->GetVar('u_id') == 0) ? -2 : $this->Application->GetVar('u_id');
+ $event->redirect_params = Array('pass' => 'all,p');
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $parent_info = $object->getLinkedInfo();
+ $review_fields = $this->Application->GetVar($event->getPrefixSpecial(true));
+
+ $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$parent_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $res = $this->Conn->GetRow($sql);
+
+ if( $res && $res['Expire'] < adodb_mktime() )
+ {
+ $sql = ' DELETE FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$parent_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $this->Conn->Query($sql);
+ unset($res);
+ }
+
+ if(!$res)
+ {
+ $object->SetFieldsFromHash( array_shift($review_fields) );
+ $object->SetDBField('CreatedById', $user_id);
+ $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
+ $object->SetDBField('CreatedOn', adodb_mktime());
+
+ $module_info = $this->Application->findModule('Var',$parent_info['ParentPrefix']);
+ $object->SetDBField('Module', $module_info['Name']);
+ if( $this->Application->CheckPermission( $this->getPermPrefix($event).'.REVIEW.PENDING', 0) )
+ {
+ $object->SetDBField('Status', 2);
+ $template_var = 'success_pending_template';
+ }
+ if( $this->Application->CheckPermission($this->getPermPrefix($event).'.REVIEW', 0) )
+ {
+ $object->SetDBField('Status', 1);
+ $template_var = 'success_template';
+ }
+
+ $object->SetDBField('ItemId', $parent_info['ParentId']);
+
+ $event->CallSubEvent('OnCreate');
+
+ if($event->status == erSUCCESS)
+ {
+ $parent =& $this->Application->recallObject($parent_info['ParentPrefix']);
+ $sql = ' SELECT COUNT(ReviewId)
+ FROM '.$object->TableName.'
+ WHERE ItemId='.$parent_info['ParentId'];
+ $review_qty = $this->Conn->GetOne($sql);
+ $parent->SetDBField('CachedReviewsQty', $review_qty);
+ $parent->Update();
+ $expire = adodb_mktime() + $this->Application->ConfigValue('product_ReviewDelay_Value') * $this->Application->ConfigValue('product_ReviewDelay_Interval');
+ $sql = ' INSERT INTO '.TABLE_PREFIX.'SpamControl
+ (ItemResourceId, IPaddress, PortalUserId, DataType, Expire)
+ VALUES ('.$parent_info['ParentId'].',
+ "'.$_SERVER['REMOTE_ADDR'].'",
+ '.$user_id.',
+ "Review",
+ '.$expire.')';
+ $this->Conn->Query($sql);
+
+ $event->redirect_params = Array('pass' => 'all,'.$parent_info['ParentPrefix']);
+ $event->redirect = $this->Application->GetVar($template_var);
+ }
+ }
+ else
+ {
+// $this->Application->removeObject($event->getPrefixSpecial());
+ $event->status == erFAIL;
+ $event->redirect=false;
+ $object->FieldErrors['ReviewText']['pseudo'] = 'too_frequent';
+ $object->ErrorMsgs['too_frequent'] = $this->Application->Phrase('lu_ferror_review_duplicate');
+ }
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.8.2/kernel/units/reviews/reviews_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.8
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.8.2/kernel/units/permissions/permissions_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.8.2/kernel/units/permissions/permissions_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.8.2/kernel/units/permissions/permissions_event_handler.php (revision 6796)
@@ -0,0 +1,207 @@
+<?php
+
+class PermissionsEventHandler extends kDBEventHandler {
+
+ /**
+ * Allows to override standart permission mapping
+ *
+ */
+ function mapPermissions()
+ {
+ parent::mapPermissions();
+ $permissions = Array(
+ 'OnGroupSavePermissions' => Array('subitem' => 'advanced:manage_permissions'),
+ );
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Save category permissions
+ *
+ * @param kEvent $event
+ */
+ function OnCategorySavePermissions(&$event)
+ {
+ $group_id = $this->Application->GetVar('current_group_id');
+ $category_id = $this->Application->GetVar('c_id');
+ $permissions = $this->Application->GetVar($event->getPrefixSpecial(true));
+ if (isset($permissions[$group_id])) {
+ $permissions = $permissions[$group_id];
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $permissions_helper =& $this->Application->recallObject('PermissionsHelper');
+ $permissions_helper->LoadPermissions($group_id, $category_id, 0);
+
+ // format: <perm_name>['inherited'] || <perm_name>['value']
+
+ $delete_ids = Array();
+ $create_sql = Array();
+ $update_sql = Array();
+ $create_mask = '(%s,%s,'.$group_id.',%s,0,'.$category_id.')';
+ $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 $perm_name => $perm_data) {
+ $inherited = $perm_data['inherited'];
+ $perm_value = isset($perm_data['value']) ? $perm_data['value'] : false;
+ $perm_id = $permissions_helper->getPermissionID($perm_name);
+
+ if ($inherited && ($perm_id != 0)) {
+ // permission become inherited (+ direct value was set before) => DELETE
+ $delete_ids[] = $permissions_helper->getPermissionID($perm_name);
+ }
+
+ if (!$inherited) {
+ // not inherited
+ if (($perm_id != 0) && ($perm_value != $permissions_helper->getPermissionValue($perm_name))) {
+ // record was found in db & new value differs from old one => UPDATE
+ $update_sql[] = ' UPDATE '.$object->TableName.'
+ SET PermissionValue = '.$perm_value.'
+ WHERE (PermissionId = '.$perm_id.')';
+ }
+
+ if ($perm_id == 0) {
+ // not found in db, but set directly => INSERT
+ $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
+ }
+
+ $this->UpdatePermissions($event, $create_sql, $update_sql, $delete_ids);
+ }
+
+ $event->MasterEvent->SetRedirectParam('item_prefix', $this->Application->GetVar('item_prefix'));
+ $event->MasterEvent->SetRedirectParam('group_id', $this->Application->GetVar('group_id'));
+ }
+
+ /**
+ * Saves permissions while editing group
+ *
+ * @param kEvent $event
+ */
+ function OnGroupSavePermissions(&$event)
+ {
+ if (!$this->Application->CheckPermission('in-portal:user_groups.advanced:manage_permissions', 1)) {
+ // no permission to save permissions
+ return false;
+ }
+
+ $permissions = $this->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($group_id, 0, 1);
+
+ $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
+ }
+ }
+
+ $this->UpdatePermissions($event, $create_sql, Array(), $delete_ids);
+
+ 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;
+ }
+
+ }
+
+ /**
+ * Apply modification sqls to permissions table
+ *
+ * @param kEvent $event
+ * @param Array $create_sql
+ * @param Array $update_sql
+ * @param Array $delete_ids
+ */
+ function UpdatePermissions(&$event, $create_sql, $update_sql, $delete_ids)
+ {
+ $object =& $event->getObject();
+
+ 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 ($update_sql) {
+ foreach ($update_sql as $sql) {
+ $this->Conn->Query($sql);
+ }
+ }
+
+ if ($delete_ids || $create_sql || $update_sql) {
+ $object->setModifiedFlag();
+
+ if ($event->Name == 'OnCategorySavePermissions') {
+ $this->Application->StoreVar('PermCache_UpdateRequired', 1);
+ }
+ }
+ }
+
+ /**
+ * Don't delete permissions from live table in case of new category creation.
+ * Called as much times as permission count for categories set, so don't
+ * perform any sql queries here!
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeDeleteFromLive(&$event)
+ {
+ if ($event->Prefix == 'c-perm') {
+ // only when saving category permissions, not group permissions
+ $foreign_keys = $event->getEventParam('foreign_key');
+
+ if ((count($foreign_keys) == 1) && ($foreign_keys[0] == 0)) {
+ // parent item has zero id
+ $temp_object =& $this->Application->recallObject('c');
+ if ($temp_object->isLoaded()) {
+ // category with id = 0 found in temp table
+ $event->status = erFAIL;
+ }
+ }
+ }
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.8.2/kernel/units/permissions/permissions_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.8
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.8.2/core/units/reviews/reviews_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.8.2/core/units/reviews/reviews_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.8.2/core/units/reviews/reviews_event_handler.php (revision 6796)
@@ -0,0 +1,188 @@
+<?php
+
+ class ReviewsEventHandler extends kDBEventHandler
+ {
+ /**
+ * Checks permissions of user
+ *
+ * @param kEvent $event
+ */
+ function CheckPermission(&$event)
+ {
+ if ($event->Name == 'OnAddReview') {
+ $item_prefix = $this->getPermPrefix($event);
+ $res = $this->Application->CheckPermission($item_prefix.'.REVIEW.PENDING', 0) || $this->Application->CheckPermission($item_prefix.'.REVIEW', 0);
+ if (!$res) {
+ $event->status = erPERM_FAIL;
+ }
+ return $res;
+ }
+
+ return parent::CheckPermission($event);
+ }
+
+ /**
+ * Returns prefix for permissions
+ *
+ * @param kEvent $event
+ */
+ function getPermPrefix(&$event)
+ {
+ $main_prefix = $this->Application->GetTopmostPrefix($event->Prefix);
+ // this will return LINK for l, ARTICLE for n, TOPIC for bb, PRODUCT for p
+ $item_prefix = $this->Application->getUnitOption($main_prefix, 'PermItemPrefix');
+
+ return $item_prefix;
+ }
+
+
+ /**
+ * Apply any custom changes to list's sql query
+ *
+ * @param kEvent $event
+ * @access protected
+ * @see OnListBuild
+ */
+ function SetCustomQuery(&$event)
+ {
+ $object =& $event->getObject();
+ switch ($event->Special)
+ {
+ case 'showall':
+ $object->clearFilters();
+ break;
+
+ case 'products':
+ $object->removeFilter('parent_filter'); // this is important
+ $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ // $object->addFilter('active', '%1$s.Status = 1');
+
+ /*$this->Application->setUnitOption('p', 'AutoLoad', true);
+ $product =& $this->Application->recallObject('p');
+ $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));*/
+ break;
+
+ case 'item':
+ $object->clearFilters();
+ $info = $object->getLinkedInfo();
+ $this->Application->setUnitOption($info['ParentPrefix'], 'AutoLoad', true);
+ $parent =& $this->Application->recallObject($info['ParentPrefix']);
+ $object->addFilter('item_reviews', '%1$s.ItemId = '.$parent->GetDBField('ResourceId'));
+ $object->addFilter('active', '%1$s.Status = 1');
+ break;
+
+ case 'product':
+ $object->clearFilters();
+ $object->addFilter('product_reviews', '%1$s.ItemId = pr.ResourceId');
+ $object->addFilter('active', '%1$s.Status = 1');
+ $this->Application->setUnitOption('p', 'AutoLoad', true);
+ $product =& $this->Application->recallObject('p');
+ $object->addFilter('current_product', 'pr.ResourceId = '.$product->GetDBField('ResourceId'));
+
+ break;
+ }
+
+ if($event->getEventParam('type') == 'current_user')
+ {
+ $user_id = $this->Application->GetVar('u_id') ? $this->Application->GetVar('u_id') : -2;
+ $ip = $_SERVER['REMOTE_ADDR'];
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $product_info = $object->getLinkedInfo();
+ $object->addFilter('current_item', '%1$s.ItemId = '.$product_info['ParentId']);
+ $object->addFilter('current_user', '%1$s.CreatedById = '.$user_id);
+ $object->addFilter('current_ip', '%1$s.IPAddress = "'.$ip.'"');
+
+ }
+ }
+
+ /**
+ * Adds review from front in case if user is logged in
+ *
+ * @param kEvent $event
+ */
+ function OnAddReview(&$event)
+ {
+ $user_id = ($this->Application->GetVar('u_id') == 0) ? -2 : $this->Application->GetVar('u_id');
+ $event->redirect_params = Array('pass' => 'all,p');
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $parent_info = $object->getLinkedInfo();
+ $review_fields = $this->Application->GetVar($event->getPrefixSpecial(true));
+
+ $sql = ' SELECT * FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$parent_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $res = $this->Conn->GetRow($sql);
+
+ if( $res && $res['Expire'] < adodb_mktime() )
+ {
+ $sql = ' DELETE FROM '.TABLE_PREFIX.'SpamControl
+ WHERE ItemResourceId='.$parent_info['ParentId'].'
+ AND IPaddress="'.$_SERVER['REMOTE_ADDR'].'"
+ AND PortalUserId='.$user_id.'
+ AND DataType="Review"';
+ $this->Conn->Query($sql);
+ unset($res);
+ }
+
+ if(!$res)
+ {
+ $object->SetFieldsFromHash( array_shift($review_fields) );
+ $object->SetDBField('CreatedById', $user_id);
+ $object->SetDBField('IPAddress', $_SERVER['REMOTE_ADDR']);
+ $object->SetDBField('CreatedOn', adodb_mktime());
+
+ $module_info = $this->Application->findModule('Var',$parent_info['ParentPrefix']);
+ $object->SetDBField('Module', $module_info['Name']);
+ if( $this->Application->CheckPermission( $this->getPermPrefix($event).'.REVIEW.PENDING', 0) )
+ {
+ $object->SetDBField('Status', 2);
+ $template_var = 'success_pending_template';
+ }
+ if( $this->Application->CheckPermission($this->getPermPrefix($event).'.REVIEW', 0) )
+ {
+ $object->SetDBField('Status', 1);
+ $template_var = 'success_template';
+ }
+
+ $object->SetDBField('ItemId', $parent_info['ParentId']);
+
+ $event->CallSubEvent('OnCreate');
+
+ if($event->status == erSUCCESS)
+ {
+ $parent =& $this->Application->recallObject($parent_info['ParentPrefix']);
+ $sql = ' SELECT COUNT(ReviewId)
+ FROM '.$object->TableName.'
+ WHERE ItemId='.$parent_info['ParentId'];
+ $review_qty = $this->Conn->GetOne($sql);
+ $parent->SetDBField('CachedReviewsQty', $review_qty);
+ $parent->Update();
+ $expire = adodb_mktime() + $this->Application->ConfigValue('product_ReviewDelay_Value') * $this->Application->ConfigValue('product_ReviewDelay_Interval');
+ $sql = ' INSERT INTO '.TABLE_PREFIX.'SpamControl
+ (ItemResourceId, IPaddress, PortalUserId, DataType, Expire)
+ VALUES ('.$parent_info['ParentId'].',
+ "'.$_SERVER['REMOTE_ADDR'].'",
+ '.$user_id.',
+ "Review",
+ '.$expire.')';
+ $this->Conn->Query($sql);
+
+ $event->redirect_params = Array('pass' => 'all,'.$parent_info['ParentPrefix']);
+ $event->redirect = $this->Application->GetVar($template_var);
+ }
+ }
+ else
+ {
+// $this->Application->removeObject($event->getPrefixSpecial());
+ $event->status == erFAIL;
+ $event->redirect=false;
+ $object->FieldErrors['ReviewText']['pseudo'] = 'too_frequent';
+ $object->ErrorMsgs['too_frequent'] = $this->Application->Phrase('lu_ferror_review_duplicate');
+ }
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.8.2/core/units/reviews/reviews_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.8
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.8.2/core/units/categories/cache_updater.php
===================================================================
--- branches/unlabeled/unlabeled-1.8.2/core/units/categories/cache_updater.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.8.2/core/units/categories/cache_updater.php (revision 6796)
@@ -0,0 +1,372 @@
+<?php
+class clsRecursionStack
+{
+ var $Stack;
+
+ function clsRecursionStack()
+ {
+ $this->Stack = Array();
+ }
+
+ function Push($values)
+ {
+ array_push($this->Stack, $values);
+ }
+
+ function Pop()
+ {
+ if ($this->Count() > 0) {
+ return array_pop($this->Stack);
+ }
+ else {
+ return false;
+ }
+ }
+
+ function Get()
+ {
+ if ($this->Count() > 0) {
+// return end($this->Stack);
+ return $this->Stack[count($this->Stack)-1];
+ }
+ else {
+ return false;
+ }
+ }
+
+ function Update($values)
+ {
+ $this->Stack[count($this->Stack)-1] = $values;
+ }
+
+ function Count()
+ {
+ return count($this->Stack);
+ }
+}
+
+
+class clsCachedPermissions
+{
+ var $Allow = Array();
+ var $Deny = Array();
+ var $CatId;
+
+ function clsCachedPermissions($CatId)
+ {
+ $this->CatId = $CatId;
+ }
+
+ function SetCatId($CatId)
+ {
+ $this->CatId = $CatId;
+ }
+
+ function CheckPermArray($Perm)
+ {
+ if (!isset($this->Allow[$Perm])) {
+ $this->Allow[$Perm] = array();
+ $this->Deny[$Perm] = array();
+ }
+ }
+
+ function AddAllow($Perm, $GroupId)
+ {
+ $this->CheckPermArray($Perm);
+ if (!in_array($GroupId, $this->Allow[$Perm])) {
+ array_push($this->Allow[$Perm], $GroupId);
+ $this->RemoveDeny($Perm, $GroupId);
+ }
+ }
+
+ function AddDeny($Perm, $GroupId)
+ {
+ $this->CheckPermArray($Perm);
+ if (!in_array($GroupId, $this->Deny[$Perm])) {
+ array_push($this->Deny[$Perm], $GroupId);
+ $this->RemoveAllow($Perm, $GroupId);
+ }
+ }
+
+ function RemoveDeny($Perm, $GroupId)
+ {
+ if (in_array($GroupId, $this->Deny[$Perm])) {
+ array_splice($this->Deny[$Perm], array_search($GroupId, $this->Deny[$Perm]), 1);
+ }
+ }
+
+ function RemoveAllow($Perm, $GroupId)
+ {
+ if (in_array($GroupId, $this->Allow[$Perm])) {
+ array_splice($this->Allow[$Perm], array_search($GroupId, $this->Allow[$Perm]), 1);
+ }
+ }
+
+ function GetInsertSQL()
+ {
+ $values = array();
+
+ $has_deny = array();
+
+ // don't write DACL at all
+ /*foreach ($this->Deny as $perm => $groups) {
+ if (count($groups) > 0) {
+ $values[] = '('.$this->CatId.', '.$perm.', "", "'.join(',', $groups).'")';
+ $has_deny[] = $perm;
+ }
+ }*/
+
+ foreach ($this->Allow as $perm => $groups) {
+// if (in_array($perm, $has_deny)) continue;
+ if (count($groups) > 0) {
+ $values[] = '(' .$this->CatId. ', ' .$perm. ', "' .join(',', $groups). '", "")';
+ }
+ }
+ if (!$values) return '';
+ $sql = 'INSERT INTO '.TABLE_PREFIX.'PermCache (CategoryId, PermId, ACL, DACL) VALUES '.join(',', $values);
+ return $sql;
+ }
+}
+
+class kPermCacheUpdater extends kHelper
+{
+ var $Stack;
+ var $iteration;
+ var $totalCats;
+ var $doneCats;
+ var $table;
+
+ var $primaryLanguageId = 0;
+ var $languageCount = 0;
+ var $root_prefixes = Array();
+
+ function Init($prefix, $special, $event_params = null)
+ {
+ parent::Init($prefix, $special, $event_params);
+
+ $continuing = $event_params['continue'];
+
+ // cache widely used values to speed up process: begin
+ $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper');
+ $this->languageCount = $ml_helper->getLanguageCount();
+ $this->primaryLanguageId = $this->Application->GetDefaultLanguageId();
+ // cache widely used values to speed up process: end
+
+ foreach ($this->Application->ModuleInfo as $module_name => $module_info) {
+ $this->root_prefixes[ $module_info['RootCat'] ] = $module_info['Var'];
+ }
+
+ $this->iteration = 0;
+ $this->table = $this->Application->GetTempName('permCacheUpdate');
+
+ if ($continuing == 1) {
+ $this->InitUpdater();
+ }
+ elseif ($continuing == 2) {
+ $this->getData();
+ }
+ }
+
+ function InitUpdater()
+ {
+ $this->Stack =& new clsRecursionStack();
+ $sql = 'DELETE FROM '.TABLE_PREFIX.'PermCache';
+ $this->Conn->Query($sql);
+ $this->initData();
+ }
+
+ function getDonePercent()
+ {
+ if(!$this->totalCats)return 0;
+ return min(100, intval( round( $this->doneCats / $this->totalCats * 100 ) ));
+ }
+
+ function getData()
+ {
+ $tmp = $this->Conn->GetOne('SELECT data FROM '.$this->table);
+ if ($tmp) $tmp = unserialize($tmp);
+
+ $this->totalCats = isset($tmp['totalCats']) ? $tmp['totalCats'] : 0;
+ $this->doneCats = isset($tmp['doneCats']) ? $tmp['doneCats'] : 0;
+ if (isset($tmp['stack'])) {
+ $this->Stack = $tmp['stack'];
+ }
+ else {
+ $this->Stack = & new clsRecursionStack();
+ }
+ }
+
+ function setData()
+ {
+ $tmp = Array (
+ 'totalCats' => $this->totalCats,
+ 'doneCats' => $this->doneCats,
+ 'stack' => $this->Stack,
+ );
+
+ $this->Conn->Query('DELETE FROM '.$this->table);
+
+ $fields_hash = Array('data' => serialize($tmp));
+ $this->Conn->doInsert($fields_hash, $this->table);
+ }
+
+ function initData()
+ {
+ $this->clearData(); // drop table before starting anyway
+
+ $this->Conn->Query('CREATE TABLE '.$this->table.'(data LONGTEXT)');
+
+ $this->totalCats = (int)$this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'Category');
+ $this->doneCats = 0;
+ }
+
+ function clearData()
+ {
+ $this->Conn->Query('DROP TABLE IF EXISTS '.$this->table);
+ $this->Conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = \'ForcePermCacheUpdate\'');
+ }
+
+ function DoTheJob()
+ {
+ $data = $this->Stack->Get();
+ if ($data === false) { //If Stack is empty
+ $data['current_id'] = 0;
+ $data['titles'] = Array();
+ $data['parent_path'] = Array();
+ $data['named_path'] = Array();
+ $data['category_template'] = '';
+ $data['item_template'] = '';
+ $this->Stack->Push($data);
+ }
+
+ if (!isset($data['queried'])) {
+ $this->QueryTitle($data);
+ $this->QueryChildren($data);
+ $this->QueryPermissions($data);
+ $data['queried'] = 1;
+
+ if ($sql = $data['perms']->GetInsertSQL()) {
+ $this->Conn->Query($sql);
+ // $this->doneCats++; // moved to the place where it pops out of the stack by Kostja
+ }
+ $this->iteration++;
+ }
+
+ // start with first child if we haven't started yet
+ if (!isset($data['current_child'])) $data['current_child'] = 0;
+
+ // if we have more children
+ if (isset($data['children'][$data['current_child']])) {
+ $next_data = Array();
+ $next_data['titles'] = $data['titles'];
+ $next_data['parent_path'] = $data['parent_path'];
+ $next_data['named_path'] = $data['named_path'];
+ $next_data['category_template'] = $data['category_template'];
+ $next_data['item_template'] = $data['item_template'];
+ $next_data['current_id'] = $data['children'][ $data['current_child'] ]; //next iteration should process child
+ $next_data['perms'] = $data['perms']; //we should copy our permissions to child - inheritance
+ $next_data['perms']->SetCatId($next_data['current_id']);
+ $data['current_child']++;
+ $this->Stack->Update($data); //we need to update ourself for the iteration after the next (or further) return to next child
+ $this->Stack->Push($next_data); //next iteration should process this child
+ return true;
+ }
+ else {
+ $this->UpdateCachedPath($data);
+ $this->Stack->Pop(); //remove ourself from stack if we have finished all the childs (or there are none)
+ // we are getting here if we finished with current level, so check if it's first level - then bail out.
+
+ $this->doneCats++; // moved by Kostja from above, seems to fix the prob
+ return $this->Stack->Count() > 0;
+ }
+ }
+
+ function UpdateCachedPath(&$data)
+ {
+ $fields_hash = Array (
+ 'ParentPath' => '|'.implode('|', $data['parent_path']).'|',
+ 'NamedParentPath' => implode('/', $data['named_path'] ),
+ 'CachedCategoryTemplate' => $data['category_template'],
+ );
+
+ $i = 1;
+ while ($i <= $this->languageCount) {
+ $fields_hash['l'.$i.'_CachedNavbar'] = implode('&|&', $data['titles'][$i]);
+ $i++;
+ }
+
+ $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$data['current_id']);
+ }
+
+ function QueryTitle(&$data)
+ {
+ $category_id = $data['current_id'];
+ $sql = 'SELECT *
+ FROM '.TABLE_PREFIX.'Category
+ WHERE CategoryId = '.$category_id;
+
+ $record = $this->Conn->GetRow($sql);
+ if ($record) {
+ $i = 1;
+ while ($i <= $this->languageCount) {
+ $data['titles'][$i][] = $record['l'.$i.'_Name'] ? $record['l'.$i.'_Name'] : $record['l'.$this->primaryLanguageId.'_Name'];
+ $i++;
+ }
+
+ $data['parent_path'][] = $category_id;
+ $data['named_path'][] = $record['Filename'];
+
+ // it is one of the modules root category
+ $root_prefix = isset($this->root_prefixes[$category_id]) ? $this->root_prefixes[$category_id] : false;
+ if ($root_prefix) {
+ $fields_hash = Array();
+ if (!$record['CategoryTemplate']) {
+ $record['CategoryTemplate'] = $this->Application->ConfigValue($root_prefix.'_CategoryTemplate');
+ $fields_hash['CategoryTemplate'] = $record['CategoryTemplate'];
+ }
+
+ $this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'Category', 'CategoryId = '.$category_id);
+ }
+
+ // if explicitly set, then use it; use parent template otherwise
+ if ($record['CategoryTemplate']) {
+ $data['category_template'] = $record['CategoryTemplate'];
+ }
+ }
+
+ }
+
+ function QueryChildren(&$data)
+ {
+ $sql = 'SELECT CategoryId
+ FROM '.TABLE_PREFIX.'Category
+ WHERE ParentId = '.$data['current_id'];
+ $data['children'] = $this->Conn->GetCol($sql);
+ }
+
+ function QueryPermissions(&$data)
+ {
+ // don't search for section "view" permissions here :)
+ $sql = 'SELECT ipc.PermissionConfigId, ip.GroupId, ip.PermissionValue
+ FROM '.TABLE_PREFIX.'Permissions AS ip
+ LEFT JOIN '.TABLE_PREFIX.'PermissionConfig AS ipc ON ipc.PermissionName = ip.Permission
+ WHERE (CatId = '.$data['current_id'].') AND (Permission LIKE "%.VIEW") AND (ip.Type = 0)';
+
+ $records = $this->Conn->Query($sql);
+
+ //create permissions array only if we don't have it yet (set by parent)
+ if (!isset($data['perms'])) {
+ $data['perms'] = new clsCachedPermissions($data['current_id']);
+ }
+
+ foreach ($records as $record) {
+ if ($record['PermissionValue'] == 1) {
+ $data['perms']->AddAllow($record['PermissionConfigId'], $record['GroupId']);
+ }
+ else {
+ $data['perms']->AddDeny($record['PermissionConfigId'], $record['GroupId']);
+ }
+ }
+ }
+}
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.8.2/core/units/categories/cache_updater.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.8
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.8.2/core/units/themes/themes_config.php
===================================================================
--- branches/unlabeled/unlabeled-1.8.2/core/units/themes/themes_config.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.8.2/core/units/themes/themes_config.php (revision 6796)
@@ -0,0 +1,92 @@
+<?php
+
+$config = Array(
+ 'Prefix' => 'theme',
+ 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
+ 'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
+ 'EventHandlerClass' => Array('class'=>'kDBEventHandler','file'=>'','build_event'=>'OnBuild'),
+ 'TagProcessorClass' => Array('class'=>'ThemesTagProcessor','file'=>'themes_tag_processor.php','build_event'=>'OnBuild'),
+ 'AutoLoad' => true,
+ 'Hooks' => Array(),
+ 'QueryString' => Array(
+ 1 => 'id',
+ 2 => 'page',
+ 3 => 'event',
+ 4 => 'mode',
+ ),
+ 'IDField' => 'ThemeId',
+
+ 'StatusField' => Array('Enabled','Primary'),
+
+ 'TitleField' => 'Name',
+
+ 'TableName' => TABLE_PREFIX.'Theme',
+ 'SubItems' => Array('themefiles'),
+
+/*
+ 'Sections' => Array(
+ 'in-portal:configure_themes' => Array(
+ 'parent' => 'in-portal:system',
+ 'icon' => 'in-portal:conf_themes',
+ 'label' => 'la_tab_Themes',
+ 'url' => Array('index_file' => 'config/config_theme.php', 'pass' => 'm'),
+ 'permissions' => Array('view', 'add', 'edit', 'delete'),
+ 'priority' => 3,
+ 'type' => stTREE,
+ ),
+
+ ),*/
+
+ 'FilterMenu' => Array(
+ 'Groups' => Array(
+ Array('mode' => 'AND', 'filters' => Array(0,1), 'type' => WHERE_FILTER),
+ ),
+
+ 'Filters' => Array(
+ 0 => Array('label' =>'la_Enabled', 'on_sql' => '', 'off_sql' => '%1$s.Enabled != 1' ),
+ 1 => Array('label' => 'la_Disabled', 'on_sql' => '', 'off_sql' => '%1$s.Enabled != 0' ),
+ )
+ ),
+
+ 'AutoDelete' => true,
+ 'AutoClone' => true,
+
+ 'ListSQLs' => Array( ''=>'SELECT * FROM %s',
+ ), // key - special, value - list select sql
+ 'ItemSQLs' => Array( ''=>' SELECT %1$s.*, style.LastCompiled, style.Name AS StyleName
+ FROM %s
+ LEFT JOIN '.TABLE_PREFIX.'Stylesheets style ON style.StylesheetId = %1$s.StylesheetId',
+ ),
+ 'ListSortings' => Array(
+ '' => Array(
+ 'Sorting' => Array('Name' => 'asc'),
+ )
+ ),
+ 'Fields' => Array(
+ 'ThemeId' => Array(),
+ 'Name' => Array('type' => 'string','not_null' => '1','default' => ''),
+ 'Enabled' => Array('type' => 'int', 'formatter' => 'kOptionsFormatter', 'options' => Array(1=>'la_Enabled', 0=>'la_Disabled'), 'use_phrases'=>1, 'not_null' => '1','default' => '1'),
+ 'Description' => Array('type' => 'string','default' => ''),
+ 'PrimaryTheme' => Array('type' => 'int','not_null' => '1','default' => '0'),
+ 'CacheTimeout' => Array('type' => 'int','not_null' => '1','default' => '0'),
+ 'StylesheetId' => Array('type' => 'int','not_null' => '1','default' => '0'),
+ ),
+
+ 'VirtualFields' => Array(
+ 'LastCompiled' => Array('type'=>'int', 'formatter'=>'kDateFormatter' ),
+ ),
+
+ 'Grids' => Array(
+ 'Default' => Array(
+ 'Icons' => Array('default'=>'icon16_custom.gif',0=>'icon16_style_disabled.gif',1=>'icon16_style.gif'),
+ 'Fields' => Array(
+ 'Name' => Array( 'title'=>'la_col_Name', 'data_block' => 'grid_checkbox_td'),
+ 'Description' => Array( 'title'=>'la_col_Description', 'data_block' => 'grid_description_td' ),
+ 'Enabled' => Array( 'title'=>'la_col_Status' ),
+ ),
+
+ ),
+ ),
+ );
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.8.2/core/units/themes/themes_config.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.8
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.8.2/core/units/languages/languages_item.php
===================================================================
--- branches/unlabeled/unlabeled-1.8.2/core/units/languages/languages_item.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.8.2/core/units/languages/languages_item.php (revision 6796)
@@ -0,0 +1,74 @@
+<?php
+
+ class LanguagesItem extends kDBItem
+ {
+ function generateID()
+ {
+ $sql = 'SELECT MAX('.$this->IDField.') FROM '.$this->Application->GetLiveName($this->TableName);
+ return $this->Conn->GetOne($sql) + 1;
+ }
+
+ function setPrimary($reset_primary = true)
+ {
+ if ($reset_primary) {
+ $sql = 'UPDATE '.$this->TableName.'
+ SET PrimaryLang = 0';
+ $this->Conn->Query($sql);
+ }
+
+ $sql = 'UPDATE '.$this->TableName.'
+ SET PrimaryLang = 1, Enabled = 1
+ WHERE '.$this->IDField.' = '.$this->GetID();
+ $this->Conn->Query($sql);
+ }
+
+ /**
+ * Allows to format number according to regional settings
+ *
+ * @param float $number
+ * @param int $precision
+ * @return float
+ */
+ function formatNumber($number, $precision = null)
+ {
+ if (is_null($precision)) {
+ $precision = preg_match('/[\.,]+/', $number) ? strlen(preg_replace('/^.*[\.,]+/', '', $number)) : 0;
+ }
+ return number_format($number, $precision, $this->GetDBField('DecimalPoint'), $this->GetDBField('ThousandSep'));
+ }
+
+ function Load($id, $id_field_name=null)
+ {
+ $default = false;
+ if ($id == 'default') {
+ $id = 1;
+ $id_field_name = 'PrimaryLang';
+ $default = true;
+ }
+
+ $res = parent::Load($id, $id_field_name);
+
+ if ($default) {
+ if (!$res) {
+ if ($this->Application->IsAdmin()) {
+ $res = parent::Load(1);
+ }
+ else {
+ if (defined('IS_INSTALL')) {
+ // during first language import prevents sql errors
+ $this->setID(1);
+ $res = true;
+ }
+ else {
+ $this->Application->ApplicationDie('No Primary Language Selected');
+ }
+ }
+ }
+ $this->Application->SetVar('lang.current_id', $this->GetID() );
+ $this->Application->SetVar('m_lang', $this->GetID() );
+ }
+ return $res;
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.8.2/core/units/languages/languages_item.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.8
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.8.2/core/units/permissions/permissions_event_handler.php
===================================================================
--- branches/unlabeled/unlabeled-1.8.2/core/units/permissions/permissions_event_handler.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.8.2/core/units/permissions/permissions_event_handler.php (revision 6796)
@@ -0,0 +1,207 @@
+<?php
+
+class PermissionsEventHandler extends kDBEventHandler {
+
+ /**
+ * Allows to override standart permission mapping
+ *
+ */
+ function mapPermissions()
+ {
+ parent::mapPermissions();
+ $permissions = Array(
+ 'OnGroupSavePermissions' => Array('subitem' => 'advanced:manage_permissions'),
+ );
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Save category permissions
+ *
+ * @param kEvent $event
+ */
+ function OnCategorySavePermissions(&$event)
+ {
+ $group_id = $this->Application->GetVar('current_group_id');
+ $category_id = $this->Application->GetVar('c_id');
+ $permissions = $this->Application->GetVar($event->getPrefixSpecial(true));
+ if (isset($permissions[$group_id])) {
+ $permissions = $permissions[$group_id];
+
+ $object =& $event->getObject( Array('skip_autoload' => true) );
+ $permissions_helper =& $this->Application->recallObject('PermissionsHelper');
+ $permissions_helper->LoadPermissions($group_id, $category_id, 0);
+
+ // format: <perm_name>['inherited'] || <perm_name>['value']
+
+ $delete_ids = Array();
+ $create_sql = Array();
+ $update_sql = Array();
+ $create_mask = '(%s,%s,'.$group_id.',%s,0,'.$category_id.')';
+ $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 $perm_name => $perm_data) {
+ $inherited = $perm_data['inherited'];
+ $perm_value = isset($perm_data['value']) ? $perm_data['value'] : false;
+ $perm_id = $permissions_helper->getPermissionID($perm_name);
+
+ if ($inherited && ($perm_id != 0)) {
+ // permission become inherited (+ direct value was set before) => DELETE
+ $delete_ids[] = $permissions_helper->getPermissionID($perm_name);
+ }
+
+ if (!$inherited) {
+ // not inherited
+ if (($perm_id != 0) && ($perm_value != $permissions_helper->getPermissionValue($perm_name))) {
+ // record was found in db & new value differs from old one => UPDATE
+ $update_sql[] = ' UPDATE '.$object->TableName.'
+ SET PermissionValue = '.$perm_value.'
+ WHERE (PermissionId = '.$perm_id.')';
+ }
+
+ if ($perm_id == 0) {
+ // not found in db, but set directly => INSERT
+ $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
+ }
+
+ $this->UpdatePermissions($event, $create_sql, $update_sql, $delete_ids);
+ }
+
+ $event->MasterEvent->SetRedirectParam('item_prefix', $this->Application->GetVar('item_prefix'));
+ $event->MasterEvent->SetRedirectParam('group_id', $this->Application->GetVar('group_id'));
+ }
+
+ /**
+ * Saves permissions while editing group
+ *
+ * @param kEvent $event
+ */
+ function OnGroupSavePermissions(&$event)
+ {
+ if (!$this->Application->CheckPermission('in-portal:user_groups.advanced:manage_permissions', 1)) {
+ // no permission to save permissions
+ return false;
+ }
+
+ $permissions = $this->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($group_id, 0, 1);
+
+ $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
+ }
+ }
+
+ $this->UpdatePermissions($event, $create_sql, Array(), $delete_ids);
+
+ 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;
+ }
+
+ }
+
+ /**
+ * Apply modification sqls to permissions table
+ *
+ * @param kEvent $event
+ * @param Array $create_sql
+ * @param Array $update_sql
+ * @param Array $delete_ids
+ */
+ function UpdatePermissions(&$event, $create_sql, $update_sql, $delete_ids)
+ {
+ $object =& $event->getObject();
+
+ 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 ($update_sql) {
+ foreach ($update_sql as $sql) {
+ $this->Conn->Query($sql);
+ }
+ }
+
+ if ($delete_ids || $create_sql || $update_sql) {
+ $object->setModifiedFlag();
+
+ if ($event->Name == 'OnCategorySavePermissions') {
+ $this->Application->StoreVar('PermCache_UpdateRequired', 1);
+ }
+ }
+ }
+
+ /**
+ * Don't delete permissions from live table in case of new category creation.
+ * Called as much times as permission count for categories set, so don't
+ * perform any sql queries here!
+ *
+ * @param kEvent $event
+ */
+ function OnBeforeDeleteFromLive(&$event)
+ {
+ if ($event->Prefix == 'c-perm') {
+ // only when saving category permissions, not group permissions
+ $foreign_keys = $event->getEventParam('foreign_key');
+
+ if ((count($foreign_keys) == 1) && ($foreign_keys[0] == 0)) {
+ // parent item has zero id
+ $temp_object =& $this->Application->recallObject('c');
+ if ($temp_object->isLoaded()) {
+ // category with id = 0 found in temp table
+ $event->status = erFAIL;
+ }
+ }
+ }
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.8.2/core/units/permissions/permissions_event_handler.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.8
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline