Exemple #1
0
    public function wpws_menu_settings()
    {
        //Load current set pages
        $wpws_settings_pages = get_option('wpws_settings_pages');
        $wpws_settings_pages['wpws_order_page'] = !empty($wpws_settings_pages['wpws_order_page']) ? $wpws_settings_pages['wpws_order_page'] : array();
        $wpws_settings_pages['wpws_product_page'] = !empty($wpws_settings_pages['wpws_product_page']) ? $wpws_settings_pages['wpws_product_page'] : array();
        //Load existing pages
        $args_page = array('sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'authors' => '', 'child_of' => 0, 'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish');
        $pagesA = get_pages($args_page);
        ?>
	<div class="wrap">
    
          <!-- Display confirmation message -->
		<?php 
        if (isset($_GET['updated']) && $_GET['updated']) {
            ?>
        
    		<div id="message" class="updated"> Settings saved!</div>
            
		<?php 
        } else {
            if (isset($_GET['errorMsg']) && $_GET['errorMsg']) {
                $msgID = intval($_GET['errorMsg']);
                ?>
 
				<div id="message" class="error"> <?php 
                echo WPWS_Menu::$errorMessages[$msgID];
                ?>
</div>
		<?php 
            }
        }
        ?>
    
    <h2>Settings</h2>	
    <h3>Pages</h3>
 
            <form method="post" action="<?php 
        echo admin_url('admin-post.php');
        ?>
">

	<!-- to determine which action to process -->
	  <input type="hidden" name="action" value="save_settings_pages" />
	  
	  <!-- Adding security through hidden referrer field -->
	  <?php 
        wp_nonce_field('wpws_settings_pages');
        ?>
      

<table width="768" class="wide-fat">

     <tr>
     	<td colspan="3">Please select your Order and Product page, then hit 'Submit' to set them.<br />
     	  Remember to add the correct short code on the pages.</td>
     </tr>
     
     <tr>
			<td width="24%">Order page:</td>
			<td width="76%">
            <select name="wpws_order_page">
            <option value="0">-- Select--</option>
            <?php 
        foreach ($pagesA as $page) {
            ?>
            	<option value="<?php 
            echo $page->ID;
            ?>
" <?php 
            echo selected($wpws_settings_pages['wpws_order_page'], $page->ID);
            ?>
><?php 
            echo $page->post_title;
            ?>
</option>
            <?php 
        }
        ?>
            </select>&nbsp;(page that will display the article submission form)</td>
  </tr>
        
        <tr>
			<td>Product listing page:</td>
			<td> 
            <select name="wpws_product_page">
            <option value="0">-- Select--</option>
            <?php 
        foreach ($pagesA as $page) {
            ?>
            	<option value="<?php 
            echo $page->ID;
            ?>
" <?php 
            echo selected($wpws_settings_pages['wpws_product_page'], $page->ID);
            ?>
><?php 
            echo $page->post_title;
            ?>
</option>
            <?php 
        }
        ?>
            </select>
			  (page that will display your services/products)</td>
		</tr>
        
	</table>

<input type="submit" value="Submit" class="button-primary"/>
</form><hr />

<h3>Categories</h3>
<form method="post" action="<?php 
        echo admin_url('admin-post.php');
        ?>
">

	<!-- to determine which action to process -->
    <input type="hidden" name="action" value="save_settings_categories" />
	  
	  <!-- Adding security through hidden referrer field -->
	  <?php 
        wp_nonce_field('wpws_settings_categories');
        ?>
      

<table width="768" class="wide-fat">

     <tr>
     	<td colspan="3"><p>Check the category that will be part of WPWS categories for your article product. In other words, you will create a subcategory list based on the categories you created in the 'Posts' section. These will be in the drop-down menu on the &quot;Order page&quot;</p></td>
     </tr>
     
     <tr>
			<td width="15%" valign="top">
            <?php 
        // Retrieve array of all categories
        $args = array('type' => 'post', 'child_of' => 0, 'parent' => '', 'orderby' => 'id', 'order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'number' => '', 'taxonomy' => 'category', 'pad_counts' => false);
        $categories = get_categories($args);
        //retrieve the saved selected categories from the Options table
        $mycategories = get_option('wpws_categories');
        $mycategories = !empty($mycategories) ? $mycategories : array();
        // Check if categories were found
        if (!is_wp_error($categories) && !empty($categories)) {
            echo '<ul>';
            // Display all types
            foreach ($categories as $category) {
                ?>
							<li><input name="wpws_product_category[]" type="checkbox" value="<?php 
                echo $category->term_id;
                ?>
" <?php 
                if (in_array($category->term_id, $mycategories)) {
                    echo 'checked';
                }
                ?>
 /><?php 
                echo $category->name;
                ?>
</li>
						
                        <?php 
            }
            echo '</ul>';
        }
        ?>
            
            
            </td>

  </tr>
        
	</table>

<input type="submit" value="Submit" class="button-primary"/>
</form><hr />


<h3>Products</h3>
<form method="post" action="<?php 
        echo admin_url('admin-post.php');
        ?>
">

	<!-- to determine which action to process -->
    <input type="hidden" name="action" value="save_settings_products" />
	  
	  <!-- Adding security through hidden referrer field -->
	  <?php 
        wp_nonce_field('wpws_settings_products');
        ?>
      

<table width="768" class="wide-fat">

     <tr>
     	<td colspan="3"><p>Please select the product Type on the left column and a Length on the right column. The combination of the two will generate a new product (i.e. Article+Short).</p></td>
     </tr>
     
     <tr>
     	<th align="left">Type</th>
        <th align="left">Length</th>
     </tr>
     
     <tr>
			<td width="15%" valign="top">
            <?php 
        // Retrieve array of all types in system
        //$types = get_terms( 'wpws_article_type', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
        $taxonomy_id = WPWS_Model::getTaxonomyID('Type');
        $types = WPWS_Model::getTerms($taxonomy_id);
        // Check if types were found
        if (!is_wp_error($types) && !empty($types)) {
            echo '<ul>';
            // Display all types
            foreach ($types as $type) {
                ?>
							<li><input name="wpws_product_type" type="radio" value="<?php 
                echo $type->term_id;
                ?>
" /><?php 
                echo $type->term;
                ?>
</li>
						
                        <?php 
            }
            echo '</ul>';
        }
        ?>
            
            
            </td>
			<td width="85%" valign="top">
              <?php 
        // Retrieve array of all lengths in system
        //$lengths = get_terms( 'wpws_article_length', array( 'orderby' => 'name', 'hide_empty' => 0 ) );
        $taxonomy_id = WPWS_Model::getTaxonomyID('Length');
        $lengths = WPWS_Model::getTerms($taxonomy_id);
        // Check if types were found
        if (!is_wp_error($lengths) && !empty($lengths)) {
            echo '<ul>';
            // Display all lengths
            foreach ($lengths as $length) {
                ?>
							<li><input name="wpws_product_length" type="radio" value="<?php 
                echo $length->term_id;
                ?>
" /><?php 
                echo $length->term;
                ?>
</li>
						
                        <?php 
            }
            echo '</ul>';
        }
        ?>
            
            
            </td>
  </tr>
        
	</table>

<input type="submit" value="Submit" class="button-primary"/>
</form><hr />

<h3>Prices/Products</h3>

<form method="post" action="<?php 
        echo admin_url('admin-post.php');
        ?>
">

	<!-- to determine which action to process -->
    <input type="hidden" name="action" value="save_settings_prices" />
	  
	  <!-- Adding security through hidden referrer field -->
	  <?php 
        wp_nonce_field('wpws_settings_prices');
        ?>
      
      <?php 
        //The link set for the 'Order'
        //(set at the time, so the variable can be reusable in the instruction)
        //Load current set pages
        $wpws_settings_pages = get_option('wpws_settings_pages');
        $wpws_order_page = $wpws_settings_pages['wpws_order_page'];
        $thelink = get_permalink($wpws_order_page);
        ?>
      

<table width="100%" class="wide-fat wp-list-table">

     <tr>
     	<td colspan="11"><p>Once you selected to create a product above, you will see it in the list below, which also contains unique URL that links to your product order form. In addition, you may delete your product or edit its price.</p>
   	    <p>To delete a product, just click the [X] on which Product ID you want to remove.<br />
   	      To update a Price, just enter your new price and hit 'Submit'.   	      </p>
   	    <p>The 'Defaut' option allows you to pick a default product/service to be displayed if your client just lands on the <a href="<?php 
        echo $thelink;
        ?>
" target="_new">Order</a> page (without any product selected yet).<br />
        </p></td>
     </tr>

        <tr>
        <th width="2%">&nbsp;</th>
        <th width="7%" align="left">Is Default?</th>
        <th width="13%" align="left">&nbsp;Product ID/Item Number</th>
        <th width="7%" align="left">Type</th>
        <th width="8%" align="left">Length</th>
        <th width="8%" align="left">Price</th>
        <th width="55%" align="left">URL (use for linking to an individual writing service/product on the Order page)</th>
      	</tr>
    </thead>
  
  <?php 
        $productA = WPWS_Model::getProducts();
        if ($productA) {
            $wpws_default_product = get_option('wpws_default_product');
            //get default product ID (if not set, it's 1)
            foreach ($productA as $product) {
                $productID = $product->productID;
                $type = WPWS_Model::getTermByTermID($product->term_id_type);
                $length = WPWS_Model::getTermByTermID($product->term_id_length);
                $delURL = add_query_arg(array('page' => 'wpws-settings', 'action' => 'del', 'productID' => $productID), admin_url('admin.php'));
                $url = $thelink . '?productID=' . $productID;
                ?>
  <tr>
    <td>&nbsp;<a href="<?php 
                echo $delURL;
                ?>
">[X]</a></td>
    <td>&nbsp;<input type="radio" name="wpws_product_default" value="<?php 
                echo $productID;
                ?>
" <?php 
                checked($wpws_default_product, $productID);
                ?>
/></td>
    <td>&nbsp;<?php 
                echo $productID;
                ?>
</td>
    <td>&nbsp;<?php 
                echo $type;
                ?>
</td>
    <td>&nbsp;<?php 
                echo $length;
                ?>
</td>
    <td>&nbsp;$<input name="wpws_product_price[<?php 
                echo $productID;
                ?>
]" type="text" size="7" maxlength="10" value="<?php 
                echo $product->price;
                ?>
" /></td>
    <td>&nbsp;<input name="wpws_product_url" type="text" value="<?php 
                echo esc_attr($url);
                ?>
" size="60" readonly="readonly" /></td>
  </tr>
  <?php 
            }
        } else {
            ?>
	
<tr>
    <td colspan="8">&nbsp;No Products</td>

  </tr>
  <?php 
        }
        ?>
  

     
        
</table>

<input type="submit" value="Submit" class="button-primary"/>
</form><hr />

<h3>Paypal Email</h3>


<?php 
        $wpws_settings_payemail = get_option('wpws_settings_payemail');
        ?>

<form method="post" action="<?php 
        echo admin_url('admin-post.php');
        ?>
">

	<!-- to determine which action to process -->
    <input type="hidden" name="action" value="save_settings_payemail" />
	  
	  <!-- Adding security through hidden referrer field -->
	  <?php 
        wp_nonce_field('wpws_settings_payemail');
        ?>
      
      

<p>Enter the PayPal email which you will accept payment from. </p>


<input name="wpws_payemail" type="text" value="<?php 
        echo $wpws_settings_payemail;
        ?>
" size="25" /></td>

<input type="submit" value="Submit" class="button-primary"/>
</form><hr />





</div>

        
    <?php 
    }