| 1 | <?php |
|---|
| 2 | // WCF includes |
|---|
| 3 | require_once(WCF_DIR.'lib/system/event/EventListener.class.php'); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Adds abstract listener for donation |
|---|
| 7 | * |
|---|
| 8 | * @author Torben Brodt |
|---|
| 9 | * @package de.easy-coding.wcf.donation |
|---|
| 10 | * @license GNU General Public License <http://opensource.org/licenses/gpl-3.0.html> |
|---|
| 11 | */ |
|---|
| 12 | class DonationAddFormAbstractListener implements EventListener { |
|---|
| 13 | protected $eventObj, $className; |
|---|
| 14 | |
|---|
| 15 | protected $icon, $templateName, $system=''; |
|---|
| 16 | |
|---|
| 17 | //data |
|---|
| 18 | protected $arr = array(); |
|---|
| 19 | protected $data = array(); |
|---|
| 20 | protected $plugindata = array(); |
|---|
| 21 | protected $username = ''; |
|---|
| 22 | protected $message = ''; |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * @see EventListener::execute() |
|---|
| 26 | */ |
|---|
| 27 | public function execute($eventObj, $className, $eventName) { |
|---|
| 28 | $this->eventObj = $eventObj; |
|---|
| 29 | $this->className = $className; |
|---|
| 30 | |
|---|
| 31 | if($this->eventObj->system != '' && $this->eventObj->system != $this->system) { |
|---|
| 32 | return; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | switch($eventName) { |
|---|
| 36 | case 'assignVariables': |
|---|
| 37 | $this->assignVariables(); |
|---|
| 38 | break; |
|---|
| 39 | case 'readData': |
|---|
| 40 | $this->readData(); |
|---|
| 41 | break; |
|---|
| 42 | case 'validate': |
|---|
| 43 | $this->validate(); |
|---|
| 44 | break; |
|---|
| 45 | case 'readFormParameters': |
|---|
| 46 | $this->readFormParameters(); |
|---|
| 47 | break; |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /** |
|---|
| 52 | * @see Page::readData() |
|---|
| 53 | */ |
|---|
| 54 | protected function readData() { |
|---|
| 55 | $arr = array_merge($this->arr, array('option_autogroupjoin_enable', 'option_autogroupjoin_groupid', 'option_benefits')); |
|---|
| 56 | $sql = "SELECT optionName, |
|---|
| 57 | optionValue |
|---|
| 58 | FROM wcf".WCF_N."_donation_option |
|---|
| 59 | WHERE optionName IN ('".implode("','", $arr)."'); "; |
|---|
| 60 | |
|---|
| 61 | // query |
|---|
| 62 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 63 | while ($row = WCF::getDB()->fetchArray($result)) { |
|---|
| 64 | $name = $row['optionName']; |
|---|
| 65 | $this->data[$name] = $row['optionValue']; |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | /** |
|---|
| 70 | * @see Page::assignVariables() |
|---|
| 71 | */ |
|---|
| 72 | protected function assignVariables() { |
|---|
| 73 | WCF::getTPL()->assign($this->data); |
|---|
| 74 | |
|---|
| 75 | WCF::getTPL()->assign(array( |
|---|
| 76 | 'donation_system' => $this->system, |
|---|
| 77 | 'donation_icon' => RELATIVE_WCF_DIR.'icon/'.$this->icon, |
|---|
| 78 | 'donation_title' => WCF::getLanguage()->get('wcf.donation.category.donation.plugins.'.$this->system), |
|---|
| 79 | 'donation_description' => WCF::getLanguage()->get('wcf.donation.category.donation.plugins.'.$this->system.'.description') |
|---|
| 80 | )); |
|---|
| 81 | |
|---|
| 82 | if($this->eventObj->step == 0) { |
|---|
| 83 | WCF::getTPL()->append('additionalDonationSystems', WCF::getTPL()->fetch('donation_container')); |
|---|
| 84 | } else { |
|---|
| 85 | WCF::getTPL()->append('donationSystemContainer', WCF::getTPL()->fetch($this->templateName)); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | /** |
|---|
| 90 | * @see Form::validate() |
|---|
| 91 | */ |
|---|
| 92 | protected function validate() { |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | /** |
|---|
| 96 | * @see Form::readFormParameters() |
|---|
| 97 | */ |
|---|
| 98 | protected function readFormParameters() { |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | /** |
|---|
| 102 | * saves donation |
|---|
| 103 | */ |
|---|
| 104 | protected function save($timestamp=null) { |
|---|
| 105 | if(WCF::getUser()->userID > 0) { |
|---|
| 106 | $this->username = WCF::getUser()->username; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | if($timestamp === null) { |
|---|
| 110 | $timestamp = time(); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | $sql = "INSERT INTO wcf".WCF_N."_donation |
|---|
| 114 | (system, timestamp, userID, username, plugindata, message) |
|---|
| 115 | VALUES ( |
|---|
| 116 | '".escapeString($this->system)."', |
|---|
| 117 | ".intval($timestamp).", |
|---|
| 118 | ".intval(WCF::getUser()->userID).", |
|---|
| 119 | '".escapeString($this->username)."', |
|---|
| 120 | '".serialize($this->plugindata)."', |
|---|
| 121 | '".escapeString($this->message)."' |
|---|
| 122 | ) "; |
|---|
| 123 | |
|---|
| 124 | WCF::getDB()->sendQuery($sql); |
|---|
| 125 | |
|---|
| 126 | // add user to group |
|---|
| 127 | if(WCF::getUser()->userID > 0 && $this->data['option_autogroupjoin_enable'] && $this->data['option_autogroupjoin_groupid']) { |
|---|
| 128 | $sql = "INSERT INTO wcf".WCF_N."_user_to_groups |
|---|
| 129 | (userID, groupID) |
|---|
| 130 | VALUES ( |
|---|
| 131 | ".WCF::getUser()->userID.", |
|---|
| 132 | ".$this->data['option_autogroupjoin_groupid']." |
|---|
| 133 | )"; |
|---|
| 134 | |
|---|
| 135 | WCF::getDB()->sendQuery($sql); |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | ?> |
|---|