1+ <?php
2+
3+ /*
4+ Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5+ All rights reserved.
6+
7+ Redistribution and use in source and binary forms, with or without modification,
8+ are permitted provided that the following conditions are met:
9+
10+ * Redistributions of source code must retain the above copyright notice,
11+ this list of conditions and the following disclaimer.
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ this list of conditions and the following disclaimer in the documentation
14+ and/or other materials provided with the distribution.
15+ * Neither the name of ISPConfig nor the names of its contributors
16+ may be used to endorse or promote products derived from this software without
17+ specific prior written permission.
18+
19+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+ IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+ */
30+
31+ class mail_module {
32+
33+ var $ module_name = 'mail ' ;
34+ var $ class_name = 'mail_module ' ;
35+ var $ actions_available = array ( 'mail_domain_insert ' ,
36+ 'mail_domain_update ' ,
37+ 'mail_domain_delete ' ,
38+ 'mail_user_insert ' ,
39+ 'mail_user_update ' ,
40+ 'mail_user_delete ' ,
41+ 'mail_access_insert ' ,
42+ 'mail_access_update ' ,
43+ 'mail_access_delete ' ,
44+ 'mail_forwarding_insert ' ,
45+ 'mail_forwarding_update ' ,
46+ 'mail_forwarding_delete ' ,
47+ 'mail_transport_insert ' ,
48+ 'mail_transport_update ' ,
49+ 'mail_transport_delete ' );
50+
51+ /*
52+ This function is called when the module is loaded
53+ */
54+
55+ function onLoad () {
56+
57+ /*
58+ Annonce the actions that where provided by this module, so plugins
59+ can register on them.
60+ */
61+
62+ $ app ->plugins ->registerEvents ($ this ->module_name ,$ this ->actions_available );
63+
64+ /*
65+ As we want to get notified of any changes on several database tables,
66+ we register for them.
67+
68+ The following function registers the function "functionname"
69+ to be executed when a record for the table "dbtable" is
70+ processed in the sys_datalog. "classname" is the name of the
71+ class that contains the function functionname.
72+ */
73+
74+ $ app ->modules ->registerTableHook ('mail_access ' ,'mail_module ' ,'process ' );
75+ $ app ->modules ->registerTableHook ('mail_domain ' ,'mail_module ' ,'process ' );
76+ $ app ->modules ->registerTableHook ('mail_forwarding ' ,'mail_module ' ,'process ' );
77+ $ app ->modules ->registerTableHook ('mail_transport ' ,'mail_module ' ,'process ' );
78+ $ app ->modules ->registerTableHook ('mail_user ' ,'mail_module ' ,'process ' );
79+
80+ }
81+
82+ /*
83+ This function is called when a change in one of the registered tables is detected.
84+ The function then raises the events for the plugins.
85+ */
86+
87+ function process ($ tablename ,$ action ,$ data ) {
88+ global $ app ;
89+
90+ switch ($ tablename ) {
91+ case 'mail_access ' :
92+ if ($ action == 'i ' ) $ app ->plugins ->raiseEvent ('mail_access_insert ' ,$ data );
93+ if ($ action == 'u ' ) $ app ->plugins ->raiseEvent ('mail_access_update ' ,$ data );
94+ if ($ action == 'd ' ) $ app ->plugins ->raiseEvent ('mail_access_delete ' ,$ data );
95+ break ;
96+ case 'mail_domain ' :
97+ if ($ action == 'i ' ) $ app ->plugins ->raiseEvent ('mail_domain_insert ' ,$ data );
98+ if ($ action == 'u ' ) $ app ->plugins ->raiseEvent ('mail_domain_update ' ,$ data );
99+ if ($ action == 'd ' ) $ app ->plugins ->raiseEvent ('mail_domain_delete ' ,$ data );
100+ break ;
101+ case 'mail_forwarding ' :
102+ if ($ action == 'i ' ) $ app ->plugins ->raiseEvent ('mail_forwarding_insert ' ,$ data );
103+ if ($ action == 'u ' ) $ app ->plugins ->raiseEvent ('mail_forwarding_update ' ,$ data );
104+ if ($ action == 'd ' ) $ app ->plugins ->raiseEvent ('mail_forwarding_delete ' ,$ data );
105+ break ;
106+ case 'mail_transport ' :
107+ if ($ action == 'i ' ) $ app ->plugins ->raiseEvent ('mail_transport_insert ' ,$ data );
108+ if ($ action == 'u ' ) $ app ->plugins ->raiseEvent ('mail_transport_update ' ,$ data );
109+ if ($ action == 'd ' ) $ app ->plugins ->raiseEvent ('mail_transport_delete ' ,$ data );
110+ break ;
111+ case 'mail_user ' :
112+ if ($ action == 'i ' ) $ app ->plugins ->raiseEvent ('mail_user_insert ' ,$ data );
113+ if ($ action == 'u ' ) $ app ->plugins ->raiseEvent ('mail_user_update ' ,$ data );
114+ if ($ action == 'd ' ) $ app ->plugins ->raiseEvent ('mail_user_delete ' ,$ data );
115+ break ;
116+ } // end switch
117+ } // end function
118+
119+ } // end class
120+
121+ ?>
0 commit comments