以前写的php日历页面的后台,现在自己都有些看不懂了:)

以前写的php日历页面的后台,现在自己都有些看不懂了:)

<?php

/* Reminder: always indent with 4 spaces (no tabs). */

// +—————————————————————————+

// | Copyright (c) 2006, Demian Turner                                         |

// | All rights reserved.                                                      |

// |                                                                           |

// | Redistribution and use in source and binary forms, with or without        |

// | modification, are permitted provided that the following conditions        |

// | are met:                                                                  |

// |                                                                           |

// | o Redistributions of source code must retain the above copyright          |

// |   notice, this list of conditions and the following disclaimer.           |

// | o Redistributions in binary form must reproduce the above copyright       |

// |   notice, this list of conditions and the following disclaimer in the     |

// |   documentation and/or other materials provided with the distribution.    |

// | o The names of the authors may not be used to endorse or promote          |

// |   products derived from this software without specific prior written      |

// |   permission.                                                             |

// |                                                                           |

// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       |

// | “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         |

// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR     |

// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |

// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     |

// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT          |

// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     |

// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     |

// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       |

// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE     |

// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.      |

// |                                                                           |

// +—————————————————————————+

// | Seagull 0.6                                                               |

// +—————————————————————————+

// | calendarMgr.php                                                    |

// +—————————————————————————+

// | Author: Alouicious Bird <jiangtao@andigo.com>                                  |

// +—————————————————————————+

// $Id: CalendarMgr.php,v 1.6 2006/08/17 08:24:50 jiangtao Exp $

require_once ‘DB/DataObject.php’;

/**

 *  calendar used files ;

 */

require_once ‘Calendar/Month/Weekdays.php’;

require_once ‘Calendar/Calendar.php’;

/**

 * Type your class description here …

 *

 * @package calendar

 * @author  Jiangtao Chen <jiangtao@andigo.com>

 */

class CalendarMgr extends SGL_Manager {

 function CalendarMgr() {

  SGL :: logMessage(null, PEAR_LOG_DEBUG);

  parent :: SGL_Manager();

  $this->pageTitle = ‘Calendar Manager’;

  $this->template = ‘calendarList.html’;

  $this->_aActionsMapping = array (

   ‘list’ => array (

    ‘list’

   ),

   /*

    * Tony add

    */

   ‘eventDetail’ => array (

    ‘eventDetail’

   ),

   ‘dayEventList’ => array (

    ‘dayEventList’

   ),

   ‘monthEventList’ => array (

    ‘monthEventList’

   ),

  

  );

 }

 function validate($req, & $input) {

  SGL :: logMessage(null, PEAR_LOG_DEBUG);

  $this->validated = true;

  $input->error = array ();

  $input->pageTitle = $this->pageTitle;

  $input->masterTemplate = $this->masterTemplate;

  $input->template = $this->template;

  $input->action = ($req->get(‘action’)) ? $req->get(‘action’) : ‘list’;

  $input->aDelete = $req->get(‘frmDelete’);

  $input->submitted = $req->get(‘submitted’);

  $input->calendar = (object) $req->get(‘calendar’);

  $input->calendarId = $req->get(‘frmCalendarID’);

  $input->calendarDate = $req->get(‘frmCalendarDate’);

  $input->calendar_id = $req->get(‘calendar_id’);

  $input->year = $req->get(‘year’);

  $input->month = $req->get(‘month’);

  $input->day = $req->get(‘day’);

  $input->flag = $req->get(‘flag’);

   if ($input->submitted || in_array($input->action, array(‘insert’, ‘update’))) {

            if (empty($input->calendar->newsdate)) {

                $aErrors[‘newsdate’] = ‘Please fill in a newsdate’;

            }

            if (empty($input->calendar->newstitle)) {

                $aErrors[‘newstitle’] = ‘Please fill in an newstitle’;

            }

            if(empty($input->calendar->newsdetail)){

             $aErrors[‘newsdetail’] = ‘Please fill in an newsdetail’;;

            }

        }

        //  if errors have occured

        if (isset($aErrors) && count($aErrors)) {

            SGL::raiseMsg(‘Please fill in the indicated fields’);

            $input->error = $aErrors;

            $input->template = ‘calendarEdit.html’;

            $this->validated = false;

           

             // save currect title

            if ($input->action == ‘insert’) {

                $input->pageTitle .= ‘ :: Add’;

            } elseif ($input->action == ‘update’) {

                $input->pageTitle .= ‘ :: Edit’;

            }

        }

 

 }

 function display(& $output) {

  if ($this->conf[‘CalendarMgr’][‘showUntranslated’] == false) {

   $c = & SGL_Config :: singleton();

   $c->set(‘debug’, array (

    ‘showUntranslated’ => false

   ));

  }

 }

 /*

  * echo event detail

  * @authour cjt

  */

 function _cmd_eventDetail(& $input, & $output) {

  SGL :: logMessage(null, PEAR_LOG_DEBUG);

  $output->template = ‘calendarEvent.html’;

  $output->pageTitle = ‘CalendarMgr :: EchoEventDeail’;

  /**

   * DB_DataObject :: factory($this->conf[‘table’][‘faq’]) return $class

   * needs DataObjects_Calendar class in /var/entities/Calendar.php

   *  else error!!

   */

  

  $output->month=$input->month;//show month

  $output->year=$input->year;//echo year

 

  //make back parameter This’s needs!!

  if($input->flag==”dayEventList”){

   $output->backParam=”frmCalendarDate=”.$input->calendarDate.”&month=”.$input->month.”&year=”.$input->year;

   $output->flag=”dayEventList”;

  }else if($input->flag==”monthEventList”){

   $output->backParam=”month=”.$input->month.”&year=”.$input->year;

   $output->flag=”monthEventList”;

  }else if($input->flag==”event”){

   $output->backParam=”month=”.$input->month.”&year=”.$input->year;

   $output->flag=”list”;

  }

 

  $calendar = DB_DataObject :: factory($this->conf[‘table’][‘calendar’]);

  //$calendar->orderBy(‘newsdate’);

  $calendar->newsid = $input->calendarId;

  //echo “calendar= “.$input->calendarId;

  //echo get_class ( $calendar );//test

  $result = $calendar->find();

  $events = array ();

  /**

   * gain data from table.

   */

  if ($result > 0) {

   while ($calendar->fetch()) {

    $calendar->newstitle = $calendar->newstitle;

    $calendar->newsdate = $calendar->newsdate;

    $calendar->newsdetail = nl2br($calendar->newsdetail); //will /n

    $events[] = clone ($calendar);

//    $output->month=substr($calendar->newsdate,0,4);//show month

//    $output->year=substr($calendar->newsdate,5,2);//show year;

   }

  }

  $output->results = $events;

 }

 /**

  *  warranty ( accoding to ) event list 

  */

 function _cmd_dayEventList(& $input, & $output) {

  SGL :: logMessage(null, PEAR_LOG_DEBUG);

  $output->template = “calendarEventList.html”;

  $output->pageTitle = “CalendarMgr :: DayEventList”;

  $calendar = DB_DataObject :: factory($this->conf[‘table’][‘calendar’]);

  $calendar->newsdate = $input->calendarDate;

  $result = $calendar->find();

  $events = array ();

  if ($result > 0) {

   while ($calendar->fetch()) {

    $calendar->newsid = $calendar->newsid;

    $calendar->newstitle = $calendar->newstitle;

    $calendar->newsdate = $calendar->newsdate;

    $calendar->newsdetail = $calendar->newsdetail;

    $events[] = clone ($calendar);

   }

  }

  $output->results = $events;

  //reback needs;

  $output->backParam=”frmCalendarDate=”.$input->calendarDate.”&flag=dayEventList&month=”.$input->month.”&year=”.$input->year;

 }

 function _cmd_monthEventList(& $input, & $output) {

  SGL :: logMessage(null, PEAR_LOG_DEBUG);

  $output->template = “calendarEventList.html”;

  $output->pageTitle = “CalendarMgr :: MonthEventList”;

  $calendar = DB_DataObject :: factory($this->conf[‘table’][‘calendar’]);

  $result = $calendar->find();

  $events = array ();

  if ($result > 0) {

   while ($calendar->fetch()) {

    if ($input->year == substr($calendar->newsdate,0,4) and $this->getDigitalMonth($input->month)==(int)substr($calendar->newsdate,5,2)) {

     $calendar->newsid = $calendar->newsid;

     $calendar->newstitle = $calendar->newstitle;

     $calendar->newsdate = $calendar->newsdate;

     $calendar->newsdetail = $calendar->newsdetail;

     $events[] = clone ($calendar);

    }

//    echo “<br>convarsion month = “.$this->getDigitalMonth(“July”);

   }

  }

  $output->results = $events;

  //reback needs;

  $output->backParam=”month=”.$input->month.”&year=”.$input->year.”&flag=monthEventList”;//show month

 }

 function _cmd_list(& $input, & $output) {

  SGL :: logMessage(null, PEAR_LOG_DEBUG);

  $output->template = ‘calendarList.html’;

  $output->pageTitle = ‘CalendarMgr :: List’;

  //    $output->year = $input->year;

  //    $output->month = $input->month;

  //    $output->day = $input->day;

  $y = $input->year;

  $m = $input->month;

  //  $d = $input->day;

  //  $mkdate = mktime(0, 0, 0, $m, 0, $y);

  /*

   * calender construct

   */

  $m = $this->getDigitalMonth($input->month);

//  echo “m=——–” . $m;

  $Month = new Calendar_Month_Weekdays($y, $m);

  $Month->build();

  //  modify cjt

  //    if (isset ($input->year))

  //     $query = “SELECT * FROM {$this->conf[‘table’][‘calendar’]} where newsdate='” . $input->year . ‘-‘ . ($input->month + 1) . ‘-‘ . $input->day . “‘”;

  //    else

  $query = “SELECT * FROM {$this->conf[‘table’][‘calendar’]} where newsdate='” . date(‘Y-n-j’) . “‘”;

  $limit = $_SESSION[‘aPrefs’][‘resPerPage’];

  $pagerOptions = array (

   ‘mode’ => ‘Sliding’,

   ‘delta’ => 3,

   ‘perPage’ => $limit,

  

  );

  $aPagedData = SGL_DB :: getPagedData($this->dbh, $query, $pagerOptions);

  $output->aPagedData = $aPagedData;

  $output->totalItems = $aPagedData[‘totalItems’];

  if (is_array($aPagedData[‘data’]) && count($aPagedData[‘data’])) {

   $output->pager = ($aPagedData[‘totalItems’] <= $limit) ? false : true;

  }

  /**

   *  old version

   */

  //  $this->showCalendar($output);//call function

  /**

   * call function bigCalendar for gain array have day and events

   */

  $currentdate = $this->getCurrentDate($input, $output);

  //  echo “??”.$currentdate[“y”];

  //  echo “??”.$currentdate[“m”];

  /**

   * accoding to a include array.

   */

  $output->monthArray = $this->bigCalendar($currentdate[“y”], $currentdate[“m”]); //call function  return a array.

//  echo “cudate = ” . $currentdate[“y”] . $currentdate[“m”];

  //$output->mydate = date(“Y-n-j”); //test

  /*

   * echo year and month

   */

  $strMonth = date(“F”, mktime(0, 0, 0, $currentdate[“m”], 1, $currentdate[“y”]));

//  echo “mkdate=” . $strMonth;

  $output->y = $currentdate[“y”];

  $output->m = $strMonth;

  //echo “mkdate = “.date(“Y-j-n”,$mkdate);

  //echo “strtotime= ” . strtotime(“10 September 2000”);

 }

 /**

  *  warrang digital month;

  */

 function getDigitalMonth($m) {

//  $m = $input->month;

  if (isset ($m)) {

   switch ($m) {

    case “January” :

     $m = 1;

     break;

    case “February” :

     $m = 2;

     break;

    case “March” :

     $m = 3;

     break;

    case “April” :

     $m = 4;

     break;

    case “May” :

     $m = 5;

     break;

    case “June” :

     $m = 6;

     break;

    case “July” :

     $m = 7;

     break;

    case “August” :

     $m = 8;

     break;

    case “September” :

     $m = 9;

     break;

    case “October” :

     $m = 10;

     break;

    case “November” :

     $m = 11;

     break;

    case “December” :

     $m = 12;

     break;

   }

  }

  return $m;

 }

 /**

  * return array include year and month;

  */

 function getNextDate($currentMonth) {

  $nextDate = array ();

  ++ $currentMonth;

  if ($currentMonth > 12) {

   $nextDate[“m”] = 1;

   $nextDate[“y”] = 1; //year add 1;

  } else {

   $nextDate[“m”] = $currentMonth;

   $nextDate[“y”] = 0;

  }

  return $nextDate;

 }

 /**

  * return array include year and month;

  */

 function getPreviousDate($currentMonth) {

  $previousDate = array ();

  — $currentMonth;

  if ($currentMonth < 1) {

   $previousDate[“m”] = 12;

   $previousDate[“y”] = -1; //year min 1;

  } else {

   $previousDate[“m”] = $currentMonth;

   $previousDate[“y”] = 0;

  }

  return $previousDate;

 }

 /**

  * getcurrentdate

  * @return array

  */

 function getCurrentDate($input) {

  $m = $this->getDigitalMonth($input->month); //call function getDigitalMonth accoding to digital month;

//  echo “==” . $m;

  $cdate = array ();

  $y = $input->year;

  /**

   * saved year and month;

   */

  if (isset ($m)) {

   if ($input->flag == “add”) { //if is >> flag

    $cdate = $this->getNextDate($m);

    $cdate[“y”] += $y;

    //echo “add===”.$cdate[“y”];//test

   } else

    if ($input->flag == “min”) { //if is << flag

     $cdate = $this->getPreviousDate($m);

     $cdate[“y”] += $y;

     //echo “min===”.$cdate[“y”];//test

    }

   else{

    $cdate[“m”]=$m;

    $cdate[“y”]=$y;

   }

  }

  return $cdate;

 }

 //show calendar

 function showCalendar(& $input, & $output) {

  require_once ‘source/activecalendar.php’;

  $cal = new activeCalendar();

  $output->cal = $cal->showMonth();

 }

 /*

  * calendar splie

  * @return array

  */

 function bigCalendar(& $y, & $m) {

  /*

   * constens Month object

   */

  if (!isset ($y) || !isset ($m)) {

   $y = date(“Y”);

   $m = date(“n”);

  }

  $Month = new Calendar_Month_Weekdays($y, $m);

  $Month->build();

  /*

   * talk all day and event

   *

   */

  $monthArray = array ();

  $weekArray = array ();

  $dayArray = array ();

  while ($Day = $Month->fetch()) {

   if ($Day->isEmpty()) {

    $weekArray[] = “”;

   } else {

    $fulldate = $y . “-” . $m . “-” . $Day->thisDay(); //fullday

    $dayArray[“day”] = $Day->thisDay();

    $dayArray[“fulldate”] = $fulldate;

    /*

     *  date motify in getEvents

     */

    $dayArray[“events”] = $this->getEvents($fulldate); //call function

    if($dayArray[“events”][“flag”]) //vardict array data;

     $dayArray[“flag”]=1;

    else

     $dayArray[“flag”]=0;

   

    /*

     * clear $dayArray after join 

     */

    $weekArray[] = $dayArray;

    $dayArray = array ();

   }

   if ($Day->isLast()) {

    /*

     * clear $weekArray after join

     */

    $monthArray[] = $weekArray;

    $weekArray = array ();

   }

  }

  return $monthArray;

 }

 /**

  * warranty(according to) currentdate fetch events!

  * get Events array

  * @param $currentdate current date. formatdate e.g: date(‘Y-n-j’) //show “2006-8-11”

  * return array

  *

  */

 function getEvents($currentdate) {

  $query = “SELECT * FROM {$this->conf[‘table’][‘calendar’]} where newsdate='” . $currentdate . “‘”;

  //$limit = $_SESSION[‘aPrefs’][‘resPerPage’];

  $pagerOptions = array (

   ‘mode’ => ‘Sliding’,

   ‘delta’ => 3,

   ‘perPage’ => 10,

  

  );

  $aPagedData = SGL_DB :: getPagedData($this->dbh, $query, $pagerOptions);

  /**

   * events included event;

   * event included

   * event[self] = eventself(string)

   * event[id] = eventid(int)

   */

  $events = array ();

  $event = array ();

  /*

   * talk events in the aPagedData[data] 

   * first talk rows info

   * thencd dicteri “newstitle” isset

   * if rows[“newstitle”] is set will newstitle insert into $events array

   */

  //echo “count = “.count($aPagedData[‘data’]);

  if(count($aPagedData[‘data’])>0){

   foreach ($aPagedData[‘data’] as $title => $rows) {

    /*

     * error logic

     */

    //foreach ($rows as $col => $value) {

    //return ($col == “newstitle” && isset ($value)) ? $value : ‘t’;

    //}

    /*

     * 

     */

    if (isset ($rows[“newstitle”])) {

     $event[“title”] = $rows[“newstitle”];

     $event[“id”] = $rows[“newsid”];

     $events[] = $event; //will $event save $events

     $event = array (); //clear $event;

    }

   }

   $events[“flag”]=1;

  }else

   $events[“flag”]=0;

  return $events;

 }

}

?>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/100650.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号