Changeset 10589


Ignore:
Timestamp:
Apr 23, 2011, 10:51:53 AM (13 years ago)
Author:
patdenice
Message:

Create a function to save upload form settings.

Location:
trunk/admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/batch_manager_global.php

    r10553 r10589  
    434434  if (!empty($update_fields))
    435435  {
    436     // Update configuration
     436    // Update upload configuration
    437437    $updates = array();
    438438    foreach ($update_fields as $field)
    439439    {
    440       if (is_bool($upload_form_config[$field]['default']))
    441       {
    442         $value = isset($_POST[$field]);
    443 
    444         $updates[] = array(
    445           'param' => 'upload_form_'.$field,
    446           'value' => boolean_to_string($value)
    447           );
    448       }
    449       else
    450       {
    451         $value = null;
    452         if (!empty($_POST[$field]))
    453         {
    454           $value = $_POST[$field];
    455         }
    456 
    457         if (preg_match($upload_form_config[$field]['pattern'], $value)
    458           and $value >= $upload_form_config[$field]['min']
    459           and $value <= $upload_form_config[$field]['max'])
    460         {
    461           $conf['upload_form_'.$field] = $value;
    462            $updates[] = array(
    463             'param' => 'upload_form_'.$field,
    464             'value' => $value
    465             );
    466         }
    467         else
    468         {
    469           $updates = null;
    470           break;
    471         }
    472       }
     440      $value = !empty($_POST[$field]) ? $_POST[$field] : null;
    473441      $form_values[$field] = $value;
    474     }
    475     if (!empty($updates))
    476     {
    477       mass_updates(
    478         CONFIG_TABLE,
    479         array(
    480           'primary' => array('param'),
    481           'update' => array('value')
    482           ),
    483         $updates
    484         );
    485     }
     442      $updates[$field] = $value;
     443    }
     444    save_upload_form_config($updates);
    486445    $template->delete_compiled_templates();
    487446  }
  • trunk/admin/include/functions_upload.inc.php

    r10570 r10589  
    177177      );
    178178  }
     179}
     180
     181function save_upload_form_config($data, &$errors=array())
     182{
     183  if (!is_array($data) or empty($data))
     184  {
     185    return false;
     186  }
     187
     188  $upload_form_config = get_upload_form_config();
     189  $updates = array();
     190
     191  foreach ($data as $field => $value)
     192  {
     193    if (!isset($upload_form_config[$field]))
     194    {
     195      continue;
     196    }
     197    if (is_bool($upload_form_config[$field]['default']))
     198    {
     199      if (isset($value))
     200      {
     201        $value = true;
     202      }
     203      else
     204      {
     205        $value = false;
     206      }
     207
     208      $updates[] = array(
     209        'param' => 'upload_form_'.$field,
     210        'value' => boolean_to_string($value)
     211        );
     212    }
     213    elseif ($upload_form_config[$field]['can_be_null'] and empty($value))
     214    {
     215      $updates[] = array(
     216        'param' => 'upload_form_'.$field,
     217        'value' => 'false'
     218        );
     219    }
     220    else
     221    {
     222      $min = $upload_form_config[$field]['min'];
     223      $max = $upload_form_config[$field]['max'];
     224      $pattern = $upload_form_config[$field]['pattern'];
     225     
     226      if (preg_match($pattern, $value) and $value >= $min and $value <= $max)
     227      {
     228         $updates[] = array(
     229          'param' => 'upload_form_'.$field,
     230          'value' => $value
     231          );
     232      }
     233      else
     234      {
     235        array_push(
     236          $errors,
     237          sprintf(
     238            $upload_form_config[$field]['error_message'],
     239            $min,
     240            $max
     241            )
     242          );
     243      }
     244    }
     245  }
     246
     247  if (count($errors) == 0)
     248  {
     249    mass_updates(
     250      CONFIG_TABLE,
     251      array(
     252        'primary' => array('param'),
     253        'update' => array('value')
     254        ),
     255      $updates
     256      );
     257    return true;
     258  }
     259
     260  return false;
    179261}
    180262
  • trunk/admin/photos_add_settings.php

    r10552 r10589  
    8181  foreach ($fields as $field)
    8282  {
    83     $value = null;
    84     if (!empty($_POST[$field]))
    85     {
    86       $value = $_POST[$field];
    87     }
    88    
    89     if (is_bool($upload_form_config[$field]['default']))
    90     {
    91       if (isset($value))
    92       {
    93         $value = true;
    94       }
    95       else
    96       {
    97         $value = false;
    98       }
     83    $value = !empty($_POST[$field]) ? $_POST[$field] : null;
     84    $form_values[$field] = $value;
     85    $updates[$field] = $value;
     86  }
    9987
    100       $updates[] = array(
    101         'param' => 'upload_form_'.$field,
    102         'value' => boolean_to_string($value)
    103         );
    104     }
    105     elseif ($upload_form_config[$field]['can_be_null'] and empty($value))
    106     {
    107       $updates[] = array(
    108         'param' => 'upload_form_'.$field,
    109         'value' => 'false'
    110         );
    111     }
    112     else
    113     {
    114       $min = $upload_form_config[$field]['min'];
    115       $max = $upload_form_config[$field]['max'];
    116       $pattern = $upload_form_config[$field]['pattern'];
    117      
    118       if (preg_match($pattern, $value) and $value >= $min and $value <= $max)
    119       {
    120          $updates[] = array(
    121           'param' => 'upload_form_'.$field,
    122           'value' => $value
    123           );
    124       }
    125       else
    126       {
    127         array_push(
    128           $page['errors'],
    129           sprintf(
    130             $upload_form_config[$field]['error_message'],
    131             $min,
    132             $max
    133             )
    134           );
    135       }
    136     }
    137    
    138     $form_values[$field] = $value;
    139   }
     88  save_upload_form_config($updates, $page['errors']);
    14089
    14190  if (count($page['errors']) == 0)
    14291  {
    143     mass_updates(
    144       CONFIG_TABLE,
    145       array(
    146         'primary' => array('param'),
    147         'update' => array('value')
    148         ),
    149       $updates
    150       );
    151    
    15292    array_push(
    15393      $page['infos'],
Note: See TracChangeset for help on using the changeset viewer.