ultimix
settings_controller.php
Go to the documentation of this file.
1 <?php
2 
3  /*
4  * This source code is a part of the Ultimix Project.
5  * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6  * it's own license wich could be found from the corresponding files or sources.
7  * This source code is provided "as is" without any warranties or garanties.
8  *
9  * Have a nice day!
10  *
11  * @url http://ultimix.sorceforge.net
12  *
13  * @author Alexey "gdever" Dodonov
14  */
15 
27 
38  var $CachedMultyFS = false;
39  var $DBSettings = false;
40  var $Security = false;
41  var $Settings = false;
42 
53  function __construct()
54  {
55  try
56  {
57  $this->CachedMultyFS = get_package( 'cached_multy_fs' , 'last' , __FILE__ );
58  $this->DBSettings = get_package_object( 'settings::db_settings' , 'last' , __FILE__ );
59  $this->Security = get_package( 'security' , 'last' , __FILE__ );
60  $this->Settings = get_package_object( 'settings::package_settings' , 'last' , __FILE__ );
61  }
62  catch( Exception $e )
63  {
64  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
65  }
66  }
67 
90  function get_posted_setting( &$Manifest )
91  {
92  try
93  {
94  $SettingName = $Manifest->get_setting( 'setting_name' );
95 
96  switch( $Manifest->get_setting( 'type' , 'input' ) )
97  {
98  case( 'input' ):
99  return( $this->Security->get_gp( $SettingName , 'string' , '' ) );
100 
101  case( 'checkbox' ):
102  return( intval( $this->Security->get_gp( $SettingName , 'integer' ) ) );
103 
104  case( 'textarea' ):
105  return( $this->Security->get_gp( $SettingName , 'string' , '' ) );
106  }
107  }
108  catch( Exception $e )
109  {
110  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
111  }
112  }
113 
132  function set_db_setting( &$Manifest )
133  {
134  try
135  {
136  $SettingName = $Manifest->get_setting( 'setting_name' );
137  $DefaultValue = $Manifest->get_setting( 'default_value' , '' );
138 
139  $SettingValue = $this->DBSettings->get_setting( $SettingName , $DefaultValue );
140  $NewSettingValue = $this->get_posted_setting( $Manifest );
141 
142  if( $SettingValue != $NewSettingValue )
143  {
144  $this->DBSettings->set_setting( $SettingName , $NewSettingValue );
145  }
146  }
147  catch( Exception $e )
148  {
149  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
150  }
151  }
152 
171  function set_package_setting( &$Manifest )
172  {
173  try
174  {
175  $Version = $Manifest->get_setting( 'package_version' , 'last' );
176  list( $Name , $ConfigFileName , $SettingName ) =
177  $Manifest->get_settings( 'package_name,config_file_name,setting_name' );
178 
179  $SettingValue = $this->Settings->get_package_setting( $Name , $Version ,
180  $ConfigFileName , $SettingName , $Manifest->get_setting( 'default_value' , '' ) );
181  $NewSettingValue = $this->get_posted_setting( $Manifest );
182 
183  if( $SettingValue != $NewSettingValue )
184  {
185  $this->Settings->set_package_setting(
186  $Name , $Version , $ConfigFileName , $SettingName , $NewSettingValue
187  );
188  }
189  }
190  catch( Exception $e )
191  {
192  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
193  }
194  }
195 
214  function handle_config_line( $ConfigLine )
215  {
216  try
217  {
218  $Manifest = get_package_object( 'settings::settings' , 'last' , __FILE__ );
219  $Manifest->load_settings( $ConfigLine );
220 
221  $PackageName = $Manifest->get_setting( 'package_name' , false );
222  if( $PackageName === false )
223  {
224  $this->set_db_setting( $Manifest );
225  }
226  else
227  {
228  $this->set_package_setting( $Manifest );
229  }
230  }
231  catch( Exception $e )
232  {
233  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
234  }
235  }
236 
255  function save_settings( $Options )
256  {
257  try
258  {
259  $FormsName = explode( ',' , $Options->get_setting( 'form_name' ) );
260 
261  foreach( $FormsName as $i => $FormName )
262  {
263  $ConfigPath = _get_package_relative_path_ex( 'settings::settings_view' , 'last' ).
264  "/conf/cf_$FormName";
265  if( $this->CachedMultyFS->file_exists( $ConfigPath ) )
266  {
267  $Config = $this->CachedMultyFS->file_get_contents( $ConfigPath , 'exploded' );
268 
269  foreach( $Config as $i => $ConfigLine )
270  {
271 
272  $this->handle_config_line( $ConfigLine );
273  }
274  }
275  }
276  }
277  catch( Exception $e )
278  {
279  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
280  }
281  }
282 
301  function controller( $Options )
302  {
303  try
304  {
305  $ContextSet = get_package( 'gui::context_set' , 'last' , __FILE__ );
306 
307  $ContextSet->add_context( dirname( __FILE__ ).'/conf/cfcx_save_settings' );
308 
309  if( $ContextSet->execute( $Options , $this , __FILE__ ) )return;
310  }
311  catch( Exception $e )
312  {
313  $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
314  }
315  }
316  }
317 
318 ?>