4949
5050class page_action extends tform_actions {
5151
52- function onShow () {
52+ private function getAffectedSites () {
5353 global $ app , $ conf ;
54-
55- if ($ this ->id > 0 ){
56- $ record = $ app ->db ->queryOneRecord ("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? " , $ this ->id );
57- if ($ record ['master_directive_snippets_id ' ] > 0 ){
58- unset($ app ->tform ->formDef ["tabs " ]['directive_snippets ' ]['fields ' ]['name ' ], $ app ->tform ->formDef ["tabs " ]['directive_snippets ' ]['fields ' ]['type ' ], $ app ->tform ->formDef ["tabs " ]['directive_snippets ' ]['fields ' ]['snippet ' ], $ app ->tform ->formDef ["tabs " ]['directive_snippets ' ]['fields ' ]['required_php_snippets ' ]);
54+
55+ if ($ this ->dataRecord ['type ' ] === 'php ' ) {
56+ $ rlike = $ this ->dataRecord ['id ' ].'|, ' .$ this ->dataRecord ['id ' ].'| ' .$ this ->dataRecord ['id ' ].', ' ;
57+ $ affected_snippets = $ app ->db ->queryAllRecords ('SELECT directive_snippets_id FROM directive_snippets WHERE required_php_snippets REGEXP ? AND type = ? ' , $ rlike , 'apache ' );
58+ if (is_array ($ affected_snippets ) && !empty ($ affected_snippets )) {
59+ foreach ($ affected_snippets as $ snippet ) {
60+ $ sql_in [] = $ snippet ['directive_snippets_id ' ];
61+ }
62+ $ affected_sites = $ app ->db ->queryAllRecords ('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id IN ? ' , $ conf ['server_id ' ], $ sql_in );
5963 }
60- unset($ record );
64+ } elseif ($ this ->dataRecord ['type ' ] === 'apache ' || $ this ->dataRecord ['type ' ] === 'nginx ' ) {
65+ $ affected_sites = $ app ->db ->queryAllRecords ('SELECT domain_id FROM web_domain WHERE server_id = ? AND directive_snippets_id = ? ' , $ conf ['server_id ' ], $ this ->dataRecord ['id ' ]);
6166 }
62-
63- parent :: onShow () ;
67+
68+ return $ affected_sites ;
6469 }
65-
66- function onShowEnd () {
67- global $ app , $ conf ;
68-
69- $ is_master = false ;
70- if ($ this ->id > 0 ){
71- if ($ this ->dataRecord ['master_directive_snippets_id ' ] > 0 ){
72- $ is_master = true ;
73- $ app ->tpl ->setVar ("name " , $ this ->dataRecord ['name ' ], true );
74- $ app ->tpl ->setVar ("type " , $ this ->dataRecord ['type ' ], true );
75- $ app ->tpl ->setVar ("snippet " , $ this ->dataRecord ['snippet ' ], true );
70+
71+ public function onBeforeUpdate () {
72+ global $ app ;
73+
74+ $ oldRecord = $ app ->tform ->getDataRecord ($ this ->id );
75+
76+ if ($ this ->dataRecord ['active ' ] !== 'y ' && $ oldRecord ['active ' ] === 'y ' ) {
77+ $ affected_sites = $ this ->getAffectedSites ();
78+ if (!empty ($ affected_sites )) {
79+ $ app ->tform ->errorMessage .= $ app ->tform ->lng ('error_disable_snippet_active_sites ' );
80+ }
81+ } elseif ($ this ->dataRecord ['customer_viewable ' ] !== 'y ' && $ oldRecord ['customer_viewable ' ] === 'y ' ) {
82+ $ affected_sites = $ this ->getAffectedSites ();
83+ if (!empty ($ affected_sites )) {
84+ $ app ->tform ->errorMessage .= $ app ->tform ->lng ('error_hide_snippet_active_sites ' );
7685 }
7786 }
78-
79- $ app ->tpl ->setVar ("is_master " , $ is_master );
80-
81- parent ::onShowEnd ();
8287 }
83-
84- function onSubmit () {
85- global $ app , $ conf ;
8688
87- if ($ this ->id > 0 ){
88- $ record = $ app ->db ->queryOneRecord ("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? " , $ this ->id );
89- if ($ record ['master_directive_snippets_id ' ] > 0 ){
90- unset($ app ->tform ->formDef ["tabs " ]['directive_snippets ' ]['fields ' ]['name ' ], $ app ->tform ->formDef ["tabs " ]['directive_snippets ' ]['fields ' ]['type ' ], $ app ->tform ->formDef ["tabs " ]['directive_snippets ' ]['fields ' ]['snippet ' ], $ app ->tform ->formDef ["tabs " ]['directive_snippets ' ]['fields ' ]['required_php_snippets ' ]);
91- }
92-
93- if (isset ($ this ->dataRecord ['update_sites ' ])) {
94- parent ::onSubmit ();
95- } else {
96- $ app ->db ->query ('UPDATE directive_snippets SET name = ?, type = ?, snippet = ?, customer_viewable = ?, required_php_snippets = ?, active = ? WHERE directive_snippets_id = ? ' , $ this ->dataRecord ['name ' ], $ this ->dataRecord ['type ' ], $ this ->dataRecord ['snippet ' ], $ this ->dataRecord ['customer_viewable ' ], implode (', ' , $ this ->dataRecord ['required_php_snippets ' ]), $ this ->dataRecord ['active ' ], $ this ->id );
97-
98- if ($ _REQUEST ["next_tab " ] == '' ) {
99- $ list_name = $ _SESSION ["s " ]["form " ]["return_to " ];
100- if ($ list_name != '' && $ _SESSION ["s " ]["list " ][$ list_name ]["parent_name " ] != $ app ->tform ->formDef ["name " ]) {
101- $ redirect = "Location: " .$ _SESSION ["s " ]["list " ][$ list_name ]["parent_script " ]."?id= " .$ _SESSION ["s " ]["list " ][$ list_name ]["parent_id " ]."&next_tab= " .$ _SESSION ["s " ]["list " ][$ list_name ]["parent_tab " ];
102- $ _SESSION ["s " ]["form " ]["return_to " ] = '' ;
103- session_write_close ();
104- header ($ redirect );
105- } elseif (isset ($ _SESSION ["s " ]["form " ]["return_to_url " ]) && $ _SESSION ["s " ]["form " ]["return_to_url " ] != '' ) {
106- $ redirect = $ _SESSION ["s " ]["form " ]["return_to_url " ];
107- $ _SESSION ["s " ]["form " ]["return_to_url " ] = '' ;
108- session_write_close ();
109- header ("Location: " .$ redirect );
110- exit ;
111- } else {
112- header ("Location: " .$ app ->tform ->formDef ['list_default ' ]);
113- }
114- exit ;
89+ public function onAfterUpdate () {
90+ global $ app ;
91+
92+ if (isset ($ this ->dataRecord ['update_sites ' ]) && $ this ->dataRecord ['update_sites ' ] === 'y ' && $ this ->dataRecord ['active ' ] === 'y ' ) {
93+ $ affected_sites = $ this ->getAffectedSites ();
94+
95+ if (is_array ($ affected_sites ) && !empty ($ affected_sites )) {
96+ foreach ($ affected_sites as $ site ) {
97+ $ website = $ app ->db ->queryOneRecord ('SELECT * FROM web_domain WHERE domain_id = ? ' , $ site ['domain_id ' ]);
98+ $ app ->db ->datalogUpdate ('web_domain ' , $ website , 'domain_id ' , $ site ['domain_id ' ], true );
11599 }
116100 }
117-
118- unset($ record );
119101 }
120-
121- parent ::onSubmit ();
122102 }
123-
124103}
125104
126105$ page = new page_action ;
127- $ page ->onLoad ();
128-
129- ?>
106+ $ page ->onLoad ();
0 commit comments