3 * MS Project Integration Facility
5 * Copyright 2004 GForge, LLC
6 * http://fusionforge.org
8 * Provides some fuctions for Ms Project Plugin.
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfwww.'pm/msproject/msp.php';
28 $send_task_email=false;
30 if (getStringFromRequest('showform')) {
33 <title>XML Parser</title>
37 <form name="xmlparser" method="post" action="<?php echo getStringFromServer('PHP_SELF'); ?>">
39 <textarea name="document" cols="50" rows="10"></textarea>
41 <input type="hidden" name="parser" value="yes">
42 <input type="submit" value="Parser">
45 } elseif (getStringFromRequest("parser") == "yes") {
47 $data = getStringFromRequest("document");
52 $ph = fopen("php://input", "rb");
54 $data .= fread($ph, 4096);
56 //$data=addslashes($data);
64 //printr($data,'initial-data');
66 // SECTION 1. DEBUG XML
67 $data = str_replace("</ ","</",$data);
68 $data = str_replace("</ ","</",$data);
69 $data = str_replace("\r","",$data);
70 printr($data,'next-data');
71 printr(getenv('TZ'),'xmlparser1:: TZ');
74 //FUNCTIONS AND VARIABLES
76 global $principal_tag;
77 global $principal_action;
78 global $subproject_id;
86 global $parent_task_id;
87 global $parent_project_id;
92 global $iddependenton;
94 global $projectiddependenton;
95 global $linktypedependenton;
98 $fdependenton = false;
100 function startElement($parser, $name, $attrib){
101 global $principal_tag;
102 global $principal_action;
103 global $subproject_id;
106 global $parent_task_id;
107 global $parent_project_id;
111 global $fdependenton;
114 global $iddependenton;
115 global $projectiddependenton;
116 global $linktypedependenton;
121 if ($name == "TASK") {
122 /* $task_id = $attrib["ID"];
123 $project_id = $attrib["PROJECTID"];
124 $parent_task_id = $attrib["PARENT_TASK_ID"];
125 $parent_project_id = $attrib["PARENT_PROJECT_ID"];
126 $isnew = $attrib["ISNEW"];
128 if ($fdependenton == true){
129 $iddependenton = $attrib["ID"];
130 $projectiddependenton = $attrib["PROJECTID"];
131 $linktypedependenton= $attrib["LINKTYPE"];
134 if ($name == "DEPENDENTON") {
135 $fdependenton = true;
141 case $name=="REQUEST" : {
142 switch ($attrib["HANDLE"]){
143 case $attrib["HANDLE"] == "GetSubprojects": {
144 $principal_tag = $attrib["HANDLE"];
145 $result[$name] = $principal_tag;
148 case $attrib["HANDLE"] == "upload": {
149 $principal_tag = $attrib["HANDLE"];
150 $result[$name] = $principal_tag;
151 $result["ACTION"] = $attrib["ACTION"];;
154 case $attrib["HANDLE"] == "download": {
155 $principal_tag = $attrib["HANDLE"];
156 $result[$name] = $principal_tag;
157 $result["ACTION"] = $attrib["ACTION"];
160 case $attrib["HANDLE"] == "GetProjects": {
161 $principal_tag = $attrib["HANDLE"];
162 $result[$name] = $principal_tag;
165 case $attrib["HANDLE"] == "CreateProject": {
166 $principal_tag = $attrib["HANDLE"];
167 $result[$name] = $principal_tag;
168 $result["GROUPID"] = $attrib["GROUPID"];
175 case $name=="SUBPROJECT" : {
176 $subproject_id = $attrib["ID"];
180 case $name=="TASKS" : {
188 function endElement($parser, $name) {
190 global $iddependenton;
191 global $fdependenton;
194 global $resourcename;
195 global $principal_tag;
196 global $adependenton;
199 if ($name == "TASK" && $principal_tag=="upload" && ($fdependenton == false)){
201 $atasks["resources"] = $resourcename;
202 $resourcename = array();
204 if ($name == "TASK" && $principal_tag=="upload" &&($fdependenton == false)) {
205 $result["tasks"][] = $atasks;
208 if ($name == "DEPENDENTON" && $principal_tag=="upload"){
209 $fdependenton = false;
210 $atasks["dependenton"] = $adependenton;
211 $adependenton = array();
216 function characterDataHandler ($parser, $data) {
217 global $principal_tag;
218 global $subproject_id;
224 global $parent_task_id;
225 global $parent_project_id;
228 global $fdependenton;
229 global $iddependenton;
230 global $adependenton;
231 global $projectiddependenton;
232 global $linktypedependenton;
233 global $resourcename;
235 if (!$principal_tag) {return;}
236 if (!$tag_aux) {return;}
238 switch ($principal_tag){
239 case $principal_tag == "GetSubprojects": {
241 case $tag_aux == "LOGINID": {
242 $result["loginid"] = $data;
245 case $tag_aux == "PASSWORD": {
246 $result["password"] = $data;
254 case $principal_tag == "download": {
256 case $tag_aux == "SESSION_ID": {
257 $result["session_id"] = $data;
260 case $tag_aux == "SUBPROJECT": {
261 $result["subproject"][] = array("id"=>$subproject_id,"name"=>$data);
269 case $principal_tag == "GetProjects": {
271 case $tag_aux == "SESSION_ID": {
272 $result["session_id"] = $data;
278 case $principal_tag == "CreateProject": {
280 case $tag_aux == "SESSION_ID": {
281 $result["session_id"] = $data;
284 case $tag_aux == "NAME": {
285 $result["name"] = $data;
288 case $tag_aux == "ISPUBLIC": {
289 $result["ispublic"] = $data;
292 case $tag_aux == "DESCRIPTION": {
293 $result["description"] = $data;
299 case $principal_tag == "upload": {
301 case $tag_aux == "SESSION_ID": {
302 $result["session_id"] = $data;
305 case $tag_aux == "SUBPROJECT": {
306 $result["subproject"][] = array("id"=>$subproject_id,"name"=>$data);
309 case $tag_aux == "TASK": {
310 if ($fdependenton == true) {
311 $adependenton[] = array("task_id"=>$iddependenton,"msproj_id"=>$projectiddependenton,"link_type"=>$linktypedependenton,"task_name"=>$data);
315 $atasks["id"] = $task_id;
316 $atasks["msproj_id"] = $project_id;
317 $atasks["parent_id"] = $project_task_id;
318 $atasks["parent_msproj_id"] = $parent_project_id;
319 $atasks["isnew"] = $isnew;
324 case $tag_aux == "ID": {
325 $atasks["id"] = trim($data);
328 case $tag_aux == "PARENT_TASK_ID": {
329 $atasks["parent_id"] = trim($data);
332 case $tag_aux == "PROJECTID": {
333 $atasks["msproj_id"] = trim($data);
336 case $tag_aux == "PARENT_PROJECT_ID": {
337 $atasks["parent_msproj_id"] = trim($data);
340 case $tag_aux == "ISNEW": {
341 $atasks["isnew"] = trim($data);
344 case $tag_aux == "NAME": {
345 $atasks["name"] = trim($data);
348 case $tag_aux == "WORK": {
349 $atasks["work"] = trim($data);
352 case $tag_aux == "START_DATE": {
353 $atasks["start_date"] = trim($data);
356 case $tag_aux == "END_DATE": {
357 $atasks["end_date"] = trim($data);
360 case $tag_aux == "PERCENT_COMPLETE": {
361 $atasks["percent_complete"] = trim($data);
364 case $tag_aux == "DURATION": {
365 $atasks["duration"] = trim($data);
368 case $tag_aux == "PRIORITY": {
369 $atasks["priority"] = trim($data);
372 case $tag_aux == "RESOURCENAME": {
373 $resourcename[] = array("user_name"=>$data);
376 case $tag_aux == "NOTES": {
377 $atasks["notes"] = trim($data);
386 printr($foo2,'Starting XMLParse 1');
387 printr(getenv('TZ'),'xmlparser2:: TZ');
389 $xml_parser = xml_parser_create();
390 xml_set_element_handler($xml_parser, "startElement", "endElement");
391 printr($foo2,'Starting XMLParse 2');
392 xml_set_character_data_handler( $xml_parser, "characterDataHandler");
393 printr($foo2,'Starting XMLParse 3');
394 if (!xml_parse($xml_parser, $data,true)) {
395 printr($foo2,'Starting XMLParse 4');
396 $err=sprintf("XML error: %s at line %d",
397 xml_error_string(xml_get_error_code($xml_parser)),
398 xml_get_current_line_number($xml_parser));
399 printr($err,'Fatal Error');
402 xml_parser_free($xml_parser);
404 printr($result["REQUEST"],'request');
405 printr(getenv('TZ'),'xmlparser3:: TZ');
406 //SECTION 4. CALL GFORGE FUNCTIONS
407 switch ($result["REQUEST"]) {
409 case $result["REQUEST"] == "GetSubprojects": {
410 $gforgeresult = MSPLogin($result["loginid"],$result["password"]);
411 print('<?xml version="1.0"?>');
413 if ($gforgeresult["success"] == true) {
414 print('<response handle="result">');
415 print('<session_id>');
416 print($gforgeresult["session_hash"]);
417 print('</session_id>');
418 $subprojects = $gforgeresult["subprojects"];
419 print('<subprojects>');
420 if (count($subprojects) > 0 ) {
421 foreach($subprojects as $k => $v) {
422 print('<subproject id ="'.$k.'">'.$v.'</subproject>');
425 print('</subprojects>');
427 print('<response handle="error">');
428 print('<error><description>'.$gforgeresult["errormessage"].'</description></error>');
430 print('</response>');
435 case $result["REQUEST"] == "download": {
436 if ((trim($result["ACTION"]) == "GetLatestVersion") || (trim($result["ACTION"]) == "Checkout")) {
437 $gforgeresult =& MSPDownload($result["session_id"],$result["subproject"][0]["id"]);
438 printr($gforgeresult,'gforgeresult');
439 $return = ('<?xml version="1.0"?>');
440 $return .= ('<xml>');
441 if ($gforgeresult["success"] == true) {
442 $return .= ('<response handle="result">');
443 $tasks =& $gforgeresult["tasks"];
444 $return .= ('<sync_time>'.date('Y-m-d H:i:s').'</sync_time>');
445 $return .= ('<tasks>');
446 for ($tc=0; $tc<count($tasks); $tc++) {
448 $return .= ('<task id ="'.$task->getID().'">');
449 $return .= ('<projectid>'.$task->getExternalID().'</projectid>');
450 $return .= ('<name>'.$task->getSummary().'</name>');
451 $return .= ('<start_date>'.date('Y-m-d H:i:s',$task->getStartDate()).'</start_date>');
452 $return .= ('<end_date>'.date('Y-m-d H:i:s',$task->getEndDate()).'</end_date>');
453 $return .= ('<work>'.$task->getHours().'</work>');
454 $return .= ('<duration>'.$task->getDuration().'</duration>');
455 $return .= ('<percent_complete>'.$task->getPercentComplete().'</percent_complete>');
456 $return .= ('<priority>'.$task->getPriority().'</priority>');
457 $return .= ('<lastmodified>');
458 if ($task->getLastModifiedDate() != "") {
459 $return .= (date('Y-m-d H:i:s',$task->getLastModifiedDate()));
461 $return .= ('</lastmodified>');
462 $users =& user_get_objects($task->getAssignedTo());
463 if (count($users) == 1 && $users[0]->getID()==100) {
464 //skip if only one user - the 100 user
466 $return .= ('<resources>');
467 for ($i=0; $i<count($users); $i++) {
468 $return .= ('<resourcename>'.$users[$i]->getUnixName().'</resourcename>');
470 $return .= ('</resources>');
472 $dependenton =& $task->getDependentOn();
473 if (count($dependenton) == 1 && $dependenton[100]) {
474 //skip if only one user - the 100 user
476 $return .= ('<dependenton>');
478 while (list ($id, $link_type) = each ($dependenton)) {
479 $return .= ('<task id="'.$id.'" linktype="'.$link_type.'"></task>');
481 $return .= ('</dependenton>');
483 $return .= ('<notes>'.$task->getDetails().'</notes>');
484 $return .= ('</task>');
486 $return .= ('</tasks>');
487 printr($return,'download XML');
490 print($return.'<response handle="error">');
491 print('<error><description>'.$gforgeresult["errormessage"].'</description></error>');
493 print('</response>');
499 case $result["REQUEST"] == "upload": {
500 if (trim($result["ACTION"]) == "Checkin") {
501 $gforgeresult = MSPCheckin($result["session_id"],$result["subproject"][0]["id"],$result["tasks"]);
502 print('<?xml version="1.0"?>');
504 if (!isset($gforgeresult["success"]) || ($gforgeresult["success"] == false)) {
505 if ($gforgeresult["errormessage"] == "Invalid Resource Name") {
506 print('<response handle="mapuser">');
507 $resourcenames = $gforgeresult["resourcename"];
508 print('<resourcenames>');
509 if (count($resourcenames) > 0 ) {
510 foreach($resourcenames as $k => $resourcename) {
511 print('<resourcename>'.$resourcename.'</resourcename>');
514 print('</resourcenames>');
515 print('<usernames>');
516 $usernames = $gforgeresult["usernames"];
517 if (count($usernames) > 0 ) {
518 foreach($usernames as $k => $username) {
519 print('<user id ="'.$k.'">'.$username.'</user>');
522 print('</usernames>');
524 print('<response handle="error">');
526 print('<description>'.$gforgeresult["errormessage"].'</description>');
529 print('</response>');
531 print ('<response handle="result">success</response>');
535 if (trim($result["ACTION"]) == "Undo") {
536 print('<?xml version="1.0"?>');
538 print ('<response handle="result">success</response>');
540 //call MSPUNDO($result["session_id"],$result["subproject"]["id"]);
546 case $result["REQUEST"] == "GetProjects": {
548 $gforgeresult = MSPGetProjects($result["session_id"]);
549 print('<?xml version="1.0"?>');
552 print('<response handle="result">');
554 for ($c=0;$c<count($gforgeresult);$c++) {
555 $cgroup=$gforgeresult[$c];
556 print('<project id ="'.$cgroup->getID().'">'.$cgroup->getPublicName().'</project>');
558 print('</projects>');
560 print('<response handle="error">');
562 print('<description>Not a member of any projects</description>');
565 print('</response>');
570 case $result["REQUEST"] == "CreateProject": {
571 if($result["ispublic"]==1 || $result["ispublic"]==true) {
572 $result["ispublic"]=1;
574 $result["ispublic"]=0;
576 $gforgeresult = MSPCreateProject($result["GROUPID"],$result["session_id"],$result["name"],$result["ispublic"],$result["description"]);
577 print('<?xml version="1.0"?>');
579 if (!is_object($gforgeresult) && $gforgeresult['code'] == "error") {
580 print('<response handle="error">');
582 print('<description>'.$gforgeresult['description'].'</description>');
585 print('<response handle="result">');
586 print('<Group_ID>'.$result["GROUPID"].'</Group_ID>');
587 print('<Group_Project_ID>'.$gforgeresult->getID().'</Group_Project_ID>');
589 print('</response>');