-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselector.php
More file actions
183 lines (166 loc) · 4.64 KB
/
Copy pathselector.php
File metadata and controls
183 lines (166 loc) · 4.64 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
<?php /* HELPDESK $Id: selector.php,v 1.14 2006-12-14 12:55 Kang Exp $ */
if (!defined('DP_BASE_DIR')){
die('You should not access this file directly.');
}
function selPermWhere( $table, $idfld ) {
global $AppUI;
// get any companies denied from viewing
$q = new DBQuery;
$q->addQuery($table, 'permissions');
$q->addWhere('permission_user = '.$AppUI->user_id);
$q->addWhere('permission_grant_on = '.$table);
$q->addWhere('permission_item = '.$idfld);
$q->addWhere('permission_value = 0');
$deny = $q->loadColumn();
$q->clear();
return "permission_user = $AppUI->user_id"
."\nAND permission_value <> 0"
."\nAND ("
."\n (permission_grant_on = 'all')"
."\n OR (permission_grant_on = '$table' and permission_item = -1)"
."\n OR (permission_grant_on = '$table' and permission_item = $idfld)"
."\n )"
. (count($deny) > 0 ? "\nAND $idfld NOT IN (" . implode( ',', $deny ) . ')' : '');
}
$debug = false;
$callback = dPgetParam( $_GET, 'callback', 0 );
$table = dPgetParam( $_GET, 'table', 0 );
$comp=dPgetParam($_GET, 'comp', 0);
$ok = $callback & $table;
$title = "Generic Selector";
$select = '';
$from = $table;
$where = '';
$order = '';
switch ($table) {
case 'companies':
$title = 'Company';
$select = 'company_id,company_name';
$order = 'company_name';
$table .= ", permissions";
$where = selPermWhere( 'companies', 'company_id' );
break;
case 'departments':
// known issue: does not filter out denied companies
$title = 'Department';
$company_id = dPgetParam( $_GET, 'company_id', 0 );
//$ok &= $company_id; // Is it safe to delete this line ??? [kobudo 13 Feb 2003]
//$where = selPermWhere( 'companies', 'company_id' );
$where = "dept_company = company_id ";
$where .= "\nAND ".selPermWhere( 'departments', 'dept_id' );
$table .= ", companies, permissions";
$hide_company = dPgetParam( $_GET, 'hide_company', 0 );
if ( $hide_company == 1 ){
$select = "dept_id, dept_name";
}else{
$select = "dept_id,CONCAT_WS(': ',company_name,dept_name) AS dept_name";
}
if ($company_id) {
$where .= "\nAND dept_company = $company_id";
$order = 'dept_name';
} else {
$order = 'company_name,dept_name';
}
break;
case 'forums':
$title = 'Forum';
$select = 'forum_id,forum_name';
$order = 'forum_name';
break;
case 'projects':
$project_company = dPgetParam( $_GET, 'project_company', 0 );
$title = 'Project';
$select = 'project_id,project_name';
$order = 'project_name';
$where = selPermWhere( 'projects', 'project_id' );
$where .= $project_company ? "\nAND project_company = $project_company" : '';
$table .= ", permissions";
break;
case 'tasks':
$task_project = dPgetParam( $_GET, 'task_project', 0 );
$title = 'Task';
$select = 'task_id,task_name';
$order = 'task_name';
$where = $task_project ? "task_project = $task_project" : '';
break;
case 'users':
$title = 'User';
$tempuserlist = getAllowedUsers($comp, 1);
foreach($tempuserlist as $key=>$value){
$list[$key]=$value;
}
break;
case 'contacts':
$title = 'Contact';
$select = "contact_id,CONCAT_WS(' ',contact_first_name,contact_last_name)";
$order = "CONCAT_WS(' ',contact_first_name,contact_last_name)";
if ($comp) {
$where = "contact_company = ".$comp;
}
// $templist = getAllowedUsers();
// foreach($templist as $key=>$value){
// $list[$key]=$value;
// }
break;
default:
$ok = false;
break;
}
if (!$ok) {
echo "Incorrect parameters passed\n";
if ($debug) {
echo "<br />callback = $callback \n";
echo "<br />table = $table \n";
echo "<br />ok = $ok \n";
}
} else {
if(!isset($list)){
/// $sql = "SELECT $select FROM $table";
/// $sql .= $where ? " WHERE $where" : '';
/// $sql .= $order ? " ORDER BY $order" : '';
/// $list = arrayMerge( array( 0=>''), db_loadHashList( $sql ) );
$q = new DBQuery;
$q->addQuery($select);
$q->addTable($table);
if ($where) {
$q->addWhere($where);
}
$q->addOrder($order);
$list = arrayMerge( array( 0=>''), $q->loadHashList());
}
echo db_error();
?>
<script language="javascript">
function setClose(key, val){
window.opener.<?php echo $callback;?>(key,val);
window.close();
}
function setHeight(){
window.opener.<?php echo $callback;?>(key,val);
window.close();
}
</script>
<table cellspacing="0" cellpadding="3" border="0">
<tr>
<td>
<?php
if (count( $list ) > 1) {
echo $AppUI->_( 'Select' ).' '.$AppUI->_( $title ).':<br />';
foreach ($list as $key => $val) {
echo "<a href=\"javascript:setClose('$key','".addslashes($val)."');\">$val</a><br>\n";
}
?>
</td>
</tr>
<tr>
<td align="right">
<input type="button" class="button" value="<?php echo $AppUI->_( 'cancel' );?>" onclick="window.close()" />
<?php
} else {
echo $AppUI->_( "no$table" );
}
?>
</td>
</tr>
</table>
<?php } ?>