Ignore:
Timestamp:
08/21/08 21:06:15 (4 years ago)
Author:
hverton
Message:

Merged trunk revisions 1588:1665 into the PLi-Fusion branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PLi-Fusion/administration/settings_languages.php

    r1538 r1666  
    2828if (!checkrights("S8") || !defined("iAUTH") || $aid != iAUTH) fallback(BASEDIR."index.php"); 
    2929 
     30/*---------------------------------------------------+ 
     31| Local functions                                    | 
     32+----------------------------------------------------*/ 
     33function migrate($tablename, $fieldname, $from_setting, $to_setting) { 
     34    global $db_prefix, $settings; 
     35 
     36    if ($from_setting == "none" && $to_setting == "single") { 
     37        // not implemented yet 
     38    } elseif ($from_setting == "none" && $to_setting == "multiple") { 
     39        // set everything to the current locale 
     40        $result = dbquery("UPDATE ".$db_prefix.$tablename. " SET ".$fieldname." = '".$settings['locale_code']."'"); 
     41        // and copy it to all other active locales 
     42        $result = dbquery("SELECT * FROM ".$db_prefix."locale WHERE locale_code <> '".$settings['locale_code']."' AND locale_active = 1"); 
     43        while ($data = dbarray($result)) { 
     44            $result2 = dbquery("SELECT * FROM ".$db_prefix.$tablename); 
     45            while ($data2 = dbarray($result2)) { 
     46                $key = 0; 
     47                $fields = ""; 
     48                $values = ""; 
     49                foreach($data2 as $name => $value) { 
     50                    // skip the primary key 
     51                    if ($key++ == 0) continue; 
     52                    $fields .= ($fields == "" ? "" : ", ") . $name; 
     53                    if ($name == $fieldname) { 
     54                        $values .= ($values == "" ? "" : ", ") . "'".$data['locale_code']."'"; 
     55                    } else { 
     56                        $values .= ($values == "" ? "" : ", ") . "'".mysql_escape_string($value)."'"; 
     57                    } 
     58                } 
     59                // insert the duplicated record with the new locale code 
     60                $result3 = dbquery("INSERT INTO ".$db_prefix.$tablename." (".$fields.") VALUES (".$values.")"); 
     61            } 
     62        }    
     63    } elseif ($from_setting == "single" && $to_setting == "none") { 
     64        // not implemented yet 
     65    } elseif ($from_setting == "single" && $to_setting == "multiple") { 
     66        // not implemented yet 
     67    } elseif ($from_setting == "multiple" && $to_setting == "none") { 
     68        $result = dbquery("UPDATE ".$db_prefix.$tablename. " SET ".$fieldname." = ''"); 
     69    } elseif ($from_setting == "multiple" && $to_setting == "single") { 
     70        // not implemented yet 
     71    } else { 
     72        terminate("invalid migration strategy detected when migrating ".$tablename."!"); 
     73    } 
     74 
     75} 
     76 
     77/*---------------------------------------------------+ 
     78| Main code                                          | 
     79+----------------------------------------------------*/ 
     80 
    3081if (isset($_POST['savesettings'])) { 
    3182    // use browser language 
     
    4697    $panels_localisation = stripinput($_POST['panels_localisation']); 
    4798    if ($panels_localisation != $settings['panels_localisation']) { 
    48         // migration required 
     99        migrate('panels', 'panel_locale', $settings['panels_localisation'], $panels_localisation); 
    49100    } 
    50101    $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".$panels_localisation."' WHERE cfg_name = 'panels_localisation'"); 
     
    53104    $sitelinks_localisation = stripinput($_POST['sitelinks_localisation']); 
    54105    if ($sitelinks_localisation != $settings['sitelinks_localisation']) { 
    55         // migration required 
     106        migrate('site_links', 'link_locale', $settings['sitelinks_localisation'], $sitelinks_localisation); 
    56107    } 
    57108    $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".$sitelinks_localisation."' WHERE cfg_name = 'sitelinks_localisation'"); 
     
    60111    $news_localisation = stripinput($_POST['news_localisation']); 
    61112    if ($news_localisation != $settings['news_localisation']) { 
    62         // migration required 
     113        migrate('news', 'news_locale', $settings['news_localisation'], $news_localisation); 
     114        migrate('news_frontpage', 'frontpage_locale', $settings['news_localisation'], $news_localisation); 
    63115    } 
    64116    $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".$news_localisation."' WHERE cfg_name = 'news_localisation'"); 
     
    67119    $download_localisation = stripinput($_POST['download_localisation']); 
    68120    if ($download_localisation != $settings['download_localisation']) { 
    69         // migration required 
     121        migrate('download_cats', 'download_cat_locale', $settings['download_localisation'], $download_localisation); 
    70122    } 
    71123    $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".$download_localisation."' WHERE cfg_name = 'download_localisation'"); 
     
    74126    $article_localisation = stripinput($_POST['article_localisation']); 
    75127    if ($article_localisation != $settings['article_localisation']) { 
    76         // migration required 
     128        migrate('article', 'article_locale', $settings['article_localisation'], $download_localisation); 
    77129    } 
    78130    $result = dbquery("UPDATE ".$db_prefix."configuration SET cfg_value = '".$article_localisation."' WHERE cfg_name = 'article_localisation'"); 
Note: See TracChangeset for help on using the changeset viewer.