Changeset 30179


Ignore:
Timestamp:
Oct 17, 2014, 2:17:13 PM (10 years ago)
Author:
plg
Message:

compatibility 2.7 and better use of core config

Location:
extensions/PayPalShoppingCart
Files:
1 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/PayPalShoppingCart/admin.php

    r21205 r30179  
    4444$tabsheet->assign();
    4545
    46 switch($page['tab']){
    47  case 'currency':
    48   $array_currency=array(
    49   'AUD'=>'Australian Dollar',
    50   'BRL'=>'Brazilian Real',
    51   'CAD'=>'Canadian Dollar',
    52   'CZK'=>'Czech Koruna',
    53   'DKK'=>'Danish Krone',
    54   'EUR'=>'Euro',
    55   'HKD'=>'Hong Kong Dollar',
    56   'HUF'=>'Hungarian Forint',
    57   'ILS'=>'Israeli New Sheqel',
    58   'JPY'=>'Japanese Yen',
    59   'MYR'=>'Malaysian Ringgit',
    60   'MXN'=>'Mexican Peso',
    61   'NOK'=>'Norwegian Krone',
    62   'NZD'=>'New Zealand Dollar',
    63   'PHP'=>'Philippine Peso',
    64   'PLN'=>'Polish Zloty',
    65   'GBP'=>'Pound Sterling',
    66   'SGD'=>'Singapore Dollar',
    67   'SEK'=>'Swedish Krona',
    68   'CHF'=>'Swiss Franc',
    69   'TWD'=>'Taiwan New Dollar',
    70   'THB'=>'Thai Baht',
    71   'USD'=>'U.S. Dollar'
    72   );
    73   if(isset($_POST['currency'])){
    74    $currency=$_POST['currency'];
    75    $query='UPDATE '.PPPPP_CONFIG_TABLE.' SET value = \''.$currency.'\' WHERE param = \'currency\';';
    76    pwg_query($query);
    77    $page['infos']=l10n('Data updated');
    78    }
     46switch($page['tab'])
     47{
     48  case 'currency':
     49   
     50    $array_currency = array(
     51      'AUD'=>'Australian Dollar',
     52      'BRL'=>'Brazilian Real',
     53      'CAD'=>'Canadian Dollar',
     54      'CZK'=>'Czech Koruna',
     55      'DKK'=>'Danish Krone',
     56      'EUR'=>'Euro',
     57      'HKD'=>'Hong Kong Dollar',
     58      'HUF'=>'Hungarian Forint',
     59      'ILS'=>'Israeli New Sheqel',
     60      'JPY'=>'Japanese Yen',
     61      'MYR'=>'Malaysian Ringgit',
     62      'MXN'=>'Mexican Peso',
     63      'NOK'=>'Norwegian Krone',
     64      'NZD'=>'New Zealand Dollar',
     65      'PHP'=>'Philippine Peso',
     66      'PLN'=>'Polish Zloty',
     67      'GBP'=>'Pound Sterling',
     68      'SGD'=>'Singapore Dollar',
     69      'SEK'=>'Swedish Krona',
     70      'CHF'=>'Swiss Franc',
     71      'TWD'=>'Taiwan New Dollar',
     72      'THB'=>'Thai Baht',
     73      'USD'=>'U.S. Dollar'
     74      );
     75 
     76    if(isset($_POST['currency']) and isset($array_currency[ $_POST['currency'] ]))
     77    {
     78      $conf['PayPalShoppingCart']['currency'] = $_POST['currency'];
     79      conf_update_param('PayPalShoppingCart', $conf['PayPalShoppingCart']);
     80     
     81      $page['infos'][] = l10n('Your configuration settings are saved');
     82    }
    7983 
    80   $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'currency\';';
    81   $result = pwg_query($query);
    82   $row = pwg_db_fetch_row($result);
    83   $template->assign('ppppp_currency',$row[0]);
    84  
    85   $template->assign('ppppp_array_currency',$array_currency);
    86   break;
     84    $template->assign(
     85      array(
     86        'ppppp_currency' => $conf['PayPalShoppingCart']['currency'],
     87        'ppppp_array_currency' => $array_currency,
     88        )
     89      );
     90   
     91    break;
    8792
    88  case 'albums' :
     93   case 'albums' :
    8994
    90    if (isset($_POST['apply_to_albums']) and in_array($_POST['apply_to_albums'], array('all', 'list')))
    91    {
    92      $conf['PayPalShoppingCart']['apply_to_albums'] = $_POST['apply_to_albums'];
    93      conf_update_param('PayPalShoppingCart', serialize($conf['PayPalShoppingCart']));
     95     if (isset($_POST['apply_to_albums']) and in_array($_POST['apply_to_albums'], array('all', 'list')))
     96     {
     97       $conf['PayPalShoppingCart']['apply_to_albums'] = $_POST['apply_to_albums'];
     98       conf_update_param('PayPalShoppingCart', $conf['PayPalShoppingCart']);
    9499
    95      if ($_POST['apply_to_albums'] == 'list')
    96      {
    97        check_input_parameter('albums', $_POST, true, PATTERN_ID);
     100       if ($_POST['apply_to_albums'] == 'list')
     101       {
     102         check_input_parameter('albums', $_POST, true, PATTERN_ID);
    98103
    99        if (empty($_POST['albums']))
    100        {
    101          $_POST['albums'][] = -1;
    102        }
     104         if (empty($_POST['albums']))
     105         {
     106           $_POST['albums'][] = -1;
     107         }
    103108       
    104        $query = '
     109         $query = '
    105110UPDATE '.CATEGORIES_TABLE.'
    106111  SET paypal_active = \'false\'
    107112  WHERE id NOT IN ('.implode(',', $_POST['albums']).')
    108113;';
    109        pwg_query($query);
     114         pwg_query($query);
    110115
    111        $query = '
     116         $query = '
    112117UPDATE '.CATEGORIES_TABLE.'
    113118  SET paypal_active = \'true\'
    114119  WHERE id IN ('.implode(',', $_POST['albums']).')
    115120;';
    116        pwg_query($query);
     121         pwg_query($query);
     122       }
     123
     124       $page['infos'][] = l10n('Your configuration settings are saved');
    117125     }
    118 
    119      array_push(
    120        $page['infos'],
    121        l10n('Your configuration settings are saved')
    122        );
    123    }
    124126   
    125    // associate to albums
    126    $query = '
     127     // associate to albums
     128     $query = '
    127129SELECT id
    128130  FROM '.CATEGORIES_TABLE.'
    129131  WHERE paypal_active = \'true\'
    130132;';
    131    $paypal_albums = array_from_query($query, 'id');
     133     $paypal_albums = array_from_query($query, 'id');
    132134
    133    $query = '
     135     $query = '
    134136SELECT id,name,uppercats,global_rank
    135137  FROM '.CATEGORIES_TABLE.'
    136138;';
    137    display_select_cat_wrapper($query, $paypal_albums, 'album_options');
     139     display_select_cat_wrapper($query, $paypal_albums, 'album_options');
    138140
    139    $template->assign('apply_to_albums', $conf['PayPalShoppingCart']['apply_to_albums']);
     141     $template->assign('apply_to_albums', $conf['PayPalShoppingCart']['apply_to_albums']);
    140142
    141    break;
     143     break;
    142144 
    143145 
    144  case 'size':
    145   if(isset($_POST['delete'])and is_numeric($_POST['delete'])){
    146    $delete_id=$_POST['delete'];
    147    $query='DELETE FROM '.PPPPP_SIZE_TABLE.' WHERE id = '.$delete_id.';';
    148    pwg_query($query);
    149    $page['infos']=l10n('Data deleted');
    150    }
    151   else if (isset($_POST['size'])and isset($_POST['price'])and is_numeric($_POST['price'])){
    152    $size=$_POST['size'];
    153    $price=$_POST['price'];
    154    $query='INSERT into '.PPPPP_SIZE_TABLE.' (size,price) values (\''.$size.'\',\''.$price.'\');';
    155    @$res=pwg_query($query);
    156    if($res==1)
    157     $page['infos']=l10n('Data appened');
    158    else
    159     $page['errors']=l10n('Error');
    160   }
    161   $query='SELECT * FROM '.PPPPP_SIZE_TABLE.';';
    162   $result = pwg_query($query);
    163   while($row = pwg_db_fetch_assoc($result)){
    164    $template->append('ppppp_array_size',$row);
    165   }
    166   break;
     146  case 'size':
     147   
     148    if (isset($_POST['delete']))
     149    {
     150      check_input_parameter('delete', $_POST, false, PATTERN_ID);
     151     
     152      pwg_query('DELETE FROM '.PPPPP_SIZE_TABLE.' WHERE id = '.$_POST['delete'].';');
    167153
    168  case 'shipping':
    169   if(isset($_POST['fixed_shipping'])and is_numeric($_POST['fixed_shipping'])){
    170    $fixed_shipping=$_POST['fixed_shipping'];
    171    $query='UPDATE '.PPPPP_CONFIG_TABLE.' SET value = \''.$fixed_shipping.'\' WHERE param = \'fixed_shipping\';';
    172    pwg_query($query);
    173    $page['infos']=l10n('Data updated');
    174    }
    175   $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'fixed_shipping\';';
    176   $result = pwg_query($query);
    177   $row = pwg_db_fetch_row($result);
    178   $template->assign('ppppp_fixed_shipping',$row[0]);
    179   break;
    180  }
     154      $page['infos'][] = l10n('Your configuration settings are saved');
     155    }
     156    else if (isset($_POST['size']) and isset($_POST['price']))
     157    {
     158      single_insert(
     159        PPPPP_SIZE_TABLE,
     160        array(
     161          'size' => pwg_db_real_escape_string($_POST['size']),
     162          'price' => pwg_db_real_escape_string($_POST['price']),
     163          )
     164        );
     165
     166      $page['infos'][] = l10n('Your configuration settings are saved');
     167    }
     168   
     169    $query='SELECT * FROM '.PPPPP_SIZE_TABLE.';';
     170    $result = pwg_query($query);
     171    while($row = pwg_db_fetch_assoc($result))
     172    {
     173      $template->append('ppppp_array_size',$row);
     174    }
     175   
     176    break;
     177
     178  case 'shipping':
     179   
     180    if (isset($_POST['fixed_shipping'])and is_numeric($_POST['fixed_shipping']))
     181    {
     182      $conf['PayPalShoppingCart']['fixed_shipping'] = $_POST['fixed_shipping'];
     183      conf_update_param('PayPalShoppingCart', $conf['PayPalShoppingCart']);
     184     
     185      $page['infos'][] = l10n('Your configuration settings are saved');
     186    }
     187   
     188    $template->assign('ppppp_fixed_shipping', $conf['PayPalShoppingCart']['fixed_shipping']);
     189    break;
     190}
    181191
    182192$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl'));
  • extensions/PayPalShoppingCart/main.inc.php

    r21205 r30179  
    6666define('PPPPP_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
    6767define('PPPPP_SIZE_TABLE', $prefixeTable.'ppppp_size');
    68 define('PPPPP_CONFIG_TABLE', $prefixeTable.'ppppp_config');
    69 define('PPPPP_VERSION', 'auto');
    70 
    7168
    7269function ppppp_append_form($tpl_source, &$smarty){
     
    122119 }
    123120
    124 function ppppp_picture_handler(){
     121function ppppp_picture_handler()
     122{
    125123  global $template, $conf, $page;
    126124
     
    146144  }   
    147145 
    148  $template->set_prefilter('picture', 'ppppp_append_form');
    149  load_language('plugin.lang', PPPPP_PATH);
    150  $query='SELECT * FROM '.PPPPP_SIZE_TABLE.' '.@$conf['PayPalShoppingCart_sizes_order_by'].';';
    151  $result = pwg_query($query);
    152  while($row = pwg_db_fetch_assoc($result)){
    153   $template->append('ppppp_array_size',$row);
     146  $template->set_prefilter('picture', 'ppppp_append_form');
     147  load_language('plugin.lang', PPPPP_PATH);
     148 
     149  $query='SELECT * FROM '.PPPPP_SIZE_TABLE.' '.@$conf['PayPalShoppingCart_sizes_order_by'].';';
     150  $result = pwg_query($query);
     151  while($row = pwg_db_fetch_assoc($result))
     152  {
     153    $template->append('ppppp_array_size',$row);
    154154  }
    155  $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'fixed_shipping\';';
    156  $result = pwg_query($query);
    157  $row = pwg_db_fetch_row($result);
    158  $template->assign('ppppp_fixed_shipping',$row[0]);
    159  $query='SELECT value FROM '.PPPPP_CONFIG_TABLE.' WHERE param = \'currency\';';
    160  $result = pwg_query($query);
    161  $row = pwg_db_fetch_row($result);
    162  $template->assign('ppppp_currency',$row[0]);
    163  
    164  $template->assign('ppppp_e_mail',get_webmaster_mail_address());
    165  }
     155
     156  $template->assign(
     157    array(
     158      'ppppp_fixed_shipping' => $conf['PayPalShoppingCart']['fixed_shipping'],
     159      'ppppp_currency' => $conf['PayPalShoppingCart']['currency'],
     160      'ppppp_e_mail' => get_webmaster_mail_address(),
     161     )
     162    );
     163}
    166164
    167165add_event_handler('loc_begin_picture', 'ppppp_picture_handler');
     
    205203/**
    206204 * plugin initialization
    207  *   - check for upgrades
    208205 *   - unserialize configuration
    209206 *   - load language
     
    211208function ppppp_init()
    212209{
    213   global $conf, $pwg_loaded_plugins;
    214  
    215   // apply upgrade if needed
    216   if (
    217     PPPPP_VERSION == 'auto' or
    218     $pwg_loaded_plugins[PPPPP_ID]['version'] == 'auto' or
    219     version_compare($pwg_loaded_plugins[PPPPP_ID]['version'], PPPPP_VERSION, '<')
    220   )
    221   {
    222     // call install function
    223     include_once(PPPPP_PATH.'include/install.inc.php');
    224     ppppp_install();
    225    
    226     // update plugin version in database
    227     if ( $pwg_loaded_plugins[PPPPP_ID]['version'] != 'auto' and PPPPP_VERSION != 'auto' )
    228     {
    229       $query = '
    230 UPDATE '. PLUGINS_TABLE .'
    231 SET version = "'. PPPPP_VERSION .'"
    232 WHERE id = "'. PPPPP_ID .'"';
    233       pwg_query($query);
    234      
    235       $pwg_loaded_plugins[PPPPP_ID]['version'] = PPPPP_VERSION;
    236      
    237       if (defined('IN_ADMIN'))
    238       {
    239         $_SESSION['page_infos'][] = 'PayPalShoppingCart plugin updated to version '. PPPPP_VERSION;
    240       }
    241     }
    242   }
     210  global $conf;
    243211 
    244212  // load plugin language file
     
    246214 
    247215  // prepare plugin configuration
    248   $conf['PayPalShoppingCart'] = unserialize($conf['PayPalShoppingCart']);
     216  $conf['PayPalShoppingCart'] = safe_unserialize($conf['PayPalShoppingCart']);
    249217}
    250218?>
Note: See TracChangeset for help on using the changeset viewer.