Advertisement
mpa4hu

Untitled

Apr 14th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 30.90 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Template Name: Edit Posts
  4.  */
  5.  
  6.     $user_id = get_current_user_id();
  7.     global $get_admin_blog;
  8.     global $post;
  9.     global $switched;
  10.     $postTitleError = '';
  11.     $postPriceError = '';
  12.     if($user_id == 1) {
  13.         $blogs = get_user_blogs_by_role( $user_id, 'administrator' );
  14.     } else {
  15.         $blogs = get_user_blogs_by_role( $user_id, 'editor');
  16.     }
  17.     if(isset($_GET['blog'])) {
  18.         $get_admin_blog = $_GET['blog'];
  19.         // Check user if he's using right shop
  20.         $i = 0;
  21.         $is_admin = false;
  22.         foreach ($blogs as $blog) {
  23.             if($blog != 3 && $blog == $get_admin_blog) {
  24.                 $is_admin = true;
  25.             }
  26.         }
  27.         if($is_admin == true) {
  28.             switch_to_blog($get_admin_blog);
  29.         } else {
  30.             $postTitleError = 'You are using someone else\'s blog';
  31.             $hasError = true;
  32.             die('<br />'.$postTitleError.'<br />');
  33.         }
  34.     } else {
  35.         $i = 0;
  36.         foreach ($blogs as $blog) {
  37.             if($blog != 3) {
  38.                 $blogarray[$i] = $blog;
  39.                 $i++;
  40.             }
  41.         }
  42.         if($i == 1) {
  43.             $get_admin_blog = $blogarray[0];
  44.             switch_to_blog($get_admin_blog);
  45.         } else {
  46.             $postTitleError = 'Please Select your Shop from dropdown';
  47.             $hasError = true;
  48.             die('<br />'.$postTitleError.'<br />');
  49.         }
  50.     }
  51.  
  52.     // Go and grab currently editing product and it's children
  53.     $query = new WP_Query( array( 'post_type' => 'wpsc-product', 'posts_per_page' => '-1', 'post_status' => 'any') );
  54.     if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
  55.         if ( isset( $_GET['post'] ) ) {
  56.             if ( $_GET['post'] == $post->ID ) {
  57.                 $current_post = $post->ID;
  58.                 $current_post_parent = $post->post_parent;
  59.                 $cur_title = get_the_title();
  60.                 $cur_content = get_the_content();
  61.                 $cur_size = array(32,32);
  62.                 $cur_imgage = get_the_post_thumbnail($post->ID, $cur_size);
  63.                 $cur_stock = get_post_meta($post->ID, '_wpsc_stock', $single);
  64.                 $cur_price = get_post_meta($post->ID, '_wpsc_price', $single);
  65.                 $cur_special_price = get_post_meta($post->ID, '_wpsc_special_price', $single);
  66.                 $cur_sku = get_post_meta($post->ID, '_wpsc_sku', $single);
  67.                 $defaults = array(
  68.                     'post_parent' => $post->ID,
  69.                     'post_type'   => 'wpsc-product',
  70.                     'numberposts' => -1,
  71.                     'post_status' => 'any'
  72.                 );
  73.                 // Get post thumbnail
  74.                 $parentThumb = get_the_post_thumbnail($current_post, 'medium', array('class' => 'img-polaroid pull-right span12'));
  75.                 // Get parent children if exist
  76.                 $queryVariations = get_children( $defaults );
  77.                 // IF it does not has children, check if it got parent
  78.                 $post_is_parent = true;
  79.                 if (empty($queryVariations)) {
  80.                     if ($current_post_parent == 0) {
  81.                         $post_is_parent = true;
  82.                         $query_post_status = 'publish';
  83.                     } else {
  84.                         $post_is_parent = false;
  85.                         $query_post_status = 'inherit';
  86.                     }
  87.                 }
  88.                 // Get variations terms if exist
  89.                 $parentVariations = wp_get_post_terms( $current_post, 'wpsc-variation' );
  90.                 // get permalink
  91.                 $permalink = get_permalink( $current_post );
  92.             }
  93.         }
  94.  
  95.     endwhile; endif;
  96.     wp_reset_query();
  97.  
  98.     global $current_post;
  99.  
  100.     // get product media library
  101.     $mediaArgs = array(
  102.         'post_type'         => 'attachment',
  103.         'post_mime_type'    => 'image',
  104.         'numberposts'       => -1,
  105.         'post_status'       => null,
  106.         'post_parent'       => $current_post,
  107.     );
  108.     $MediaAttachments = get_posts($mediaArgs);
  109.  
  110.     $parentMediaArray = array();
  111.     foreach ($MediaAttachments as $MediaAttachment) {
  112.         $parentMediaArray[] = $MediaAttachment->ID;
  113.     }
  114.     // get ALL the media library exept that I'm using now
  115.     $mediaArgs2 = array(
  116.         'post_type'         => 'attachment',
  117.         'post_mime_type'    => 'image',
  118.         'numberposts'       => -1,
  119.         'post_status'       => null,
  120.         'exclude'           => $parentMediaArray,
  121.         'post_parent'       => 'any', // any parent
  122.     );
  123.     $MediaAttachmentsALL = get_posts($mediaArgs2);
  124.  
  125.     // add 'Selected' argument where ID == current_post category ID
  126.     //get categories dropdown
  127.     $term_name = strip_tags( get_the_term_list( $current_post, 'wpsc_product_category', '', ', ', '' ) );
  128.     $term_obj = get_term_by('name', $term_name, 'wpsc_product_category');
  129.     if($term_obj) {
  130.         $rterm_id = $term_obj->term_id;    
  131.     } else {
  132.         $rterm_id = '';
  133.     }
  134.  
  135.     $args2 = array(
  136.         'show_option_all' => '-- აირჩიეთ კატეგორია --',
  137.         'selected' => $rterm_id,
  138.         'hide_empty' => 0,
  139.         'tab_index' => 4,
  140.         'echo' => 0,
  141.         'name' => 'cat',
  142.         'hierarchical' => 1,
  143.         'taxonomy' => 'wpsc_product_category',
  144.         'hide_empty' => false );
  145.  
  146.     $dropdowncats = wp_dropdown_categories( $args2 );
  147.  
  148.     //get variations
  149.     $args=array(
  150.         'orderby' => 'id',
  151.         'order' => 'ASC',
  152.         'taxonomy' => 'wpsc-variation',
  153.         'hierarchical' => 1,
  154.         'hide_empty' => 0
  155.     );
  156.     $variationCategories=get_categories($args);
  157.     $hasError = false;
  158.     // EDIT POST
  159.     if(isset($_POST['submitted']) && isset($_POST['post_nonce_field']) && wp_verify_nonce($_POST['post_nonce_field'], 'post_nonce')) {
  160.         if(trim($_POST['postTitle']) === '') {
  161.             $postTitleError = 'პროდუქტს აუცილებლად უნდა ქონდეს დასახელება.';
  162.             $hasError = true;
  163.         } else {
  164.             $postTitle = trim($_POST['postTitle']);
  165.         }
  166.         if(trim($_POST['postPrice']) === '') {
  167.             $postPriceError = 'პროდუქტს აუცილებლად უნდა ქონდეს ფასი.';
  168.             $hasError = true;
  169.         } else {
  170.             $postPrice = trim($_POST['postPrice']);
  171.         }
  172.  
  173.         if ($hasError == false) {
  174.             // Create post object
  175.             $new_entry = array();
  176.             $new_entry['ID'] = $current_post;
  177.             $new_entry['post_title'] = esc_attr(strip_tags($_POST['postTitle']));
  178.             $new_entry['post_content'] = esc_attr(strip_tags($_POST['postContent']));
  179.             $new_entry['post_status'] = $query_post_status;
  180.         //  $new_entry['post_category'] = $_POST['cat'];
  181.             $new_entry['post_type'] = 'wpsc-product';
  182.             $new_entry['post_author'] = $user_id;
  183.             $post_id = wp_update_post($new_entry);
  184.             if($post_id) {
  185.                 // ON success
  186.                
  187.                 $price = esc_attr(strip_tags($_POST['postPrice']));
  188.                 $special_price = esc_attr(strip_tags($_POST['postSpecialPrice']));
  189.                 $sku = esc_attr(strip_tags($_POST['postSKU']));
  190.                 $stock = esc_attr(strip_tags($_POST['postStock']));
  191.                 if(isset($_POST['updateThumb'])) {
  192.                     $updateThumb = true;
  193.                 } else {
  194.                     $updateThumb = false;
  195.                 }
  196.                 if ($post_is_parent == true) {
  197.                     $terms = $_POST['cat'];
  198.                     wp_set_post_terms($post_id, $terms, 'wpsc_product_category');
  199.                 }
  200.                 update_post_meta($post_id, '_wpsc_price', $price);
  201.                 update_post_meta($post_id, '_wpsc_special_price', $special_price);
  202.                 update_post_meta($post_id, '_wpsc_sku', $sku);
  203.                 update_post_meta($post_id, '_wpsc_stock', $stock);
  204.                 if ($_FILES) {
  205.                     foreach ($_FILES as $file => $array) {
  206.                         if ($updateThumb == true) {
  207.                             $newupload = insert_attachment($file,$post_id, true);
  208.                         } else {                       
  209.                             $newupload = insert_attachment($file,$post_id, false);
  210.                         }
  211.                     }
  212.                 }
  213.                 $varArray = array();
  214.                 foreach($parentVariations as $variation) {
  215.                     $varArray[] = $variation->term_id;
  216.                 }
  217.                 if(isset($_POST['variationChild'])) {
  218.                     $parent = array();
  219.                     $children = array();
  220.                     $parent = $_POST['variationParent'];
  221.                     $children = $_POST['variationChild'];
  222.                     if(!empty($parent)) {
  223.                         $affparent = wp_set_post_terms( $post_id, $parent, 'wpsc-variation', true );
  224.                         $affchildren = wp_set_post_terms( $post_id, $children, 'wpsc-variation', true );
  225.                         $N = count($children);
  226.                         // here loop *(children power of parents  times)
  227.                         for($i=0; $i < $N; $i++) {
  228.                             $cat_id = (int) $children[$i];
  229.                             if(!in_array($cat_id,$varArray)){
  230.                                 $cat = get_term( $cat_id, 'wpsc-variation' );
  231.                                 $new_entr = array();
  232.                                 $new_entr['post_title'] = esc_attr(strip_tags($_POST['postTitle'])) . " (" . $cat->name . ")";
  233.                                 $new_entr['post_content'] = esc_attr(strip_tags($_POST['postContent']));
  234.                                 $new_entr['post_status'] = 'inherit';
  235.                                 $new_entr['post_category']  = $cat->term_id;
  236.                                 $new_entr['post_type'] = 'wpsc-product';
  237.                                 $new_entr['post_parent'] = $post_id;
  238.                                 $new_entr['post_author'] = $user_id;
  239.                                 $var_id = wp_insert_post($new_entr);
  240.                                 wp_set_post_terms( $var_id, $cat->term_id, 'wpsc-variation' );
  241.                                 update_post_meta($var_id, '_wpsc_price', $price);
  242.                                 update_post_meta($var_id, '_wpsc_special_price', $special_price);
  243.                                 update_post_meta($var_id, '_wpsc_sku', $sku);
  244.                                 update_post_meta($var_id, '_wpsc_stock', $stock);
  245.                             }
  246.                         }
  247.                     }
  248.                 }
  249.             }          
  250.         }
  251.     }
  252.     restore_current_blog();
  253. ?>
  254. <?php get_header(); ?>
  255. <form action="" id="primaryPostForm" method="POST" enctype="multipart/form-data">
  256.     <section class="section">
  257.         <div class="row-fluid">
  258.             <?php get_sidebar( 'left' ) ?>
  259.             <div class="span11">
  260.                 <div class="content">
  261.                     <div class="content-header">
  262.                         <ul class="content-header-action pull-right">
  263.                             <li>
  264.                                 <a href="#">
  265.                                     <canvas width="32" height="32"></canvas><span style="display: none;" data-chart="peity-bar" data-height="32" data-colours="[&quot;#00A600&quot;, &quot;#00A600&quot;]">5,3,9,6,5,9,7,3,5,2</span>
  266.                                     <div class="action-text color-green">8765 <span class="helper-font-small color-silver-dark">ვიზიტი</span></div>
  267.                                 </a>
  268.                             </li>
  269.                             <li class="divider"></li>
  270.                             <li>
  271.                                 <a href="#">
  272.                                     <canvas width="32" height="32"></canvas><span style="display: none;" data-chart="peity-bar" data-height="32" data-colours="[&quot;#00A0B1&quot;, &quot;#00A0B1&quot;]">9,7,9,6,3,5,3,5,5,2</span>
  273.                                     <div class="action-text color-teal">1437 <span class="helper-font-small color-silver-dark">მომხმა.</span></div>
  274.                                 </a>
  275.                             </li>
  276.                             <li class="divider"></li>
  277.                             <li>
  278.                                 <a href="#">
  279.                                     <canvas width="32" height="32"></canvas><span style="display: none;" data-chart="peity-bar" data-height="32" data-colours="[&quot;#BF1E4B&quot;, &quot;#BF1E4B&quot;]">6,5,9,7,3,5,2,5,3,9</span>
  280.                                     <div class="action-text color-red">4367 <span class="helper-font-small color-silver-dark">შეკვეთა</span></div>
  281.                                 </a>
  282.                             </li>
  283.                         </ul>
  284.                         <h2><i class="icofont-home"></i> Dashboard <small>შენ შემოგევლე</small></h2>
  285.                     </div>
  286.                     <div class="content-breadcrumb">
  287.                         <ul class="breadcrumb-nav pull-right">
  288.                             <li class="divider"></li>
  289.                             <li class="btn-group">
  290.                                 <button type="submit" href="#" class="btn btn-small btn-link">
  291.                                     <i class="icofont-ok-sign color-green"></i>შენახვა
  292.                                 </button>
  293.                             </li>
  294.                             <li class="divider"></li>
  295.                             <li class="btn-group">
  296.                                 <button href="#" class="btn btn-small btn-link">
  297.                                     <i class="icofont-remove-sign color-red"></i>წაშლა
  298.                                 </button>
  299.                             </li>
  300.                             <li class="divider"></li>
  301.                             <li class="btn-group">
  302.                                 <a href="<?php echo $permalink ?>" target="_blank" class="btn btn-small btn-link">
  303.                                     <i class="icofont-external-link"></i>პროდუქტის ნახვა
  304.                                 </a>
  305.                             </li>
  306.                             <li class="divider"></li>
  307.                             <li class="btn-group">
  308.                                 <a href="#" class="btn btn-small btn-link dropdown-toggle" data-toggle="dropdown">
  309.                                     <i class="icofont-tasks"></i>&nbsp;მაღაზია
  310.                                     <i class="icofont-caret-down"></i>
  311.                                 </a>
  312.                                 <ul class="dropdown-menu">
  313.                                     <?php
  314.                                         foreach ($blogs as $blog) {
  315.                                             if($blog != 3) {
  316.                                                 $blog_details = get_blog_details($blog);
  317.                                                 echo "<li><a href='?blog=" . $blog . "'>" . $blog_details->blogname . "</a></li>";
  318.                                             }
  319.                                         }
  320.                                     ?>
  321.                                 </ul>
  322.                             </li>
  323.                         </ul>
  324.                         <ul class="breadcrumb">
  325.                             <li><a href="/"><i class="icofont-home"></i> Dashboard</a> <span class="divider">›</span></li>
  326.                             <li class="active">აქ ვარ მე</li>
  327.                         </ul>
  328.                     </div>
  329.                     <div class="content-body" style="padding-top:20px">
  330.                         <div class="insert-post">
  331.                             <div class="row-fluid">
  332.                                 <div class="span8">
  333.                                     <div class="box corner-all">
  334.                                         <div class="box-header corner-top" style="text-align:center;">
  335.                                             <span>პროდუქტის დახასიათება</span>
  336.                                         </div>
  337.                                         <div class="box-body">
  338.                                             <?php if($postTitleError != '') { ?>
  339.                                                 <div class="alert alert-error">
  340.                                                     <?php echo $postTitleError; ?>
  341.                                                 </div>
  342.                                                 <div class="clearfix"></div>
  343.                                             <?php } ?>
  344.                                             <fieldset>
  345.                                                 <input type="text" name="postTitle" id="postTitle" placeholder="პროდუქტის დასახელება" value="<?php echo $cur_title; ?>" class="required span12" />
  346.                                             </fieldset>
  347.                                             <fieldset>
  348.                                                 <textarea name="postContent" class="span12" id="postContent" placeholder="პროდუქტის დახასიათება" rows="8" cols="30"><?php echo $cur_content; ?></textarea>
  349.                                             </fieldset>
  350.                                         </div>
  351.                                     </div>
  352.                                     <?php // CHECK IF WE HAVE SOME VARIATIONS
  353.                                     if (empty($queryVariations)) {
  354.                                         if ($post_is_parent == true) {
  355.                                     ?>
  356.                                     <fieldset>
  357.                                         <ul class="formVariations"><li>
  358.                                             <?php
  359.                                                 $parentArray = array();
  360.                                                 foreach ($parentVariations as $variation) {
  361.                                                     $parentArray[] = $variation->term_id;
  362.                                                 }
  363.                                                 foreach($variationCategories as $category) {
  364.                                                     if (in_array($category->term_id, $parentArray)) {
  365.                                                         if ($category->parent == 0) {
  366.                                                             echo "</li><li class='formVariationParent'><input type='checkbox' checked name='variationParent[]' autocomplete='off' value='". $category->term_id ."'>" . $category->name . "";
  367.                                                         } else {
  368.                                                             echo "<ul><li class='formVariationChild'><input type='checkbox' name='variationChild[]' checked autocomplete='off' value='". $category->term_id ."'>" . $category->name . "</li></ul>";
  369.                                                         }
  370.                                                     } else {
  371.                                                         if ($category->parent == 0) {
  372.                                                             echo "</li><li class='formVariationParent'><input type='checkbox' name='variationParent[]' autocomplete='off' value='". $category->term_id ."'>" . $category->name . "";
  373.                                                         } else {
  374.                                                             echo "<ul><li class='formVariationChild'><input type='checkbox' name='variationChild[]' autocomplete='off' value='". $category->term_id ."'>" . $category->name . "</li></ul>";
  375.                                                         }
  376.                                                     }
  377.                                                 }
  378.                                             ?>
  379.                                         </ul>
  380.                                     </fieldset>
  381.                                     <?php } } else { ?>
  382.                                     <div class="box-tab corner-all">
  383.                                         <div class="box-header corner-top">
  384.                                             <ul class="nav nav-tabs">
  385.                                                 <li class="pull-right"><a data-toggle="tab" href="#boxtab-2">დამატება</a></li>
  386.                                                 <li class="pull-right active"><a data-toggle="tab" href="#boxtab-1">მართვა</a></li>
  387.                                                 <li style="padding-top:8px;padding-left:8px;font-size:1.2em;font-weight:400;">ვარიაციები</li>
  388.                                             </ul>
  389.                                         </div>
  390.                                         <div class="box-body">
  391.                                             <div class="tab-content">
  392.                                                 <div class="tab-pane fade active in" id="boxtab-1">
  393.                                                     <table aria-describedby="datatables_info" id="datatables" class="table table-striped responsive dataTable table-condensed">
  394.                                                         <thead>
  395.                                                             <tr role="row">
  396.                                                                 <th aria-label="" class="span12" aria-sort="ascending" colspan="1" rowspan="1" aria-controls="datatables" tabindex="0" role="columnheader" class="sorting">სახელი</th>
  397.                                                                 <th aria-label="" colspan="1" rowspan="1" aria-controls="datatables" tabindex="0" role="columnheader" class="sorting">SKU</th>
  398.                                                                 <th aria-label="" colspan="1" rowspan="1" aria-controls="datatables" tabindex="0" role="columnheader" class="sorting">ფასი</th>
  399.                                                                 <th aria-label="" colspan="1" rowspan="1" aria-controls="datatables" tabindex="0" role="columnheader" class="sorting">ფასდაკლება</th>
  400.                                                                 <th aria-label="" colspan="1" rowspan="1" aria-controls="datatables" tabindex="0" role="columnheader" class="sorting">საწყობი</th>
  401.                                                                 <th aria-label="" colspan="1" rowspan="1" aria-controls="datatables" tabindex="0" role="columnheader" class="sorting">მართვა</th>
  402.                                                             </tr>
  403.                                                         </thead>
  404.                                                         <tbody aria-relevant="all" aria-live="polite" role="alert">
  405.                                                             <?php
  406.                                                                 // Go and grab currently editing product variations
  407.                                                                 switch_to_blog($get_admin_blog);
  408.                                                                 $size = array(32,32);
  409.                                                                 $sizeOfVariations = count($queryVariations);
  410.                                                                 foreach($queryVariations as $variation) {
  411.                                                             ?>
  412.                                                             <tr class="gradeA" id="trvar<?php echo $variation->ID?>">
  413.                                                                 <td class="span12">
  414.                                                                     <?php echo get_the_post_thumbnail($current_post, $size); ?>
  415.                                                                     <?php echo $variation->post_title; ?>
  416.                                                                 </td>
  417.                                                                 <td class=""><?php echo get_post_meta($variation->ID, '_wpsc_sku', $single); ?></td>
  418.                                                                 <td class=""><?php echo get_post_meta($variation->ID, '_wpsc_price', $single); ?></td>
  419.                                                                 <td class=""><?php echo get_post_meta($variation->ID, '_wpsc_special_price', $single); ?></td>
  420.                                                                 <td class=""><?php echo get_post_meta($variation->ID, '_wpsc_stock', $single); ?></td>
  421.                                                                 <td class="">
  422.                                                                     <div class="btn-group">
  423.                                                                         <?php $editVariation = add_query_arg('post', $variation->ID, get_permalink(239)); ?>
  424.                                                                         <a class="btn btn-new btn-success" target="_blank" href="<?php echo $editVariation; ?>">
  425.                                                                             <i class="icofont-edit"></i>
  426.                                                                         </a>
  427.                                                                         <a class="btn btn-new btn-danger" onclick="apfDeleteVariation(<?php echo $variation->ID ?>,<?php echo $current_post ?>,<?php echo $sizeOfVariations ?>,<?php echo $get_admin_blog ?>)">
  428.                                                                             <i class="icofont-trash"></i>
  429.                                                                         </a>
  430.                                                                     </div>
  431.                                                                 </td>
  432.                                                             </tr>
  433.                                                             <?php } ?>
  434.                                                             <?php restore_current_blog(); ?>
  435.                                                         </tbody>
  436.                                                     </table>
  437.                                                 </div>
  438.                                                 <div class="tab-pane fade" id="boxtab-2">
  439.                                                     <fieldset>
  440.                                                         <ul class="formVariations" id="formVariationsID"><li>
  441.                                                             <?php
  442.                                                                 $parentArray = array();
  443.                                                                 foreach ($parentVariations as $variation) {
  444.                                                                     $parentArray[] = $variation->term_id;
  445.                                                                 }
  446.                                                                 foreach($variationCategories as $category) {
  447.                                                                     if (in_array($category->term_id, $parentArray)) {
  448.                                                                         if ($category->parent == 0) {
  449.                                                                             echo "</li><li class='formVariationParent'><input type='checkbox' checked name='variationParent[]' autocomplete='off' value='". $category->term_id ."'>" . $category->name . "";
  450.                                                                         } else {
  451.                                                                             echo "<ul><li class='formVariationChild'><input type='checkbox' name='variationChild[]' checked autocomplete='off' value='". $category->term_id ."'>" . $category->name . "</li></ul>";
  452.                                                                         }
  453.                                                                     } else {
  454.                                                                         if ($category->parent == 0) {
  455.                                                                             echo "</li><li class='formVariationParent'><input type='checkbox' name='variationParent[]' autocomplete='off' value='". $category->term_id ."'>" . $category->name . "";
  456.                                                                         } else {
  457.                                                                             echo "<ul><li class='formVariationChild'><input type='checkbox' name='variationChild[]' autocomplete='off' value='". $category->term_id ."'>" . $category->name . "</li></ul>";
  458.                                                                         }
  459.                                                                     }
  460.                                                                 }
  461.                                                             ?>
  462.                                                         </ul>
  463.                                                     </fieldset>
  464.                                                 </div>
  465.                                             </div>
  466.                                         </div>
  467.                                     </div>
  468.                                     <?php } ?>
  469.                                 </div>
  470.                                 <div class="span4">
  471.                                     <div class="box corner-all">
  472.                                         <div class="box-header bg-black color-white corner-top" style="text-align:center;">
  473.                                             <div class="header-control">
  474.                                                 <a data-box="collapse"><i class="icofont-caret-up"></i></a>
  475.                                             </div>
  476.                                             <span>დამატებითი ინფორმაცია</span>
  477.                                         </div>
  478.                                         <div class="box-body corner-bottom">
  479.                                             <?php if($postPriceError != '') { ?>
  480.                                                 <div class="alert alert-error">
  481.                                                     <?php echo $postPriceError; ?>
  482.                                                 </div>
  483.                                                 <div class="clearfix"></div>
  484.                                             <?php } ?>
  485.                                             <?php if ($post_is_parent == true) {
  486.                                             ?>
  487.                                             <fieldset>
  488.                                                 <p><?php echo $dropdowncats; ?></p>
  489.                                             </fieldset>
  490.                                             <?php } ?>
  491.                                             <div class="form-inline">
  492.                                                 <fieldset>
  493.                                                     <input type="text" name="postPrice" id="postPrice" placeholder="ფასი" value="<?php echo $cur_price; ?>" class="required span6" />
  494.                                                     <input type="text" name="postSpecialPrice" id="postSpecialPrice" placeholder="ფასდაკლება" value="<?php echo $cur_special_price; ?>" class="required span6" />
  495.                                                 </fieldset>
  496.                                             </div><p>
  497.                                             <div class="form-inline">
  498.                                                 <fieldset>
  499.                                                     <input type="text" name="postSKU" id="postSKU" placeholder="SKU" value="<?php echo $cur_sku; ?>" class="required span6" />
  500.                                                     <input type="text" name="postStock" id="postStock" placeholder="საწყობი" value="<?php echo $cur_stock; ?>" class="required span6" />
  501.                                                 </fieldset>
  502.                                             </div><p>
  503.                                             <div class="">
  504.                                                 <fieldset id="fieldThumb">
  505.                                                     <?php echo $parentThumb; ?>
  506.                                                 </fieldset><br />
  507.                                                 <span class="pull-right"><a href="#mediaManager" class="btn btn-primary" role="button" data-toggle="modal">მედიის მართვა</a></span>
  508.                                                 <br><br>
  509.                                                
  510.                                             </div>
  511.                                         </div>
  512.                                     </div>
  513.                                 </div>
  514.                             </div>
  515.                             <div class="form-actions">
  516.                                 <fieldset>
  517.                                     <?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>
  518.                                     <input type="hidden" name="submitted" id="submitted" value="true" />
  519.                                     <button type="submit" class="btn btn-primary"><?php _e('Edit Post', 'framework') ?></button>
  520.                                     <button type="button" class="btn">Cancel</button>
  521.                                 </fieldset>
  522.                             </div>
  523.                         </div>
  524.                     </div>
  525.                 </div>
  526.             </div>
  527.         </div>
  528.     </section>
  529.  
  530.     <div id="mediaManager" class="modal bigModal hide fade" tabindex="-1" role="dialog" aria-labelledby="mediaManagerLabel" aria-hidden="true">
  531.         <div class="modal-header">
  532.             <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  533.             <h3 id="mediaManagerLabel">მედიის მართვა</h3>
  534.         </div>
  535.         <div class="modal-body">
  536.             <div class="box-tab corner-all">
  537.                 <div class="box-header corner-top">
  538.                     <ul class="nav nav-tabs">
  539.                         <!--tab menus-->
  540.                         <li class="active"><a data-toggle="tab" href="#prodimages">პროდუქტის სურათები</a></li>
  541.                         <li class=""><a data-toggle="tab" href="#mediaimages">მედია სურათები</a></li>
  542.                         <li class=""><a data-toggle="tab" href="#mediaUpload">მედიის ატვირთვა</a></li>
  543.                     </ul>
  544.                 </div>
  545.                 <div class="box-body">
  546.                     <!-- widgets-tab-body -->
  547.                     <div class="tab-content">
  548.                         <div class="tab-pane fade" id="mediaUpload">
  549.                             <div class="row-fluid">
  550.                                 <div class="span9">
  551.                                     <fieldset class="images">
  552.                                         <label class="pull-left" for="image1">სურათის დამატება</label>
  553.                                         <button type="button" class="btn btn-mini btn-primary pull-left" style="margin-left:15px;" id="plusimage">&nbsp;+&nbsp;</button>
  554.                                         <button type="button" class="btn btn-mini btn-primary pull-left" style="margin-left:5px;" id="minusimage">&nbsp;-&nbsp;</button>
  555.                                         <input type="checkbox" class="pull-left" name="updateThumb" style="margin-left:5px;" id="updateThumb"><span class="pull-left"><i class="icofont-star"></i>განახლება&nbsp;</span></input>
  556.                                        
  557.                                         <div class="clearfix"></div>
  558.                                         <input type="file" name="image1" id="image1" size="35">
  559.                                     </fieldset>
  560.                                 </div>
  561.                                 <div class="span3">
  562.                                     <div class="mediaManagerImage"></div>
  563.                                 </div>
  564.                             </div>
  565.                         </div>
  566.                         <div class="tab-pane fade active in" id="prodimages">
  567.                             <table class="table table-hover responsive table-condensed">
  568.                                 <thead>
  569.                                     <tr>
  570.                                         <th>#რიგი</th>
  571.                                         <th>სურათი</th>
  572.                                         <th style="text-align:center;">ზომა</th>
  573.                                         <th style="text-align:center">მოქმედება</th>
  574.                                     </tr>
  575.                                 </thead>
  576.                                 <tbody>
  577.                                     <div id="apf-text">
  578.                                     <div id="apf-response2" style="background-color:#E6E6FA ;color:blue;"></div>       
  579.                                     <?php
  580.                                         if($MediaAttachments) {
  581.                                             $k = 1;
  582.                                             switch_to_blog($get_admin_blog);
  583.                                             $size = array(32,32);
  584.                                             $post_thumbnail_id = get_post_thumbnail_id($current_post);
  585.                                             foreach ($MediaAttachments as $post) {
  586.                                                 setup_postdata($post);
  587.                                                 $image_metadata = wp_get_attachment_metadata( $post->ID );    
  588.                                     ?>
  589.                                     <tr id="attach<?php echo $post->ID ?>">
  590.                                         <td><input style="width:25px;" value="<?php echo $k ?>"></input></td>
  591.                                         <td class="attachImage span12"><?php echo wp_get_attachment_image( $post->ID, 'medium' ); echo "&nbsp;&nbsp;&nbsp;" . $post->post_title; ?></td>
  592.                                         <td><?php echo $image_metadata['width'] . "x" . $image_metadata['height'] . "px" ?></td>
  593.                                         <td style="text-align:right">
  594.                                             <div class="btn-group">
  595.                                                 <?php if($post_thumbnail_id) { ?>
  596.                                                     <a class="btn btn-new btn-primary" onclick="apfSetAsThumb(<?php echo $post->ID?>,<?php echo $current_post ?>,<?php echo $get_admin_blog ?>,<?php echo $post_thumbnail_id ?>);" style="cursor: pointer"><b><i class="icofont-star"></i></b></a></i>
  597.                                                 <?php } else { ?>
  598.                                                     <a class="btn btn-new btn-primary" onclick="apfSetAsThumb(<?php echo $post->ID?>,<?php echo $current_post ?>,<?php echo $get_admin_blog ?>);" style="cursor: pointer"><b><i class="icofont-star"></i></b></a></i>
  599.                                                 <?php } ?>
  600.                                                 <button class="btn btn-new btn-success"><i class="icofont-edit"></i></button>
  601.                                                 <a class="btn btn-new btn-danger" onclick="apfUncheckThumb(<?php echo $post->ID?>,<?php echo $current_post ?>,<?php echo $get_admin_blog ?>);" style="cursor: pointer"><b><i class="icofont-trash"></b></a></i>
  602.                                             </div>
  603.                                         </td>
  604.                                     </tr>
  605.                                     <?php   $k++;   }
  606.                                             }
  607.                                             restore_current_blog();
  608.                                     ?>
  609.                                     </div>
  610.                                 </tbody>
  611.                             </table>
  612.                         </div>
  613.                         <div class="tab-pane fade" id="mediaimages">
  614.                             <table class="table table-hover responsive table-condensed">
  615.                                 <thead>
  616.                                 <tr>
  617.                                     <th>#რიგი</th>
  618.                                     <th>სურათი</th>
  619.                                     <th>ზომა</th>
  620.                                     <th style="text-align:center">მოქმედება</th>
  621.                                 </tr>
  622.                                 </thead>
  623.                                 <tbody>
  624.                                 <?php
  625.                                     if($MediaAttachmentsALL) {
  626.                                         $k = 1;
  627.                                         switch_to_blog($get_admin_blog);
  628.                                         $size = array(32,32);
  629.                                         $post_thumbnail_id = get_post_thumbnail_id($current_post);
  630.                                         foreach ($MediaAttachmentsALL as $post) {
  631.                                             setup_postdata($post);
  632.                                             $image_metadata = wp_get_attachment_metadata( $post->ID );    
  633.                                 ?>
  634.                                 <tr id="attach<?php echo $post->ID ?>">
  635.                                     <td><?php echo $k ?></td>
  636.                                     <td class="attachImage span12"><?php echo wp_get_attachment_image( $post->ID, 'medium' ); echo "&nbsp;&nbsp;&nbsp;" . $post->post_title; ?></td>
  637.                                     <td><?php echo $image_metadata['width'] . "x" . $image_metadata['height'] . "px" ?></td>
  638.                                     <td style="text-align:right">
  639.                                         <div class="btn-group">
  640.                                             <?php if($post_thumbnail_id) { ?>
  641.                                                 <a class="btn btn-new btn-primary" onclick="apfSetAsThumb(<?php echo $post->ID?>,<?php echo $current_post ?>,<?php echo $get_admin_blog ?>,<?php echo $post_thumbnail_id ?>);" style="cursor: pointer"><b><i class="icofont-star"></i></b></a></i>
  642.                                             <?php } else { ?>
  643.                                                 <a class="btn btn-new btn-primary" onclick="apfSetAsThumb(<?php echo $post->ID?>,<?php echo $current_post ?>,<?php echo $get_admin_blog ?>, false);" style="cursor: pointer"><b><i class="icofont-star"></i></b></a></i>
  644.                                             <?php } ?>
  645.                                             <button class="btn btn-new btn-success"><i class="icofont-plus"></i></button>
  646.                                         </div>
  647.                                     </td>
  648.                                 </tr>
  649.                                 <?php       $k++;
  650.                                         }
  651.                                     }
  652.                                     restore_current_blog();
  653.                                 ?>
  654.                                 </tbody>
  655.                             </table>
  656.                         </div>
  657.                     </div><!--/widgets-tab-body-->
  658.                 </div>
  659.             </div>
  660.         </div>
  661.         <div class="modal-footer">
  662.             <button type="button" class="btn btn-danger" data-dismiss="modal" aria-hidden="true">დახურვა</button>
  663.         </div>
  664.     </div>
  665. </form>
  666. <?php dynamic_sidebar( 'sidebar-blog' ) ?>
  667. <?php get_footer(); ?>
  668. <script>
  669. //  insertPost variation collapse/expand
  670. jQuery('.formVariations > li:first-child').hide();
  671. jQuery('.formVariationParent > input').change(function() {
  672.     if(this.checked) {
  673.         jQuery(this).parent('li').find('ul input').prop('checked', true);
  674.     } else {
  675.         jQuery(this).parent('li').find('ul input').prop('checked', false);
  676.     }
  677. });
  678. jQuery('.formVariationChild > input').change(function() {
  679.     if(this.checked) {
  680.         if (jQuery(this).parent('li').parent('ul').parent('li').find('> input').is(":not(:checked)")) {
  681.             jQuery(this).parent('li').parent('ul').parent('li').find('> input').prop('checked', true);
  682.         }
  683.     }
  684. });
  685. //  insertPost appendImage eventhandler
  686. var imageid = 1;
  687. jQuery('#plusimage').on('click', function() {
  688.     imageid++;
  689.     if (imageid === 7) {
  690.         alert('სამწუხაროდ, ერთ ატვირთვაზე მაქსიმუმ 6 სურათის ატვირთვა შეიძლება, გთხოვთ გამოიყენოთ მედია კატეგორია სურათების დასამატებლად და მერე მედია მენეჯერი რათა პროდუქტს მიაბათ სურათი.');
  691.     } else {
  692.         jQuery(this).parent('fieldset').parent('div').append('<fieldset id="imagefield' + imageid + '" class="images"><input type="file" name="image' + imageid + '" id="image' + imageid + '" size="35">');   
  693.     }
  694. });
  695. jQuery('#minusimage').on('click', function() {
  696.     if (imageid === 1) {
  697.         alert('ერთი ფორმა მაინც უნდა იყოს');
  698.     } else {
  699.         jQuery(this).parent('fieldset').parent('div').find('#imagefield' + imageid).remove();
  700.         imageid--;
  701.     }
  702. });
  703. //make category dropdown fullwidth
  704. jQuery('#cat').addClass('span12');
  705. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement