This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
add-new-auction.php
411 lines (369 loc) · 17.9 KB
/
add-new-auction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<?php
wp_enqueue_media();
$post_id;
if(!empty($_POST)){
if(isset($_POST['ua_wdm_add_auc']) && wp_verify_nonce($_POST['ua_wdm_add_auc'],'ua_wp_n_f')){
$auction_title=(!empty($_POST["auction_title"])) ? ($_POST["auction_title"]):'';
$auction_content=(!empty($_POST["auction_description"])) ? ($_POST["auction_description"]):'';
$auction_excerpt=(!empty($_POST["auction_excerpt"])) ? ($_POST["auction_excerpt"]):'';
$auc_end_tm = isset($_POST["end_date"]) ? strtotime($_POST["end_date"]) : 0;
$blog_curr_tm = strtotime(date("Y-m-d H:i:s", time()));
if(($auc_end_tm > $blog_curr_tm) && $auction_title!="" && $auction_content!=""){
global $post_id;
$is_update=false;
$reactivate=false;
//update auction mode
if(isset($_POST["update_auction"]) && !empty($_POST["update_auction"]) /*&& !isset($_GET["reactivate"])*/){
$post_id=$_POST["update_auction"];
$args=array(
'ID' => $post_id,
'post_title' => $auction_title,
'post_content' => $auction_content,
'post_excerpt' => $auction_excerpt
);
wp_update_post( $args );
$is_update = true;
}
//reactivate auction mode
elseif(/*isset($_POST["update_auction"]) && !empty($_POST["update_auction"]) && */isset($_GET["reactivate"]))
{
$args = array(
'post_title' => wp_strip_all_tags( $auction_title ),//except for title all other fields are sanitized by wordpress
'post_content' => $auction_content,
'post_type' => 'ultimate-auction',
'post_status' => 'publish',
'post_excerpt' => $auction_excerpt
);
$post_id = wp_insert_post($args);
$this->wdm_set_auction($post_id);
$this->auction_id=$post_id;
$reactivate = true;
}
//create/add auction mode
else{
$args = array(
'post_title' => wp_strip_all_tags( $auction_title ),//except for title all other fields are sanitized by wordpress
'post_content' => $auction_content,
'post_type' => 'ultimate-auction',
'post_status' => 'publish',
'post_excerpt' => $auction_excerpt
);
$post_id = wp_insert_post($args);
$this->wdm_set_auction($post_id);
$this->auction_id=$post_id;
}
if($post_id){
$get_default_timezone = get_option('wdm_time_zone');
if(!empty($get_default_timezone))
{
date_default_timezone_set($get_default_timezone);
}
echo '<div id="message" class="updated fade">';
echo "<p><strong>";
if($is_update)
_e("Auction updated successfully.", "wdm-ultimate-auction");
elseif($reactivate)
{
printf(__("Auction reactivated successfully. Auction id is %d", "wdm-ultimate-auction"), $post_id);
update_post_meta($post_id, 'wdm-auth-key',md5(time().rand()));
add_post_meta($post_id, 'wdm_creation_time', date("Y-m-d H:i:s", time()));
}
else
{
printf(__("Auction created successfully. Auction id is %d", "wdm-ultimate-auction"), $post_id);
update_post_meta($post_id, 'wdm-auth-key',md5(time().rand()));
add_post_meta($post_id, 'wdm_creation_time', date("Y-m-d H:i:s", time()));
}
echo "</strong></p></div>";
$temp = term_exists('live', 'auction-status');
wp_set_post_terms($post_id, $temp["term_id"], 'auction-status');
//update options
for($u=1; $u<=4; $u++)
{
update_post_meta($post_id, "wdm-image-".$u,$_POST["auction_image_".$u]);
}
update_post_meta($post_id, 'wdm-main-image',$_POST["auction_main_image"]);
update_post_meta($post_id, 'wdm_listing_ends', $_POST["end_date"]);
update_post_meta($post_id, 'wdm_opening_bid', round($_POST["opening_bid"], 2));
update_post_meta($post_id, 'wdm_lowest_bid', round($_POST["lowest_bid"], 2));
update_post_meta($post_id, 'wdm_buy_it_now', round($_POST["buy_it_now_price"], 2));
update_post_meta($post_id, 'wdm_incremental_val', round($_POST["incremental_value"], 2));
update_post_meta($post_id, 'wdm_payment_method', $_POST["payment_method"]);
//if another bidding engine is active
$bidding_engine = ( isset($_POST["bidding_engine"]) ? $_POST["bidding_engine"] : "" );
update_post_meta($post_id, 'wdm_bidding_engine', $bidding_engine);
for($im=1; $im<=4; $im++)
{
if(get_post_meta($post_id,'wdm-main-image',true) == 'main_image_'.$im)
{
$main_image = get_post_meta($post_id,'wdm-image-'.$im,true);
update_post_meta($post_id, 'wdm_auction_thumb', $main_image);
}
}
}
}
elseif($auc_end_tm <= $blog_curr_tm)
{
?> <div id="message" class="error">
<p><strong><?php _e("Please enter a future date/time.", "wdm-ultimate-auction");?></strong></p>
</div>
<?php
}
else{
?>
<div id="message" class="error"><p><strong><?php _e("Auction title and Auction description cannot be left blank.", "wdm-ultimate-auction");?></strong></p></div>
<?php
}
}
else{
die(__('Sorry, your nonce did not verify.', 'wdm-ultimate-auction'));
}
}
$wdm_post=$this->wdm_get_post();
//Currency Code
$currency_code = substr(get_option('wdm_currency'), -3);
?>
<!--form to add/update an auction-->
<form id="wdm-add-auction-form" class="auction_settings_section_style" action="" method="POST">
<?php
if($wdm_post["title"]!="")
echo "<h3>".__("Update Auction", "wdm-ultimate-auction")."</h3>";
else
echo "<h3>".__("Add New Auction", "wdm-ultimate-auction")."</h3>";
?>
<table class="form-table">
<?php
$after_thumb = "";
$bidding_engine = array();
$bidding_engine = apply_filters('ua_add_bidding_engine', $bidding_engine);
if(!empty($bidding_engine)){
$after_thumb = '<tr valign="top">
<th scope="row">
<label for="bidding_engine">'.__("Bidding Engine", "wdm-ultimate-auction").'</label>
</th>
<td>
<select id="bidding_engine" name="bidding_engine">
<option value="">'.__("Simple Bidding", "wdm-ultimate-auction").'</option>';
foreach($bidding_engine as $be){
$opt = get_option("wdm_bidding_engines");
$opt_new = $this->wdm_post_meta("wdm_bidding_engine");
if((isset($_GET['edit_auction']) && !empty($_GET['edit_auction'])) || isset($post_id))
$opt = $opt_new;
$select = $opt == $be["val"] ? "selected" : "";
$after_thumb .= '<option value="'.$be["val"].'" '.$select.'>'.$be["text"].'</option>';
}
$after_thumb .= '</select>
</td>
</tr>';
}
echo $after_thumb;
?>
<tr valign="top">
<th scope="row">
<label for="auction_title"><?php _e("Product Title", "wdm-ultimate-auction");?></label>
</th>
<td>
<input name="auction_title" type="text" id="auction_title" class="regular-text" value="<?php echo $wdm_post["title"];?>"/>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="auction_description"><?php _e("Product Description", "wdm-ultimate-auction");?></label>
</th>
<td>
<!--<textarea name="auction_description" type="text" id="auction_description" cols="50" rows="10" class="large-text code"><?php echo $wdm_post["content"];?></textarea>-->
<?php
$args = array(
'media_buttons' => false,
'textarea_name' => 'auction_description',
'textarea_rows' => 10
);
wp_editor($wdm_post["content"], 'auction_description', $args);?>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="auction_excerpt"><?php _e("Product Short Description", "wdm-ultimate-auction");?></label>
</th>
<td>
<textarea name="auction_excerpt" id="auction_excerpt" class="regular-text ua_thin_textarea_field"><?php echo $wdm_post["excerpt"];?></textarea>
<div class="ult-auc-settings-tip"><?php _e("Enter short description (excerpt) for the product. This description is shown on the auctions listing page.", "wdm-ultimate-auction");?></div>
</td>
</tr>
<?php
$after_desc = '';
$after_desc = apply_filters('wdm_ua_after_product_desc', $after_desc);
echo $after_desc;
for($p=1; $p<=4; $p++)
{
$single_img = $this->wdm_post_meta("wdm-image-".$p);
echo '<tr valign="top">
<th scope="row">
<label for="auction_image_'.$p.'">'.__("Product Image/Video", "wdm-ultimate-auction").' '.$p.'</label>
</th>
<td>
<input name="auction_image_'.$p.'" type="text" id="auction_image_'.$p.'" class="regular-text wdm_image_'.$p.'_url url" value="'.$single_img.'"/>
<input name="wdm_upload_image_'.$p.'_button" id="wdm_image_'.$p.'_url" class="button wdm_auction_image_upload" type="button" value="'.__('Select File', 'wdm-ultimate-auction').'"/>
</td>
</tr>';
}
?>
<tr valign="top">
<th scope="row">
<label for="auction_main_image"><?php _e("Thumbnail Image", "wdm-ultimate-auction");?></label>
</th>
<td>
<select id="auction_main_image" name="auction_main_image">
<?php for($m=1; $m<=4; $m++)
{
?>
<option value="main_image_<?php echo $m;?>" <?php echo $this->wdm_post_meta("wdm-main-image") == "main_image_".$m ? "selected" : "";?>><?php _e("Product Image/Video", "wdm-ultimate-auction"); echo " ".$m;?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="opening_bid"><?php _e("Opening Price", "wdm-ultimate-auction");?></label>
</th>
<td>
<?php echo $currency_code;?>
<input name="opening_bid" type="text" id="opening_bid" class="small-text number" value="<?php echo $this->wdm_post_meta('wdm_opening_bid');?>"/>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="lowest_bid"><?php _e("Lowest Price to Accept", "wdm-ultimate-auction");?></label>
</th>
<td>
<?php echo $currency_code;?>
<input name="lowest_bid" type="text" id="lowest_bid" class="small-text number" value="<?php echo $this->wdm_post_meta('wdm_lowest_bid');?>"/>
<div>
<span class="ult-auc-settings-tip"><?php _e("Set Reserve price for your auction.", "wdm-ultimate-auction");?></span>
<a href="" class="auction_fields_tooltip"><strong>?</strong>
<span><?php _e("A reserve price is the lowest price at which you are willing to sell your item. If you don't want to sell your item below a certain price, you can a set a reserve price. The amount of your reserve price is not disclosed to your bidders, but they will see that your auction has a reserve price and whether or not the reserve has been met. If a bidder does not meet that price, you're not obligated to sell your item.", "wdm-ultimate-auction");?>
<br /><strong><?php _e("Why have a reserve price?", "wdm-ultimate-auction");?></strong><br />
<?php _e("Many sellers have found that too high a starting price discourages interest in their item, while an attractively low starting price makes them vulnerable to selling at an unsatisfactorily low price. A reserve price helps with this.", "wdm-ultimate-auction");?>
</span>
</a>
</div>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="incremental_value"><?php _e("Incremental Value", "wdm-ultimate-auction");?></label>
</th>
<td>
<?php echo $currency_code;?>
<input name="incremental_value" type="text" id="incremental_value" class="small-text number" value="<?php echo $this->wdm_post_meta('wdm_incremental_val');?>"/>
<div class="ult-auc-settings-tip"><?php _e("Set an amount from which next bid should start.", "wdm-ultimate-auction");?></div>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="end_date"><?php _e("Ending Date", "wdm-ultimate-auction");?></label>
</th>
<td>
<input name="end_date" type="text" id="end_date" class="regular-text" readOnly value="<?php echo $this->wdm_post_meta('wdm_listing_ends');?>"/>
<?php $def_timezone = get_option('wdm_time_zone');
if(!empty($def_timezone)){
printf(__('Current blog time is %s', 'wdm-ultimate-auction'),'<strong>'.date("Y-m-d H:i:s", time()).'</strong> ');
echo __('Timezone:', 'wdm-ultimate-auction').' <strong>'.$def_timezone.'</strong>';
}
else
printf(__('Please select your Timezone at %s Tab of the plugin.', 'wdm-ultimate-auction'), '<a href="'.admin_url('admin.php?page=ultimate-auction').'">'.__('Settings', 'wdm-ultimate-auction').'</a>');
?>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label for="buy_it_now_price"><?php _e("Buy Now Price", "wdm-ultimate-auction");?></label>
</th>
<td>
<?php echo $currency_code;?>
<input name="buy_it_now_price" type="text" id="buy_it_now_price" class="small-text number" value="<?php echo $this->wdm_post_meta('wdm_buy_it_now');?>"/>
<div class="ult-auc-settings-tip" ><?php _e("Visitors can buy your auction by making payments via PayPal.", "wdm-ultimate-auction");?></div>
</td>
</tr>
<?php do_action('ua_add_shipping_cost_input_field'); //SHP-ADD hook to add new price field ?>
<tr valign="top">
<th scope="row">
<label for="payment_method"><?php _e("Payment Method", "wdm-ultimate-auction");?></label>
</th>
<td>
<?php /*$paypal_enabled = get_option('wdm_paypal_address');
$wire_enabled = get_option('wdm_wire_transfer');
$mailing_enabled = get_option('wdm_mailing_address');*/
$pay_methods = array();
$pay_methods = get_option('payment_options_enabled');
?>
<select id="payment_method" name="payment_method">
<option id="wdm_method_paypal" value="method_paypal" <?php if($this->wdm_post_meta('wdm_payment_method') == "method_paypal") echo "selected"; if(!array_key_exists("method_paypal", $pay_methods)) echo "disabled='disabled'";?>>PayPal</option>
<option id="wdm_method_wire_transfer" value="method_wire_transfer" <?php if($this->wdm_post_meta('wdm_payment_method') == "method_wire_transfer") echo "selected"; if(!array_key_exists("method_wire_transfer", $pay_methods)) echo "disabled='disabled'";?>>Wire Transfer</option>
<option id="wdm_method_mailing" value="method_mailing" <?php if($this->wdm_post_meta('wdm_payment_method') == "method_mailing") echo "selected"; if(!array_key_exists("method_mailing", $pay_methods)) echo "disabled='disabled'";?>>By Cheque</option>
<option id="wdm_method_cash" value="method_cash" <?php if($this->wdm_post_meta('wdm_payment_method') == "method_cash") echo "selected"; if(!array_key_exists("method_cash", $pay_methods)) echo "disabled='disabled'";?>><?php _e("Cash", "wdm-ultimate-auction");?></option>
</select>
<div class="ult-auc-settings-tip"><?php _e("Only those methods will be active for which you've entered details inside plugin's settings page.", "wdm-ultimate-auction");?></div>
</td>
</tr>
</table>
<?php
global $post_id;
if(isset($_GET["edit_auction"]) && !empty($_GET["edit_auction"]) && !isset($_GET["reactivate"])){
echo "<input type='hidden' value='".$_GET["edit_auction"]."' name='update_auction'>";
}
else if($post_id != "")//user came here after clicking on submit button
echo "<input type='hidden' value='".$post_id."' name='update_auction'>";
echo wp_nonce_field('ua_wp_n_f','ua_wdm_add_auc');
?>
<?php submit_button(__('Save Changes', 'wdm-ultimate-auction')); ?>
</form>
<!--script to handle image upload and date picker functionality-->
<script type="text/javascript">
jQuery(document).ready(function($){
//var x;
//jQuery(".wdm_auction_image_upload").click(function(){
// tb_show('', 'media-upload.php?type=image&TB_iframe=true');
// x=jQuery(this).attr("id");
// return false;
// });
//
//window.send_to_editor = function(html) {
// imgurl = jQuery('img',html).attr('src');
// jQuery('.'+x).val(imgurl);
// tb_remove();
// }
var custom_uploader;
jQuery('.wdm_auction_image_upload').click(function(e) {
var target_input = jQuery(this).attr('id');
e.preventDefault();
//If the uploader object has already been created, reopen the dialog
//if (custom_uploader) {
// custom_uploader.open();
// return;
//}
//Extend the wp.media object
custom_uploader = wp.media.frames.file_frame = wp.media({
title: 'Choose Image',
button: {
text: 'Choose Image'
},
multiple: false
});
//When a file is selected, grab the URL and set it as the text field's value
custom_uploader.on('select', function() {
attachment = custom_uploader.state().get('selection').first().toJSON();
jQuery('.' + target_input).val(attachment.url);
});
//Open the uploader dialog
custom_uploader.open();
});
jQuery('#end_date').datetimepicker({
timeFormat: "HH:mm:ss",
dateFormat : 'yy-mm-dd',
minDateTime: 0
});
});
</script>