ruạṛ
<?php /** * Edit product * @version 0.9 * @author Robert Urquhart <programmer@activatedesign.co.nz> * @package WEP-CMS */ session_start(); require_once 'scripts-includes/universal.php'; require_once 'scripts-includes/display.php'; /** * @var array $categories * @var bool $new (superseded by if($p->prod_id) ??) * @var string $dir product files directory * @var int $prod_id * @var object $p * @var string $h1 page heading * @var string $action form action target * @var string $button submit text */ $categories = build_category_tree(); // recursive function $new = false; $dir = ''; if(!$prod_id = is_numeric_id($_GET['prod'], false)) { $p = new product(); if(isset($_SESSION['passback'])) { $p->load_from_data($_SESSION['passback']); } $button = $h1 = 'Add product'; $action = 'process-product-new.php'; $new = true; } else { $p = new product($prod_id); //if(!$product = mysql_query("select * from products where prod_id = '$prod_id'")) if(!$p->prod_id) { getout('Product not found','categories.php'); exit; } $action = 'process-product-edit.php'; $button = 'Update product'; $h1 = 'Edit '.$p->name; $dir = '/resources/images/product/'.$prod_id.'/'; } /* * display page * this code will vary between implementations with site-specific product information */ head('products','Edit a product'); // var_dump($p); //debugging ?> <h1><?php echo $h1; ?></h1> <div class="tabs"> <ul> <li><a href="#tab1">Content</a></li> <?php if($p->prod_id): ?> <li><a href="#tab2">Images</a></li> <li><a href="#tab3">Categories</a></li> <?php if(MODULE_PRODUCTS_ASSOCIATED): ?> <li><a href="#tab4">Associated</a></li> <?php endif; ?> <?php endif; ?> </ul> <div class="mock_table" id="tab1"> <form method="post" action="processes/<?php echo $action; ?>" name="prod_edit" id="prod_edit" enctype="multipart/form-data"> <input name="prod_id" id="prod_id1" type="hidden" value="<?php echo $prod_id; ?>" /> <?php /* * if new product */ if(!$p->prod_id) { /* * initial category */ ?> <label for="category"> <span class="right">Initial Category:</span> <span class="left"> <select name="category" id="category"> <?php echo build_category_select($categories,1,0,3,true); ?> </select> </span> </label> <hr /> <?php } // end if new product ?> <label for="product_name"><span class="right">Product name:</span><span class="left"><input name="product_name" id="product_name" type="text" size="60" maxlength="60" value="<?php echo $p->name; ?>" /></span></label> <label for="price"><span class="right">Price:</span><span class="left">$<input name="price" id="price" type="text" size="10" maxlength="7" value="<?php echo ($p->price>0) ? number_format($p->price,2,'.',''): ''; ?>" /></span></label> <label for="featured"><span class="right">Featured product:</span><span class="left"><input name="featured" id="featured" type="checkbox" value="1" <?php if($p->featured){ echo "checked"; } ?> /></span></label> <label for="description"><span class="right">Short description:</span><span class="left"><textarea name="description" id="description" cols="38" rows="4"><?php echo "$p->short"; ?></textarea></span></label> <?php //* ?> <label for="content"><span class="right">Long description:</span></label> <br class="clear" /> <div style=" margin: 0px auto; text-align: center;"> <?php //* WYSIWYG ?> <textarea name="content" class="editor product_description" style="height:600px"><?php echo html_entity_decode($p->description,ENT_QUOTES); ?></textarea> </div> <?php // */ ?> <?php /* ?> <label for="sidebar"><span class="right">Sidebar product:</span><span class="left"><input name="sidebar" id="sidebar" type="checkbox" value="1" <?php if($p->sidebar){ echo "checked"; } ?> /></span></label> <?php // */ ?> <?php /* * data attributes */ if($p->product_data_fields->count_options()) { ?> <h2>Product data</h2> <p class="info">Structured information fields displayed alongside the product description.</p> <?php foreach($p->product_data_fields->options as $o) { $label = $o->text; $a = 'data_'.$o->option_id; ?> <label for="<?php echo $a; ?>"><span class="right"><?php echo $label; ?>:</span><span class="left"><input name="<?php echo $a; ?>" id="<?php echo $a; ?>" type="text" size="60" maxlength="100" value="<?php echo $p->data[$o->option_id]; ?>" /></span></label> <?php } } /* * data attributes */ if($p->product_options_fields->count_options()) { ?> <h2>Product Options</h2> <p class="info">Option values that the customer can select from when adding an item to their cart. One option per line.<p> <?php foreach($p->product_options_fields->options as $o) { $label = $o->text; $a = 'options_'.$o->option_id; ?> <p><span class="right"><label for="<?php echo $a; ?>"><?php echo $label; ?>:</label></span><span class="left"><textarea name="<?php echo $a; ?>" id="<?php echo $a; ?>" rows="4"><?php echo $p->options[$o->option_id]; ?></textarea></span></p> <?php } } /* deprecated foreach($p->prodAttr as $a) { $label = ucfirst(str_replace('_',' ',$a)); ?> <label for="<?php echo $a; ?>"><span class="right"><?php echo $label; ?>:</span><span class="left"><input name="<?php echo $a; ?>" id="<?php echo $a; ?>" type="text" size="60" maxlength="100" value="<?php echo $p->$a; ?>" /></span></label> <?php } */ ?> <p> </p> <p class="center"> <input name="submit" id="submit" type="submit" value="<?php echo $button; ?>" /> </p> </form> </div><!-- end #tab1.mock_table --> <?php /* * if existing product */ if($p->prod_id) { /* * images */ $maxPos = select_one('image_data','max(image_position)',"concat_ws(':',image_type,container_id)",'product-gallery:'.$p->prod_id); $refresh = '?refresh='.time(); ?> <div class="mock_table<?php if($_GET['tab']=='images'){ echo ' active'; } ?>" id="tab2"> <h2>Images</h2> <form method="post" action="processes/process-product-images.php" name="prod_images" id="prod_images" enctype="multipart/form-data"> <input name="prod_id" id="prod_id2" type="hidden" value="<?php echo $prod_id; ?>" /> <label for="new_image"><span class="right">Add Image:</span><span class="left"><input name="new_image" id="new_image" type="file" size="30" /></span></label> <label for="new_image_caption"><span class="right">With caption (optional):</span><span class="left"><input name="new_image_caption" id="new_image_caption" type="text" size="30" value="" /></span></label> <label for="new_image_position"><span class="right">At position:</span><span class="left"><input name="new_image_position" id="new_image_position" type="text" size="3" maxlength="3" placeholder="<?php echo $maxPos+10; ?>" /></span></label> <p> </p> <p class="center"> <input name="submit" id="submit" type="submit" value="Update images" /> </p> <?php foreach($p->images as $i) { $id = $i['image_id']; $maxPos = $i['image_position']; ?> <hr /> <label for="image_caption<?php echo $id; ?>"><span class="right">Caption:</span><span class="left"><input name="image_caption[caption<?php echo $id; ?>]" id="image_caption<?php echo $id; ?>" type="text" size="30" value="<?php echo $i['title']; ?>" /></span></label> <label for="image_position<?php echo $sid; ?>"><span class="right">Image position:</span><span class="left"><input name="image_position[<?php echo $id; ?>]" id="image_position<?php echo $id; ?>" type="text" size="3" maxlength="3" value="<?php echo $maxPos; ?>" /> <?php echo ($maxPos==10) ? '[used for listing thumbnail]' : ''; ?></span></label> <label for="image<?php echo $id; ?>"><span class="right">Replace Image:</span><span class="left"><input name="image[image<?php echo $id; ?>]" id="image<?php echo $sid; ?>" type="file" size="30" /></span></label> <p class="center"> <img align="middle" src="<?php echo $i['image'].$refresh; ?>" /><br /> <input name="imgdel" type="button" value="Remove image" onclick="if(confirm('Remove image?')){window.location='processes/process-image-remove.php?product=<?php echo $prod_id; ?>&image=<?php echo $id; ?>';return true;}else{return false;}" /> </p> <br class="clear" /> <?php } // end foreach if(count($p->images)) { ?> <hr /> <p> </p> <p class="center"> <input name="submit" id="submit" type="submit" value="Update images" /> </p> <?php } ?> </form> </div> <!-- end #tab2.mock_table --> <p> </p> <?php /* * categories (if existing product) */ ?> <div class="mock_table<?php if($_GET['tab']=='categories'){ echo ' active'; } ?>" id="tab3"> <h2>Categories</h2> <form class="categories" action="processes/process-product-categories.php" method="post" enctype="multipart/form-data"> <input name="prod_id" id="prod_id3" type="hidden" value="<?php echo $prod_id; ?>" /> <div class="checkboxes"> <?php echo build_category_checkboxes($categories,array_keys($p->categories)); ?> </div> <script type="text/javascript"> $labels = $('.categories .checkboxes label'); $(document).ready(function(){ $('.categories .checkboxes input').click(function(){ $label = $(this).parent('label'); t = $label.attr('class'); n = parseInt(t.replace('tier-','')); if(this.checked && $label.attr('class') != 'tier-1') { //work "upwards" checking boxes stop = false; // can't just prevUntil('tier-1') because that doesn't get the tier-1 $siblings = $label.prevUntil('tier-1').add($label.prevAll('tier-1').first()); $siblings.children('input').each(function(){ u = $(this).parent('label').attr('class'); m = parseInt(u.replace('tier-','')); //console.log(n,m); if(!stop && m < n) { this.checked = true; if( m == 1) { //stop stop = true; } } }); } else { //work "downwards" unchecking boxes // always stop if we reach the next tier-1 $label.nextUntil('.tier-1').children('input').each(function(){ u = $(this).parent('label').attr('class'); m = parseInt(u.replace('tier-','')); if(m > n) { this.checked = false; } else if( m == n ) //next branch { return; } }); } }); }); </script> <p class="center"> <input name="submit" id="submit" type="submit" value="Update categories" /> </p> </form> </div><!-- end #tab3.mock_table --> <?php /* * associated products */ if(MODULE_PRODUCTS_ASSOCIATED) { ?> <div class="mock_table<?php if($_GET['tab']=='associated'){ echo ' active'; } ?>" id="tab4"> <h2>Associated Products</h2> <form class="add center" action="processes/process-product-associated-add.php" method="post" enctype="multipart/form-data"> <input name="prod_id" id="prod_id4" type="hidden" value="<?php echo $prod_id; ?>" /> <input name="assoc_id" id="assoc_id" type="hidden" value="<?php echo $assoc_id; ?>" /> <label for="select_product_name">Find Product:</label> <input type="text" name="select_product_name" id="select_product_name" class="select_on_focus" value=""> <input type="submit" value="Add product" /> </form> <?php $p->load_associated(); if(empty($p->associated)) { ?> <p class="center">No associated products were found</p> <?php } else { ?> <table class="control_panel" style="width:50%"> <thead> <tr> <th class="left">Product</th> <th class="control center">Remove</th> <tr> </th> <tfoot></tfoot> <tbody> <?php foreach($p->associated as $a) { ?> <tr> <td class="left"><?php echo ($a->active) ? '<a href="'.$a->path.'" target="preview">'.$a->name.'</a>' : $a->name; ?></td> <td class="control center"><a href="processes/process-product-associated-remove.php?prod=<?php echo $prod_id; ?>&assoc=<?php echo $a->prod_id; ?>" onClick="if(confirm('Remove <?php echo addslashes($a->name); ?>?')){return true}else{return false}" class="delete"><img src="images/img-del.png" alt="Remove" /></a></td> </tr> <? } ?> </tbody> </table> </div><!-- end #tab4.mock_table --> <?php } //end if $p->associated }//endif MODULE_PRODUCTS_ASSOCIATED } // end if existing product ?> </div><!-- end .tabs --> <?php footer(); exit; ?>
cải xoăn