<?php   
    Header("Cache-Control: no-cache");
    Header("Pragma: no-cache");
    Header("Expires: Sat, Jan 01 2000 01:01:01 GMT");

    include("global.inc");

function content()
{    

    content_start();
    header_start();
    header_left();
    global $user;
    echo L_FOLDERS . " - $user - " . PROG_NAME;
      
    header_left_right_end();
    header_right();

    global $folder;
?>
    <form action="index.php" method="get">
    <input type="hidden" name="folder" value="<?php echo $folder ?>">
    <input type="submit" value="<?php echo L_GO_BACK_BTN ?>">
    </form>
<?php
    header_left_right_end();
    header_end();
    body_start();
    title_start();
    title_left();    
    echo L_FOLDER_NAME;
    title_left_end();
    title_left('width="20%"');
    echo L_NUM_MESSAGES;
    title_left_end();
    title_end();

    global $mailbox;
    global $name, $action;

    $folder_str = construct_folder_str($name);
    if($action == "create")
    {
        imap_createmailbox($mailbox, IMAP_STR . "$folder_str");
    }
    if($action == "delete")
    {
        imap_deletemailbox($mailbox, IMAP_STR . "$folder_str");
    }
    $mailboxes = imap_listmailbox($mailbox, IMAP_STR, FILTER. "*");
    if($mailboxes)
    {
        sort($mailboxes);
        $first = "rowoff";
        $second = "rowon";
        if (FILTER != "INBOX" && NO_INBOX_EXPLICIT != 1)
        {
            body_row('class="rowon"');
            body_left();
            echo "<a href=\"index.php?folder=INBOX\">INBOX</a>";
            body_left_end();
            body_left();
            echo imap_num_msg($mailbox);
            body_left_end();
            body_row_end();
            $first = "rowon";
            $second = "rowoff";
        }
        for ($i = 0; $i < count($mailboxes); $i++)
        {
            $bg = (($i + 1)/2 == floor(($i + 1)/2)) ? $first : $second;
            imap_reopen($mailbox, $mailboxes[$i]);
            $nm = substr($mailboxes[$i], strrpos($mailboxes[$i], "}") + 1, strlen($mailboxes[$i]));
            body_row('class="' . $bg . '"');
            body_left();
            if ($nm != "INBOX")
            {
                $nm = deconstruct_folder_str($nm);
            }

            $url_nm = urlencode($nm);

            echo "<a href=\"index.php?folder=$url_nm\">$nm</a>";
            body_left_end();
            body_left();
            echo imap_num_msg($mailbox);
            body_left_end();
            body_row_end();
        }
    }
    else
    {
        body_row('class="rowon"');
        body_left();
        echo "<a href=\"index.php?folder=INBOX\">INBOX</a>";
        body_left_end();
        body_left();
        echo imap_num_msg($mailbox);
        body_left_end();
        body_row_end();
    }
    imap_close($mailbox);
    body_end();

    header_start();
    header_left('colspan="2"');
    ?>

<form action="folder.php" method="get">
<select name="action">
<option value="create"><?php echo L_FOLDER_CREATE ?>
<option value="delete"><?php echo L_FOLDER_DELETE ?>
</select> <label for="name"><?php echo L_NAMED ?></label>
<input type="text" name="name" id="name"><input type="hidden" name="folder" value="<?php echo $folder ?>">
<input type="submit" value="<?php echo L_SUBMIT_BTN ?>">
</form>


<?php
    header_left_right_end();
    header_end();
    content_end();
}



/* MAIN */
include(HTML_TEMPLATE);
 
?>
