Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Tue, Jun 24, 11:28 PM

in-portal

Index: branches/unlabeled/unlabeled-1.18.2/kernel/units/general/helpers/permissions_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.18.2/kernel/units/general/helpers/permissions_helper.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.18.2/kernel/units/general/helpers/permissions_helper.php (revision 6107)
@@ -0,0 +1,451 @@
+<?php
+
+ class kPermissionsHelper extends kHelper {
+
+ /**
+ * Current set of permissions for group being edited
+ *
+ * @var Array
+ */
+ var $Permissions = Array();
+
+ function LoadPermissions($group_id, $cat_id, $type = 1)
+ {
+ $perm_table = $this->Application->getUnitOption('perm', 'TableName');
+ $perm_table = $this->Application->GetTempName($perm_table);
+ $sql = 'SELECT *
+ FROM '.$perm_table.'
+ WHERE (GroupId = '.$group_id.') AND (CatId = '.$cat_id.') AND (Type = '.$type.')';
+ $permissions = $this->Conn->Query($sql, 'Permission');
+
+ $this->Permissions = Array();
+ foreach ($permissions as $perm_name => $perm_options) {
+ $perm_record['value'] = $perm_options['PermissionValue'];
+ $perm_record['id'] = $perm_options['PermissionId'];
+ $this->Permissions[$perm_name] = $perm_record;
+ }
+ }
+
+ function getPermissionValue($perm_name)
+ {
+ return isset($this->Permissions[$perm_name]) ? $this->Permissions[$perm_name]['value'] : 0;
+ }
+
+ function getPermissionID($perm_name)
+ {
+ return isset($this->Permissions[$perm_name]) ? $this->Permissions[$perm_name]['id'] : 0;
+ }
+
+ /**
+ * This is old permission like ADMIN or LOGIN
+ *
+ * @param string $section_name
+ * @param string $perm_name
+ * @return bool
+ */
+ function isOldPermission($section_name, $perm_name)
+ {
+ return $section_name == 'in-portal:root' && $perm_name != 'view';
+ }
+
+ /**
+ * Returns permission names to check based on event name and item prefix (main item or subitem)
+ *
+ * @param kEvent $event
+ * @return Array
+ */
+ function getPermissionByEvent(&$event, $perm_mapping)
+ {
+ $top_prefix = $event->getEventParam('top_prefix');
+
+ $pefix_type = ($top_prefix == $event->Prefix) ? 'self' : 'subitem';
+ $perm_mapping = getArrayValue($perm_mapping, $event->Name);
+
+ if (!$perm_mapping[$pefix_type]) {
+ trigger_error('Permission mappings not defined for event <b>'.$top_prefix.' <- '.$event->Prefix.':'.$event->Name.'</b>', E_USER_ERROR);
+ }
+
+ if ($perm_mapping[$pefix_type] === true) {
+ // event is defined in mapping but is not checked by permissions
+ return true;
+ }
+
+ return explode('|', $perm_mapping[$pefix_type]);
+ }
+
+ /**
+ * Common event permission checking method
+ *
+ * @param kEvent $event
+ */
+ function CheckEventPermission(&$event, $perm_mapping)
+ {
+ $section = $event->getSection();
+ if (preg_match('/^CATEGORY:(.*)/', $section)) {
+ return $this->CheckEventCategoryPermission($event, $perm_mapping);
+ }
+
+ $top_prefix = $event->getEventParam('top_prefix');
+ $check_perms = $this->getPermissionByEvent($event, $perm_mapping);
+
+ if ($check_perms === true) {
+ // event is defined in mapping but is not checked by permissions
+ return true;
+ }
+
+ $perm_status = false;
+ foreach ($check_perms as $perm_name) {
+ // check if at least one of required permissions is set
+ $perm_name = $section.'.'.$perm_name;
+ $perm_status = $this->CheckPermission($perm_name, 1);
+ if (($perm_name == $section.'.add') && $perm_status && ($top_prefix == $event->Prefix)) {
+ // main item, add permission allowed, but ID is > 0, then deny permission
+ // how to get id here
+ }
+ if ($perm_status) {
+ return $perm_status;
+ }
+ }
+
+ if (!$perm_status) {
+ if ($this->Application->isDebugMode()) {
+ // for debugging purposes
+ $event->SetRedirectParam('section', $section);
+ $event->SetRedirectParam('main_prefix', $top_prefix);
+ $event->SetRedirectParam('event_name', $event->Name);
+ $event->SetRedirectParam('next_template', $this->Application->GetVar('t'));
+ }
+ $event->status = erPERM_FAIL;
+ }
+ return $perm_status;
+ }
+
+ /**
+ * Checks non-system permission on event per category basis
+ *
+ * @param kEvent $event
+ */
+ function CheckEventCategoryPermission(&$event, $event_perm_mapping)
+ {
+ // mapping between specific permissions and common permissions
+ $perm_mapping = Array('add' => 'ADD', 'add.pending' => 'ADD.PENDING', 'edit' => 'MODIFY', 'edit.pending' => 'MODIFY.PENDING', 'delete' => 'DELETE', 'view' => 'VIEW');
+
+ $top_prefix = $event->getEventParam('top_prefix');
+ $event_handler =& $this->Application->recallObject($event->Prefix.'_EventHandler');
+ if ($event->Prefix != $top_prefix) {
+ $top_event = new kEvent($top_prefix.':'.$event->Name);
+ $id = $event_handler->getPassedID($top_event);
+ }
+ else {
+ $id = $event_handler->getPassedID($event);
+ }
+
+ // 1. get primary category of category item
+ $id_field = $this->Application->getUnitOption($top_prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($top_prefix, 'TableName');
+ $ci_table = $this->Application->getUnitOption('ci', 'TableName');
+
+ if (!$id) {
+ // item being created -> check by current (before editing started, saved in OnPreCreate event) category permissions
+ $category_id = $this->Application->RecallVar('m_cat_id');
+ }
+ elseif ($top_prefix == 'c') {
+ $category_id = $id;
+ }
+ else {
+ // item being edited -> check by it's primary category permissions
+ $sql = 'SELECT ci.CategoryId, main_table.CreatedById
+ FROM '.$table_name.' main_table
+ LEFT JOIN '.$ci_table.' ci ON ci.ItemResourceId = main_table.ResourceId
+ WHERE (main_table.'.$id_field.' = '.$id.') AND (ci.PrimaryCat = 1)';
+ $item_info = $this->Conn->GetRow($sql);
+ $category_id = $item_info['CategoryId'];
+ $owner_id = $item_info['CreatedById'];
+ }
+
+ $item_prefix = $this->Application->getUnitOption($top_prefix, 'PermItemPrefix');
+
+ if (substr($event->Name, 0, 9) == 'OnPreSave') {
+ if ($event_handler->isNewItemCreate($event)) {
+ return $this->CheckPermission($item_prefix.'.ADD', 0, $category_id) ||
+ $this->CheckPermission($item_prefix.'.ADD.PENDING', 0, $category_id);
+ }
+ else {
+ return $this->CheckPermission($item_prefix.'.ADD', 0, $category_id) ||
+ $this->CheckPermission($item_prefix.'.ADD.PENDING', 0, $category_id) ||
+ $this->ModifyCheckPermission($owner_id, $category_id, $top_prefix);
+ }
+ }
+
+ $perm_status = false;
+ $check_perms = $this->getPermissionByEvent($event, $event_perm_mapping);
+
+ if ($check_perms === true) {
+ // event is defined in mapping but is not checked by permissions
+ return true;
+ }
+
+ foreach ($check_perms as $perm_name) {
+ // check if at least one of required permissions is set
+ if (!isset($perm_mapping[$perm_name])) {
+ // not mapped permission (e.g. advanced:approve) -> skip
+ continue;
+ }
+ $perm_name = $item_prefix.'.'.$perm_mapping[$perm_name];
+ $this->showDebug('Event <b>'.$event->Name.'</b> permission(-s): <b>'.$perm_name.'</b>', Array());
+ $perm_status = $this->CheckPermission($perm_name, 0, $category_id);
+
+ if ($perm_status) {
+ return $perm_status;
+ }
+ }
+
+ if (!$perm_status) {
+ $event->SetRedirectParam('index_file', 'index.php'); // because called from browse.php
+ if ($this->Application->isDebugMode()) {
+ // for debugging purposes
+ $event->SetRedirectParam('section', $event->getSection());
+ $event->SetRedirectParam('main_prefix', $top_prefix);
+ $event->SetRedirectParam('event_name', $event->Name);
+ $event->SetRedirectParam('next_template', $this->Application->GetVar('t'));
+ }
+ $event->status = erPERM_FAIL;
+ }
+ return $perm_status;
+ }
+
+ function showDebug($text, $params)
+ {
+ $is_ajax = $this->Application->GetVar('ajax') == 'yes' || isset($params['ajax']) || isset($params['tab_init']);
+ if (!$this->Application->isDebugMode() || $is_ajax) return true;
+ echo $text.'<br />';
+ }
+
+ function TagPermissionCheck($params, $tag_name)
+ {
+ $perm_prefix = getArrayValue($params, 'perm_prefix');
+ $perm_event = getArrayValue($params, 'perm_event');
+ $permission_groups = getArrayValue($params, 'permissions');
+
+ if ($permission_groups) {
+ // check permissions by permission names in current category
+ $this->showDebug('Tag <b>'.$tag_name.'</b> permission(-s): <b>'.$permission_groups.'</b>', $params);
+ $permission_groups = explode('|', $permission_groups);
+ $group_has_permission = false;
+
+ $perm_category = $this->Application->GetVar('m_cat_id');
+
+ if ($perm_prefix) {
+ // use primary category of item with id from {perm_prefix}_id as base for permission checking
+ $perm_category = $this->getPrimaryCategory($perm_prefix);
+ }
+
+ foreach ($permission_groups as $permission_group) {
+ $permissions = explode(',', $permission_group);
+ $has_permission = true;
+ foreach ($permissions as $permission) {
+ $has_permission = $has_permission && $this->CheckPermission($permission, isset($params['system']) && $params['system'] ? 1 : 0, $perm_category);
+ }
+ $group_has_permission = $group_has_permission || $has_permission;
+
+ if ($group_has_permission) {
+ return true;
+ }
+ }
+ return false;
+ }
+ elseif ($perm_event) {
+ // check permission by event name
+ $this->showDebug('Tag <b>'.$tag_name.'</b> permission_event: <b>'.$perm_event.'</b>', $params);
+ list($prefix, $event) = explode(':', $perm_event);
+ $event_handler =& $this->Application->recallObject($prefix.'_EventHandler');
+ return $event_handler->CheckPermission( new kEvent($perm_event) );
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns item's primary category (get item_id from request)
+ *
+ * @param string $prefix
+ * @return int
+ */
+ function getPrimaryCategory($prefix)
+ {
+ $id_field = $this->Application->getUnitOption($prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($prefix, 'TableName');
+ $id = $this->Application->GetVar($prefix.'_id');
+
+ if (!$id) return $this->Application->GetVar('m_cat_id');
+
+ $sql = 'SELECT ResourceId
+ FROM '.$table_name.'
+ WHERE '.$id_field.' = '.$id;
+ $resource_id = $this->Conn->GetOne($sql);
+
+ $sql = 'SELECT CategoryId
+ FROM '.$this->Application->getUnitOption('ci', 'TableName').'
+ WHERE ItemResourceId = '.$resource_id.' AND PrimaryCat = 1';
+ return $this->Conn->GetOne($sql);
+ }
+
+ /**
+ * Returns no permission template to redirect to
+ *
+ * @param Array $params
+ * @return Array
+ */
+ function getPermissionTemplate($params)
+ {
+ $t = $this->Application->GetVar('t');
+ if ($next_t = getArrayValue($params, 'next_template')) {
+ $t = $next_t;
+ }
+
+ if (!$this->Application->LoggedIn()) {
+ $redirect_template = $params['login_template'];
+ $redirect_params = Array('next_template' => $t);
+ }
+ else {
+ if (isset($params['no_permissions_template'])) {
+ $redirect_template = $params['no_permissions_template'];
+ }
+ else {
+ $redirect_template = $this->Application->IsAdmin() ? 'no_permission' : $this->Application->ConfigValue('NoPermissionTemplate');
+ }
+
+ $redirect_params = $this->Application->isDebugMode() ? Array('from_template' => 1, 'perms' => $params[ isset($params['permissions']) ? 'permissions' : 'perm_event'], 'next_template' => $t) : Array();
+ }
+
+ if (isset($params['index_file']) && $params['index_file']) {
+ $redirect_params['index_file'] = $params['index_file'];
+ }
+
+ return Array($redirect_template, $redirect_params);
+ }
+
+ /**
+ * Check current user permissions based on it's group permissions in specified category (for non-system permissions) or just checks if system permission is set
+ *
+ * @param string $name permission name
+ * @param int $cat_id category id, current used if not specified
+ * @param int $type permission type {1 - system, 0 - per category}
+ * @return int
+ */
+ function CheckPermission($name, $type = 1, $cat_id = null)
+ {
+ if ($this->Application->GetVar('u_id') == -1) {
+ // "root" is allowed anywhere
+ return $name == 'SYSTEM_ACCESS.READONLY' ? 0 : 1;
+ }
+
+ if ($type == 1) {
+ // "system" permission are always checked per "Home" category (ID = 0)
+ $cat_id = 0;
+ }
+
+ if (!isset($cat_id)) {
+ $cat_id = $this->Application->GetVar('m_cat_id');
+ }
+
+ $cache_key = $name.'|'.$type.'|'.$cat_id;
+ $perm_value = $this->Application->getCache('permissions', $cache_key);
+ if ($perm_value !== false) {
+ return $perm_value;
+ }
+
+ // perm cache is build only based on records in db, that's why if permission is not explicitly denied, then
+ // that (perm cache creator) code thinks that it is allowed & adds corresponding record and code below will
+ // return incorrect results
+
+ if (preg_match('/(.*)\.VIEW$/', $name) && ($type == 0)) {
+ // cached view permission of category: begin
+ $sql = 'SELECT PermissionConfigId
+ FROM '.TABLE_PREFIX.'PermissionConfig
+ WHERE PermissionName = '.$this->Conn->qstr($name);
+ $perm_id = $this->Conn->GetOne($sql);
+
+ $sql = 'SELECT PermId
+ FROM '.TABLE_PREFIX.'PermCache
+ WHERE (PermId = '.$perm_id.') AND (CategoryId = '.$cat_id.')';
+
+ $view_filters = Array();
+ $groups = explode(',', $this->Application->RecallVar('UserGroups'));
+ foreach ($groups as $group) {
+ $view_filters[] = 'FIND_IN_SET('.$group.', ACL)';
+ }
+ $sql .= ' AND ('.implode(' OR ', $view_filters).')';
+ $perm_value = $this->Conn->GetOne($sql) ? 1 : 0;
+
+ $this->Application->setCache('permissions', $cache_key, $perm_value);
+ return $perm_value;
+ // cached view permission of category: end
+ }
+
+ if ($cat_id == 0) {
+ $cat_hierarchy = Array(0);
+ }
+ else {
+ $sql = 'SELECT ParentPath
+ FROM '.$this->Application->getUnitOption('c', 'TableName').'
+ WHERE CategoryId = '.$cat_id;
+ $cat_hierarchy = $this->Conn->GetOne($sql);
+ $cat_hierarchy = explode('|', substr($cat_hierarchy, 1, -1));
+ $cat_hierarchy = array_reverse($cat_hierarchy);
+ array_push($cat_hierarchy, 0);
+ }
+
+ $perm_value = 0;
+ $groups = $this->Application->RecallVar('UserGroups');
+ foreach ($cat_hierarchy as $category_id) {
+ $sql = 'SELECT SUM(PermissionValue)
+ FROM '.TABLE_PREFIX.'Permissions
+ WHERE Permission = "'.$name.'" AND CatId = '.$category_id.' AND GroupId IN ('.$groups.') AND Type = '.$type;
+ $res = $this->Conn->GetOne($sql);
+ if ($res !== false && !is_null($res)) {
+ $perm_value = $res ? 1 : 0;
+ break;
+ }
+ }
+
+ $this->Application->setCache('permissions', $cache_key, $perm_value);
+ return $perm_value;
+ }
+
+ /**
+ * Allows to check MODIFY & OWNER.MODFY +/- PENDING permission combinations on item
+ *
+ * @param int $owner_id user_id, that is owner of the item
+ * @param int $category_id primary category of item
+ * @param string $prefix prefix of item
+ * @return int {0 - no MODIFY permission, 1 - has MODIFY permission, 2 - has MODIFY.PENDING permission}
+ */
+ function ModifyCheckPermission($owner_id, $category_id, $prefix)
+ {
+ $perm_prefix = $this->Application->getUnitOption($prefix, 'PermItemPrefix');
+
+ $live_modify = $this->CheckPermission($perm_prefix.'.MODIFY', ptCATEGORY, $category_id);
+ if ($live_modify) {
+ return 1;
+ }
+ else if ($this->CheckPermission($perm_prefix.'.MODIFY.PENDING', ptCATEGORY, $category_id)) {
+ return 2;
+ }
+
+ if ($owner_id == $this->Application->GetVar('u_id')) {
+ // user is item's OWNER -> check this permissions first
+ $live_modify = $this->CheckPermission($perm_prefix.'.OWNER.MODIFY', ptCATEGORY, $category_id);
+ if ($live_modify) {
+ return 1;
+ }
+ else if ($this->CheckPermission($perm_prefix.'.OWNER.MODIFY.PENDING', ptCATEGORY, $category_id)) {
+ return 2;
+ }
+ }
+
+ return 0;
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.18.2/kernel/units/general/helpers/permissions_helper.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.18
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.18.2/kernel/admin/include/toolbar/browse.php
===================================================================
--- branches/unlabeled/unlabeled-1.18.2/kernel/admin/include/toolbar/browse.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.18.2/kernel/admin/include/toolbar/browse.php (revision 6107)
@@ -0,0 +1,942 @@
+<?php
+global $objConfig,$objSections,$section, $rootURL,$adminURL, $admin, $imagesURL,$envar,
+ $m_var_list_update,$objCatList, $homeURL, $upURL, $objSession,$CatScopeClause,$DefaultTab;
+
+global $CategoryFilter,$TotalItemCount;
+
+global $Bit_All,$Bit_Pending,$Bit_Disabled,$Bit_New,$Bit_Pop,$Bit_Hot,$Bit_Ed;
+
+global $hideSelectAll;
+
+/* bit place holders for category view menu */
+$Bit_Active=64;
+$Bit_Pending=32;
+$Bit_Disabled=16;
+$Bit_New=8;
+$Bit_Pop=4;
+$Bit_Hot=2;
+$Bit_Ed=1;
+
+if( isset($_GET['SetTab']) )
+{
+ if($_GET["SetTab"] != "categories")
+ {
+ $m_tab_CatTab_Hide = 1;
+ $DefaultTab = $_GET["SetTab"];
+ }
+ else
+ {
+ $DefaultTab="categories";
+ $m_tab_CatTab_Hide = 0;
+ }
+}
+else
+ $m_tab_CatTab_Hide = (int)$objConfig->Get("CatTab_Hide");
+
+$CategoryView = $objConfig->Get("Category_View");
+if(!is_numeric($CategoryView))
+{
+ $CategoryView = 127;
+}
+
+$Category_Sortfield = $objConfig->Get("Category_Sortfield");
+if(!strlen($Category_Sortfield))
+ $Category_Sortfield = "Name";
+
+$Category_Sortorder = $objConfig->Get("Category_Sortorder");
+if(!strlen($Category_Sortorder))
+ $Category_Sortorder = "desc";
+
+$Perpage_Category = (int)$objConfig->Get("Perpage_Category");
+if(!$Perpage_Category)
+ $Perpage_Category="'all'";
+
+
+if($CategoryView == 127)
+{
+ $Category_ShowAll = 1;
+}
+else
+{
+ $Category_ShowAll=0;
+ $Status = array();
+ $Mod = array();
+ if($CategoryView & $Bit_Pending)
+ $Status[] = STATUS_PENDING;
+
+ if($CategoryView & $Bit_Active)
+ $Status[] = STATUS_ACTIVE;
+
+
+ if($CategoryView & $Bit_Disabled)
+ $Status[] = STATUS_DISABLED;
+
+ if(count($Status))
+ {
+ $CategoryFilter .= " AND (Status IN (".implode(",",$Status).") ";
+ }
+ else
+ $CategoryFilter .= " AND ((Status=-1) ";
+
+ if($CategoryView & $Bit_Ed)
+ {
+ $CategoryFilter .= " OR (EditorsPick=1) ";
+ }
+
+ if($CategoryView & $Bit_New)
+ {
+ $cutoff = adodb_date("U") - ($objConfig->Get("Category_DaysNew") * 86400);
+ $CategoryFilter .= " OR (CreatedOn > ".$cutoff.") ";
+ }
+ $CategoryFilter .= ")";
+}
+
+$list = $objSession->GetVariable("SearchWord");
+if(strlen($list))
+{
+ $CatScope = $objSession->GetVariable("SearchScope");
+ switch($CatScope)
+ {
+ case 0 :
+ $CatScopeClause = "";
+ break;
+ case 1:
+ $cat = $objCatList->CurrentCategoryID();
+ if($cat>0)
+ {
+ $allcats = $objCatList->AllSubCats($cat);
+ if(count($allcats)>0)
+ {
+ $catlist = implode(",",$allcats);
+ $CatScopeClause = " CategoryId IN ($catlist) ";
+ }
+ }
+ break;
+ case 2:
+ $CatScopeClause = "CategoryId=".$objCatList->CurrentCategoryID();
+ break;
+ }
+}
+else
+ $CatScopeClause="";
+
+$Cat_Paste = "false";
+if($objCatList->ItemsOnClipboard()>0)
+ $Cat_Paste = "true";
+
+$CurrentCat = $objCatList->CurrentCategoryID();
+if($CurrentCat>0)
+{
+ $c = $objCatList->GetItem($CurrentCat);
+ $CurrentRes = (int)$c->Get("ResourceId");
+}
+else
+ $CurrentRes =0;
+$mnuClearSearch = language("la_SearchMenu_Clear");
+$mnuNewSearch = language("la_SearchMenu_New");
+$mnuSearchCategory = language("la_SearchMenu_Categories");
+
+$lang_New = language("la_Text_New");
+$lang_Hot = language("la_Text_Hot");
+$lang_EdPick = language("la_prompt_EditorsPick");
+$lang_Pop = language("la_Text_Pop");
+
+$lang_Rating = language("la_prompt_Rating");
+$lang_Hits = language("la_prompt_Hits");
+$lang_Votes = language("la_prompt_Votes");
+$lang_Name = language("la_prompt_Name");
+
+$lang_Categories = language("la_ItemTab_Categories");
+$lang_Description = language("la_prompt_Description");
+$lang_MetaKeywords = language("la_prompt_MetaKeywords");
+$lang_SubSearch = language("la_prompt_SubSearch");
+$lang_Within = language("la_Text_Within");
+$lang_Current = language("la_Text_Current");
+$lang_Active = language("la_Text_Active");
+$lang_SubCats = language("la_Text_SubCats");
+$lang_SubItems = language("la_Text_Subitems");
+
+// View, Sort, Select, Per Page
+$lang_View = language('la_Text_View');
+$lang_Sort = language('la_Text_Sort');
+$lang_PerPage = language('la_prompt_PerPage');
+$lang_Select = language('la_Text_Select');
+$lang_InDevelopment = language('la_Text_InDevelopment');
+
+print <<<END
+
+<script language="JavaScript">
+// global usage phrases
+var lang_View = '$lang_View';
+var lang_Sort = '$lang_Sort';
+var lang_PerPage = '$lang_PerPage';
+var lang_Select = '$lang_Select';
+
+// local usage phrases
+var Category_Sortfield = '$Category_Sortfield';
+var Category_Sortorder = '$Category_Sortorder';
+var Category_Perpage = $Perpage_Category;
+var Category_ShowAll = $Category_ShowAll;
+var CategoryView = $CategoryView;
+var default_tab = "$DefaultTab";
+var Categories_Paste = $Cat_Paste;
+var CurrentCat = $CurrentCat;
+var CurrentRes = $CurrentRes;
+
+PasteButton = PasteButton || Categories_Paste;
+
+//JS Language variables
+var lang_New = "$lang_New";
+var lang_Hot = "$lang_Hot";
+var lang_EdPick = "$lang_EdPick";
+
+var lang_Pop = "$lang_Pop";
+var lang_Rating = "$lang_Rating";
+var lang_Hits = "$lang_Hits";
+var lang_Votes = "$lang_Votes";
+var lang_Name = "$lang_Name";
+var lang_Categories = "$lang_Categories";
+var lang_Description = "$lang_Description";
+var lang_MetaKeywords = "$lang_MetaKeywords";
+var lang_SubSearch = "$lang_SubSearch";
+var lang_Within="$lang_Within";
+var lang_Current = "$lang_Current";
+var lang_Active = "$lang_Active";
+var lang_SubCats = "$lang_SubCats";
+var lang_SubItems = "$lang_SubItems";
+var lang_InDevelopment = "$lang_InDevelopment";
+
+var m_tab_CatTab_hide = $m_tab_CatTab_Hide;
+var hostname = '$rootURL';
+var env = '$envar';
+var actionlist = new Array();
+var homeURL = "$homeURL";
+var upURL = "$upURL";
+
+
+ // K4 code for handling toolbar operations: begin
+ var \$TabRegistry = Array();
+
+ function InpGrid(tab)
+ {
+ this.TabId = tab;
+ }
+
+ InpGrid.prototype.ClearSelection = function(force,called_from)
+ {
+ unselectAll(this.TabId, 1); //1 means don't upate toolbar
+ }
+
+ function registerTab(\$tab_id)
+ {
+ var \$tab = document.getElementById(\$tab_id);
+ var \$index = \$TabRegistry.length;
+
+ \$TabRegistry[\$index] = new Array();
+ \$TabRegistry[\$index]['tab_id'] = \$tab_id;
+ \$TabRegistry[\$index]['prefix_special'] = \$tab.getAttribute('PrefixSpecial');
+ \$TabRegistry[\$index]['edit_template'] = \$tab.getAttribute('EditURL');
+ }
+
+ function queryTabRegistry(\$search_key, \$search_value, \$return_key)
+ {
+ var \$i = 0;
+ while(\$i < \$TabRegistry.length)
+ {
+ if(\$TabRegistry[\$i][\$search_key] == \$search_value)
+ {
+ return \$TabRegistry[\$i][\$return_key];
+ break;
+ }
+ \$i++;
+ }
+ return '<'+\$search_key+'='+\$search_value+'>';
+ }
+
+ function k4_actionHandler(action, prefix_special)
+ {
+ var k4_action = '';
+ switch (action)
+ {
+ case 'edit':
+ k4_action = 'edit_item("'+prefix_special+'")';
+ break;
+ case 'delete':
+ k4_action = 'delete_items("'+prefix_special+'")';
+ break;
+ case 'unselect':
+ k4_action = 'unselect("'+prefix_special+'")';
+ break;
+
+ case 'approve':
+ k4_action = 'approve_items("'+prefix_special+'")';
+ break;
+ case 'decline':
+ k4_action = 'decine_items("'+prefix_special+'")';
+ break;
+
+ case 'm_rebuild_cache':
+ k4_action = 'rebuild_cache("c")';
+ break;
+
+// case 'import':
+// k4_action = 'import_items("'+prefix_special+'")';
+// break;
+
+ case 'export':
+ k4_action = 'export_items("'+prefix_special+'")';
+ break;
+
+ case 'copy':
+ k4_action = 'copy_items("'+prefix_special+'")';
+ break;
+ case 'cut':
+ k4_action = 'cut_items("'+prefix_special+'")';
+ break;
+
+ case 'move_up':
+ k4_action = 'move_up("'+prefix_special+'")';
+ break;
+ case 'move_down':
+ k4_action = 'move_down("'+prefix_special+'")';
+ break;
+ }
+
+ if (k4_action != '')
+ {
+ \$form_name = queryTabRegistry('prefix_special', prefix_special, 'tab_id') + '_form';
+ eval(k4_action);
+ }
+ else alert(action+' not implemented');
+
+ }
+
+ function approve_items(prefix_special)
+ {
+ set_hidden_field('remove_specials['+prefix_special+']',1);
+ submit_event(prefix_special,'OnMassApprove','')
+ }
+
+ function decine_items(prefix_special)
+ {
+ set_hidden_field('remove_specials['+prefix_special+']',1);
+ submit_event(prefix_special,'OnMassDecline','')
+ }
+
+// function import_items(prefix_special)
+// {
+// set_hidden_field('remove_specials['+prefix_special+']',1);
+// submit_event(prefix_special,'OnImport','')
+// }
+
+ function export_items(prefix_special)
+ {
+ set_hidden_field('remove_specials['+prefix_special+']',1);
+ submit_event(prefix_special,'OnExport','')
+ }
+
+ function edit()
+ {
+ edit_item( queryTabRegistry('tab_id', activeTab.id, 'prefix_special') );
+ }
+
+ function edit_item(prefix_special)
+ {
+ opener_action('d');
+ set_hidden_field(prefix_special+'_mode', 't');
+ submit_event(prefix_special, 'OnEdit', queryTabRegistry('prefix_special', prefix_special, 'edit_template'), '../../admin/index.php');
+ }
+
+ function delete_items(prefix_special)
+ {
+ set_hidden_field('remove_specials['+prefix_special+']',1);
+ submit_event(prefix_special,'OnMassDelete','')
+ }
+
+ function copy_items(prefix_special)
+ {
+ submit_event(prefix_special,'OnCopy','')
+ }
+
+ function cut_items(prefix_special)
+ {
+ submit_event(prefix_special,'OnCut','')
+ }
+
+ function move_up(prefix_special)
+ {
+ submit_event(prefix_special,'OnMassMoveUp','')
+ }
+
+ function move_down(prefix_special)
+ {
+ submit_event(prefix_special,'OnMassMoveDown','')
+ }
+
+ function unselect(prefix_special)
+ {
+ Grids[prefix_special].ClearSelection(null,'Inp_AdvancedView.Unselect');
+ }
+
+ function rebuild_cache(prefix_special)
+ {
+ submit_event(prefix_special,'OnRebuildCache','')
+ }
+ // K4 code for handling toolbar operations: end
+
+
+
+ function InitPage()
+ {
+ addCommonActions();
+ initToolbar('mainToolBar', actionHandler);
+ initCheckBoxes();
+ //toggleMenu();
+ }
+
+ function AddButtonAction(action_name,action_value)
+ {
+ actionlist[actionlist.length] = new Array(action_name, action_value);
+ }
+
+ function actionHandler(button)
+ {
+// alert('a button has been pressed!');
+ for(i=0; i<actionlist.length;i++)
+ {
+
+ a = actionlist[i];
+ if(button.action==a[0])
+ {
+// alert('Button action '+a[0]+' is '+a[1]);
+ eval(a[1]);
+ break;
+ }
+ }
+ }
+
+ function addCommonActions()
+ {
+ AddButtonAction('upcat',"get_to_server(upURL,'');");// UP
+ AddButtonAction('homecat',"get_to_server(homeURL,'');"); //home
+ AddButtonAction('new_cat',"get_to_server('$adminURL/category/addcategory.php',env+'&new=1');"); //new cat
+ AddButtonAction('editcat',"edit_current(); "); //edit current
+ AddButtonAction('edit',"check_submit('','edit');"); //edit
+ AddButtonAction('delete',"check_submit('$admin/browse','delete');"); //delete
+ AddButtonAction('approve',"check_submit('$admin/browse','approve');"); //approve
+ AddButtonAction('decline',"check_submit('$admin/browse','decline');"); //decline
+
+// AddButtonAction('import',"check_submit('$admin/browse','import');"); // import
+ AddButtonAction('export',"check_submit('$admin/browse','export');"); // export
+
+ AddButtonAction('rebuild_cache',"check_submit('$admin/category/category_maint', 'm_rebuild_cache');"); // rebuild_cache
+
+ AddButtonAction('cut',"check_submit('$admin/browse','cut');"); //cut
+ AddButtonAction('copy',"check_submit('$admin/browse','copy');"); //copy
+ AddButtonAction('paste',"get_to_server('$adminURL/browse.php',env+'&Action=m_paste');"); //paste
+ AddButtonAction('move_up',"check_submit('$admin/browse','move_up');"); //up
+ AddButtonAction('move_down',"check_submit('$admin/browse','move_down');"); //down
+ AddButtonAction('print',"window.print();"); //print ?
+ AddButtonAction('view',"toggleMenu(); window.FW_showMenu(window.cat_menu,getRealLeft(button) - ((document.all) ? 6 : -2),getRealTop(button)+32);");
+ AddButtonAction('search_a',"setSearchMenu(); window.FW_showMenu(window.SearchMenu,getRealLeft(button)-134 - ((document.all) ? 8 : -1),getRealTop(button)+22);");
+ AddButtonAction('search_b',"search_submit();");
+ AddButtonAction('search_c',"new_search_submit();");
+ }
+
+ function AdminCatNav(url)
+ {
+ f = document.getElementById("admin_search");
+ if(f)
+ {
+ f.action = url;
+ new_search_submit();
+ }
+ }
+
+ function search_submit()
+ {
+ f = document.getElementById("admin_search");
+ if(f)
+ {
+ //alert('Setting SearchWord to ' + f.value);
+ f.Action.value = "m_SearchWord";
+ f.submit();
+ }
+ }
+ function new_search_submit()
+ {
+ var newSearchInput = document.getElementById("NewSearch");
+ if (newSearchInput) newSearchInput.value = 1;
+ search_submit();
+ }
+
+ function ClearSearch()
+ {
+ //alert('Clearing Search');
+ f = document.getElementById("admin_search");
+ if(f)
+ {
+ f.Action.value = "m_ClearSearch";
+ f.submit();
+ }
+ }
+
+ function SetSearchType(value)
+ {
+ f = document.getElementById("admin_search");
+ if(f)
+ {
+ f.SearchType.value = value;
+ }
+ }
+
+ function SetSearchScope(value)
+ {
+ f = document.getElementById("admin_search");
+ if(f)
+ {
+ f.SearchScope.value = value;
+ }
+ }
+
+ function ToggleNewSearch()
+ {
+ f = document.getElementById("admin_search");
+ if(f)
+ {
+ value = f.NewSearch.value;
+ if(value==1)
+ {
+ f.NewSearch.value=0;
+ }
+ else
+ f.NewSearch.value=1;
+ }
+ }
+ function isNewSearch()
+ {
+ f = document.getElementById("admin_search");
+ if(f)
+ {
+ return f.NewSearch.value;
+ }
+ else return 0;
+ }
+
+
+ function get_to_server(path,attr)
+ {
+ if(attr.length>0)
+ path = path + '?'+attr;
+
+ window.location.href=path;
+ return true;
+ }
+
+ function check_submit(page, actionValue)
+ {
+ if (actionValue.match(/delete$/))
+ {
+ if (!theMainScript.Confirm(lang_DeleteConfirm)) return;
+ }
+
+ var formname = '';
+ var action_prefix ='';
+
+ var isCategoryExport = activeTab && isAnyChecked('categories') && (actionValue == 'export');
+
+ // skip news & topics for export operations (not to raise js errors)
+ if ((actionValue == 'export') && (activeTab.getAttribute("PrefixSpecial") == 'n' || activeTab.getAttribute("PrefixSpecial") == 'bb')) {
+ alert(lang_InDevelopment);
+ return false;
+ }
+
+ if (activeTab && (!isAnyChecked('categories') || isCategoryExport))
+ {
+ form_name = activeTab.id;
+ action_prefix = activeTab.getAttribute("ActionPrefix");
+ if (page.length == 0) page = activeTab.getAttribute("EditURL");
+
+ if (actionValue == 'export') {
+ save_selected_categories('export_categories');
+ }
+
+ if ( action_prefix.match("k4:(.*)") )
+ {
+ act = RegExp.$1;
+ act = act.replace('$\$event$$', actionValue);
+ act = act.replace('$\$prefix$$', activeTab.getAttribute("PrefixSpecial") );
+ eval(act);
+ return;
+ }
+ else if(actionValue == 'export') // || actionValue == 'import'
+ {
+ return k4_actionHandler(actionValue, activeTab.getAttribute("PrefixSpecial"));
+ }
+ }
+ else
+ {
+ form_name = 'categories';
+ action_prefix = 'm_cat_';
+ if (page.length == 0) page = "$admin" + '/category/addcategory';
+ }
+
+ var f = document.getElementsByName(form_name+'_form')[0];
+ if(f)
+ {
+ if (actionValue.substring(0,2) == 'm_')
+ {
+ f.Action.value = actionValue;
+ }
+ else
+ {
+ f.Action.value = action_prefix + actionValue;
+ }
+
+ f.action = '$rootURL' + page + '.php?'+ env;
+// alert(f.name+ ' is submitting to '+ f.action + ' action=' + f.Action.value);
+ f.submit();
+ }
+ } // check submit
+
+ function save_selected_categories(field_name)
+ {
+ var result = '';
+ var checkboxes = document.getElementsByName('catlist[]');
+
+ for (var i = 0; i < checkboxes.length; i++)
+ {
+ if (checkboxes[i].checked == true)
+ {
+ result += checkboxes[i].value + ',';
+ }
+ }
+ result = result.replace(/(.*),\$/, '\$1');
+ if (activeTab) \$form_name = activeTab.id + '_form';
+ set_hidden_field(field_name, result);
+ }
+
+ function edit_current()
+ {
+ if(CurrentCat==0)
+ {
+ get_to_server('$adminURL/category/addcategory_permissions.php',env+'&item=0');
+ }
+ else
+ get_to_server('$adminURL/category/addcategory.php',env+'&item=$CurrentRes');
+ }
+
+ function flip_current(field_suffix)
+ {
+ if(activeTab)
+ {
+ field = activeTab.getAttribute("tabTitle")+field_suffix;
+ return flip(eval(field));
+ }
+ }
+
+ function config_current(field_suffix,value)
+ {
+ if(activeTab)
+ {
+ field = activeTab.getAttribute("tabTitle")+field_suffix;
+ config_val(field,value);
+ }
+ }
+
+ function getSType(type,value)
+ {
+ f = document.getElementById("admin_search");
+ if(f)
+ {
+ if (f.SearchType.value == type) return 2; else return 0;
+ } else return 0;
+
+ }
+
+ function getSScope(scope)
+ {
+ f = document.getElementById("admin_search");
+ if(f)
+ {
+ if (f.SearchScope.value == scope) return 2; else return 0;
+ } else return 0;
+
+ }
+
+ function setSearchMenu()
+ {
+
+ window.SearchMenu = new Menu("search");
+ SearchMenu.addMenuItem(lang_All,"SetSearchType('all');",getSType('all'));
+ SearchMenu.addMenuSeparator()
+
+ SearchMenu.addMenuItem(lang_Categories, "SetSearchType('categories');",getSType('categories'));
+ param = "";
+
+ for (var i = 0; i < tabIDs.length; i++)
+ {
+ d = document.getElementById(tabIDs[i]);
+ if(d)
+ {
+ tabname = d.getAttribute("tabTitle");
+ param = "SetSearchType('"+tabname+"');";
+
+ SearchMenu.addMenuItem(tabname,param,getSType(tabname));
+ }
+ }
+
+ SearchMenu.addMenuSeparator();
+ SearchMenu.addMenuItem(lang_All+' '+lang_Categories,"SetSearchScope('0');",getSScope(0));
+ SearchMenu.addMenuItem(lang_SubSearch,"ToggleNewSearch();",isNewSearch());
+ SearchMenu.addMenuItem(lang_Current+' '+lang_Categories,"SetSearchScope('2');",getSScope(2));
+ SearchMenu.addMenuItem(lang_Within+' '+lang_Categories,"SetSearchScope('1');",getSScope(1));
+
+ SearchMenu.addMenuSeparator();
+
+ window.SearchMenu.addMenuItem('$mnuClearSearch',"ClearSearch();","");
+ window.triedToWriteMenus = false;
+ window.SearchMenu.writeMenus();
+ }
+
+ \$fw_menus['c_view_menu'] = function()
+ {
+ // filtering menu
+ \$Menus['c_filtring_menu'] = new Menu(lang_View);
+ \$Menus['c_filtring_menu'].addMenuItem(lang_All,"config_val('Category_View', 127);",CategoryView==127);
+ \$Menus['c_filtring_menu'].addMenuSeparator();
+ \$Menus['c_filtring_menu'].addMenuItem(lang_Active,"FlipBit('Category_View',CategoryView,6);",BitStatus(CategoryView,6));
+ \$Menus['c_filtring_menu'].addMenuItem(lang_Pending,"FlipBit('Category_View',CategoryView,5);", BitStatus(CategoryView,5));
+ \$Menus['c_filtring_menu'].addMenuItem(lang_Disabled,"FlipBit('Category_View',CategoryView,4);",BitStatus(CategoryView,4));
+ \$Menus['c_filtring_menu'].addMenuSeparator();
+ \$Menus['c_filtring_menu'].addMenuItem(lang_New,"FlipBit('Category_View',CategoryView,3);",BitStatus(CategoryView,3));
+ \$Menus['c_filtring_menu'].addMenuItem(lang_EdPick,"FlipBit('Category_View',CategoryView,0);",BitStatus(CategoryView,0));
+
+ // sorting menu
+ \$Menus['c_sorting_menu'] = new Menu(lang_Sort);
+ \$Menus['c_sorting_menu'].addMenuItem(lang_Asc,"config_val('Category_Sortorder','asc');",RadioIsSelected(Category_Sortorder,'asc'));
+ \$Menus['c_sorting_menu'].addMenuItem(lang_Desc,"config_val('Category_Sortorder','desc');",RadioIsSelected(Category_Sortorder,'desc'));
+ \$Menus['c_sorting_menu'].addMenuSeparator();
+ \$Menus['c_sorting_menu'].addMenuItem(lang_Default,"config_val('Category_Sortfield','Name');","");
+ \$Menus['c_sorting_menu'].addMenuItem(lang_Name,"config_val('Category_Sortfield','Name');",RadioIsSelected(Category_Sortfield,'Name'));
+ \$Menus['c_sorting_menu'].addMenuItem(lang_Description,"config_val('Category_Sortfield','Description');",RadioIsSelected(Category_Sortfield,'Description'));
+ \$Menus['c_sorting_menu'].addMenuItem(lang_CreatedOn,"config_val('Category_Sortfield','CreatedOn');",RadioIsSelected(Category_Sortfield,'CreatedOn'));
+ \$Menus['c_sorting_menu'].addMenuItem(lang_SubCats,"config_val('Category_Sortfield','CachedDescendantCatsQty');",RadioIsSelected(Category_Sortfield,'CachedDescendantCatsQty'));
+
+ // perpage menu
+
+ // select menu
+ \$Menus['c_select_menu'] = new Menu(lang_Select);
+ \$Menus['c_select_menu'].addMenuItem(lang_All,"javascript:selectAllC('categories');","");
+ \$Menus['c_select_menu'].addMenuItem(lang_Unselect,"javascript:unselectAll('categories');","");
+ \$Menus['c_select_menu'].addMenuItem(lang_Invert,"javascript:invert('categories');","");
+
+ // view menu
+ \$Menus['c_view_menu'] = new Menu(lang_Categories);
+ \$Menus['c_view_menu'].addMenuItem( \$Menus['c_filtring_menu'] );
+ \$Menus['c_view_menu'].addMenuItem( \$Menus['c_sorting_menu'] );
+ \$Menus['c_view_menu'].addMenuItem( \$Menus['c_select_menu'] );
+ }
+
+ function toggleMenu()
+ {
+ var \$ViewMenus = new Array();
+
+ // prepare categories menu
+ if (document.getElementById('categories').active)
+ {
+ \$fw_menus['c_view_menu']();
+ \$ViewMenus.push('c');
+ }
+
+ if (activeTab)
+ {
+ var prefix_special = activeTab.getAttribute('PrefixSpecial');
+ \$fw_menus[prefix_special+'_view_menu']();
+ \$ViewMenus.push(prefix_special);
+ }
+
+ if(\$ViewMenus.length == 1)
+ {
+ prefix_special = \$ViewMenus[\$ViewMenus.length-1];
+ window.cat_menu = \$Menus[prefix_special+'_view_menu'];
+ }
+ else
+ {
+ window.cat_menu = new Menu('ViewMenu_mixed');
+
+ // merge menus into new one
+ for(var i in \$ViewMenus)
+ {
+ prefix_special = \$ViewMenus[i];
+ window.cat_menu.addMenuItem( \$Menus[prefix_special+'_view_menu'] );
+ }
+ }
+
+ window.triedToWriteMenus = false;
+ window.cat_menu.writeMenus();
+ }
+
+function toggleCategoriesA(tabHeader, instant)
+{
+ var categories = document.getElementById('categories');
+ if (!categories) return;
+ toggleCategories(instant);
+
+ tabHeader.setAttribute("background", '$imagesURL'+'/itemtabs/' + ((categories.active) ? "tab_active" : "tab_inactive") + ".gif")
+ var images = tabHeader.getElementsByTagName("IMG");
+ if (images.length < 1) return;
+ images[0].src = '$imagesURL'+'/itemtabs/' + ((categories.active) ? "divider_up" : "divider_dn") + ".gif";
+}
+
+function toggleCategoriesB(tabHeader, instant)
+{
+ var categories = document.getElementById('categories');
+ if (!categories) return;
+ toggleCategories(instant);
+ var active_str = '$imagesURL'+'/itemtabs/' + (categories.active ? 'tab_active' : 'tab_inactive');
+ SetBackground('l_cat', active_str + '_l.gif');
+ SetBackground('m_cat', active_str + '.gif');
+ SetBackground('m1_cat', active_str + '.gif');
+ SetBackground('r_cat', active_str + '_r.gif');
+
+ var images = tabHeader.getElementsByTagName("IMG");
+ if (images.length < 1) return;
+ images[0].src = '$imagesURL'+'/itemtabs/' + ((categories.active) ? "divider_up" : "divider_dn") + ".gif";
+}
+
+function toggleTabA(tabId, atm)
+{
+ var hl = document.getElementById("hidden_line");
+ var activeTabId;
+
+
+ if (activeTab) activeTabId = activeTab.id;
+ if (activeTabId == tabId)
+ {
+ var devider = document.getElementById("tabsDevider");
+ devider.style.display = "";
+
+ unselectAll(tabId);
+ var tab = document.getElementById(tabId);
+ tab.active = false;
+ activeTab = null;
+ collapseTab = tab;
+ toolbar.setTab(null);
+ showTab();
+ }
+
+ else
+ {
+ if (activeTab) toggleTab(tabId, true)
+ else toggleTab(tabId, atm)
+
+ if (hl) hl.style.display = "none";
+ }
+ tab_hdr = document.getElementById('tab_headers');
+ if (!tab_hdr) return;
+ for (var i = 0; i < tabIDs.length; i++)
+ {
+ var tabHeader;
+ TDs = tab_hdr.getElementsByTagName("TD");
+ for (var j = 0; j < TDs.length; j++)
+ if (TDs[j].getAttribute("tabHeaderOf") == tabIDs[i])
+ {
+ tabHeader = TDs[j];
+ break;
+ }
+ if (!tabHeader) continue;
+
+ var tab = document.getElementById(tabIDs[i]);
+ if (!tab) continue;
+
+ tabHeader.setAttribute("background", "$imagesURL/itemtabs/" + ((tab.active) ? "tab_active" : "tab_inactive") + ".gif")
+
+ var images = tabHeader.getElementsByTagName("IMG");
+ if (images.length < 1) continue;
+
+ images[0].src = "$imagesURL/itemtabs/" + ((tab.active) ? "divider_up" : "divider_dn") + ".gif";
+ }
+}
+
+ function toggleTabB(tabId, atm)
+ {
+ var hl = document.getElementById("hidden_line");
+ var activeTabId;
+
+ if (activeTab) activeTabId = activeTab.id;
+ if (activeTabId == tabId)
+ {
+ var devider = document.getElementById("tabsDevider");
+ devider.style.display = "";
+
+ unselectAll(tabId);
+ var tab = document.getElementById(tabId);
+ tab.active = false;
+ activeTab = null;
+ collapseTab = tab;
+ toolbar.setTab(null);
+ showTab();
+ }
+ else
+ {
+ if (activeTab)
+ toggleTab(tabId, true)
+ else
+ toggleTab(tabId, atm)
+ if (hl) hl.style.display = "none";
+ }
+ tab_hdr = document.getElementById('tab_headers');
+ if (!tab_hdr) return;
+
+ // process all module tabs
+ var active_str = '';
+ for(var i = 0; i < tabIDs.length; i++)
+ {
+ var tabHeader;
+ TDs = tab_hdr.getElementsByTagName("TD");
+ for (var j = 0; j < TDs.length; j++)
+ if (TDs[j].getAttribute("tabHeaderOf") == tabIDs[i])
+ {
+ tabHeader = TDs[j];
+ break;
+ }
+ if (!tabHeader) continue;
+
+ var tab = document.getElementById(tabIDs[i]);
+ if (!tab) continue;
+ active_str = (tab.active) ? "tab_active" : "tab_inactive";
+
+ if (TDs[j].getAttribute("tabHeaderOf") == tabId) {
+ // module tab is selected
+ SetBackground('l_' + tabId, "$imagesURL/itemtabs/" + active_str + "_l.gif");
+ SetBackground('m_' + tabId, "$imagesURL/itemtabs/" + active_str + ".gif");
+ SetBackground('m1_' + tabId, "$imagesURL/itemtabs/" + active_str + ".gif");
+ SetBackground('r_' + tabId, "$imagesURL/itemtabs/" + active_str + "_r.gif");
+ }
+ else
+ {
+ // module tab is not selected
+ SetBackground('l_' +tabIDs[i], "$imagesURL/itemtabs/" + active_str + "_l.gif");
+ SetBackground('m_' + tabIDs[i], "$imagesURL/itemtabs/" + active_str + ".gif");
+ SetBackground('m1_' + tabIDs[i], "$imagesURL/itemtabs/" + active_str + ".gif");
+ SetBackground('r_' + tabIDs[i], "$imagesURL/itemtabs/" + active_str + "_r.gif");
+ }
+
+ var images = tabHeader.getElementsByTagName("IMG");
+ if (images.length < 1) continue;
+
+ images[0].src = "$imagesURL/itemtabs/" + ((tab.active) ? "divider_up" : "divider_dn") + ".gif";
+ }
+ }
+
+ function SetBackground(element_id, img_url)
+ {
+ // set background image of element specified by id
+ var el = document.getElementById(element_id);
+ el.style.backgroundImage = 'url('+img_url+')';
+ }
+</script>
+
+END;
+?>
Property changes on: branches/unlabeled/unlabeled-1.18.2/kernel/admin/include/toolbar/browse.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.18
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.18.2/core/units/general/helpers/permissions_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.18.2/core/units/general/helpers/permissions_helper.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.18.2/core/units/general/helpers/permissions_helper.php (revision 6107)
@@ -0,0 +1,451 @@
+<?php
+
+ class kPermissionsHelper extends kHelper {
+
+ /**
+ * Current set of permissions for group being edited
+ *
+ * @var Array
+ */
+ var $Permissions = Array();
+
+ function LoadPermissions($group_id, $cat_id, $type = 1)
+ {
+ $perm_table = $this->Application->getUnitOption('perm', 'TableName');
+ $perm_table = $this->Application->GetTempName($perm_table);
+ $sql = 'SELECT *
+ FROM '.$perm_table.'
+ WHERE (GroupId = '.$group_id.') AND (CatId = '.$cat_id.') AND (Type = '.$type.')';
+ $permissions = $this->Conn->Query($sql, 'Permission');
+
+ $this->Permissions = Array();
+ foreach ($permissions as $perm_name => $perm_options) {
+ $perm_record['value'] = $perm_options['PermissionValue'];
+ $perm_record['id'] = $perm_options['PermissionId'];
+ $this->Permissions[$perm_name] = $perm_record;
+ }
+ }
+
+ function getPermissionValue($perm_name)
+ {
+ return isset($this->Permissions[$perm_name]) ? $this->Permissions[$perm_name]['value'] : 0;
+ }
+
+ function getPermissionID($perm_name)
+ {
+ return isset($this->Permissions[$perm_name]) ? $this->Permissions[$perm_name]['id'] : 0;
+ }
+
+ /**
+ * This is old permission like ADMIN or LOGIN
+ *
+ * @param string $section_name
+ * @param string $perm_name
+ * @return bool
+ */
+ function isOldPermission($section_name, $perm_name)
+ {
+ return $section_name == 'in-portal:root' && $perm_name != 'view';
+ }
+
+ /**
+ * Returns permission names to check based on event name and item prefix (main item or subitem)
+ *
+ * @param kEvent $event
+ * @return Array
+ */
+ function getPermissionByEvent(&$event, $perm_mapping)
+ {
+ $top_prefix = $event->getEventParam('top_prefix');
+
+ $pefix_type = ($top_prefix == $event->Prefix) ? 'self' : 'subitem';
+ $perm_mapping = getArrayValue($perm_mapping, $event->Name);
+
+ if (!$perm_mapping[$pefix_type]) {
+ trigger_error('Permission mappings not defined for event <b>'.$top_prefix.' <- '.$event->Prefix.':'.$event->Name.'</b>', E_USER_ERROR);
+ }
+
+ if ($perm_mapping[$pefix_type] === true) {
+ // event is defined in mapping but is not checked by permissions
+ return true;
+ }
+
+ return explode('|', $perm_mapping[$pefix_type]);
+ }
+
+ /**
+ * Common event permission checking method
+ *
+ * @param kEvent $event
+ */
+ function CheckEventPermission(&$event, $perm_mapping)
+ {
+ $section = $event->getSection();
+ if (preg_match('/^CATEGORY:(.*)/', $section)) {
+ return $this->CheckEventCategoryPermission($event, $perm_mapping);
+ }
+
+ $top_prefix = $event->getEventParam('top_prefix');
+ $check_perms = $this->getPermissionByEvent($event, $perm_mapping);
+
+ if ($check_perms === true) {
+ // event is defined in mapping but is not checked by permissions
+ return true;
+ }
+
+ $perm_status = false;
+ foreach ($check_perms as $perm_name) {
+ // check if at least one of required permissions is set
+ $perm_name = $section.'.'.$perm_name;
+ $perm_status = $this->CheckPermission($perm_name, 1);
+ if (($perm_name == $section.'.add') && $perm_status && ($top_prefix == $event->Prefix)) {
+ // main item, add permission allowed, but ID is > 0, then deny permission
+ // how to get id here
+ }
+ if ($perm_status) {
+ return $perm_status;
+ }
+ }
+
+ if (!$perm_status) {
+ if ($this->Application->isDebugMode()) {
+ // for debugging purposes
+ $event->SetRedirectParam('section', $section);
+ $event->SetRedirectParam('main_prefix', $top_prefix);
+ $event->SetRedirectParam('event_name', $event->Name);
+ $event->SetRedirectParam('next_template', $this->Application->GetVar('t'));
+ }
+ $event->status = erPERM_FAIL;
+ }
+ return $perm_status;
+ }
+
+ /**
+ * Checks non-system permission on event per category basis
+ *
+ * @param kEvent $event
+ */
+ function CheckEventCategoryPermission(&$event, $event_perm_mapping)
+ {
+ // mapping between specific permissions and common permissions
+ $perm_mapping = Array('add' => 'ADD', 'add.pending' => 'ADD.PENDING', 'edit' => 'MODIFY', 'edit.pending' => 'MODIFY.PENDING', 'delete' => 'DELETE', 'view' => 'VIEW');
+
+ $top_prefix = $event->getEventParam('top_prefix');
+ $event_handler =& $this->Application->recallObject($event->Prefix.'_EventHandler');
+ if ($event->Prefix != $top_prefix) {
+ $top_event = new kEvent($top_prefix.':'.$event->Name);
+ $id = $event_handler->getPassedID($top_event);
+ }
+ else {
+ $id = $event_handler->getPassedID($event);
+ }
+
+ // 1. get primary category of category item
+ $id_field = $this->Application->getUnitOption($top_prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($top_prefix, 'TableName');
+ $ci_table = $this->Application->getUnitOption('ci', 'TableName');
+
+ if (!$id) {
+ // item being created -> check by current (before editing started, saved in OnPreCreate event) category permissions
+ $category_id = $this->Application->RecallVar('m_cat_id');
+ }
+ elseif ($top_prefix == 'c') {
+ $category_id = $id;
+ }
+ else {
+ // item being edited -> check by it's primary category permissions
+ $sql = 'SELECT ci.CategoryId, main_table.CreatedById
+ FROM '.$table_name.' main_table
+ LEFT JOIN '.$ci_table.' ci ON ci.ItemResourceId = main_table.ResourceId
+ WHERE (main_table.'.$id_field.' = '.$id.') AND (ci.PrimaryCat = 1)';
+ $item_info = $this->Conn->GetRow($sql);
+ $category_id = $item_info['CategoryId'];
+ $owner_id = $item_info['CreatedById'];
+ }
+
+ $item_prefix = $this->Application->getUnitOption($top_prefix, 'PermItemPrefix');
+
+ if (substr($event->Name, 0, 9) == 'OnPreSave') {
+ if ($event_handler->isNewItemCreate($event)) {
+ return $this->CheckPermission($item_prefix.'.ADD', 0, $category_id) ||
+ $this->CheckPermission($item_prefix.'.ADD.PENDING', 0, $category_id);
+ }
+ else {
+ return $this->CheckPermission($item_prefix.'.ADD', 0, $category_id) ||
+ $this->CheckPermission($item_prefix.'.ADD.PENDING', 0, $category_id) ||
+ $this->ModifyCheckPermission($owner_id, $category_id, $top_prefix);
+ }
+ }
+
+ $perm_status = false;
+ $check_perms = $this->getPermissionByEvent($event, $event_perm_mapping);
+
+ if ($check_perms === true) {
+ // event is defined in mapping but is not checked by permissions
+ return true;
+ }
+
+ foreach ($check_perms as $perm_name) {
+ // check if at least one of required permissions is set
+ if (!isset($perm_mapping[$perm_name])) {
+ // not mapped permission (e.g. advanced:approve) -> skip
+ continue;
+ }
+ $perm_name = $item_prefix.'.'.$perm_mapping[$perm_name];
+ $this->showDebug('Event <b>'.$event->Name.'</b> permission(-s): <b>'.$perm_name.'</b>', Array());
+ $perm_status = $this->CheckPermission($perm_name, 0, $category_id);
+
+ if ($perm_status) {
+ return $perm_status;
+ }
+ }
+
+ if (!$perm_status) {
+ $event->SetRedirectParam('index_file', 'index.php'); // because called from browse.php
+ if ($this->Application->isDebugMode()) {
+ // for debugging purposes
+ $event->SetRedirectParam('section', $event->getSection());
+ $event->SetRedirectParam('main_prefix', $top_prefix);
+ $event->SetRedirectParam('event_name', $event->Name);
+ $event->SetRedirectParam('next_template', $this->Application->GetVar('t'));
+ }
+ $event->status = erPERM_FAIL;
+ }
+ return $perm_status;
+ }
+
+ function showDebug($text, $params)
+ {
+ $is_ajax = $this->Application->GetVar('ajax') == 'yes' || isset($params['ajax']) || isset($params['tab_init']);
+ if (!$this->Application->isDebugMode() || $is_ajax) return true;
+ echo $text.'<br />';
+ }
+
+ function TagPermissionCheck($params, $tag_name)
+ {
+ $perm_prefix = getArrayValue($params, 'perm_prefix');
+ $perm_event = getArrayValue($params, 'perm_event');
+ $permission_groups = getArrayValue($params, 'permissions');
+
+ if ($permission_groups) {
+ // check permissions by permission names in current category
+ $this->showDebug('Tag <b>'.$tag_name.'</b> permission(-s): <b>'.$permission_groups.'</b>', $params);
+ $permission_groups = explode('|', $permission_groups);
+ $group_has_permission = false;
+
+ $perm_category = $this->Application->GetVar('m_cat_id');
+
+ if ($perm_prefix) {
+ // use primary category of item with id from {perm_prefix}_id as base for permission checking
+ $perm_category = $this->getPrimaryCategory($perm_prefix);
+ }
+
+ foreach ($permission_groups as $permission_group) {
+ $permissions = explode(',', $permission_group);
+ $has_permission = true;
+ foreach ($permissions as $permission) {
+ $has_permission = $has_permission && $this->CheckPermission($permission, isset($params['system']) && $params['system'] ? 1 : 0, $perm_category);
+ }
+ $group_has_permission = $group_has_permission || $has_permission;
+
+ if ($group_has_permission) {
+ return true;
+ }
+ }
+ return false;
+ }
+ elseif ($perm_event) {
+ // check permission by event name
+ $this->showDebug('Tag <b>'.$tag_name.'</b> permission_event: <b>'.$perm_event.'</b>', $params);
+ list($prefix, $event) = explode(':', $perm_event);
+ $event_handler =& $this->Application->recallObject($prefix.'_EventHandler');
+ return $event_handler->CheckPermission( new kEvent($perm_event) );
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns item's primary category (get item_id from request)
+ *
+ * @param string $prefix
+ * @return int
+ */
+ function getPrimaryCategory($prefix)
+ {
+ $id_field = $this->Application->getUnitOption($prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($prefix, 'TableName');
+ $id = $this->Application->GetVar($prefix.'_id');
+
+ if (!$id) return $this->Application->GetVar('m_cat_id');
+
+ $sql = 'SELECT ResourceId
+ FROM '.$table_name.'
+ WHERE '.$id_field.' = '.$id;
+ $resource_id = $this->Conn->GetOne($sql);
+
+ $sql = 'SELECT CategoryId
+ FROM '.$this->Application->getUnitOption('ci', 'TableName').'
+ WHERE ItemResourceId = '.$resource_id.' AND PrimaryCat = 1';
+ return $this->Conn->GetOne($sql);
+ }
+
+ /**
+ * Returns no permission template to redirect to
+ *
+ * @param Array $params
+ * @return Array
+ */
+ function getPermissionTemplate($params)
+ {
+ $t = $this->Application->GetVar('t');
+ if ($next_t = getArrayValue($params, 'next_template')) {
+ $t = $next_t;
+ }
+
+ if (!$this->Application->LoggedIn()) {
+ $redirect_template = $params['login_template'];
+ $redirect_params = Array('next_template' => $t);
+ }
+ else {
+ if (isset($params['no_permissions_template'])) {
+ $redirect_template = $params['no_permissions_template'];
+ }
+ else {
+ $redirect_template = $this->Application->IsAdmin() ? 'no_permission' : $this->Application->ConfigValue('NoPermissionTemplate');
+ }
+
+ $redirect_params = $this->Application->isDebugMode() ? Array('from_template' => 1, 'perms' => $params[ isset($params['permissions']) ? 'permissions' : 'perm_event'], 'next_template' => $t) : Array();
+ }
+
+ if (isset($params['index_file']) && $params['index_file']) {
+ $redirect_params['index_file'] = $params['index_file'];
+ }
+
+ return Array($redirect_template, $redirect_params);
+ }
+
+ /**
+ * Check current user permissions based on it's group permissions in specified category (for non-system permissions) or just checks if system permission is set
+ *
+ * @param string $name permission name
+ * @param int $cat_id category id, current used if not specified
+ * @param int $type permission type {1 - system, 0 - per category}
+ * @return int
+ */
+ function CheckPermission($name, $type = 1, $cat_id = null)
+ {
+ if ($this->Application->GetVar('u_id') == -1) {
+ // "root" is allowed anywhere
+ return $name == 'SYSTEM_ACCESS.READONLY' ? 0 : 1;
+ }
+
+ if ($type == 1) {
+ // "system" permission are always checked per "Home" category (ID = 0)
+ $cat_id = 0;
+ }
+
+ if (!isset($cat_id)) {
+ $cat_id = $this->Application->GetVar('m_cat_id');
+ }
+
+ $cache_key = $name.'|'.$type.'|'.$cat_id;
+ $perm_value = $this->Application->getCache('permissions', $cache_key);
+ if ($perm_value !== false) {
+ return $perm_value;
+ }
+
+ // perm cache is build only based on records in db, that's why if permission is not explicitly denied, then
+ // that (perm cache creator) code thinks that it is allowed & adds corresponding record and code below will
+ // return incorrect results
+
+ if (preg_match('/(.*)\.VIEW$/', $name) && ($type == 0)) {
+ // cached view permission of category: begin
+ $sql = 'SELECT PermissionConfigId
+ FROM '.TABLE_PREFIX.'PermissionConfig
+ WHERE PermissionName = '.$this->Conn->qstr($name);
+ $perm_id = $this->Conn->GetOne($sql);
+
+ $sql = 'SELECT PermId
+ FROM '.TABLE_PREFIX.'PermCache
+ WHERE (PermId = '.$perm_id.') AND (CategoryId = '.$cat_id.')';
+
+ $view_filters = Array();
+ $groups = explode(',', $this->Application->RecallVar('UserGroups'));
+ foreach ($groups as $group) {
+ $view_filters[] = 'FIND_IN_SET('.$group.', ACL)';
+ }
+ $sql .= ' AND ('.implode(' OR ', $view_filters).')';
+ $perm_value = $this->Conn->GetOne($sql) ? 1 : 0;
+
+ $this->Application->setCache('permissions', $cache_key, $perm_value);
+ return $perm_value;
+ // cached view permission of category: end
+ }
+
+ if ($cat_id == 0) {
+ $cat_hierarchy = Array(0);
+ }
+ else {
+ $sql = 'SELECT ParentPath
+ FROM '.$this->Application->getUnitOption('c', 'TableName').'
+ WHERE CategoryId = '.$cat_id;
+ $cat_hierarchy = $this->Conn->GetOne($sql);
+ $cat_hierarchy = explode('|', substr($cat_hierarchy, 1, -1));
+ $cat_hierarchy = array_reverse($cat_hierarchy);
+ array_push($cat_hierarchy, 0);
+ }
+
+ $perm_value = 0;
+ $groups = $this->Application->RecallVar('UserGroups');
+ foreach ($cat_hierarchy as $category_id) {
+ $sql = 'SELECT SUM(PermissionValue)
+ FROM '.TABLE_PREFIX.'Permissions
+ WHERE Permission = "'.$name.'" AND CatId = '.$category_id.' AND GroupId IN ('.$groups.') AND Type = '.$type;
+ $res = $this->Conn->GetOne($sql);
+ if ($res !== false && !is_null($res)) {
+ $perm_value = $res ? 1 : 0;
+ break;
+ }
+ }
+
+ $this->Application->setCache('permissions', $cache_key, $perm_value);
+ return $perm_value;
+ }
+
+ /**
+ * Allows to check MODIFY & OWNER.MODFY +/- PENDING permission combinations on item
+ *
+ * @param int $owner_id user_id, that is owner of the item
+ * @param int $category_id primary category of item
+ * @param string $prefix prefix of item
+ * @return int {0 - no MODIFY permission, 1 - has MODIFY permission, 2 - has MODIFY.PENDING permission}
+ */
+ function ModifyCheckPermission($owner_id, $category_id, $prefix)
+ {
+ $perm_prefix = $this->Application->getUnitOption($prefix, 'PermItemPrefix');
+
+ $live_modify = $this->CheckPermission($perm_prefix.'.MODIFY', ptCATEGORY, $category_id);
+ if ($live_modify) {
+ return 1;
+ }
+ else if ($this->CheckPermission($perm_prefix.'.MODIFY.PENDING', ptCATEGORY, $category_id)) {
+ return 2;
+ }
+
+ if ($owner_id == $this->Application->GetVar('u_id')) {
+ // user is item's OWNER -> check this permissions first
+ $live_modify = $this->CheckPermission($perm_prefix.'.OWNER.MODIFY', ptCATEGORY, $category_id);
+ if ($live_modify) {
+ return 1;
+ }
+ else if ($this->CheckPermission($perm_prefix.'.OWNER.MODIFY.PENDING', ptCATEGORY, $category_id)) {
+ return 2;
+ }
+ }
+
+ return 0;
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.18.2/core/units/general/helpers/permissions_helper.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.18
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline