diff --git a/htdocs/admin/user.php b/htdocs/admin/user.php index 723a9f74e8db844276ef2f7ad41c0fd3d46cead8..4dd1cf421447c05e575aa1e72cfd26270e178fe2 100644 --- a/htdocs/admin/user.php +++ b/htdocs/admin/user.php @@ -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"> </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"> </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>'; diff --git a/htdocs/core/ajaxconstantonoff.php b/htdocs/core/ajaxconstantonoff.php new file mode 100644 index 0000000000000000000000000000000000000000..104f4b4fa1c4df88163eb88e33309df970aa593f --- /dev/null +++ b/htdocs/core/ajaxconstantonoff.php @@ -0,0 +1,65 @@ +<?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); + } + } +} + +?> diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php index 5be8794e3bc427cd0acc7947e345799206d099ec..37b2e0b032db5100e832700b85079d9265660039 100644 --- a/htdocs/lib/ajax.lib.php +++ b/htdocs/lib/ajax.lib.php @@ -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 ... diff --git a/htdocs/theme/auguria/style.css.php b/htdocs/theme/auguria/style.css.php index d1fd78a198c6020cf95c9f1c57ca1d8d692a3086..91fc347c16972507c86b73cc4a4d12dcaa1f973e 100644 --- a/htdocs/theme/auguria/style.css.php +++ b/htdocs/theme/auguria/style.css.php @@ -165,6 +165,8 @@ div.float float:<?php print $left; ?>; } +.hideobject { display: none; } +.linkobject { cursor: pointer; } /* For dragging lines */