home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Admin / ad_languages.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  26.4 KB  |  1,003 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Language functions
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 22nd April 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new ad_langs();
  26.  
  27.  
  28. class ad_langs {
  29.  
  30.     var $base_url;
  31.  
  32.     function ad_langs() {
  33.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  34.  
  35.         switch($IN['code'])
  36.         {
  37.             
  38.             case 'add':
  39.                 $this->add_language();
  40.                 break;
  41.                 
  42.             case 'edit':
  43.                 $this->do_form('edit');
  44.                 break;
  45.                 
  46.             case 'edit2':
  47.                 $this->show_file();
  48.                 break;
  49.                 
  50.             case 'doadd':
  51.                 $this->save_wrapper('add');
  52.                 break;
  53.                 
  54.             case 'doedit':
  55.                 $this->save_langfile();
  56.                 break;
  57.                 
  58.             case 'remove':
  59.                 $this->remove();
  60.                 break;
  61.                 
  62.             case 'editinfo':
  63.                 $this->edit_info();
  64.                 break;
  65.                 
  66.             case 'export':
  67.                 $this->export();
  68.                 break;
  69.                 
  70.             case 'import':
  71.                 $this->import();
  72.                 break;
  73.                 
  74.             case 'doimport':
  75.                 $this->doimport();
  76.                 break;
  77.                 
  78.             //-------------------------
  79.             default:
  80.                 $this->list_current();
  81.                 break;
  82.         }
  83.         
  84.     }
  85.     
  86.     function doimport()
  87.     {
  88.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  89.         
  90.         if ($IN['tarball'] == "")
  91.         {
  92.             $ADMIN->error("You did not select a tar-chive to import!");
  93.         }
  94.         
  95.         require $root_dir."sources/lib/tar.php";
  96.         
  97.         $to_dir = $INFO['base_dir']."/lang";
  98.         
  99.         $tarname = $IN['tarball'];
  100.         
  101.         $from_dir = $INFO['base_dir']."/archive_in";
  102.         
  103.         $tar = new tar();
  104.         
  105.         //------------------------------
  106.         
  107.         $real_name = preg_replace( "/^lang-(\S+)\.tar$/", "\\1", $IN['tarball'] );
  108.         
  109.         $real_name = preg_replace( "/_/", " ", $real_name );
  110.         
  111.         //------------------------------
  112.         
  113.         $tar->new_tar( $from_dir, $tarname );
  114.         
  115.         $files = $tar->list_files();
  116.         
  117.         if (count($files) > 0)
  118.         {
  119.             foreach($files as $giles)
  120.             {
  121.                 if ( ! preg_match( "/^(?:[\.\w\d\+\-\_\/]+)$/", $giles) )
  122.                 {
  123.                     $ADMIN->error("$tarname is possibly corrupted, please re-upload in binary");
  124.                 }
  125.             }
  126.         }
  127.         else
  128.         {
  129.             $ADMIN->error("$tarname is not a valid tar-chive");
  130.         }
  131.         
  132.         $DB->query("INSERT INTO ibf_languages (ldir, lname) VALUES('temp', '$real_name (Import)')");
  133.         
  134.         $new_id = $DB->get_insert_id();
  135.         
  136.         //-------------------------
  137.         // attempt to make new dir
  138.         //-------------------------
  139.         
  140.         $dest = $to_dir."/".$new_id;
  141.         
  142.         if ( ! mkdir($dest, 0777) )
  143.         {
  144.             $DB->query("DELETE FROM ibf_languages WHERE lid='$new_id'");
  145.             
  146.             $ADMIN->error("Could not create a new directory in $to_dir, please give sufficient CHMOD permissions to allow this");
  147.         }
  148.         
  149.         //------------------------------
  150.         // Extract the tarball
  151.         //------------------------------
  152.         
  153.         $tar->extract_files($dest);
  154.         
  155.         if ($tar->error != "")
  156.         {
  157.             $DB->query("DELETE FROM ibf_languages WHERE lid='$new_id'");
  158.             
  159.             $ADMIN->error( $tar->error );
  160.         }
  161.         
  162.         $extra = array( 'lauthor' => "", 'lemail' => "" );
  163.         
  164.         if (file_exists($dest."/conf.inc"))
  165.         {
  166.             require $dest."/conf.inc";
  167.         
  168.             $extra['lauthor'] = stripslashes($config['lauthor']);
  169.             $extra['lemail']  = stripslashes($config['lemail']);
  170.             
  171.         }
  172.         
  173.         $extra['ldir'] = $new_id;
  174.         
  175.         $db_string = $DB->compile_db_update_string($extra);
  176.         
  177.         $DB->query("UPDATE ibf_languages SET $db_string WHERE lid='$new_id'");
  178.         
  179.         $ADMIN->done_screen("Language Pack Export Imported", "Manage Language Sets", "act=lang" );
  180.         
  181.     }
  182.     
  183.     //--------------------------------------------
  184.     
  185.     function import()
  186.     {
  187.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  188.     
  189.         $ADMIN->page_detail = "The tar-chive that you wish to import must reside in 'archive_in' and be a valid tar-chive uploaded in binary format.";
  190.         $ADMIN->page_title  = "Language Pack Import";
  191.         
  192.         //+-------------------------------
  193.         
  194.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'      , 'doimport'    ),
  195.                                                   2 => array( 'act'       , 'lang'      ),
  196.                                          )      );
  197.                                          
  198.         //+-------------------------------
  199.         
  200.         $SKIN->td_header[] = array( " " , "50%" );
  201.         $SKIN->td_header[] = array( " " , "50%" );
  202.  
  203.         //+-------------------------------
  204.         
  205.         $ADMIN->html .= $SKIN->start_table( "Choose a tar-chive to import" );
  206.         
  207.         $files = $ADMIN->get_tar_names("lang-");
  208.         
  209.         $form_array = array();
  210.         
  211.         if (count($files) > 0)
  212.         {
  213.             foreach($files as $piles)
  214.             {
  215.                 $form_array[] = array( $piles, $piles );
  216.             }
  217.         }
  218.         
  219.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Tar-chive to import...</b>" ,
  220.                                           $SKIN->form_dropdown( "tarball", $form_array  )
  221.                                  )      );
  222.     
  223.         $ADMIN->html .= $SKIN->end_form("Import!");
  224.                                          
  225.         $ADMIN->html .= $SKIN->end_table();
  226.         
  227.         $ADMIN->output();
  228.     
  229.     
  230.     }
  231.     
  232.     
  233.     //--------------------------------------------
  234.     
  235.     
  236.     function export()
  237.     {
  238.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  239.         
  240.         if ($IN['id'] == "")
  241.         {
  242.             $ADMIN->error("You must specify an existing language set ID, go back and try again");
  243.         }
  244.         
  245.         //+-------------------------------
  246.         
  247.         $DB->query("SELECT * from ibf_languages WHERE lid='".$IN['id']."'");
  248.         
  249.         if ( ! $row = $DB->fetch_row() )
  250.         {
  251.             $ADMIN->error("Could not query the information from the database");
  252.         }
  253.         
  254.         //+-------------------------------
  255.         
  256.         $archive_dir = $INFO['base_dir']."/archive_out";
  257.         $lang_dir    = $INFO['base_dir']."/lang/".$row['ldir'];
  258.         
  259.         require $root_dir."sources/lib/tar.php";
  260.         
  261.         if (!is_dir($archive_dir))
  262.         {
  263.             $ADMIN->error("Could not locate $archive_dir, is the directory there?");
  264.         }
  265.         
  266.         if (!is_writeable($archive_dir))
  267.         {
  268.             $ADMIN->error("Cannot write in $archive_dir, CHMOD via FTP to 0755 or 0777 to enable this script to write into it. IBF cannot do this for you");
  269.         }
  270.         
  271.         if (!is_dir($lang_dir))
  272.         {
  273.             $ADMIN->error("Could not locate $lang_dir, is the directory there?");
  274.         }
  275.         
  276.         //+-------------------------------
  277.         // Attempt to copy the files to the
  278.         // working directory...
  279.         //+-------------------------------
  280.         
  281.         $l_name = preg_replace( "/\s{1,}/", "_", $row['lname'] );
  282.         
  283.         $new_dir = "lang-".$l_name;
  284.         
  285.         if ( ! $ADMIN->copy_dir($lang_dir, $archive_dir."/".$new_dir) )
  286.         {
  287.             $ADMIN->error( $ADMIN->errors );
  288.         }
  289.         
  290.         // Generate the config file..
  291.         
  292.         $file_content = "<?php\n\n\$config=array('lauthor' => \"".addslashes($row['lauthor'])."\", 'lemail'=>\"".addslashes($row['lemail'])."\")\n\n?".">";
  293.         
  294.         $FH = fopen($archive_dir."/".$new_dir."/"."conf.inc", 'w');
  295.         fwrite($FH, $file_content, strlen($file_content));
  296.         fclose($FH);
  297.         
  298.         // Add files and write tarball
  299.         
  300.         $tar = new tar();
  301.         
  302.         $tar->new_tar( $archive_dir, $new_dir.".tar" );
  303.         $tar->add_directory( $archive_dir."/".$new_dir );
  304.         $tar->write_tar();
  305.         
  306.         // Check for errors.
  307.         
  308.         if ($tar->error != "")
  309.         {
  310.             $ADMIN->error($tar->error);
  311.         }
  312.         
  313.         // remove original unarchived directory
  314.         
  315.         $ADMIN->rm_dir($archive_dir."/".$new_dir);
  316.         
  317.         $ADMIN->done_screen("Language Pack Export Created<br><br>You can download the tar-chive <a href='archive_out/{$new_dir}.tar'>here</a>", "Manage Language Sets", "act=lang" );
  318.         
  319.         
  320.     }
  321.     
  322.     
  323.     
  324.     
  325.     
  326.     function show_file()
  327.     {
  328.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  329.         
  330.         if ($IN['id'] == "")
  331.         {
  332.             $ADMIN->error("You must specify an existing language set ID, go back and try again");
  333.         }
  334.         
  335.         //+-------------------------------
  336.         
  337.         $DB->query("SELECT * from ibf_languages WHERE lid='".$IN['id']."'");
  338.         
  339.         if ( ! $row = $DB->fetch_row() )
  340.         {
  341.             $ADMIN->error("Could not query the information from the database");
  342.         }
  343.         
  344.         //+-------------------------------
  345.         
  346.         $lang_dir = $INFO['base_dir']."lang/".$row['ldir'];
  347.         
  348.         $form_array = array();
  349.         
  350.         $lang_file = $lang_dir."/".$IN['lang_file'];
  351.     
  352.         
  353.         if ( ! is_writeable($lang_dir) )
  354.         {
  355.             $ADMIN->error("Cannot write into '$lang_dir', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  356.         }
  357.         
  358.         if (! file_exists($lang_file) )
  359.         {
  360.             $ADMIN->error("Cannot locate {$IN['lang_file']} in '$lang_dir', please go back and check the input");
  361.         }
  362.         else
  363.         {
  364.             require $lang_file;
  365.         }
  366.         
  367.         if ($IN['lang_file'] == 'email_content.php')
  368.         {
  369.             $lang = $EMAIL;
  370.         }
  371.         
  372.         if ( ! is_writeable($lang_file) )
  373.         {
  374.             $ADMIN->error("Cannot write to '$lang_file', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  375.         }
  376.     
  377.     
  378.         $ADMIN->page_detail = "You may edit any of the language information below.";
  379.         $ADMIN->page_title  = "Edit Language set: ".$row['lname'];
  380.         
  381.         //+-------------------------------
  382.         
  383.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'      , 'doedit'    ),
  384.                                                   2 => array( 'act'       , 'lang'      ),
  385.                                                   3 => array( 'id'        , $IN['id']   ),
  386.                                                   4 => array( 'lang_file' , $IN['lang_file']   ),
  387.                                          )      );
  388.                                          
  389.         //+-------------------------------
  390.         
  391.         $SKIN->td_header[] = array( "Block Name" , "20%" );
  392.         $SKIN->td_header[] = array( "Content"    , "80%" );
  393.  
  394.         //+-------------------------------
  395.         
  396.         $ADMIN->html .= $SKIN->start_table( "Language Text: ".$IN['lang_file'] );
  397.                                          
  398.         foreach($lang as $k => $v)
  399.         {
  400.             
  401.                 
  402.             //+-------------------------------
  403.             // Swop < and > into ascii entities
  404.             // to prevent textarea breaking html
  405.             //+-------------------------------
  406.             
  407.             $v = stripslashes($v);
  408.             
  409.             $v = preg_replace("/&/", "&", $v );
  410.             $v = preg_replace("/</", "<", $v );
  411.             $v = preg_replace("/>/", ">", $v );
  412.             $v = preg_replace("/'/", "'", $v );
  413.             
  414.             if ($IN['lang_file'] == 'email_content.php')
  415.             {
  416.                 $rows = 15;
  417.             
  418.                 $cols = 70;
  419.                     
  420.                 $ADMIN->html .= $SKIN->add_td_row( array( 
  421.                                                     "<ibf.lang.<b>".$k."</b>>",
  422.                                                     $SKIN->form_textarea('XX_'.$k, $v, $cols, $rows),
  423.                                          )      );
  424.             }
  425.             else
  426.             {
  427.                 $ADMIN->html .= $SKIN->add_td_row( array( 
  428.                                                     "<ibf.lang.<b>".$k."</b>>",
  429.                                                     $SKIN->form_input('XX_'.$k, $v),
  430.                                          )      );
  431.             }
  432.                 
  433.         }
  434.                                          
  435.  
  436.                                                  
  437.         $ADMIN->html .= $SKIN->end_form("Edit this file");
  438.                                          
  439.         $ADMIN->html .= $SKIN->end_table();
  440.         
  441.         //+-------------------------------
  442.         //+-------------------------------
  443.         
  444.         $ADMIN->output();
  445.         
  446.         
  447.     }
  448.     
  449.     //-------------------------------------------------------------
  450.     // Edit language pack information
  451.     //-------------------------------------------------------------
  452.     
  453.     function edit_info()
  454.     {
  455.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  456.         
  457.         if ($IN['id'] == "")
  458.         {
  459.             $ADMIN->error("You must specify an existing language set ID, go back and try again");
  460.         }
  461.         
  462.         //+-------------------------------
  463.         
  464.         $DB->query("SELECT * from ibf_languages WHERE lid='".$IN['id']."'");
  465.         
  466.         if ( ! $row = $DB->fetch_row() )
  467.         {
  468.             $ADMIN->error("Could not query the information from the database");
  469.         }
  470.         
  471.         $final['lname'] = stripslashes($HTTP_POST_VARS['lname']);
  472.         
  473.         if (isset($HTTP_POST_VARS['lname']))
  474.         {
  475.             $final['lauthor'] = stripslashes($HTTP_POST_VARS['lauthor']);
  476.             $final['lemail']  = stripslashes($HTTP_POST_VARS['lemail']);
  477.         }
  478.         
  479.         $db_string = $DB->compile_db_update_string( $final );
  480.         
  481.         $DB->query("UPDATE ibf_languages SET $db_string WHERE lid='".$IN['id']."'");
  482.         
  483.         $ADMIN->done_screen("Language pack information updated", "Manage language sets", "act=lang" );
  484.         
  485.     }
  486.     
  487.     //-------------------------------------------------------------
  488.     // Add language pack
  489.     //-------------------------------------------------------------
  490.     
  491.     
  492.     function add_language()
  493.     {
  494.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  495.         
  496.         if ($IN['id'] == "")
  497.         {
  498.             $ADMIN->error("You must specify an existing language set ID, go back and try again");
  499.         }
  500.         
  501.         
  502.         $DB->query("SELECT * FROM ibf_languages WHERE lid='".$IN['id']."'");
  503.         
  504.         //-------------------------------------
  505.         
  506.         if ( ! $row = $DB->fetch_row() )
  507.         {
  508.             $ADMIN->error("Could not query that language set from the DB, so there");
  509.         }
  510.         
  511.         //-------------------------------------
  512.         
  513.         //-------------------------------------
  514.         
  515.         if ( ! is_writeable($root_path.'lang') )
  516.         {
  517.             $ADMIN->error("The directory 'lang' is not writeable by this script. Please check the permissions on that directory. CHMOD to 0777 if in doubt and try again");
  518.         }
  519.         
  520.         //-------------------------------------
  521.         
  522.         if ( ! is_dir($root_path.'lang/'.$row['ldir']) )
  523.         {
  524.             $ADMIN->error("Could not locate the original language set to copy, please check and try again");
  525.         }
  526.         
  527.         //-------------------------------------
  528.         
  529.         $row['lname'] = $row['lname'].".2";
  530.         
  531.         // Insert a new row into the DB...
  532.         
  533.         $final = array();
  534.         
  535.         foreach($row as $k => $v)
  536.         {
  537.             if ($k == 'lid')
  538.             {
  539.                 continue;
  540.             }
  541.             else
  542.             {
  543.                 $final[ $k ] = $v;
  544.             }
  545.         }
  546.         
  547.         $db_string = $DB->compile_db_insert_string( $final );
  548.         
  549.         $DB->query("INSERT INTO ibf_languages (".$db_string['FIELD_NAMES'].") VALUES(".$db_string['FIELD_VALUES'].")");
  550.         
  551.         $new_id = $DB->get_insert_id();
  552.         
  553.         //-------------------------------------
  554.         
  555.         if ( ! $ADMIN->copy_dir( $INFO['base_dir'].'lang/'.$row['ldir'] , $INFO['base_dir'].'lang/'.$new_id ) )
  556.         {
  557.             $DB->query("DELETE FROM ibf_languages WHERE lid='$new_id'");
  558.             
  559.             $ADMIN->error( $ADMIN->errors );
  560.         }
  561.         else
  562.         {
  563.             $DB->query("UPDATE ibf_languages SET ldir='$new_id' WHERE lid='$new_id'");
  564.         }
  565.         
  566.         //-------------------------------------
  567.         // Pass to edit / add form...
  568.         //-------------------------------------
  569.         
  570.         $this->do_form('add', $new_id);
  571.     
  572.     }
  573.     
  574.     //-------------------------------------------------------------
  575.     // REMOVE WRAPPERS
  576.     //-------------------------------------------------------------
  577.     
  578.     function remove()
  579.     {
  580.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  581.         
  582.         //+-------------------------------
  583.         
  584.         
  585.         if ($IN['id'] == "")
  586.         {
  587.             $ADMIN->error("You must specify an existing image set ID, go back and try again");
  588.         }
  589.         
  590.         if ($IN['id'] == 1)
  591.         {
  592.             $ADMIN->error("You cannot remove this language pack.");
  593.         }
  594.         
  595.         $DB->query("SELECT * from ibf_languages WHERE lid='".$IN['id']."'");
  596.         
  597.         if ( ! $row = $DB->fetch_row() )
  598.         {
  599.             $ADMIN->error("Could not query the language information from the database");
  600.         }
  601.         
  602.         if ( $ADMIN->rm_dir( $INFO['base_dir']."lang/".$row['ldir'] ) )
  603.         {
  604.         
  605.             $DB->query("DELETE FROM ibf_languages WHERE lid='".$IN['id']."'");
  606.             
  607.             $std->boink_it($SKIN->base_url."&act=lang");
  608.             exit();
  609.         }
  610.         else
  611.         {
  612.             $ADMIN->error("Could not remove the language pack files, please check the CHMOD permissions to ensure that this script has the correct permissions to allow this");
  613.         }
  614.     }
  615.     
  616.     
  617.     
  618.     //-------------------------------------------------------------
  619.     // ADD / EDIT IMAGE SETS
  620.     //-------------------------------------------------------------
  621.     
  622.     function save_langfile()
  623.     {
  624.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  625.         
  626.         //+-------------------------------
  627.         
  628.         if ($IN['id'] == "")
  629.         {
  630.             $ADMIN->error("You must specify an existing language set ID, go back and try again");
  631.         }
  632.         
  633.         if ($IN['lang_file'] == "")
  634.         {
  635.             $ADMIN->error("You must specify an existing language filename, go back and try again");
  636.         }
  637.     
  638.         $DB->query("SELECT * from ibf_languages WHERE lid='".$IN['id']."'");
  639.         
  640.         if ( ! $row = $DB->fetch_row() )
  641.         {
  642.             $ADMIN->error("Could not query the language information from the database");
  643.         }
  644.         
  645.         $lang_file = $root_path."lang/".$row['ldir']."/".$IN['lang_file'];
  646.         
  647.         if (! file_exists( $lang_file ) )
  648.         {
  649.             $ADMIN->error("Could not locate $lang_file, is it there?");
  650.         }
  651.         
  652.         if (! is_writeable( $lang_file ) )
  653.         {
  654.             $ADMIN->error("Cannot write to $lang_file, please chmod to 0666 or better and try again");
  655.         }
  656.         
  657.         $barney = array();
  658.         
  659.         foreach ($IN as $k => $v)
  660.         {
  661.             if ( preg_match( "/^XX_(\S+)$/", $k, $match ) )
  662.             {
  663.                 if ( isset($IN[ $match[0] ]) )
  664.                 {
  665.                     $v = preg_replace("/'/", "'", stripslashes($HTTP_POST_VARS[ $match[0] ]) );
  666.                     $v = preg_replace("/</", "<",  $v );
  667.                     $v = preg_replace("/>/", ">", $v );
  668.                     $v = preg_replace("/&/", "&", $v );
  669.                     $v = preg_replace("/\r/", "", $v );
  670.                 
  671.                     $barney[ $match[1] ] = $v;
  672.                 }
  673.             }
  674.         }
  675.         
  676.         if ( count($barney) < 1 )
  677.         {
  678.             $ADMIN->error("Oopsie, something has gone wrong - did you leave all the fields blank?");
  679.         }
  680.         
  681.         $start = "<?php\n\n";
  682.         
  683.         if ($IN['lang_file'] == 'email_content.php')
  684.         {
  685.             foreach($barney as $key => $text)
  686.             {
  687.                 $text = preg_replace("/n{1,}$/", "", $text);
  688.                 $start .= "\n".'$EMAIL['."'$key'".'] = <<<EOF'."\n".$text."\nEOF;\n";
  689.             }
  690.         }
  691.         else
  692.         {
  693.             foreach($barney as $key => $text)
  694.             {
  695.                 $start .= "\n".'$lang['."'$key'".']  = "'.addslashes($text).'";';
  696.             }
  697.         }
  698.         
  699.         $start .= "\n\n?".">";
  700.         
  701.         if ($fh = fopen( $lang_file, 'w') )
  702.         {
  703.             fwrite($fh, $start, strlen($start) );
  704.             fclose($fh);
  705.         }
  706.         else
  707.         {
  708.             $ADMIN->error("Could not write back to $lang_file");
  709.         }
  710.         
  711.         $ADMIN->done_screen("Set updated", "Manage Language Sets", "act=lang" );
  712.         
  713.         
  714.         
  715.     }
  716.     
  717.     //-------------------------------------------------------------
  718.     // EDIT SPLASH
  719.     //-------------------------------------------------------------
  720.     
  721.     function do_form( $method='add', $id="" )
  722.     {
  723.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  724.         
  725.         //+-------------------------------
  726.         
  727.         if ($id != "")
  728.         {
  729.             $IN['id'] = $id;
  730.         }
  731.         
  732.         //+-------------------------------
  733.         
  734.         if ($IN['id'] == "")
  735.         {
  736.             $ADMIN->error("You must specify an existing language set ID, go back and try again");
  737.         }
  738.         
  739.         //+-------------------------------
  740.         
  741.         $DB->query("SELECT * from ibf_languages WHERE lid='".$IN['id']."'");
  742.         
  743.         if ( ! $row = $DB->fetch_row() )
  744.         {
  745.             $ADMIN->error("Could not query the information from the database");
  746.         }
  747.         
  748.         //+-------------------------------
  749.         
  750.         $lang_dir = $INFO['base_dir']."lang/".$row['ldir'];
  751.         
  752.         $form_array = array();
  753.     
  754.         if ($method != 'add')
  755.         {
  756.             if ( ! is_writeable($lang_dir) )
  757.             {
  758.                 $ADMIN->error("Cannot write into '$lang_dir', please check the CHMOD value, and if needed, CHMOD to 0777 via FTP. IBF cannot do this for you.");
  759.             }
  760.         }
  761.         
  762.         //+-------------------------------
  763.         
  764.         if ( is_dir($lang_dir) )
  765.         {
  766.             $handle = opendir($lang_dir);
  767.             
  768.             while (($filename = readdir($handle)) !== false)
  769.             {
  770.                 if (($filename != ".") && ($filename != ".."))
  771.                 {
  772.                     if (preg_match("/^index/", $filename))
  773.                     {
  774.                         continue;
  775.                     }
  776.                     
  777.                     if (preg_match("/\.php$/", $filename))
  778.                     {
  779.                         $form_array[] = array( $filename, preg_replace( "/\.php$/", "", $filename ) );
  780.                     }
  781.                 }
  782.             }
  783.                 
  784.             closedir($handle);
  785.         }
  786.         
  787.         if ($row['lauthor'] and $row['lemail'])
  788.         {
  789.             $author = "<br><br>This language set <b>'{$row['lname']}'</b> was created by <a href='mailto:{$row['lemail']}' target='_blank'>{$row['lauthor']}</a>";
  790.         }
  791.         else if ($row['lauthor'])
  792.         {
  793.             $author = "<br><br>This language set <b>'{$row['lname']}'</b> was created by {$row['lauthor']}";
  794.         }
  795.         
  796.         //+-------------------------------
  797.     
  798.         $ADMIN->page_detail = "Please choose which language section you wish to edit below.$author $url";
  799.         $ADMIN->page_title  = "Edit Language set";
  800.         
  801.         //+-------------------------------
  802.         
  803.         //+-------------------------------
  804.         
  805.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'editinfo'    ),
  806.                                                   2 => array( 'act'   , 'lang'       ),
  807.                                                   3 => array( 'id'    , $IN['id']     ),
  808.                                          )      );
  809.                                          
  810.         //+-------------------------------
  811.         
  812.         $SKIN->td_header[] = array( " "   , "60%" );
  813.         $SKIN->td_header[] = array( " "   , "40%" );
  814.  
  815.         //+-------------------------------
  816.         
  817.         $ADMIN->html .= $SKIN->start_table( "Edit language set information" );
  818.         
  819.                                          
  820.         $ADMIN->html .= $SKIN->add_td_row( array( 
  821.                                                     "<b>Language Set Name</b>",
  822.                                                     $SKIN->form_input('lname', $row['lname']),
  823.                                          )      );
  824.                                          
  825.         if ($method == 'add')
  826.         {
  827.                                          
  828.             $ADMIN->html .= $SKIN->add_td_row( array( 
  829.                                                         "<b>Language set author name:</b>",
  830.                                                         $SKIN->form_input('lauthor', $row['lauthor']),
  831.                                              )      );
  832.                                              
  833.             $ADMIN->html .= $SKIN->add_td_row( array( 
  834.                                                         "<b>Language set author email:</b>",
  835.                                                         $SKIN->form_input('lemail', $row['lemail']),
  836.                                              )      );
  837.                                              
  838.         }
  839.                                          
  840.         $ADMIN->html .= $SKIN->end_form("Edit language set details");
  841.                                          
  842.         $ADMIN->html .= $SKIN->end_table();
  843.                                          
  844.         //+-------------------------------
  845.         //+-------------------------------
  846.         
  847.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'edit2'    ),
  848.                                                   2 => array( 'act'   , 'lang'     ),
  849.                                                   3 => array( 'id'    , $IN['id']   ),
  850.                                          )      );
  851.                                          
  852.         //+-------------------------------
  853.         
  854.         $SKIN->td_header[] = array( " "   , "60%" );
  855.         $SKIN->td_header[] = array( " "   , "40%" );
  856.  
  857.         //+-------------------------------
  858.         
  859.         $ADMIN->html .= $SKIN->start_table( "Edit language files in set '".$row['lname']."'" );
  860.         
  861.         $ADMIN->html .= $SKIN->add_td_row( array( 
  862.                                                     "<b>Please select a language file to edit</b>",
  863.                                                     $SKIN->form_dropdown('lang_file', $form_array),
  864.                                          )      );
  865.                                          
  866.         $ADMIN->html .= $SKIN->end_form("Edit this language file");
  867.                                          
  868.         $ADMIN->html .= $SKIN->end_table();
  869.                                          
  870.         //+-------------------------------
  871.         //+-------------------------------
  872.         
  873.         $ADMIN->output();
  874.         
  875.     }
  876.     
  877.     //-------------------------------------------------------------
  878.     // SHOW ALL LANGUAGE PACKS
  879.     //-------------------------------------------------------------
  880.     
  881.     function list_current()
  882.     {
  883.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  884.         
  885.         $form_array = array();
  886.     
  887.         $ADMIN->page_detail = "You can edit, remove and create new language packs from this section";
  888.         $ADMIN->page_title  = "Manage Language Sets";
  889.         
  890.         //+-------------------------------
  891.         
  892.         $DB->query("select ibf_languages.*, count(ibf_members.id) as mcount from ibf_languages left join ibf_members on(ibf_members.language=ibf_languages.ldir) where (ibf_members.language is not null or ibf_members.language = 'en') group by ibf_languages.ldir order by ibf_languages.lname");
  893.         
  894.         
  895.         $used_ids = array();
  896.         $show_array = array();
  897.         
  898.         if ( $DB->get_num_rows() )
  899.         {
  900.         
  901.             $SKIN->td_header[] = array( "Title"        , "40%" );
  902.             $SKIN->td_header[] = array( "Members"      , "30%" );
  903.             $SKIN->td_header[] = array( "Export"       , "10%" );
  904.             $SKIN->td_header[] = array( "Edit"         , "10%" );
  905.             $SKIN->td_header[] = array( "Remove"       , "10%" );
  906.         
  907.             $ADMIN->html .= $SKIN->start_table( "Current Language Packs In Use" );
  908.             
  909.             while ( $r = $DB->fetch_row() )
  910.             {
  911.             
  912.                 $show_array[ $r['lid'] ] .= stripslashes($r['lname'])."<br>";
  913.             
  914.                 if ( in_array( $r['lid'], $used_ids ) )
  915.                 {
  916.                     continue;
  917.                 }
  918.                 
  919.                 $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['lname'])."</b>",
  920.                                                           "<center>{$r['mcount']}</center>",
  921.                                                           "<center><a href='".$SKIN->base_url."&act=lang&code=export&id={$r['lid']}'>Export</a></center>",
  922.                                                           "<center><a href='".$SKIN->base_url."&act=lang&code=edit&id={$r['lid']}'>Edit</a></center>",
  923.                                                           "<i>Deallocate before removing</i>",
  924.                                                  )      );
  925.                                                    
  926.                 $used_ids[] = $r['lid'];
  927.                 
  928.                 $form_array[] = array( $r['lid'], $r['lname'] );
  929.                 
  930.             }
  931.             
  932.             $ADMIN->html .= $SKIN->end_table();
  933.         }
  934.         
  935.         if ( count($used_ids) < 1 )
  936.         {
  937.             $used_ids[] = '0';
  938.         }
  939.             $DB->query("SELECT lid, ldir, lname FROM ibf_languages WHERE lid NOT IN(".implode(",",$used_ids).")");
  940.         
  941.             if ( $DB->get_num_rows() )
  942.             {
  943.             
  944.                 $SKIN->td_header[] = array( "Title"  , "40%" );
  945.                 $SKIN->td_header[] = array( "Export" , "10%" );
  946.                 $SKIN->td_header[] = array( "Edit"   , "30%" );
  947.                 $SKIN->td_header[] = array( "Remove" , "20%" );
  948.             
  949.                 $ADMIN->html .= $SKIN->start_table( "Current Unallocated Language Packs" );
  950.                 
  951.                 $ADMIN->html .= $SKIN->js_checkdelete();
  952.                 
  953.                 while ( $r = $DB->fetch_row() )
  954.                 {
  955.                     
  956.                     $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['lname'])."</b>",
  957.                                                                "<center><a href='".$SKIN->base_url."&act=lang&code=export&id={$r['lid']}'>Export</a></center>",
  958.                                                               "<center><a href='".$SKIN->base_url."&act=lang&code=edit&id={$r['lid']}'>Edit</a></center>",
  959.                                                               "<center><a href='javascript:checkdelete(\"act=lang&code=remove&id={$r['lid']}\")'>Remove</a></center>",
  960.                                                      )      );
  961.                                                      
  962.                     $form_array[] = array( $r['lid'], $r['lname'] );
  963.                                                        
  964.                 }
  965.                 
  966.                 $ADMIN->html .= $SKIN->end_table();
  967.             }
  968.         //}
  969.         
  970.         //+-------------------------------
  971.         //+-------------------------------
  972.         
  973.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'add'     ),
  974.                                                   2 => array( 'act'   , 'lang'    ),
  975.                                          )      );
  976.         
  977.         $SKIN->td_header[] = array( " "  , "40%" );
  978.         $SKIN->td_header[] = array( " "  , "60%" );
  979.         
  980.         $ADMIN->html .= $SKIN->start_table( "Create Language Set" );
  981.             
  982.         //+-------------------------------
  983.         
  984.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Base new language set on...</b>" ,
  985.                                                     $SKIN->form_dropdown( "id", $form_array)
  986.                                  )      );
  987.         
  988.         $ADMIN->html .= $SKIN->end_form("Create new Language set");
  989.                                          
  990.         $ADMIN->html .= $SKIN->end_table();
  991.         
  992.         //+-------------------------------
  993.         //+-------------------------------
  994.         
  995.         $ADMIN->output();
  996.     
  997.     }
  998.     
  999.     
  1000. }
  1001.  
  1002.  
  1003. ?>