forked from nilsteampassnet/TeamPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.settings_categories.php
225 lines (206 loc) · 8.34 KB
/
admin.settings_categories.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
<?php
/**
*
* @file admin.settings_categories.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.
*/
require_once('sources/sessions.php');
session_start();
if (!isset($_SESSION['CPM']) || $_SESSION['CPM'] != 1) {
die('Hacking attempt...');
}
include $_SESSION['settings']['cpassman_dir'].'/includes/language/'.$_SESSION['user_language'].'.php';
include $_SESSION['settings']['cpassman_dir'].'/includes/settings.php';
include $_SESSION['settings']['cpassman_dir'].'/includes/include.php';
header("Content-type: text/html; charset=utf-8");
include $_SESSION['settings']['cpassman_dir'].'/sources/main.functions.php';
require_once $_SESSION['settings']['cpassman_dir'].'/sources/SplClassLoader.php';
// connect to the server
require_once $_SESSION['settings']['cpassman_dir'].'/includes/libraries/Database/Meekrodb/db.class.php';
DB::$host = $server;
DB::$user = $user;
DB::$password = $pass;
DB::$dbName = $database;
DB::$port = $port;
DB::$error_handler = 'db_error_handler';
$link = mysqli_connect($server, $user, $pass, $database, $port);
//Build tree
$tree = new SplClassLoader('Tree\NestedTree', './includes/libraries');
$tree->register();
$tree = new Tree\NestedTree\NestedTree($pre.'nested_tree', 'id', 'parent_id', 'title');
$tree->rebuild();
/*
* Loads the Item Categories
*/
//Build tree of Categories
$categoriesSelect = "";
$arrCategories = array();
$rows = DB::query(
"SELECT * FROM ".$pre."categories
WHERE level = %i
ORDER BY ".$pre."categories.order ASC",
'0'
);
foreach ($rows as $record) {
array_push(
$arrCategories,
array(
$record['id'],
$record['title'],
$record['order']
)
);
// build selection list
$categoriesSelect .= '<option value="'.$record['id'].'">'.($record['title']).'</option>';
}
echo '
<div id="tabs-8">
<div id="categories_list">
<table id="tbl_categories" style="">';
if (isset($arrCategories) && count($arrCategories) > 0) {
// build table
foreach ($arrCategories as $category) {
// get associated Folders
$foldersList = $foldersNumList = "";
$rows = DB::query(
"SELECT t.title AS title, c.id_folder as id_folder
FROM ".$pre."categories_folders AS c
INNER JOIN ".$pre."nested_tree AS t ON (c.id_folder = t.id)
WHERE c.id_category = %i",
$category[0]
);
foreach ($rows as $record) {
if (empty($foldersList)) {
$foldersList = $record['title'];
$foldersNumList = $record['id_folder'];
} else {
$foldersList .= " | ".$record['title'];
$foldersNumList .= ";".$record['id_folder'];
}
}
// display each cat and fields
echo '
<tr id="t_cat_'.$category[0].'">
<td colspan="2">
<input type="text" id="catOrd_'.$category[0].'" size="1" class="category_order" value="'.$category[2].'" />
<input type="radio" name="sel_item" id="item_'.$category[0].'_cat" />
<label for="item_'.$category[0].'_cat" id="item_'.$category[0].'" style="font-weight:bold;">'.$category[1].'</label>
<a href="#" title="'.$LANG['field_add_in_category'].'" onclick="fieldAdd('.$category[0].')" class="cpm_button tip" style="margin-left:20px;">
<img src="includes/images/zone--plus.png" />
</a>
</td>
<td>
<a href="#" title="'.$LANG['category_in_folders'].'" onclick="catInFolders('.$category[0].')" class="cpm_button tip" style="margin-left:5px;">
<img src="includes/images/folder_edit.png" />
</a>
'.$LANG['category_in_folders_title'].':
<span style="font-family:italic; margin-left:10px;" id="catFolders_'.$category[0].'">'.$foldersList.'</span>
<input type="hidden" id="catFoldersList_'.$category[0].'" value="'.$foldersNumList.'" />
</td>
</tr>';
$rows = DB::query(
"SELECT * FROM ".$pre."categories
WHERE parent_id = %i
ORDER BY ".$pre."categories.order ASC",
$category[0]
);
$counter = DB::count();
if ($counter > 0) {
foreach ($rows as $field) {
echo '
<tr id="t_field_'.$field['id'].'">
<td width="20px"></td>
<td>
<input type="text" id="catOrd_'.$field['id'].'" size="1" class="category_order" value="'.$field['order'].'" />
<input type="radio" name="sel_item" id="item_'.$field['id'].'_cat" />
<label for="item_'.$field['id'].'_cat" id="item_'.$field['id'].'">'.($field['title']).'</label>
</td>
<td></td>
</tr>';
}
}
}
}
echo '
</table>
</div>';
if (!isset($arrCategories) || count($arrCategories) == 0) {
echo '
<div class=ui-state-highlight ui-corner-all" style="padding:2px;" id="no_category">
'.$LANG['no_category_defined'].'
</div>';
}
// add management button
echo '
<div class="ui-state-highlight ui-corner-all" style="padding: 5px; margin-top:25px;">
<div>
'.$LANG['new_category_label'].':
<input type="text" id="new_category_label" class="ui-content" style="margin-left:5px; width: 200px;" />
<input type="button" value="Add Category" onclick="categoryAdd()" style="margin-left:5px;" />
</div>
<div style="margin-top:5px;">
'.$LANG['for_selected_items'].':<br />
<input type="text" id="new_item_title" class="ui-content" style="margin-left:30px; width: 200px;" />
<input type="button" value="'.$LANG['rename'].'" onclick="renameItem()" style="margin-left:5px;" />
|
<input type="button" value="'.$LANG['delete'].'" onclick="deleteItem()" style="margin-left:5px;" />
|
<input type="button" value="'.$LANG['move'].'" onclick="moveItem()" style="margin-left:5px;" />
<select id="moveItemTo" style="margin-left:10px;">'.$categoriesSelect.'</select>
</div>
<div style="margin-top:5px;">
<input type="button" value="'.$LANG['save_categories_position'].'" onclick="storePosition()" style="margin-left:5px;" />
<input type="button" value="'.$LANG['reload_table'].'" onclick="loadFieldsList()" style="margin-left:5px;" />
</div>
</div>';
echo '
</div>';
// hidden
echo '
<input type="hidden" id="post_id" />
<input type="hidden" id="post_data" />
<input type="hidden" id="post_type" />
<input type="hidden" id="selected_row" />';
// dialogboxes
echo '
<div id="category_confirm" style="display:none;">
<span id="category_confirm_text"></span>?
</div>';
echo '
<div id="add_new_field" style="display:none;">
'.$LANG['new_field_title'].'<input type="text" id="new_field_title" style="width: 200px; margin-left:20px;" />
</div>';
echo '
<div id="category_in_folder" style="display:none;">
'.$LANG['select_folders_for_category'].'
"<span style="font-weight:bold;" id="catInFolder_title"></span>" :
<br />
<div style="text-align:center; margin-top:10px;">
<select id="cat_folders_selection" multiple size="12">';
$folders = $tree->getDescendants();
foreach ($folders as $folder) {
DB::query(
"SELECT * FROM ".$pre."nested_tree
WHERE personal_folder = %i AND id = %i",
'0',
$folder->id
);
$counter = DB::count();
if ($counter > 0) {
echo '
<option value="'.$folder->id.'">'.str_replace("&", "&", $folder->title).'</option>';
}
}
echo '
</div>
<div id="catInFolder_wait" class="ui-state-focus ui-corner-all" style="display:none;padding:2px;margin:5px 0 5px 0;">'.$LANG['please_wait'].'...</div>
</div>';
require_once 'admin.settings.load.php';