Advertisement
artemisian

Untitled

Oct 27th, 2011
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.21 KB | None | 0 0
  1. <?php
  2. /*
  3. * Template Name: Fayres directory entry form
  4. */
  5. ?>
  6.  
  7.  
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
  10.  
  11. <head profile="http://gmpg.org/xfn/11">
  12.     <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
  13.  
  14.     <title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
  15.  
  16.     <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
  17.     <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/custom.css" type="text/css" media="screen, print" />
  18.     <!--[if IE 7]><link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/ie7.css" type="text/css" media="screen" /><![endif]-->
  19.     <!--[if IE 6]><link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/ie6.css" type="text/css" media="screen" /><![endif]-->
  20.     <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/print.css" type="text/css" media="print" />
  21.     <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> RSS Feed" href="<?php bloginfo('rss2_url'); ?>" />
  22.     <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> Atom Feed" href="<?php bloginfo('atom_url'); ?>" />
  23.     <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
  24.  
  25.     <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
  26.  
  27.     <?php wp_head(); ?>
  28.    
  29.     <link type="text/css" href="<?php bloginfo('template_url'); ?>/jquery/css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />
  30.     <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/jquery/js/jquery-1.6.2.min.js"></script>
  31.     <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/jquery/js/jquery-ui-1.8.16.custom.min.js"></script>
  32.     <script>
  33.     $(function() {
  34.         $( "#datepicker" ).datepicker({
  35.             dateFormat: 'dd/mm/yy',
  36.             numberOfMonths: 3,
  37.             showButtonPanel: true
  38.             });
  39.     });
  40.     </script>
  41.  
  42. </head>
  43.  
  44. <body>
  45.  
  46.     <ul id="shortcuts" title="Accessibility shortcuts menu">
  47.         <li><a href="#maincontent">Skip to main content</a></li>
  48.     </ul>
  49.  
  50. <div id="container"><div id="wrapper">
  51.  
  52.     <div id="branding">
  53.         <a href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?> homepage"><img src="<?php bloginfo('template_url'); ?>/images/logo.gif" alt="<?php bloginfo('name'); ?>" id="logo" /></a>
  54.         <p id="strap"><?php bloginfo('description'); ?></p>
  55.         <?php // Check if this is a post or page, if it has a thumbnail, and if it's a big one
  56.             if ( is_singular() &&
  57.             has_post_thumbnail( $post->ID ) &&
  58.             ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail') ) &&
  59.             $image[1] >= HEADER_IMAGE_WIDTH ) :
  60.             // We have a new header image!
  61.             echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
  62.             else : ?>
  63.             <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
  64.         <?php endif; ?>
  65.     </div><!--branding-->
  66.    
  67.     <div id="mainmenu" role="navigation">
  68.         <?php // Navigation menu.  If one isn't filled out, wp_nav_menu falls back to wp_page_menu.  The menu assiged to the primary position is the one used.  If none is assigned, the menu with the lowest ID is used.  // ?>
  69.         <?php wp_nav_menu( array( 'container' => '', 'theme_location' => 'primary' ) ); ?>
  70.     </div><!--mainmenu -->
  71.  
  72.     <div id="contentcontainer">
  73.    
  74.         <div id="maincontent" class="withsidebar">
  75.        
  76.             <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  77.                 <h1><?php the_title(); ?></h1> 
  78.                 <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
  79.             <?php endwhile; endif; ?>
  80.            
  81.            
  82.            
  83.            
  84.            
  85.          
  86.             <?php
  87.                                      
  88.                 global $wpdb;
  89.                 global $post;
  90.                 $title = $_POST['title']; // get the inputted title
  91.                 $content = $_POST['content']; // get the inputted content
  92.                 $categorie = $_POST['cat'];  // get the category selected by user
  93.                 $zombies = $_POST['zombies'];
  94.                 $venue = $_POST['venue_name'];
  95.                 $date = $_POST['datepicker'];
  96.                 $starttime = $_POST['start_time'];
  97.                 $endtime = $_POST['end_time'];
  98.                 $entry = $_POST['entry_fee'];
  99.                 $link = $_POST['link'];
  100.                 $address = $_POST['venue_address'];
  101.                 $contact = $_POST['contact_name'];
  102.                 $phone = $_POST['contact_number'];
  103.                 $email = $_POST['contact_email'];
  104.                
  105.                 list ($day, $month, $year) = split ("/", $date);
  106.                 $usdate = $month."/".$day."/".$year;
  107.                 $countdowndate = $year."-".$month."-".$day;
  108.                
  109.                 # run a query to check for a post containing the data that our user is about to submit
  110.                 # store results in $verifica
  111.                 $sql = "
  112.                 SELECT wposts.*
  113.                 FROM $wpdb->posts wposts
  114.                     LEFT JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id
  115.                     LEFT JOIN $wpdb->term_relationships ON (wposts.ID = $wpdb->term_relationships.object_id)
  116.                     LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
  117.                 WHERE wposts.post_status = 'publish'
  118.                     AND wposts.post_title = '$title'
  119.                     AND wposts.post_content = '$content'
  120.                     AND $wpdb->term_taxonomy.taxonomy = 'category'
  121.                     AND $wpdb->term_taxonomy.term_id IN($categorie)";
  122.                 $verifica = $wpdb->get_results($sql);
  123.                
  124.                   if( 'POST' == $_SERVER['REQUEST_METHOD'] ) { // if form has been submitted
  125.                  
  126.                   # some validation
  127.                       if(empty($title)) {
  128.                         echo "Please give your post a title<br />";
  129.                       }
  130.                       if (empty($content)){
  131.                         echo "Please write your post's content<br />";
  132.                       }
  133.                       if ($categorie == -1){
  134.                            echo "Please assign a category to your post.<br />";
  135.                       }
  136.                       # if there are no similar posts ($verifica is empty) and user filled in the fields, insert post
  137.                       # also, redirect to the homepage to make sure we don't get 404-ed
  138.                       if (empty($verifica) && !empty($title) && !empty($content) && $categorie != -1) {
  139.                         $my_post = array(
  140.                          'post_title' => $title,
  141.                          'post_excerpt' => $content,
  142.                          'post_status' => 'draft',
  143.                          'post_author' => 1,
  144.                          'tax_input' => array( 'fayre-region' => $categorie ),
  145.                          'post_type'    => 'fayres'
  146.                           );
  147.                          
  148.                     $my_post = wp_insert_post($my_post);
  149.                     add_post_meta($my_post, 'venue_name', $venue);
  150.                     add_post_meta($my_post, 'fayre_date', $countdowndate);
  151.                     add_post_meta($my_post, 'fayre_start_time', $starttime);
  152.                     add_post_meta($my_post, 'fayre_end_time', $endtime);
  153.                     add_post_meta($my_post, 'entry_fee', $entry);
  154.                     add_post_meta($my_post, 'link', $link);
  155.                     add_post_meta($my_post, 'venue_address', $address);
  156.                     add_post_meta($my_post, 'contact_name', $contact);
  157.                     add_post_meta($my_post, 'contact_number', $phone);
  158.                     add_post_meta($my_post, 'contact_email', $email);
  159.                    
  160.                     if (!function_exists('wp_generate_attachment_metadata')){
  161.                         require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  162.                         require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  163.                         require_once(ABSPATH . "wp-admin" . '/includes/media.php');
  164.                     }
  165.                      if ($_FILES) {
  166.                         foreach ($_FILES as $file => $array) {
  167.                             if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
  168.                                 return "upload error : " . $_FILES[$file]['error'];
  169.                             }
  170.                             $attach_id = media_handle_upload( $file, $my_post );
  171.                         }  
  172.                     }
  173.                     if ($attach_id > 0){
  174.                         //and if you want to set that image as Post  then use:
  175.                         update_post_meta($my_post,'_thumbnail_id',$attach_id);
  176.                     }
  177.                    
  178.                     wp_redirect( home_url() );
  179.                       }
  180.                      
  181.                       # if $verifica is not empty, then we don't insert the post and we display a message
  182.                       else if( !empty($verifica) ) { echo "You are trying to submit the same post twice! Be nice.";  }
  183.                   }
  184.                  
  185.             ?>
  186.            
  187.             <form action="" method="post" name="FayreEntryForm" class="fayre-entry-form" enctype="multipart/form-data">
  188.                 <p>Submit your details for only &pound;20 (we will phone to take your payment once you have filled out the form below).</p>
  189.                 <p><em>Please note this service is FREE to our advertisers, please contact the office for more information.</em></p>
  190.                 <h3>Fayre details</h3>
  191.                 <p>
  192.                     <label for="title">Name of fayre</label>
  193.                     <input type="text" name="title" id="title" class="large" />
  194.                 </p>
  195.                 <p>
  196.                     <label for="datepicker">Date of fayre</label>
  197.                     <input type="text" id="datepicker" name="datepicker" class="medium" />
  198.                 </p>
  199.                 <p>
  200.                     <label for="start_time">Opening time</label>
  201.                     <input type="text" id="start_time" name="start_time" class="small" />
  202.                 </p>
  203.                 <p>
  204.                     <label for="end_time">Closing time</label>
  205.                     <input type="text" id="end_time" name="end_time" class="small" />
  206.                 </p>
  207.                 <p>
  208.                     <label for="cat">Region</label>
  209.                     <?php wp_dropdown_categories('show_option_none=Select region&show_count=0&hide_empty=0&echo=1&taxonomy=fayre-region'); ?>
  210.                 </p>
  211.                 <p>
  212.                     <label for="venue_name">Venue name</label>
  213.                     <input type="text" name="venue_name" id="venue_name" class="large" />
  214.                 </p>
  215.                 <p>
  216.                     <label for="venue_address">Venue address</label>
  217.                     <input type="text" name="venue_address" id="venue_address" class="large" />
  218.                 </p>
  219.                 <p>
  220.                     <label for="entry_fee">Entry fee</label>
  221.                     <input type="text" name="entry_fee" id="entry_fee" class="small" value="&pound;" />
  222.                 </p>
  223.                 <p>
  224.                     <label for="link">Fayre website</label>
  225.                     <input type="text" name="link" id="link" value="http://" class="large" />
  226.                 </p>
  227.                 <p>
  228.                     <label for="content">Brief description of fayre (up to 50 words)</label>
  229.                     <textarea name="content" id="content" cols="30" rows="5" class="large"></textarea>
  230.                 </p>
  231.                 <p>
  232.                     <label for="thumbnail">Image of venue (150x150 pixels)</label>
  233.                     <input type="file" name="thumbnail" id="thumbnail" />
  234.                 </p>
  235.                
  236.                 <h3>Contact details</h3>
  237.                 <p>Please enter your contact details. This is just for our records, and won't be posted with your entry.</p>
  238.                 <p>
  239.                     <label for="contact_name">Contact name</label>
  240.                     <input type="text" name="contact_name" id="contact_name" class="medium" />
  241.                 </p>
  242.                 <p>
  243.                     <label for="contact_number">Contact phone no.</label>
  244.                     <input type="text" name="contact_number" id="contact_number" class="medium" />
  245.                 </p>
  246.                 <p>
  247.                     <label for="contact_email">Contact email</label>
  248.                     <input type="text" name="contact_email" id="contact_email" class="large" />
  249.                 </p>
  250.                 <p id="submitrow"><input type="submit" value="Submit entry"></p>
  251.                 <?php wp_nonce_field( 'FayreEntryForm' ); ?>
  252.  
  253.             </form>
  254.            
  255.  
  256.            
  257.            
  258.            
  259.         </div><!--maincontent-->
  260.        
  261.         <div id="sidebar">
  262.             <ul class="widgets">
  263.                 <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Site sidebar') ) : ?>
  264.                 <?php endif; ?>
  265.             </ul>
  266.         </div><!--sidebar-->
  267.        
  268. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement