Author URI: http://jparks.net */ // Defines define('LIBRARY_IMG_URL_P1', 'http://ec1.images-amazon.com/images/P/'); define('LIBRARY_IMG_URL_P2', '.01._SCTHUMBZZZZ_.jpg'); define('THIS_FILE', 'edit.php?page=bookshelf.php'); define('TABLE_SUFFIX', 'bookshelf'); define('AMAZON_LINK_PREFIX', 'http://www.amazon.com/exec/obidos/redirect?link_code=as2&path=ASIN/'); define('AMAZON_LINK_SUFFIX', '&tag=jparksnet-20&camp=1789&creative=9325'); // Actions add_action('activate_bookshelf.php','bookshelf_install'); add_action('admin_menu', 'bookshelf_add_pages'); // Functions function bookshelf_install() { global $table_prefix, $wpdb; $table_name = $table_prefix . TABLE_SUFFIX; if($wpdb->get_var("show tables like '$table_name'") != $table_name) { $sql = "CREATE TABLE ".$table_name." ( id mediumint(9) NOT NULL AUTO_INCREMENT, isbn VARCHAR(13) NOT NULL, date_started date DEFAULT '0000-00-00' NOT NULL, date_finished date DEFAULT '0000-00-00' NOT NULL, author VARCHAR(55) NOT NULL, title VARCHAR(55) NOT NULL, img_url VARCHAR(255) NOT NULL, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/upgrade-functions.php'); dbDelta($sql); update_option('shoutbox_fade_from', "666666"); update_option('shoutbox_fade_to', "FFFFFF"); update_option('shoutbox_update_seconds', 4000); } } function bookshelf_add_pages() { add_management_page('Bookshelf', 'Bookshelf', 8, __FILE__, 'bookshelf_manage_page'); } function bookshelf_unset_get_vars() { unset($_GET['edit']); unset($_GET['delete']); } function bookshelf_manage_page() { global $table_prefix, $wpdb; $table_name = $table_prefix . TABLE_SUFFIX; $messages[1] = __('Book added.'); $messages[2] = __('Book updated.'); $messages[3] = __('Book deleted.'); $message = 0; if (isset($_POST['addbook'])) { $isbn = $_POST['isbn']; $title = $_POST['title']; $author = $_POST['author']; $date_started = $_POST['date_started']; $date_finished = $_POST['date_finished']; $img_url = LIBRARY_IMG_URL_P1 . $isbn . LIBRARY_IMG_URL_P2; $insert = "INSERT INTO " . $table_name . " (isbn,date_started,date_finished,author,title,img_url) ". "VALUES ('" . $isbn . "','" . $date_started . "','" . $date_finished . "','" . $author . "','" . $title . "','" . $img_url ."')"; $wpdb->query($insert); $message = 1; // unset the get vars so that we don't // process anything other than the add bookshelf_unset_get_vars(); } else if (isset($_POST['updatebook'])) { $id = $_POST['id']; $isbn = $_POST['isbn']; $title = $_POST['title']; $author = $_POST['author']; $date_started = $_POST['date_started']; $date_finished = $_POST['date_finished']; $img_url = $_POST['img_url']; if ($img_url == "") { $img_url = LIBRARY_IMG_URL_P1 . $isbn . LIBRARY_IMG_URL_P2; } $update = "UPDATE " . $table_name . " SET " . "isbn='" . $isbn . "'," . "date_started='" . $date_started . "'," . "date_finished='" . $date_finished . "'," . "author = '" . $author . "'," . "title='" . $title . "'," . "img_url='" . $img_url . "' WHERE id=". $id; $wpdb->query($update); $message = 2; // unset the get vars so that we don't // process anything other than the update bookshelf_unset_get_vars(); } if (isset($_GET['delete'])) { $id = (int) $_REQUEST['delete']; $wpdb->query("DELETE FROM $table_name WHERE id='$id'"); $message = 3; // unset the get vars so that we don't // process anything other than the delete bookshelf_unset_get_vars(); } if (isset($_GET['edit'])) { $id = (int) $_GET['edit']; $row = $wpdb->get_row("SELECT * FROM $table_name WHERE id='$id'"); ?>
| id; ?> | isbn; ?> | date_started; ?> | date_finished; ?> | author; ?> | title; ?> |
|---|