Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
functions.php
1<?php
2
3// get js onclick for sorting
4function getJavaSort($field)
5{
6 $addr = "index.php";
7 $flag = "ASC";
8 if (isset($_GET['flag'])) {
9 if ($_GET['flag'] == "ASC") {
10 $flag = "DESC";
11 }
12 }
13 if (isset($_GET['tags'])) {
14 $addr = "index.php?tags=" . $_GET['tags'] . "&flag=" . $flag;
15 } else {
16 $addr = "index.php?flag=" . $flag;
17 }
18 $addr = $addr . "&orderby=" . $field;
19 return "<td onclick=\"window.location='" . $addr . "'\">";
20}
21
22// return query with or without sorting
23function getQuery($db)
24{
25 $stmt = "SELECT * FROM Files";
26 if (isset($_GET['tags'])) {
27 if ($_GET['tags'] != "") {
28 $que = $_GET['tags'];
29
30 preg_match_all('("([^"]|"")*")', $que, $sentences);
31 foreach ($sentences[0] as $value) {
32 $que = str_replace($value, " ", $que);
33 }
34 $que = preg_replace('/\s+/', ' ', $que);
35 $arr = preg_split('/[\s]+/', $que);
36 $i = 0;
37 $bind_tags = "";
38 $bind_comment = "";
39 $array_tags = array();
40 $array_comment = array();
41 foreach ($arr as $value) {
42 if (strlen($value) == 0)
43 continue;
44 if ($value[0] == '#') {
45 $value = substr($value, 1); // remove #
46 array_push($array_tags, $value);
47 } else {
48 array_push($array_comment, $value);
49 }
50 }
51 $question_tag = "";
52 $name_id = 0;
53 if (count($array_tags) > 0 || count($array_comment) > 0 || count($sentences[0]) > 0) {
54 $stmt = $stmt . " WHERE ";
55 }
56 if (count($array_tags) > 0) {
57 $question_tag = "Tags LIKE ";
58 foreach ($array_tags as $value) {
59 $question_tag = $question_tag . ":name" . ($name_id ++) . " AND Tags LIKE";
60 }
61 $question_tag = substr($question_tag, 0, - 13);
62 $question_tag = $question_tag . "";
63 }
64 $question_word = "";
65 if (count($array_comment) > 0 || count($sentences[0]) > 0) {
66 $question_word = "Comment LIKE ";
67 foreach ($array_comment as $value) {
68 $question_word = $question_word . ":name" . ($name_id ++) . " AND Comment LIKE";
69 }
70 foreach ($sentences[0] as $value) {
71 $question_word = $question_word . ":name" . ($name_id ++) . " AND Comment LIKE";
72 }
73 $question_word = substr($question_word, 0, - 16);
74 $question_word = $question_word . "";
75 }
76
77 if (strlen($question_tag) > 0 && strlen($question_word) > 0) {
78 $stmt = $stmt . "(" . $question_tag . ") AND (" . $question_word . ")";
79 } else if (strlen($question_tag) > 0) {
80 $stmt = $stmt . " " . $question_tag;
81 } else {
82 $stmt = $stmt . " " . $question_word;
83 }
84 $statement = $db->prepare($stmt);
85 $count = 0;
86 foreach ($array_tags as $val) {
87 $val = '%' . $val . '%';
88 $parname = ":name" . $count ++;
89 $statement->bindParam($parname, $val);
90 }
91 foreach ($array_comment as $val) {
92 $val = "%" . $val . "%";
93 $parname = ":name" . $count ++;
94 $statement->bindParam($parname, $val);
95 }
96 foreach ($sentences[0] as $val) {
97 $val = "%" . $val . "%";
98 $parname = ":name" . $count ++;
99 $statement->bindParam($parname, $val);
100 }
101
102 $xx = $statement->execute();
103 // $statement->debugDumpParams();
104 return $xx;
105 }
106 }
107 if (isset($_GET['flag']) && isset($_GET['orderby'])) {
108 $stmt = $stmt . " ORDER BY " . $_GET['orderby'] . " " . $_GET['flag'];
109 return $db->query($stmt);
110 }
111 return $db->query($stmt);
112}
113
114// return google record
115function getGoogleRec($row)
116{
117 echo "<a href=\"html_rep/html_" . $row['FILE_ID'] . "/index.html?task_id=" . $row['TASK_ID'] . "\">" . $row['ID'] . ". " . $row['Comment'] . "</a></br>" . PHP_EOL;
118 echo "<font color=\"green\">Tags : " . $row['Tags'] . "</font></br>" . PHP_EOL;
119 echo "File path: " . $row['PathFile'] . "</br>" . PHP_EOL;
120 echo "Analysis name: " . $row['AnaName'] . "</br>" . PHP_EOL;
121 echo "Input file: " . $row['InputFile'] . "</br>" . PHP_EOL;
122 echo "Data format: " . $row['DataType'] . "</br>" . PHP_EOL;
123 echo "Processed events: " . $row['ProcessedEvents'] . "</br>" . PHP_EOL;
124 echo "Software ver: " . $row['SoftVer'] . "</br>" . PHP_EOL;
125}
126
127// get table-like record
128function getTableRec($row)
129{
130 echo "<tr><td>" . $row['ID'] . "</td><td>" . $row['Comment'] . "</td><td>" . $row['InputFile'] . "</td><td>" . $row['AnaName'] . "</td><td>" . $row['PathFile'] . "</td><td><a href=\"html_rep/html_" . $row['FILE_ID'] . "/index.html?task_id=" . $row["TASK_ID"] . "\">Link</a></td><td>" . $row['Tags'] . "</td></tr>" . PHP_EOL;
131}
132
133// show entrie table
134function showTable($result)
135{
136 echo "</td></tr></table>" . PHP_EOL;
137 echo "<div class=\"CSSTableGenerator\">" . PHP_EOL;
138 echo "<table class=\"sortable\">" . PHP_EOL;
139 echo "<tr><td>No</td>" . getJavaSort("Comment") . "Comment</td>" . getJavaSort("InputFile") . "InputFile</td>" . getJavaSort("AnaName") . "AnaName</td>" . getJavaSort("PathFile") . "Full Path</td>" . getJavaSort("ID") . "Link</td>" . getJavaSort("Tags") . "Tags</td><tr>" . PHP_EOL;
140 while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
141 getTableRec($row);
142 }
143 echo "</table>" . PHP_EOL;
144 echo "</div>" . PHP_EOL;
145}
146
147// show google
148function showGoogle($result)
149{
150 while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
151 getGoogleRec($row);
152 }
153 echo "</table>" . PHP_EOL;
154}
155
156?>