<?php
/***********************************************************************
Copyright (C) 2005 Connor Dunn (Connorhd@mypunbb.com)
This software is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
************************************************************************/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;
// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
define('PLUGIN_VERSION',1.5);
function RoundSigDigs($number, $sigdigs) {
$multiplier = 1;
while ($number < 0.1) {
$number *= 10;
$multiplier /= 10;
}
while ($number >= 1) {
$number /= 10;
$multiplier *= 10;
}
return round($number, $sigdigs) * $multiplier;
}
if (isset($_POST['lang']))
{
// Update default lang
$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$_POST['form']['default_lang'].'\' WHERE conf_name="o_default_lang"') or error('Unable to update lang config', __FILE__, __LINE__, $db->error());
// Update lang
$db->query('UPDATE '.$db->prefix.'users SET language=\''.$_POST['form']['language'].'\'') or error('Unable to set lang settings', __FILE__, __LINE__, $db->error());
// Regenerate the config cache
require_once PUN_ROOT.'include/cache.php';
generate_config_cache();
redirect('admin_loader.php?plugin=AP_Langages_et_Styles.php');
}
elseif (isset($_POST['style']))
{
// Update default style
$db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$_POST['form']['default_style'].'\' WHERE conf_name="o_default_style"') or error('Unable to update style config', __FILE__, __LINE__, $db->error());
// Update style
$db->query('UPDATE '.$db->prefix.'users SET style=\''.$_POST['form']['style'].'\'') or error('Unable to set style settings', __FILE__, __LINE__, $db->error());
// Regenerate the config cache
require_once PUN_ROOT.'include/cache.php';
generate_config_cache();
redirect('admin_loader.php?plugin=AP_Langages_et_Styles.php');
}
else // If not, we show the form
{
// Display the admin navigation menu
generate_admin_menu($plugin);
?>
<div class="block">
<h2><span>Langages et Styles TST v.<?php echo PLUGIN_VERSION; ?></span></h2>
<div class="box">
<div class="inbox">
<p>Ce plugin permet de faire les réglages de styles et de langages.
<br />Impact : Configuration générale du forum et utilisateurs.</p>
</div>
</div>
</div>
<div class="blockform">
<h2 class="block2"><span>Langages</span></h2>
<div class="box">
<form id="lang" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<fieldset>
<legend>Langages</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Langage par défaut</th>
<td>
<select name="form[default_lang]">
<?php
$languages = array();
$d = dir(PUN_ROOT.'lang');
while (($entry = $d->read()) !== false)
{
if ($entry != '.' && $entry != '..' && is_dir(PUN_ROOT.'lang/'.$entry) && file_exists(PUN_ROOT.'lang/'.$entry.'/common.php'))
$languages[] = $entry;
}
$d->close();
@natsort($languages);
while (list(, $temp) = @each($languages))
{
if ($pun_config['o_default_lang'] == $temp)
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.$temp.'</option>'."\n";
else
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.$temp.'</option>'."\n";
}
?>
</select>
<span>Choisissez la langue par défaut qui sera utilisée par les invités ou les futurs membres.
<br />Attention : Si vous supprimez un pack de langage vous devrez mettre à jour ce réglage.</span>
</td>
</tr>
<tr>
<th scope="row">Utilisation des langages</th>
<td>
<?php
$result = $db->query('SELECT language, count(*) as number FROM '.$db->prefix.'users WHERE id > 1 GROUP BY language ORDER BY number') or error('Unable to fetch lang settings', __FILE__, __LINE__, $db->error());
$number = $db->num_rows($db->query('SELECT username from '.$db->prefix.'users WHERE id > 1'));
while ($cur_lang = $db->fetch_assoc($result)) {
echo RoundSigDigs($cur_lang['number'] / $number * 100,3).'% '.str_replace('_',' ',$cur_lang['language']).'<br>';
}
?>
</td>
</tr>
<tr>
<th scope="row">Initialiser langage</th>
<td>
<?php
$languages = array();
$d = dir(PUN_ROOT.'lang');
while (($entry = $d->read()) !== false)
{
if ($entry != '.' && $entry != '..' && is_dir(PUN_ROOT.'lang/'.$entry))
$languages[] = $entry;
}
$d->close();
?>
<select name="form[language]">
<?php
while (list(, $temp) = @each($languages))
{
if ($pun_config['o_default_lang'] == $temp)
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.$temp.'</option>'."\n";
else
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.$temp.'</option>'."\n";
}
?>
</select>
<span>Toutes les langues d'utilisateurs seront remises à zéro à cette option.</span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<p class="submitend"><input type="submit" name="lang" value="Initialiser !" tabindex="2" /></p>
</form>
</div>
</div>
<div class="blockform">
<h2 class="block2"><span>Styles</span></h2>
<div class="box">
<form id="style" method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<fieldset>
<legend>Styles</legend>
<div class="infldset">
<table class="aligntop" cellspacing="0">
<tr>
<th scope="row">Style par défaut</th>
<td>
<select name="form[default_style]">
<?php
$styles = array();
$d = dir(PUN_ROOT.'style');
while (($entry = $d->read()) !== false)
{
if (substr($entry, strlen($entry)-4) == '.css')
$styles[] = substr($entry, 0, strlen($entry)-4);
}
$d->close();
@natsort($styles);
while (list(, $temp) = @each($styles))
{
if ($pun_config['o_default_style'] == $temp)
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n";
else
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n";
}
?>
</select>
<span>Choisissez le style par défaut qui sera utilisée par les invités ou les futurs membres.
<br />Attention : Si vous supprimez un pack de style vous devrez mettre à jour ce réglage.</span>
</td>
</tr>
<tr>
<th scope="row">Utilisation des styles</th>
<td>
<?php
$result = $db->query('SELECT style, count(*) as number FROM '.$db->prefix.'users WHERE id > 1 GROUP BY style ORDER BY number') or error('Unable to fetch style settings', __FILE__, __LINE__, $db->error());
$number = $db->num_rows($db->query('SELECT username from '.$db->prefix.'users WHERE id > 1'));
while ($cur_lang = $db->fetch_assoc($result)) {
echo RoundSigDigs($cur_lang['number'] / $number * 100,3).'% '.str_replace('_',' ',$cur_lang['style']).'<br>';
}
?>
</td>
</tr>
<tr>
<th scope="row">Initialiser style</th>
<td>
<?php
$styles = array();
$d = dir(PUN_ROOT.'style');
while (($entry = $d->read()) !== false)
{
if (substr($entry, strlen($entry)-4) == '.css')
$styles[] = substr($entry, 0, strlen($entry)-4);
}
$d->close();
@natsort($styles);
?>
<select name="form[style]">
<?php
while (list(, $temp) = @each($styles))
{
if ($pun_config['o_default_style'] == $temp)
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'" selected="selected">'.str_replace('_', ' ', $temp).'</option>'."\n";
else
echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$temp.'">'.str_replace('_', ' ', $temp).'</option>'."\n";
}
?>
</select>
<span>Tous les styles d'utilisateurs seront remis à zéro à cette option.</span>
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<p class="submitend"><input type="submit" name="style" value="Initialiser !" tabindex="2" /></p>
</form>
</div>
</div>
<?php
}
?>