<?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/stringvalidator.class.php" );

class AddHaikuAction extends BlogOwnerAdminAction
{
  var $_text;
  var $_syl;
  
  function perform()
  {
    $emsg = $smsg = "";

    $haikuDao = new PlogHaikuDao();
    $text = $this->_request->getValue('text');
    $syl = $this->_request->getValue('syl');

    $val = new StringValidator();
    if( $val->validate( $text )) {
        // get the current date/time
        /* Need to localize */
        $l = new Locale("en_UK");
        $t = new Timestamp($your_sql_date);
        $dateString = $l->formatDate($t, "%Y-%m-%d %H:%M:%S");
     
        $haikuObject = new PlogHaikuObject('0',$syl,$text,$dateString,$this->_blogInfo->getOwner(),$this->_blogInfo->getId());
     
        if ($haikuDao->addHaiku($haikuObject))
        {
          $smsg .= $this->_locale->tr("haiku_added_ok")."<br/>";
        } else {
          $emsg .= $this->_locale->tr("error_adding_haiku")."<br/>";
        }
    }
    else {
        $emsg = $this->_locale->tr( "error_adding_haiku" );
    }
    
    $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;
  }

}

?>
