';
}
add_action('admin_head', 'actionable_admin_head');
/*---- Set up database and options ----*/
function actionable_init() {
add_option('actionable', true);
global $wpdb, $actionable_db, $actionable_actions_db, $actionable_categories_db;
$sql = "CREATE TABLE IF NOT EXISTS ".$actionable_db." (
`actionable_id` int(10) NOT NULL auto_increment,
`user_id` bigint(20) default NULL,
`actionable_value` longtext,
PRIMARY KEY (`actionable_id`),
KEY `user_id` (`user_id`)
)";
$result = $wpdb->query($sql);
$sql = "CREATE TABLE ".$actionable_actions_db." (
`actionable_id` int(10) NOT NULL auto_increment,
`actionable_action` text,
`actionable_cat` smallint(5) default NULL,
`actionable_value` smallint(5) default NULL,
PRIMARY KEY (`actionable_id`),
KEY `ID` (`actionable_id`)
)";
$result = $wpdb->query($sql);
$sql = "CREATE TABLE ".$actionable_categories_db." (
`actionable_id` int(10) NOT NULL auto_increment,
`actionable_cat` varchar(255) default NULL,
PRIMARY KEY (`actionable_id`)
)";
$result = $wpdb->query($sql);
$wpdb->hide_errors();
}
/*---- Wrapper function which calls the form and processes input. ----*/
function wpactionable_callback($content) {
global $wpactionable_strings, $wpdb, $user_ID, $actionable_db, $actionable_actions_db, $actionable_categories_db;
get_currentuserinfo();
if (!preg_match('||', $content)) {
return $content;
}
/*-- If no user is logged then --*/
if (!$user_ID) {
echo '
By registering , you can create a green actions profile and save it for future reference.
';
}
/*-- Else show the form. --*/
else {
$userprofile = $wpdb->get_results("SELECT actionable_value FROM ".$actionable_db." WHERE user_id = $user_ID");
$serialactions = $wpdb->escape(serialize($_POST['box']));
if (wpactionable_check_input()) {
if ($userprofile) {
$query_upd = "UPDATE ".$actionable_db." SET actionable_value = '$serialactions' WHERE user_id = $user_ID";
$result = $wpdb->query($query_upd);
}
else {
$query_add = "INSERT INTO ".$actionable_db." (user_id, actionable_value) VALUES ($user_ID, '$serialactions')";
$result = $wpdb->query($query_add);
}
}
$dbuserprofile = $wpdb->get_row("SELECT * FROM ".$actionable_db." WHERE user_id = $user_ID");
$userprofile = $dbuserprofile->actionable_value;
if ($userprofile) {
$unserialactions = unserialize($userprofile);
}
$cathead = $wpdb->get_results("SELECT * FROM ".$actionable_categories_db."");
$form = ' '.eol();
$catcount = 1;
$form .= ''.eol();
$form .= ''.eol();
foreach ($cathead as $catitemhead) {
$divref = divname($catitemhead->actionable_cat);
$divref = "javascript:animatedcollapse.toggle('$divref')";
$form .= ''.eol();
if ($catcount % 6 == 0) {
$form .= ' '.eol();
}
$catcount++;
}
$form .= ' '.eol();
$form .= '
'.eol();
$form .= '';
$form .= '
';
return str_replace('', $form, $content);
}
/*-- END - if (!($user_ID) else --*/
}
/*-- END - wpactionable_callback --*/
/*---- This function checks to see if data is being posted ----*/
function wpactionable_check_input() {
if (!(isset($_POST['actionable_post']))) {
return false;
}
else {
return true;
}
}
/*---- Sets checkboxes to checked if the action profile contains that item ----*/
function wpactionable_check_box($boxvalue) {
if ($boxvalue == "1") {
$setvalue = 'checked="checked"';
}
else {
$setvalue = "";
}
return $setvalue;
}
/*---- Actionable CSS Styling and animatedcollapse (should be moved) ---*/
function wpactionable_css() {
global $actionable_path, $wpdb, $actionable_categories_db;
$wp = get_bloginfo('wpurl');
if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
$endl = "\r\n";
}
elseif (strtoupper(substr(PHP_OS, 0, 3) == 'MAC')) {
$endl = "\r";
}
else {
$endl = "\n";
}
$url = $wp.'/'.$actionable_path;
echo ' ';
echo ''.$endl;
}
function divname($divinput) {
$divtag = str_replace(" ", "-", $divinput);
$divtag = strtolower($divtag);
return $divtag;
}
/*---- Add administrative page ----*/
function wpactionable_add_options_page() {
add_options_page('Actionable Options', 'Actionable', 8, basename(__FILE__), 'wpactionable_subpanel');
}
function eol() {
if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
$el = "\r\n";
}
elseif (strtoupper(substr(PHP_OS, 0, 3) == 'MAC')) {
$el = "\r";
}
else {
$el = "\n";
}
return $el;
}
function wpactionable_count_stats($table) {
global $wpdb;
$stats_count = $wpdb->get_var("SELECT COUNT(*) FROM $table;");
return $stats_count;
}
function wpactionable_list_users() {
global $wpdb, $user_ID, $actionable_db;
$actionable_user_list = "";
$actionableusers = $wpdb->get_results("SELECT user_id FROM ".$actionable_db." ORDER by user_id ASC;");
foreach ($actionableusers as $actionableuser) {
$userid = $actionableuser->user_id;
$actionable_user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = $userid");
$actionable_action_count = count_user_actions($userid);
$actionable_user_list .= "$actionable_user->user_login - $actionable_action_count actions ".eol();
}
return $actionable_user_list;
}
function count_user_actions($usrid) {
global $wpdb, $actionable_db;
$useractions = $wpdb->get_row("SELECT * FROM ".$actionable_db." WHERE user_id = $usrid");
$actioncount = $useractions->actionable_value;
$actioncount = unserialize($actioncount);
$actioncount = count($actioncount);
return $actioncount;
}
/*
function wpactionable_show_results {
global $wpdb;
$numberactions = wpactionable_count_stats('wp_actionable_actions');
$totalresults = $wpdb->get_results("SELECT actionable_value FROM wp_actionable WHERE user_id = $user_ID");
foreach ($totalresults as $result) {
$currentresult = $unserialactions[$result->actionable_id];
foreach ($currentresult as $resultkey->$resultitem) {
for ($i = 0; $i <= $numberactions; $i++) {
}
}
}
}
*/
/*---- Add administrative page ----*/
function wpactionable_add_pages() {
/*-- Add a new submenu under Manage: --*/
add_management_page('Actionable', 'Actionable', 8, 'actionable.php', 'wpactionable_manage_page');
}
/*---- Displays the page content for the Actionable Managment ----*/
function wpactionable_manage_page() {
global $table_prefix, $wpdb, $actionable_db, $actionable_actions_db, $actionable_categories_db;
$action = $_GET['action'];
if (!empty($action)) {
switch ($action) {
case "add":
$type = $_REQUEST['type'];
if (!empty($type)) {
/*-- Save Action --*/
if ($_POST['add_action']) {
/*-- Get postdata --*/
$actionable_item = htmlspecialchars(trim($_POST['actionable_item']));
$actionable_category = htmlspecialchars(trim($_POST['actionable_category']));
$actionable_value = htmlspecialchars(trim($_POST['actionable_value']));
/*-- validate fields --*/
if (empty($_POST['actionable_item']))
$errors .= __('Action is required
', "actionable");
if ($_POST['actionable_category'] == '0')
$errors .= __('Category is required
', "actionable");
$query_add = sprintf("INSERT INTO %s (actionable_action, actionable_cat, actionable_value) VALUES ('%s','%s','%s')", $wpdb->escape($actionable_actions_db), $wpdb->escape($actionable_item), $wpdb->escape($actionable_category), $wpdb->escape($actionable_value));
$result = $wpdb->query($query_add);
if ($result) {
if (empty($info))
echo ''.__("Action successfully added", "actionable").'
';
else
echo ''.__("Download added Successfully", "wp-download_monitor").' - '.$info.'
';
$_POST['add_action'] = "";
$show = true;
}
else
_e('Error saving to database
', "actionable");
break;
}
}
if (!empty($_POST['add_new_action'])) {
?>
This page is currently a stub pending completion of administrative page development. Currently you
cannot add or edit actions, or categories. You can page though the list of actions and view the current categories and basic statistics.', 'actionable')?>
escape($actionable_actions_db));
/*-- Figure out the limit for the query based on the current page number. --*/
$from = (($page * 20) - 20);
$paged_select = sprintf("SELECT * FROM %s ORDER BY %s LIMIT %s,20;", $wpdb->escape($actionable_actions_db), $wpdb->escape($sort), $wpdb->escape($from));
$actions = $wpdb->get_results($paged_select);
$total = $wpdb->get_var($total_results);
/*-- Figure out the total number of pages. Always round up using ceil() --*/
$total_pages = ceil($total / 20);
if (!empty($actions)) {
echo '';
foreach ($actions as $a) {
echo('');
echo ''.$a->actionable_id.'
'.$a->actionable_action.'
';
if ($a->actionable_cat == "" || $a->actionable_cat == 0)
echo "N/A";
else {
$c = $wpdb->get_row("SELECT * FROM ".$actionable_categories_db." where actionable_id=".$a->actionable_cat." LIMIT 1;");
$chain = $c->actionable_cat;
while ($c->parent > 0) {
$c = $wpdb->get_row("SELECT * FROM ".$actionable_categories_db." where actionable_id=".$c->parent." LIMIT 1;");
$chain = $c->actionable_cat.' — '.$chain;
}
echo $chain;
}
echo '
'.$a->actionable_value.'
';
}
echo ' ';
}
else
echo ''.__('No actions added yet.', "actionable").' ';
// FIXED: 1.6 - Colspan changed
?>
1) {
/*-- Build Page Number Hyperlinks --*/
if ($page > 1) {
$prev = ($page - 1);
echo "
« ".__('Previous', "actionable")." ";
}
else
echo "« ".__('Previous', "actionable")."";
for ($i = 1; $i <= $total_pages; $i++) {
if (($page) == $i) {
echo " $i ";
}
else {
echo "
$i ";
}
}
/*-- Build Next Link --*/
if ($page < $total_pages) {
$next = ($page + 1);
echo "
".__('Next', "wp-download_monitor")." » ";
}
else
echo __('Next', "actionable")." »";
}
?>
You must categorize your actions for them to appear.', "actionable");?>
Name
escape($actionable_categories_db));
$cats = $wpdb->get_results($query_select_cats);
if (!empty($cats)) {
foreach ($cats as $c) {
echo ''.$c->actionable_id.' '.$c->actionable_cat.' ';
}
}
else {
echo ''.__('No categories exist', "actionable").' ';
}
?>
Number of actions available: '.wpactionable_count_stats($actionable_actions_db).'
Number of action categories: '.wpactionable_count_stats($actionable_categories_db).'
Number of action profiles entered: '.wpactionable_count_stats($actionable_db).'
', "actionable");?>
Add, edit and delete actions
Add and collect demographic information
Add, edit and delete categories and subcategories
View collated totals by action
View individual actions per user
More...
', "actionable");?>