<?php
/*
PluginAdRotate
Copyright (C) 2005 Matthew Wood
                                                                                
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
*/

include_once(PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php");
include_once(PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php");

include_once(PLOG_CLASS_PATH.
    "plugins/adrotate/class/view/adminadrotatestatisticsview.class.php");
include_once(PLOG_CLASS_PATH.
    "plugins/adrotate/class/dao/adrotateadsstats.class.php");

class AdminAdRotateRemoveAdAction extends SiteAdminAction
{
  function AdminAdRotateRemoveAdAction($actionInfo,$request)
  {
    $this->SiteAdminAction($actionInfo,$request);
    $this->registerFieldValidator("adId",new ArrayValidator());

    $this->_view = new AdminAdRotateStatisticsView($this->_blogInfo);
    $this->setValidationErrorView($this->_view);
  }
  function validate()
  {
    return true;
  }
  function perform()
  {
    $ids = $this->_request->getValue("adId");
    $ads = new AdRotateAdsStats();
    
    $emsg = $smsg = "";

    foreach($ids as $adid) {
      $ad = $ads->getAd($adid);
      if (!$ad)
        $emsg .= "del fail - localize\n";
      else {
        $ads->deleteAd($adid);
        $smsg .= "del succeeded - localize\n";
      }
    }
    if ($smsg != "")
      $this->_view->setSuccessMessage($smsg);
    if ($emsg != "")
      $this->_view->setErrorMessage($emsg);

    $this->setCommonData();
    return true;
  }
}
?>
