1<div class="row">
2<div class="span8">
3<?php
4    $categories = Category::objects()
5        ->exclude(Q::any(array(
6            'ispublic'=>Category::VISIBILITY_PRIVATE,
7            Q::all(array(
8                    'faqs__ispublished'=>FAQ::VISIBILITY_PRIVATE,
9                    'children__ispublic' => Category::VISIBILITY_PRIVATE,
10                    'children__faqs__ispublished'=>FAQ::VISIBILITY_PRIVATE,
11                    ))
12        )))
13        //->annotate(array('faq_count'=>SqlAggregate::COUNT('faqs__ispublished')));
14        ->annotate(array('faq_count' => SqlAggregate::COUNT(
15                        SqlCase::N()
16                        ->when(array(
17                                'faqs__ispublished__gt'=> FAQ::VISIBILITY_PRIVATE), 1)
18                        ->otherwise(null)
19        )))
20        ->annotate(array('children_faq_count' => SqlAggregate::COUNT(
21                        SqlCase::N()
22                        ->when(array(
23                                'children__faqs__ispublished__gt'=> FAQ::VISIBILITY_PRIVATE), 1)
24                        ->otherwise(null)
25        )));
26
27       // ->filter(array('faq_count__gt' => 0));
28    if ($categories->exists(true)) { ?>
29        <div><?php echo __('Click on the category to browse FAQs.'); ?></div>
30        <ul id="kb">
31<?php
32        foreach ($categories as $C) {
33            // Don't show subcategories with parents.
34            if (($p=$C->parent)
35                    && ($categories->findFirst(array(
36                                'category_id' => $p->getId()))))
37                continue;
38
39            $count = $C->faq_count + $C->children_faq_count;
40            ?>
41            <li><i></i>
42            <div style="margin-left:45px">
43            <h4><?php echo sprintf('<a href="faq.php?cid=%d">%s %s</a>',
44                $C->getId(), Format::htmlchars($C->getLocalName()),
45                $count ? "({$count})": ''
46                ); ?></h4>
47            <div class="faded" style="margin:10px 0">
48                <?php echo Format::safe_html($C->getLocalDescriptionWithImages()); ?>
49            </div>
50<?php
51            if (($subs=$C->getPublicSubCategories())) {
52                echo '<p/><div style="padding-bottom:15px;">';
53                foreach ($subs as $c) {
54                    echo sprintf('<div><i class="icon-folder-open"></i>
55                            <a href="faq.php?cid=%d">%s (%d)</a></div>',
56                            $c->getId(),
57                            $c->getLocalName(),
58                            $c->faq_count
59                            );
60                }
61                echo '</div>';
62            }
63
64            foreach ($C->faqs
65                    ->exclude(array('ispublished'=>FAQ::VISIBILITY_PRIVATE))
66                    ->limit(5) as $F) { ?>
67                <div class="popular-faq"><i class="icon-file-alt"></i>
68                <a href="faq.php?id=<?php echo $F->getId(); ?>">
69                <?php echo $F->getLocalQuestion() ?: $F->getQuestion(); ?>
70                </a></div>
71<?php       } ?>
72            </div>
73            </li>
74<?php   } ?>
75       </ul>
76<?php
77    } else {
78        echo __('NO FAQs found');
79    }
80?>
81</div>
82<div class="span4">
83    <div class="sidebar">
84    <div class="searchbar">
85        <form method="get" action="faq.php">
86        <input type="hidden" name="a" value="search"/>
87        <select name="topicId"  style="width:100%;max-width:100%"
88            onchange="javascript:this.form.submit();">
89            <option value="">—<?php echo __("Browse by Topic"); ?>—</option>
90<?php
91$topics = Topic::objects()
92    ->annotate(array('has_faqs'=>SqlAggregate::COUNT('faqs')))
93    ->filter(array('has_faqs__gt'=>0));
94foreach ($topics as $T) { ?>
95        <option value="<?php echo $T->getId(); ?>"><?php echo $T->getFullName();
96            ?></option>
97<?php } ?>
98        </select>
99        </form>
100    </div>
101    <br/>
102    <div class="content">
103        <section>
104            <div class="header"><?php echo __('Other Resources'); ?></div>
105        </section>
106    </div>
107    </div>
108</div>
109</div>
110