root/g-map/optionals/de.easy-coding.wcf.map.custominput/files/lib/system/event/listener/MapCustomInputListener.class.php @ 1327

Revision 1327, 3.5 kB (checked in by Torben Brodt, 2 years ago)

another acptemplate fix

RevLine 
[1306]1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/system/event/EventListener.class.php');
[1326]4require_once(WCF_DIR.'lib/data/gmap/GmapApi.class.php');
[1306]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 */
14class MapCustomInputListener implements EventListener {
[1326]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
[1306]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':
[1326]38                               
[1306]39                                $this->current = explode(",", $eventObj->activeOptions['gmap_custominput']['optionValue']);
[1326]40                                $this->current = $this->validate($this->current);
41                                $eventObj->activeOptions['gmap_custominput']['optionValue'] = implode(",", $this->current);
[1306]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                                        document.getElementById("gmap_custominput").style.display = "none";
77                                });
78                                </script>');
79                        break;
80                }
81        }
82       
83        /**
84         * Gets user options ids.
85         */
86        protected function getOptionIDs() {
87                $sql = "SELECT          optionName, optionID
88                        FROM            wcf".WCF_N."_user_option option_table,
89                                        wcf".WCF_N."_package_dependency package_dependency
90                        WHERE           option_table.packageID = package_dependency.dependency
91                                        AND package_dependency.packageID = ".PACKAGE_ID."
92                                        AND option_table.categoryName IN (
93                                                SELECT  categoryName
94                                                FROM    wcf".WCF_N."_user_option_category
95                                                WHERE   parentCategoryName = 'profile'
96                                        )
97                                        AND option_table.editable < 4
98                                        AND option_table.visible < 4
99                        ORDER BY        package_dependency.priority";
100                $result = WCF::getDB()->sendQuery($sql);
101                $options = array();
102                while ($row = WCF::getDB()->fetchArray($result)) {
103                        $options[$row['optionName']] = $row['optionID'];
104                }
105               
106                $this->optionIDs = implode(',', $options);
107        }
108       
109        /**
110         * Gets a list of user options.
111         */
112        protected function readOptions() {
113                $this->options = array();
114                $sql = "SELECT          *
115                        FROM            wcf".WCF_N."_user_option
116                        WHERE           optionID IN (".$this->optionIDs.")";
117                $result = WCF::getDB()->sendQuery($sql);
118                while ($row = WCF::getDB()->fetchArray($result)) {
119                        $row['isCustomInput'] = in_array($row['optionName'], $this->current);
120                        $this->options[] = $row;
121                }
122        }
123}
124?>
Note: See TracBrowser for help on using the browser.