Project

General

Profile

« Previous | Next » 

Revision 1791

Added by Dietmar about 12 years ago

  1. fixed save search settings

View differences:

save.php
198 198
    'website_description',
199 199
    'website_keywords',
200 200
    'wysiwyg_style',
201
    'search_module_order',
202
    'search_max_excerpt',
203
    'search_time_limit',
204 201
    'pages_directory',
205 202
    'page_icon_dir',
206 203
    'media_directory',
......
298 295
    }
299 296

  
300 297
}
298
/**
299
 * now save search settings
300
 */
301 301
$StripCodeFromISearch = array(
302 302
    'search_header',
303 303
    'search_results_header',
304 304
    'search_results_loop',
305 305
    'search_results_footer',
306
    'search_no_results',
307 306
    'search_footer',
308 307
    'search_module_order',
309 308
    'search_max_excerpt',
309
    'search_no_results',
310 310
    'search_time_limit',
311
    'search_max_excerpt',
311 312
    );
312 313
$allow_empty_values = array(
313
    'search_footer',
314
    'header',
315
    'results_header',
316
    'results_loop',
317
    'results_footer',
318
    'footer',
319
    'module_order',
320
    'no_results',
314 321
    );
322
$allow_tags_in_fields = array(
323
    'header',
324
    'results_header',
325
    'results_loop',
326
    'results_footer',
327
    'no_results',
328
    'footer',
329
    );
315 330

  
316 331
// Query current search settings in the db, then loop through them and update the db with the new value
317 332
$sql  = 'SELECT `name`, `value` FROM `'.TABLE_PREFIX.'search` ';
318
$sql .= 'WHERE `extra` = ""';
319
$res_search = $database->query($sql);
320

  
321
if($database->is_error()) {
322
	$admin->print_error($database->is_error(), $js_back );
333
$sql .= 'WHERE `extra` =  \'\' ';
334
if( !($oSearch = $database->query($sql)) ) {
335
    if($database->is_error()) {
336
    	$admin->print_error(explode(';',$database->get_error()), $js_back );
337
    }
323 338
}
324 339

  
325
while($search_setting = $res_search->fetchRow(MYSQL_ASSOC))
340
while($aSearch = $oSearch->fetchRow(MYSQL_ASSOC))
326 341
{
327
	$old_value = $search_setting['value'];
328
	$setting_name = $search_setting['name'];
329
	$post_name = 'search_'.$setting_name;
342
	$passed = false;
343
	$old_value = $aSearch['value'];
344
	$sSearchName = $aSearch['name'];
345
	$sPostName = 'search_'.$sSearchName;
330 346

  
331
    // hold old value if post is empty
332
    // check search template
333
    $value = ($admin->get_post($post_name));
334
    if(in_array($post_name, $StripCodeFromISearch) ) {
347
    $value = $admin->get_post($sPostName);
348
    $value = isset($value) ?  $value : $old_value;
349
    if(in_array($sPostName, $StripCodeFromISearch) ) {
335 350
        $value = $admin->StripCodeFromText($value);
336 351
    }
337 352

  
338
    $passed = in_array($post_name, $allow_empty_values);
353
/**
354
 *  hold old value if post is empty
355
 *  check search template
356
 */
357
	switch ($sSearchName) {
358
		case 'template':
359
 			$passed = true;
360
            $value =  ( !($admin->get_post($sPostName)) || ($value == DEFAULT_TEMPLATE ) ) ? '' : $admin->get_post($sPostName);
361
			break;
362
		case 'max_excerpt':
363
 			$passed = true;
364
        	if(preg_match('/[^0-9]+/i', $value)) {
365
                $value = $old_value;
366
        	}
367
			break;
368
		case 'time_limit':
369
            $passed = true;
370
        	if(preg_match('/[^0-9]+/i', $value)) {
371
                $value = $old_value;
372
        	}
373
			break;
374
		default :
375
        	$passed = ($admin->get_post($sPostName) || in_array($sSearchName, $allow_empty_values));
339 376

  
340
    $value = ( (!in_array($post_name, $allow_empty_values)) && ($setting_name != 'template') ) ? $old_value : $value;
377
            if (!in_array($sSearchName, $allow_tags_in_fields))
378
            {
379
                $value = strip_tags($value);
380
            }
381
			break;
382
	}
341 383

  
342
    // $value =  ( ($admin->get_post($post_name) == '') && ($setting_name == 'template') ) ? DEFAULT_TEMPLATE : $admin->get_post($post_name);
343
    if(isset($value))
384
    if ( ($passed == true) )
344 385
	{
345 386
		$value = $admin->add_slashes($value);
346 387
        $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
347 388
        $sql .= 'SET `value` = \''.$value.'\' ';
348
        $sql .= 'WHERE `name` = \''.$setting_name.'\' ';
389
        $sql .= 'WHERE `name` = \''.$sSearchName.'\' ';
349 390
        $sql .= 'AND `extra` = \'\' ';
350 391
		if($database->query($sql)) {
392

  
351 393
		}
352 394
		$sql_info = mysql_info($database->db_handle);
353 395
    }

Also available in: Unified diff