| 1 | <?php |
|---|
| 2 | // WCF include |
|---|
| 3 | require_once(WCF_DIR.'lib/system/event/EventListener.class.php'); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * links two user profile options with an ajax request |
|---|
| 7 | * |
|---|
| 8 | * @author Torben Brodt |
|---|
| 9 | * @license GNU General Public License <http://opensource.org/licenses/gpl-3.0.html> |
|---|
| 10 | * @package de.easy-coding.wcf.optiondependency |
|---|
| 11 | */ |
|---|
| 12 | class UserProfileEditOptionDependencyListener implements EventListener { |
|---|
| 13 | protected $eventObj; |
|---|
| 14 | protected $className; |
|---|
| 15 | |
|---|
| 16 | protected $optionDependencies = array(); |
|---|
| 17 | |
|---|
| 18 | /** |
|---|
| 19 | * @see EventListener::execute() |
|---|
| 20 | */ |
|---|
| 21 | public function execute($eventObj, $className, $eventName) { |
|---|
| 22 | $this->eventObj = $eventObj; |
|---|
| 23 | $this->className = $className; |
|---|
| 24 | |
|---|
| 25 | switch ($eventName) { |
|---|
| 26 | case 'assignVariables': |
|---|
| 27 | $this->assignVariables(); |
|---|
| 28 | break; |
|---|
| 29 | case 'readData': |
|---|
| 30 | $this->readData(); |
|---|
| 31 | break; |
|---|
| 32 | } |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | /** |
|---|
| 36 | * @see UserPage::assignVariables() |
|---|
| 37 | */ |
|---|
| 38 | protected function assignVariables() { |
|---|
| 39 | WCF::getTPL()->assign(array( |
|---|
| 40 | 'optionDependencies' => $this->optionDependencies |
|---|
| 41 | )); |
|---|
| 42 | WCF::getTPL()->append('additionalFields', WCF::getTPL()->fetch('optionDependency')); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | /** |
|---|
| 47 | * @see UserPage::readData() |
|---|
| 48 | */ |
|---|
| 49 | protected function readData() { |
|---|
| 50 | $sql = "SELECT opt.optionType AS srcType, |
|---|
| 51 | opt.optionName AS srcOption, |
|---|
| 52 | opt2.optionName AS dstOption, |
|---|
| 53 | opt2.optionType AS dstType, |
|---|
| 54 | opt.optionDependencyRequest |
|---|
| 55 | FROM wcf".WCF_N."_user_option opt |
|---|
| 56 | JOIN wcf".WCF_N."_user_option_category option_category |
|---|
| 57 | ON opt.categoryName = option_category.categoryName |
|---|
| 58 | JOIN wcf".WCF_N."_package_dependency package_dependency |
|---|
| 59 | ON option_category.packageID = package_dependency.dependency |
|---|
| 60 | LEFT JOIN wcf".WCF_N."_user_option opt2 |
|---|
| 61 | ON opt.optionDependency = opt2.optionID |
|---|
| 62 | WHERE package_dependency.packageID = ".PACKAGE_ID." |
|---|
| 63 | AND option_category.categoryName LIKE 'profile.%' |
|---|
| 64 | AND opt.optionDependencyRequest != ''"; |
|---|
| 65 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 66 | $optionCategories = array(); |
|---|
| 67 | while ($row = WCF::getDB()->fetchArray($result)) { |
|---|
| 68 | $row['srcValue'] = WCF::getUser()->$row['srcOption']; |
|---|
| 69 | $row['dstValue'] = WCF::getUser()->$row['dstOption']; |
|---|
| 70 | |
|---|
| 71 | if(isset($_POST['values'][$row['srcOption']])) { |
|---|
| 72 | $row['srcValue'] = $_POST['values'][$row['srcOption']]; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | if(isset($_POST[$row['srcOption']])) { |
|---|
| 76 | $row['srcValue'] = $_POST[$row['srcOption']]; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | if(isset($_POST[$row['dstOption']])) { |
|---|
| 80 | $row['dstValue'] = $_POST[$row['dstOption']]; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | if(isset($_POST['values'][$row['dstOption']])) { |
|---|
| 84 | $row['dstValue'] = $_POST['values'][$row['dstOption']]; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | $this->optionDependencies[] = $row; |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | ?> |
|---|