<?php
/*
Plugin - PlogBirthdays
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.
*/

                                                                                
/*core*/
include_once(PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php");
include_once(PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php");
include_once(PLOG_CLASS_PATH.
    "class/data/validator/integervalidator.class.php");
/*plugin*/
include_once(PLOG_CLASS_PATH.
    "plugins/plogbirthdays/class/view/adminplogbirthdaysview.class.php");
                                                                                
class AdminPlogBirthdaysSearchAction extends SiteAdminAction
{
  function AdminPlogBirthdaysSearchAction($actionInfo,$request)
  {
    $this->SiteAdminAction($actionInfo,$request);
  }
  function perform()
  {
    $pbdays = new PlogBirthdays();
    $page = $this->getCurrentPageFromRequest();

    $strValid = new StringValidator();
    $uintValid = new IntegerValidator();
    
    $namet = $this->_request->getValue("namek");
    if (!$strValid->validate($namet))
      $namet = "";
    $mt = $this->_request->getValue("month");
    if (!$uintValid->validate($mt))
      $mt = "";
    $dt = $this->_request->getValue("day");
    if (!$uintValid->validate($dt))
      $dt = "";
    $yt = $this->_request->getValue("year");
    if (!$uintValid->validate($yt))
      $yt = "";
    
    $bdays = array();
    $totalResults = 0;
    $op = "plogbirthdaysSearch&month=$mt&day=$dt&year=$yt&namek=$namet";
    if ($namet == "" && $mt == "" && $yt == "" && $dt == "")
    {
      $totalResults = $pbdays->getBirthdayCount();
      /* this constant defined by adminplogbirthdaysview */
      $bdays = $pbdays->getBirthdays(PLUGIN_PLOGBIRTHDAYS_BIRTHDAYS_PER_PAGE,
          $page);
    }
    else
    {
      /* this constant defined by adminplogbirthdaysview */
      $bdays = $pbdays->searchBirthdays(PLUGIN_PLOGBIRTHDAYS_BIRTHDAYS_PER_PAGE,
          $page,$namet,$mt,$dt,$yt,&$totalResults);
    }

    $this->_view = new AdminPlogBirthdaysView(
        $this->_blogInfo,$page,$totalResults,$op);

    $this->_view->setValue("birthdays",$bdays);

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

  /* this is a poor hack... */
  function getCurrentPageFromRequest()
  {
    /* Luckly these constants are defined by
     * view.class.php extended from adminplogbirthdaysview.class.php
     *
     * This method is stolen from view to abstract the page
     * some from view... make these actions useful
     *
     * Integer validator is already included by view (like the defines)
     * no need to include it again...
     */
    $page = HttpVars::getRequestValue( VIEW_DEFAULT_PAGE_PARAMETER );
                                                                                
    $val = new IntegerValidator();
    if( !$val->validate( $page ))
      $page = VIEW_DEFAULT_START_PAGE;
                                                                                
    return $page;
  }
}
                                                                                
/* vim:sw=2:cin:ai:expandtab:
   */
?>
