-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin-tags.php
106 lines (85 loc) · 2.48 KB
/
admin-tags.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
function wptc_logging($msg) {
// TODO: this should never go prodcution!
$DEBUG = false;
if($DEBUG) {
$logfile = fopen(ABSPATH . 'logging.log', "a");
// time stamp
fwrite($logfile, $msg . "\n");
fclose($logfile);
}
}
/**
* create database tables for the project management
* if force create tables, all data will be droped.
* default is NOT force to create tables.
*/
function wptc_create_tables($force=false) {
require_once(ABSPATH . "wp-admin/includes/upgrade.php");
// the project table.
$sql = "CREATE TABLE " . WPTC_PROJECT . " (
id mediumint(9) not null auto_increment,
name varchar(100) not null,
description varchar(512) not null default '',
PRIMARY KEY (id),
KEY name (name)
);";
wptc_logging("create project table: " . $sql);
dbDelta($sql);
// the project metadata table.
// the type will be one of [milestone, version]
$sql = "CREATE TABLE " . WPTC_PROJECT_METADATA . " (
id mediumint(9) not null auto_increment,
name varchar(100) not null,
project_id mediumint(9) not null,
type varchar(64) not null,
description varchar(512) not null default '',
due_date datetime not null default '0000-00-00 00:00:00',
PRIMARY KEY (id),
KEY id (id)
);";
wptc_logging("crate project metadata table: ". $sql);
dbDelta($sql);
}
/**
* return all projects
*/
function wptc_get_projects() {
global $wpdb;
$query = "select * from " . WPTC_PROJECT;
$projects = $wpdb->get_results($query, ARRAY_A);
return $projects;
}
function wptc_add_project($name, $description) {
global $wpdb;
$success = $wpdb->insert(
WPTC_PROJECT,
array(
'name' => $name,
'description' => $description
),
array(
'%s',
'%s'
)
);
return $success;
}
function wptc_get_project($name) {
global $wpdb;
$query = "select * from " . WPTC_PROJECT .
" where name = %s";
$query = $wpdb->prepare($query, $name);
$project = $wpdb->get_row($query, ARRAY_A);
return $project;
}
function wptc_remove_project($name) {
global $wpdb;
$query = "delete from " . WPTC_PROJECT .
" where name = %s";
$query = $wpdb->prepare($query, $name);
// if error, false is return.
// else number of rows affected/selected.
$rows = $wpdb->query($query);
return $rows;
}