<?php

require_once 'dummy.php';
require_once 'inc.sqltables.php';
if (!isset($data)) {
    $data = array('headline' => 'Forms', 'body' => array('Here you can view, edit, copy and delete your existing subscription forms, or add new subscription forms.', 'search', 'Usersearch:'), 'tablehead' => array('Name', 'Newsletters'), 'link' => array("edit" => "?p=de/3/1", "new" => "?p=de/3/1", "detail" => "?p=de/3/1", 'delete' => '?p=de/7/1', 'copy' => '#', 'save' => 'javascript:history.back();'));
}
$data['data'] = "SELECT id, name, '1' AS newsletters FROM " . $SQLTable['subscription_form'] . " WHERE domain_id='" . $GLOBALS['tnl_domain_id'] . "' ORDER BY name";
$data['buttons'] = 133;
echo drawList($data);
}
// set num results to total of news and teaser entries
$GLOBALS['num_results'] = countQuery("SELECT id FROM " . $SQLTable['content'] . $where);
$GLOBALS['max_results_per_page'] = 200;
if (isset($issue_id)) {
    $issue = new cIssue($issue_id);
    $nl = $issue->getNewsletter();
    $tm = new xoxNewsletterTheme($nl->template_html);
    $first = true;
    $all_subs = array();
    foreach ($tm->sub_name as $sub => $name) {
        $data['tablehead'] = array($name, 'Text');
        $sqls = "SELECT id,  title, body FROM " . $SQLTable['content'] . $where . " AND flags='" . $sub . "' ORDER BY displayorder";
        $data['data'] = $sqls;
        $data['buttons'] = 15;
        $data['sort'] = $sub;
        echo drawList($data, $first);
        $first = false;
        $all_subs[] = $sub;
    }
} else {
}
$num_results_subs = countQuery("SELECT id FROM " . $SQLTable['content'] . $where . " AND flags IN ('" . implode("','", $all_subs) . "')");
if ($num_results_subs < $GLOBALS['num_results']) {
    // now draw all entries without matching sub
    $data2 = $data;
    $data2['tablehead'] = array('Keiner Kategorie zugeordnet', 'Text');
    $data2['data'] = "SELECT id,  title, body FROM " . $SQLTable['content'] . $where . " AND flags NOT IN ('" . implode("','", $all_subs) . "') ORDER BY displayorder";
    $data2['sort'] = 'all';
    echo drawList($data2, false);
}