<?php
/*
Plugin - PlogHaiku
Copyright (C) 2005 Darren Greer
                                                                                
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/blogowneradminaction.class.php");
include_once(PLOG_CLASS_PATH."plugins/ploghaiku/class/dao/ploghaikudao.class.php");
include_once(PLOG_CLASS_PATH."plugins/ploghaiku/class/dao/ploghaikuobject.class.php");
include_once(PLOG_CLASS_PATH."plugins/ploghaiku/class/view/managehaikuview.class.php");
include_once(PLOG_CLASS_PATH."class/data/validator/arrayvalidator.class.php");

class DeleteHaikuAction extends BlogOwnerAdminAction
{

  function perform()
  {
    $haikuDao = new PlogHaikuDao($this->_blogInfo);

    $emsg = $smsg = "";

    $haikuId = $this->_request->getValue('haikuid');
    $aryv = new ArrayValidator();
    if ($aryv->validate($haikuId))
    {
      foreach ($haikuId as $hid)
      {
        if($haikuDao->deleteHaiku($hid))
          $smsg .= $this->_locale->pr( "haiku_deleted_ok", $hid );
        else
          $emsg .= $this->_locale->pr( "error_deleting_haiku", $hid );
      }
    }

    $totalHaiku = $haikuDao->getHaikuCount($this->_blogInfo->getId());
    $haikuList = $haikuDao->getHaikuList(100,1,$this->_blogInfo->getId());

    $this->_view = new ManageHaikuView($this->_blogInfo,1,$totalHaiku,"manageHaikuView");
    $this->_view->setValue("haikuList",$haikuList);

    if ($smsg != "")
      $this->_view->setSuccessMessage($smsg);
    if ($emsg != "")
      $this->_view->setErrorMessage($emsg);

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

}

?>
