forked from nilsteampassnet/TeamPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
folders.load.php
295 lines (277 loc) · 12.3 KB
/
folders.load.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?php
/**
* @file folders.load.php
* @author Nils Laumaillé
* @version 2.1.26
* @copyright (c) 2009-2016 Nils Laumaillé
* @licensing GNU AFFERO GPL 3.0
* @link http://www.teampass.net
*
* This library 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.
*/
if (!isset($_SESSION['CPM']) || $_SESSION['CPM'] != 1) {
die('Hacking attempt...');
}
?>
<script type="text/javascript">
//<![CDATA[
$(function() {
//Launch the datatables pluggin
var tableFolders = $("#t_folders").dataTable({
"order": [[ 1, "asc" ]],
"ordering": false,
"searching": false,
"paging": false,
"processing": true,
"serverSide": true,
"ajax": {
url: "sources/datatable/datatable.folders.php"
},
"language": {
"url": "includes/language/datatables.<?php echo $_SESSION['user_language'];?>.txt"
},
"columns": [
{"width": "7%"},
{"width": "5%"},
{className: "dt-body-left"},
{"width": "15%"},
{"width": "10%"},
{"width": "10%"},
{"width": "5%"},
{"width": "5%"},
{"width": "5%"}
]
})
.on('xhr.dt', function ( e, settings, json, xhr ) {
//$(".tip").tooltipster();
} );
$("#div_add_group").dialog({
bgiframe: true,
modal: true,
autoOpen: false,
width: 350,
height: 450,
title: "<?php echo $LANG['add_new_group'];?>",
open: function(event, ui) {
$("#new_folder_wait").hide();
//empty dialogbox
$("#div_add_group input, #div_add_group select").val("");
$("#add_node_renewal_period").val("0");
$("#folder_block_modif, #folder_block_creation").val("0");
},
buttons: {
"<?php echo $LANG['save_button'];?>": function() {
//Check if renewal_period is an integer
if (isInteger(document.getElementById("add_node_renewal_period").value) == false) {
document.getElementById("addgroup_show_error").innerHTML = "<?php echo $LANG['error_renawal_period_not_integer'];?>";
$("#addgroup_show_error").show();
} else if (document.getElementById("new_rep_complexite").value == "") {
document.getElementById("addgroup_show_error").innerHTML = "<?php echo $LANG['error_group_complex'];?>";
$("#addgroup_show_error").show();
} else {
if (document.getElementById("ajouter_groupe_titre").value != "" && document.getElementById("parent_id").value != "na") {
$("#new_folder_wait").show();
$("#addgroup_show_error").hide();
//prepare data
var data = '{"title":"'+$('#ajouter_groupe_titre').val().replace(/"/g,'"') + '", "complexity":"'+$('#new_rep_complexite').val().replace(/"/g,'"')+'", '+
'"parent_id":"'+$('#parent_id').val().replace(/"/g,'"')+'", "renewal_period":"'+$('#add_node_renewal_period').val().replace(/"/g,'"')+'" , "block_creation":"'+$("#folder_block_creation").val()+'" , "block_modif":"'+$("#folder_block_modif").val()+'"}';console.log(data);
//send query
$.post(
"sources/folders.queries.php",
{
type : "add_folder",
data : prepareExchangedData(data, "encode", "<?php echo $_SESSION['key'];?>"),
key : "<?php echo $_SESSION['key'];?>"
},
function(data) {
//Check errors
if (data[0].error == "error_group_exist") {
$("#div_add_group").dialog("open");
$("#addgroup_show_error").html("<?php echo $LANG['error_group_exist'];?>");
$("#addgroup_show_error").show();
} else if (data[0].error == "error_html_codes") {
$("#div_add_group").dialog("open");
$("#addgroup_show_error").html("<?php echo $LANG['error_html_codes'];?>");
$("#addgroup_show_error").show();
} else {
tableFolders.api().ajax.reload();
$("#parent_id, #edit_parent_id").empty().append(data[0].droplist);
$("#div_add_group").dialog("close");
}
},
"json"
);
} else {
document.getElementById("addgroup_show_error").innerHTML = "<?php echo $LANG['error_fields_2'];?>";
$("#addgroup_show_error").show();
}
}
},
"<?php echo $LANG['cancel_button'];?>": function() {
$(this).dialog("close");
}
}
});
$("#div_edit_folder").dialog({
bgiframe: true,
modal: true,
autoOpen: false,
width: 350,
height: 450,
title: "<?php echo $LANG['at_category'];?>",
open: function(event, ui) {
var id = $("#folder_id_to_edit").val();
$("#edit_folder_wait").hide();
//update dialogbox with data
$("#edit_folder_title").val($("#title_"+id).text());
$("#edit_folder_renewal_period").val($("#renewal_"+id).text());
$("#edit_folder_complexite").val($("#renewal_id_"+id).val());
$("#edit_parent_id").val($("#parent_id_"+id).val());
$("#edit_folder_block_creation").val($("#block_creation_"+id).val());
$("#edit_folder_block_modif").val($("#block_modif_"+id).val());
},
buttons: {
"<?php echo $LANG['delete'];?>": function() {
if (confirm("<?php echo $LANG['confirm_delete_group'];?>")) {
//send query
$.post(
"sources/folders.queries.php",
{
type : "delete_folder",
id : $("#folder_id_to_edit").val(),
key : "<?php echo $_SESSION['key'];?>"
},
function(data) {
tableFolders.api().ajax.reload();
$("#div_edit_folder").dialog("close");
}
);
}
//Close
$("#div_edit_folder").dialog("close");
},
"<?php echo $LANG['save_button'];?>": function() {
if ($('#edit_folder_complexite').val() == "") {
$("#edit_folder_show_error").html("<?php echo $LANG['error_group_complex'];?>").show();
return;
}if ($('#edit_folder_title').val() == "") {
$("#edit_folder_show_error").html("<?php echo $LANG['error_group_label'];?>").show();
return;
}
$("#edit_folder_wait").show();
//prepare data
var data = '{"id":"'+$("#folder_id_to_edit").val()+'", "title":"'+$('#edit_folder_title').val().replace(/"/g,'"') + '", "complexity":"'+$('#edit_folder_complexite').val().replace(/"/g,'"')+'", '+
'"parent_id":"'+$('#edit_parent_id').val().replace(/"/g,'"')+'", "renewal_period":"'+$('#edit_folder_renewal_period').val().replace(/"/g,'"')+'" , "block_creation":"'+$("#edit_folder_block_creation").val()+'" , "block_modif":"'+$("#edit_folder_block_modif").val()+'"}';
//send query
$.post(
"sources/folders.queries.php",
{
type : "update_folder",
data : prepareExchangedData(data, "encode", "<?php echo $_SESSION['key'];?>"),
key : "<?php echo $_SESSION['key'];?>"
},
function(data) {
//Check errors
if (data[0].error == "error_group_exist") {
$("#edit_folder_show_error").html("<?php echo $LANG['error_group_exist'];?>").show();
LoadingPage();
} else if (data[0].error == "error_html_codes") {
$("#edit_folder_show_error").html("<?php echo $LANG['error_html_codes'];?>").show();
LoadingPage();
} else {
$("#folder_id_to_edit").val(""); //clear id
tableFolders.api().ajax.reload();
$("#parent_id, #edit_parent_id").empty().append(data[0].droplist);
$("#div_edit_folder").dialog("close");
}
$("#edit_folder_wait").hide();
},
"json"
);
},
"<?php echo $LANG['cancel_button'];?>": function() {
//clear id
$("#folder_id_to_edit").val("");
//Close
$("#div_edit_folder").dialog("close");
}
}
});
$(".cb_selected_folder").click(function() {
var elem = $(this).attr("id").split("-");
if ($(this).prop("checked") == true) {
$("#row_"+elem[1]).css({"font-weight":"bold"});
$("#title_"+elem[1]).css({"background-color":"#E9FF00"});
} else {
$("#row_"+elem[1]).css({"font-weight":""});
$("#title_"+elem[1]).css({"background-color":"#FFF"});
}
});
// manage the click on toggle icons
$(document).on({
click: function (event) {
$("#div_loading").show();
var tmp = $(this).attr('tp').split('-'); //[0]>ID ; [1]>action ; [2]>NewValue
// send change to be stored
$.post(
"sources/folders.queries.php",
{
type : tmp[1],
value : tmp[2],
id : tmp[0],
key : "<?php echo $_SESSION['key'];?>"
},
function(data) {
$("#div_loading").hide();
// refresh table content
tableFolders.api().ajax.reload();
}
);
}
}, ".fa-toggle-off, .fa-toggle-on");
$( "#click_delete_multiple_folders" ).click(function() {
var list_i = "";
$(".cb_selected_folder:checked").each(function() {
var elem = $(this).attr("id").split("-");
if (list_i == "") list_i = elem[1];
else list_i = list_i+';'+elem[1];
});
if (list_i != "" && $("#action_on_going").val() == "" && confirm("<?php echo addslashes($LANG['confirm_deletion']);?>")) {
$("#div_loading").show();
$("#action_on_going").val("multiple_folders");
var data = '{"foldersList":"'+list_i+'"}';
//send query
$.post(
"sources/folders.queries.php",
{
type : "delete_multiple_folders",
data : prepareExchangedData(data, "encode", "<?php echo $_SESSION['key'];?>"),
key : "<?php echo $_SESSION['key'];?>"
},
function(data) {
tableFolders.api().ajax.reload();
$("#action_on_going").val("");
$("#div_loading").hide();
},
"json"
);
}
});
$("#click_refresh_folders_list").click(function() {
tableFolders.api().ajax.reload();
});
});
/**
*
* @access public
* @return void
**/
function open_edit_folder_dialog(id)
{
$("#folder_id_to_edit").val(id);
$("#div_edit_folder").dialog("open");
}
//]]>
</script>