<?php

$Paging = new PerchPaging();
$Paging->set_per_page(24);
$API = new PerchAPI(1.0, 'perch_twitter');
$HTML = $API->get('HTML');
$ScheduledTweets = new PerchTwitter_ScheduledTweets();
$state = PerchUtil::get('filter', 'unsent');
switch ($state) {
    case 'sent':
        $tweets = $ScheduledTweets->all_sent($Paging);
        break;
    case 'unsent':
        $tweets = $ScheduledTweets->all_unsent($Paging);
        break;
}
<?php

$HTML = $API->get('HTML');
$Form = $API->get('Form');
if (!$CurrentUser->has_priv('perch_twitter.schedule')) {
    PerchUtil::redirect($API->app_path() . '/scheduled/');
}
$Tweets = new PerchTwitter_ScheduledTweets();
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
    $tweetID = (int) $_GET['id'];
    $Tweet = $Tweets->find($tweetID);
}
if (!$Tweet || !is_object($Tweet)) {
    PerchUtil::redirect($API->app_path() . '/scheduled/');
}
/* --------- Delete Form ----------- */
$Form = new PerchForm('delete');
if ($Form->posted() && $Form->validate()) {
    $Tweet->delete();
    if ($Form->submitted_via_ajax) {
        echo $API->app_path() . '/scheduled/';
        exit;
    } else {
        PerchUtil::redirect($API->app_path() . '/scheduled/');
    }
}