Fix: function is loaded once and not overwritten if loaded

by another ajax page. So if we need inputok/ko and pageyes/no to be
different according to ajax calls (to have several confirm box
loaded from different ajax parts of page, we must place such variables
outside of function. For this $useglobalvars must be set to 1.
This commit is contained in:
Laurent Destailleur 2012-06-08 23:48:53 +02:00
parent 1022c73c24
commit 158930eb7b
4 changed files with 26 additions and 28 deletions

View File

@ -93,34 +93,12 @@ if (preg_match('/\.\./',$upload_dir) || preg_match('/[<>|]/',$upload_dir))
}
/*
* Action
*/
/*
if ($action == 'remove_file') // Remove a file
{
clearstatcache();
// None
dol_syslog(__FILE__." remove $original_file $urlsource", LOG_DEBUG);
// This test should be useless. We keep it to find bug more easily
if (! file_exists($original_file_osencoded))
{
dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$_GET["file"]));
exit;
}
dol_delete_file($original_file);
dol_syslog(__FILE__." back to ".urldecode($urlsource), LOG_DEBUG);
header("Location: ".urldecode($urlsource));
return;
}
*/
/*
@ -260,6 +238,7 @@ if (! empty($conf->use_javascript_ajax) && empty($conf->global->MAIN_ECM_DISABLE
if ($section)
{
require_once(DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php');
$useglobalvars=1;
$form = new Form($db);
$formquestion=array('urlfile'=>array('type'=>'hidden','value'=>'','name'=>'urlfile'));
print $form->formconfirm(DOL_URL_ROOT.'/ecm/index.php'.($param?'?':'').(preg_replace('/^&/','',$param)),$langs->trans("DeleteFile"),$langs->trans("ConfirmDeleteFile"),'confirm_deletefile',$formquestion,"no",'deletefile');

View File

@ -2143,6 +2143,7 @@ class Form
function formconfirm($page, $title, $question, $action, $formquestion='', $selectedchoice="", $useajax=0, $height=170, $width=500)
{
global $langs,$conf;
global $useglobalvars;
$more='';
$formconfirm='';
@ -2241,13 +2242,13 @@ class Form
}
}
// New code using jQuery only
// Show JQuery confirm box. Note that global var $useglobalvars is used inside this template
include(DOL_DOCUMENT_ROOT.'/core/tpl/ajax/formconfirm.tpl.php');
}
else
{
$formconfirm.= "\n<!-- begin form_confirm page=".$page." -->\n";
$formconfirm.= '<form method="POST" action="'.$page.'" class="notoptoleftroright">'."\n";
$formconfirm.= '<input type="hidden" name="action" value="'.$action.'">';
$formconfirm.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n";
@ -2279,7 +2280,7 @@ class Form
$formconfirm.= "</form>\n";
$formconfirm.= '<br>';
$formconfirm.= "<!-- end form_confirm -->\n";
}

View File

@ -25,6 +25,20 @@
<?php echo img_help('','').' '.$question; ?>
</div>
<script type="text/javascript">
/*
* Warning: function is loaded once and not overwritten if loaded by another ajax page.
* So if we need inputok/ko and pageyes/no to be different according to ajax calls (to have several confirm box loaded
* from different ajax parts of page, we must place such variables outside of function. For this $useglobalvars must be set to 1.
*/
<?php if (! empty($useglobalvars)) { ?>
var inputok=<?php echo json_encode($inputok); ?>;
var inputko=<?php echo json_encode($inputko); ?>;
var pageyes='<?php echo dol_escape_js($pageyes?$pageyes:''); ?>';
var pageno='<?php echo dol_escape_js($pageno?$pageno:''); ?>';
<?php } ?>
$(function() {
$( "#<?php echo $dialogconfirm; ?>" ).dialog({
autoOpen: <?php echo ($autoOpen ? 'true' : 'false'); ?>,
@ -36,8 +50,10 @@ $(function() {
buttons: {
'<?php echo dol_escape_js($langs->transnoentities("Yes")); ?>': function() {
var options="";
var inputok = <?php echo json_encode($inputok); ?>;
<?php if (empty($useglobalvars)) { ?>
var inputok = <?php echo json_encode($inputok); ?>;
var pageyes = '<?php echo dol_escape_js($pageyes?$pageyes:''); ?>';
<?php } ?>
if (inputok.length>0) {
$.each(inputok, function(i, inputname) {
var more = '';
@ -54,8 +70,10 @@ $(function() {
},
'<?php echo dol_escape_js($langs->transnoentities("No")); ?>': function() {
var options = '';
<?php if (empty($useglobalvars)) { ?>
var inputko = <?php echo json_encode($inputko); ?>;
var pageno='<?php echo dol_escape_js($pageno?$pageno:''); ?>';
<?php } ?>
if (inputko.length>0) {
$.each(inputko, function(i, inputname) {
var more = '';

View File

@ -379,7 +379,7 @@ print $langs->trans("ECMAreaDesc2")."<br>";
print "<br>\n";
// Confirm remove file
if ($action == 'delete')
if ($action == 'delete' && empty($conf->use_javascript_ajax))
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"].'?section='.$section.'&urlfile='.urlencode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile','','',1);
if ($ret == 'html') print '<br>';