<div class="container topheader">
<div class="row">
<div class="span8">
    <h2><strong><?php 
echo $category->getLocalName();
?>
</strong></h2>
<p>
<?php 
echo Format::safe_html($category->getLocalDescriptionWithImages());
?>
</p>
<hr>
<div class="panel panel-default faqlist">
<?php 
$faqs = FAQ::objects()->filter(array('category' => $category))->exclude(array('ispublished' => FAQ::VISIBILITY_PRIVATE))->annotate(array('has_attachments' => SqlAggregate::COUNT(SqlCase::N()->when(array('attachments__inline' => 0), 1)->otherwise(null))))->order_by('-ispublished', 'question');
if ($faqs->exists(true)) {
    echo '
    <div class="panel-heading">
         <h2 class="panel-title">' . __('Frequently Asked Questions') . '</h2>
         </div>
      <div class="panel-body">
         <div id="faq">
            <ol>';
    foreach ($faqs as $F) {
        $attachments = $F->has_attachments ? '<span class="Icon file"></span>' : '';
        echo sprintf('
            <li><a href="faq.php?id=%d" >%s &nbsp;%s</a></li>', $F->getId(), Format::htmlchars($F->question), $attachments);
    }
    echo '  </ol>
         </div>
<?php

if (!defined('OSTCLIENTINC')) {
    die('Access Denied');
}
if ($_REQUEST['q'] || $_REQUEST['cid'] || $_REQUEST['topicId']) {
    //Search
    $faqs = FAQ::allPublic()->annotate(array('attachment_count' => SqlAggregate::COUNT('attachments'), 'topic_count' => SqlAggregate::COUNT('topics')))->order_by('question');
    if ($_REQUEST['cid']) {
        $faqs->filter(array('category_id' => $_REQUEST['cid']));
    }
    if ($_REQUEST['topicId']) {
        $faqs->filter(array('topics__topic_id' => $_REQUEST['topicId']));
    }
    if ($_REQUEST['q']) {
        $faqs->filter(Q::ANY(array('question__contains' => $_REQUEST['q'], 'answer__contains' => $_REQUEST['q'], 'keywords__contains' => $_REQUEST['q'], 'category__name__contains' => $_REQUEST['q'], 'category__description__contains' => $_REQUEST['q'])));
    }
    include CLIENTINC_DIR . 'kb-search.inc.php';
} else {
    //Category Listing.
    include CLIENTINC_DIR . 'kb-categories.inc.php';
}
"
            ><?php 
    echo $t->getFullName();
    ?>
</a></div>
<?php 
}
?>
        </section>
        <section>
            <div class="header"><?php 
echo __('Categories');
?>
</div>
<?php 
foreach (Category::objects()->annotate(array('faqs_count' => SqlAggregate::count('faqs')))->filter(array('faqs_count__gt' => 0)) as $C) {
    ?>
        <div><a href="?cid=<?php 
    echo urlencode($C->getId());
    ?>
"
            ><?php 
    echo $C->getLocalName();
    ?>
</a></div>
<?php 
}
?>
        </section>
    </div>
    </div>
    }
}
?>
                     </select>
                  </div>
                  <div class="col-md-3">
                     <input class="btn btn-block btn-info" type="submit" value="Search" id="searchSubmit" class="button">
                  </div>
               </div>
            </div>
         </form>
      </div>
      <div class="col-md-12">
         <div class="kb-results">
            <?php 
$categories = Category::objects()->exclude(Q::any(array('ispublic' => Category::VISIBILITY_PRIVATE, 'faqs__ispublished' => FAQ::VISIBILITY_PRIVATE)))->annotate(array('faq_count' => SqlAggregate::COUNT('faqs')))->filter(array('faq_count__gt' => 0));
if ($categories->exists(true)) {
    ?>
            <div class="well"><?php 
    echo __('Click on the category to browse FAQs.');
    ?>
</div>
            <ul id="kb">
               <?php 
    foreach ($categories as $C) {
        ?>
               <li>
                  <i></i>
                  <div style="margin-left:45px">
                     <h4><?php 
        echo sprintf('<a href="faq.php?cid=%d">%s (%d)</a>', $C->getId(), Format::htmlchars($C->getLocalName()), $C->faq_count);
<?php 
} else {
    echo __('NO FAQs found');
}
?>
</div>
<div class="span4">
    <div class="sidebar">
    <div class="searchbar">
        <form method="get" action="faq.php">
        <input type="hidden" name="a" value="search"/>
        <select name="topicId"  style="width:100%;max-width:100%"
            onchange="javascript:this.form.submit();">
            <option value="">— Browse by Topic —</option>
<?php 
$topics = Topic::objects()->annotate(array('has_faqs' => SqlAggregate::COUNT('faqs')))->filter(array('has_faqs__gt' => 0));
foreach ($topics as $T) {
    ?>
        <option value="<?php 
    echo $T->getId();
    ?>
"><?php 
    echo $T->getFullName();
    ?>
</option>
<?php 
}
?>
        </select>
        </form>
    </div>