The following files exists in this folder. Click to view.
old_functions.php164 lines UTF-8 Unix (LF) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
<?php
// -------------------------------------------------------------------------------------------
//
// createCodeFromFile
// description: Makes <code>-tags around every line of the given file
// inparam: $filename, the name of the file (including directory)
// inparam: $specialCharacter, true if htmlspecialchars() will be used. Used with php and html
// return: String of code-tags
//
function createCodeFromFile($fileName, $specialCharacter){
$returnString = "";
$file = fopen($fileName, "r");
while(!feof($file)){
$returnString .= $specialCharacter ? "<code>".htmlspecialchars(fgets($file))."</code>" : "<code>".fgets($file)."</code>";
}
fclose($file);
return $returnString;
}
// -------------------------------------------------------------------------------------------
//
// createCodeFromArray
// description: Makes <code>-tags around every component of the given array
// inparam: $arr, the array
// return: String of code-tags
//
function createCodeFromArray($arr){
$returnString = "";
for($i = 0; $i < count($arr); $i++) {
$returnString .= "<code>".$arr[$i]."</code>\n";
}
return $returnString;
}
// -------------------------------------------------------------------------------------------
//
// createTableFromSql
// description: Makes a table of result from a sql script
// inparam: $arr, array of attribute to print head of table
// inparam: $sql, the sql script
// return: String of table content
//
function createTableFromSql($arr, $sql){
// Läser in databaskopplingen, require eftersom det måste göras igen!
require('dbConn.php');
$returnString = "<table class=\"utskrift\">
<tr>";
# creates head of table
for($i = 0; $i < count($arr); $i++) {
$returnString .= "<th>".$arr[$i]."</th>\n";
}
$returnString .= "</tr>";
# gets result set an makes body of the table
$stmt = $pdo->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$returnString .= "<tr>";
foreach ($arr as $i){
$returnString .= $row[$i]!="" ? "<td>{$row[$i]}</td>\n" : "<td><i>null</i></td>";
}
$returnString .= "</tr>";
}
$returnString .= "</table>";
return $returnString;
}
// -------------------------------------------------------------------------------------------
//
// createTableFromSqlEdit
// description: Makes a table of result from a sql script
// inparam: $arr, array of attribute to print head of table
// inparam: $sql, the sql script
// inparam: $table, name of table to link edit and delete
// return: String of table content
//
function createTableFromSqlEdit($arr, $sql, $table){
// Läser in databaskopplingen, require eftersom det måste göras igen!
require('dbConn.php');
$returnString = "<table class=\"utskrift\">
<tr>";
# Skapar tabellhuvudet
for($i = 0; $i < count($arr); $i++) {
$returnString .= "<th>".$arr[$i]."</th>\n";
}
$returnString .= "<th>delete</th>";
$returnString .= "</tr>";
# Hämtar resultset och placerar ut det i tabellen
$stmt = $pdo->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
# Special, hämta id och skriv ut det i första kolumnen och sista som länkar.
foreach ($result as $row) {
$id = -1;
$returnString .= "<tr>";
foreach ($arr as $i){
if($id == -1){
$id = $row[$i];
$returnString .= "<td><a href='edit.php?table={$table}&id={$id}'>{$row[$i]}</a></td>";
} else {
$returnString .= $row[$i]!="" ? "<td>{$row[$i]}</td>\n" : "<td><i>null</i></td>";
}
}
$returnString .= "<td><a href='edit.php?table={$table}&action=delete&id={$id}'>X</a></td>";
$returnString .= "</tr>";
}
$returnString .= "</table>";
return $returnString;
}
// -------------------------------------------------------------------------------------------
//
// executeSQLFile
// description: Run all sql-scripts from a file to the database
// inparam: $fileName, name of sql-file to run
// inparam: $urlRedirect, the page to redirect
// return: nothing
//
function executeSQLFile($fileName, $urlRedirect){
// Läser in databaskopplingen, require eftersom det måste göras igen!
require('dbConn.php');
$mess = "";
try
{
$sql = file_get_contents($fileName);
$qr = $pdo->exec($sql); # 2 är bra lokalt, 0 är bra på Binero
$mess = "Databasen återställd!";
# Kolla över detta, http://php.net/manual/en/pdo.exec.php
# $qr skall ge värdet för antal rader, kan man jobba med $db->errorInfo() för
// Errorinfo
// ok: Array ( [0] => 00000 [1] => [2] => )
# print_r($pdo->errorInfo());
#$mess = $pdo->errorInfo();
/*
if($qr == 2){
$mess = "Databasen återställd!";
} else {
$mess = "Något gick fel, databasen är ej återställd";
}*/
}
catch (PDOException $e)
{
$mess = "Connection failed: $e->getMessage()" ;
}
$urlRedirect .= "?mess=".$mess;
header("location: $urlRedirect");
}
?>