<?php
/*
* Created on 2012-4-24 by xiongxuebing
*/
class Calendar extends DB_Connect
{
/**
* 日历根据此日期构建
* YYYY-MM-DD HH:MM:SS
* @var string
*/
private $_useDate;
/**
* 日历显示月份
* @var int
*/
private $_m;
/**
* 年
* @var int
*/
private $_y;
/**
* 这个月有多少天
* @var int
*/
private $_daysInMonth;
/**
* 这个月从周几开始
* @var int
*/
private $_startDay;
public function __construct($dbo = NULL, $useDate = NULL)
{
parent::__construct($dbo);
/*
* Gather and store data relevant to the month
*/
if (isset($useDate)) {
$this->_useDate = $useDate;
} else {
$this->_useDate = date('Y-m-d H:i:s');
}
$ts = strtotime($this->_useDate);
$this->_m = date('m', $ts);
$this->_y = date('Y', $ts);
$this->_daysInMonth = cal_days_in_month(
CAL_GREGORIAN,
$this->_m,
$this->_y
);
$ts = mktime(0, 0, 0, $this->_m, 1, $this->_y);
$this->_startDay = date('w', $ts);
}
/**
* 生成用于显示日历和活动的HTML标记
*
* 使用储存在类属性中的数据,截入给定月份的活动数据,生成并返回完整的日历HTML标记
* @return string 日历HTML标记
*/
public function buildCalendar()
{
/**
* 确定日历显示月份并创建一个用于标识日历每列星期几的缩写数组
*/
$cal_month = date('F Y', strtotime($this->_useDate));
$cal_id = date('Y-m', strtotime($this->_useDate));
$weekdays = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
/**
* 给日历标记添加一个标题
*/
$html = "\n\t<h2 id=\"month-$cal_id\">$cal_month</h2>";
for ($d = 0, $labels = NULL; $d < 7; ++$d) {
$labels .= "\n\t\t<li>" . $weekdays[$d] . "</li>";
}
$html .= "\n\t<ul class=\"weekdays\">" . $labels . "\n\t</ul>";
/*
* Load events data
*/
$events = $this->_createEventObj();
/*
* 生成日历HTML标记
*/
$html .= "\n\t<ul>"; // 开始一个新的<ul>
for ($i = 1, $c = 1, $t = date('j'), $m = date('m'), $y = date('Y'); $c <= $this->_daysInMonth; ++$i) {
$event_info = NULL; // clear the variable
//为该月的之前几天添加填充项
$class = $i <= $this->_startDay ? "fill" : NULL;
//如果当前处理日期是今天,则为他添加class today
if ($c == $t && $m == $this->_m && $y == $this->_y) {
$class = "today";
}
$ls = sprintf("\n\t\t<li class=\"%s\">", $class);
$le = "\n\t\t</li>";
if ($this->_startDay < $i && $this->_daysInMonth >= $c) {
if (isset($events[$c])) {
foreach ($events[$c] as $event) {
$link = '<a href="view.php?event_id=' . $event->id . '">' . $event->title . '</a>';
$event_info = "\n\t\t\t$link";
}
}
$date = sprintf("\n\t\t\t<strong>%02d</strong>", $c++);
} else {
$date = " ";
}
//如果赶上星期六,就新起一行
$wrap = $i != 0 && $i % 7 == 0 ? "\n\t</ul>\n\t<ul>" : NULL;
//Assemble the pieces into a finished item
$html .= $ls . $date . $event_info . $le . $wrap;
}
//Add filler to finish out the last week
while ($i % 7 != 1) {
$html .= "\n\t\t<li class=\"fill\"> </li>";
++$i;
}
//Close the final unordered list
$html .= "\n\t</ul>\n\n";
$admin = $this->_adminGeneralOptions();
/**
* 返回用于输出的HTML标记
*/
return $html . $admin;
}
/**
* 得到活动信息HTML
* @param int $id 活动ID
* @return string 用于显示活动信息的基本HTML标记
*/
public function displayEvent($id)
{
/**
* Make sure an ID was passed
* */
if (empty($id)) {
return NULL;
}
/**
* Make sure the ID is an integer
**/
$id = preg_replace('/[^0-9]/', '', $id);
/**
* Load the event data from the DB
**/
$event = $this->_loadEventById($id);
/**
* Generate strings for the date, start, and end time
* */
$ts = strtotime($event->start);
$date = date('F d, Y', $ts);
$start = date('g:ia', $ts);
$end = date('g:ia', strtotime($event->end));
/*
* Load admin options if the user is logged in
*/
$admin = $this->_adminEntryOptions($id);
return "<h2>$event->title</h2>\n\t<p class=\"dates\">$date, $start—$end</p>" .
"\n\t<p>$event->description</p>$admin";
}
public function displayForm()
{
if (isset($_POST['event_id'])) {
$id = (int)$_POST['event_id'];
// Force integer type to sanitize data
} else {
$id = NULL;
}
/*
* Instantiate the headline/submit button text
*/
$submit = "Create new!";
/*
* If an ID is passed, loads the associated event
*/
if (!empty($id)) {
$event = $this->_loadEventById($id);
if (!is_object($event)) {
return NULL;
}
$submit = "Edit event!";
}
return <<<FORM_MARKUP
<form action="assets/inc/process.inc.php" method="post">
<fieldset>
<legend>$submit</legend>
<label for="event_title">Event Title</label>
<input type="text" name="event_title" id="event_title" value="$event->title" />
<label for="event_start">Start Time</label>
<input type="text" name="event_start" id="event_start" value="$event->start" />
<label for="event_end">End Time</label>
<input type="text" name="event_end" id="event_end" value="$event->end" />
<label for="event_description">Event Description</label>
<textarea name="event_description" id="event_description">$event->description</textarea>
<input type="hidden" name="event_id" value="$event->id" />
<input type="hidden" name="token" value="$_SESSION[token]" />
<input type="hidden" name="action" value="event_edit" />
<input type="submit" name="event_submit" value="$submit" /> or <a href="./" class = "link">cancel</a>
</fieldset>
</form>
FORM_MARKUP;
}
public function processForm()
{
if ($_POST['action'] != 'event_edit') {
return "The method processForm was accessed incorrectly";
}
$title = htmlentities($_POST['event_title'], ENT_QUOTES, "UTF-8");
$desc = htmlentities($_POST['event_description'], ENT_QUOTES, "UTF-8");
$start = htmlentities($_POST['event_start'], ENT_QUOTES, "UTF-8");
$end = htmlentities($_POST['event_end'], ENT_QUOTES, "UTF-8");
if (!$this->_validDate($start) || !$this->_validDate($end)) {
return "Invalid date format! Use YYYY-MM-DD HH:MM:SS.";
}
/*
* If no event ID passed, create a new event
*/
if (empty($_POST['event_id'])) {
$sql = "INSERT INTO `events` (`event_title`, `event_desc`, `event_start`, `event_end`)" .
" VALUES (:title, :description, :start, :end)";
} else {
$id = (int)$_POST['event_id'];
没有合适的资源?快使用搜索试试~ 我知道了~
一个简单的calendar源代码
共16个文件
php:8个
xml:5个
sql:1个
5星 · 超过95%的资源 需积分: 10 24 下载量 18 浏览量
2016-06-19
22:13:26
上传
评论
收藏 14KB RAR 举报
温馨提示
来源于深入php与jQuery开发配套源代码,只不过流传的都有些问题 此源代码只跟进到刚好显示日历,其它的后面应该会跟进。 另外,此源码用phpStorm测试,此开发工具的调试能力无限强大。
资源推荐
资源详情
资源评论
收起资源包目录
calendar1.rar (16个子文件)
calendar1
public
inc
js
assets
common
header.inc.php 534B
footer.inc.php 16B
css
style.css 2KB
index.php 720B
sys
class
class.calendar.inc.php 15KB
class.db_connect.inc.php 952B
class.event.inc.php 1KB
core
init.inc.php 799B
config
db-cred.inc.php 427B
php-jquery_example.sql 916B
.idea
misc.xml 671B
workspace.xml 26KB
calendar.iml 281B
modules.xml 268B
copyright
profiles_settings.xml 76B
vcs.xml 180B
共 16 条
- 1
资源评论
- codeqq2017-03-24很好,参考学习了,谢谢分享~
永远的麦田
- 粉丝: 238
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 驱动代码驱动代码驱动代码驱动代码
- SVID_20240523_141155_1.mp4
- Code for the complete guide to tkinter tutorial
- 关于百货中心供应链管理系统.zip
- SimpleFolderIcon-master 修改Unity的Project下的文件夹图标
- A python Tkinter widget to display tile based maps
- A pure Python library for adding tables to a Tkinter application
- Vector资源文件.zip
- MobaXterm-Installer
- 88-520告白(520气球).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功