~katiekitty/+junk/solidstate

« back to all changes in this revision

Viewing changes to solidstate/branches/v0.5 Alpha/modules/resellerclub/.svn/text-base/resellerclub.class.php.svn-base

  • Committer: root
  • Date: 2010-01-13 07:44:31 UTC
  • Revision ID: root@ds3-vamp.cs-monitor.cz.cc-20100113074431-kt8ceoeznpjg22x7
Reviving the project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * ResellerClub.class.php
 
4
 *
 
5
 * This file contains the definition of the ResellerClub class.
 
6
 *
 
7
 * @package resellerclub
 
8
 * @author John Diamond <jdiamond@solid-state.org>
 
9
 * @copyright John Diamond <jdiamond@solid-state.org>
 
10
 * @license http://www.opensource.org/licenses/gpl-license.php GNU Public License
 
11
 */
 
12
 
 
13
// Base class
 
14
require_once BASE_PATH . "modules/RegistrarModule.class.php";
 
15
 
 
16
/**
 
17
 * ResellerClub
 
18
 *
 
19
 * Provides a wrapper for the Reseller Club API library.
 
20
 *
 
21
 * @package resellerclub
 
22
 * @author John Diamond <jdiamond@solid-state.org>
 
23
 */
 
24
class ResellerClub extends RegistrarModule
 
25
{
 
26
  /**
 
27
   * @var string Configuration page
 
28
   */
 
29
  var $configPage = "rcm_config";
 
30
 
 
31
  /**
 
32
   * @var Customer Reseller Club API Customer object
 
33
   */
 
34
  var $customer = null;
 
35
 
 
36
  /**
 
37
   * @var boolean Debug flag
 
38
   */
 
39
  var $debug = false;
 
40
 
 
41
  /**
 
42
   * @var string Default customer password
 
43
   */
 
44
  var $defaultCustomerPassword = "defaultpw";
 
45
 
 
46
  /**
 
47
   * @var DomContact Reseller Club API Domain Contact object
 
48
   */
 
49
  var $domContact = null;
 
50
 
 
51
  /**
 
52
   * @var DomOrder Reseller Club API Order object
 
53
   */
 
54
  var $domOrder = null;
 
55
 
 
56
  /**
 
57
   * @var string Module name
 
58
   */
 
59
  var $name = "resellerclub";
 
60
 
 
61
  /**
 
62
   * @var string Reseller Club language preference
 
63
   */
 
64
  var $langpref = "en";
 
65
 
 
66
  /**
 
67
   * @var string Long description
 
68
   */
 
69
  var $description = "Reseller Club Domain Registrar Module";
 
70
 
 
71
  /**
 
72
   * @var integer Parent ID
 
73
   */
 
74
  var $parentID = 999999998;
 
75
 
 
76
  /**
 
77
   * @var string Reseller Club password
 
78
   */
 
79
  var $password = "password";
 
80
 
 
81
  /**
 
82
   * @var integer Reseller ID
 
83
   */
 
84
  var $resellerID = 1;
 
85
 
 
86
  /**
 
87
   * @var string Reseller Club Role
 
88
   */
 
89
  var $role = "reseller";
 
90
 
 
91
  /**
 
92
   * @var string Short Description
 
93
   */
 
94
  var $sDescription = "Reseller Club";
 
95
 
 
96
  /**
 
97
   * @var string Service URL
 
98
   */
 
99
  var $serviceURL = "http://demo.myorderbox.com/anacreon/servlet/rpcrouter";
 
100
 
 
101
  /**
 
102
   * @var string Reseller Club Username
 
103
   */
 
104
  var $username = "user@email.com";
 
105
 
 
106
  /**
 
107
   * @var integer Version
 
108
   */
 
109
  var $version = 1;
 
110
 
 
111
  /**
 
112
   * Add a Customer
 
113
   *
 
114
   * Create a new customer at Reseller Club
 
115
   *
 
116
   * @param string $username Directi Username (an email address)
 
117
   * @param string $password Password
 
118
   * @param string $name Customer's name
 
119
   * @param string $company Customer's company
 
120
   * @param string $address1 Address line 1
 
121
   * @param string $address2 Address line 2
 
122
   * @param string $address3 Address line 3
 
123
   * @param string $city City
 
124
   * @param string $state State
 
125
   * @param string $contry Contry code
 
126
   * @param string $zip Postal code
 
127
   * @param string $telephone1 Customer's telephone (1-xxxxxxxxxx format)
 
128
   * @param string $telephone2 Customer's mobile phone (1-xxxxxxxxxx format)
 
129
   * @param string $fax Customer's fax number (1-xxxxxxxxxx format)
 
130
   * @return integer Customer ID
 
131
   */
 
132
  function addCustomer( $username,
 
133
                        $password,
 
134
                        $name,
 
135
                        $company,
 
136
                        $address1,
 
137
                        $address2,
 
138
                        $address3,
 
139
                        $city,
 
140
                        $state,
 
141
                        $country,
 
142
                        $zip,
 
143
                        $telephone1,
 
144
                        $telephone2,
 
145
                        $fax )
 
146
  {
 
147
    // Massage the data as needed
 
148
    if( empty( $company ) )
 
149
      {
 
150
        // Company can not be null
 
151
        $company = $name;
 
152
      }
 
153
 
 
154
    // Add a customer at Directi
 
155
    $telephone1 = $this->parse_phone_number( $telephone1 );
 
156
    $telephone2 = $this->parse_phone_number( $telephone2 );
 
157
    $result = $this->customer->addCustomer( $this->getUsername(),
 
158
                                            $this->getPassword(),
 
159
                                            $this->getRole(),
 
160
                                            $this->getLangPref(),
 
161
                                            $this->getParentID(),
 
162
                                            $username,
 
163
                                            $password,
 
164
                                            $name,
 
165
                                            $company,
 
166
                                            $address1,
 
167
                                            $address2,
 
168
                                            $address3,
 
169
                                            $city,
 
170
                                            $state,
 
171
                                            $country,
 
172
                                            $zip,
 
173
                                            $telephone1['cc'],
 
174
                                            $telephone1['number'],
 
175
                                            $telephone2['cc'],
 
176
                                            $telephone2['number'],
 
177
                                            "",
 
178
                                            "",
 
179
                                            "en" );
 
180
    
 
181
    if( !is_numeric( $result ) )
 
182
      {
 
183
        // Error when adding customer
 
184
        return false;
 
185
      }
 
186
 
 
187
    // Customer added
 
188
    return true;
 
189
  }
 
190
  
 
191
  /**
 
192
   * Add or Edit a Reseller Club Contact Record
 
193
   *
 
194
   * Add a new contact record at Reseller Club, or if it already exists, update it.
 
195
   *
 
196
   * @param integer $customer_id The customer who this contact belongs to
 
197
   * @param ContactDBO $contactDBO Contact DBO
 
198
   * @return integer Directi Contact ID
 
199
   */
 
200
  function addOrEditContact( $customerID, $contactDBO )
 
201
  {
 
202
    if( empty( $contactDBO->getBusinessName ) )
 
203
      {
 
204
        // If no company is provided, set company field to contact name
 
205
        $contactDBO->setBusinessName( $contactDBO->getName() );
 
206
      }
 
207
 
 
208
    // Find out if this contact already exists
 
209
    $contactID = -1;
 
210
    $contacts = $this->domContact->listNames( $this->getUsername(),
 
211
                                              $this->getPassword(),
 
212
                                              $this->getRole(),
 
213
                                              $this->getLangPref(),
 
214
                                              $this->getParentID(),
 
215
                                              $customerID );
 
216
    if( $contacts != null )
 
217
      {
 
218
        foreach( $contacts as $key => $data )
 
219
          {
 
220
            if( is_numeric( $key ) )
 
221
              {
 
222
                if( $data['company'] == $contactDBO->getBusinessName() && 
 
223
                    $data['name'] == $contactDBO->getName() )
 
224
                  {
 
225
                    // Contact already exists
 
226
                    $contactID = $data['contactid'];
 
227
                    break;
 
228
                  }
 
229
              }
 
230
          }
 
231
      }
 
232
 
 
233
    if( $contactID > 0 )
 
234
      {
 
235
        // Update contact
 
236
        $phone = $this->parse_phone_number( $contactDBO->getPhone() );
 
237
        $fax = $this->parse_phone_number( $contactDBO->getFax() );
 
238
        $result = $this->domContact->mod( $this->getUsername(),
 
239
                                          $this->getPassword(),
 
240
                                          $this->getRole(),
 
241
                                          $this->getLangPref(),
 
242
                                          $this->getParentID(),
 
243
                                          $contactID,
 
244
                                          $contactDBO->getName(),
 
245
                                          $contactDBO->getBusinessName(),
 
246
                                          $contactDBO->getEmail(),
 
247
                                          $contactDBO->getAddress1(),
 
248
                                          $contactDBO->getAddress2(),
 
249
                                          $contactDBO->getAddress3(),
 
250
                                          $contactDBO->getCity(),
 
251
                                          $contactDBO->getState(),
 
252
                                          $contactDBO->getCountry(),
 
253
                                          $contactDBO->getPostalCode(),
 
254
                                          $phone['cc'],
 
255
                                          $phone['number'],
 
256
                                          $fax['cc'],
 
257
                                          $fax['number'] );
 
258
        if( $result['status'] != "Success" )
 
259
          {
 
260
            print_r( $result );
 
261
            fatal_error( "ResellerClub::addOrEditContact()", 
 
262
                         "could not modify contact for domain registration at Reseller Club!" );
 
263
          }
 
264
      }
 
265
    else
 
266
      {
 
267
        // Add contact
 
268
        $phone = $this->parse_phone_number( $contactDBO->getPhone() );
 
269
        $fax = $this->parse_phone_number( $contactDBO->getFax() );
 
270
        $contact_id = 
 
271
          $this->domContact->addContact( $this->getUsername(),
 
272
                                         $this->getPassword(),
 
273
                                         $this->getRole(),
 
274
                                         $this->getLangPref(),
 
275
                                         $this->getParentID(),
 
276
                                         $contactDBO->getName(),
 
277
                                         $contactDBO->getBusinessName(),
 
278
                                         $contactDBO->getEmail(),
 
279
                                         $contactDBO->getAddress1(),
 
280
                                         $contactDBO->getAddress2(),
 
281
                                         $contactDBO->getAddress3(),
 
282
                                         $contactDBO->getCity(),
 
283
                                         $contactDBO->getState(),
 
284
                                         $contactDBO->getCountry(),
 
285
                                         $contactDBO->getPostalCode(),
 
286
                                         $phone['cc'],
 
287
                                         $phone['number'],
 
288
                                         $fax['cc'],
 
289
                                         $fax['number'],
 
290
                                         $customerID );
 
291
        if( !is_numeric( $contactID ) )
 
292
          {
 
293
            fatal_error( "RegistrarDirecti::add_edit_contact()", 
 
294
                         "could not add contact for domain registration at Directi!" );
 
295
          }
 
296
      }
 
297
 
 
298
    return $contactID;
 
299
  }
 
300
 
 
301
  /**
 
302
   * Check Domain Availability
 
303
   *
 
304
   * @return boolean True if the domain is available to be registered
 
305
   */
 
306
  function checkAvailability( $fqdn )
 
307
  {
 
308
    $this->checkEnabled();
 
309
 
 
310
    // Check domain name availability
 
311
    $result = $this->domOrder->checkAvailability( $this->getUsername(),
 
312
                                                  $this->getPassword(),
 
313
                                                  $this->getRole(),
 
314
                                                  $this->getLangPref(),
 
315
                                                  $this->getParentID(),
 
316
                                                  $fqdn,
 
317
                                                  false );
 
318
 
 
319
    if( !isset( $result[$fqdn] ) )
 
320
      {
 
321
        throw new RegistrarException( "[RESELLER_CLUB_NO_DATA_RETURNED]." );
 
322
      }
 
323
 
 
324
    return $result[$fqdn]['status'] == "available";
 
325
  }
 
326
 
 
327
  /**
 
328
   * Get Debug Flag
 
329
   *
 
330
   * @return boolean Debug flag
 
331
   */
 
332
  function getDebug() { return $this->debug; }
 
333
 
 
334
  /**
 
335
   * Get Default Customer Password
 
336
   *
 
337
   * @return string Default customer password
 
338
   */
 
339
  function getDefaultCustomerPassword() { return $this->defaultCustomerPassword; }
 
340
 
 
341
  /**
 
342
   * Get Language Preference
 
343
   *
 
344
   * @return string Language preference
 
345
   */
 
346
  function getLangPref() { return $this->langpref; }
 
347
 
 
348
  /**
 
349
   * Get Parent ID
 
350
   *
 
351
   * @return integer Parent ID
 
352
   */
 
353
  function getParentID() { return $this->parentID; }
 
354
 
 
355
  /**
 
356
   * Get Password
 
357
   *
 
358
   * @return string Password
 
359
   */
 
360
  function getPassword() { return $this->password; }
 
361
 
 
362
  /**
 
363
   * Get Reseller ID
 
364
   *
 
365
   * @return integer Reseller ID
 
366
   */
 
367
  function getResellerID() { return $this->resellerID; }
 
368
 
 
369
  /**
 
370
   * Get Role
 
371
   *
 
372
   * @return string Role
 
373
   */
 
374
  function getRole() { return $this->role; }
 
375
 
 
376
  /**
 
377
   * Get Service URL
 
378
   *
 
379
   * @return string Service URL
 
380
   */
 
381
  function getServiceURL() { return $this->serviceURL; }
 
382
 
 
383
  /**
 
384
   * Get Username
 
385
   *
 
386
   * @return string Username
 
387
   */
 
388
  function getUsername() { return $this->username; }
 
389
 
 
390
  /**
 
391
   * Initialize Reseller Club Module
 
392
   *
 
393
   * Invoked when the module is loaded.  Call the parent method first, then
 
394
   * load settings.
 
395
   */
 
396
  function init()
 
397
  {
 
398
    parent::init();
 
399
 
 
400
    // Load settings
 
401
    $this->setDebug( $this->moduleDBO->loadSetting( "debug" ) );
 
402
    $this->setLangPref( $this->moduleDBO->loadSetting( "langpref" ) );
 
403
    $this->setParentID( $this->moduleDBO->loadSetting( "parentid" ) );
 
404
    $this->setUsername( $this->moduleDBO->loadSetting( "username" ) );
 
405
    $this->setPassword( $this->moduleDBO->loadSetting( "password" ) );
 
406
    $this->setResellerID( $this->moduleDBO->loadSetting( "resellerid" ) );
 
407
    $this->setRole( $this->moduleDBO->loadSetting( "role" ) );
 
408
    $this->setServiceURL( $this->moduleDBO->loadSetting( "serviceurl" ) );
 
409
        
 
410
    if( $this->isEnabled() )
 
411
      {
 
412
        // Reseller Club API
 
413
        require BASE_PATH . "modules/resellerclub/lib/domorder.class.php";
 
414
        require BASE_PATH . "modules/resellerclub/lib/customer.class.php";
 
415
        require BASE_PATH . "modules/resellerclub/lib/domcontact.class.php";
 
416
 
 
417
        // Create Reseller Club objects
 
418
        $this->domOrder = 
 
419
          new DomOrder( BASE_PATH . "modules/resellerclub/lib/wsdl/domain.wsdl" );
 
420
        $this->customer = 
 
421
          new Customer( BASE_PATH . "modules/resellerclub/lib/wsdl/customer.wsdl" );
 
422
        $this->domContact = 
 
423
          new DomContact( BASE_PATH . "modules/resellerclub/lib/wsdl/domaincontact.wsdl" );
 
424
      }
 
425
  }
 
426
 
 
427
  /**
 
428
   * Install Reseller Club Module
 
429
   *
 
430
   * Invoked when the module is installed.  Calls the parent first, which does
 
431
   * most of the work, then saves the default settings to the DB.
 
432
   */
 
433
  function install()
 
434
  {
 
435
    parent::install();
 
436
    $this->saveSettings();
 
437
  }
 
438
 
 
439
  /**
 
440
   * Verify Domain is Transfer Eligible
 
441
   *
 
442
   * @param string $fqdn Domain name
 
443
   * @return boolean True if the domain is transfer eligible
 
444
   */
 
445
  function isTransferable( $fqdn )
 
446
  {
 
447
    $this->checkEnabled();
 
448
 
 
449
    // Check domain name availability
 
450
    $result = $this->domOrder->checkAvailability( $this->getUsername(),
 
451
                                                  $this->getPassword(),
 
452
                                                  $this->getRole(),
 
453
                                                  $this->getLangPref(),
 
454
                                                  $this->getParentID(),
 
455
                                                  $fqdn,
 
456
                                                  false );
 
457
 
 
458
    if( !isset( $result[$fqdn] ) )
 
459
      {
 
460
        throw new RegistrarException( "[RESELLER_CLUB_NO_DATA_RETURNED]." );
 
461
      }
 
462
 
 
463
    // Transferable rules:
 
464
    //  * The domain must not be available
 
465
    //  * The domain must not be registered through us
 
466
    return !($result[$fqdn]['status'] == "available" ||
 
467
             $result[$fqdn]['status'] == "regthroughus");
 
468
  }
 
469
 
 
470
  /**
 
471
   * Parse Phone Number
 
472
   *
 
473
   * Parse a SolidWorks phone number for use with Reseller Club
 
474
   *
 
475
   * @param string $phoneNumber A solidstate phone number (+x-xxxxxxxxxx)
 
476
   * @return array Phone number components ('CC' and 'number')
 
477
   */
 
478
  protected function parse_phone_number( $phoneNumber )
 
479
  {
 
480
    $components = explode( "-", $phoneNumber );
 
481
    $result['cc'] = intval( $components[0] );
 
482
    $result['number'] = $components[1];
 
483
 
 
484
    return $result;
 
485
  }
 
486
 
 
487
  /**
 
488
   * Prepare Customer and Contacts
 
489
   *
 
490
   * Queries the customer ID, or creates a new customer if necessary.  Then adds
 
491
   * or edits the contacts as necessary.
 
492
   *
 
493
   * @param array $contacts An array of ContactDBO's
 
494
   * @param AccountDBO $accountDBO The account DBO
 
495
   * @return array ID's in an associative array with keys: customerid, adminid, techid, billingid
 
496
   */
 
497
  function prepareCustomerContacts( $contacts, $accountDBO )
 
498
  {
 
499
    // Reseller Club uses e-mail addresses as customer usernames
 
500
    $customer = $accountDBO->getContactEmail();
 
501
 
 
502
    // Query the customer's ID
 
503
    if( !( $customerID = $this->queryCustomerID( $customer ) ) )
 
504
      {
 
505
        // Add a new customer
 
506
        if( !($customerID = $this->addCustomer( $accountDBO->getContactEmail(),
 
507
                                                $this->getDefaultCustomerPassword(),
 
508
                                                $accountDBO->getContactName(),
 
509
                                                $accountDBO->getBusinessName(),
 
510
                                                $accountDBO->getAddress1(),
 
511
                                                $accountDBO->getAddress2(),
 
512
                                                null,
 
513
                                                $accountDBO->getCity(),
 
514
                                                $accountDBO->getState(),
 
515
                                                $accountDBO->getCountry(),
 
516
                                                $accountDBO->getPostalCode(),
 
517
                                                $accountDBO->getPhone(),
 
518
                                                $accountDBO->getMobilePhone(),
 
519
                                                $accountDBO->getFax() ) ) )
 
520
          {
 
521
            fatal_error( "ResellerClub::registerNewDomain()",
 
522
                         "There was an error when trying to add a new Reseller Club customer" );
 
523
          }
 
524
      }
 
525
 
 
526
    // Enter Admin contact
 
527
    $adminID = $this->addOrEditContact( $customerID, $contacts['admin'] );
 
528
    if( !is_numeric( $adminID ) || $adminID < 0 )
 
529
      {
 
530
        fatal_error( "ResellerClub::registerDomain", 
 
531
                     "could not add Admin contact for domain registration at Reseller Club!" );
 
532
      }
 
533
 
 
534
    // Enter Technical contact
 
535
    $techID = $this->addOrEditContact( $customerID, $contacts['tech'] );
 
536
    if( !is_numeric( $techID ) || $techID < 0 )
 
537
      {
 
538
        fatal_error( "ResellerClub::registerDomain",
 
539
                     "could not add Tech contact for domain registration at Reseller Club!" );
 
540
      }
 
541
 
 
542
    // Enter Billing contact
 
543
    $billingID = $this->addOrEditContact( $customerID, $contacts['billing'] );
 
544
    if( !is_numeric( $billingID )  || $billingID < 0 )
 
545
      {
 
546
        fatal_error( "ResellerClub::registerDomain",
 
547
                     "could not add Billing contact for domain registration at Reseller Club!" );
 
548
      }
 
549
 
 
550
    return array( "customerid" => $customerID,
 
551
                  "adminid" => $adminID,
 
552
                  "techid" => $techID,
 
553
                  "billingid" => $billingID );
 
554
  }
 
555
 
 
556
  /**
 
557
   * Register a New Domain
 
558
   *
 
559
   * Registers a new domain name without requiring any Reseller Club specific
 
560
   * information.
 
561
   *
 
562
   * @param string $domainName Domain name to be registered (without TLD)
 
563
   * @param string $TLD Domain TLD to register
 
564
   * @param integer $term Number of years to register the domain for
 
565
   * @param array $contacts Admin, billing, and technical contact DBOs
 
566
   * @param AccountDBO $accountDBO The account that is registering this domain
 
567
   */
 
568
  function registerNewDomain( $domainName, $TLD, $term, $contacts, $accountDBO )
 
569
  {
 
570
    global $conf;
 
571
 
 
572
    // Make sure this module is enabled
 
573
    $this->checkEnabled();
 
574
 
 
575
    // Prepare customer and contacts, get IDs
 
576
    $ids = $this->prepareCustomerContacts( $contacts, $accountDBO );
 
577
 
 
578
    // Register Domain
 
579
    $fqdn = sprintf( "%s.%s", $domainName, $TLD );
 
580
    $results = $this->domOrder->registerDomain( $this->getUsername(),
 
581
                                                $this->getPassword(),
 
582
                                                $this->getRole(),
 
583
                                                $this->getLangPref(),
 
584
                                                $this->getParentID(),
 
585
                                                array( $fqdn => "{$term}" ),
 
586
                                                $conf['dns']['nameservers'],
 
587
                                                $ids['adminid'],
 
588
                                                $ids['adminid'],
 
589
                                                $ids['techid'],
 
590
                                                $ids['billingid'],
 
591
                                                $ids['customerid'],
 
592
                                                "NoInvoice" );
 
593
 
 
594
    if( $results[$fqdn]['status'] != "Success" )
 
595
      {
 
596
        // Error
 
597
        throw new RegistrarException( "[RESELLER_CLUB_FAILED_TO_REGISTER]: " . 
 
598
                                      var_export( $results ) );
 
599
      }
 
600
  }
 
601
 
 
602
  /**
 
603
   * Renew a Domain
 
604
   *
 
605
   * @param DomainServicePurchaseDBO $purchseDBO The domain to be renewed
 
606
   * @param integer $renewTerms Number of years to renew for
 
607
   */
 
608
  function renewDomain( $purchaseDBO, $renewTerms )
 
609
  {
 
610
    $this->checkEnabled();
 
611
    $fqdn = $purchaseDBO->getFullDomainName();
 
612
 
 
613
    // Query the Reseller Club domain record
 
614
    if( !($domainRecord = $this->queryDomainRecord( $fqdn )) )
 
615
      {
 
616
        // Domain record not found at Reseller Club
 
617
        return false;
 
618
      }
 
619
 
 
620
    // Renew the domain (note: noofyears must be passed as a string)
 
621
    $request = array( $fqdn => array( "entityid" => $domainRecord['entity.entityid'],
 
622
                                      "noofyears" => sprintf( "%d", $renewTerms ),
 
623
                                      "expirydate" => $domainRecord['orders.endtime'] ) );
 
624
    if( !($result = $this->domOrder->renewDomain( $this->getUsername(),
 
625
                                                  $this->getPassword(),
 
626
                                                  $this->getRole(),
 
627
                                                  $this->getLangPref(),
 
628
                                                  $this->getParentID(),
 
629
                                                  $request,
 
630
                                                  "NoInvoice" ) ) )
 
631
      {
 
632
        throw new RegistrarException( "Unexpected return value from DomOrder::renewDomain()!" );
 
633
      }
 
634
    if( !$result[$fqdn]['actionstatus'] == "Success" )
 
635
      {
 
636
        // Error
 
637
        throw new RegistrarException( "[RESELLER_CLUB_FAILED_TO_RENEW]: " . 
 
638
                                      $result['actionstatusdesc'] );
 
639
      }
 
640
  }
 
641
 
 
642
  /**
 
643
   * Query Reseller Club Customer ID
 
644
   *
 
645
   * Given the customer's username (an e-mail address), query the customer's ID
 
646
   * from Reseller Club
 
647
   *
 
648
   * @param string $username Customer's username (an e-mail address)
 
649
   * @return integer Customer ID, or null
 
650
   */
 
651
  function queryCustomerID( $username )
 
652
  {
 
653
    $result = $this->customer->listOrder( $this->getUsername(),
 
654
                                          $this->getPassword(),
 
655
                                          $this->getRole(),
 
656
                                          $this->getLangPref(),
 
657
                                          $this->getParentID(),
 
658
                                          null,
 
659
                                          $this->getResellerID(),
 
660
                                          $username,
 
661
                                          null,
 
662
                                          null,
 
663
                                          null,
 
664
                                          null,
 
665
                                          null,
 
666
                                          null,
 
667
                                          null,
 
668
                                          null,
 
669
                                          null,
 
670
                                          10,
 
671
                                          1,
 
672
                                          null );
 
673
    
 
674
    if( $result['recsindb'] > 1 )
 
675
      {
 
676
        fatal_error( "ResellerClub::queryCustomerID()",
 
677
                     "Customer::list() returned unexpected results" );
 
678
      }
 
679
 
 
680
    return $result[1]["customer.customerid"];
 
681
  }
 
682
 
 
683
  /**
 
684
   * Query Reseller Club Domain Record
 
685
   *
 
686
   * Given a domain name, query the order record stored at Reseller Club
 
687
   *
 
688
   * @param string $fqdn Domain name
 
689
   * @return array Reseller Club's domain record
 
690
   */
 
691
  function queryDomainRecord( $fqdn )
 
692
  {
 
693
    // Query the domain
 
694
    $result = $this->domOrder->listOrder( $this->getUsername(),
 
695
                                          $this->getPassword(),
 
696
                                          $this->getRole(),
 
697
                                          $this->getLangPref(),
 
698
                                          $this->getParentID(),
 
699
                                          null,
 
700
                                          $this->getResellerID(),
 
701
                                          null,
 
702
                                          true,
 
703
                                          null,
 
704
                                          null,
 
705
                                          null,
 
706
                                          null,
 
707
                                          null,
 
708
                                          null,
 
709
                                          null,
 
710
                                          100,
 
711
                                          1,
 
712
                                          null );
 
713
    if( !is_array( $result ) )
 
714
      {
 
715
        fatal_error( "ResellerClub::queryDomainRecord()",
 
716
                     "Unexpected result from domOrder::listOrder()!" );
 
717
      }
 
718
                                          
 
719
    // Search the list for the domain name
 
720
    foreach( $result as $key => $domainData )
 
721
      {
 
722
        if( is_array( $domainData ) && $domainData['entity.description'] == $fqdn )
 
723
          {
 
724
            // Domain record found
 
725
            return $domainData;
 
726
          }
 
727
      }
 
728
 
 
729
    // Could not find domain record
 
730
    return false;
 
731
  }
 
732
 
 
733
  /**
 
734
   * Save Reseller Club Settings
 
735
   */
 
736
  function saveSettings()
 
737
  {
 
738
    // Save default settings
 
739
    $this->moduleDBO->saveSetting( "debug", 
 
740
                                   $this->getDebug() == null ? 0 : $this->getDebug() );
 
741
    $this->moduleDBO->saveSetting( "defaultcustomerpassword", $this->getDefaultCustomerPassword() );
 
742
    $this->moduleDBO->saveSetting( "langpref", $this->getLangPref() );
 
743
    $this->moduleDBO->saveSetting( "parentid", $this->getParentID() );
 
744
    $this->moduleDBO->saveSetting( "username", $this->getUsername() );
 
745
    $this->moduleDBO->saveSetting( "password", $this->getPassword() );
 
746
    $this->moduleDBO->saveSetting( "resellerid", $this->getResellerID() );
 
747
    $this->moduleDBO->saveSetting( "role", $this->getRole() );
 
748
    $this->moduleDBO->saveSetting( "serviceurl", $this->getServiceURL() );
 
749
  }
 
750
 
 
751
  /**
 
752
   * Set Debug Flag
 
753
   *
 
754
   * @param boolean $debug Debug flag
 
755
   */
 
756
  function setDebug( $debug ) 
 
757
  { 
 
758
    global $debugfunction;
 
759
 
 
760
    $this->debug = $debug; 
 
761
 
 
762
    // Reseller Club API Global var
 
763
    $debugfunction = ($debug == true);
 
764
  }
 
765
 
 
766
  /**
 
767
   * Set Default Customer Password
 
768
   *
 
769
   * @param string $password Default customer password
 
770
   */
 
771
  function setDefaultCustomerPassword( $password )
 
772
  {
 
773
    $this->defaultCustomerPassword = $password;
 
774
  }
 
775
 
 
776
  /**
 
777
   * Set Language Preference
 
778
   *
 
779
   * @param string $langpref Language preference
 
780
   */
 
781
  function setLangPref( $langpref ) { $this->langpref = $langpref; }
 
782
 
 
783
  /**
 
784
   * Set Parent ID
 
785
   *
 
786
   * @param integer $parentid Parent ID
 
787
   */
 
788
  function setParentID( $parentID ) { $this->parentID = $parentID; }
 
789
 
 
790
  /**
 
791
   * Set Password
 
792
   *
 
793
   * @param string $password Password
 
794
   */
 
795
  function setPassword( $password ) { $this->password = $password; }
 
796
 
 
797
  /**
 
798
   * Set Reseller ID
 
799
   *
 
800
   * @return integer $resellerID Reseller ID
 
801
   */
 
802
  function setResellerID( $resellerID ) { $this->resellerID = $resellerID; }
 
803
 
 
804
  /**
 
805
   * Set Role
 
806
   *
 
807
   * @param string $role Role
 
808
   */
 
809
  function setRole( $role ) { $this->role = $role; }
 
810
 
 
811
  /**
 
812
   * Set Service URL
 
813
   *
 
814
   * @param string $serviceURL Service URL
 
815
   */
 
816
  function setServiceURL( $serviceURL ) 
 
817
  { 
 
818
    global $serviceurl;
 
819
 
 
820
    $this->serviceURL = $serviceURL; 
 
821
 
 
822
    // Reseller Club API Global variable
 
823
    $serviceurl = $serviceURL;
 
824
  }
 
825
 
 
826
  /**
 
827
   * Set Username
 
828
   *
 
829
   * @param string $username Username
 
830
   */
 
831
  function setUsername( $username ) { $this->username = $username; }
 
832
 
 
833
  /**
 
834
   * Transfer a Domain
 
835
   *
 
836
   * @param string $domainName Domain name to be transferred (without TLD)
 
837
   * @param string $TLD Domain TLD
 
838
   * @param integer $term Number of years to renew domain for
 
839
   * @param string $secret The domain secret
 
840
   * @param array An associative array of ContactDBO's (admin, billing, and tech)
 
841
   * @param AccountDBO $accountDBO The account that is transferring this domain
 
842
   * @return boolean True for success
 
843
   */
 
844
  function transferDomain( $domainName, $TLD, $term, $secret, $contacts, $accountDBO )
 
845
  {
 
846
    global $conf;
 
847
 
 
848
    // Make sure this module is enabled
 
849
    $this->checkEnabled();
 
850
 
 
851
    // Prepare customer and contacts, get IDs
 
852
    $ids = $this->prepareCustomerContacts( $contacts, $accountDBO );
 
853
 
 
854
    // Send transfer request to Reseller Club
 
855
    $fqdn = sprintf( "%s.%s", $domainName, $TLD );
 
856
    $result = $this->domOrder->transferDomain( $this->getUsername(),
 
857
                                               $this->getPassword(),
 
858
                                               $this->getRole(),
 
859
                                               $this->getLangPref(),
 
860
                                               $this->getParentID(),
 
861
                                               array( $fqdn => $secret ),
 
862
                                               $ids['adminid'],
 
863
                                               $ids['adminid'],
 
864
                                               $ids['techid'],
 
865
                                               $ids['billingid'],
 
866
                                               $ids['customerid'],
 
867
                                               "NoInvoice" );
 
868
    if( $result[$fqdn]['status'] != "Success" )
 
869
      {
 
870
        // Error
 
871
        throw new RegistrarException( "[RESELLER_CLUB_FAILED_TO_TRANSFER]: " . 
 
872
                                      $result[$fqdn]['actionstatusdesc'] );
 
873
      }
 
874
  }
 
875
}
 
876
?>
 
 
b'\\ No newline at end of file'