Exemplo n.º 1
0
    function category_manager($group_id = '', $update = FALSE)
    {
        global $DSP, $IN, $DB, $LANG, $SESS;
        if ($IN->GBL('Z') == 1) {
            if (!$DSP->allowed_group('can_admin_weblogs') and !$DSP->allowed_group('can_edit_categories')) {
                return $DSP->no_access_message();
            }
        } else {
            if (!$DSP->allowed_group('can_admin_weblogs')) {
                return $DSP->no_access_message();
            }
        }
        if ($group_id == '') {
            if (($group_id = $IN->GBL('group_id')) === FALSE or !is_numeric($group_id)) {
                return FALSE;
            }
        }
        /** ---------------------------------------
        		/**  Check discrete privileges
        		/** ---------------------------------------*/
        if ($IN->GBL('Z') == 1) {
            $query = $DB->query("SELECT can_edit_categories FROM exp_category_groups WHERE group_id = '" . $DB->escape_str($group_id) . "'");
            if ($query->num_rows == 0) {
                return FALSE;
            }
            $can_edit = explode('|', rtrim($query->row['can_edit_categories'], '|'));
            if ($SESS->userdata['group_id'] != 1 and !in_array($SESS->userdata['group_id'], $can_edit)) {
                return $DSP->no_access_message();
            }
        }
        $zurl = $IN->GBL('Z') == 1 ? AMP . 'Z=1' : '';
        $zurl .= $IN->GBL('cat_group') !== FALSE ? AMP . 'cat_group=' . $IN->GBL('cat_group') : '';
        $zurl .= $IN->GBL('integrated') !== FALSE ? AMP . 'integrated=' . $IN->GBL('integrated') : '';
        $query = $DB->query("SELECT group_name, sort_order FROM  exp_category_groups WHERE group_id = '" . $DB->escape_str($group_id) . "'");
        $group_name = $query->row['group_name'];
        $sort_order = $query->row['sort_order'];
        $r = '';
        if ($IN->GBL('Z') == 1) {
            $url = BASE . AMP . 'C=admin' . AMP . 'M=blog_admin' . AMP . 'P=edit_category' . AMP . 'group_id=' . $group_id . $zurl;
            $js = ' onclick="navjump(\'' . $url . '\');"  onmouseover="navCrumbOn();" onmouseout="navCrumbOff();" ';
            $r .= $DSP->anchor($url, '<div class="crumblinksR" style="width:300px;margin-left:auto;" id="rcrumb" ' . $js . '>' . $DSP->qdiv('itemWrapper', $LANG->line('new_category')) . '</div>');
        }
        $r .= $DSP->qdiv('tableHeading', $group_name);
        if ($update != FALSE) {
            $r .= $DSP->qdiv('box', $DSP->qspan('success', $LANG->line('category_updated')));
        }
        // Fetch the category tree
        $this->category_tree('table', $group_id, '', $sort_order);
        if (count($this->categories) == 0) {
            $r .= $DSP->qdiv('box', $DSP->qdiv('highlight', $LANG->line('no_category_message')));
        } else {
            $r .= $DSP->table('tableBorder', '0', '0') . $DSP->tr() . $DSP->table_qcell('tableHeadingAlt', 'ID', '2%') . $DSP->table_qcell('tableHeadingAlt', $LANG->line('order'), '8%') . $DSP->table_qcell('tableHeadingAlt', $LANG->line('category_name'), '50%') . $DSP->table_qcell('tableHeadingAlt', $LANG->line('edit'), '20%') . $DSP->table_qcell('tableHeadingAlt', $LANG->line('delete'), '20%');
            $r .= $DSP->tr_c();
            foreach ($this->categories as $val) {
                $prefix = strlen($val['0']) == 1 ? NBS . NBS : NBS;
                $r .= $val;
            }
            $r .= $DSP->table_c();
            $r .= $DSP->qdiv('defaultSmall', '');
            // Category order
            if ($IN->GBL('Z') == FALSE) {
                $r .= $DSP->form_open(array('action' => 'C=admin' . AMP . 'M=blog_admin' . AMP . 'P=global_cat_order' . AMP . 'group_id=' . $group_id . $zurl));
                $r .= $DSP->div('box320');
                $r .= $DSP->qdiv('defaultBold', $LANG->line('global_sort_order'));
                $r .= $DSP->div('itemWrapper');
                $r .= $DSP->input_radio('sort_order', 'a', $sort_order == 'a' ? 1 : '') . NBS . $LANG->line('alpha') . NBS . NBS . $DSP->input_radio('sort_order', 'c', $sort_order != 'a' ? 1 : '') . NBS . $LANG->line('custom');
                $r .= NBS . NBS . NBS . $DSP->input_submit($LANG->line('update'));
                $r .= $DSP->div_c();
                $r .= $DSP->div_c();
                $r .= $DSP->form_close();
            }
        }
        // Build category tree for javascript replacement
        if ($IN->GBL('Z') == 1) {
            if (!class_exists('Publish')) {
                require PATH_CP . 'cp.publish' . EXT;
            }
            $PUB = new Publish();
            $PUB->category_tree($IN->GBL('cat_group') !== FALSE ? $IN->GBL('cat_group') : $IN->GBL('group_id'), 'new', '', '', $IN->GBL('integrated') == 'y' ? 'y' : 'n');
            $cm = "";
            foreach ($PUB->categories as $val) {
                $cm .= $val;
            }
            $cm = preg_replace("/(\r\n)|(\r)|(\n)/", '', $cm);
            $DSP->extra_header = '
			<script type="text/javascript"> 
				
				function update_cats() 
				{
					var str = "' . $cm . '";
					opener.swap_categories(str);
					window.close();
				}
				
			</script>';
            // $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultCenter', '<a href="javascript:update_cats();"><b>'.$LANG->line('update_publish_cats').'</b></a>'));
            $r .= '<form>';
            $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('defaultCenter', '<input type="submit" value="' . NBS . $LANG->line('update_publish_cats') . NBS . '" onclick="update_cats();"/>'));
            $r .= '</form>';
        }
        // Assign output data
        $DSP->title = $LANG->line('categories');
        $DSP->crumb = $DSP->anchor(BASE . AMP . 'C=admin' . AMP . 'area=weblog_administration', $LANG->line('weblog_administration')) . $DSP->crumb_item($DSP->anchor(BASE . AMP . 'C=admin' . AMP . 'M=blog_admin' . AMP . 'P=categories', $LANG->line('category_groups'))) . $DSP->crumb_item($LANG->line('categories'));
        $DSP->right_crumb($LANG->line('new_category'), BASE . AMP . 'C=admin' . AMP . 'M=blog_admin' . AMP . 'P=edit_category' . AMP . 'group_id=' . $group_id);
        $DSP->body = $r;
    }