@import "'. GRE_URLPATH .'/admin/admin.css";'."\n"; } add_action ('admin_head','greatrealestate_add_adminhead'); # additional custom fields on page edit form function greatrealestate_add_edit() { global $post_ID; global $post; global $wpdb; global $listing; # only add this stuff if the Page is subpage of the Listings Main Page # [2008-07-22] added logic to handle case where post has no parent # and option has not been set if ($post->post_parent && (get_option('greatrealestate_pageforlistings') == $post->post_parent)) { # get the listing data associated with the post/page $listing = $wpdb->get_row("SELECT * FROM $wpdb->gre_listings WHERE pageid = '$post_ID'"); include (dirname (__FILE__).'/editpage.php'); } } add_action('edit_page_form', 'greatrealestate_add_edit', 90); # corresponding header content for page edit (page.php) function greatrealestate_add_edit_js() { // We're trying not to toss this in every dang admin page global $post; # [2008-07-22] added logic to handle case where post has no parent # and option has not been set if ($post->post_parent && (get_option('greatrealestate_pageforlistings') == $post->post_parent)) { # wp_enqueue_script('jquery'); # for some reason enqueue doesn't work in admin screens ?> \n"; ?> get_var("SELECT post_parent from $wpdb->posts WHERE ID = '$postID' LIMIT 1"); if (! ($listparent == $postparent )) return; # first, do we already have a listing record associated with # this particular post? # if so, get the id # NOTE: we are being passed an id $postID in the function call if ($postID > 0) { $listdata_id = $wpdb->get_var("SELECT id from $wpdb->gre_listings WHERE pageid = '$postID' LIMIT 1"); } # filter input, store it (new or update) # not much checking, yet... some JS validation on edit form # to clear out an entry we update even if blank # $listing->pageid = $postID; $listing->mlsid = $_POST['listings_mlsid']; $listing->address = $_POST['listings_address']; $listing->city = $_POST['listings_city']; $listing->state = $_POST['listings_state']; $listing->postcode = $_POST['listings_postcode']; $listing->featured = $_POST['listings_featured']; $listing->status = $_POST['listings_status']; $listing->blurb = $_POST['listings_blurb']; $listing->listdate = to_mysqldate($_POST['listings_listdate']); $listing->listprice = $_POST['listings_listprice']; $listing->saledate = to_mysqldate($_POST['listings_saledate']); $listing->saleprice = $_POST['listings_saleprice']; $listing->latitude = $_POST['listings_latitude']; $listing->longitude = $_POST['listings_longitude']; $listing->galleryid = $_POST['listings_galleryid']; $listing->videoid = $_POST['listings_videoid']; $listing->downloadid = $_POST['listings_downloadid']; # multi-select $listing->panoid = $_POST['listings_panoid']; # multi-select $listing->featureid = $_POST['listings_featureid']; # multi-select $listing->bedrooms = $_POST['listings_bedrooms']; $listing->bathrooms = $_POST['listings_bathrooms']; $listing->halfbaths = $_POST['listings_halfbaths']; $listing->garage = $_POST['listings_garage']; $listing->acsf = $_POST['listings_acsf']; $listing->totsf = $_POST['listings_totsf']; $listing->acres = $_POST['listings_acres']; # rearrange any multi-selects, ie arrays, into comma delimited foreach ($listing as $lkey => $lvalue) { if (is_array($lvalue)) { $listing->$lkey = implode(',',$lvalue); } } if ($listdata_id) { # update existing record # safer to reference the index on update $sql = "UPDATE $wpdb->gre_listings SET "; foreach ($listing as $lkey => $lvalue) { $sql .= "$lkey = '$lvalue', "; } $sql = substr($sql,0,-2); // remove last comma $sql .= " WHERE id = '$listdata_id'"; $wpdb->query($sql); } else { # new association - link to current post id if ($postID) { $sql = "INSERT INTO $wpdb->gre_listings ("; $values = ' VALUES ('; foreach ($listing as $lkey => $lvalue) { $sql .= "$lkey,"; $values .= "'$lvalue',"; } $sql = substr($sql,0,-1); // remove last comma $values = substr($values,0,-1); // remove last comma $sql .= ') ' . $values . ') '; $wpdb->query($sql); } else { // Whoops - can't save, no post id echo "WHOA! we dont know the page id (given $postID)"; exit; } } } add_action('save_post', 'greatrealestate_add_savepage'); # utility functions for edit page # return list of options, with current option selected function re_status_dropdown($currstatus) { global $re_status; // array with all valid statuses $ddlist = ""; foreach ($re_status as $id => $status) { $mysel = ($currstatus == $id) ? ' selected="selected"' : ""; $ddlist .= "$status"; } echo $ddlist; return; } function get_listing_panodropdown($currid = '') { global $wpdb; global $post; $id = $post->ID; $currids = explode(',',$currid); $files = get_children("post_parent=$id&post_type=attachment&post_mime_type=video/quicktime"); if($files) { foreach($files as $fid => $attachment) { echo ''."\n\t"; } } } function get_listing_featuredropdown($currid = '') { global $wpdb; global $post; global $re_features; $id = $post->ID; $currids = explode(',',$currid); $features = $re_features; if($features) { foreach($features as $fid => $label) { echo ''."\n\t"; } } } ?>