Guest User

Untitled

a guest
Apr 16th, 2018
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.17 KB | None | 0 0
  1. <?php
  2. require_once('lib/AbstractEntity.class.php');
  3.  
  4. class Client extends AbstractEntity {
  5.  
  6. /** @var int accountNumber */
  7. var $accountNumber = null;
  8. /** @var string company */
  9. var $company = null;
  10. /** @var int industryId */
  11. var $industryId = null;
  12. /** @var string firstName */
  13. var $firstName = null;
  14. /** @var string lastName */
  15. var $lastName = null;
  16. /** @var string address1 */
  17. var $address1 = null;
  18. /** @var string address2 */
  19. var $address2 = null;
  20. /** @var string city */
  21. var $city = null;
  22. /** @var string state */
  23. var $state = null;
  24. /** @var string zip */
  25. var $zip = null;
  26. /** @var string country */
  27. var $country = null;
  28. /** @var string email */
  29. var $email = null;
  30. /** @var string phone */
  31. var $phone = null;
  32. /** @var string password */
  33. var $username = null;
  34. var $password = null;
  35. /** @var int salesRep */
  36. var $salesRep = null;
  37. /** @var string status */
  38. var $status = null;
  39. /** @var string string */
  40. var $string = null;
  41. var $reseller = null;
  42. var $resellerDiscount = null;
  43. var $howHeard = null;
  44.  
  45. var $cards = array();
  46. var $promo = null; //promotion object
  47. var $promoCode = null;
  48. var $referralID = null;
  49. /** @var boolean tenPercentResller */
  50. var $tenPercentResller = null;
  51. /** @var string tenPercentReferralID */
  52. var $tenPercentReferralID = null;
  53.  
  54. /* these fields are used during domain ordering, but are never saved in the DB at this point 7.8.08 NM */
  55. var $shipFirstName = null;
  56. var $shipLastName = null;
  57. var $shipCompany = null;
  58. var $shipCompanyTitle = null;
  59. var $shipAddress1 = null;
  60. var $shipAddress2 = null;
  61. var $shipCity = null;
  62. var $shipState = null;
  63. var $shipCountry = null;
  64. var $shipZip = null;
  65. var $fax = null;
  66.  
  67. var $table = 'clients';
  68. var $fields = array('id', 'accountNumber', 'company', 'industryId', 'firstName', 'lastName',
  69. 'address1', 'address2', 'city', 'state', 'zip', 'country', 'email', 'phone',
  70. 'username', 'password', 'salesRep', 'status', 'howHeard',
  71. 'string', 'reseller', 'resellerDiscount', 'promoCode', 'paypalPreferred', 'tenPercentReseller', 'tenPercentReferralID', 'referralID');
  72.  
  73. function Client($id=null){
  74. if(null != $id){
  75. $this->setString($id);
  76. //$this->abstractEntity($id);
  77. $this->setId($id);
  78. require_once(dirname(__FILE__) . '/ClientDAO.class.php');
  79. $dao = new ClientDAO();
  80. $dao->_populate($this);
  81. }
  82. }
  83.  
  84.  
  85. /**
  86. * Updates the status of this client
  87. *
  88. * @author nikita m
  89. * @param string $status the status to switch to
  90. */
  91. function updateStatus($status){
  92. require_once('lib/ClientDAO.class.php');
  93. $dao = new ClientDAO();
  94. $dao->updateStatus($status, $this);
  95. }
  96.  
  97. function getUpdateValueArray($var=null){
  98. $retArr = array();
  99. $fields = $this->getFields($var);
  100.  
  101. foreach($fields as $x => $field){
  102. if($field != 'password'){
  103. $xvar = 'get'.ucfirst($field);
  104. $retArr[] = ($this->$xvar()) ? $this->$xvar() : '';
  105. }
  106. }
  107.  
  108. return $retArr;
  109. }
  110.  
  111. function getUpdatePrepareString($var=null){
  112. $new = array();
  113. $fields = $this->getFields($var);
  114.  
  115. if(is_array($fields)){
  116. foreach($fields as $field){
  117. if($field != 'password'){
  118. $new[] = $field . ' = |';
  119. }
  120. }
  121.  
  122. return join(', ', $new);
  123. }
  124. }
  125.  
  126. /**
  127. * Updates the record information in the database. Overrides parent method.
  128. *
  129. * @author nikita m
  130. */
  131. function update(){
  132. require_once(dirname(__FILE__) . '/ClientDAO.class.php');
  133. $dao = new ClientDAO();
  134. return $dao->update($this);
  135. }
  136.  
  137. /**
  138. * Populates this object using the email
  139. *
  140. * @author nikita m
  141. */
  142. function loadFromEmail(){
  143. require_once(dirname(__FILE__) . '/ClientDAO.class.php');
  144. $dao = new ClientDAO();
  145. $this->setId($dao->getIdFromEmail($this));
  146. $dao->_populate($this);
  147. }
  148.  
  149. /**
  150. * Checks to see this object's credentials against entries in the database to see if they are valid
  151. *
  152. * @author nikita m
  153. * @return bool
  154. */
  155. function canLogin(){
  156. require_once(dirname(__FILE__) . '/ClientDAO.class.php');
  157. $dao = new ClientDAO();
  158. return $dao->canLogin($this);
  159. }
  160.  
  161. /**
  162. * Checks the object's string value against the db to see if they match. If they do,
  163. * the client is logged in, otherwise he is not
  164. *
  165. * @author nikita m
  166. * @return bool
  167. */
  168. function isLoggedIn(){
  169.  
  170. $myString = $this->getString();
  171. if(!$myString || $myString == ""){
  172. return false;
  173. }
  174. require_once(dirname(__FILE__) . '/ClientDAO.class.php');
  175. $dao = new ClientDAO();
  176. return $dao->isLoggedIn($this);
  177. }
  178.  
  179.  
  180. /**
  181. * Checks to see if the client with a given email already exists in the DB
  182. *
  183. * @author nikita m
  184. * @return bool
  185. */
  186. function exists(){
  187. require_once(dirname(__FILE__) . '/ClientDAO.class.php');
  188. $dao = new ClientDAO();
  189. return $dao->exists($this);
  190. }
  191.  
  192. /**
  193. * Convert internal military state codes into their appropriate abbreviations
  194. *
  195. * @author matt delong
  196. * @param string $state the internal state code
  197. * @return string
  198. */
  199. function convertMilitaryState($state){
  200. /*
  201. Armed Forces Africa A1 = AE
  202. Armed Forces Americas A2 = AA
  203. Armed Forces Canada A3 = AE
  204. Armed Forces Europe A4 = AE
  205. Armed Forces Middle East A5 = AE
  206. Armed Forces Pacific A6 = AP
  207. */
  208.  
  209. switch($state){
  210. case 'A1':
  211. return 'AE';
  212. break;
  213.  
  214. case 'A2':
  215. return 'AA';
  216. break;
  217.  
  218. case 'A3':
  219. return 'AE';
  220. break;
  221.  
  222. case 'A4':
  223. return 'AE';
  224. break;
  225.  
  226. case 'A5':
  227. return 'AE';
  228. break;
  229.  
  230. case 'A6':
  231. return 'AP';
  232. break;
  233.  
  234. default:
  235. return $state;
  236. }
  237. }
  238.  
  239. /** MUTATORS & ACCESSORS */
  240. function setShipFirstName($value) {
  241. $this->shipFirstName = $value;
  242. }
  243.  
  244.  
  245. function getShipFirstName() {
  246. return $this->shipFirstName;
  247. }
  248.  
  249.  
  250. function setShipLastName($value) {
  251. $this->shipLastName = $value;
  252. }
  253.  
  254.  
  255. function getShipLastName() {
  256. return $this->shipLastName;
  257. }
  258.  
  259.  
  260. function setShipCompany($value) {
  261. $this->shipCompany = $value;
  262. }
  263.  
  264.  
  265. function getShipCompany() {
  266. return $this->shipCompany;
  267. }
  268.  
  269.  
  270. function setShipCompanyTitle($value) {
  271. $this->shipCompanyTitle = $value;
  272. }
  273.  
  274.  
  275. function getShipCompanyTitle() {
  276. return $this->shipCompanyTitle;
  277. }
  278.  
  279.  
  280. function setShipAddress1($value) {
  281. $this->shipAddress1 = $value;
  282. }
  283.  
  284.  
  285. function getShipAddress1() {
  286. return $this->shipAddress1;
  287. }
  288.  
  289.  
  290. function setShipAddress2($value) {
  291. $this->shipAddress2 = $value;
  292. }
  293.  
  294.  
  295. function getShipAddress2() {
  296. return $this->shipAddress2;
  297. }
  298.  
  299.  
  300. function setShipCity($value) {
  301. $this->shipCity = $value;
  302. }
  303.  
  304.  
  305. function getShipCity() {
  306. return $this->shipCity;
  307. }
  308.  
  309.  
  310. function setShipState($value) {
  311. $this->shipState = $value;
  312. }
  313.  
  314.  
  315. function getShipState() {
  316. return $this->shipState;
  317. }
  318.  
  319.  
  320. function setShipCountry($value) {
  321. $this->shipCountry = $value;
  322. }
  323.  
  324.  
  325. function getShipCountry() {
  326. return $this->shipCountry;
  327. }
  328.  
  329.  
  330. function setShipZip($value) {
  331. $this->shipZip = $value;
  332. }
  333.  
  334.  
  335. function getShipZip() {
  336. return $this->shipZip;
  337. }
  338.  
  339.  
  340. function setFax($value) {
  341. $this->fax = $value;
  342. }
  343.  
  344.  
  345. function getFax() {
  346. return $this->fax;
  347. }
  348.  
  349.  
  350. function getHowHeard(){
  351. return $this->howHeard;
  352. }
  353.  
  354.  
  355. function setHowHeard($value){
  356. $this->howHeard = $value;
  357. }
  358.  
  359.  
  360.  
  361. /**
  362. * Sets the accountNumber
  363. *
  364. * @param int $accountNumber
  365. */
  366. function setAccountNumber ($accountNumber ){$this->accountNumber = $accountNumber ;}
  367.  
  368. /**
  369. * Gets the accountNumber
  370. *
  371. * @return int
  372. */
  373. function getAccountNumber (){return $this->accountNumber ;}
  374.  
  375. /**
  376. * Sets the company
  377. *
  378. * @param string $company
  379. */
  380. function setCompany ($company ){$this->company = $company ;}
  381.  
  382. /**
  383. * Gets the company
  384. *
  385. * @return string
  386. */
  387. function getCompany (){return $this->company ;}
  388.  
  389. /**
  390. * Sets the industryId
  391. *
  392. * @param int $industryId
  393. */
  394. function setIndustryId ($industryId ){$this->industryId = $industryId ;}
  395.  
  396. /**
  397. * Gets the industryId
  398. *
  399. * @return int
  400. */
  401. function getIndustryId (){return $this->industryId ;}
  402.  
  403. /**
  404. * Sets the firstName
  405. *
  406. * @param string $firstName
  407. */
  408. function setFirstName ($firstName ){$this->firstName = $firstName ;}
  409.  
  410. /**
  411. * Gets the firstName
  412. *
  413. * @return string
  414. */
  415. function getFirstName (){return $this->firstName ;}
  416.  
  417. /**
  418. * Sets the lastName
  419. *
  420. * @param string $lastName
  421. */
  422. function setLastName ($lastName ){$this->lastName = $lastName ;}
  423.  
  424. /**
  425. * Gets the lastName
  426. *
  427. * @return string
  428. */
  429. function getLastName (){return $this->lastName ;}
  430.  
  431. /**
  432. * Sets the address1
  433. *
  434. * @param string $address1
  435. */
  436. function setAddress1 ($address1 ){$this->address1 = $address1 ;}
  437.  
  438. /**
  439. * Gets the address1
  440. *
  441. * @return string
  442. */
  443. function getAddress1 (){return $this->address1 ;}
  444.  
  445. /**
  446. * Sets the address2
  447. *
  448. * @param string $address2
  449. */
  450. function setAddress2 ($address2 ){$this->address2 = $address2 ;}
  451.  
  452. /**
  453. * Gets the address2
  454. *
  455. * @return string
  456. */
  457. function getAddress2 (){return $this->address2 ;}
  458.  
  459. /**
  460. * Sets the city
  461. *
  462. * @param string $city
  463. */
  464. function setCity ($city ){$this->city = $city ;}
  465.  
  466. /**
  467. * Gets the city
  468. *
  469. * @return string
  470. */
  471. function getCity (){return $this->city ;}
  472.  
  473. /**
  474. * Sets the state
  475. *
  476. * @param string $state
  477. */
  478. function setState ($state ){$this->state = $state ;}
  479.  
  480. /**
  481. * Gets the state
  482. *
  483. * @return string
  484. */
  485. function getState ($convert=false){
  486. $state = $this->state;
  487.  
  488. if($convert){
  489. $state = $this->convertMilitaryState($state);
  490. }
  491. return $state;
  492.  
  493. }
  494.  
  495. /**
  496. * Sets the zip
  497. *
  498. * @param string $zip
  499. */
  500. function setZip ($zip ){$this->zip = $zip ;}
  501.  
  502. /**
  503. * Gets the zip
  504. *
  505. * @return string
  506. */
  507. function getZip (){return $this->zip ;}
  508.  
  509. /**
  510. * Sets the country
  511. *
  512. * @param string $country
  513. */
  514. function setCountry ($country ){$this->country = $country ;}
  515.  
  516. /**
  517. * Gets the country
  518. *
  519. * @return string
  520. */
  521. function getCountry (){return $this->country ;}
  522.  
  523. /**
  524. * Sets the email
  525. *
  526. * @param string $email
  527. */
  528. function setEmail ($email ){$this->email = $email ;}
  529.  
  530. /**
  531. * Gets the email
  532. *
  533. * @return string
  534. */
  535. function getEmail (){return $this->email ;}
  536.  
  537. /**
  538. * Sets the phone
  539. *
  540. * @param string $phone
  541. */
  542. function setPhone ($phone ){$this->phone = $phone ;}
  543.  
  544. /**
  545. * Gets the phone
  546. *
  547. * @return string
  548. */
  549. function getPhone (){return $this->phone ;}
  550.  
  551. /**
  552. * Sets the password
  553. *
  554. * @param string $password
  555. */
  556. function setPassword ($password ){
  557. require_once(dirname(__FILE__) . '/framework/Util.class.php');
  558. $this->password = Util::rot13($password);
  559. }
  560.  
  561. /**
  562. * Gets the password
  563. *
  564. * @return string
  565. */
  566. function getPassword (){return $this->password ;}
  567.  
  568.  
  569. function getUsername(){
  570. return $this->username;
  571. }
  572.  
  573.  
  574. function setUsername($value){
  575. $this->username = $value;
  576. }
  577.  
  578.  
  579. /**
  580. * Sets the salesRep
  581. *
  582. * @param int $salesRep
  583. */
  584. function setSalesRep ($salesRep ){$this->salesRep = $salesRep ;}
  585.  
  586. /**
  587. * Gets the salesRep
  588. *
  589. * @return int
  590. */
  591. function getSalesRep (){return $this->salesRep ;}
  592.  
  593. /**
  594. * Sets the status
  595. *
  596. * @param string $status
  597. */
  598. function setStatus ($status ){$this->status = $status ;}
  599.  
  600. /**
  601. * Gets the status
  602. *
  603. * @return string
  604. */
  605. function getStatus (){return $this->status ;}
  606.  
  607. /**
  608. * Sets the string
  609. *
  610. * @param string $string
  611. */
  612. function setString($string){$this->string = $string;}
  613.  
  614. /**
  615. * Gets the string
  616. *
  617. * @return string
  618. */
  619. function getString(){return $this->string;}
  620.  
  621.  
  622. function getStoreId(){
  623. return $this->storeId;
  624. }
  625.  
  626.  
  627. function setStoreId($value){
  628. $this->storeId = $value;
  629. }
  630.  
  631.  
  632. function getCards(){
  633. return $this->cards;
  634. }
  635.  
  636.  
  637. function addCard($card){
  638. $this->cards[] = $card;
  639. }
  640.  
  641.  
  642. function setCards($value){
  643. $this->cards = $value;
  644. }
  645.  
  646.  
  647. function _populateRunCards(){
  648. require_once(dirname(__FILE__) . '/ClientDAO.class.php');
  649. $dao = new ClientDAO();
  650. $dao->_populateRunCards($this);
  651. }
  652.  
  653.  
  654. function _populateCards(){
  655. require_once(dirname(__FILE__) . '/ClientDAO.class.php');
  656. $dao = new ClientDAO();
  657. $dao->_populateCards($this);
  658. }
  659.  
  660.  
  661. function getReseller(){
  662. return $this->reseller;
  663. }
  664.  
  665.  
  666. function setReseller($value){
  667. $this->reseller = $value;
  668. }
  669.  
  670.  
  671. function getResellerDiscount(){
  672. return $this->resellerDiscount;
  673. }
  674.  
  675.  
  676. function setResellerDiscount($value){
  677. $this->resellerDiscount = $value;
  678. }
  679.  
  680.  
  681. function getPromo(){
  682. global $request;
  683.  
  684. if($promoCode = $request->getCookie('offerCode')){
  685. require_once('lib/Promotion.class.php');
  686. $promo = new Promotion($promoCode);
  687.  
  688. if(!$promo->hasExpired()){
  689. $this->promo = $promo;
  690. return $promo;
  691. }
  692. }
  693.  
  694. return false;
  695. }
  696.  
  697.  
  698. function getPromoCode(){
  699. global $request;
  700.  
  701. if($promoCode = $request->getCookie('offerCode')){
  702. $promo = $this->getPromo();
  703.  
  704. if($promo && !$promo->hasExpired()){
  705. return $promoCode;
  706. }
  707. }
  708.  
  709. return false;
  710. }
  711.  
  712.  
  713. function setPromoCode($value){
  714. $this->promoCode = $value;
  715. }
  716.  
  717.  
  718. function getMyIpCountry(){
  719. require_once('lib/IpAddress.class.php');
  720. require_once('lib/IpLocation.class.php');
  721.  
  722. $ip = IpAddress::getMyIpAddress();
  723. $ipLocation = new IpLocation($ip);
  724. $ipLocation->lookup();
  725.  
  726. return $ipLocation->getCountry();
  727. }
  728.  
  729.  
  730. function sendSalesLead(){
  731. $body = "The following person is currently attempting/attempted to signup with Core Commerce.\n\n"
  732.  
  733. . "Name: " . $this->getName() . "\n"
  734. . "Email: " . $this->getEmail() . "\n"
  735. . "Phone: " . $this->getPhone() . "\n"
  736. . "Country: " . $this->getMyIpCountry() . "\n"
  737. . "";
  738.  
  739. $to = array();
  740. $to[] = 'steven.croft@sumeffect.com';
  741. $to[] = 'kris@sumeffect.com';
  742.  
  743. foreach($to as $email){
  744. mail($email, 'Core Commerce Signup Lead', $body, 'From: sales@corecommerce.com');
  745. }
  746. }
  747.  
  748.  
  749. function getMyName(){
  750. return $this->getFirstName() . ' ' . $this->getLastName();
  751. }
  752.  
  753.  
  754. function splitNames(){
  755. $tmp = @explode(' ', $this->getName());
  756.  
  757. if(1 == count($tmp)){
  758. $this->setFirstName($this->getName());
  759. return;
  760. }
  761.  
  762. $max = (count($tmp)-1);
  763. $this->setLastName($tmp[$max]);
  764. unset($tmp[$max]);
  765.  
  766. $this->setFirstName(@join(' ', $tmp));
  767. }
  768.  
  769.  
  770. function getPaypalPreferred(){
  771. return $this->paypalPreferred;
  772. }
  773.  
  774.  
  775. function setPaypalPreferred($value){
  776. $this->paypalPreferred = $value;
  777. }
  778.  
  779.  
  780. function setReferralID($value){
  781. $this->referralID = $value;
  782. }
  783.  
  784.  
  785. function getReferralID(){
  786. return $this->referralID;
  787. }
  788.  
  789.  
  790. function setTenPercentReseller($value){
  791. $this->tenPercentReseller = $value;
  792. }
  793.  
  794.  
  795. function getTenPercentReseller(){
  796. return $this->tenPercentReseller;
  797. }
  798.  
  799.  
  800. function setTenPercentReferralID($value){
  801. $this->tenPercentReferralID = $value;
  802. }
  803.  
  804.  
  805. function getTenPercentReferralID(){
  806. return $this->tenPercentReferralID;
  807. }
  808.  
  809.  
  810. function getSalesRepFromReferralID(){
  811. require_once(dirname(__FILE__) . '/ClientDAO.class.php');
  812.  
  813. $dao = new ClientDAO();
  814.  
  815. return $dao->getSalesRepFromReferralID($this);
  816. }
  817.  
  818.  
  819.  
  820. }
  821.  
  822. ?>
Add Comment
Please, Sign In to add comment