-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_task.php
More file actions
115 lines (94 loc) · 3.03 KB
/
Copy pathadd_task.php
File metadata and controls
115 lines (94 loc) · 3.03 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
<?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;
$return = array();
function getNewID($companies)
{
$highestNum = 0;
foreach ($companies->childNodes as $company)
{
$tasks = $company->childNodes->item(2);
$companyID = $company->getAttribute('id');
$companyName = $company->childNodes->item(0)->nodeValue;
foreach ($tasks->childNodes as $task)
{
if($task->getAttribute('id') > $highestNum)
{
$highestNum = $task->getAttribute('id');
}
}
}
return $highestNum+1;
}
function addTask($companies, $newID, $xml)
{
$title = $_POST['title'];
$leader = $_POST['leader'];
$participants = $_POST['participants'];
$date = $_POST['date'];
$summary = $_POST['summary'];
$status = 'New';
$url = $_POST['url'];
foreach ($companies->childNodes as $company)
{
if($company->getAttribute('id') == $_SESSION['company-id'])
{
$tasks = $company->childNodes->item(2);
$firstTask = $tasks->childNodes->item(0);
$participantNode;
//title node
$titleNode=$xml->createElement("title");
$titleTextNode=$xml->createTextNode($title);
$titleNode->appendChild($titleTextNode);
//leader node
$leaderNode=$xml->createElement("leader");
$leaderTextNode=$xml->createTextNode($leader);
$leaderNode->appendChild($leaderTextNode);
//participants node
$participantsNode=$xml->createElement("participants");
$participantNode=$xml->createElement("participant");
$participantTextNode=$xml->createTextNode($participants[0]);
$participantNode->appendChild($participantTextNode);
$participantsNode->appendChild($participantNode);
//date node
$dateNode=$xml->createElement("date");
$dateTextNode=$xml->createTextNode("$date");
$dateNode->appendChild($dateTextNode);
//summary node
$summaryNode=$xml->createElement("summary");
$summaryTextNode=$xml->createTextNode("$summary");
$summaryNode->appendChild($summaryTextNode);
//status node
$statusNode=$xml->createElement("status");
$statusTextNode=$xml->createTextNode("$status");
$statusNode->appendChild($statusTextNode);
//url node
$urlNode=$xml->createElement("url");
$urlTextNode=$xml->createTextNode("$url");
$urlNode->appendChild($urlTextNode);
$newTaskNode=$xml->createElement("task");
$newTaskNode->setAttribute("id",$newID);
$newTaskNode->appendChild($titleNode);
$newTaskNode->appendChild($leaderNode);
$newTaskNode->appendChild($participantsNode);
$newTaskNode->appendChild($dateNode);
$newTaskNode->appendChild($summaryNode);
$newTaskNode->appendChild($statusNode);
$newTaskNode->appendChild($urlNode);
$tasks->insertBefore($newTaskNode,$firstTask);
$xml->save("users.xml");
}
}
}
$newID = getNewID($companies);
addTask($companies, $newID, $xml);
$return['success'] = true;
echo json_encode($return);