die('Illegal call');
}
$plugin_name = 'newsletter';
$oPage = new cPage();
$oRecipients = new RecipientCollection();
if (is_array($cfg['plugins']['recipients'])) {
    foreach ($cfg['plugins']['recipients'] as $plugin) {
        plugin_include("recipients", $plugin . "/" . $plugin . ".php");
    }
}
// Note, that the object name has to be $recipient for plugins
if ($action == "recipients_create" && $perm->have_perm_area_action($area, $action)) {
    $recipient = $oRecipients->create("*****@*****.**", " " . i18n("-- new recipient --", $plugin_name));
    $oPage->setReload();
} elseif ($action == "recipients_delete" && $perm->have_perm_area_action($area, $action)) {
    $oRecipients->delete($idrecipient);
    $recipient = new Recipient();
    $oPage->setReload();
} elseif ($action == "recipients_purge" && $perm->have_perm_area_action($area, "recipients_delete")) {
    $oClient = new cApiClient($client);
    $timeframe = $oClient->getProperty("newsletter", "purgetimeframe");
    if (!$timeframe) {
        $timeframe = 30;
    }
    $purgedrecipients = $oRecipients->purge($timeframe);
    /* backslashdollar: There is a problem translating \$ - it is either not recognized or translated correctly (using poEdit) */
    if ($purgedrecipients > 0) {
        $sNotis = $notification->messageBox("info", sprintf(str_replace("backslashdollar", "\$", i18n("%1backslashdollard recipients, which hasn't been confirmed since more than %2backslashdollard days has been removed.", $plugin_name)), $purgedrecipients, $timeframe), 0);
    } else {
        $sNotis = $notification->messageBox("info", sprintf(str_replace("backslashdollar", "\$", i18n("There are no recipients, which hasn't been confirmed since more than %2backslashdollard days has been removed.", $plugin_name)), 0, $timeframe), 0);
    }
 /**
  * Purge method to delete recipients which hasn't been confirmed since over a month
  * @param  $timeframe int    Days after creation a not confirmed recipient will be removed
  * @return int             Count of deleted recipients
  */
 public function purge($timeframe)
 {
     global $client, $lang;
     $oRecipientCollection = new RecipientCollection();
     // DATEDIFF(created, NOW()) > 30 would be better, but it's only available in MySQL V4.1.1 and above
     // Note, that, TO_DAYS or NOW may not be available in other database systems than MySQL
     $oRecipientCollection->setWhere("idclient", $client);
     $oRecipientCollection->setWhere("idlang", $lang);
     $oRecipientCollection->setWhere("confirmed", 0);
     $oRecipientCollection->setWhere("(TO_DAYS(NOW()) - TO_DAYS(created))", $timeframe, ">");
     $oRecipientCollection->query();
     while ($oItem = $oRecipientCollection->next()) {
         $oRecipientCollection->delete($oItem->get("idnewsrcp"));
     }
     return $oRecipientCollection->count();
 }