Skip to content
Snippets Groups Projects
Commit 2eded2f7 authored by Regis Houssin's avatar Regis Houssin
Browse files

Fix: uniformize code

New: ajax button on/off for constant
parent 455e69f0
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -37,38 +38,35 @@ $langs->load("users");
if (!$user->admin)
accessforbidden();
$typeconst=array('yesno','texte','chaine');
// Action mise a jour ou ajout d'une constante
if ($_POST["action"] == 'update' || $_POST["action"] == 'add')
{
$result=dolibarr_set_const($db, $_POST["constname"],$_POST["constvalue"],$typeconst[$_POST["consttype"]],0,isset($_POST["constnote"])?$_POST["constnote"]:'',$conf->entity);
if ($result < 0)
{
print $db->error();
}
}
// Action activation d'un sous module du module adherent
if ($_GET["action"] == 'set')
/*
* Action
*/
if (preg_match('/set_(.*)/',$action,$reg))
{
$result=dolibarr_set_const($db, $_GET["name"],$_GET["value"],'',0,'',$conf->entity);
if ($result < 0)
{
print $db->error();
}
$code=$reg[1];
if (dolibarr_set_const($db, $code, 1, 'chaine', 0, '', $conf->entity) > 0)
{
Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
dol_print_error($db);
}
}
// Action desactivation d'un sous module du module adherent
if ($_GET["action"] == 'unset')
if (preg_match('/del_(.*)/',$action,$reg))
{
$result=dolibarr_del_const($db,$_GET["name"],$conf->entity);
if ($result < 0)
{
print $db->error();
}
$code=$reg[1];
if (dolibarr_del_const($db, $code, $conf->entity) > 0)
{
Header("Location: ".$_SERVER["PHP_SELF"]);
exit;
}
else
{
dol_print_error($db);
}
}
......@@ -78,9 +76,6 @@ if ($_GET["action"] == 'unset')
llxHeader();
$var=True;
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print_fiche_titre($langs->trans("UsersSetup"),$linkback,'setup');
print "<br>";
......@@ -90,25 +85,36 @@ print_fiche_titre($langs->trans("MemberMainOptions"),'','');
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Description").'</td>';
print '<td>'.$langs->trans("Value").'</td>';
print '<td align="center">'.$langs->trans("Action").'</td>';
print "</tr>\n";
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="center" width="100">'.$langs->trans("Value").'</td>'."\n";
print '</tr>';
$var=true;
$form = new Form($db);
// Mail required for members
$var=!$var;
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="rowid" value="'.$rowid.'">';
print '<input type="hidden" name="constname" value="USER_MAIL_REQUIRED">';
print '<tr '.$bc[$var].'><td>'.$langs->trans("UserMailRequired").'</td><td>';
print $form->selectyesno('constvalue',$conf->global->USER_MAIL_REQUIRED,1);
print '</td><td align="center" width="80">';
print '<input type="submit" class="button" value="'.$langs->trans("Update").'" name="Button">';
print "</td></tr>\n";
print '</form>';
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("UserMailRequired").'</td>';
print '<td align="center" width="20">&nbsp;</td>';
print '<td align="center" width="100">';
if ($conf->use_javascript_ajax)
{
print ajax_constantonoff('USER_MAIL_REQUIRED');
}
else
{
if($conf->global->USER_MAIL_REQUIRED == 0)
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_USER_MAIL_REQUIRED">'.img_picto($langs->trans("Disabled"),'off').'</a>';
}
else if($conf->global->USER_MAIL_REQUIRED == 1)
{
print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_USER_MAIL_REQUIRED">'.img_picto($langs->trans("Enabled"),'on').'</a>';
}
}
print '</td></tr>';
print '</table>';
print '<br>';
......
<?php
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
*
* This program 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 program 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.
*/
/**
* \file htdocs/core/ajaxconstantonoff.php
* \brief File to set or del an on/off constant
* \version $Id$
*/
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
require('../main.inc.php');
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
/*
* View
*/
// Ajout directives pour resoudre bug IE
//header('Cache-Control: Public, must-revalidate');
//header('Pragma: public');
//top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header.
top_httphead();
print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
// Registering the location of boxes
if((isset($_GET['action']) && ! empty($_GET['action'])) && (isset($_GET['name']) && ! empty($_GET['name'])) )
{
if ($user->admin && ! $user->entity)
{
if ($_GET['action'] == 'set')
{
dolibarr_set_const($db, $_GET['name'], 1, 'chaine', 0, '', $conf->entity);
}
else if ($_GET['action'] == 'del')
{
dolibarr_del_const($db, $_GET['name'], $conf->entity);
}
}
}
?>
......@@ -213,6 +213,45 @@ function ajax_combobox($htmlname)
return $msg;
}
/**
* On/off button for constant
* @param code Name of constant
*/
function ajax_constantonoff($code)
{
global $conf, $langs;
$out= '<script type="text/javascript">
$(function() {
$( "#set_'.$code.'" ).click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajaxconstantonoff.php", {
action: \'set\',
name: \''.$code.'\'
},
function() {
$( "#set_'.$code.'" ).hide();
$( "#del_'.$code.'" ).show();
});
});
$( "#del_'.$code.'" ).click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajaxconstantonoff.php", {
action: \'del\',
name: \''.$code.'\'
},
function() {
$( "#del_'.$code.'" ).hide();
$( "#set_'.$code.'" ).show();
});
});
});
</script>';
$out.= '<div id="set_'.$code.'" class="linkobject '.($conf->global->$code?'hideobject':'').'">'.img_picto($langs->trans("Disabled"),'off').'</div>';
$out.= '<div id="del_'.$code.'" class="linkobject '.($conf->global->$code?'':'hideobject').'">'.img_picto($langs->trans("Enabled"),'on').'</div>';
return $out;
}
/**
*
* Enter description here ...
......
......@@ -165,6 +165,8 @@ div.float
float:<?php print $left; ?>;
}
.hideobject { display: none; }
.linkobject { cursor: pointer; }
/* For dragging lines */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment