[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_admin/ -> language.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     ©Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvsroot/e107/e107_0.7/e107_admin/language.php,v $
  14  |     $Revision: 1.37 $
  15  |     $Date: 2006/11/06 10:46:23 $
  16  |     $Author: e107coders $
  17  +----------------------------------------------------------------------------+
  18  */
  19  require_once ("../class2.php");
  20  if (!getperms("ML"))
  21  {
  22      header("location:".e_BASE."index.php");
  23      exit;
  24  }
  25  
  26  $e_sub_cat = 'language';
  27  
  28  require_once ("auth.php");
  29  require_once(e_HANDLER."form_handler.php");
  30  $rs = new form;
  31  
  32  $tabs = table_list(); // array("news","content","links");
  33  $lanlist = explode(",",e_LANLIST);
  34  $message = "";
  35  
  36  if (e_QUERY) {
  37      $tmp = explode('.', e_QUERY);
  38      $action = $tmp[0];
  39      $sub_action = $tmp[1];
  40      $id = $tmp[2];
  41      unset($tmp);
  42  }
  43  
  44  if (isset($_POST['submit_prefs']) && isset($_POST['mainsitelanguage'])) {
  45  
  46      $pref['multilanguage']    = $_POST['multilanguage'];
  47      if($_POST['multilanguage_subdomain']){
  48          $pref['multilanguage_subdomain'] = ".".$_POST['multilanguage_subdomain'];
  49      }else{
  50          $pref['multilanguage_subdomain'] = "";
  51      }
  52  
  53      $pref['sitelanguage'] = $_POST['mainsitelanguage'];
  54  
  55      save_prefs();
  56      $ns->tablerender(LAN_SAVED, "<div style='text-align:center'>".LAN_SETSAVED."</div>");
  57  
  58  }
  59  
  60  
  61  // ----------------- delete tables ---------------------------------------------
  62  if (isset($_POST['del_existing']) && $_POST['lang_choices']) {
  63  
  64      $lang = strtolower($_POST['lang_choices']);
  65      foreach ($tabs as $del_table) {
  66          if (db_Table_exists($lang."_".$del_table)) {
  67              $qry = "DROP TABLE ".$mySQLprefix."lan_".$lang."_".$del_table;
  68          echo $qry;
  69              $message .= (mysql_query($qry)) ? $_POST['lang_choices']." ".$del_table." deleted<br />" :
  70               $_POST['lang_choices']." $del_table couldn't be deleted<br />";
  71          }
  72      }
  73      global $cachevar;
  74      unset($cachevar['table_list']);
  75  
  76  }
  77  
  78  // ----------create tables -----------------------------------------------------
  79  
  80  if (isset($_POST['create_tables']) && $_POST['language']) {
  81  
  82      $table_to_copy = array();
  83      $lang_to_create = array();
  84  
  85  
  86      foreach ($tabs as $value) {
  87          $lang = strtolower($_POST['language']);
  88          if (isset($_POST[$value])) {
  89              $copdata = ($_POST['copydata_'.$value]) ? 1 : 0;
  90              if (copy_table($value, "lan_".$lang."_".$value, $_POST['drop'],$copdata)) {
  91                  $message .= " ".$_POST['language']." ".$value." created<br />";
  92              } else {
  93                  $message .= (!$_POST['drop'])? " ".$_POST['language']." ".$value." ".LANG_LAN_00."<br />" : $_POST['language']." ".$value." ".LANG_LAN_01."<br />";
  94              }
  95          } elseif(db_Table_exists($lang."_".$value)) {
  96              if ($_POST['remove']) {
  97                  // Remove table.
  98                  $message .= (mysql_query("DROP TABLE ".$mySQLprefix."lan_".$lang."_".$value)) ? $_POST['language']." ".$value." ".LAN_DELETED."<br />" :  $_POST['language']." $value ".LANG_LAN_02."<br />";
  99              } else {
 100                  // leave table.
 101                  $message = $_POST['language']." ".$value." was disabled but left intact.";
 102              }
 103          }
 104      }
 105      global $cachevar;
 106      unset($cachevar['table_list']);
 107  }
 108  
 109  
 110  
 111      if(isset($message) && $message){
 112            $ns->tablerender(LAN_OK, $message);
 113      }
 114  
 115  
 116  
 117  unset($text);
 118  
 119  
 120  if (!e_QUERY || $action == 'main' && !$_POST['language'] && !$_POST['edit_existing']) {
 121      multilang_prefs();
 122  }
 123  
 124  if ($action == 'db') {
 125      multilang_db();
 126  }
 127  
 128  if($action == "tools"){
 129      show_tools();
 130  }
 131  
 132  
 133  
 134  
 135  
 136  // Grab Language configuration. ---
 137  if ($_POST['edit_existing']) {
 138  
 139      $text .= "
 140      <form method='post' action='".e_SELF."?db' >
 141      <div style='text-align:center'>
 142      <table class='fborder' style='".ADMIN_WIDTH."'>\n";
 143  
 144      foreach ($tabs as $table_name) {
 145          $installed = strtolower($_POST['lang_choices'])."_".$table_name;
 146          if (stristr($_POST['lang_choices'], $installed) === FALSE) {
 147              $text .= "<tr>
 148                  <td style='width:30%' class='forumheader3'>".ucfirst(str_replace("_", " ", $table_name))."</td>\n
 149                  <td style='width:70%' class='forumheader3'>\n";
 150              $selected = (db_Table_exists($installed)) ? "checked='checked'" : "";
 151              $text .= "<input type=\"checkbox\" id='$table_name' name=\"$table_name\" value=\"1\" $selected onclick=\"if(document.getElementById('$table_name').checked){document.getElementById('datacopy_$table_name').style.display = '';} \"  />";
 152              $text .= "<span id='datacopy_$table_name' style='display:none'>".LANG_LAN_15."<input type=\"checkbox\" name=\"copydata_$table_name\" value=\"1\" /> </span>";
 153              $text .= "</td></tr>\n";
 154          }
 155      }
 156  
 157      $text .= "
 158      <tr><td class='forumheader3' colspan='2'>&nbsp;
 159      <input type='hidden' name='language' value='".$_POST['lang_choices']."' />
 160      </td></tr>";
 161  
 162      // ===========================================================================
 163  
 164      // Drop tables ?
 165      $text .= "<tr><td class='forumheader3'><b>".LANG_LAN_07."</b></td>
 166          <td class='forumheader3'>".$rs->form_checkbox("drop", 1)."\n
 167          <span class=\"smalltext\" >".LANG_LAN_08."</span></td></tr>\n
 168  
 169          <tr>
 170              <td class='forumheader3'><b>".LANG_LAN_10."</b></td>
 171              <td class='forumheader3'>".$rs->form_checkbox("remove", 1)."\n
 172                 <span class=\"smalltext\" >".LANG_LAN_11."</span></td>
 173          </tr>
 174  
 175          <tr>
 176              <td colspan='2' style='width:100%; text-align: center;' class='forumheader' >";
 177  
 178              $button_capt = LANG_LAN_06. " / ". LAN_UPDATE;
 179              $text .="<input type='submit' class='button' name='create_tables' value=\"".$button_capt."\" />";
 180  
 181         $text .="</td>
 182          </tr>
 183  
 184      </table></div>\n";
 185  
 186      $text .= $rs->form_close();
 187      $ns->tablerender($_POST['lang_choices'], $text);
 188  }
 189  
 190  require_once(e_ADMIN."footer.php");
 191  
 192  // ---------------------------------------------------------------------------
 193  function multilang_prefs() {
 194      global $ns, $pref,$lanlist;
 195  
 196      $text = "<div style='text-align:center'>
 197          <form method='post' action='".e_SELF."' id='linkform'>
 198          <table style='".ADMIN_WIDTH."' class='fborder'>";
 199  
 200  
 201      $text .= "<tr>
 202  
 203          <td style='width:80%' class='forumheader3'>".LANG_LAN_14.": </td>
 204          <td style='width:20%; text-align:center' class='forumheader3'>";
 205  
 206  
 207      $text .= "
 208          <select name='mainsitelanguage' class='tbox'>\n";
 209          $sellan = preg_replace("/lan_*.php/i", "", $pref['sitelanguage']);
 210          foreach($lanlist as $lan){
 211              $sel =  ($lan == $sellan) ? "selected='selected'" : "";
 212              $text .= "<option value='{$lan}' {$sel}>".$lan."</option>\n";
 213          }
 214  
 215      $text .= "</select>
 216          </td>
 217          </tr>";
 218  
 219      $text .= "
 220          <tr>
 221          <td style='width:80%' class='forumheader3'>".LANG_LAN_12.": </td>
 222          <td style='width:20%;text-align:center' class='forumheader3'>";
 223      $checked = ($pref['multilanguage'] == 1) ? "checked='checked'" : "";
 224      $text .= "<input type='checkbox' name='multilanguage'   value='1' $checked />
 225          </td>
 226          </tr>
 227          ";
 228  
 229      $text .= "
 230      <tr>
 231      <td style='width:80%' class='forumheader3'>".LANG_LAN_18."<br />
 232      <span class='smalltext'>".LANG_LAN_19."<br />".LANG_LAN_20."</span></td>
 233      <td style='width:20%;text-align:center' class='forumheader3'>www.";
 234      $text .= "<input class='tbox' type='text' name='multilanguage_subdomain'   value=\"".substr($pref['multilanguage_subdomain'],1)."\" />
 235      </td>
 236      </tr>
 237      ";
 238  
 239  
 240      $text .= "<tr style='vertical-align:top'>
 241          <td colspan='2' style='text-align:center' class='forumheader'>";
 242      $text .= "<input class='button' type='submit' name='submit_prefs' value='".LAN_SAVE."' />";
 243      $text .= "</td>
 244          </tr>
 245          </table>
 246          </form>
 247          </div>";
 248  
 249      $caption = LANG_LAN_13; // "Language Preferences";
 250      $ns->tablerender($caption, $text);
 251  }
 252  
 253  // ----------------------------------------------------------------------------
 254  
 255  function db_Table_exists($table)
 256  {
 257      global $mySQLdefaultdb;
 258      $tables = getcachedvars("table_list");
 259      if(!$tables)
 260      {
 261          $tablist = mysql_list_tables($mySQLdefaultdb);
 262          while($tmp = mysql_fetch_array($tablist))
 263          {
 264              $tables[] = $tmp[0];
 265          }
 266          cachevars("table_list", $tables);
 267      }
 268      return in_array(strtolower(MPREFIX."lan_".$table), $tables);
 269  }
 270  // ----------------------------------------------------------------------------
 271  
 272  function copy_table($oldtable, $newtable, $drop = FALSE, $data = FALSE)
 273  {
 274      global $sql;
 275      $old = MPREFIX.strtolower($oldtable);
 276      $new = MPREFIX.strtolower($newtable);
 277      if($drop)
 278      {
 279          $sql->db_Select_gen("DROP TABLE IF EXISTS {$new}");
 280      }
 281  
 282      //Get $old table structure
 283      $sql->db_Select_gen('SET SQL_QUOTE_SHOW_CREATE = 1');
 284      $qry = "SHOW CREATE TABLE {$old}";
 285      if($sql->db_Select_gen($qry))
 286      {
 287          $row = $sql->db_Fetch();
 288          $qry = $row[1];
 289          $qry = str_replace($old, $new, $qry);
 290      }
 291      $result = mysql_query($qry);
 292      if(!$result)
 293      {
 294          return FALSE;
 295      }
 296      if ($data)  //We need to copy the data too
 297      {
 298          $qry = "INSERT INTO {$new} SELECT * FROM {$old}";
 299          $sql->db_Select_gen($qry);
 300      }
 301      return TRUE;
 302  }
 303  
 304  // ----------------------------------------------------------------------------
 305  
 306  function table_list() {
 307      // grab default language lists.
 308      global $mySQLdefaultdb;
 309  
 310      $exclude[] = "banlist";        $exclude[] = "banner";
 311      $exclude[] = "cache";        $exclude[] = "core";
 312      $exclude[] = "online";        $exclude[] = "parser";
 313      $exclude[] = "plugin";        $exclude[] = "user";
 314      $exclude[] = "upload";        $exclude[] = "userclass_classes";
 315      $exclude[] = "rbinary";        $exclude[] = "session";
 316      $exclude[] = "tmp";             $exclude[] = "flood";
 317      $exclude[] = "stat_info";    $exclude[] = "stat_last";
 318      $exclude[] = "submit_news";    $exclude[] = "rate";
 319      $exclude[] = "stat_counter";$exclude[] = "user_extended";
 320      $exclude[] = "user_extended_struc";
 321      $exclude[] = "pm_messages";
 322      $exclude[] = "pm_blocks";
 323  
 324      $tables = mysql_list_tables($mySQLdefaultdb);
 325  
 326      while (list($temp) = mysql_fetch_array($tables))
 327      {
 328          if(strpos($temp, MPREFIX) === 0)
 329          {
 330              $e107tab = str_replace(MPREFIX, "", $temp);
 331              if (!in_array($e107tab, $exclude) && stristr($e107tab, "lan_") === FALSE)
 332              {
 333                  $tabs[] = $e107tab;
 334              }
 335          }
 336      }
 337  
 338      return $tabs;
 339  }
 340  
 341  
 342  // ------------- render form ---------------------------------------------------
 343  function multilang_db(){
 344      global $pref,$ns,$tp,$rs,$lanlist,$tabs;
 345  
 346      if(isset($pref['multilanguage']) && $pref['multilanguage']){
 347          $caption = LANG_LAN_16; // language
 348          $text = MLAD_LAN_4."<br /><br />";
 349  
 350  
 351          // Choose Language to Edit:
 352          $text = "<div style='text-align:center'>
 353          <div style='".ADMIN_WIDTH.";margin-left: auto; margin-right: auto;'>
 354          <table class='fborder' style='width:99%; margin-top: 1px;'>
 355          <tr><td class='fcaption'>".ADLAN_132."</td>
 356          <td class='fcaption'>".LANG_LAN_03."</td>
 357          <td class='fcaption'>".LAN_OPTIONS."</td>
 358          </tr>\n\n";
 359          sort($lanlist);
 360          for($i = 0; $i < count($lanlist); $i++)
 361          {
 362              $installed = 0;
 363  
 364              $text .= "<tr><td class='forumheader3' style='width:30%'>".$lanlist[$i]."</td><td class='forumheader3'>\n";
 365              foreach ($tabs as $tab_name) {
 366                  if (db_Table_exists(strtolower($lanlist[$i])."_".$tab_name)) {
 367                      $text .= $tab_name.", ";
 368                      $installed++;
 369                  }
 370              }
 371              if($lanlist[$i] == $pref['sitelanguage']){
 372                  $text .= "<div style='text-align:center'><i>".LANG_LAN_17."</i></div>";
 373              }else{
 374                  $text .= (!$installed)? "<div style='text-align:center'><i>".LANG_LAN_05."</i></div>" : "";
 375              }
 376              $text .= "</td><td class='forumheader3' style='width:20%;white-space:nowrap;text-align:right'>\n";
 377              $text .= $rs->form_open("post", e_SELF."?modify", "lang_form_".str_replace(" ", "_", $lanlist[$i]));
 378              $text .= "<div style='text-align: center'>\n";
 379                 if ($installed) {
 380                  $text .= " <input type='submit' class='button' name='edit_existing' value='".LAN_EDIT."' />\n";
 381                     $text .= " <input type='submit' class='button' name='del_existing' value='".LAN_DELETE."' onclick=\"return jsconfirm('Delete all tables in ".$lanlist[$i]." ?')\" />\n";
 382              } elseif($lanlist[$i] != $pref['sitelanguage']) {
 383                  $text .= "<input type='submit' class='button' name='edit_existing' value='".LAN_CREATE."' />\n";
 384              }
 385              $text .= "<input type='hidden' name='lang_choices' value='".$lanlist[$i]."' />";
 386                 $text .= "</div>";
 387              $text .= $rs->form_close();
 388              $text .= "</td></tr>";
 389          }
 390  
 391          $text .= "</table></div></div>";
 392  
 393          $ns->tablerender($caption, $text);
 394      }
 395  }
 396  
 397  
 398  // ----------------------------------------------------------------------------
 399  
 400  function show_tools()
 401  {
 402      global $ns;
 403  
 404      include_lan(e_LANGUAGEDIR.e_LANGUAGE."/admin/lan_lancheck.php");
 405  
 406      $text .= "
 407      <form name='lancheck' method='post' action='".e_ADMIN."lancheck.php'>
 408      <table class='fborder' style='".ADMIN_WIDTH."'>
 409      <tr>
 410      <td class='fcaption'>".LAN_CHECK_1."</td>
 411      <td class='forumheader3' style='text-align:center'>
 412      <select name='language' class='tbox'>
 413      <option value=''>".LAN_SELECT."</option>";
 414  
 415      $languages = explode(",",e_LANLIST);
 416      sort($languages);
 417  
 418      foreach($languages as $lang)
 419      {
 420          if($lang != "English")
 421          {
 422                 $text .= "<option value='{$lang}' >{$lang}</option>\n";
 423          }
 424      }
 425  
 426      $text .= "
 427      </select>
 428      <input type='submit' name='language_sel' value=\"".LAN_CHECK_2."\" class='button' />
 429      </td></tr>
 430      </table></form>";
 431  
 432      $ns->tablerender(LANG_LAN_21, $text);
 433  }
 434  
 435  
 436  // ----------------------------------------------------------------------------
 437  
 438  function language_adminmenu() {
 439      global $action,$pref;
 440      if ($action == "") {
 441          $action = "main";
 442      }
 443  
 444      if($action == "modify"){
 445          $action = "db";
 446      }
 447      $var['main']['text'] = LAN_PREFS;
 448      $var['main']['link'] = e_SELF;
 449  
 450      if(isset($pref['multilanguage']) && $pref['multilanguage']){
 451          $var['db']['text'] = LANG_LAN_03;
 452          $var['db']['link'] = e_SELF."?db";
 453      }
 454  
 455      $lcnt = explode(",",e_LANLIST);
 456      if(count($lcnt) > 1)
 457      {
 458          $var['tools']['text'] = ADLAN_CL_6;
 459          $var['tools']['link'] = e_SELF."?tools";
 460      }
 461  
 462      show_admin_menu(ADLAN_132, $action, $var);
 463  }
 464  
 465  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7