| Current Path : /var/www/homesaver/www/bitrix/modules/webdebug.excel/admin/ |
| Current File : /var/www/homesaver/www/bitrix/modules/webdebug.excel/admin/wd_excel2_popup.php |
<?
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
CModule::IncludeModule('webdebug.excel');
IncludeModuleLangFile(__FILE__);
$obJSPopup = new CJSPopup();
$obJSPopup->ShowTitlebar(GetMessage("WEBDEBUG_EXCEL_AJAX_WINDOW_TITLE"));
?>
<script src="/bitrix/js/webdebug.excel/jquery.1.10.2.min.js"></script>
<script src="/bitrix/js/webdebug.excel/jquery.form.min.js"></script>
<script src="/bitrix/js/webdebug.excel/jquery.textchange.js"></script>
<?if(ToLower(CWebdebugExcel2::substr($_GET['str_URI'],0,14))!='/bitrix/admin/'):?>
<link rel="stylesheet" type="text/css" href="/bitrix/themes/.default/webdebug.excel.css" />
<?endif?>
<script>
var WD_ExcelPath = [];
</script>
<form action="/bitrix/admin/wd_excel2_do.php" method="post" enctype="multipart/form-data" name="wd_excel2_popup_form" id="wd_excel2_popup_form">
<div id="wd_excel2_cols_wrapper">
<div id="wd_excel2_cols">
<div id="wd_excel2_cols_maincol">
<div id="wd_excel2_cols_content">
<div class="field_profile">
<p class="label"><?=GetMessage('WEBDEBUG_EXCEL_AJAX_FIELD_PROFILE')?></p>
<?
$arProfiles = array();
if (CModule::IncludeModule("webdebug.excel")) {
$resProfiles = CWebdebugExcel2Profile::GetList(array("SORT"=>"ASC"),array("ACTIVE"=>"Y"));
while ($arProfile = $resProfiles->GetNext()) {
$arProfiles[] = $arProfile;
}
}
?>
<script>
<?foreach($arProfiles as $arProfile):?>
WD_ExcelPath['p_<?=$arProfile['ID']?>'] = '<?=str_replace('\\','/',$arProfile['FILE']);?>';
<?endforeach?>
</script>
<select name="profile" id="wd_excel2_profile_selector">
<option value=""><?=GetMessage('WEBDEBUG_EXCEL_AJAX_FIELD_PROFILE_EMPTY')?></option>
<?foreach($arProfiles as $arProfile):?>
<option value="<?=$arProfile["ID"]?>"<?if($_REQUEST["default_profile"]==$arProfile["ID"]):?> selected="selected"<?endif?>>[<?=$arProfile["ID"]?>] <?=$arProfile["NAME"]?><?if(isset($_SESSION["WEBDEBUG"]["EXCEL"]["STATUS"][$arProfile["ID"]]) && is_array($_SESSION["WEBDEBUG"]["EXCEL"]["STATUS"][$arProfile["ID"]]) && !empty($_SESSION["WEBDEBUG"]["EXCEL"]["STATUS"][$arProfile["ID"]])):?><?=GetMessage('WEBDEBUG_EXCEL_AJAX_PROFILE_STARTED')?><?endif?></option>
<?endforeach?>
</select>
</div>
<br/>
<div class="field_profile">
<p class="label"><?=GetMessage('WEBDEBUG_EXCEL_AJAX_FIELD_FILE')?></p>
<br/>
<div>
<p class="small"><?=GetMessage('WEBDEBUG_EXCEL_AJAX_FIELD_FILE_SITE')?></p>
<?CAdminFileDialog::ShowScript(Array(
'event' => 'WDOpenExcelFile',
'arResultDest' => array('FORM_NAME' => 'wd_excel2_popup_form', 'FORM_ELEMENT_NAME' => 'wd_excel2_file_site'),
'arPath' => array(),
'select' => 'F',
'operation' => 'O',
'showUploadTab' => true,
'showAddToMenuTab' => false,
'fileFilter' => 'xls,xlsx,gz',
'allowAllFiles' => true,
'saveConfig' => true,
));?>
<input type="text" name="wd_excel2_file_site" id="wd_excel2_file_site" value="" />
<input type="button" value="..." id="wd_excel2_file_comp_open" onclick="WDOpenExcelFile()" title="<?=GetMessage('WEBDEBUG_EXCEL_AJAX_FIELD_FILE_DESC')?>" />
</div>
<br/>
<div>
<p class="small"><?=GetMessage('WEBDEBUG_EXCEL_AJAX_FIELD_FILE_COMP')?></p>
<input type="file" name="wd_excel2_file_comp" id="wd_excel2_file_comp" />
<script>
$('#wd_excel2_file_site').bind('textchange',function(){
var WDFileParent = $('#wd_excel2_file_comp').parent();
var WDOldFileInput = $('#wd_excel2_file_comp');
var WDNewFileInput = WDOldFileInput.clone();
WDOldFileInput.remove();
WDFileParent.append(WDNewFileInput);
$('#wd_excel2_file_comp').change(function(){
$('#wd_excel2_file_site').val('');
});
}).change(function(){
$(this).trigger('textchange');
});
$('#wd_excel2_file_comp').change(function(){
$('#wd_excel2_file_site').val('');
});
</script>
</div>
<br/>
</div>
<div class="field_submit">
<hr/>
<div id="wd_excel2_export">
<div>
<input type="checkbox" id="wd_excel2_checkbox_export" name="export" value="Y" />
<label for="wd_excel2_checkbox_export"><?=GetMessage('WEBDEBUG_EXCEL_CHECKBOX_EXPORT')?></label>
</div>
<div>
<input type="checkbox" id="wd_excel2_checkbox_colors" name="colors" value="Y" />
<label for="wd_excel2_checkbox_colors"><?=GetMessage('WEBDEBUG_EXCEL_CHECKBOX_COLORS')?></label>
</div>
</div>
<hr/><br/>
<input type="hidden" name="begin" value="Y" />
<input type="submit" id="wd_excel2_btn_submit" value="<?=GetMessage('WEBDEBUG_EXCEL_AJAX_BUTTON_START')?>" class="adm-btn-green" />
<input type="button" id="wd_excel2_btn_cancel" value="<?=GetMessage('WEBDEBUG_EXCEL_AJAX_BUTTON_STOP')?>" disabled="disabled" />
</div>
</div>
</div>
<div id="wd_excel2_cols_right">
<div id="wd_excel2_ajax_container">
<?=GetMessage('WEBDEBUG_EXCEL_DEFAULT_AJAX_CONTAINER')?>
</div>
</div>
<div id="wd_excel2_cols_clear"></div>
</div>
</div>
</form>
<script>
$('#wd_excel2_checkbox_colors').change(function(){
if ($(this).is(':checked')) {
var ExportChecked = $('#wd_excel2_checkbox_export').is(':checked');
$('#wd_excel2_checkbox_export').attr('checked-old', ExportChecked?'Y':'N').attr('disabled','disabled');
$('#wd_excel2_checkbox_export').each(function(){
this.checked = true;
})
} else {
if ($('#wd_excel2_checkbox_export').attr('checked-old')=='Y') {
$('#wd_excel2_checkbox_export').attr('checked','checked');
} else {
$('#wd_excel2_checkbox_export').removeAttr('checked');
}
$('#wd_excel2_checkbox_export').removeAttr('disabled');
}
});
var WDExcel2AJAX = false;
function SetInputsDisabled(Flag) {
if (Flag===true) {
$('#wd_excel2_popup_form').removeClass('wd_excel_loading');
$('#wd_excel2_btn_submit').removeAttr('disabled');
$('#wd_excel2_btn_cancel').attr('disabled','disabled');
$('#wd_excel2_checkbox_export').removeAttr('disabled');
$('#wd_excel2_checkbox_colors').removeAttr('disabled');
$('#wd_excel2_profile_selector').removeAttr('disabled');
$('#wd_excel2_file_site').removeAttr('disabled');
$('#wd_excel2_file_comp_open').removeAttr('disabled');
$('#wd_excel2_file_comp').removeAttr('disabled');
} else {
$('#wd_excel2_popup_form').addClass('wd_excel_loading');
$('#wd_excel2_btn_submit').attr('disabled','disabled');
$('#wd_excel2_btn_cancel').removeAttr('disabled');
$('#wd_excel2_checkbox_export').attr('disabled','disabled');
$('#wd_excel2_checkbox_colors').attr('disabled','disabled');
$('#wd_excel2_profile_selector').attr('disabled','disabled');
$('#wd_excel2_file_site').attr('disabled','disabled');
$('#wd_excel2_file_comp_open').attr('disabled','disabled');
$('#wd_excel2_file_comp').attr('disabled','disabled');
}
}
document.getElementById('wd_excel2_popup_form').onsubmit = null;
// Form plugin
$('#wd_excel2_popup_form').submit(function(){
// Check profile selected
if ($.trim($('#wd_excel2_profile_selector').val())=='') {
alert('<?=GetMessage('WEBDEBUG_EXCEL_ERROR_NOPROFILE');?>');
return false;
}
// Check file format
var FileNameSite = $('#wd_excel2_file_site').val().toLowerCase();
var FileSiteValid = $.trim(FileNameSite)!='' && (FileNameSite.substr(-4)=='.xls' || FileNameSite.substr(-5)=='.xlsx' || FileNameSite.substr(-7)=='.tar.gz');
var FileNameComp = $('#wd_excel2_file_comp').val().toLowerCase();
var FileCompValid = $.trim(FileNameComp)!='' && (FileNameComp.substr(-4)=='.xls' || FileNameComp.substr(-5)=='.xlsx' || FileNameComp.substr(-7)=='.tar.gz');
if (!FileSiteValid && !FileCompValid) {
alert('<?=GetMessage('WEBDEBUG_EXCEL_ERROR_FILE_FORMAT');?>');
return false;
}
});
$('#wd_excel2_popup_form').ajaxForm({
beforeSend: function() {
$('#wd_excel2_ajax_container').html('<?=GetMessage('WEBDEBUG_EXCEL_LOADING_START');?>').removeAttr('stopping').attr('loading','loading');
SetInputsDisabled(false);
},
uploadProgress: function(event, position, total, percentComplete) {},
success: function() {},
complete: function(xhr) {
WebdebugExcel2_CheckResultActions(xhr.responseText);
}
});
// Cancel click
$('#wd_excel2_btn_cancel').click(function(){
$('#wd_excel2_ajax_container').attr('stopping','stopping');
if ($('#wd_excel2_ajax_container').attr('loading')!='loading') {
SetInputsDisabled(true);
$('#wd_excel2_ajax_container').html('<?=GetMessage('WEBDEBUG_EXCEL_STOPPED');?>');
}
if (WDExcel2AJAX!=false && WDExcel2AJAX.abort) {
WDExcel2AJAX.abort();
}
});
function var_dump(obj) {
var result = '';
for (var i in obj) {
if (obj != "")
result += obj + '.' + i + ' = ' + obj[i] + '\n';
else
result += i + ' = ' + obj[i] + '\n';
}
return result;
}
// Auto fill profile file
$('#wd_excel2_profile_selector').change(function(){
$('#wd_excel2_file_site').val(WD_ExcelPath['p_'+$(this).val()]);
}).change();
// Check actions after result
function WebdebugExcel2_CheckResultActions(HTML) {
// insert result HTML
$('#wd_excel2_ajax_container').html(HTML);
// if success done
if ($('#wd_excel2_ajax_container').find('input[name=wd_excel2_next]').size()==0) {
SetInputsDisabled(true);
}
if ($('#wd_excel2_ajax_container').attr('stopping')=='stopping') {
// if stopping
SetInputsDisabled(true);
$('#wd_excel2_ajax_container').html('<?=GetMessage('WEBDEBUG_EXCEL_STOPPED');?>');
} else if ($('#wd_excel2_ajax_container').find('input[name=wd_excel2_next]').size()>0) {
// if need next request
var Timeout = $('#wd_excel2_ajax_container').find('input[name=wd_excel2_timeout]').val();
Timeout = parseInt(Timeout);
if (isNaN(Timeout) || Timeout<0) Timeout = 0;
WebdebugExcel2_DoNextStep(Timeout);
}
$('#wd_excel2_ajax_container').removeAttr('loading');
$('#wd_excel2_ajax_container').removeAttr('stopping');
}
// Do next step
function WebdebugExcel2_DoNextStep(Timeout) {
setTimeout(function(){
if ($('#wd_excel2_ajax_container').attr('stopping')!='stopping') {
WDExcel2AJAX = $.ajax({
url: $('#wd_excel2_popup_form').attr('action'),
type: 'POST',
data: 'profile='+$('#wd_excel2_profile_selector').val()+'&export='+($('#wd_excel2_checkbox_export').is(':checked')?'Y':'N')+'&colors='+($('#wd_excel2_checkbox_colors').is(':checked')?'Y':'N'),
success: function(res) {
WebdebugExcel2_CheckResultActions(res);
}
});
}
},Timeout);
}
if (window.WDExcel2AltXBinded!==true) {
$(document).keydown(function(Event){
if (Event.altKey && Event.keyCode == 88) {
window.WDExcel2AltXBinded = true;
$('#wd_excel2_btn_submit').click();
}
});
}
</script>