/** * update the content of the note in the DB * @param string $url * @param text $content * @return boolean true, if PDO success * @return error message if exception catched during PDO */ function updateNote($url, $content, $pdo) { if (!isSaved($url)) { try { $stmt = $pdo->prepare("INSERT INTO note(id,content,pwdView,pwdEdit) VALUES(:url,:content,:pwdView,:pwdEdit)"); $stmt->bindValue(':url', $url, PDO::PARAM_STR); $stmt->bindValue(':content', $content, PDO::PARAM_STR); $stmt->bindValue(':pwdView', null); $stmt->bindValue(':pwdEdit', null); $stmt->execute(); return True; } catch (PDOException $e) { throw $e; } } else { try { $stmt = $pdo->prepare("UPDATE note SET content = :content WHERE id = :url"); $stmt->bindValue(':url', $url, PDO::PARAM_STR); $stmt->bindValue(':content', $content, PDO::PARAM_STR); $stmt->execute(); return True; } catch (PDOException $e) { throw $e; } } }
/** * add a password to protect the view * @param string $url * @param string $password * @return boolean true, if password was added * @return error message if exception catched during PDO */ function protectView($url, $password, $pdo) { require 'password_hash.php'; $hash = create_hash($password); if (!isSaved($url)) { try { $stmt = $pdo->prepare("INSERT INTO note(id,content,pwdView,pwdEdit) VALUES(:url,:content,:pwdView,:pwdEdit)"); $stmt->bindValue(':url', $url, PDO::PARAM_STR); $stmt->bindValue(':content', null); $stmt->bindValue(':pwdView', $hash, PDO::PARAM_STR); $stmt->bindValue(':pwdEdit', null); $stmt->execute(); return True; } catch (PDOException $e) { throw $e; } } else { try { $stmt = $pdo->prepare("UPDATE note SET pwdView = :pwdView WHERE id = :url"); $stmt->bindValue(':url', $url, PDO::PARAM_STR); $stmt->bindValue(':pwdView', $hash, PDO::PARAM_STR); $stmt->execute(); return True; } catch (PDOException $e) { throw $e; } } }
function saveQuery($arrayserialized, $first, $second, $limit, $maxdepth, $depth) { include 'queries.inc.php'; $save = unserialize(str_replace('__perc__', '%', str_replace('__quot__', '"', $arrayserialized))); $first = str_replace('__perc__', '%', $first); $second = str_replace('__perc__', '%', $second); $ignoredPredicates = array(); $ignoredObjects = array(); for ($t = 0; $t < 5; $t++) { if (isset($_REQUEST['ignoreObject_' . $t])) { $ignoredObjects[] = $_REQUEST['ignoreObject_' . $t]; } } for ($t = 0; $t < 5; $t++) { if (isset($_REQUEST['ignorePredicate_' . $t])) { $ignoredPredicates[] = $_REQUEST['ignorePredicate_' . $t]; } } if (!isSaved($first, $second, $limit, $maxdepth, $depth, $ignoredObjects, $ignoredPredicates)) { $queries[] = array('firstObject' => $first, 'secondObject' => $second, 'limit' => $limit, 'maxdepth' => $maxdepth, 'savedResult' => $save, 'ignoredObjects' => $ignoredObjects, 'ignoredPredicates' => $ignoredPredicates, 'clickCount' => 1, 'saveTime' => microtime(true)); file_put_contents('queries.inc.php', "<?\n\$queries=" . var_export($queries, true) . ";\n?>"); echo '<span style="color:green">Query saved!</span>'; } else { echo '<span style="color:red">Query already saved!</span>'; } }
function calcConnectionDirectConnection($first, $second, $startlimit, $maxdepth, $depth, $ignoredObjects, $ignoredPredicates, $fullconnection) { $time = microtime(true); mysql_connect($GLOBALS['host'], $GLOBALS['user'], $GLOBALS['password']); mysql_select_db($GLOBALS['db']); //fuer alte Links if (isset($_GET['maxdepth'])) { $maxdepth = $_GET['maxdepth'] + 1; } $foundconnection = false; $limit = $startlimit; $idcounter = 0; $htmlcounter = 0; $saveRow = array(); //ignorierte Objekte/Praedikate kommen als Array an => Umrechnung in String fuer URL for ($i = 0; $i < count($ignoredObjects); $i++) { $permalinkIgnoreObjects .= '&ignoreObject_' . $i . '=' . $ignoredObjects[$i]; } for ($i = 0; $i < count($ignoredPredicates); $i++) { $permalinkIgnorePredicates .= '&ignorePredicate_' . $i . '=' . $ignoredPredicates[$i]; } //Ueberpruefung, ob gegebene Anfrage schon gespeichert ist include "queries.inc.php"; $savedIndex = isSaved($first, $second, $limit, $maxdepth, $depth, $ignoredObjects, $ignoredPredicates); //Falls gegebene Anfrage schon gespeichert ist=> Ausgeben if (is_int($savedIndex)) { $lastdepth = -1; for ($i = 0; $i < count($queries[$savedIndex]['savedResult']['row']); $i++) { echo $lastdepth != $queries[$savedIndex]['savedResult']['depth'][$i] ? '<table style="border:solid 1px #FF8040;margin-left:2px;"><tr><td style="background-color:#e4e4e4;border:1px solid #CFCFCF;">Distance: ' . ($queries[$savedIndex]['savedResult']['depth'][$i] + 1) . '</td></tr>' : ''; printResults($queries[$savedIndex]['savedResult']['row'][$i], $htmlcounter, $idcounter, $first, $second); echo $queries[$savedIndex]['savedResult']['depth'][$i] != $queries[$savedIndex]['savedResult']['depth'][$i + 1] || !isset($queries[$savedIndex]['savedResult']['depth'][$i + 1]) ? '</table><br>' : ''; $lastdepth = $queries[$savedIndex]['savedResult']['depth'][$i]; } echo 'This is a cached result. It was saved on ' . date('r', $queries[$savedIndex]['saveTime']) . '.<br>'; $queries[$savedIndex]['clickCount']++; file_put_contents('queries.inc.php', "<?\n\$queries=" . var_export($queries, true) . ";\n?>"); } else { if ($GLOBALS['usingClusterTable'] == true && $fullconnection == false) { $clusterConSwitch = calcConnectionCluster($first, $second, $maxdepth); if (is_Int($clusterConSwitch)) { $depth = $clusterConSwitch; echo 'We are now searching the complete data set for connections. Meanwhile, you may have a look at a preview result <a href="#" onclick="loadClusterConnection(\'ajax.php?f=6&first=' . str_replace("%", "__perc__", $first) . '&second=' . str_replace("%", "__perc__", $second) . $permalinkIgnoreObjects . $permalinkIgnorePredicates . '\')" title="Load Cluster Connection">here</a>.<br><br>'; echo '<div id="clusterCon" style="display:none;"></div>'; echo '<div id="ib_1000" style="position:absolute;top:500px;left:20%;width:200px;height:100px;"></div>'; #echo ', or maybe you want to <a href="'.substr($_SERVER['PHP_SELF'],0,-strlen($_SERVER['SCRIPT_NAME'])).'index.php?firstObject='.$first.'&secondObject='.$second.'&limit='.$startlimit.'&maxdistance='.$maxdepth.$permalinkIgnoreObjects.$permalinkIgnorePredicates.'&fullc=true&saved=saved">load the full Results</a>?<br><br>'; $fullconnection = true; } else { if ($clusterConSwitch == 'notenoughdistance') { echo 'For a Preview Result click <a href="#" onclick="loadClusterConnection(\'ajax.php?f=6&first=' . str_replace("%", "__perc__", $first) . '&second=' . str_replace("%", "__perc__", $second) . $permalinkIgnoreObjects . $permalinkIgnorePredicates . '\')" title="Load Cluster Connection">here</a>.<br>'; echo '<div id="clusterCon" style="display:none;"></div>'; echo '<div id="ib_0" style="position:absolute;top:500px;left:20%;width:200px;height:100px;"></div>'; } } } if ($fullconnection == true || $GLOBALS['usingClusterTable'] == false) { ob_flush(); flush(); do { //Berechnung der Verbindung, falls dieses moeglich ist $res = mysql_query(getQuery($depth, $first, $second, $limit, $ignoredObjects, $ignoredPredicates)) or die(mysql_error()); if (mysql_num_rows($res) > 0) { $limit = $limit - mysql_num_rows($res); $foundconnection = true; echo '<table style="border:solid 1px #FF8040;margin-left:2px;"><tr><td style="background-color:#e4e4e4;border:1px solid #CFCFCF;">Distance: ' . ($depth + 1) . '</td></tr>'; while ($row = mysql_fetch_row($res)) { printResults($row, $htmlcounter, $idcounter, $first, $second); $saveRow['row'][] = $row; $saveRow['depth'][] = $depth; } echo '</table><br>'; } else { if ($depth == $maxdepth - 1) { echo "No Connection Found at max. Distance {$maxdepth} !<br><br>"; //f�r maximale Tiefe Fehlschlag ausgeben #if ($GLOBALS['usingClusterTable']==true) #calcConnectionCluster($first,$second,$maxdepth,true); } } $depth++; } while ($depth < $maxdepth && $limit > 0); if ($foundconnection == true) { //Queries koennen abgespeichert werden, wenn eine Verbindung gefunden wurde echo '<span style="padding-left:2px;">Would you like to <a href="#" title="save Query" onmousedown="saveQuery(\'ajax.php?f=3&first=' . str_replace("%", "__perc__", $first) . '&second=' . str_replace("%", "__perc__", $second) . '&limit=' . $startlimit . '&maxdepth=' . $maxdepth . $permalinkIgnoreObjects . $permalinkIgnorePredicates . '&depth=' . $depth . '\',\'' . str_replace('%', '__perc__', str_replace('"', '__quot__', serialize($saveRow))) . '\');">save</a> your query?</span><br>'; echo '<span style="padding-left:2px;"><div id="save"> </div></span><br>'; } } } echo 'Result obtained in ' . round(microtime(true) - $time, 3) . ' seconds.<br>'; }