我正试图在SugarCRM中创建一个交互式安装程序,其中从manifest.php文件中调用的pre_execute.php脚本使用javascript弹出一个确认对话框,从那里,我将答案提供给php脚本(通过表单),以便就脚本应该做什么做出决定。
当没有从清单文件调用(示例) pre_execute.php脚本时,弹出对话框的结果将正确地反映在用户响应后脚本采取的操作中。
在安装期间从清单文件调用脚本时,我会显示javascript弹出确认框,但是弹出对话框的结果没有反映在脚本在用户响应后采取的操作中。
如果我在从清单文件中调用的脚本中包含弹出对话框,模块安装完成,显示“显示日志”的页面出现一段时间,但随后将被仅显示以下错误消息的屏幕替换:
未指定操作模式。
我从清单,php文件调用pre_execute.php文件
'pre_execute' => array
(
0 => '<basepath>/scripts/pre_execute.php',
),在$installdefs数组中
在我的pre_execute.php文件中(只要用户单击OK就创建一个文件,或者不创建一个文件就是用户单击Cancel)
<?php
// This is a custom script which will be run once before the copy instructions are followed
echo "Made it to the start of the pre_execute script <br />.";
// Store the current page so that it can be refreshed during the javascript feed of the user response to the server php script
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; }
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443")
{
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else
{
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
echo "The url for this page is $pageURL <br />";
// Pop up a dialog box asking the user if they want to continue the installation
// If not, terminate the install
$message = "Do you want to continue the installation? Click on OK to continue, Cancel to terminate.";
echo "<form action=$pageURL method='post'>";
echo "<input type='hidden' name='answer' id='answer'>";
echo "</form>";
$java_code = <<<EOJS
<script type="text/javascript">
var alert_message = "$message";
var response = document.getElementById("answer");
response.value = confirm(alert_message);
response.form.submit();
exit();
</script>
EOJS;
if ( ! isset($_POST['answer']) )
{
echo $java_code;
}
elseif ( $_POST['answer'] === 'false' )
{
echo "The user response was ".$_POST['answer']." so the script terminated.<br />";
die('User terminated installation');
}
else
{
echo "The user response was ".$_POST['answer']." so the script will continue.<br />";
// Create a new file with content (just to have something happen in this script)
$created_file_name = '/var/www/html/crm/custom/custom_script_pre_execute_created_file.txt';
$test_file_create = fopen($created_file_name,'x');
$file_content = <<<EOF
This is the content
Put into the pre-execute file
by the script.
EOF;
fwrite($test_file_create,$file_content);
fclose($test_file_create);
echo "The file $created_file_name has been created by the script. <br />";
// Return to the calling file which included this file
return;
}
?>所以,真正的问题是:我如何才能使一个弹出对话框不仅弹出(我正在工作),而且还能使它:-用户响应被正确捕获并在脚本中操作?-在安装完成后,使用弹出对话框不会产生错误?
发布于 2014-01-31 05:33:42
我认为在这个pre_execute时间内请求和接收/处理数据的方法是有缺陷的,或者至少比它所需要的更困难。您会考虑一个简单地回显消息并链接到配置页面的post_execute函数吗?您可以像index.php?module=MyNewModule&action=config一样访问配置页面(将文件命名为config.php并将其放到模块的目录中)。
您可以在开源SugarForge模块JJWDesign Google for SugarCRM http://www.sugarforge.org/projects/jjwgooglemaps/中找到这方面的示例(直接在v6.zip下载该模块)。
优点是,现在您在实际的页面上,您可以更容易地输出您的DHTML,并将数据发布到相同的页面进行处理。
https://stackoverflow.com/questions/21470649
复制相似问题