Please update!';
if (version_compare($wp_version,"2.7","<")) {
exit ($exit_msg);
}
global $att_users_db_version;
$att_users_db_version = "1.0";
global $att_global_settings;
$att_global_settings = get_option('att_reg_settings');
class ML_Att_users {
// foreign key tutorial: http://www.1keydata.com/sql/sql-foreign-key.html
// installs 3 tables in the database
function att_users_install() {
global $wpdb, $att_users_db_version, $att_global_settings;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$sql = "CREATE TABLE " . $wpdb->prefix . "att_users (
id mediumint(9) NOT NULL AUTO_INCREMENT,
user_id mediumint(9) NOT NULL,
att_post_id mediumint(9) NOT NULL,
UNIQUE KEY id (id),
Foreign Key (user_id) references " . $wpdb->prefix . "users(ID),
Foreign Key (att_post_id) references " . $wpdb->prefix . "posts(ID)
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE TABLE " . $wpdb->prefix . "att_titles (
att_title mediumint(9) NOT NULL,
att_post_id mediumint(9) NOT NULL,
UNIQUE KEY att_post_id (att_post_id),
Foreign Key (att_title) references " . $wpdb->prefix . "att_list_titles(att_list_id)
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE TABLE " . $wpdb->prefix . "att_list_titles (
att_title text NOT NULL,
att_list_id mediumint(9) NOT NULL AUTO_INCREMENT,
UNIQUE KEY att_list_id (att_list_id)
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
";
dbDelta($sql);
$att_options = array(
'att_btn_sub' => 'Submit',
'att_btn_unsub' => 'unsubscribe',
'att_msg_not_logged' => 'If you want to particiate, please log in or register!',
'att_post_types' => array('page', 'post')
);
add_option("att_reg_settings", $att_options);
add_option("att_users_db_version", $att_users_db_version);
}
// adds Attending Users as page under Settings
function att_admin_actions() {
add_options_page ("Attending Users", "Att Users Settings", 8, "att-user-titles", array(&$this, att_admin));
}
// content of options page
function att_admin() {
global $wpdb, $att_global_settings;
$att_global_settings = get_option('att_reg_settings');
if (!current_user_can('manage_options')) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
// adds new title to the list of titles
if ($_POST['add_title']) {
$add_title = $_POST['add_title'];
$wpdb->query("
INSERT INTO ".$wpdb->prefix."att_list_titles (att_title)
VALUE ('$add_title')
");
}
// delete a title from the list of titles
if ($_GET['delete_title']) {
$delete_title = $_GET['delete_title'];
$wpdb->query("
DELETE FROM ".$wpdb->prefix."att_list_titles
WHERE att_title = '$delete_title'
");
}
// deletes post types from the list of post types
$delete_post_type = $_GET['delete_post_type'];
$that_post_type = $att_global_settings['att_post_types'];
if ( isset($_GET['delete_post_type'])) {
unset($att_global_settings['att_post_types'][$delete_post_type]);
}
echo '
Titles for Attending Users Lists
From this page you can add new titles for Attending Users Lists, or delete existing
';
// view for form for adding new titles
echo '
Add Title
'
;
// view listing titles and giving option to delete them
echo '
';
}
echo '';
/* the folloring statements check if there are comming new values for the supported options
* name of subscribe button
* name of unsubscribe button
* name of message for not logged in users
* name of new content type */
if ($_POST['att_btn_sub'] != null) {
$att_global_settings['att_btn_sub'] = $_POST['att_btn_sub'];
}
if ($_POST['att_btn_unsub'] != null ) {
$att_global_settings['att_btn_unsub'] = $_POST['att_btn_unsub'];
}
if ($_POST['att_msg_not_logged'] != null) {
$att_global_settings['att_msg_not_logged'] = $_POST['att_msg_not_logged'];
}
if ($_POST['att_post_types'] != null) {
$att_global_settings['att_post_types'][] = $_POST['att_post_types'];
}
update_option('att_reg_settings', $att_global_settings);
// view of form for adding new post types
?>
ID);
$att_add_title = $custom["att_add_title"][0];
if ($att_add_title) {
// establish database connection between the post and the selected title
$wpdb->query ("
INSERT INTO ".$wpdb->prefix."att_titles (att_title, att_post_id)
VALUES ('".$att_add_title."', '".$post->ID."')
");
// update the title - no matter if changed or not
$wpdb->query ("
UPDATE ".$wpdb->prefix."att_titles
SET att_title='".$att_add_title."'
WHERE att_post_id='".$post->ID."'
");
}
// if $att_add_title == null - delete all users from the list and the title reference
// ps. may be I should change that code, because it adds extra queries to the system
else {
$wpdb->query ("
DELETE
FROM ".$wpdb->prefix."att_users
WHERE att_post_id = ".$post->ID."
");
$wpdb->query ("
DELETE
FROM ".$wpdb->prefix."att_titles
WHERE att_post_id = ".$post->ID."
");
}
// get all titles from the database
$titles = $wpdb->get_results("
SELECT *
FROM ".$wpdb->prefix."att_list_titles
");
echo '
Choose title for Attending List: