-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalists.php
More file actions
executable file
·231 lines (168 loc) · 4.95 KB
/
Copy pathjavalists.php
File metadata and controls
executable file
·231 lines (168 loc) · 4.95 KB
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
<?php /* INVENTORY $ld: utility.php, v1.00 2003/11/05 13:53 dylan_cuthbert Exp $ */ ?>
<SCRIPT LANGUAGE="JavaScript">
<!--
function getElementById( _id )
{
isIE=document.all?true:false;
isDOM=document.getElementById?true:false;
isNS4=document.layers?true:false;
if (isDOM)
{
return document.getElementById(_id);
}
else if (isIE)
{
eval( "return document.all."+_id+" ;" );
}
else if(isNS4)
{
eval("return document.layers['"+_id+" ;" );
}
}
function emptyList( box )
{
// Set each option to null thus removing it
while ( box.options.length ) box.options[0] = null;
}
// This function assigns new drop down options to the given
// drop down box from the list of lists specified
function fillList( box, arr, _selected, _optionzero ) {
// arr[0] holds the display text
// arr[1] are the values
if ( typeof _selected == "undefined" ) _selected = 0;
if ( typeof _optionzero == "undefined" ) _optionzero = "";
box.selectedIndex=0;
try
{
if ( _optionzero != "" )
{
option = new Option( _optionzero, 0 );
box.options[0] = option;
if ( _selected == 0 ) box.selectedIndex = 0;
}
for ( i = 0; i < arr[0].length; i++ )
{
// Create a new drop down option with the
// display text and value from arr
option = new Option( arr[0][i], arr[1][i] );
// Add to the end of the existing options
box.options[box.length] = option;
if ( arr[1][i] == _selected)
{
box.selectedIndex=box.length-1;
}
}
}
catch( error )
{
if ( _optionzero == "" )
{
option = new Option( <?php echo '"'.$AppUI->_( "Non Applicable" ).'"'; ?>, 0 );
box.options[ box.length ] = option;
}
}
}
// This function performs a drop down list option change by first
// emptying the existing option list and then assigning a new set
function changeList( box, lists, id, _selected )
{
// Isolate the appropriate list by using the value
// of the currently selected option
if ( typeof selected == "undefined" ) selected = 0;
list = lists[box.options[box.selectedIndex].value];
// Next empty the slave list
destination = getElementById( id );
emptyList( destination );
// Then assign the new list values
fillList( destination, list, _selected );
}
function changeListByType( _main, _type, _id, _selected, _optionzero )
{
if ( typeof _selected == "undefined" ) _selected = 0;
if ( typeof _optionzero == "undefined" ) _optionzero = "";
// First empty the slave list
destination = getElementById( _id );
emptyList( destination );
box = getElementById( _main );
typebox = getElementById( _type );
switch( typebox.options[ typebox.selectedIndex ].value )
{
case "department":
list = dept_lists[box.options[box.selectedIndex].value];
break;
case "project":
list = project_lists[box.options[box.selectedIndex].value];
break;
case "user":
list = user_lists[box.options[box.selectedIndex].value];
break;
default:
return;
}
// Then assign the new list values
fillList( destination, list, _selected, _optionzero );
}
<?php
// create javascript variables to populate the department and users dialogs
// based on security settings and dynamic form selection
// load up list of departments per company
// and set them into javascript variables
// this neads load_company_list to have been run (utility.php)
function generateJSarray( $prefix, $table, $specify_company = 0, $namefield = "name" )
{
global $company_list;
echo "var ".$prefix."_lists = new Array();";
$sql = "
SELECT {$prefix}_id AS id, {$prefix}_{$namefield} AS name, {$prefix}_company AS company
FROM {$table}
";
if ( $specify_company ) $sql .= "WHERE {$prefix}_company = $specify_company";
if (($sql_list = db_loadList( $sql, NULL )))
{
// create quick index table
$elem_list = array();
foreach ( $sql_list as $row )
{
$elem_list[ $row[ "id" ] ] = $row;
}
// create quick index table for the elements in the companies
$company_idx = array();
reset( $elem_list );
foreach( $elem_list as $elem )
{
$company_idx[ $elem[ "company" ] ][] = $elem[ "id" ];
}
// now go through each company in turn
reset( $company_idx );
foreach ( $company_idx as $key => $company )
{
if ( !isset($company_list[ $key ] ) ) continue;
echo $prefix."_lists[ ".$key." ] = new Array( ";
$nametext = "new Array( ";
$valuetext = "new Array( ";
$lastval = end($company);
reset( $company );
// and go through each element within that company
foreach( $company as $id )
{
$nametext .= '"'.$elem_list[ $id ][ "name" ].'"';
$valuetext .= '"'.$id.'"';
if ( $lastval != $id )
{
$nametext .= ", ";
$valuetext .= ", ";
}
}
echo $nametext." ),\n";
echo $valuetext." ) );\n";
}
}
}
global $specify_company;
if ( !isset( $specify_company ) ) $specify_company = 0;
generateJSarray( "dept", "departments", $specify_company );
generateJSarray( "user", "users", $specify_company, "username" );
generateJSarray( "project", "projects", $specify_company );
?>
-->
</SCRIPT>