<?php
/*
* Copyright 2012 Sean Proctor
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require_once("$phpc_includes_path/phpccalendar.class.php");
require_once("$phpc_includes_path/phpcevent.class.php");
require_once("$phpc_includes_path/phpcoccurrence.class.php");
require_once("$phpc_includes_path/phpcuser.class.php");
class PhpcDatabase {
var $dbh;
var $calendars;
function __construct($host, $username, $passwd, $dbname, $port) {
// Make the database connection.
$this->dbh = new mysqli($host, $username, $passwd, $dbname,
$port);
if(mysqli_connect_errno()) {
soft_error("Database connect failed ("
. mysqli_connect_errno() . "): "
. mysqli_connect_error());
}
$this->dbh->set_charset("utf8");
}
function __destruct() {
$this->dbh->close();
}
private function get_event_fields() {
$events_table = SQL_PREFIX . "events";
$cats_table = SQL_PREFIX . "categories";
$fields = array('subject', 'description', 'owner', 'eid', 'cid',
'readonly', 'catid', 'ctime', 'mtime');
return "`$cats_table`.`gid`, `$events_table`.`"
. implode("`, `$events_table`.`", $fields) . "`\n";
}
private function get_occurrence_fields() {
return $this->get_event_fields() . ", `time_type`, `oid`, "
. "UNIX_TIMESTAMP(`start_ts`) AS `start_ts`, "
. "DATE_FORMAT(`start_date`, '%Y%m%d') AS `start_date`, "
. "UNIX_TIMESTAMP(`end_ts`) AS `end_ts`, "
. "DATE_FORMAT(`end_date`, '%Y%m%d') AS `end_date`\n";
}
private function get_user_fields() {
$users_table = SQL_PREFIX . "users";
return "`$users_table`.`uid`, `username`, `password`, `$users_table`.`admin`, `password_editable`, `timezone`, `language`";
}
// returns all the events for a particular day
// $from and $to are timestamps only significant to the date.
// an event that happens later in the day of $to is included
function get_occurrences_by_date_range($cid, $from, $to)
{
$from_date = date('Y-m-d', $from);
$to_date = date('Y-m-d', $to);
$events_table = SQL_PREFIX . "events";
$occurrences_table = SQL_PREFIX . "occurrences";
$users_table = SQL_PREFIX . 'users';
$cats_table = SQL_PREFIX . 'categories';
$query = "SELECT " . $this->get_occurrence_fields()
.", `username`, `name`, `bg_color`, `text_color`\n"
."FROM `$events_table`\n"
."INNER JOIN `$occurrences_table` USING (`eid`)\n"
."LEFT JOIN `$users_table` ON `uid` = `owner`\n"
."LEFT JOIN `$cats_table` ON `$events_table`.`catid` "
."= `$cats_table`.`catid`\n"
."WHERE `$events_table`.`cid` = '$cid'\n"
." AND IF(`start_ts`, DATE(`start_ts`), `start_date`) <= DATE('$to_date')\n"
." AND IF(`end_ts`, DATE(`end_ts`), `end_date`) >= DATE('$from_date')\n"
." ORDER BY `start_ts`, `start_date`, `oid`";
$results = $this->dbh->query($query)
or $this->db_error(__('Error in get_occurrences_by_date_range'),
$query);
return $results;
}
/* if category is visible to user id */
function is_cat_visible($uid, $catid) {
$users_table = SQL_PREFIX . 'users';
$user_groups_table = SQL_PREFIX . 'user_groups';
$cats_table = SQL_PREFIX . 'categories';
if (is_admin())
return true;
$query = "SELECT * FROM `$users_table` u\n"
."JOIN `$user_groups_table` ug USING (`uid`)\n"
."JOIN `$cats_table` c ON c.`gid`=ug.`gid`\n"
."WHERE c.`catid`='$catid' AND u.`uid`='$uid'";
$results = $this->dbh->query($query);
if(!$results)
return false;
return $results->num_rows>0;
}
// returns all the events for a particular day
function get_occurrences_by_date($cid, $year, $month, $day)
{
$stamp = mktime(0, 0, 0, $month, $day, $year);
return $this->get_occurrences_by_date_range($cid, $stamp,
$stamp);
}
// returns the event that corresponds to eid
function get_event_by_eid($eid)
{
$events_table = SQL_PREFIX . 'events';
$users_table = SQL_PREFIX . 'users';
$cats_table = SQL_PREFIX . 'categories';
$query = "SELECT " . $this->get_event_fields()
.", `username`, `name`, `bg_color`, `text_color`\n"
."FROM `$events_table`\n"
."LEFT JOIN `$users_table` ON `uid` = `owner`\n"
."LEFT JOIN `$cats_table` USING (`catid`)\n"
."WHERE `eid` = '$eid'\n";
$sth = $this->dbh->query($query)
or $this->db_error(__('Error in get_event_by_eid'),
$query);
$result = $sth->fetch_assoc()
or soft_error(__("Event doesn't exist") . ": $eid");
return $result;
}
// returns the event that corresponds to oid
function get_event_by_oid($oid)
{
$events_table = SQL_PREFIX . 'events';
$occurrences_table = SQL_PREFIX . 'occurrences';
$users_table = SQL_PREFIX . 'users';
$cats_table = SQL_PREFIX . 'categories';
$query = "SELECT " . $this->get_event_fields()
.", `username`, `name`, `bg_color`, `text_color`\n"
."FROM `$events_table`\n"
."LEFT JOIN `$occurrences_table` USING (`eid`)\n"
."LEFT JOIN `$users_table` ON `uid` = `owner`\n"
."LEFT JOIN `$cats_table` USING (`catid`)\n"
."WHERE `oid` = '$oid'\n";
$sth = $this->dbh->query($query)
or $this->db_error(__('Error in get_event_by_oid'),
$query);
$result = $sth->fetch_assoc()
or soft_error(__("Event doesn't exist with oid")
. ": $oid");
return $result;
}
// returns the category that corresponds to $catid
function get_category($catid) {
$cats_table = SQL_PREFIX . 'categories';
$groups_table = SQL_PREFIX . 'groups';
$query = "SELECT `$cats_table`.`name` AS `name`, `text_color`, "
."`bg_color`, `$cats_table`.`cid` AS `cid`, "
."`$cats_table`.`gid`, `catid`, "
."`$groups_table`.`name` AS `group_name`\n"
."FROM `$cats_table`\n"
."LEFT JOIN `$groups_table` USING (`gid`)\n"
."WHERE `catid` = $catid";
$sth = $this->dbh->query($query)
or $this->db_error(__('Error in get_category'), $query);
$result = $sth->fetch_assoc()
or soft_error(__("Category doesn't exist with catid")
. ": $catid");
return $result;
}
function get_group($gid) {
$groups_table = SQL_PREFIX . 'groups';
$query = "SELECT `name`, `gid`, `cid`\n"
."FROM `$groups_table`\n"
."WHERE `gid` = $gid";
$sth = $this->dbh->query($query)
or $this->db_error(__('Error in get_group'), $query);
$result = $sth->fetch_assoc()
or soft_error(__("Group doesn't exist with gid")
. ": $gid");
return $result;
}
function get_groups($cid = false) {
$groups_table = SQL_PREFIX . 'groups';
$query = "SELECT `gid`, `name`, `cid`\n"
."FROM `$groups_table`\n";
if($cid !== false)
$query .= "WHERE `cid` = $cid";
$sth = $this->dbh->query($query)
or $this->db_error(__('Error in get_groups'), $query);
$groups = array();
while($row = $sth->fetch_assoc()) {
$groups[] = $row;
}
return $groups;
}
function get_user_groups($uid) {
$groups_table = SQL_PREFIX . 'groups';
$user_groups_table = SQL_PREFIX . 'user_groups';
$query = "SELECT `gid`, `cid`, `name`\n"
."FROM `$groups_table`\n"
."INNER JOIN `$user_groups_table` USING (`gid`)\n"
."WHERE `uid` = $uid";
$sth = $this->dbh->query($query)
or $this->db_error(__('Error in get_user_groups'),
$query);
$groups = array();
while($row = $sth->fetch_assoc()) {
$groups[] = $row;
}
return $groups;
}
// returns the categories for calendar $cid
function get_categories($cid = false) {
$cats_table = SQL_PREFIX . 'categories';
$groups_table = SQL_PREFIX . 'groups';
if($cid)
$where = "WHERE `$cats_table`.`cid` = '$cid'\n";
else
$where = "WHERE
没有合适的资源?快使用搜索试试~ 我知道了~
PHP-Calendar日程安排程序.7z
共109个文件
php:48个
html:22个
po:14个
0 下载量 48 浏览量
2023-03-14
10:41:00
上传
评论
收藏 199KB 7Z 举报
温馨提示
PHP-Calendar日程安排程序.7z
资源推荐
资源详情
资源评论
收起资源包目录
PHP-Calendar日程安排程序.7z (109个子文件)
AUTHORS 71B
jPicker-1.1.6.css 7KB
phpc.css 4KB
jPicker-1.1.6.min.css 4KB
jquery-ui-timepicker.css 1KB
picker.gif 146B
mappoint.gif 93B
rangearrows.gif 76B
.gitignore 22B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
index.html 0B
jpicker-1.1.6.js 98KB
jquery.ui.timepicker.js 62KB
jpicker-1.1.6.min.js 37KB
phpc.js 10KB
jquery.hoverIntent.minified.js 1KB
NEWS 16KB
phpcdatabase.class.php 25KB
form.php 22KB
calendar.php 22KB
install.php 21KB
event_form.php 12KB
html.php 9KB
util.php 8KB
Gettext_PHP.php 8KB
display_month.php 8KB
display_week.php 7KB
display_event.php 7KB
cadmin.php 7KB
msgfmt-functions.php 6KB
phpcoccurrence.class.php 6KB
lib_autolink.php 6KB
setup.php 6KB
admin.php 5KB
occur_form.php 4KB
import.php 4KB
settings.php 4KB
display_day.php 4KB
search.php 4KB
phpcevent.class.php 3KB
phpccalendar.class.php 3KB
user_create.php 3KB
index.php 3KB
occurrence_delete.php 3KB
category_submit.php 3KB
event_delete.php 3KB
user_groups.php 3KB
calendar_form.php 2KB
login.php 2KB
category_delete.php 2KB
category_form.php 2KB
group_delete.php 2KB
embed_setup.php 2KB
calendar_delete.php 2KB
user_delete.php 2KB
globals.php 2KB
group_submit.php 2KB
user_permissions_submit.php 2KB
password_submit.php 2KB
translate.php 2KB
phpcuser.class.php 2KB
embed.php 1KB
group_form.php 1KB
cadmin_submit.php 1KB
logout.php 818B
Maps.png 76KB
AlphaBar.png 2KB
office-calendar.png 603B
NoColor.png 552B
Bars.png 382B
map-opacity.png 139B
preview-opacity.png 135B
bar-opacity.png 134B
messages.po 40KB
messages.po 33KB
messages.po 33KB
messages.po 32KB
messages.po 31KB
messages.po 31KB
messages.po 30KB
共 109 条
- 1
- 2
资源评论
BryanDing
- 粉丝: 299
- 资源: 5583
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功