-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_user_tasks.php
More file actions
114 lines (101 loc) · 4.07 KB
/
Copy pathget_user_tasks.php
File metadata and controls
114 lines (101 loc) · 4.07 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
<?php
session_start();
$file = "users.xml";
$fp = fopen($file, "rb") or die("Err - can't open file");
$str = fread($fp, filesize($file));
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->loadXML($str) or die("Err - can't load XML data");
$root = $xml->documentElement;
$companies = $root;
$titleIndex = '0';
$leaderIndex = '1';
$participantsIndex = '2';
$targetDateIndex = '3';
$summaryIndex = '4';
$statusIndex = '5';
$urlIndex = '6';
function getAllLeaderTasks($companies, $titleIndex, $leaderIndex, $participantsIndex, $targetDateIndex, $summaryIndex, $statusIndex, $urlIndex)
{
$count = 0;
$tasksArray = array();
foreach ($companies->childNodes as $company) {
if($company->getAttribute('id') == $_SESSION["company-id"])
{
$tasks = $company->childNodes->item(2);
foreach ($tasks->childNodes as $task)
{
if($task->childNodes->item($leaderIndex)->nodeValue == $_POST['name'])
{
$tasksArray[$count]["id"] = $task->getAttribute('id');
$tasksArray[$count]["title"] = $task->childNodes->item($titleIndex)->nodeValue;
$tasksArray[$count]["leader"] = $task->childNodes->item($leaderIndex)->nodeValue;
$participants = $task->childNodes->item($participantsIndex);
$participantCount = 0;
foreach($participants->childNodes as $participant)
{
$tasksArray[$count]["participants"][$participantCount] = $participant->childNodes->item(0)->nodeValue;
$participantCount++;
}
$tasksArray[$count]["targetDate"] = $task->childNodes->item($targetDateIndex)->nodeValue;
$tasksArray[$count]["summary"] = $task->childNodes->item($summaryIndex)->nodeValue;
$tasksArray[$count]["status"] = $task->childNodes->item($statusIndex)->nodeValue;
$tasksArray[$count]["status"] = $task->childNodes->item($statusIndex)->nodeValue;
$tasksArray[$count]["url"] = $task->childNodes->item($urlIndex)->nodeValue;
$count++;
}
}
}
}
return $tasksArray;
}
function getAllParticipantTasks($companies, $titleIndex, $leaderIndex, $participantsIndex, $targetDateIndex, $summaryIndex, $statusIndex, $urlIndex)
{
$count = 0;
$tasksArray = array();
foreach ($companies->childNodes as $company) {
if($company->getAttribute('id') == $_SESSION["company-id"])
{
$tasks = $company->childNodes->item(2);
foreach ($tasks->childNodes as $task)
{
$participantsMatches = $task->childNodes->item($participantsIndex);
foreach ($participantsMatches->childNodes as $participantsMatch)
{
if($participantsMatch->childNodes->item(0)->nodeValue == $_POST['name'])
{
$tasksArray[$count]["id"] = $task->getAttribute('id');
$tasksArray[$count]["title"] = $task->childNodes->item($titleIndex)->nodeValue;
$tasksArray[$count]["leader"] = $task->childNodes->item($leaderIndex)->nodeValue;
$participants = $task->childNodes->item($participantsIndex);
$participantCount = 0;
foreach($participants->childNodes as $participant)
{
$tasksArray[$count]["participants"][$participantCount] = $participant->childNodes->item(0)->nodeValue;
$participantCount++;
}
$tasksArray[$count]["targetDate"] = $task->childNodes->item($targetDateIndex)->nodeValue;
$tasksArray[$count]["summary"] = $task->childNodes->item($summaryIndex)->nodeValue;
$tasksArray[$count]["status"] = $task->childNodes->item($statusIndex)->nodeValue;
$tasksArray[$count]["status"] = $task->childNodes->item($statusIndex)->nodeValue;
$tasksArray[$count]["url"] = $task->childNodes->item($urlIndex)->nodeValue;
$count++;
}
}
}
}
}
return $tasksArray;
}
if($_POST['role'] == 'leader')
{
$return['success'] = true;
$return['tasks'] = getAllLeaderTasks($companies, $titleIndex, $leaderIndex, $participantsIndex, $targetDateIndex, $summaryIndex, $statusIndex, $urlIndex);
}
if($_POST['role'] == 'participant')
{
$return['success'] = true;
$return['tasks'] = getAllParticipantTasks($companies, $titleIndex, $leaderIndex, $participantsIndex, $targetDateIndex, $summaryIndex, $statusIndex, $urlIndex);
}
echo json_encode($return);