forked from nilsteampassnet/TeamPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
folders.php
279 lines (257 loc) · 11.8 KB
/
folders.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
<?php
/**
*
* @file folders.php
* @author Nils Laumaillé
* @version 2.1.22
* @copyright (c) 2009-2014 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 ||
!isset($_SESSION['user_id']) || empty($_SESSION['user_id']) ||
!isset($_SESSION['key']) || empty($_SESSION['key']))
{
die('Hacking attempt...');
}
/* do checks */
require_once $_SESSION['settings']['cpassman_dir'].'/sources/checks.php';
if (!checkUser($_SESSION['user_id'], $_SESSION['key'], curPage())) {
$_SESSION['error']['code'] = ERR_NOT_ALLOWED; //not allowed page
include $_SESSION['settings']['cpassman_dir'].'/error.php';
exit();
}
require_once $_SESSION['settings']['cpassman_dir'].'/sources/SplClassLoader.php';
/* load help*/
require_once $_SESSION['settings']['cpassman_dir'].'/includes/language/'.$_SESSION['user_language'].'_admin_help.php';
//Build tree
$tree = new SplClassLoader('Tree\NestedTree', $_SESSION['settings']['cpassman_dir'].'/includes/libraries');
$tree->register();
$tree = new Tree\NestedTree\NestedTree($pre.'nested_tree', 'id', 'parent_id', 'title');
/* Get full tree structure */
$tst = $tree->getDescendants();
/* Build list of all folders */
if ($_SESSION['is_admin'] == 1 || $_SESSION['settings']['can_create_root_folder'] == 1) {
$folders_list = "\'0\':\'".$LANG['root']."\'";
} else {
$folders_list = "";
}
$ident = "";
foreach ($tst as $t) {
if (in_array($t->id, $_SESSION['groupes_visibles']) && !in_array($t->id, $_SESSION['personal_visible_groups'])) {
if ($t->nlevel == 1) {
$ident = ">";
}
if ($t->nlevel == 2) {
$ident = "->";
}
if ($t->nlevel == 3) {
$ident = "-->";
}
if ($t->nlevel == 4) {
$ident = "--->";
}
if ($t->nlevel == 5) {
$ident = "---->";
}
$folders_list .= ','."\'".$t->id.'\':\''.$ident." ".addslashes(addslashes($t->title))."\'";
}
}
/* Display header */
echo '
<div class="title ui-widget-content ui-corner-all">' .
$LANG['admin_groups'].' <img src="includes/images/folder--plus.png" id="open_add_group_div" title="'.$LANG['item_menu_add_rep'].'" style="cursor:pointer;" />
<img src="includes/images/folder--minus.png" onclick="delete_multiple_folders()" style="cursor:pointer;" title="'.$LANG['item_menu_del_rep'].'" />
<span style="float:right;margin-right:5px;">
<img src="includes/images/question-white.png" style="cursor:pointer" title="'.$LANG['show_help'].'" onclick="OpenDialog(\'help_on_folders\')" />
</span>
</div>';
// Hidden things
echo '
<input type="hidden" id="folder_id_to_edit" value="" />';
echo '
<form name="form_groupes" method="post" action="">
<div style="width:700px;margin:auto; line-height:20px;">
<table cellspacing="0" style="margin-top:10px;">
<thead><tr>
<th></th>
<th>ID</th>
<th>'.$LANG['group'].'</th>
<th>'.$LANG['complexity'].'</th>
<th>'.$LANG['group_parent'].'</th>
<th>'.$LANG['level'].'</th>
<th title="'.$LANG['group_pw_duration_tip'].'">'.$LANG['group_pw_duration'].'</th>
<th title="'.$LANG['del_group'].'"><img src="includes/images/folder--minus.png" /></th>
<th title="'.$LANG['auth_creation_without_complexity'].'"><img src="includes/images/auction-hammer.png" /></th>
<th title="'.$LANG['auth_modification_without_complexity'].'"><img src="includes/images/alarm-clock.png" /></th>
</tr></thead>
<tbody>';
$x = 0;
$arr_ids = array();
foreach ($tst as $t) {
if (in_array($t->id, $_SESSION['groupes_visibles']) && !in_array($t->id, $_SESSION['personal_visible_groups'])) {
// r?cup $t->parent_id
$data = DB::queryFirstRow("SELECT title FROM ".$pre."nested_tree WHERE id = %i", $t->parent_id);
if ($t->nlevel == 1) {
$data['title'] = $LANG['root'];
}
// r?cup les droits associ?s ? ce groupe
$tab_droits = array();
$rows = DB::query("SELECT fonction_id FROM ".$pre."rights WHERE authorized=%i AND tree_id = %i", 1, $t->id);
foreach ($rows as $record) {
array_push($tab_droits, $record['fonction_id']);
}
// g?rer l'identation en fonction du niveau
$ident = "";
for ($l = 1; $l < $t->nlevel; $l++) {
$ident .= " ";
}
// Get some elements from DB concerning this node
$node_data = DB::queryFirstRow(
"SELECT m.valeur as valeur, n.renewal_period as renewal_period
FROM ".$pre."misc as m,
".$pre."nested_tree as n
WHERE m.type=%s AND m.intitule = n.id AND m.intitule = %i",
"complex",
$t->id
);
echo '
<tr class="ligne0" id="row_'.$t->id.'">
<td align="center""><input type="checkbox" class="cb_selected_folder" id="cb_selected-'.$t->id.'" /></td>
<td align="center" onclick="open_edit_folder_dialog('.$t->id.')">'.$t->id.'</td>
<td width="50%" onclick="open_edit_folder_dialog('.$t->id.')">
'.$ident.'<span id="title_'.$t->id.'">'.$t->title.'</span>
</td>
<td align="center" onclick="open_edit_folder_dialog('.$t->id.')">
<span id="complexite_'.$t->id.'">'.@$pwComplexity[$node_data['valeur']][1].'</span>
</td>
<td align="center" onclick="open_edit_folder_dialog('.$t->id.')">
<span id="parent_'.$t->id.'">'.$node_data['valeur'].'</span>
</td>
<td align="center" onclick="open_edit_folder_dialog('.$t->id.')">
'.$t->nlevel.'
</td>
<td align="center" onclick="open_edit_folder_dialog('.$t->id.')">
<span id="renewal_'.$t->id.'">'.$node_data['renewal_period'].'</span>
</td>
<td align="center">
<img src="includes/images/folder--minus.png" onclick="supprimer_groupe(\''.$t->id.'\')" style="cursor:pointer;" />
</td>';
$data3 = DB::queryFirstRow("SELECT bloquer_creation,bloquer_modification FROM ".$pre."nested_tree WHERE id = %i", intval($t->id));
echo '
<td align="center">
<input type="checkbox" id="cb_droit_'.$t->id.'" onchange="Changer_Droit_Complexite(\''.$t->id.'\',\'creation\')"', isset($data3['bloquer_creation']) && $data3['bloquer_creation'] == 1 ? 'checked' : '', ' />
</td>
<td align="center">
<input type="checkbox" id="cb_droit_modif_'.$t->id.'" onchange="Changer_Droit_Complexite(\''.$t->id.'\',\'modification\')"', isset($data3['bloquer_modification']) && $data3['bloquer_modification'] == 1 ? 'checked' : '', ' />
</td>
<td>
<input type="hidden" id="parent_id_'.$t->id.'" value="'.$t->parent_id.'" />
<input type="hidden" id="renewal_id_'.$t->id.'" value="'.$node_data['valeur'].'" />
</td>
</tr>';
array_push($arr_ids, $t->id);
$x++;
}
}
echo '
</tbody>
</table>
<div style="font-size:11px;font-style:italic;margin-top:5px;">
<img src="includes/images/information-white.png" alt="" /> '.$LANG['info_click_to_edit'].'
</div>
</div>
</form>';
// DIV FOR HELP
echo '
<div id="help_on_folders" style="">
<div>'.$LANG['help_on_folders'].'</div>
</div>';
/* Form Add a folder */
echo '
<div id="div_add_group" style="display:none;">
<div id="addgroup_show_error" style="text-align:center;margin:2px;display:none;" class="ui-state-error ui-corner-all"></div>
<label for="ajouter_groupe_titre" class="label_cpm">'.$LANG['group_title'].' :</label>
<input type="text" id="ajouter_groupe_titre" class="input_text text ui-widget-content ui-corner-all" />
<label for="parent_id" class="label_cpm">'.$LANG['group_parent'].' :</label>
<select id="parent_id" class="input_text text ui-widget-content ui-corner-all">';
echo '<option value="na">---'.$LANG['select'].'---</option>';
if ($_SESSION['is_admin'] == 1 || $_SESSION['can_create_root_folder'] == 1) {
echo '<option value="0">'.$LANG['root'].'</option>';
}
$prev_level = 0;
foreach ($tst as $t) {
if (in_array($t->id, $_SESSION['groupes_visibles']) && !in_array($t->id, $_SESSION['personal_visible_groups'])) {
$ident = "";
for ($x = 1; $x < $t->nlevel; $x++) {
$ident .= " ";
}
if ($prev_level < $t->nlevel) {
echo '<option value="'.$t->id.'">'.$ident.$t->title.'</option>';
} elseif ($prev_level == $t->nlevel) {
echo '<option value="'.$t->id.'">'.$ident.$t->title.'</option>';
} else {
echo '<option value="'.$t->id.'">'.$ident.$t->title.'</option>';
}
$prev_level = $t->nlevel;
}
}
echo '
</select>
<label for="new_rep_complexite" class="label_cpm">'.$LANG['complex_asked'].' :</label>
<select id="new_rep_complexite" class="input_text text ui-widget-content ui-corner-all">';
foreach ($pwComplexity as $complex) {
echo '<option value="'.$complex[0].'">'.$complex[1].'</option>';
}
echo '
</select>
<label for="add_node_renewal_period" class="label_cpm">'.$LANG['group_pw_duration'].' :</label>
<input type="text" id="add_node_renewal_period" value="0" class="input_text text ui-widget-content ui-corner-all" />
</div>';
/* Form EDIT a folder */
echo '
<div id="div_edit_folder" style="display:none;">
<div id="edit_folder_show_error" style="text-align:center;margin:2px;display:none;" class="ui-state-error ui-corner-all"></div>
<label for="edit_folder_title" class="label_cpm">'.$LANG['group_title'].' :</label>
<input type="text" id="edit_folder_title" class="input_text text ui-widget-content ui-corner-all" />
<label for="edit_parent_id" class="label_cpm">'.$LANG['group_parent'].' :</label>
<select id="edit_parent_id" class="input_text text ui-widget-content ui-corner-all">';
echo '<option value="na">---'.$LANG['select'].'---</option>';
if ($_SESSION['is_admin'] == 1 || $_SESSION['can_create_root_folder'] == 1) {
echo '<option value="0">'.$LANG['root'].'</option>';
}
$prev_level = 0;
foreach ($tst as $t) {
if (in_array($t->id, $_SESSION['groupes_visibles']) && !in_array($t->id, $_SESSION['personal_visible_groups'])) {
$ident = "";
for ($x = 1; $x < $t->nlevel; $x++) {
$ident .= " ";
}
if ($prev_level < $t->nlevel) {
echo '<option value="'.$t->id.'">'.$ident.$t->title.'</option>';
} elseif ($prev_level == $t->nlevel) {
echo '<option value="'.$t->id.'">'.$ident.$t->title.'</option>';
} else {
echo '<option value="'.$t->id.'">'.$ident.$t->title.'</option>';
}
$prev_level = $t->nlevel;
}
}
echo '
</select>
<label for="edit_folder_complexite" class="label_cpm">'.$LANG['complex_asked'].' :</label>
<select id="edit_folder_complexite" class="input_text text ui-widget-content ui-corner-all">';
foreach ($pwComplexity as $complex) {
echo '<option value="'.$complex[0].'">'.$complex[1].'</option>';
}
echo '
</select>
<label for="edit_folder_renewal_period" class="label_cpm">'.$LANG['group_pw_duration'].' :</label>
<input type="text" id="edit_folder_renewal_period" value="0" class="input_text text ui-widget-content ui-corner-all" />
</div>';
require_once 'folders.load.php';