Skip to content

Commit

Permalink
get start the project management page:
Browse files Browse the repository at this point in the history
projects list is based on WP_List_Table
Add new porject is working, we are using server side validation.
  • Loading branch information
seanchen committed Feb 6, 2013
1 parent 65ee4fd commit d5c2be1
Show file tree
Hide file tree
Showing 4 changed files with 451 additions and 1 deletion.
36 changes: 35 additions & 1 deletion wp-trac-client/admin-manager.php
@@ -1,3 +1,37 @@
<?php
// load context.
$pm_context = wptc_widget_pm_context();
?>

<div class='wrap'>
<h2>WordPress Trac Client - Management</h2>

<?php
// handle submit
wptc_handle_pm_submit($pm_context);

switch($pm_context['action']) {
case 'newproject':
wptc_widget_new_project();
break;
case 'list':
default:
wptc_widget_projects_list();
break;
}
?>

<?php
if ($DEBUG) {
global $wptc_db_version;
//wptc_create_tables();
$file = __FILE__;
$path = MY_PLUGIN_PATH;
$filename = basename(__FILE__);
echo <<<EOT
<p>$wptc_db_version</p>
<p>file: $file, basename: $filename</p>
<p>MY_PLUGIN_PATH: {$path}</p>
EOT;
}
?>
</div>
1 change: 1 addition & 0 deletions wp-trac-client/admin-settings.php
@@ -1,5 +1,6 @@
<?php

wp_enqueue_script("wp_ajax_response");
$DEBUG = False;

if (isset($_POST['wptc_settings_form_submit']) &&
Expand Down
92 changes: 92 additions & 0 deletions wp-trac-client/admin-tags.php
@@ -0,0 +1,92 @@
<?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;
}

0 comments on commit d5c2be1

Please sign in to comment.