Exemplo n.º 1
0
function cat_event_category_list($event)
{
    $out = n . n . hed(gTxt($event . '_head') . sp . popHelp($event . '_category'), 3) . form(fInput('text', 'title', '', 'edit', '', '', 20) . fInput('submit', '', gTxt('Create'), 'smallerbox') . eInput('category') . sInput('cat_' . $event . '_create'), '', '', 'post', 'action-create ' . $event);
    $rs = getTree('root', $event);
    if ($rs) {
        $total_count = array();
        if ($event == 'article') {
            $rs2 = safe_rows_start('Category1, count(*) as num', 'textpattern', "1 = 1 group by Category1");
            while ($a = nextRow($rs2)) {
                $name = $a['Category1'];
                $num = $a['num'];
                $total_count[$name] = $num;
            }
            $rs2 = safe_rows_start('Category2, count(*) as num', 'textpattern', "1 = 1 group by Category2");
            while ($a = nextRow($rs2)) {
                $name = $a['Category2'];
                $num = $a['num'];
                if (isset($total_count[$name])) {
                    $total_count[$name] += $num;
                } else {
                    $total_count[$name] = $num;
                }
            }
        } else {
            switch ($event) {
                case 'link':
                    $rs2 = safe_rows_start('category, count(*) as num', 'txp_link', "1 group by category");
                    break;
                case 'image':
                    $rs2 = safe_rows_start('category, count(*) as num', 'txp_image', "1 group by category");
                    break;
                case 'file':
                    $rs2 = safe_rows_start('category, count(*) as num', 'txp_file', "1 group by category");
                    break;
            }
            while ($a = nextRow($rs2)) {
                $name = $a['category'];
                $num = $a['num'];
                $total_count[$name] = $num;
            }
        }
        $items = array();
        $ctr = 1;
        foreach ($rs as $a) {
            extract($a);
            // format count
            switch ($event) {
                case 'article':
                    $url = 'index.php?event=list' . a . 'search_method=categories' . a . 'crit=' . $name;
                    break;
                case 'link':
                    $url = 'index.php?event=link' . a . 'search_method=category' . a . 'crit=' . $name;
                    break;
                case 'image':
                    $url = 'index.php?event=image' . a . 'search_method=category' . a . 'crit=' . $name;
                    break;
                case 'file':
                    $url = 'index.php?event=file' . a . 'search_method=category' . a . 'crit=' . $name;
                    break;
            }
            $count = isset($total_count[$name]) ? '(' . href($total_count[$name], $url) . ')' : '(0)';
            if (empty($title)) {
                $edit_link = '<em>' . eLink('category', 'cat_' . $event . '_edit', 'id', $id, gTxt('untitled')) . '</em>';
            } else {
                $edit_link = eLink('category', 'cat_' . $event . '_edit', 'id', $id, $title);
            }
            $items[] = graf(checkbox('selected[]', $id, 0) . sp . str_repeat(sp . sp, $level * 2) . $edit_link . sp . small($count), ' class="' . ($ctr % 2 == 0 ? 'even' : 'odd') . ' level-' . $level . '"');
            $ctr++;
        }
        if ($items) {
            $out .= cat_article_multiedit_form($event, $items);
        }
    } else {
        $out .= graf(gTxt('no_categories_exist'));
    }
    return $out;
}
Exemplo n.º 2
0
function cat_event_category_list($event)
{
    $rs = getTree('root', $event);
    $parent = ps('parent_cat');
    $heading = 'tab_' . ($event == 'article' ? 'list' : $event);
    $for = $rs ? ' for="' . $event . '_category_parent"' : '';
    $out = n . n . hed(gTxt($heading) . sp . popHelp($event . '_category'), 2) . form(fInput('text', 'title', '', '', '', '', INPUT_REGULAR) . ($rs ? '<div class="parent"><label' . $for . '>' . gTxt('parent') . '</label>' . treeSelectInput('parent_cat', $rs, $parent, $event . '_category_parent') . '</div>' : '') . n . fInput('submit', '', gTxt('Create')) . n . eInput('category') . n . sInput('cat_' . $event . '_create'), '', '', 'post', 'action-create ' . $event);
    if ($rs) {
        $total_count = array();
        if ($event == 'article') {
            // Count distinct articles for both categories, avoid duplicates
            $rs2 = getRows('select category, count(*) as num from (' . 'select ID, Category1 as category from ' . safe_pfx('textpattern') . ' union ' . 'select ID, Category2 as category from ' . safe_pfx('textpattern') . ') as t where category != "" group by category');
            if ($rs2 !== false) {
                foreach ($rs2 as $a) {
                    $total_count[$a['category']] = $a['num'];
                }
            }
        } else {
            switch ($event) {
                case 'link':
                    $rs2 = safe_rows_start('category, count(*) as num', 'txp_link', "1 group by category");
                    break;
                case 'image':
                    $rs2 = safe_rows_start('category, count(*) as num', 'txp_image', "1 group by category");
                    break;
                case 'file':
                    $rs2 = safe_rows_start('category, count(*) as num', 'txp_file', "1 group by category");
                    break;
            }
            while ($a = nextRow($rs2)) {
                $name = $a['category'];
                $num = $a['num'];
                $total_count[$name] = $num;
            }
        }
        $items = array();
        foreach ($rs as $a) {
            extract($a);
            // format count
            switch ($event) {
                case 'article':
                    $url = 'index.php?event=list' . a . 'search_method=categories' . a . 'crit=' . $name;
                    break;
                case 'link':
                    $url = 'index.php?event=link' . a . 'search_method=category' . a . 'crit=' . $name;
                    break;
                case 'image':
                    $url = 'index.php?event=image' . a . 'search_method=category' . a . 'crit=' . $name;
                    break;
                case 'file':
                    $url = 'index.php?event=file' . a . 'search_method=category' . a . 'crit=' . $name;
                    break;
            }
            $count = isset($total_count[$name]) ? href('(' . $total_count[$name] . ')', $url) : '(0)';
            if (empty($title)) {
                $edit_link = '<em>' . eLink('category', 'cat_' . $event . '_edit', 'id', $id, gTxt('untitled')) . '</em>';
            } else {
                $edit_link = eLink('category', 'cat_' . $event . '_edit', 'id', $id, $title);
            }
            $items[] = graf(checkbox('selected[]', $id, 0) . sp . str_repeat(sp . sp, $level * 2) . $edit_link . sp . $count, ' class="level-' . $level . '"');
        }
        if ($items) {
            $out .= cat_article_multiedit_form($event, $items);
        }
    } else {
        $out .= graf(gTxt('no_categories_exist'));
    }
    return $out;
}
Exemplo n.º 3
0
/**
 * Renders a list of categories.
 *
 * @param  string $event Type of category
 * @return string HTML
 */
function cat_event_category_list($event)
{
    $rs = getTree('root', $event);
    $parent = ps('parent_cat');
    $heading = 'tab_' . ($event == 'article' ? 'list' : $event);
    $for = $rs ? ' for="' . $event . '_category_parent"' : '';
    $out = hed(gTxt($heading) . popHelp($event . '_category'), 2) . form(graf(tag(gTxt('create_new_category'), 'label', array('for' => $event . '_category_new')) . br . fInput('text', 'title', '', '', '', '', INPUT_REGULAR, '', $event . '_category_new')) . ($rs ? graf('<label' . $for . '>' . gTxt('parent') . '</label>' . br . treeSelectInput('parent_cat', $rs, $parent, $event . '_category_parent'), array('class' => 'parent')) : '') . graf(fInput('submit', '', gTxt('Create')) . eInput('category') . sInput('cat_' . $event . '_create')), '', '', 'post', $event);
    if ($rs) {
        $total_count = array();
        if ($event == 'article') {
            // Count distinct articles for both categories, avoid duplicates.
            $rs2 = getRows("SELECT category, COUNT(*) AS num FROM (\n                    SELECT ID, Category1 AS category FROM " . safe_pfx('textpattern') . "\n                        UNION\n                    SELECT ID, Category2 AS category FROM " . safe_pfx('textpattern') . "\n                ) AS t WHERE category != '' GROUP BY category");
            if ($rs2 !== false) {
                foreach ($rs2 as $a) {
                    $total_count[$a['category']] = $a['num'];
                }
            }
        } else {
            switch ($event) {
                case 'link':
                    $rs2 = safe_rows_start("category, COUNT(*) AS num", 'txp_link', "1 = 1 GROUP BY category");
                    break;
                case 'image':
                    $rs2 = safe_rows_start("category, COUNT(*) AS num", 'txp_image', "1 = 1 GROUP BY category");
                    break;
                case 'file':
                    $rs2 = safe_rows_start("category, COUNT(*) AS num", 'txp_file', "1 = 1 GROUP BY category");
                    break;
            }
            while ($a = nextRow($rs2)) {
                $name = $a['category'];
                $num = $a['num'];
                $total_count[$name] = $num;
            }
        }
        $items = array();
        foreach ($rs as $a) {
            extract($a);
            // Format count.
            switch ($event) {
                case 'article':
                    $url = 'index.php?event=list' . a . 'search_method=categories' . a . 'crit=' . $name;
                    break;
                case 'link':
                    $url = 'index.php?event=link' . a . 'search_method=category' . a . 'crit=' . $name;
                    break;
                case 'image':
                    $url = 'index.php?event=image' . a . 'search_method=category' . a . 'crit=' . $name;
                    break;
                case 'file':
                    $url = 'index.php?event=file' . a . 'search_method=category' . a . 'crit=' . $name;
                    break;
            }
            $count = isset($total_count[$name]) ? href('(' . $total_count[$name] . ')', $url) : '(0)';
            if (empty($title)) {
                $edit_link = '<em>' . eLink('category', 'cat_' . $event . '_edit', 'id', $id, gTxt('untitled')) . '</em>';
            } else {
                $edit_link = eLink('category', 'cat_' . $event . '_edit', 'id', $id, $title);
            }
            $items[] = graf(checkbox('selected[]', $id, 0) . sp . str_repeat(sp . sp, $level * 2) . $edit_link . sp . $count, ' class="level-' . $level . '"');
        }
        if ($items) {
            $out .= cat_article_multiedit_form($event, $items);
        }
    } else {
        $out .= graf(span(null, array('class' => 'ui-icon ui-icon-info')) . ' ' . gTxt('no_categories_exist'), array('class' => 'alert-block information'));
    }
    return $out;
}
Exemplo n.º 4
0
function cat_event_category_list($evname)
{
    global $prefs;
    if ($evname == 'article') {
        $headspan = $prefs['show_article_category_count'] ? 3 : 2;
    }
    $o = hed(gTxt($evname . '_head') . popHelp($evname . '_category'), 3);
    $o .= form(fInput('text', 'name', '', 'edit', '', '', 10) . fInput('submit', '', gTxt('Create'), 'smallerbox') . eInput('category') . sInput('cat_' . $evname . '_create'));
    $rs = getTree('root', $evname);
    if ($rs) {
        foreach ($rs as $a) {
            extract($a);
            if ($name == 'root') {
                continue;
            }
            //Stuff for articles only
            if ($evname == 'article' && $prefs['show_article_category_count']) {
                $sname = doSlash($name);
                $count = sp . small(safe_count("textpattern", "((Category1='{$sname}') or (Category2='{$sname}'))"));
            } else {
                $count = '';
            }
            $cbox = checkbox('selected[]', $id, 0);
            $editlink = eLink('category', 'cat_' . $evname . '_edit', 'id', $id, $title);
            $items[] = graf($cbox . sp . str_repeat(sp, max(0, $level - 1) * 2) . $editlink . $count);
        }
        if (!empty($items)) {
            $o .= cat_article_multiedit_form($evname, $items);
        }
    }
    return $o;
}