PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/import_action.php

https://github.com/Burton/Analysis-of-Competing-Hypotheses
PHP | 204 lines | 117 code | 63 blank | 24 comment | 83 complexity | 2327f804f6aed4a206174935694148e0 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /* ////////////////////////////////////////////////////////////////////////////////
  3. ** Copyright 2010 Matthew Burton, http://matthewburton.org
  4. ** Code by Burton and Joshua Knowles, http://auscillate.com
  5. **
  6. ** This software is part of the Open Source ACH Project (ACH). You'll find
  7. ** all current information about project contributors, installation, updates,
  8. ** bugs and more at http://competinghypotheses.org.
  9. **
  10. **
  11. ** ACH is free software: you can redistribute it and/or modify
  12. ** it under the terms of the GNU General Public License as published by
  13. ** the Free Software Foundation, either version 3 of the License, or
  14. ** (at your option) any later version.
  15. **
  16. ** ACH 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.
  20. **
  21. ** You should have received a copy of the GNU General Public License
  22. ** along with Open Source ACH. If not, see <http://www.gnu.org/licenses/>.
  23. //////////////////////////////////////////////////////////////////////////////// */
  24. header("Content-Type: text/html; charset=iso-8859-1");
  25. include("code/includes.php");
  26. if ( isset($_FILES['achz']['name']) ) {
  27. $filedir = 'imports/';
  28. $filename = $filedir . basename($_FILES['achz']['name']);
  29. if( move_uploaded_file($_FILES['achz']['tmp_name'], $filename) ) {
  30. $success = TRUE;
  31. } else {
  32. $success = FALSE;
  33. }
  34. }
  35. if( $success ) {
  36. $short_filename = substr($filename, 0, -4) . "gz";
  37. $unzip_filename = substr($filename, 0, -5);
  38. exec("mv " . $filename . " " . $short_filename);
  39. exec("gunzip -d " . $short_filename);
  40. $fh = fopen($unzip_filename, "r");
  41. while( !feof($fh) ) { $filedata .= fgets($fh, 4096); }
  42. fclose($fh);
  43. $filedata = utf16_to_utf8($filedata);
  44. $filedata = str_replace("PROJECT-TITLE>", "PROJECTTITLE>", $filedata);
  45. $filedata = str_replace("LAST-INDEX>", "LASTINDEX>", $filedata);
  46. $filedata = str_replace("COLOR-SCHEME>", "COLORSCHEME>", $filedata);
  47. //echo($filedata);
  48. $dom = new domDocument;
  49. $dom->loadXML($filedata);
  50. $achz = simplexml_import_dom($dom);
  51. //print_r($achz);
  52. $this_project = new Project();
  53. $this_project->title = $achz->PROJECTTITLE;
  54. if( strtolower($achz->CLASSIFICATION) == "u" ) { $this_project->classification = "U"; }
  55. if( strtolower($achz->CLASSIFICATION) == "fouo" ) { $this_project->classification = "U"; }
  56. if( strtolower($achz->CLASSIFICATION) == "aiou" ) { $this_project->classification = "U"; }
  57. if( strtolower($achz->CLASSIFICATION) == "unclassified" ) { $this_project->classification = "U"; }
  58. if( strtolower($achz->CLASSIFICATION) == "c" ) { $this_project->classification = "C"; }
  59. if( strtolower($achz->CLASSIFICATION) == "confidential" ) { $this_project->classification = "C"; }
  60. if( strtolower($achz->CLASSIFICATION) == "s" ) { $this_project->classification = "S"; }
  61. if( strtolower($achz->CLASSIFICATION) == "secret" ) { $this_project->classification = "S"; }
  62. if( strtolower($achz->CLASSIFICATION) == "t" ) { $this_project->classification = "TS"; }
  63. if( strtolower($achz->CLASSIFICATION) == "ts" ) { $this_project->classification = "TS"; }
  64. if( strtolower($achz->CLASSIFICATION) == "top secret" ) { $this_project->classification = "TS"; }
  65. if( strtolower($achz->CLASSIFICATION) == "top-secret" ) { $this_project->classification = "TS"; }
  66. $this_project->open = "n";
  67. $this_project->user_id = $active_user->id;
  68. $this_project->insertNew();
  69. $this_hypothesis = Array();
  70. for( $i = 0; $i < count($achz->MATRIX->HYPOTHESIS); $i++ ) {
  71. $this_hypothesis[$i] = new Hypothesis();
  72. $this_hypothesis[$i]->label = $achz->MATRIX->HYPOTHESIS[$i]->NAME;
  73. $this_hypothesis[$i]->user_id = $active_user->id;
  74. $this_hypothesis[$i]->project_id = $this_project->id;
  75. $this_hypothesis[$i]->insertNew();
  76. }
  77. for( $i = 0; $i < count($achz->MATRIX->EVIDENCE); $i++ ) {
  78. $this_evidence = new Evidence();
  79. $this_evidence->name = $achz->MATRIX->EVIDENCE[$i]->NAME[0];
  80. $this_evidence->details = $achz->MATRIX->EVIDENCE[$i]->NOTES[0];
  81. if( $achz->MATRIX->EVIDENCE[$i]->LINK[0] != "" ) {
  82. if( $this_evidence->details != "" ) { $this_evidence->details .= " "; }
  83. $this_evidence->details .= "Link: " . $achz->MATRIX->EVIDENCE[$i]->LINK[0];
  84. }
  85. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "open source" ) { $this_evidence->type = "OSINT"; }
  86. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "osint" ) { $this_evidence->type = "OSINT"; }
  87. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "press" ) { $this_evidence->type = "OSINT"; }
  88. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "assu" ) { $this_evidence->type = "Assumption"; }
  89. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "assumption" ) { $this_evidence->type = "Assumption"; }
  90. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "hum" ) { $this_evidence->type = "HUMINT"; }
  91. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "humint" ) { $this_evidence->type = "HUMINT"; }
  92. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "imagery" ) { $this_evidence->type = "IMINT"; }
  93. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "imint" ) { $this_evidence->type = "IMINT"; }
  94. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "sig" ) { $this_evidence->type = "SIGINT"; }
  95. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "sigint" ) { $this_evidence->type = "SIGINT"; }
  96. if( strtolower($achz->MATRIX->EVIDENCE[$i]->TYPE[0]) == "masint" ) { $this_evidence->type = "MASINT"; }
  97. $date_of_source = substr($achz->MATRIX->EVIDENCE[$i]->DATE, 0, -3);
  98. if ($achz->MATRIX->EVIDENCE[$i]->DATE == 0) {
  99. $this_evidence->date_of_source = "";
  100. } else { $this_evidence->date_of_source = date("Y-m-d H:i:s", $date_of_source);
  101. }
  102. $this_evidence->code = $achz->MATRIX->EVIDENCE[$i]->CODE[0];
  103. $this_evidence->user_id = $active_user->id;
  104. $this_evidence->project_id = $this_project->id;
  105. if( $achz->MATRIX->EVIDENCE[$i]->FLAG == 1 ) {
  106. $this_evidence->flag = "y";
  107. } else {
  108. $this_evidence->flag = "n";
  109. }
  110. $this_evidence->insertNew();
  111. $values = Array();
  112. $values = explode(",", $achz->MATRIX->EVIDENCE[$i]->VALUES[0]);
  113. for( $j = 0; $j < count($values); $j++ ) {
  114. if( $values[$j] == "I I" ) { $this_rating = "Very Inconsistent"; }
  115. if( $values[$j] == "I" ) { $this_rating = "Inconsistent"; }
  116. if( $values[$j] == "NA" ) { $this_rating = "N/A"; }
  117. if( $values[$j] == "N" ) { $this_rating = "Neutral"; }
  118. if( $values[$j] == "C" ) { $this_rating = "Consistent"; }
  119. if( $values[$j] == "C C" ) { $this_rating = "Very Consistent"; }
  120. $this_hypothesis_id = $this_hypothesis[$j]->id;
  121. mysql_do("INSERT INTO `ratings` (`hypothesis_id`,`evidence_id`,`user_id`,`rating`) VALUES ('$this_hypothesis_id', '$this_evidence->id', '$active_user->id', '$this_rating');");
  122. }
  123. $this_credibility = new Credibility();
  124. $this_credibility->evidence_id = $this_evidence->id;
  125. $this_credibility->user_id = $active_user->id;
  126. if( $achz->MATRIX->EVIDENCE[$i]->CREDIBILITY == "HIGH" ) { $this_credibility->value = "y"; }
  127. if( $achz->MATRIX->EVIDENCE[$i]->CREDIBILITY == "MEDIUM" ) { $this_credibility->value = "y"; }
  128. if( $achz->MATRIX->EVIDENCE[$i]->CREDIBILITY == "LOW" ) { $this_credibility->value = "n"; }
  129. $this_credibility->weight = 1;
  130. $this_credibility->insertNew();
  131. }
  132. }
  133. ?>
  134. <html>
  135. <head>
  136. <title>Updating...</title>
  137. <meta http-equiv=Refresh content="0; url=project/<?=$this_project->id?>/edit">
  138. </head>
  139. <body>
  140. </body>
  141. </html>