| [91] | 1 | <?php |
|---|
| 2 | // WCF includes |
|---|
| 3 | require_once(WCF_DIR.'lib/system/event/EventListener.class.php'); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Adds code for donation |
|---|
| 7 | * |
|---|
| 8 | * @author Torben Brodt |
|---|
| [104] | 9 | * @package de.easy-coding.wcf.code |
|---|
| [91] | 10 | * @license GNU General Public License <http://opensource.org/licenses/gpl-3.0.html> |
|---|
| 11 | */ |
|---|
| [104] | 12 | class DonationAddFormBankCode implements EventListener { |
|---|
| 13 | protected $system = 'code'; |
|---|
| 14 | protected $prefix = 'donation_code_'; |
|---|
| 15 | protected $eventObj; |
|---|
| 16 | |
|---|
| 17 | //data |
|---|
| 18 | protected $code, $message; |
|---|
| [91] | 19 | |
|---|
| 20 | /** |
|---|
| 21 | * @see EventListener::execute() |
|---|
| 22 | */ |
|---|
| 23 | public function execute($eventObj, $className, $eventName) { |
|---|
| [104] | 24 | $this->eventObj = $eventObj; |
|---|
| 25 | |
|---|
| 26 | if($this->eventObj->system != $this->system) { |
|---|
| 27 | return; |
|---|
| [91] | 28 | } |
|---|
| [104] | 29 | |
|---|
| 30 | switch($eventName) { |
|---|
| 31 | case 'readFormParameters': |
|---|
| 32 | $this->readFormParameters(); |
|---|
| 33 | break; |
|---|
| 34 | case 'assignVariables': |
|---|
| 35 | $this->assignVariables(); |
|---|
| 36 | break; |
|---|
| 37 | case 'validate': |
|---|
| 38 | $this->validate(); |
|---|
| 39 | break; |
|---|
| 40 | case 'save': |
|---|
| 41 | $this->save(); |
|---|
| 42 | break; |
|---|
| 43 | } |
|---|
| [91] | 44 | } |
|---|
| [104] | 45 | |
|---|
| 46 | /** |
|---|
| 47 | * validates code |
|---|
| 48 | * @param code |
|---|
| 49 | */ |
|---|
| 50 | protected function validateCode($code) { |
|---|
| 51 | $sql = "SELECT COUNT(*) AS c |
|---|
| 52 | FROM wcf".WCF_N."_donation_code |
|---|
| 53 | WHERE code = ".escapeString($this->code)." |
|---|
| 54 | AND userID = 0; "; |
|---|
| 55 | |
|---|
| 56 | $row = WCF::getDB()->getFirstRow($sql); |
|---|
| 57 | return empty($row['c']) ? false : true; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | * @see Form::readFormParameters() |
|---|
| 62 | */ |
|---|
| 63 | protected function readFormParameters() { |
|---|
| 64 | switch($this->eventObj->step) { |
|---|
| 65 | case 1: |
|---|
| 66 | if(isset($_POST[$this->prefix.'code'])) $this->code = $_POST[$this->prefix.'code']; |
|---|
| 67 | break; |
|---|
| 68 | case 2: |
|---|
| 69 | if(isset($_POST[$this->prefix.'message'])) $this->message = $_POST[$this->prefix.'message']; |
|---|
| 70 | break; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * @see Form::validate() |
|---|
| 76 | */ |
|---|
| 77 | protected function validate() { |
|---|
| 78 | switch($this->eventObj->step) { |
|---|
| 79 | case 1: |
|---|
| 80 | if(!$this->validateCode($this->code)) { |
|---|
| 81 | // TODO: exception |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | break; |
|---|
| 85 | case 2: |
|---|
| 86 | if(!$this->validateCode($this->code)) { |
|---|
| 87 | // TODO: exception |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | //EventListener::fireEvent($this->eventObj, 'save'); TODO: EventListener |
|---|
| 92 | break; |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | /** |
|---|
| 97 | * @see Form::save() |
|---|
| 98 | */ |
|---|
| 99 | protected function save() { |
|---|
| 100 | $sql = "UPDATE wcf".WCF_N."_donation |
|---|
| 101 | SET |
|---|
| 102 | userID = ".WCF::getUser()->userID." |
|---|
| 103 | WHERE userID = 0 |
|---|
| 104 | AND code = '".escapeString($this->message)."'; "; |
|---|
| 105 | WCF::getDB()->sendQuery($sql); |
|---|
| 106 | |
|---|
| 107 | $sql = "INSERT INTO wcf".WCF_N."_donation |
|---|
| 108 | ( |
|---|
| 109 | system, |
|---|
| 110 | timestamp, |
|---|
| 111 | userID, |
|---|
| 112 | username, |
|---|
| 113 | amount, |
|---|
| 114 | message |
|---|
| 115 | ) VALUES ( |
|---|
| 116 | 'code', |
|---|
| 117 | ".time()." |
|---|
| 118 | ".WCF::getUser()->userID.", |
|---|
| 119 | '".WCF::getUser()->username."', |
|---|
| 120 | 0.0, |
|---|
| 121 | '".escapeString($this->message)."' |
|---|
| 122 | );"; |
|---|
| 123 | |
|---|
| 124 | WCF::getDB()->sendQuery($sql); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | /** |
|---|
| 128 | * @see Page::assignVariables() |
|---|
| 129 | */ |
|---|
| 130 | protected function assignVariables() { |
|---|
| 131 | switch($this->eventObj->step) { |
|---|
| 132 | case 0: |
|---|
| 133 | WCF::getTPL()->assign(array( |
|---|
| 134 | 'donation_system' => $this->system, |
|---|
| 135 | 'donation_icon' => RELATIVE_WCF_DIR.'icon/donation_code.png', |
|---|
| 136 | 'donation_title' => WCF::getLanguage()->get('wcf.acp.option.category.donation.plugins.code'), |
|---|
| 137 | 'donation_desrciption' => WCF::getLanguage()->get('wcf.acp.option.category.donation.plugins.code.description') |
|---|
| 138 | )); |
|---|
| 139 | |
|---|
| 140 | WCF::getTPL()->append('additionalDonationSystems', WCF::getTPL()->fetch('donation_container')); |
|---|
| 141 | break; |
|---|
| 142 | case 1: |
|---|
| 143 | case 2: |
|---|
| 144 | WCF::getTPL()->append('donationSystemContainer', WCF::getTPL()->fetch('donationCode')); |
|---|
| 145 | break; |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| [91] | 148 | } |
|---|
| 149 | ?> |
|---|