예제 #1
0
 static function _getAllowedCats($user_id, $actions_allowed, $require_all, $check_published, $specific_catids, $find_first)
 {
     global $globalcats;
     $db = JFactory::getDBO();
     $usercats = array();
     // We ignore the user_id in the case FLEXIaccess, because FLEXIaccess only calculates access for current user,
     // this is ok since, because we pass the user_id only for the purpose of being able to cache this function call
     // -- passing by different user_id parameter this function call can be cached properly
     $user = FLEXI_ACCESS ? JFactory::getUser() : JFactory::getUser($user_id);
     if (FLEXI_J16GE) {
         // *** J1.6+ ***
         $allcats = FlexicontentHelperPerm::returnAllCats($check_published, $specific_catids);
         foreach ($allcats as $category_id) {
             // Construct asset name for the category
             $asset = 'com_content.category.' . $category_id;
             // Check all actions with Logical OR or Logical AND
             // We start with FALSE for OR and TRUE for AND
             $has_access = $require_all ? true : false;
             foreach ($actions_allowed as $action_name) {
                 $has_access = $require_all ? $has_access && $user->authorise($action_name, $asset) : $has_access || $user->authorise($action_name, $asset);
             }
             if ($has_access) {
                 $usercats[] = $category_id;
                 if ($find_first) {
                     break;
                 }
                 // J1.6+ performance consideration skip checking permissions of remaining categories
             }
         }
         return $usercats;
     } else {
         if (!FLEXI_ACCESS || $user->gid == 25) {
             // *** J1.5 without FLEXIaccess or user is super admin, return all category ids ***
             if ($user->gid < 19) {
                 return array();
             }
             // Less than J1.5 Author
             return FlexicontentHelperPerm::returnAllCats($check_published, $specific_catids);
         } else {
             // *** J1.5 with FLEXIaccess ***
             $aro_value = $user->gmid;
             // FLEXIaccess group
             // Create a limit for aco (ACTION privilege)
             $limit_aco = array();
             if (in_array('core.create', $actions_allowed)) {
                 $limit_aco[] = 'aco = ' . $db->Quote('add');
             }
             if (in_array('core.edit', $actions_allowed)) {
                 $limit_aco[] = 'aco = ' . $db->Quote('edit');
             }
             if (in_array('core.edit.own', $actions_allowed)) {
                 $limit_aco[] = 'aco = ' . $db->Quote('editown');
             }
             $oper = $require_all ? ' AND ' : ' OR ';
             if (count($limit_aco)) {
                 $limit_aco = implode($oper, $limit_aco);
             } else {
                 $limit_aco = 'aco = ' . $db->Quote('add') . $oper . ' aco = ' . $db->Quote('edit') . $oper . ' aco = ' . $db->Quote('editown');
             }
             // We will search for permission all on the given permission (add,edit,editown),
             // if found it means that there are no ACL limitations for given user, aka return all cats
             $query = 'SELECT COUNT(*) FROM #__flexiaccess_acl' . ' WHERE acosection = ' . $db->Quote('com_content') . ' AND ( ' . $limit_aco . ' )' . ' AND arosection = ' . $db->Quote('users') . ' AND aro IN ( ' . $aro_value . ' )' . ' AND axosection = ' . $db->Quote('content') . ' AND axo = ' . $db->Quote('all');
             $db->setQuery($query);
             // *** No limitations found, return all category ids ***
             if ($db->loadResult()) {
                 return FlexicontentHelperPerm::returnAllCats($check_published, $specific_catids);
             }
             // *** Limitations found, check and return category ids with 'create' permission ***
             // creating for -content- axosection is 'add' but for -category- axosection is 'submit'
             $limit_aco = str_replace('add', 'submit', $limit_aco);
             $query = 'SELECT axo FROM #__flexiaccess_acl' . ' WHERE acosection = ' . $db->Quote('com_content') . ' AND ( ' . $limit_aco . ' )' . ' AND arosection = ' . $db->Quote('users') . ' AND aro IN ( ' . $aro_value . ' )' . ' AND axosection = ' . $db->Quote('category') . ($specific_catids ? '  AND axo IN (' . implode(",", $specific_catids) . ')' : '');
             $db->setQuery($query);
             $allowedcats = $db->loadColumn();
             $allowedcats = $allowedcats ? $allowedcats : array();
             // we add all descendent to the array
             foreach ($allowedcats as $allowedcat) {
                 $usercats[] = $allowedcat;
                 if ($globalcats[$allowedcat]->children) {
                     foreach ($globalcats[$allowedcat]->descendantsarray as $k => $v) {
                         if (!$check_published || $globalcats[$v]->published) {
                             $usercats[] = $v;
                         }
                     }
                 }
             }
             $usercats = array_unique($usercats);
             return $usercats;
         }
     }
 }
예제 #2
0
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        // Get some api objects
        $db = JFactory::getDBO();
        $user = JFactory::getUser();
        $document = JFactory::getDocument();
        $field->html = '';
        $ri_field_name = str_replace('-', '_', $field->name);
        $fieldname = FLEXI_J16GE ? 'custom[' . $ri_field_name . '][]' : $ri_field_name . '[]';
        // Case of autorelated item
        $autorelation_itemid = JRequest::getInt('autorelation_' . $field->id);
        if ($autorelation_itemid) {
            // automatically related item
            $query = 'SELECT title, id, catid, state, alias ' . ' FROM #__content ' . ' WHERE id =' . $autorelation_itemid;
            $db->setQuery($query);
            $rel_item = $db->loadObject();
            if (!$rel_item) {
                $field->html = 'auto relating item id: ' . $autorelation_itemid . ' : item not found ';
                return;
            }
            $field->html = '<input id="' . $ri_field_name . '" name="' . $fieldname . '" type="hidden" value="' . $rel_item->id . ':' . $rel_item->catid . '" />';
            $field->html .= $rel_item->title;
            return;
        }
        // ************************************************************************
        // Initialise values and split them into: (a) item ids and (b) category ids
        // ************************************************************************
        $default_values = '';
        if ($item->version == 0 && $default_values) {
            $field->value = explode(",", $default_values);
        } else {
            if (!$field->value) {
                $field->value = array();
            } else {
                // Compatibility with old values, we no longer serialize all values to one, this way the field can be reversed more easily !!!
                $field->value = ($field_data = @unserialize($field->value[0])) ? $field_data : $field->value;
            }
        }
        $_itemids_catids = array();
        foreach ($field->value as $i => $val) {
            list($itemid, $catid) = explode(":", $val);
            $itemid = (int) $itemid;
            $catid = (int) $catid;
            $_itemids_catids[$itemid] = new stdClass();
            $_itemids_catids[$itemid]->itemid = $itemid;
            $_itemids_catids[$itemid]->catid = $catid;
            $_itemids_catids[$itemid]->value = $val;
        }
        $auto_relate_curritem = $field->parameters->get('auto_relate_curritem', 0);
        if ($auto_relate_curritem && !empty($_itemids_catids) && !FlexicontentHelperPerm::getPerm()->SuperAdmin) {
            $query = 'SELECT title, id, catid, state, alias ' . ' FROM #__content ' . ' WHERE id IN (' . implode(array_keys($_itemids_catids), ',') . ')';
            $db->setQuery($query);
            $rel_items = $db->loadObjectList();
            $i = 0;
            foreach ($rel_items as $rel_item) {
                $field->html .= '<input id="' . $ri_field_name . $i . '" name="' . $fieldname . '" type="hidden" value="' . $rel_item->id . ':' . $rel_item->catid . '" />';
                $field->html .= $rel_item->title . " <br/> \n";
                $i++;
            }
            return;
        }
        // ******************
        // SCOPE PARAMETERS
        // ******************
        // categories scope parameters
        $method_cat = $field->parameters->get('method_cat', 1);
        $usesubcats = $field->parameters->get('usesubcats', 0);
        $catids = $field->parameters->get('catids');
        if (empty($catids)) {
            $catids = array();
        } else {
            if (!is_array($catids)) {
                $catids = !FLEXI_J16GE ? array($catids) : explode("|", $catids);
            }
        }
        // types scope parameters
        $method_types = $field->parameters->get('method_types', 1);
        $types = $field->parameters->get('types');
        if (empty($types)) {
            $types = array();
        } else {
            if (!is_array($types)) {
                $types = !FLEXI_J16GE ? array($types) : explode("|", $types);
            }
        }
        // other limits of scope parameters
        $samelangonly = $field->parameters->get('samelangonly', 1);
        $onlypublished = $field->parameters->get('onlypublished', 1);
        $ownedbyuser = $field->parameters->get('ownedbyuser', 0);
        // ******************
        // EDITING PARAMETERS
        // ******************
        // some parameters shortcuts
        $size = $field->parameters->get('size', 12);
        $size = $size ? ' size="' . $size . '"' : '';
        $prepend_item_state = $field->parameters->get('prepend_item_state', 1);
        $maxtitlechars = $field->parameters->get('maxtitlechars', 40);
        $title_filter = $field->parameters->get('title_filter', 1);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $select_items_prompt = $field->parameters->get('select_items_prompt', 'FLEXI_RIFLD_SELECT_ITEMS_PROMPT');
        $selected_items_label = $field->parameters->get('selected_items_label', 'FLEXI_RIFLD_SELECTED_ITEMS_LABEL');
        $display_cat_filter_label = $field->parameters->get('display_cat_filter_label', 1);
        $display_title_filter_label = $field->parameters->get('display_title_filter_label', 1);
        $default_value_title_filter = $field->parameters->get('default_value_title_filter', '');
        // ***********************************************
        // Get & check Global category related permissions
        // ***********************************************
        require_once JPATH_ROOT . DS . 'components' . DS . 'com_flexicontent' . DS . 'helpers' . DS . 'permission.php';
        $viewallcats = FlexicontentHelperPerm::getPerm()->ViewAllCats;
        $viewtree = FlexicontentHelperPerm::getPerm()->ViewTree;
        if (!$viewtree) {
            $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::_('FLEXI_NO_ACCESS_LEVEL_TO_VIEW_CATEGORY_TREE') . '</div><div class="clear"></div>';
            return;
        }
        // ****************************************************
        // Calculate categories to use for retrieving the items
        // ****************************************************
        $allowed_cats = $disallowed_cats = false;
        // Get user allowed categories
        $usercats = FLEXI_J16GE || FLEXI_ACCESS ? FlexicontentHelperPerm::getAllowedCats($user, $actions_allowed = array('core.create', 'core.edit', 'core.edit.own'), $require_all = false, $check_published = true) : FlexicontentHelperPerm::returnAllCats($check_published = true, $specific_catids = null);
        // Find (if configured) , descendants of the categories
        if ($usesubcats) {
            global $globalcats;
            $_catids = array();
            foreach ($catids as $catid) {
                $subcats = $globalcats[$catid]->descendantsarray;
                foreach ($subcats as $subcat) {
                    $_catids[(int) $subcat] = 1;
                }
            }
            $catids = array_keys($_catids);
        }
        // ... TODO: retrieve items via AJAX
        // *********************************************
        // Item retrieving query ... CREATE WHERE CLAUSE
        // *********************************************
        $where = array();
        // **************
        // CATEGORY SCOPE
        // **************
        // Include method
        if ($method_cat == 3) {
            $allowed_cats = $viewallcats ? $catids : array_intersect($usercats, $catids);
            if (!empty($allowed_cats)) {
                $where[] = " rel.catid IN (" . implode(',', $allowed_cats) . ") ";
            } else {
                $field->html = JText::_('FLEXI_CANNOT_EDIT_FIELD') . ': <br/> ' . JText::_('FLEXI_NO_ACCESS_TO_USE_CONFIGURED_CATEGORIES');
                return;
            }
        } else {
            if ($method_cat == 2) {
                $disallowed_cats = $viewallcats ? $catids : array_diff($usercats, $catids);
                if (!empty($disallowed_cats)) {
                    $where[] = " rel.catid NOT IN (" . implode(',', $disallowed_cats) . ") ";
                }
            } else {
                if (!$viewallcats) {
                    $allowed_cats = $usercats;
                    if (!empty($allowed_cats)) {
                        $where[] = " rel.catid IN (" . implode(',', $allowed_cats) . ") ";
                    } else {
                        $field->html = JText::_('FLEXI_CANNOT_EDIT_FIELD') . ': <br/> ' . JText::_('FLEXI_NO_ACCESS_TO_USE_ANY_CATEGORIES');
                        return;
                    }
                }
            }
        }
        // TYPE SCOPE
        if (($method_types == 2 || $method_types == 3) && (!count($types) || empty($types[0]))) {
            $field->html = 'Content Type scope is set to include/exclude but no Types are selected in field configuration, please set to "ALL" or select types to include/exclude';
            return;
        }
        if ($method_types == 2) {
            $where[] = ' ie.type_id NOT IN (' . implode(',', $types) . ')';
        } else {
            if ($method_types == 3) {
                $where[] = ' ie.type_id IN (' . implode(',', $types) . ')';
            }
        }
        // include method
        // OTHER SCOPE LIMITS
        if ($samelangonly) {
            $where[] = $item->language == '*' ? " ie.language='*' " : " (ie.language='{$item->language}' OR ie.language='*') ";
        }
        if ($onlypublished) {
            $where[] = " i.state IN (1, -5) ";
        }
        if ($ownedbyuser == 1) {
            $where[] = " i.created_by = " . $user->id;
        } else {
            if ($ownedbyuser == 2) {
                $where[] = " i.created_by = " . $item->created_by;
            }
        }
        $where = !count($where) ? "" : " WHERE " . implode(" AND ", $where);
        // ***********************************************
        // Item retrieving query ... CREATE ORDERBY CLAUSE
        // ***********************************************
        $order = $field->parameters->get('orderby_form', 'alpha');
        // TODO: add more orderings: commented, rated
        $orderby = flexicontent_db::buildItemOrderBy($field->parameters, $order, $request_var = '', $config_param = '', $item_tbl_alias = 'i', $relcat_tbl_alias = 'rel', $default_order = '', $default_order_dir = '', $sfx = '_form', $support_2nd_lvl = false);
        // Create JOIN for ordering items by a most rated
        if (in_array('author', $order) || in_array('rauthor', $order)) {
            $orderby_join = ' LEFT JOIN #__users AS u ON u.id = i.created_by';
        }
        // *****************************************************
        // Item retrieving query ... put together and execute it
        // *****************************************************
        $query = 'SELECT i.title, i.id, i.catid, i.state, i.alias' . ", GROUP_CONCAT(rel.catid SEPARATOR ',') as catlist" . ' FROM #__content AS i ' . ($samelangonly || $method_types > 1 ? " LEFT JOIN #__flexicontent_items_ext AS ie on i.id=ie.item_id " : "") . ' JOIN #__flexicontent_cats_item_relations AS rel on i.id=rel.itemid ' . @$orderby_join . $where . " GROUP BY rel.itemid " . $orderby;
        $db->setQuery($query);
        $items_arr = $db->loadObjectList();
        if ($db->getErrorNum()) {
            echo $db->getErrorMsg();
            $field->html = '';
            return false;
        }
        // *******************************************************
        // Create category tree to use for selecting related items
        // *******************************************************
        require_once JPATH_ROOT . DS . "components" . DS . "com_flexicontent" . DS . "classes" . DS . "flexicontent.categories.php";
        $tree = flexicontent_cats::getCategoriesTree();
        // Get categories without filtering
        if ($allowed_cats) {
            foreach ($allowed_cats as $catid) {
                $allowedtree[$catid] = $tree[$catid];
            }
        }
        if ($disallowed_cats) {
            foreach ($disallowed_cats as $catid) {
                unset($tree[$catid]);
            }
            $allowedtree =& $tree;
        }
        if (!$allowed_cats && !$disallowed_cats) {
            $allowedtree =& $tree;
        }
        // *****************************************
        // Create field's HTML display for item form
        // *****************************************
        static $common_css_js_added = false;
        if (!$common_css_js_added) {
            $common_css_js_added = true;
            flexicontent_html::loadFramework('select2');
            $css = '' . '.fcrelation_field_used_items, .fcrelation_field_unused_items, .fcrelation_field_controls { display:inline-block; float:left !important; margin: 0 0 8px 0; }' . '.fcrelation_field_used_items.fc_vertical,   .fcrelation_field_unused_items.fc_vertical   { min-width: 100%; }' . '.fcrelation_field_used_items.fc_horizontal, .fcrelation_field_unused_items.fc_horizontal { margin: 8px 0%; }' . '.fcrelation_field_controls.fc_vertical   { min-width: 100%; }' . '.fcrelation_field_controls.fc_horizontal { max-width:6%; margin: 48px 1% 0 1%; width: auto; }' . '.fcrelation_field_controls.fc_horizontal span.fcrelation_btn { float: left !important; clear: both !important; }' . '.fcfield-placement-h.fc_horizontal { display: none !important; }' . '.fcfield-placement-v.fc_vertical { display: none !important; }' . '.fcrelation_field_filters { display:inline-block; float:left !important; }' . '.fcrelation_field_filters span.label { min-width: 140px; }' . '.fcrelation_field_used_items select, .fcrelation_field_unused_items select { min-width: 100%; margin:0px; }';
            if ($css) {
                $document->addStyleDeclaration($css);
            }
        }
        // The split up the items
        $items_options = '';
        $items_options_select = '';
        $items_options_unused = '';
        $state_shortname = array(1 => 'P', 0 => 'U', -1 => 'A', -3 => 'PE', -4 => 'OQ', -5 => 'IP');
        foreach ($items_arr as $itemdata) {
            $itemtitle = mb_strlen($itemdata->title) > $maxtitlechars ? mb_substr($itemdata->title, 0, $maxtitlechars) . "..." : $itemdata->title;
            if ($prepend_item_state) {
                $statestr = "[" . @$state_shortname[$itemdata->state] . "] ";
                $itemtitle = $statestr . $itemtitle . " ";
                //.$itemdata->catlist;
            }
            $itemcat_arr = explode(",", $itemdata->catlist);
            $classes_str = "";
            $itemid = $itemdata->id;
            foreach ($itemcat_arr as $catid) {
                $classes_str .= " " . "cat_" . $catid;
            }
            if (isset($_itemids_catids[$itemid])) {
                $items_options .= '<option class="' . $classes_str . '" value="' . $_itemids_catids[$itemid]->value . '" >' . $itemtitle . '</option>' . "\n";
                $items_options_select .= '<option selected="selected" class="' . $classes_str . '" value="' . $_itemids_catids[$itemid]->value . '" >' . $itemtitle . '</option>' . "\n";
            } else {
                $items_options_unused .= '<option class="' . $classes_str . '" value="' . $itemid . '" >' . $itemtitle . '</option>' . "\n";
            }
        }
        $cat_selected = count($allowedtree) == 1 ? reset($allowedtree) : '';
        $cat_selecor_box_style = count($allowedtree) == 1 ? 'style="display:none;" ' : '';
        $_cat_selector = flexicontent_cats::buildcatselect($allowedtree, $ri_field_name . '_fccats', $catvals = $cat_selected ? $cat_selected->id : '', $top = 2, ' class="use_select2_lib ' . $ri_field_name . '_fccats" ', $check_published = true, $check_perms = true, $actions_allowed = array('core.create', 'core.edit', 'core.edit.own'), $require_all = false, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options = array('__ALL__' => 'FLEXI_RIFLD_FILTER_LIST_ALL'));
        if ($title_filter) {
            $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/filterlist.js');
            $_title_filtering = '' . '<input class="fcfield_textval" id="' . $ri_field_name . '_regexp" name="' . $ri_field_name . '_regexp" onKeyUp="' . $ri_field_name . '_titlefilter.set(this.value)" size="30" onfocus="if (this.value==\'' . $default_value_title_filter . '\') this.value=\'\';" onblur="if (this.value==\'\') this.value=\'' . $default_value_title_filter . '\';" value="' . $default_value_title_filter . '" />' . '<input class="fcfield-button" type="button" onclick="' . $ri_field_name . '_titlefilter.reset();this.form.' . $ri_field_name . '_regexp.value=\'\'" value="' . JText::_('FLEXI_RIFLD_RESET') . '" />';
        }
        $field->html .= '
		<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">
			<span class="fcrelation_field_filters">
				
				<span class="fcrelation_field_filter_by_cat nowrap_box" ' . $cat_selecor_box_style . '>
					' . ($display_cat_filter_label ? '<span class="label">' . JText::_('FLEXI_RIFLD_FILTER_BY_CAT') . '</span>' : '') . '
					' . $_cat_selector . '
				</span>
				
				' . ($title_filter ? '
				<span class="fcrelation_field_filter_by_title nowrap_box">
					' . ($display_title_filter_label ? '<span class="label">' . JText::_('FLEXI_RIFLD_FILTER_BY_TITLE') . '</span>' : '') . '
	    		' . $_title_filtering . '
				</span>
				' : '') . '
				
			</span>
			<div class="fcclear"></div>
		';
        $initial_placement = $field->parameters->get('initial_placement', 'h');
        $placement_class = $initial_placement == 'h' ? ' fc_horizontal' : ' fc_vertical';
        $field->html .= '
			<span class="fcrelation_field_unused_items' . $placement_class . '">
				<span class="label">' . JText::_($select_items_prompt) . '</span><br/>
				<select id="' . $ri_field_name . '_visitems" name="' . $ri_field_name . '_visitems[]" multiple="multiple" class="fcfield_selectmulval" ' . $size . ' >
				</select>
			</span>
		
			<span class="fcrelation_field_controls' . $placement_class . '">
				<span id="btn-add_' . $ri_field_name . '" class="fcrelation_btn fcfield-list-add ' . $placement_class . '" title="' . JText::_('FLEXI_ADD') . '"></span>
				<span id="btn-remove_' . $ri_field_name . '" class="fcrelation_btn fcfield-list-del ' . $placement_class . '" title="' . JText::_('FLEXI_REMOVE') . '"></span>
				<span id="btn-toggle_horizontal_' . $ri_field_name . '" class="fcrelation_btn fcfield-placement-h fc_toggle ' . $placement_class . '" onclick="jQuery(this).closest(\'.valuebox\').find(\'.fc_vertical\').removeClass(\'fc_vertical\').addClass(\'fc_horizontal\');" title="' . JText::_('FLEXI_HORIZONTAL') . '"></span>
				<span id="btn-toggle_vertical_' . $ri_field_name . '" class="fcrelation_btn fcfield-placement-v fc_toggle ' . $placement_class . '" onclick="jQuery(this).closest(\'.valuebox\').find(\'.fc_horizontal\').removeClass(\'fc_horizontal\').addClass(\'fc_vertical\');" title="' . JText::_('FLEXI_VERTICAL') . '"></span>
			</span>
    	
    	<span class="fcrelation_field_used_items' . $placement_class . '">
				<span class="label">' . JText::_($selected_items_label) . '</span><br/>
				<select id="' . $ri_field_name . '" name="' . $fieldname . '" multiple="multiple" class="' . $required . '" style="display:none;" ' . $size . ' >
					' . $items_options_select . '
				</select>
				
				<select id="' . $ri_field_name . '_selitems" name="' . $ri_field_name . '_selitems[]" multiple="multiple" class="fcfield_selectmulval" ' . $size . ' >
					' . $items_options . '
				</select>
				
				<select id="' . $ri_field_name . '_hiditems" name="' . $ri_field_name . '_hiditems" style="display:none;" >
					' . $items_options_unused . '
				</select>
			</span>
		</div>
		';
        $js = ($title_filter ? ' var filteredfield, ' . $ri_field_name . '_titlefilter;' : '') . "\n\njQuery(document).ready(function() {\n\n" . ($title_filter ? '
	filteredfield = document.getElementById("' . $ri_field_name . '_visitems");
	' . $ri_field_name . '_titlefilter = new filterlist( filteredfield );
	' : '') . "\n\n  jQuery('#btn-add_" . $ri_field_name . "').click(function(){\n      jQuery('#" . $ri_field_name . "_visitems option:selected').each( function() {\n          jQuery('#" . $ri_field_name . "_selitems').append(\"<option class='\"+jQuery(this).attr('class')+\"' value='\"+jQuery(this).val()+\"'>\"+jQuery(this).text()+\"</option>\");\n          jQuery('#" . $ri_field_name . "').append(\"<option selected='selected' class='\"+jQuery(this).attr('class')+\"' value='\"+jQuery(this).val()+\"'>\"+jQuery(this).text()+\"</option>\");\n          jQuery(this).remove();\n      });\n  });\n  jQuery('#btn-remove_" . $ri_field_name . "').click(function(){\n      jQuery('#" . $ri_field_name . "_selitems option:selected').each( function() {\n          jQuery('#" . $ri_field_name . "_visitems').append(\"<option class='\"+jQuery(this).attr('class')+\"' value='\"+jQuery(this).val()+\"'>\"+jQuery(this).text()+\"</option>\");\n          jQuery(\"#" . $ri_field_name . " option[value='\"+jQuery(this).val()+\"']\").remove();\n          jQuery(this).remove();\n      });\n  });\n\n});\n\njQuery(document).ready(function() {\n\t\n\tjQuery('#" . $ri_field_name . "_fccats').change(function() {\n\t\t\n\t\tvar " . $ri_field_name . "_fccats_val = jQuery('#" . $ri_field_name . "_fccats').val();\n\t\t\n\t\t" . ($title_filter ? $ri_field_name . "_titlefilter.reset(); this.form." . $ri_field_name . "_regexp.value='';" : "") . "\n\t\t\n\t  jQuery('#" . $ri_field_name . "_visitems option').each( function() {\n\t  \tvar data = jQuery(this).val().split(':'); \n\t  \tvar itemid = data[0];\n\t  \tjQuery('#" . $ri_field_name . "_hiditems').append(\"<option class='\"+jQuery(this).attr('class')+\"' value='\"+itemid+\"'>\"+jQuery(this).text()+\"</option>\");\n\t  \tjQuery(this).remove();\n\t\t});\n\t\t\n\t  jQuery('#" . $ri_field_name . "_hiditems option').each( function() {\n\t  \tif ( " . $ri_field_name . "_fccats_val == '__ALL__' || jQuery(this).hasClass('cat_' + " . $ri_field_name . "_fccats_val ) ) {\n\t\t\t  jQuery('#" . $ri_field_name . "_visitems').append(\"<option class='\"+jQuery(this).attr('class')+\"'value='\"+jQuery(this).val()+\":\"+ " . $ri_field_name . "_fccats_val+\"'>\"+jQuery(this).text()+\"</option>\");\n\t\t\t\tjQuery(this).remove();\n\t  \t}\n\t\t});\n\t\t\n\t\t" . ($title_filter ? $ri_field_name . "_titlefilter.init();" : "") . "\n\t});\n\t" . (count($allowedtree) == 1 ? "jQuery('#" . $ri_field_name . "_fccats').trigger('change');" : "") . "\n\t\n});";
        $document->addScriptDeclaration($js);
    }