| 1 | <?php |
|---|
| 2 | // wcf imports |
|---|
| 3 | require_once(WCF_DIR.'lib/system/event/EventListener.class.php'); |
|---|
| 4 | require_once(WCF_DIR.'lib/data/gmap/GmapApi.class.php'); |
|---|
| 5 | |
|---|
| 6 | /** |
|---|
| 7 | * Admin to configure custom useroptions. |
|---|
| 8 | * |
|---|
| 9 | * @author Torben Brodt |
|---|
| 10 | * @copyright 2010 easy-coding.de |
|---|
| 11 | * @license GNU General Public License <http://opensource.org/licenses/gpl-3.0.html> |
|---|
| 12 | * @package de.easy-coding.wcf.map.custominput |
|---|
| 13 | */ |
|---|
| 14 | class MapCustomInputListener implements EventListener { |
|---|
| 15 | |
|---|
| 16 | public function validate($tmp) { |
|---|
| 17 | $cols = array(); |
|---|
| 18 | foreach($tmp as $field) { |
|---|
| 19 | $col = User::getUserOptionID($field); |
|---|
| 20 | if($col) { |
|---|
| 21 | $cols[] = $col; |
|---|
| 22 | } |
|---|
| 23 | } |
|---|
| 24 | return $cols; |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * @see EventListener::execute() |
|---|
| 29 | */ |
|---|
| 30 | public function execute($eventObj, $className, $eventName) { |
|---|
| 31 | |
|---|
| 32 | if($eventObj->activeCategory != 'general') { |
|---|
| 33 | return; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | switch($eventName) { |
|---|
| 37 | case 'readData': |
|---|
| 38 | |
|---|
| 39 | $this->current = explode(",", $eventObj->activeOptions['gmap_custominput']['optionValue']); |
|---|
| 40 | $this->current = $this->validate($this->current); |
|---|
| 41 | $eventObj->activeOptions['gmap_custominput']['optionValue'] = implode(",", $this->current); |
|---|
| 42 | $this->getOptionIDs(); |
|---|
| 43 | $this->readOptions(); |
|---|
| 44 | break; |
|---|
| 45 | case 'assignVariables': |
|---|
| 46 | WCF::getTPL()->assign(array( |
|---|
| 47 | 'customInputOptions' => $this->options |
|---|
| 48 | )); |
|---|
| 49 | |
|---|
| 50 | WCF::getTPL()->append('additionalHeaderButtons', '<script type="text/javascript"> |
|---|
| 51 | function changeCustomInput(id) { |
|---|
| 52 | var d = document.getElementById("gmap_custominput"); |
|---|
| 53 | var s = []; |
|---|
| 54 | var l = d.value == "" ? [] : d.value.split(","); |
|---|
| 55 | var existing = false; |
|---|
| 56 | for(var i=0; i<l.length; i++) { |
|---|
| 57 | if(l[i] == id) { |
|---|
| 58 | document.getElementById("status_" + id).src = RELATIVE_WCF_DIR + "icon/disabledS.png"; |
|---|
| 59 | existing = true; |
|---|
| 60 | continue; |
|---|
| 61 | } |
|---|
| 62 | s.push(l[i]); |
|---|
| 63 | } |
|---|
| 64 | if(!existing) { |
|---|
| 65 | document.getElementById("status_" + id).src = RELATIVE_WCF_DIR + "icon/enabledS.png"; |
|---|
| 66 | s.push(id); |
|---|
| 67 | } |
|---|
| 68 | d.value = s.join(","); |
|---|
| 69 | |
|---|
| 70 | return false; |
|---|
| 71 | } |
|---|
| 72 | onloadEvents.push(function() { |
|---|
| 73 | var d = document.createElement("div"); |
|---|
| 74 | d.innerHTML = '.json_encode(WCF::getTPL()->fetch('mapCustomInput')).'; |
|---|
| 75 | document.getElementById("gmap_custominputDiv").appendChild(d); |
|---|
| 76 | |
|---|
| 77 | var d = document.getElementById("gmap_custominput").value = ""; |
|---|
| 78 | document.getElementById("gmap_custominput").style.display = "none"; |
|---|
| 79 | }); |
|---|
| 80 | </script>'); |
|---|
| 81 | break; |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | /** |
|---|
| 86 | * Gets user options ids. |
|---|
| 87 | */ |
|---|
| 88 | protected function getOptionIDs() { |
|---|
| 89 | $sql = "SELECT optionName, optionID |
|---|
| 90 | FROM wcf".WCF_N."_user_option option_table, |
|---|
| 91 | wcf".WCF_N."_package_dependency package_dependency |
|---|
| 92 | WHERE option_table.packageID = package_dependency.dependency |
|---|
| 93 | AND package_dependency.packageID = ".PACKAGE_ID." |
|---|
| 94 | AND option_table.categoryName IN ( |
|---|
| 95 | SELECT categoryName |
|---|
| 96 | FROM wcf".WCF_N."_user_option_category |
|---|
| 97 | WHERE parentCategoryName = 'profile' |
|---|
| 98 | ) |
|---|
| 99 | AND option_table.editable < 4 |
|---|
| 100 | AND option_table.visible < 4 |
|---|
| 101 | ORDER BY package_dependency.priority"; |
|---|
| 102 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 103 | $options = array(); |
|---|
| 104 | while ($row = WCF::getDB()->fetchArray($result)) { |
|---|
| 105 | $options[$row['optionName']] = $row['optionID']; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | $this->optionIDs = implode(',', $options); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * Gets a list of user options. |
|---|
| 113 | */ |
|---|
| 114 | protected function readOptions() { |
|---|
| 115 | $this->options = array(); |
|---|
| 116 | $sql = "SELECT * |
|---|
| 117 | FROM wcf".WCF_N."_user_option |
|---|
| 118 | WHERE optionID IN (".$this->optionIDs.")"; |
|---|
| 119 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 120 | while ($row = WCF::getDB()->fetchArray($result)) { |
|---|
| 121 | $row['isCustomInput'] = in_array($row['optionName'], $this->current); |
|---|
| 122 | $this->options[] = $row; |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | ?> |
|---|