Parent Directory
|
Revision Log
|
Revision Graph
more options
| 1 | <?php |
| 2 | /* $Id: ebay.module,v 1.5 2007/08/19 23:41:37 hideout Exp $ */ |
| 3 | |
| 4 | //error_reporting(E_ERROR); |
| 5 | |
| 6 | /** |
| 7 | * Display help and module information |
| 8 | * @param section which section of the site we're displaying help |
| 9 | * @return help text for section |
| 10 | */ |
| 11 | function ebay_help($section='admin/help#ebay') { |
| 12 | |
| 13 | $output = ''; |
| 14 | |
| 15 | switch ($section) { |
| 16 | case "admin/help#ebay": |
| 17 | $output = '<p>'. t("Allows to sell drupal products on ebay"). '</p>'; |
| 18 | break; |
| 19 | case "node/add/product#ebay": |
| 20 | $output = t("Allows to sell drupal products on ebay"); |
| 21 | break; |
| 22 | } |
| 23 | |
| 24 | return $output; |
| 25 | } // function ebay_help |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * Valid permissions for this module |
| 30 | * @return array An array of valid permissions for the ebay module |
| 31 | */ |
| 32 | function ebay_perm() { |
| 33 | return array('create ebay item'); |
| 34 | } // function onthisdate_perm() |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | * Implementation of hook_access(). |
| 39 | */ |
| 40 | function ebay_access($op, $node) { |
| 41 | global $user; |
| 42 | |
| 43 | if ($op == 'create') { |
| 44 | return user_access('create ebay item'); |
| 45 | } |
| 46 | |
| 47 | if ($op == 'update' || $op == 'delete') { |
| 48 | if (user_access('edit own ebay items') && ($user->uid == $node->uid)) { |
| 49 | return TRUE; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | |
| 55 | /** |
| 56 | * Implementation of ecommerce' hook_ec_settings(). |
| 57 | */ |
| 58 | function ebay_ec_settings() { |
| 59 | |
| 60 | $form['ebay_certid'] = array( |
| 61 | '#type' => 'textfield', |
| 62 | '#title' => t('API Certificate Id?'), |
| 63 | '#description' => t('Ebay API Certificate Id'), |
| 64 | '#default_value' => variable_get('ebay_certid',''), |
| 65 | '#size' => 44, |
| 66 | '#maxlength' => 1024, |
| 67 | '#required' => TRUE, |
| 68 | ); |
| 69 | |
| 70 | $form['ebay_appid'] = array( |
| 71 | '#type' => 'textfield', |
| 72 | '#title' => t('API Application Id?'), |
| 73 | '#description' => t('Ebay API Application Id'), |
| 74 | '#default_value' => variable_get('ebay_appid',''), |
| 75 | '#size' => 44, |
| 76 | '#maxlength' => 1024, |
| 77 | '#required' => TRUE, |
| 78 | ); |
| 79 | |
| 80 | $form['ebay_devid'] = array( |
| 81 | '#type' => 'textfield', |
| 82 | '#title' => t('API Development Id?'), |
| 83 | '#description' => t('Ebay API Development Id'), |
| 84 | '#default_value' => variable_get('ebay_devid',''), |
| 85 | '#size' => 44, |
| 86 | '#maxlength' => 1024, |
| 87 | '#required' => TRUE, |
| 88 | ); |
| 89 | |
| 90 | $form['ebay_user'] = array( |
| 91 | '#type' => 'textfield', |
| 92 | '#title' => t('Ebay username?'), |
| 93 | '#description' => t('Your ebay username'), |
| 94 | '#default_value' => variable_get('ebay_user',''), |
| 95 | '#size' => 16, |
| 96 | '#maxlength' => 256, |
| 97 | '#required' => TRUE, |
| 98 | ); |
| 99 | |
| 100 | $form['ebay_token'] = array( |
| 101 | '#type' => 'textarea', |
| 102 | '#title' => t('Ebay API token?'), |
| 103 | '#description' => t('Ebay API token for this Id/username combination'), |
| 104 | '#default_value' => variable_get('ebay_token',''), |
| 105 | '#size' => 3, |
| 106 | '#required' => TRUE, |
| 107 | ); |
| 108 | |
| 109 | $currencylist = array('AUD'=>'AUD','CAD'=>'CAD','CHF'=>'CHF','CNY'=>'CNY','EUR'=>'EUR','GBP'=>'GBP','HKD'=>'HKD','INR'=>'INR', |
| 110 | 'MYR'=>'MYR','PHP'=>'PHP','PLN'=>'PLN','SEK'=>'SEK','SGD'=>'SGD','TWD'=>'TWD','USD'=>'USD'); |
| 111 | $form['ebay_currency'] = array( |
| 112 | '#type' => 'select', |
| 113 | '#title' => t('Ebay currency?'), |
| 114 | '#description' => t('your ebay items currency'), |
| 115 | '#default_value' => variable_get('ebay_currency',''), |
| 116 | '#options' => $currencylist, |
| 117 | ); |
| 118 | |
| 119 | $form['ebay_location'] = array( |
| 120 | '#type' => 'textfield', |
| 121 | '#title' => t('Your location?'), |
| 122 | '#description' => t('Where is your business located?'), |
| 123 | '#default_value' => variable_get('ebay_location',''), |
| 124 | '#size' => 16, |
| 125 | '#maxlength' => 256, |
| 126 | '#required' => TRUE, |
| 127 | ); |
| 128 | |
| 129 | $form['ebay_country'] = array( |
| 130 | '#type' => 'textfield', |
| 131 | '#title' => t('Your country?'), |
| 132 | '#description' => t('Country specification for your ebay listings.'), |
| 133 | '#default_value' => variable_get('ebay_country',''), |
| 134 | '#size' => 2, |
| 135 | '#maxlength' => 2, |
| 136 | ); |
| 137 | |
| 138 | $form['ebay_paypal_addr'] = array( |
| 139 | '#type' => 'textfield', |
| 140 | '#title' => t('Your paypal address for ebay listings?'), |
| 141 | '#description' => t('PayPal is the preferred payment method for most ebay listings.'), |
| 142 | '#default_value' => variable_get('ebay_paypal_addr',''), |
| 143 | '#size' => 16, |
| 144 | '#maxlength' => 64, |
| 145 | ); |
| 146 | |
| 147 | $form['ebay_nfymail_subj'] = array( |
| 148 | '#type' => 'textfield', |
| 149 | '#title' => t('Notify email subject?'), |
| 150 | '#description' => t('Notify emails are being sent to buyers. Please enter the subject!'), |
| 151 | '#default_value' => variable_get('ebay_nfymail_subj',''), |
| 152 | '#size' => 16, |
| 153 | '#maxlength' => 64, |
| 154 | ); |
| 155 | |
| 156 | $form['ebay_nfymail_body'] = array( |
| 157 | '#type' => 'textarea', |
| 158 | '#title' => t('Notify email body?'), |
| 159 | '#description' => t('Notify emails are being sent to buyers. Please enter the email content!'), |
| 160 | '#default_value' => variable_get('ebay_nfymail_body',''), |
| 161 | '#size' => 3, |
| 162 | '#required' => TRUE, |
| 163 | ); |
| 164 | |
| 165 | return system_settings_form($form); |
| 166 | } |
| 167 | |
| 168 | |
| 169 | /** |
| 170 | * call SetNotificationPreferences |
| 171 | */ |
| 172 | function ebay_ec_settings_validate($form_id, $form_values, $form) { |
| 173 | $sp = _ebay_session(); |
| 174 | |
| 175 | require_once 'ebatns/SetNotificationPreferencesRequestType.php'; |
| 176 | $req = new SetNotificationPreferencesRequestType(); |
| 177 | |
| 178 | $events = array('AskSellerQuestion','EndOfAuction','Feedback'); |
| 179 | $usrdevpref = new NotificationEnableArrayType(); |
| 180 | for ($i=0;$i<count($events);$i++) |
| 181 | { |
| 182 | $tmpc = new NotificationEnableType(); |
| 183 | $tmpc->setEventType($events[$i]); |
| 184 | $tmpc->setEventEnable('Enable'); |
| 185 | $usrdevpref->setNotificationEnable($tmpc,$i + 1); |
| 186 | } |
| 187 | $req->setUserDeliveryPreferenceArray($usrdevpref); |
| 188 | |
| 189 | $appdevtype = new ApplicationDeliveryPreferencesType(); |
| 190 | //$appdevtype->setAlertEnable('Enable'); |
| 191 | //$appdevtype->setAlertEmail('mailto://my@email'); |
| 192 | $appdevtype->setApplicationEnable('Enable'); |
| 193 | @eregi("^(http|https):",getenv('SCRIPT_URI'),$regs); |
| 194 | $proto = $regs[1]; |
| 195 | if (!$proto) $proto = 'http'; |
| 196 | $appdevtype->setApplicationURL($proto .'://'. getenv('HTTP_HOST') . base_path() .'/ebay/apirx'); |
| 197 | $req->setApplicationDeliveryPreferences($appdevtype); |
| 198 | $res = $sp->SetNotificationPreferences($req); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | function ebay_menu($may_cache) { |
| 203 | $items = array(); |
| 204 | |
| 205 | if ($may_cache) { |
| 206 | $items[] = array( |
| 207 | 'path' => 'admin/ecsettings/ebay', |
| 208 | 'title' => 'Ebay', |
| 209 | 'description' => 'Ebay integration settings', |
| 210 | 'callback' => 'drupal_get_form', |
| 211 | 'callback arguments' => array('ebay_ec_settings'), |
| 212 | 'access' => user_access('administer store'), |
| 213 | 'type' => MENU_NORMAL_ITEM, |
| 214 | ); |
| 215 | } |
| 216 | else { |
| 217 | if (arg(0) == 'ebay' && is_numeric(arg(1))) { |
| 218 | $items[] = array( |
| 219 | 'path' => 'ebay', |
| 220 | 'title' => t('bid'), |
| 221 | 'callback' => 'ebay_page', |
| 222 | 'access' => user_access('access content'), |
| 223 | 'type' => MENU_CALLBACK |
| 224 | ); |
| 225 | } |
| 226 | $items[] = array( |
| 227 | 'path' => 'ebay/autocomplete', |
| 228 | 'callback' => 'ebay_ac_category', |
| 229 | 'access' => user_access('access content'), |
| 230 | 'type' => MENU_CALLBACK, |
| 231 | ); |
| 232 | $items[] = array( |
| 233 | 'path' => 'ebay/apirx', |
| 234 | 'callback' => 'ebay_apirx', |
| 235 | 'access' => user_access(''), |
| 236 | 'type' => MENU_CALLBACK, |
| 237 | ); |
| 238 | $items[] = array( |
| 239 | 'path' => 'ebay/checkout', |
| 240 | 'title' => t('checkout'), |
| 241 | 'callback' => 'ebay_checkout_page', |
| 242 | 'access' => user_access('access content'), |
| 243 | 'type' => MENU_CALLBACK |
| 244 | ); |
| 245 | |
| 246 | $items[] = array( |
| 247 | 'path' => 'admin/store/ebay', |
| 248 | 'title' => t('ebay'), |
| 249 | 'callback' => 'ebay_admin_page', |
| 250 | 'access' => user_access('administer store'), |
| 251 | 'description' => t('Manage ebay events'), |
| 252 | ); |
| 253 | |
| 254 | $items[] = array( |
| 255 | 'path' => 'admin/store/ebay/status', |
| 256 | 'title' => t('Status'), |
| 257 | 'type' => MENU_DEFAULT_LOCAL_TASK, |
| 258 | ); |
| 259 | |
| 260 | $items[] = array( |
| 261 | 'path' => 'admin/store/ebay/feedback', |
| 262 | 'title' => t('Feedback'), |
| 263 | 'callback' => 'ebay_feedback_list', |
| 264 | 'type' => MENU_LOCAL_TASK, |
| 265 | 'weight' => 1 |
| 266 | ); |
| 267 | |
| 268 | $items[] = array( |
| 269 | 'path' => 'admin/store/ebay/feedback/leave', |
| 270 | 'title' => t('Leave Feedback'), |
| 271 | 'callback' => 'drupal_get_form', |
| 272 | 'callback arguments' => array('ebay_feedback_leave'), |
| 273 | 'type' => MENU_CALLBACK, |
| 274 | 'weight' => 1, |
| 275 | ); |
| 276 | |
| 277 | $items[] = array( |
| 278 | 'path' => 'admin/store/ebay/feedback/delete', |
| 279 | 'title' => t('Delete Feedback Request'), |
| 280 | 'callback' => 'drupal_get_form', |
| 281 | 'callback arguments' => array('ebay_feedback_delete'), |
| 282 | 'type' => MENU_CALLBACK, |
| 283 | ); |
| 284 | |
| 285 | $items[] = array( |
| 286 | 'path' => 'admin/store/ebay/questions', |
| 287 | 'title' => t('BuyerQuestions'), |
| 288 | 'callback' => 'ebay_question_list', |
| 289 | 'type' => MENU_LOCAL_TASK, |
| 290 | 'weight' => 1 |
| 291 | ); |
| 292 | |
| 293 | $items[] = array( |
| 294 | 'path' => 'admin/store/ebay/questions/answer', |
| 295 | 'title' => t('Answer Question'), |
| 296 | 'callback' => 'drupal_get_form', |
| 297 | 'callback arguments' => array('ebay_question_answer'), |
| 298 | 'type' => MENU_CALLBACK, |
| 299 | 'weight' => 1, |
| 300 | ); |
| 301 | |
| 302 | $items[] = array( |
| 303 | 'path' => 'admin/store/ebay/questions/delete', |
| 304 | 'title' => t('Delete Question'), |
| 305 | 'callback' => 'drupal_get_form', |
| 306 | 'callback arguments' => array('ebay_question_delete'), |
| 307 | 'type' => MENU_CALLBACK, |
| 308 | ); |
| 309 | } |
| 310 | |
| 311 | return $items; |
| 312 | } |
| 313 | |
| 314 | |
| 315 | /* |
| 316 | * Implemetation of hook_nodeapi() |
| 317 | * |
| 318 | */ |
| 319 | function ebay_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
| 320 | switch ($op) { |
| 321 | case 'view': |
| 322 | if (isset($node->ptype) && $node->ptype == 'ebay') { |
| 323 | global $user; |
| 324 | if ($page) { |
| 325 | $form = drupal_get_form('product_ebay_view_form',$node,$user); |
| 326 | $node->content['body']['#value'] .= $form; |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | |
| 333 | function ebay_productapi(&$node, $op, $a3 = null, $a4 = null) { |
| 334 | |
| 335 | switch ($op) { |
| 336 | case 'fields': |
| 337 | return array('buyitnow' => $node->buyitnow, 'ebay_category' => $node->ebay_category, 'ebay_payment' => $node->ebay_payment, |
| 338 | 'test' => $node->bid_history); |
| 339 | |
| 340 | /* add link in admin/create content/product */ |
| 341 | case 'wizard_select': |
| 342 | return array('ebay' => t('Ebay Item')); |
| 343 | |
| 344 | /* add fields to create/edit ebay product */ |
| 345 | case 'form': |
| 346 | $form['expires'] = array( |
| 347 | '#type' => 'select', |
| 348 | '#title' => t('Expiration date'), |
| 349 | '#default_value' => 'Days_7', |
| 350 | '#options' => array('Days_1'=>'1 Day','Days_3'=>'3 Days','Days_5'=>'5 Days','Days_7'=>'7 Days','Days_10'=>'10 Days','Days_14'=>'14 Days', |
| 351 | 'Days_21'=>'21 Days','Days_30'=>'30 Days','Days_60'=>'60 Days','Days_90'=>'90 Days','Days_120'=>'120 Days'), |
| 352 | '#description' => t('Enter the date this product is no longer open for bidding.'), |
| 353 | ); |
| 354 | $form['buyitnow'] = array( |
| 355 | '#type' => 'textfield', |
| 356 | '#title' => t('Buy It Now'), |
| 357 | '#default_value' => '0.00', |
| 358 | '#description' => t('If you want to allow buy-it-now, please specify a price.'), |
| 359 | ); |
| 360 | $form['ebay_payment'] = array( |
| 361 | '#type' => 'select', |
| 362 | '#title' => t('Accepted payment methods?'), |
| 363 | '#multiple' => true, |
| 364 | '#description' => t('Which payment methods do you accept? Please note some methods are not allowed in certain ebay sites and/or categories!'), |
| 365 | '#default_value' => '', |
| 366 | '#options' => array('AmEx'=>'American Express','CashOnPickup'=>'Cash-on-Pickup','CCAccepted'=>'Credit Card','COD'=>'Cash-on-Delivery', |
| 367 | 'MOCC'=>'Money order/cashiers check','MoneyXferAccepted'=>'Direct money transfer','None'=>'None specified', |
| 368 | 'Other'=>'Other payments','OtherOnlinePayments'=>'Other online payments','PaymentSeeDescription'=>'Payment-see-Description', |
| 369 | 'PayPal'=>'PayPal','PersonalCheck'=>'Personal Check'), |
| 370 | ); |
| 371 | $form['ebay_category'] = array( |
| 372 | '#type' => 'textfield', |
| 373 | '#title' => t('Item category?'), |
| 374 | '#maxlength' => 60, |
| 375 | '#autocomplete_path' => 'ebay/autocomplete/all', |
| 376 | '#description' => t('Enter the id\'s of the products that you which to add to the invoice. Here is a <a href="%product_quicklist" onclick="window.open()">...</a>'), |
| 377 | ); |
| 378 | |
| 379 | $form['ebay_misc'] = array( |
| 380 | '#type' => 'fieldset', |
| 381 | '#title' => t('Miscellaneous Ebay settings'), |
| 382 | '#collapsible' => TRUE, |
| 383 | '#collapsed' => TRUE, |
| 384 | ); |
| 385 | $form['ebay_misc']['ebay_quantity'] = array( |
| 386 | '#type' => 'textfield', |
| 387 | '#title' => t('Quantity'), |
| 388 | '#default_value' => 1, |
| 389 | '#description' => t('This items quantity.'), |
| 390 | ); |
| 391 | $form['ebay_misc']['ebay_lotsize'] = array( |
| 392 | '#type' => 'textfield', |
| 393 | '#title' => t('Lotsize?'), |
| 394 | '#default_value' => 0, |
| 395 | '#description' => t('A lot is a set of two or more similar items that must be purchased together in a single transaction.'), |
| 396 | ); |
| 397 | $form['ebay_misc']['ebay_shipto'] = array( |
| 398 | '#type' => 'textfield', |
| 399 | '#title' => t('Ship to location?'), |
| 400 | '#default_value' => '', |
| 401 | '#description' => t('Where are you willing to ship the item? Special-use values: None and Worldwide.'), |
| 402 | ); |
| 403 | $form['ebay_misc']['ebay_schedule'] = array( |
| 404 | '#type' => 'textfield', |
| 405 | '#title' => t('Schedule time?'), |
| 406 | '#default_value' => '', |
| 407 | '#description' => t('Start auction at a delayed date/time; format: YYYY-MM-DDTHH:MM:SS.SSSZ'), |
| 408 | ); |
| 409 | $form['ebay_misc']['ebay_subtitle'] = array( |
| 410 | '#type' => 'textfield', |
| 411 | '#title' => t('Subtitle?'), |
| 412 | '#default_value' => '', |
| 413 | '#description' => t('A subtitle for your item; This will increase the fee.'), |
| 414 | ); |
| 415 | $form['ebay_misc']['ebay_reserve'] = array( |
| 416 | '#type' => 'textfield', |
| 417 | '#title' => t('Reserve price?'), |
| 418 | '#default_value' => '', |
| 419 | '#description' => t('The lowest price you are willing to sell for. Must be higher than start price, not available for all categories.'), |
| 420 | ); |
| 421 | $form['ebay_misc']['ebay_nowandnew'] = array( |
| 422 | '#type' => 'checkbox', |
| 423 | '#title' => t('Now-and-New?'), |
| 424 | '#description' => t('Ebay Now-and-New option; only valid with buy-it-now!'), |
| 425 | ); |
| 426 | $form['ebay_misc']['ebay_shippingindesc'] = array( |
| 427 | '#type' => 'checkbox', |
| 428 | '#title' => t('Shipping terms in description?'), |
| 429 | '#default_value' => true, |
| 430 | '#description' => t('Indicates whether details about shipping costs and arrangements are specified in the item description.'), |
| 431 | ); |
| 432 | $form['ebay_misc']['ebay_private'] = array( |
| 433 | '#type' => 'checkbox', |
| 434 | '#title' => t('Private Listing?'), |
| 435 | '#description' => t('Buyer userids will not appear in the bid history.'), |
| 436 | ); |
| 437 | $form['ebay_misc']['ebay_hitcounter'] = array( |
| 438 | '#type' => 'select', |
| 439 | '#options' => array('BasicStyle'=>'Basic Counter','HiddenStyle'=>'hidden/invisible counter','NoHitCounter'=>'No counter','RetroStyle'=>'Computer-style counter'), |
| 440 | '#default_value' => 'NoHitCounter', |
| 441 | '#title' => t('Hitcounter'), |
| 442 | '#description' => t('Display a hit counter on your items page.'), |
| 443 | ); |
| 444 | $form['ebay_misc']['ebay_enhancement'] = array( |
| 445 | '#type' => 'select', |
| 446 | '#multiple' => true, |
| 447 | '#options' => array('BoldTitle'=>'Bold Title','Border'=>'Border','Featured'=>'Featured Plus','Highlight'=>'Highlighted','HomePageFeatured'=> |
| 448 | 'Show on main page'), |
| 449 | '#title' => t('Listing enhancements'), |
| 450 | '#description' => t('You may upgrade your ebay listing with enhancements. This will increase the fee.'), |
| 451 | ); |
| 452 | |
| 453 | |
| 454 | return $form; |
| 455 | |
| 456 | /* check if AddItem call would succede */ |
| 457 | case 'validate': |
| 458 | |
| 459 | $sp = _ebay_session(); |
| 460 | |
| 461 | require_once 'ebatns/VerifyAddItemRequestType.php'; |
| 462 | |
| 463 | $item = new ItemType(); |
| 464 | $item->Description = $node->body; |
| 465 | $item->Title = $node->title; |
| 466 | $item->Currency = variable_get('ebay_currency','USD'); |
| 467 | $item->Quantity = $node->ebay_quantity; |
| 468 | if ($node->ebay_lotsize) $item->LotSize = $node->ebay_lotsize; |
| 469 | if ($node->ebay_nowandnew) $item->NowAndNew = true; |
| 470 | if ($node->ebay_shippingindesc) $item->ShippingTermsInDescription = true; |
| 471 | if ($node->ebay_private) $item->PrivateListing = true; |
| 472 | $item->HitCounter = $node->ebay_hitcounter; |
| 473 | if ($node->ebay_reserve) $item->ReservePrice = $node->ebay_reserve; |
| 474 | if ($node->ebay_subtitle) $item->SubTitle = $node->ebay_subtitle; |
| 475 | if ($node->ebay_schedule) $item->ScheduleTime = $node->ebay_schedule; |
| 476 | if ($node->ebay_shipto) $item->ShipToLocations = $node->ebay_shipto; |
| 477 | if ($node->ebay_enhancement) |
| 478 | { |
| 479 | $i=1; |
| 480 | foreach ($node->ebay_enhancement as $ehm) |
| 481 | { |
| 482 | $item->setListingEnhancement($ehm,$i); |
| 483 | $i++; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | $item->Country = variable_get('ebay_country','US'); |
| 488 | //$item->Country = 'DE'; |
| 489 | //$item->Site = 'Germany'; |
| 490 | |
| 491 | $item->StartPrice = $node->price; |
| 492 | $item->ListingDuration = $node->expires; |
| 493 | if ($node->buyitnow && $node->buyitnow != '0.00') $item->BuyItNowPrice = $node->buyitnow; |
| 494 | $item->Location = variable_get('ebay_location','nowhere'); |
| 495 | $item->PrimaryCategory = new CategoryType(); |
| 496 | $item->PrimaryCategory->CategoryID = db_result(db_query("SELECT categoryid FROM {ec_ebay_categories} WHERE categoryname = '%s'", $node->ebay_category)); |
| 497 | |
| 498 | $item->setPaymentMethods($node->ebay_payment); |
| 499 | //$item->setPaymentMethods(array('PayPal')); |
| 500 | $item->setPayPalEmailAddress(variable_get('ebay_paypal_addr','')); |
| 501 | |
| 502 | $req = new VerifyAddItemRequestType(); |
| 503 | $req->Item = $item; |
| 504 | //drupal_set_message("<pre>". print_r($req,1) ."</pre>"); |
| 505 | $res = $sp->VerifyAddItem($req); |
| 506 | |
| 507 | // itemId |
| 508 | //$res['ItemID']; |
| 509 | //$res = $cs->VerifyAddItem($req); |
| 510 | |
| 511 | |
| 512 | //drupal_set_message("<pre>". print_r($res,1) ."</pre>"); |
| 513 | |
| 514 | if ($res->Ack == 'Failure') { |
| 515 | foreach($res->Errors as $err) |
| 516 | $errstr .= $err->LongMessage .'<br>'; |
| 517 | form_set_error('ebay','Ebay API returned Error(s):<br>'. $errstr); |
| 518 | } |
| 519 | break; |
| 520 | |
| 521 | /* New product, tell it ebay API */ |
| 522 | case 'insert': |
| 523 | |
| 524 | $sp = _ebay_session(); |
| 525 | |
| 526 | require_once 'ebatns/AddItemRequestType.php'; |
| 527 | require_once 'ebatns/ItemType.php'; |
| 528 | |
| 529 | $item = new ItemType(); |
| 530 | $item->Description = $node->body; |
| 531 | $item->Title = $node->title; |
| 532 | $item->Currency = variable_get('ebay_currency','USD'); |
| 533 | |
| 534 | $item->Quantity = $node->ebay_quantity; |
| 535 | if ($node->ebay_lotsize) $item->LotSize = $node->ebay_lotsize; |
| 536 | if ($node->ebay_nowandnew) $item->NowAndNew = true; |
| 537 | if ($node->ebay_shippingindesc) $item->ShippingTermsInDescription = true; |
| 538 | if ($node->ebay_private) $item->PrivateListing = true; |
| 539 | $item->HitCounter = $node->ebay_hitcounter; |
| 540 | if ($node->ebay_reserve) $item->ReservePrice = $node->ebay_reserve; |
| 541 | if ($node->ebay_subtitle) $item->SubTitle = $node->ebay_subtitle; |
| 542 | if ($node->ebay_schedule) $item->ScheduleTime = $node->ebay_schedule; |
| 543 | if ($node->ebay_shipto) $item->ShipToLocations = $node->ebay_shipto; |
| 544 | if ($node->ebay_enhancement) |
| 545 | { |
| 546 | $i=1; |
| 547 | foreach ($node->ebay_enhancement as $ehm) |
| 548 | { |
| 549 | $item->setListingEnhancement($ehm,$i); |
| 550 | $i++; |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | $item->Country = variable_get('ebay_country','US'); |
| 555 | //$item->Country = 'DE'; |
| 556 | //$item->Site = 'Germany'; |
| 557 | |
| 558 | $item->StartPrice = $node->price; |
| 559 | $item->ListingDuration = $node->expires; |
| 560 | if ($node->buyitnow && $node->buyitnow != '0.00') $item->BuyItNowPrice = $node->buyitnow; |
| 561 | $item->Location = variable_get('ebay_location','nowhere'); |
| 562 | $item->PrimaryCategory = new CategoryType(); |
| 563 | $item->PrimaryCategory->CategoryID = db_result(db_query("SELECT categoryid FROM {ec_ebay_categories} WHERE categoryname = '%s'", $node->ebay_category)); |
| 564 | $item->CategoryMappingAllowed = true; |
| 565 | |
| 566 | $item->setPaymentMethods($node->ebay_payment); |
| 567 | $item->setPayPalEmailAddress(variable_get('ebay_paypal_addr','')); |
| 568 | |
| 569 | if ($node->files) { |
| 570 | $pictdet = new PictureDetailsType(); |
| 571 | $pictdet->setPhotoDisplay('VendorHostedPictureShow'); |
| 572 | @eregi("^(http|https):",getenv('SCRIPT_URI'),$regs); |
| 573 | $proto = $regs[1]; |
| 574 | if (!$proto) $proto = 'http'; |
| 575 | reset($node->files); |
| 576 | $i=1; |
| 577 | while(list($fname,$farr) = @each($node->files)) { |
| 578 | $pictdet->setPictureUrl($proto .'://'. getenv('HTTP_HOST') . base_path() .'/files/'. $farr['filename'], $i); |
| 579 | $i++; |
| 580 | } |
| 581 | reset($node->files); |
| 582 | $item->PictureDetails = $pictdet; |
| 583 | } |
| 584 | |
| 585 | $req = new AddItemRequestType(); |
| 586 | $req->Item = $item; |
| 587 | //drupal_set_message("<pre>". print_r($req,1) ."</pre>"); |
| 588 | $res = $sp->AddItem($req); |
| 589 | |
| 590 | // itemId |
| 591 | //$res['ItemID']; |
| 592 | //$res = $cs->VerifyAddItem($req); |
| 593 | |
| 594 | |
| 595 | //drupal_set_message("<pre>". print_r($res,1) ."</pre>"); |
| 596 | //drupal_set_message("<pre>". print_r($node,1) ."</pre>"); |
| 597 | |
| 598 | if ($res->Ack == 'Success') { |
| 599 | $i = 0; |
| 600 | while ($FeeType = $res->Fees->getFee($i)) { |
| 601 | $fee = $fee + $FeeType->Fee->value; |
| 602 | $i++; |
| 603 | } |
| 604 | drupal_set_message("Successfully created ebay listing (ItemID: ". $res->ItemID .", fee: $fee)"); |
| 605 | return db_query("INSERT INTO {ec_product_ebay} (nid, itemid, fee) VALUES (%d, '%s', %f)", $node->nid, $res->ItemID, $fee); |
| 606 | } |
| 607 | else { |
| 608 | foreach($res->Errors as $err) |
| 609 | $errstr .= $err->LongMessage .'<br>'; |
| 610 | form_set_error('',"Error creating ebay product: $errstr"); |
| 611 | } |
| 612 | break; |
| 613 | |
| 614 | |
| 615 | case 'update': |
| 616 | $sp = _ebay_session(); |
| 617 | require_once 'ebatns/ReviseItemRequestType.php'; |
| 618 | require_once 'ebatns/ItemType.php'; |
| 619 | |
| 620 | $item = new ItemType(); |
| 621 | $item->Description = $node->body; |
| 622 | $item->Title = $node->title; |
| 623 | $item->Currency = variable_get('ebay_currency','USD'); |
| 624 | |
| 625 | $item->Quantity = $node->ebay_quantity; |
| 626 | if ($node->ebay_lotsize) $item->LotSize = $node->ebay_lotsize; |
| 627 | if ($node->ebay_nowandnew) $item->NowAndNew = true; |
| 628 | if ($node->ebay_shippingindesc) $item->ShippingTermsInDescription = true; |
| 629 | if ($node->ebay_private) $item->PrivateListing = true; |
| 630 | $item->HitCounter = $node->ebay_hitcounter; |
| 631 | if ($node->ebay_reserve) $item->ReservePrice = $node->ebay_reserve; |
| 632 | if ($node->ebay_subtitle) $item->SubTitle = $node->ebay_subtitle; |
| 633 | if ($node->ebay_schedule) $item->ScheduleTime = $node->ebay_schedule; |
| 634 | if ($node->ebay_shipto) $item->ShipToLocations = $node->ebay_shipto; |
| 635 | if ($node->ebay_enhancement) |
| 636 | { |
| 637 | $i=1; |
| 638 | foreach ($node->ebay_enhancement as $ehm) |
| 639 | { |
| 640 | $item->setListingEnhancement($ehm,$i); |
| 641 | $i++; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | $item->Country = variable_get('ebay_country','US'); |
| 646 | |
| 647 | $item->StartPrice = $node->price; |
| 648 | $item->ListingDuration = $node->expires; |
| 649 | if ($node->buyitnow && $node->buyitnow != '0.00') $item->BuyItNowPrice = $node->buyitnow; |
| 650 | $item->Location = variable_get('ebay_location','nowhere'); |
| 651 | $item->PrimaryCategory = new CategoryType(); |
| 652 | $item->PrimaryCategory->CategoryID = db_result(db_query("SELECT categoryid FROM {ec_ebay_categories} WHERE categoryname = '%s'", $node->ebay_category)); |
| 653 | $item->CategoryMappingAllowed = true; |
| 654 | |
| 655 | $item->setPaymentMethods($node->ebay_payment); |
| 656 | $item->setPayPalEmailAddress(variable_get('ebay_paypal_addr','')); |
| 657 | |
| 658 | if ($node->files) { |
| 659 | $pictdet = new PictureDetailsType(); |
| 660 | $pictdet->setPhotoDisplay('VendorHostedPictureShow'); |
| 661 | @eregi("^(http|https):",getenv('SCRIPT_URI'),$regs); |
| 662 | $proto = $regs[1]; |
| 663 | if (!$proto) $proto = 'http'; |
| 664 | reset($node->files); |
| 665 | $i=1; |
| 666 | while(list($fname,$farr) = @each($node->files)) { |
| 667 | $pictdet->setPictureUrl($proto .'://'. getenv('HTTP_HOST') . base_path() .'/files/'. $farr['filename'], $i); |
| 668 | $i++; |
| 669 | } |
| 670 | reset($node->files); |
| 671 | $item->PictureDetails = $pictdet; |
| 672 | } |
| 673 | |
| 674 | $itemid = db_result(db_query('SELECT itemid FROM {ec_product_ebay} WHERE nid = %d', $node->nid)); |
| 675 | $item->ItemID = $itemid; |
| 676 | |
| 677 | $req = new ReviseItemRequestType(); |
| 678 | $req->Item = $item; |
| 679 | //drupal_set_message("<pre>". print_r($req,1) ."</pre>"); |
| 680 | $res = $sp->ReviseItem($req); |
| 681 | //drupal_set_message("<pre>". print_r($res,1) ."</pre>"); |
| 682 | |
| 683 | // itemId |
| 684 | //$res['ItemID']; |
| 685 | //$res = $cs->VerifyAddItem($req); |
| 686 | |
| 687 | break; |
| 688 | |
| 689 | |
| 690 | case 'delete': |
| 691 | $sp = _ebay_session(); |
| 692 | require_once 'ebatns/EndItemRequestType.php'; |
| 693 | |
| 694 | $item = db_result(db_query('SELECT itemid FROM {ec_product_ebay} WHERE nid = %d', $node->nid)); |
| 695 | |
| 696 | $req = new EndItemRequestType(); |
| 697 | $req->ItemID = $item; |
| 698 | $req->EndingReason = 'NotAvailable'; // hardcoded for now |
| 699 | $res = $sp->EndItem($req); |
| 700 | |
| 701 | db_query('DELETE FROM {ec_product_ebay} WHERE nid = %d', $node->nid); |
| 702 | break; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | |
| 707 | /** |
| 708 | * Create form array and load some useful information for later theming |
| 709 | * |
| 710 | * @param |
| 711 | * Object $node |
| 712 | * @param |
| 713 | * Object $user |
| 714 | * @return |
| 715 | * A formapi array which contains additional ebay form elems. |
| 716 | * Array['theme'] contains the non-form data. |
| 717 | */ |
| 718 | |
| 719 | function product_ebay_view_form($node,$user){ |
| 720 | |
| 721 | $form['theme'] = array(); |
| 722 | $form['theme']['#itemid'] = db_result(db_query('SELECT itemid FROM {ec_product_ebay} WHERE nid = %d', $node->nid)); |
| 723 | $form['theme']['#fee'] = db_result(db_query('SELECT fee FROM {ec_product_ebay} WHERE nid = %d', $node->nid)); |
| 724 | |
| 725 | return $form; |
| 726 | } |
| 727 | |
| 728 | |
| 729 | function theme_product_ebay_view_form($form){ |
| 730 | $output = l('View item on ebay','http://sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&item=' . $form['theme']['#itemid']); |
| 731 | $output .= "<br><b>Ebay Fee</b>: ". $form['theme']['#fee']; |
| 732 | return $output; |
| 733 | } |
| 734 | |
| 735 | |
| 736 | /* |
| 737 | * We never need the "Add to cart" link, since items are bought on ebay. |
| 738 | */ |
| 739 | function ebay_link_alter(&$node, &$links) { |
| 740 | if (isset($node->ptype) && $node->ptype == 'ebay' && $links['add_to_cart']) { |
| 741 | unset($links['add_to_cart']); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | |
| 746 | /** |
| 747 | * Do various tasks (Feedback, Buyer Questions, ...) |
| 748 | */ |
| 749 | function ebay_admin_page($type='', $string='') { |
| 750 | $questions = db_result(db_query('SELECT COUNT(*) FROM {ec_ebay_questions}')); |
| 751 | $feedbacks = db_result(db_query('SELECT COUNT(*) FROM {ec_product_ebay} WHERE buyerfb=1 AND sellerfb=0')); |
| 752 | |
| 753 | $content .= "Buyer questions awaiting answer: $questions<br>\n"; |
| 754 | $content .= "You need to leave feedback for $feedbacks items<br>\n"; |
| 755 | |
| 756 | return $content; |
| 757 | } |
| 758 | |
| 759 | /** |
| 760 | * List ebay questions |
| 761 | */ |
| 762 | function ebay_question_list($type='', $string='') { |
| 763 | $head = array( |
| 764 | array('data' => t('Product'), 'field' => 'nid'), |
| 765 | array('data' => t('Question Type'), 'field' => 'questiontype'), |
| 766 | array('data' => t('Sender'), 'field' => 'senderid'), |
| 767 | array('data' => t('Subject'), 'field' => 'subject'), |
| 768 | array('data' => t('Created'), 'field' => 'creationdate'), |
| 769 | array('data' => t('Status'), 'field' => 'messagestatus'), |
| 770 | array() |
| 771 | ); |
| 772 | |
| 773 | $sql = "SELECT q.nid,q.messageid,q.questiontype,q.senderid,q.subject,q.creationdate,q.messagestatus FROM {ec_ebay_questions} q"; |
| 774 | |
| 775 | $result = pager_query($sql. tablesort_sql($head), 50); |
| 776 | |
| 777 | while ($question = db_fetch_object($result)) { |
| 778 | $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $question->nid)); |
| 779 | $rows[] = array( |
| 780 | array('data' => l($title, 'node/'. $question->nid)), |
| 781 | array('data' => $question->questiontype), |
| 782 | array('data' => $question->senderid), |
| 783 | array('data' => $question->subject), |
| 784 | array('data' => $question->creationdate), |
| 785 | array('data' => $question->messagestatus), |
| 786 | array('data' => l(t('Delete'), 'admin/store/ebay/questions/delete/'. $question->messageid) .' '. |
| 787 | l(t('Answer'), 'admin/store/ebay/questions/answer/'. $question->messageid)), |
| 788 | ); |
| 789 | } |
| 790 | |
| 791 | $output.= theme('table', $head, $rows); |
| 792 | $output.= theme('pager', 50); |
| 793 | |
| 794 | return $output; |
| 795 | } |
| 796 | |
| 797 | |
| 798 | /** |
| 799 | * Delete question |
| 800 | */ |
| 801 | function ebay_question_delete($mid = NULL) { |
| 802 | if (!$mid || (!db_result(db_query("SELECT COUNT(*) FROM {ec_ebay_questions} WHERE messageid = '%s'", $mid)))) { |
| 803 | drupal_not_found(); |
| 804 | exit(); |
| 805 | } |
| 806 | |
| 807 | $form['mid'] = array( |
| 808 | '#type' => 'value', |
| 809 | '#value' => $mid, |
| 810 | ); |
| 811 | return confirm_form($form, t('Do you want to delete question %qu', array('%qu' => $mid)),'admin/store/ebay/questions',t('This question will be deleted from our database, but still be available in your ebay account.'), t('Delete')); |
| 812 | } |
| 813 | |
| 814 | |
| 815 | function ebay_question_delete_submit($form_id, $form_values) { |
| 816 | db_query("DELETE FROM {ec_ebay_questions} WHERE messageid = '%s'", $form_values['mid']); |
| 817 | drupal_set_message(t('Question %qu has been deleted', array('%qu' => $form_values['mid']))); |
| 818 | return 'admin/store/ebay/questions'; |
| 819 | } |
| 820 | |
| 821 | |
| 822 | /** |
| 823 | * Answer Ebay AskSellerQuestion Question |
| 824 | */ |
| 825 | function ebay_question_answer($mid = NULL) { |
| 826 | $form['mid'] = array( |
| 827 | '#type' => 'value', |
| 828 | '#value' => $mid, |
| 829 | ); |
| 830 | $form['ebay_body'] = array( |
| 831 | '#type' => 'textarea', |
| 832 | '#title' => t('Message content'), |
| 833 | '#description' => t('Enter the content of your message.'), |
| 834 | ); |
| 835 | $form['ebay_displaytopublic'] = array( |
| 836 | '#type' => 'checkbox', |
| 837 | '#title' => t('Display to public?'), |
| 838 | ); |
| 839 | $form['ebay_hidesender'] = array( |
| 840 | '#type' => 'checkbox', |
| 841 | '#title' => t('Hide email address?'), |
| 842 | ); |
| 843 | $form['ebay_copytosender'] = array( |
| 844 | '#type' => 'checkbox', |
| 845 | '#title' => t('Send copy to sender?'), |
| 846 | ); |
| 847 | $form[] = array( |
| 848 | '#type' => 'submit', |
| 849 | '#value' => t('Answer Question'), |
| 850 | ); |
| 851 | return $form; |
| 852 | } |
| 853 | |
| 854 | |
| 855 | function ebay_question_answer_submit($form_id, $form_values) { |
| 856 | $sp = _ebay_session(); |
| 857 | require_once 'ebatns/AddMemberMessageRTQRequestType.php'; |
| 858 | |
| 859 | $item = db_result(db_query('SELECT itemid FROM {ec_product_ebay},{ec_ebay_questions} WHERE {ec_ebay_questions}.nid = {ec_product_ebay}.nid AND {ec_ebay_questions}.messageid = %d', $form_values['mid'])); |
| 860 | $senderid = db_result(db_query('SELECT senderid FROM {ec_ebay_questions} WHERE messageid = %d', $form_values['mid'])); |
| 861 | |
| 862 | $req = new AddMemberMessageRTQRequestType(); |
| 863 | $req->ItemID = $item; |
| 864 | $req->MemberMessage = new MemberMessageType(); |
| 865 | $req->MemberMessage->setParentMessageID($form_values['mid']); |
| 866 | $req->MemberMessage->setRecipientID($senderid); |
| 867 | $req->MemberMessage->setHideSendersEmailAddress($form_values['ebay_hidesender']); |
| 868 | $req->MemberMessage->setDisplayToPublic($form_values['ebay_displaytopublic']); |
| 869 | $req->MemberMessage->setEmailCopyToSender($form_values['ebay_copytosender']); |
| 870 | $req->MemberMessage->setBody($form_values['ebay_body']); |
| 871 | $res = $sp->AddMemberMessageRTQ($req); |
| 872 | |
| 873 | if ($res->Ack == 'Success') { |
| 874 | db_query('DELETE FROM {ec_ebay_questions} WHERE messageid = %d', $form_values['mid']); |
| 875 | drupal_set_message(t('Question %qu has been answered', array('%qu' => $form_values['mid']))); |
| 876 | } else { |
| 877 | drupal_set_message(t('Question could not be answered, a problem occured.')); |
| 878 | //drupal_set_message('<pre>'. print_r($req,1) .'</pre>'); |
| 879 | //drupal_set_message('<pre>'. print_r($res,1) .'</pre>'); |
| 880 | } |
| 881 | |
| 882 | return "admin/store/ebay/questions"; |
| 883 | } |
| 884 | |
| 885 | |
| 886 | /** |
| 887 | * List items awaiting feedback |
| 888 | */ |
| 889 | function ebay_feedback_list($type='', $string='') { |
| 890 | $head = array( |
| 891 | array('data' => t('Product'), 'field' => 'nid'), |
| 892 | array() |
| 893 | ); |
| 894 | |
| 895 | $sql = "SELECT q.nid FROM {ec_product_ebay} q WHERE buyerfb=1 AND sellerfb=0 |
| 896 | GROUP BY q.nid"; |
| 897 | |
| 898 | $result = pager_query($sql. tablesort_sql($head), 50); |
| 899 | |
| 900 | while ($fb = db_fetch_object($result)) { |
| 901 | $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $fb->nid)); |
| 902 | $rows[] = array( |
| 903 | array('data' => l($title, 'node/'. $fb->nid)), |
| 904 | array('data' => l(t('Delete'), 'admin/store/ebay/feedback/delete/'. $fb->nid) .' '. |
| 905 | l(t('Answer'), 'admin/store/ebay/feedback/leave/'. $fb->nid)), |
| 906 | ); |
| 907 | } |
| 908 | |
| 909 | $output.= theme('table', $head, $rows); |
| 910 | $output.= theme('pager', 50); |
| 911 | |
| 912 | return $output; |
| 913 | } |
| 914 | |
| 915 | |
| 916 | /** |
| 917 | * Delete feedback request |
| 918 | */ |
| 919 | function ebay_feedback_delete($nid = NULL) { |
| 920 | if (!$nid || (!db_result(db_query("SELECT COUNT(*) FROM {ec_product_ebay} WHERE nid = '%s'", $nid)))) { |
| 921 | drupal_not_found(); |
| 922 | exit(); |
| 923 | } |
| 924 | |
| 925 | $form['nid'] = array( |
| 926 | '#type' => 'value', |
| 927 | '#value' => $nid, |
| 928 | ); |
| 929 | return confirm_form($form, t('Do you want to delete feedback request %fb', array('%fb' => $nid)),'admin/store/ebay/feedback',t('This feedback request will be deleted from our database.'), t('Delete')); |
| 930 | } |
| 931 | |
| 932 | |
| 933 | function ebay_feedback_delete_submit($form_id, $form_values) { |
| 934 | db_query("UPDATE {ec_product_ebay} SET sellerfb=1 WHERE nid = '%s'", $form_values['nid']); |
| 935 | drupal_set_message(t('Feedback request %fb has been deleted', array('%fb' => $form_values['nid']))); |
| 936 | return 'admin/store/ebay/feedback'; |
| 937 | } |
| 938 | |
| 939 | |
| 940 | /** |
| 941 | * Leave feedback for buyer |
| 942 | */ |
| 943 | function ebay_feedback_leave($nid = NULL) { |
| 944 | $form['nid'] = array( |
| 945 | '#type' => 'value', |
| 946 | '#value' => $nid, |
| 947 | ); |
| 948 | $form['ebay_content'] = array( |
| 949 | '#type' => 'textarea', |
| 950 | '#title' => t('Feedback content'), |
| 951 | '#description' => t('Enter the content of your feedback.'), |
| 952 | ); |
| 953 | $form['ebay_type'] = array( |
| 954 | '#type' => 'select', |
| 955 | '#title' => t('Feedback Type?'), |
| 956 | '#options' => array('Positive'=>'Positive','Neutral'=>'Neutral','Negative'=>'Negative'), |
| 957 | ); |
| 958 | $form[] = array( |
| 959 | '#type' => 'submit', |
| 960 | '#value' => t('Send Feedback'), |
| 961 | ); |
| 962 | return $form; |
| 963 | } |
| 964 | |
| 965 | |
| 966 | function ebay_feedback_leave_submit($form_id, $form_values) { |
| 967 | $sp = _ebay_session(); |
| 968 | require_once 'ebatns/LeaveFeedbackRequestType.php'; |
| 969 | |
| 970 | $item = db_result(db_query('SELECT itemid FROM {ec_product_ebay} WHERE nid = %d', $form_values['nid'])); |
| 971 | $senderid = db_result(db_query('SELECT ebayuserid FROM {ec_product_ebay} WHERE nid = %d', $form_values['nid'])); |
| 972 | |
| 973 | $req = new LeaveFeedbackRequestType(); |
| 974 | $req->ItemID = $item; |
| 975 | $req->TargetUser = $senderid; |
| 976 | $req->setCommentText($form_values['ebay_content']); |
| 977 | $req->setCommentType($form_values['ebay_type']); |
| 978 | $res = $sp->LeaveFeedback($req); |
| 979 | |
| 980 | if ($res->Ack == 'Success') { |
| 981 | db_query('UPDATE {ec_product_ebay} SET sellerfb=1 WHERE nid = %d', $form_values['nid']); |
| 982 | drupal_set_message(t('Feedback %fb has been sent', array('%fb' => $form_values['nid']))); |
| 983 | } else { |
| 984 | drupal_set_message(t('Feedback could not be sent, a problem occured.')); |
| 985 | //drupal_set_message('<pre>'. print_r($req,1) .'</pre>'); |
| 986 | //drupal_set_message('<pre>'. print_r($res,1) .'</pre>'); |
| 987 | } |
| 988 | |
| 989 | return "admin/store/ebay/feedback"; |
| 990 | } |
| 991 | |
| 992 | |
| 993 | /** |
| 994 | * Receive incoming messages (notifications) from Ebay API |
| 995 | */ |
| 996 | function ebay_apirx($type='', $string='') { |
| 997 | require_once 'ebatns/EbatNs_NotificationClient.php'; |
| 998 | $handler = new EbatNs_NotificationClient(); |
| 999 | $msg = file_get_contents('php://input'); |
| 1000 | $res = $handler->getResponse($msg); |
| 1001 | |
| 1002 | /* |
| 1003 | $fp = fopen("/tmp/ebay.txt","a"); |
| 1004 | fwrite($fp,"----\n"); |
| 1005 | fwrite($fp,print_r($res,1)); |
| 1006 | fclose($fp); |
| 1007 | */ |
| 1008 | |
| 1009 | |
| 1010 | if ($res->NotificationEventName == 'AskSellerQuestion') |
| 1011 | { |
| 1012 | $q = $res->MemberMessage[0]->Question; |
| 1013 | $nid = db_result(db_query("SELECT nid FROM {ec_product_ebay} WHERE itemid='%s'", $res->MemberMessage[0]->Item->ItemID)); |
| 1014 | db_query("INSERT INTO {ec_ebay_questions} (nid,subject,body,senderid,senderemail,messageid,questiontype,messagestatus) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $nid, |
| 1015 | $q->Subject,$q->Body,$q->SenderID,$q->SenderEmail,$q->MessageID,$q->QuestionType,$res->MemberMessage[0]->MessageStatus); |
| 1016 | } |
| 1017 | elseif ($res->NotificationEventName == 'Feedback') |
| 1018 | { |
| 1019 | if ($res->FeedbackDetailArray[0]->CommentType == 'Positive') |
| 1020 | db_query("UPDATE {ec_product_ebay} SET buyerfb=1 WHERE itemid='%s'",$res->FeedbackDetailArray[0]->ItemID); |
| 1021 | } |
| 1022 | elseif ($res->NotificationEventName == 'EndOfAuction') |
| 1023 | { |
| 1024 | $nid = db_result(db_query("SELECT nid FROM {ec_product_ebay} WHERE itemid='%s'", $res->Item->ItemID)); |
| 1025 | db_query("UPDATE {node} SET status=0 WHERE nid='%d'",$nid); |
| 1026 | db_query("UPDATE {ec_product} SET price='%s' WHERE nid='%d'",$res->TransactionArray[0]->TransactionPrice->value,$nid); |
| 1027 | db_query("UPDATE {ec_product_ebay} SET ebayuserid='%s',auctionend=UNIX_TIMESTAMP() WHERE itemid='%s'",$res->TransactionArray[0]->Buyer->UserID,$res->Item->ItemID); |
| 1028 | |
| 1029 | @eregi("^(http|https):",getenv('SCRIPT_URI'),$regs); |
| 1030 | $proto = $regs[1]; |
| 1031 | if (!$proto) $proto = 'http'; |
| 1032 | $paylink = $proto .'://'. getenv('HTTP_HOST') . base_path() .'/cart/add/'. $nid; |
| 1033 | |
| 1034 | $defaultbody = "Thank you for your purchase at Drupal! Please use the following link to pay: $paylink"; |
| 1035 | $body = variable_get('ebay_nfymail_body',''); |
| 1036 | |
| 1037 | if (!$body) $body = $defaultbody; |
| 1038 | $body = ereg_replace("\{PAYLINK\}",$paylink,$body); |
| 1039 | |
| 1040 | $sp = _ebay_session(); |
| 1041 | require_once 'ebatns/AddMemberMessageAAQToPartnerRequestType.php'; |
| 1042 | $req = new AddMemberMessageAAQToPartnerRequestType(); |
| 1043 | $req->ItemID = $res->Item->ItemID; |
| 1044 | $req->MemberMessage = new MemberMessageType(); |
| 1045 | $req->MemberMessage->setRecipientID($res->TransactionArray[0]->Buyer->UserID); |
| 1046 | $req->MemberMessage->setQuestionType('Payment'); |
| 1047 | $req->MemberMessage->setSubject(variable_get('ebay_nfymail_subj','Thank you for your purchase!')); |
| 1048 | $req->MemberMessage->setBody($body); |
| 1049 | $res2 = $sp->AddMemberMessageAAQToPartner($req); |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | |
| 1054 | /** |
| 1055 | * Ebay Category Autocomplete |
| 1056 | */ |
| 1057 | function ebay_ac_category($type, $string) { |
| 1058 | switch ($type) { |
| 1059 | case 'parent': |
| 1060 | $where = '(categoryparentid = 1)'; |
| 1061 | break; |
| 1062 | |
| 1063 | case 'child': |
| 1064 | $where = '(categoryparentid != 1)'; |
| 1065 | break; |
| 1066 | |
| 1067 | default: |
| 1068 | $where = '1'; |
| 1069 | } |
| 1070 | if ((strpos($string, ',')) !== false) { |
| 1071 | $pre_string = substr($string, 0, strrpos($string, ',')+1); |
| 1072 | $string = substr($string, strrpos($string, ',')+1); |
| 1073 | } |
| 1074 | |
| 1075 | $ts_last_sync = variable_get('ebay_catsync',0); |
| 1076 | // expired, get em from ebay |
| 1077 | if (false) { |
| 1078 | //if (($ts_last_sync + (86400 * 14)) < time()) { |
| 1079 | $sp = _ebay_session(); |
| 1080 | require_once 'ebatns/GetCategoriesRequestType.php'; |
| 1081 | require_once 'ebatns/GetCategoriesResponseType.php'; |
| 1082 | require_once 'ebatns/CategoryType.php'; |
| 1083 | |
| 1084 | set_time_limit(900); |
| 1085 | $req = ne |