Index: branches/unlabeled/unlabeled-1.64.2/kernel/units/general/cat_event_handler.php =================================================================== diff -u -r5862 -r5868 --- branches/unlabeled/unlabeled-1.64.2/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5862) +++ branches/unlabeled/unlabeled-1.64.2/kernel/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5868) @@ -65,7 +65,6 @@ $perm_value = true; $perm_helper =& $this->Application->recallObject('PermissionsHelper'); foreach ($items as $item_id => $item_data) { - if ($perm_helper->ModifyCheckPermission($item_data['CreatedById'], $item_data['CategoryId'], $event->Prefix) == 0) { // one of items selected has no permission $perm_value = false; @@ -315,7 +314,18 @@ } // add permission filter - $view_perm = 1; + if ($this->Application->GetVar('u_id') == -1) { + // for "root" CATEGORY.VIEW permission is checked for items lists too + $view_perm = 1; + } + else { + // for any real user itemlist view permission is checked instead of CATEGORY.VIEW + $sql = 'SELECT PermissionConfigId + FROM '.TABLE_PREFIX.'PermissionConfig + WHERE PermissionName = "'.$this->Application->getUnitOption($event->Prefix, 'PermItemPrefix').'.VIEW"'; + $view_perm = $this->Conn->GetOne($sql); + } + $object->addFilter('perm_filter', 'perm.PermId = '.$view_perm); if ( !$this->Application->IsAdmin() ) @@ -1738,22 +1748,38 @@ // 1. clone original item $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array($object->GetID()), null, null, null, true); + $ci_table = $this->Application->GetTempName(TABLE_PREFIX.'CategoryItems'); - // 1.1. clone category items here too + // 2. delete record from CategoryItems (about cloned item) that was automatically created during call of Create method of kCatDBItem + $sql = 'SELECT ResourceId + FROM '.$object->TableName.' + WHERE '.$object->IDField.' = '.$cloned_ids[0]; + $clone_resource_id = $this->Conn->GetOne($sql); - // 2. put cloned id to OrgId field of item being cloned + $sql = 'DELETE FROM '.$ci_table.' + WHERE ItemResourceId = '.$clone_resource_id.' AND PrimaryCat = 1'; + $this->Conn->Query($sql); + + // 3. copy main item categoryitems to cloned item + $sql = ' INSERT INTO '.$ci_table.' (CategoryId, ItemResourceId, PrimaryCat, ItemPrefix, Filename) + SELECT CategoryId, '.$clone_resource_id.' AS ItemResourceId, PrimaryCat, ItemPrefix, Filename + FROM '.$ci_table.' + WHERE ItemResourceId = '.$object->GetDBField('ResourceId'); + $this->Conn->Query($sql); + + // 4. put cloned id to OrgId field of item being cloned $sql = 'UPDATE '.$object->TableName.' SET OrgId = '.$object->GetID().' WHERE '.$object->IDField.' = '.$cloned_ids[0]; $this->Conn->Query($sql); - // 3. substitute id of item being cloned with clone id + // 5. substitute id of item being cloned with clone id $this->Application->SetVar($event->getPrefixSpecial().'_id', $cloned_ids[0]); $selected_ids = explode(',', $this->Application->RecallVar($event->getPrefixSpecial().'_selected_ids')); $selected_ids[ array_search($object->GetID(), $selected_ids) ] = $cloned_ids[0]; $this->Application->StoreVar($event->getPrefixSpecial().'_selected_ids', implode(',', $selected_ids)); - // 4. delete original item from temp table + // 6. delete original item from temp table $temp_handler->DeleteItems($event->Prefix, $event->Special, Array($object->GetID())); } } Index: branches/unlabeled/unlabeled-1.64.2/core/units/general/cat_event_handler.php =================================================================== diff -u -r5862 -r5868 --- branches/unlabeled/unlabeled-1.64.2/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5862) +++ branches/unlabeled/unlabeled-1.64.2/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 5868) @@ -65,7 +65,6 @@ $perm_value = true; $perm_helper =& $this->Application->recallObject('PermissionsHelper'); foreach ($items as $item_id => $item_data) { - if ($perm_helper->ModifyCheckPermission($item_data['CreatedById'], $item_data['CategoryId'], $event->Prefix) == 0) { // one of items selected has no permission $perm_value = false; @@ -315,7 +314,18 @@ } // add permission filter - $view_perm = 1; + if ($this->Application->GetVar('u_id') == -1) { + // for "root" CATEGORY.VIEW permission is checked for items lists too + $view_perm = 1; + } + else { + // for any real user itemlist view permission is checked instead of CATEGORY.VIEW + $sql = 'SELECT PermissionConfigId + FROM '.TABLE_PREFIX.'PermissionConfig + WHERE PermissionName = "'.$this->Application->getUnitOption($event->Prefix, 'PermItemPrefix').'.VIEW"'; + $view_perm = $this->Conn->GetOne($sql); + } + $object->addFilter('perm_filter', 'perm.PermId = '.$view_perm); if ( !$this->Application->IsAdmin() ) @@ -1738,22 +1748,38 @@ // 1. clone original item $temp_handler =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); $cloned_ids = $temp_handler->CloneItems($event->Prefix, $event->Special, Array($object->GetID()), null, null, null, true); + $ci_table = $this->Application->GetTempName(TABLE_PREFIX.'CategoryItems'); - // 1.1. clone category items here too + // 2. delete record from CategoryItems (about cloned item) that was automatically created during call of Create method of kCatDBItem + $sql = 'SELECT ResourceId + FROM '.$object->TableName.' + WHERE '.$object->IDField.' = '.$cloned_ids[0]; + $clone_resource_id = $this->Conn->GetOne($sql); - // 2. put cloned id to OrgId field of item being cloned + $sql = 'DELETE FROM '.$ci_table.' + WHERE ItemResourceId = '.$clone_resource_id.' AND PrimaryCat = 1'; + $this->Conn->Query($sql); + + // 3. copy main item categoryitems to cloned item + $sql = ' INSERT INTO '.$ci_table.' (CategoryId, ItemResourceId, PrimaryCat, ItemPrefix, Filename) + SELECT CategoryId, '.$clone_resource_id.' AS ItemResourceId, PrimaryCat, ItemPrefix, Filename + FROM '.$ci_table.' + WHERE ItemResourceId = '.$object->GetDBField('ResourceId'); + $this->Conn->Query($sql); + + // 4. put cloned id to OrgId field of item being cloned $sql = 'UPDATE '.$object->TableName.' SET OrgId = '.$object->GetID().' WHERE '.$object->IDField.' = '.$cloned_ids[0]; $this->Conn->Query($sql); - // 3. substitute id of item being cloned with clone id + // 5. substitute id of item being cloned with clone id $this->Application->SetVar($event->getPrefixSpecial().'_id', $cloned_ids[0]); $selected_ids = explode(',', $this->Application->RecallVar($event->getPrefixSpecial().'_selected_ids')); $selected_ids[ array_search($object->GetID(), $selected_ids) ] = $cloned_ids[0]; $this->Application->StoreVar($event->getPrefixSpecial().'_selected_ids', implode(',', $selected_ids)); - // 4. delete original item from temp table + // 6. delete original item from temp table $temp_handler->DeleteItems($event->Prefix, $event->Special, Array($object->GetID())); } } Index: branches/unlabeled/unlabeled-1.25.2/core/kernel/utility/temp_handler.php =================================================================== diff -u -r5862 -r5868 --- branches/unlabeled/unlabeled-1.25.2/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 5862) +++ branches/unlabeled/unlabeled-1.25.2/core/kernel/utility/temp_handler.php (.../temp_handler.php) (revision 5868) @@ -143,6 +143,35 @@ $this->SetTables($tables); } + /** + * Searches through TempHandler tables info for required prefix + * + * @param string $prefix + * @param Array $master + * @return mixed + */ + function SearchTable($prefix, $master = null) + { + if (is_null($master)) { + $master = $this->Tables; + } + + if ($master['Prefix'] == $prefix) { + return $master; + } + + if (isset($master['SubTables'])) { + foreach ($master['SubTables'] as $sub_table) { + $found = $this->SearchTable($prefix, $sub_table); + if ($found !== false) { + return $found; + } + } + } + + return false; + } + function AddTables($prefix, &$tables) { if (!$this->Application->prefixRegistred($prefix)) { @@ -429,7 +458,6 @@ $live_foreign_key = $this->Conn->GetCol($query); if (isset($temp_id)) { - // if id < 0, then it is 0 by now => substitute it (in progress, by Alex) $query = 'SELECT '.$parent_key_field.' FROM '.$this->GetTempName($master['TableName']).' WHERE '.$master['IdField'].' IN ('.join(',', $temp_id).')'; $temp_foreign_key = $this->Conn->GetCol($query);