forked from dotproject/dotProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvw_usr_transfer.php
More file actions
103 lines (92 loc) · 3.81 KB
/
vw_usr_transfer.php
File metadata and controls
103 lines (92 loc) · 3.81 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
<?php
/*
* Allow a user's tasks and projects to be re-assigned to another
* user. Only accessible by an admin, used to handle the situation
* where a user has moved on and another is taking their place.
*/
global $AppUI, $user_id, $canEdit, $canDelete, $tab;
if (!defined('DP_BASE_DIR')) {
die('You should not access this file directly.');
}
if (! $canEdit) {
$AppUI->redirect('m=public&a=access_denied');
}
// Get the list of projects associated with this user.
// We need to get all projects that are owned by the user
// or where the user is a project contact.
// We then need to add all projects where a user is assigned a task, is a
// task contact, or is the owner of a task within that project.
// This should cover all situations that we need to correct.
$projects = array();
$q = new DBQuery();
$q->addQuery('user_contact');
$q->addTable('users');
$q->addWhere('user_id = ' . (int)$user_id);
$contact_id = $q->loadResult();
$q->addQuery('distinct project_id, project_name');
$q->addTable('projects');
$q->addWhere('project_owner = ' .(int)$user_id);
$projects += $q->loadHashList();
$q->addQuery('distinct prj.project_id, prj.project_name');
$q->addTable('projects', 'prj');
$q->innerJoin('project_contacts', 'prc', array('project_id'));
$q->addWhere('prc.contact_id = ' . (int)$contact_id);
$projects += $q->loadHashList();
$q->addQuery('distinct prj.project_id, prj.project_name');
$q->addTable('tasks', 't');
$q->innerJoin('projects', 'prj', 'prj.project_id = t.task_project');
$q->leftJoin('user_tasks', 'ut', 'ut.task_id = t.task_id');
$q->addWhere('t.task_owner = ' . (int)$user_id
. ' OR ut.user_id = ' . (int)$user_id);
$projects += $q->loadHashList();
$q->addQuery('distinct prj.project_id, prj.project_name');
$q->addTable('tasks', 't');
$q->innerJoin('projects', 'prj', 'prj.project_id = t.task_project');
$q->innerJoin('task_contacts', 'tc', 'tc.task_id = t.task_id');
$q->addWhere('tc.contact_id = ' . (int)$contact_id);
$projects += $q->loadHashList();
$q->addQuery('user_id, concat(u.user_username, \' (\', c.contact_first_name, \' \', c.contact_last_name, \')\') as username');
$q->addTable('users', 'u');
$q->leftJoin('contacts', 'c', 'c.contact_id = u.user_contact');
$q->addWhere('u.user_id != ' . (int)$user_id);
$q->addOrder('u.user_username');
$users = $q->loadHashList();
?>
<script >
function checkAllProjects()
{
var sellist = document.getElementById('prjSelectList');
var l = sellist.options.length;
for (var i = 0; i < l; i++) {
sellist.options[i].selected = true;
}
}
</script>
<p><?php echo $AppUI->_('Transfer tasks and projects from this user to another'); ?></p>
<form name="frmTxfr" method="post" action="?m=admin">
<input type="hidden" name="dosql" value="do_user_transfer" />
<input type="hidden" name="from_user" value="<?php echo $user_id; ?>" />
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr><td width="50%" valign="top">
<?php
// Left hand panel shows list of user's projects, allowing
// each project to be selected, or all.
?>
<table width="100%" cellspacing="1" cellpadding="2" border="0" class="std">
<tr><th><?php echo $AppUI->_('Transfer Projects'); ?></th></tr>
<tr><td><?php echo arraySelect($projects, 'project[]', 'multiple="multiple" size="8" id="prjSelectList"', false); ?></td></tr>
<tr><td><input type="button" name="selectAll" value="<?php echo $AppUI->_('Select All'); ?>" onclick="checkAllProjects();" /></td></tr>
</table>
</td>
<td width="50%" valign="top">
<?php
// Right hand panel shows list of users who can receive the tasks.
?>
<table width="100%" cellspacing="1" cellpadding="2" border="0" class="std">
<tr><th><?php echo $AppUI->_('To User'); ?></th></tr>
<tr><td><?php echo arraySelect($users, 'user', 'size="8"', false); ?></td></tr>
<tr><td><input type="submit" name="Go" value="<?php echo $AppUI->_('Transfer'); ?>"/></td></tr>
</table>
</td></tr>
</table>
</form>