forked from dotproject/dotProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdo_user_transfer.php
More file actions
90 lines (81 loc) · 2.22 KB
/
do_user_transfer.php
File metadata and controls
90 lines (81 loc) · 2.22 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
<?php
if (!defined('DP_BASE_DIR')) {
die('You should not access this file directly.');
}
if (! $AppUI->acl()->checkModule($m, 'edit')) {
$AppUI->redirect('m=public&a=access_denied');
}
$user_id = (int)dPgetParam($_POST, 'user');
$projects = dPgetCleanParam($_POST, 'project');
$from_user = (int)dPgetParam($_POST, 'from_user');
if (count($projects) > 1) {
$project_where = 'IN (';
$first = true;
foreach ($projects as $prj) {
if ($first) {
$first = false;
} else {
$project_where .= ',';
}
$project_where .= (int)$prj;
}
$project_where .= ')';
} else {
$project_where = '= ' . (int)$projects[0];
}
// Need to figure out which items to update. Easiest to do this
// as separate queries.
// Projects:
$q = new DBQuery();
$q->addUpdate('project_owner', $user_id);
$q->addTable('projects');
$q->addWhere('project_owner = ' . $from_user);
$q->addWhere('project_id' . $project_where);
if (! $q->exec()) {
$AppUI->setMsg('failed to update project owner', UI_MSG_ERROR);
return;
}
$q->clear();
$q->addUpdate('contact_id', $user_id);
$q->addTable('project_contacts');
$q->addWhere('contact_id = ' . $from_user);
$q->addWhere('project_id ' . $project_where);
if (!$q->exec()) {
$AppUI->setMsg('failed to update project contacts', UI_MSG_ERROR);
return;
}
$q->clear();
// Tasks:
$q->addUpdate('task_owner', $user_id);
$q->addTable('tasks');
$q->addWhere('task_owner = ' . $from_user);
$q->addWhere('task_project' . $project_where);
if (!$q->exec()) {
$AppUI->setMsg('failed to update task owner', UI_MSG_ERROR);
return;
}
$q->clear();
$q->addQuery('task_id');
$q->addTable('tasks');
$q->addWhere('task_project' . $project_where);
$task_sql = $q->prepare();
$q->clear();
$q->addUpdate('contact_id', $user_id);
$q->addTable('task_contacts');
$q->addWhere('contact_id = ' . $from_user);
$q->addWhere('task_id IN (' . $task_sql . ')');
if (!$q->exec()) {
$AppUI->setMsg('failed to update task contacts', UI_MSG_ERROR);
return;
}
$q->clear();
$q->addUpdate('user_id', $user_id);
$q->addTable('user_tasks');
$q->addWhere('user_id = ' . $from_user);
$q->addWhere('task_id IN (' . $task_sql . ')');
if (!$q->exec()) {
$AppUI->setMsg('failed to update task assignments', UI_MSG_ERROR);
return;
}
$q->clear();
$AppUI->setMsg('updated', UI_MSG_OK);