Skip to content

Commit

Permalink
Fix for #64
Browse files Browse the repository at this point in the history
Fix for #64
  • Loading branch information
nielsengelen committed Aug 29, 2020
1 parent 9ac0877 commit a013f2f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 154 deletions.
90 changes: 36 additions & 54 deletions exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@
<button class="btn btn-default dropdown-toggle form-control" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Restore selected <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li class="dropdown-header">Download as</li>
<li><a class="dropdown-link download-pst" data-itemid="multipleexport" data-mailboxid="<?php echo $uid; ?>" data-mailsubject="<?php echo $owner['name']; ?>" data-type="multiple" href="<?php echo $_SERVER['REQUEST_URI']; ?>#"><i class="fa fa-download"></i> PST file</a></li>
<li><a class="dropdown-link" href="javascript:void(0);" onclick="downloadPST('multipleexport', '<?php echo $uid; ?>', '<?php echo $owner['name']; ?>', 'multiple')"><i class="fa fa-download"></i> PST file</a></li>
<li class="divider"></li>
<li class="dropdown-header">Restore to</li>
<li><a class="dropdown-link restore-original" data-itemid="multiplerestore" data-mailboxid="<?php echo $uid; ?>" data-type="multiple" href="<?php echo $_SERVER['REQUEST_URI']; ?>#"><i class="fa fa-upload"></i> Original location</a></li>
<li><a class="dropdown-link restore-different" data-itemid="multiplerestore" data-mailboxid="<?php echo $uid; ?>" data-type="multiple" href="<?php echo $_SERVER['REQUEST_URI']; ?>#"><i class="fa fa-upload"></i> Different location</a></li>
<li><a class="dropdown-link" href="javascript:void(0);" onclick="restoreToOriginal('multiplerestore', '<?php echo $uid; ?>', 'multiple')"><i class="fa fa-upload"></i> Original location</a></li>
<li><a class="dropdown-link" href="javascript:void(0);" onclick="restoreToDifferent('multiplerestore', '<?php echo $uid; ?>', 'multiple')"><i class="fa fa-upload"></i> Different location</a></li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -363,7 +363,7 @@
</ul>
</div>
<script>
$(function () {
$(function() {
$('#jstree').jstree({
core: {
check_callback: true
Expand All @@ -373,19 +373,19 @@

var to = false;

$('#jstree_q').keyup(function (e) {
$('#jstree_q').keyup(function(e) {
if (to) {
clearTimeout(to);
}

to = setTimeout(function (e) {
to = setTimeout(function(e) {
var v = $('#jstree_q').val();

$('#jstree').jstree(true).search(v);
}, 250);
});

$('#jstree').on('activate_node.jstree', function (e, data) {
$('#jstree').on('activate_node.jstree', function(e, data) {
if (data == undefined || data.node == undefined || data.node.id == undefined || data.node.data.folderid == undefined)
return;

Expand Down Expand Up @@ -459,11 +459,11 @@
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Options <span class="caret"></span></button>
<ul class="dropdown-menu dropdown-menu-right">
<li class="dropdown-header">Download as</li>
<li><a class="dropdown-link download-pst" data-itemid="<?php echo $value['name']; ?>" data-mailsubject="<?php echo $value['name']; ?>" data-mailboxid="<?php echo $value['id']; ?>" data-type="full" href="<?php echo $_SERVER['REQUEST_URI']; ?>#"><i class="fa fa-download"></i> PST file</a></li>
<li><a class="dropdown-link" href="javascript:void(0);" onclick="downloadPST('<?php echo $value['name']; ?>', '<?php echo $value['id']; ?>', '<?php echo $value['name']; ?>', 'full')"><i class="fa fa-download"></i> PST file</a></li>
<li class="divider"></li>
<li class="dropdown-header">Restore to</li>
<li><a class="dropdown-link restore-original" data-itemid="<?php echo $value['name']; ?>" data-mailboxid="<?php echo $value['id']; ?>" data-type="full" href="<?php echo $_SERVER['REQUEST_URI']; ?>#"><i class="fa fa-upload"></i> Original location</a></li>
<li><a class="dropdown-link restore-different" data-itemid="<?php echo $value['name']; ?>" data-mailboxid="<?php echo $value['id']; ?>" data-type="full" href="<?php echo $_SERVER['REQUEST_URI']; ?>#"><i class="fa fa-upload"></i> Different location</a></li>
<li><a class="dropdown-link" href="javascript:void(0);" onclick="restoreToOriginal('<?php echo $value['name']; ?>', '<?php echo $value['id']; ?>', 'full')"><i class="fa fa-upload"></i> Original location</a></li>
<li><a class="dropdown-link" href="javascript:void(0);" onclick="restoreToDifferent('<?php echo $value['name']; ?>', '<?php echo $value['id']; ?>', 'full')"><i class="fa fa-upload"></i> Different location</a></li>
</ul>
</div>
</td>
Expand Down Expand Up @@ -547,8 +547,6 @@

$.post('veeam.php', {'action' : 'startrestore', 'json' : json, 'id' : oid}).done(function(data) {
if (data.match(/([a-zA-Z0-9]{8})-([a-zA-Z0-9]{4})-([a-zA-Z0-9]{4})-([a-zA-Z0-9]{4})-([a-zA-Z0-9]{12})/g)) {
e.preventDefault();

Swal.fire({
type: 'success',
title: 'Session started',
Expand All @@ -570,8 +568,6 @@
$('.btn-stop-restore').click(function(e) {
var rid = '<?php echo $rid; ?>';

e.preventDefault();

const swalWithBootstrapButtons = Swal.mixin({
confirmButtonClass: 'btn btn-success btn-margin',
cancelButtonClass: 'btn btn-danger',
Expand Down Expand Up @@ -647,22 +643,17 @@
});

/* Export to MSG file */
$('.download-msg').click(function(e) {
var itemid = $(this).data('itemid');
var mailboxid = $(this).data('mailboxid');
function downloadMsg(itemid, mailboxid, mailsubject) {
var rid = '<?php echo $rid; ?>';
var json = '{ "savetoMsg": null }';
var mailsubject = $(this).data('mailsubject');

Swal.fire({
type: 'info',
title: 'Download is starting',
text: 'Download will start soon.'
})

$.post('veeam.php', {'action': 'exportmailitem', 'itemid' : itemid, 'mailboxid' : mailboxid, 'rid' : rid, 'json' : json}).done(function(data) {
e.preventDefault();

$.post('veeam.php', {'action': 'exportmailitem', 'itemid' : itemid, 'mailboxid' : mailboxid, 'rid' : rid, 'json' : json}).done(function(data) {
if (data) {
$.redirect('download.php', {ext : 'msg', file : data, name : mailsubject}, 'POST');
} else {
Expand All @@ -674,14 +665,11 @@
return;
}
});
});
}

/* Export to PST file */
$('.download-pst').click(function(e) {
var itemid = $(this).data('itemid');
var mailboxid = $(this).data('mailboxid');
function downloadPST(itemid, mailboxid, mailsubject, type) {
var rid = '<?php echo $rid; ?>';
var type = $(this).data('type');

Swal.fire({
type: 'info',
Expand All @@ -692,7 +680,7 @@
if (type == 'multiple') { /* Multiple items export */
var act = 'exportmultiplemailitems';
var ids = '';
var mailsubject = 'exported-mailitems-' + $(this).data('mailsubject');
var mailsubject = 'exported-mailitems-' + mailsubject;

if ($("input[name='checkbox-mail']:checked").length === 0) { /* Error handling for multiple export button */
Swal.close();
Expand Down Expand Up @@ -721,10 +709,9 @@
} else {
if (type == 'single') { /* Single item export */
var act = 'exportmailitem';
var mailsubject = $(this).data('mailsubject');
} else { /* Full mailbox export */
var act = 'exportmailbox';
var mailsubject = 'mailbox-' + $(this).data('mailsubject'); /* mailbox-username */
var mailsubject = 'mailbox-' + mailsubject; /* mailbox-username */
}

var json = '{ \
Expand All @@ -734,9 +721,7 @@
}';
}

$.post('veeam.php', {'action' : act, 'itemid' : itemid, 'mailboxid' : mailboxid, 'rid' : rid, 'json' : json}).done(function(data) {
e.preventDefault();

$.post('veeam.php', {'action' : act, 'itemid' : itemid, 'mailboxid' : mailboxid, 'rid' : rid, 'json' : json}).done(function(data) {
if (data && data != '500') {
$.redirect('download.php', {ext : 'pst', file : data, name : mailsubject}, 'POST');

Expand All @@ -751,14 +736,11 @@

return;
});
});
}

/* Restore to a different location */
$('.restore-different').click(function(e) {
var itemid = $(this).data('itemid');
var mailboxid = $(this).data('mailboxid');
function restoreToDifferent(itemid, mailboxid, type) {
var rid = '<?php echo $rid; ?>';
var type = $(this).data('type');

if (type == 'multiple' && $("input[name='checkbox-mail']:checked").length == 0) { /* Error handling for multiple restore button */
Swal.fire({
Expand Down Expand Up @@ -799,7 +781,7 @@
'<div class="form-group row">' +
'<label for="restore-different-folder" class="col-sm-4 col-form-label text-right">Folder:</label>' +
'<div class="col-sm-8"><input type="text" class="form-control" id="restore-different-folder" placeholder="Custom folder (optional)"></input></div>' +
'<br /><h6>By default items will be restored in a folder named <em>Restored-via-web-client</em>.</h6>' +
'<br><h6>By default items will be restored in a folder named <em>Restored-via-web-client</em>.</h6>' +
'</div>' +
'</form>',
focusConfirm: false,
Expand Down Expand Up @@ -912,15 +894,12 @@
return;
}
});
});
}

/* Restore to original location */
$('.restore-original').click(function(e) {
var itemid = $(this).data('itemid');
var mailboxid = $(this).data('mailboxid');
function restoreToOriginal(itemid, mailboxid, type) {
var rid = '<?php echo $rid; ?>';
var type = $(this).data('type');

console.log(type);
if (type == 'multiple' && $("input[name='checkbox-mail']:checked").length == 0) { /* Error handling for multiple restore button */
Swal.fire({
type: 'error',
Expand Down Expand Up @@ -1030,7 +1009,7 @@
return;
}
});
});
}

function disableTree() {
$('#jstree li.jstree-node').each(function(e) {
Expand All @@ -1053,7 +1032,10 @@ function enableTree() {
function fillTable(response, mailboxid) {
if (response.results.length !== 0) {
for (var i = 0; i < response.results.length; i++) {
if (response.results[i].itemClass != 'IPM.Appointment') {
if (response.results[i].itemClass != 'IPM.Appointment') {
var itemid = response.results[i].id;
var mailsubject = response.results[i].subject;

$('#table-exchange-items tbody').append('<tr> \
<td class="text-center"><input type="checkbox" name="checkbox-mail" value="' + response.results[i].id + '"></td> \
<td class="text-center"><span class="logo fa fa-envelope"></span></td> \
Expand All @@ -1065,12 +1047,12 @@ function fillTable(response, mailboxid) {
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Options <span class="caret"></span></button> \
<ul class="dropdown-menu dropdown-menu-right"> \
<li class="dropdown-header">Download as</li> \
<li><a class="dropdown-link download-msg" data-itemid="' + response.results[i].id + '" data-mailsubject="' + response.results[i].subject + '" data-mailboxid="' + mailboxid + '" href="' + window.location + '"><i class="fa fa-download"></i> MSG file</a></li> \
<li><a class="dropdown-link download-pst" data-itemid="' + response.results[i].id + '" data-mailsubject="' + response.results[i].subject + '" data-mailboxid="' + mailboxid + '" data-type="single" href="' + window.location + '"><i class="fa fa-download"></i> PST file</a></li> \
<li><a class="dropdown-link" href="javascript:void(0);" onclick="downloadMsg(\'' + itemid + '\', \'' + mailboxid + '\', \'' + mailsubject + '\')"><i class="fa fa-download"></i> MSG file</a></li> \
<li><a class="dropdown-link" href="javascript:void(0);" onclick="downloadPST(\'' + itemid + '\', \'' + mailboxid + '\', \'' + mailsubject + '\', \'single\')"><i class="fa fa-download"></i> PST file</a></li> \
<li class="divider"></li> \
<li class="dropdown-header">Restore to</li> \
<li><a class="dropdown-link restore-original" data-itemid="' + response.results[i].id + '" data-mailboxid="' + mailboxid + '" data-type="single" href="' + window.location + '"><i class="fa fa-upload"></i> Original location</a></li> \
<li><a class="dropdown-link restore-different" data-itemid="' + response.results[i].id + '" data-mailboxid="' + mailboxid + '" data-type="single" href="' + window.location + '"><i class="fa fa-upload"></i> Different location</a></li> \
<li><a class="dropdown-link" href="javascript:void(0);" onclick="restoreToOriginal(\'' + itemid + '\', \'' + mailboxid + '\', \'single\')"><i class="fa fa-upload"></i> Original location</a></li> \
<li><a class="dropdown-link" href="javascript:void(0);" onclick="restoreToDifferent(\'' + itemid + '\', \'' + mailboxid + '\', \'single\')"><i class="fa fa-upload"></i> Different location</a></li> \
</ul> \
</div> \
</td> \
Expand All @@ -1087,12 +1069,12 @@ function fillTable(response, mailboxid) {
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Options <span class="caret"></span></button> \
<ul class="dropdown-menu dropdown-menu-right"> \
<li class="dropdown-header">Download as</li> \
<li><a class="dropdown-link download-msg" data-itemid="' + response.results[i].id + '" data-mailsubject="' + response.results[i].subject + '" data-mailboxid="' + mailboxid + '" href="' + window.location + '"><i class="fa fa-download"></i> MSG file</a></li> \
<li><a class="dropdown-link download-pst" data-itemid="' + response.results[i].id + '" data-mailsubject="' + response.results[i].subject + '" data-mailboxid="' + mailboxid + '" data-type="single" href="' + window.location + '"><i class="fa fa-download"></i> PST file</a></li> \
<li><a class="dropdown-link" href="javascript:void(0);" onclick="downloadMsg(\'' + itemid + '\', \'' + mailboxid + '\', \'' + mailsubject + '\')"><i class="fa fa-download"></i> MSG file</a></li> \
<li><a class="dropdown-link" href="javascript:void(0);" onclick="downloadPST(\'' + itemid + '\', \'' + mailboxid + '\', \'' + mailsubject + '\', \'single\')"><i class="fa fa-download"></i> PST file</a></li> \
<li class="divider"></li> \
<li class="dropdown-header">Restore to</li> \
<li><a class="dropdown-link restore-original" data-itemid="' + response.results[i].id + '" data-mailboxid="' + mailboxid + '" data-type="single" href="' + window.location + '"><i class="fa fa-upload"></i> Original location</a></li> \
<li><a class="dropdown-link restore-different" data-itemid="' + response.results[i].id + '" data-mailboxid="' + mailboxid + '" data-type="single" href="' + window.location + '"><i class="fa fa-upload"></i> Different location</a></li> \
<li><a class="dropdown-link" href="javascript:void(0);" onclick="restoreToOriginal(\'' + itemid + '\', \'' + mailboxid + '\', \'single\')"><i class="fa fa-upload"></i> Original location</a></li> \
<li><a class="dropdown-link" href="javascript:void(0);" onclick="restoreToDifferent(\'' + itemid + '\', \'' + mailboxid + '\', \'single\')"><i class="fa fa-upload"></i> Different location</a></li> \
</ul> \
</div> \
</td> \
Expand Down
Loading

0 comments on commit a013f2f

Please sign in to comment.