require_once('jb_inc_conf.php');
function jb_connect( $fnwhere ) { // ** CONNECT TO MySQL DATABASE ON Hostagator - return handle or die
$handle = mysqli_connect("localhost", "jbideas_fun001", "cuefun001");
if (!$handle) {
// mysql_connect failed
die("Connection to database failed in function [" . $fnwhere . "] because: " . mysqli_error($handle) );
} else {
if (!mysqli_select_db($handle, "jbideas_functionality")) {
die('Database selection [jbideas_functionality] failed because ' . mysqli_error($handle));
}
}
return $handle;
} // jb_connect
function jb_recreate_tables() { // ** DESTROYS ALL DATA - RECREATES ALL TABLES AGAIN
$handle=jb_connect("jb_create_tables"); // connect or die
// DROP ALL TABLES
$sql="DROP TABLE IF EXISTS fsf";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error DROPPING table [fsf]: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS dropping table [fsf]
";
}
$sql="DROP TABLE IF EXISTS stm";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error DROPPING table [stm]: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS dropping table [stm]
";
}
$sql="DROP TABLE IF EXISTS sss";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error DROPPING table [sss]: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS dropping table [sss]
";
}
$sql="DROP TABLE IF EXISTS cltc";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error DROPPING table [cltc]: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS dropping table [cltc]
";
}
$sql="DROP TABLE IF EXISTS clti";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error DROPPING table [clti]: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS dropping table [clti]
";
}
$sql="DROP TABLE IF EXISTS cltv";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error DROPPING table [cltv]: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS dropping table [cltv]
";
}
$sql="DROP TABLE IF EXISTS pct";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error DROPPING table [pct]: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS dropping table [pct]
";
}
$sql="DROP TABLE IF EXISTS cse";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error DROPPING table [cse]: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS dropping table [cse]
";
}
// CREATE ALL NECESSARY TABLES
$sql="CREATE TABLE IF NOT EXISTS fsf ( " . // ** BESTANDEN EN DIRECTORIES **
"fsf_name VARCHAR(100), " . // de naam van het bestand of de directory
"fsf_isfirst INTEGER, " . // is het het eerste image dus voor de catalogus? 0=nee, 1=ja
"fsf_isdir INTEGER, " . // is het een directory? 0=nee, 1=ja
"fsf_dirpath TEXT, " . // het pad totaan de directory of het bestand
"fsf_width INTEGER, " . // image breedte in pixels
"fsf_height INTEGER, " . // image hoogte in pixels
"fsf_size INTEGER, " . // grootte van het bestand in bytes
"fsf_description TEXT, " . // beheerder: beschrijving van het bestand of directory *not used*
"fsf_price TEXT, " . // prijs van het image *not used*
"fsf_firstscanned VARCHAR(14), " . // wanneer dit bestand voor het eerst gevonden is
"fsf_lastscanned VARCHAR(14), " . // laatste keer dat dit bestand gescand is
"PRIMARY KEY (fsf_name) " . // de sleutel
");";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error creating table [fsf] ERROR: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS creating table [fsf]
";
}
// ----------------------------------------------------------------------------------------------------
$sql="CREATE TABLE IF NOT EXISTS stm ( " . // ** SYSTEEM INSTELLINGEN ** we gebruiken stm_user John als sleutel
"stm_id INTEGER, " . // Nep sleutel, waarde is altijd 1
"stm_lastscanned VARCHAR(14), " . // De laatste keer dat de hele boom gescand is
"stm_lastscanduration FLOAT, " . // Hoeveel seconden dit de laatste keer duurde
"stm_scanstatus VARCHAR(10), " . // Scanstatus SCHEDULED | BUSY | DONE
"stm_user VARCHAR(10), " . // De naam van de beheerder van de site
"stm_pwd VARCHAR(10), " . // zijn wachtwoord
"stm_timeout INTEGER, " . // geldigheidsduur van een sessie in seconden
"PRIMARY KEY (stm_id) " . // de sleutel
");";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error creating table [stm] ERROR: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS creating table [stm]
";
/* INSERT EEN RECORD */
$sql="INSERT INTO stm VALUES('1','','','','John','jb4848','1800');";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error adding default record [stm] ERROR: " . mysqli_error($handle) . "
";
} else {
print "Success adding default record [stm]
";
}
}
// ----------------------------------------------------------------------------------------------------
$sql="CREATE TABLE IF NOT EXISTS sss ( ". // ** SESSIES BIJHOUDEN **
"sss_id VARCHAR(15), " . // unieke sessie sleutel
"sss_timer INTEGER, " . // starttijd sessie
"sss_ipaddress TEXT, " . // ip_adres van de actieve sessie
"PRIMARY KEY (sss_id) " . // de sleutel
");";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error creating table [sss] ERROR: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS creating table [sss]
";
}
// ----------------------------------------------------------------------------------------------------
$sql="CREATE TABLE IF NOT EXISTS cltc ( ". // ** COLLECTIES - contents : eerste images van cases **
"cltc_name VARCHAR(50), " . // naam van de collectie
"cltc_imagefq VARCHAR(100), " . // imagenaam met volledig pad
"PRIMARY KEY (cltc_name, cltc_imagefq) " . // de sleutel
");";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error creating table [cltc] ERROR: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS creating table [cltc]
";
}
// ----------------------------------------------------------------------------------------------------
$sql="CREATE TABLE IF NOT EXISTS clti ( ". // ** COLLECTIES - images voor overzicht 1 per collectie **
"clti_name VARCHAR(50), " . // naam van de collectie
"clti_imagefq VARCHAR(100), " . // imagenaam voor collectie overzicht met volledig pad
"PRIMARY KEY (clti_name) " . // de sleutel
");";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error creating table [clti] ERROR: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS creating table [clti]
";
}
// ----------------------------------------------------------------------------------------------------
$sql="CREATE TABLE IF NOT EXISTS cltv ( ". // ** COLLECTIES - visibility in directories **
"cltv_name VARCHAR(50), " . // naam van de collectie
"cltv_dirfq VARCHAR(100), " . // directory voor collectie overzicht met volledig pad
"PRIMARY KEY (cltv_name, cltv_dirfq) " . // de sleutel
");";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error creating table [cltv] ERROR: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS creating table [cltv]
";
}
// ----------------------------------------------------------------------------------------------------
$sql="CREATE TABLE IF NOT EXISTS pct ( ". // ** PRICE CATEGORIES - contents : prices per category **
"pct_name VARCHAR(20), " . // naam van de category
"pct_price VARCHAR(20), " . // prijs danwel omschrijving van de category
"PRIMARY KEY (pct_name) " . // de sleutel
");";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error creating table [pct] ERROR: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS creating table [pct]
";
/* INSERT EEN RECORD */
$sql="INSERT INTO pct VALUES('-- empty --','');";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error adding default record [pct] ERROR: " . mysqli_error($handle) . "
";
} else {
print "Success adding default record [pct]
";
}
}
// ----------------------------------------------------------------------------------------------------
$sql="CREATE TABLE IF NOT EXISTS cse ( ". // ** PRICE CATEGORIES - contents : prices per category **
"cse_name VARCHAR(100), " . // naam van de het image incl. extensie maar zonder pad.
"cse_displayname VARCHAR(100), " . // Naam die getoond wordt aan de gebruiker als niet leeg
"cse_description TEXT, " . // Description voor onder het image
"cse_pct_name VARCHAR(20), " . // Prijs categorie uit pct
"PRIMARY KEY (cse_name) " . // de sleutel
");";
if (!mysqli_query($handle,$sql)) { // mislukt
print "Error creating table [cltc] ERROR: " . mysqli_error($handle) . "
";
} else {
print "SUCCESS creating table [cltc]
";
}
// ----------------------------------------------------------------------------------------------------
} // jb_create_tables
/* ##################################################################################################
TABLE FUNCTIONS
fsf - file system files and directories read from /catalog/
stm - system
sss - sessions
cltc - collections contents
clti - collections images
cltv - collections visibility
pct - price categories
cse - case information based on imagename
#################################################################################################### */
/* ====================================================================================================
fsf - file system files and directories read from /catalog/
====================================================================================================
- jb_fsf_exists( $f_name
) key exists?
- jb_fsf_add( $f_name,
$fsf_isfirst,
$f_isdir,
$f_dirpath,
$f_width,
$f_height,
$f_size,
$f_description,
$f_price,
$f_firstscanned,
$f_lastscanned
) insert or update
- jb_fsf_get( $f_name
) get data for key
- jb_fsf_update() read entire structure (again), set lastscanned
- jb_fsf_update_ssh() read entire structure (again), set lastscanned for jb_cup_ssh.php commandline execution
- jb_fsf_dircount() returns the number of directories from the database
- jb_fsf_dirs() returns [0..n][ $f_name ]
[0..n][ $f_dirpath ]
- jb_fsf_imagecount() returns the number of images from the database
- jb_fsf_firstimages() returns all firstimages of all cases
- jb_fsf_caseimages( $f_dirpath ) returns all images in dirpath sorted by fsf_name
- jb_fsf_firstimages_under_dir( $f_dirpath ) returns all firstimages under dir
- jb_fsf_images_in_dir( $f_dirpath ) returns images in given dir
==================================================================================================== */
function jb_fsf_exists( $f_name ) {
$handle=jb_connect("jb_fsf_exists"); // or die
$sql="SELECT fsf_name FROM fsf WHERE (fsf_name=" . '"' . $f_name . '")';
$answer = mysqli_query($handle,$sql);
if (!$answer) { // sql failed
die("jb_fsf_exists invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
if ($row=mysqli_fetch_row( $answer )) {
return TRUE; // exists
} else {
return FALSE; // doesn't exist
}
}
} // jb_fsf_exists
function jb_fsf_add( $f_name, $f_isfirst, $f_isdir, $f_dirpath, $f_width, $f_height, $f_size, $f_description, $f_price, $f_firstscanned, $f_lastscanned ) {
if (jb_fsf_exists( $f_name )) { // exist, so update, except |name|description|price|firstscanned| (watch for 's in dirnames like [tracy's case])
$sql= "UPDATE fsf " .
"SET fsf_isfirst='$f_isfirst'," .
"fsf_isdir='$f_isdir'," .
"fsf_dirpath=" . '"' . $f_dirpath . '",' .
"fsf_width='$f_width'," .
"fsf_height='$f_height'," .
"fsf_size='$f_size'," .
"fsf_lastscanned='$f_lastscanned' " .
"WHERE (fsf_name=" . '"' . $f_name . '"' . ");";
$handle=jb_connect("jb_fsf_add"); // or die
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query invalid!
die("jb_fsf_add - UPDATE : [" . $sql . "] ERROR : " . mysqli_error($handle));
}
} else { // INSERT new record (watch out for 's in dirnames like [tracy's case])
$sql= "INSERT INTO fsf " .
"SET fsf_name=" . '"' . $f_name . '"' . "," .
"fsf_isfirst='$f_isfirst'," .
"fsf_isdir='$f_isdir'," .
"fsf_dirpath=" . '"' . $f_dirpath . '",' .
"fsf_width='$f_width'," .
"fsf_height='$f_height'," .
"fsf_size='$f_size'," .
"fsf_description='$f_description'," .
"fsf_price='$f_price'," .
"fsf_firstscanned='$f_firstscanned'," .
"fsf_lastscanned='$f_lastscanned';";
$handle=jb_connect("jb_fsf_add"); // or die
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query invalid!
die("jb_fsf_add - INSERT : [" . $sql . "] ERROR : " . mysqli_error($handle));
}
}
} // jb_fsf_add
function jb_fsf_get( $f_name ) { // haal bestandsgegevens
$handle=jb_connect("jb_fsf_get"); // or die
$sql="SELECT * FROM fsf WHERE (fsf_name=" . '"'. $f_name . '"' . ");";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_fsf_get : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
if ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
return $row; // record als array retourneren
} else {
return Array(); // record niet gevonden
}
}
} // jb_fsf_get
function jb_fsf_update() { // lees de gehele structuur, indien een bestand inmiddels verwijderd is, dat wordt lastscanned niet gezet.
$start_time = jb_misc_microtime();
$af=jb_misc_read_files(JB_CATALOG_ROOT_FQ . "*");
$scandatum=date("YmdHis");
// Bepaal bestandsinformatie en schrijf dit naar de databasae
$firsts=Array();
for ($i=0;$i"_functionality") and (basename($af[$i])<>"_colimages") ) { // Het is een directory en niet _functionality of _colimages
$name=basename($af[$i]);
$isfirst=0;
$isdir=1;
$dp=dirname($af[$i]) . "/"; // because catalog is /catalog/
$dirpath=substr( dirname($af[$i]), strpos($dp,JB_CATALOG_ROOT) ); // strip everything preceding JB_CATALOG_ROOT because for html we need that
$width=0; // nvt
$height=0; // nvt
$size=0; // nvt
$description=""; // nvt
$price=""; // nvt
$firstscanned=$scandatum;
$lastscanned=$scandatum;
$add=TRUE;
} else {
$add=FALSE;
}
} else { // file
if ( (basename(dirname($af[$i]))<>"_functionality") and (basename(dirname($af[$i]))<>"_colimages") ) { // De file is niet in _functionality of _colimages
$name=basename($af[$i]);
$isfirst=0;
$isdir=0;
$dp=dirname($af[$i]) . "/"; // because catalog is /catalog/
$dirpath=substr( dirname($af[$i]), strpos($dp,JB_CATALOG_ROOT) ); // strip everything preceding JB_CATALOG_ROOT because for html we need that
$imgSpecs=getimagesize($af[$i]);
$width=$imgSpecs[0];
$height=$imgSpecs[1];
$size=filesize($af[$i]);
$description="";
$price="";
$firstscanned=$scandatum;
$lastscanned=$scandatum;
// we moeten de eerste images per directory weten als het een .jpg is
// is het een jpg, hebben we de dir al gehad?
if (substr($name,strlen($name)-3,3)=="jpg") { // ja image
if (!array_key_exists($dirpath, $firsts)) { // eerste image want we kennen de dir nog niet
$isfirst=1;
$firsts[$dirpath]=1; // directory gehad
}
}
$add=TRUE;
} else {
$add=FALSE;
}
}
// voeg toe aan fsf (of update) ALLEEN INDIEN dir is niet _functionality en niet _colimages
if ($add) {
jb_fsf_add( $name, $isfirst, $isdir, $dirpath, $width, $height, $size, $description, $price, $firstscanned, $lastscanned );
}
}
// Special situation: Add the catalog dir to be able to define a collection on that level too
jb_fsf_add( "catalog", 0, 1, "", 0, 0, 0, "", "", $scandatum, $scandatum );
$end_time = jb_misc_microtime();
$used_time = $end_time - $start_time;
// Bewaar benodigde tijd en tijdstip laatste update in stm
jb_stm_set_scandata($lastscanned,$used_time);
// Delete all entries where lastscanned does not equual scandatum, because they've been removed from disk
$sql="DELETE FROM fsf WHERE (fsf_lastscanned<>'$scandatum');";
$handle=jb_connect("jb_update_fsf"); // or die
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query invalid!
die("jb_update_fsf : [" .$sql . "] ERROR : " . mysqli_error($handle));
}
} // jb_fsf_update()
function jb_fsf_update_ssh() { // SSH OPTIMISED VERSION
$start_time = jb_misc_microtime();
$af=jb_misc_read_files(JB_CATALOG_ROOT_SSH . "*");
$scandatum=date("YmdHis");
$handle=jb_connect("jb_update_fsf_ssh"); // or die
// Bepaal bestandsinformatie en schrijf dit naar de databasae
$firsts=Array();
for ($i=0;$i"_functionality") and (basename($af[$i])<>"_colimages") ) { // Het is een directory en niet _functionality of _colimages
$name=basename($af[$i]);
$isfirst=0;
$isdir=1;
$dp=dirname($af[$i]) . "/"; // because catalog is /catalog/
$dirpath=substr( dirname($af[$i]), strpos($dp,JB_CATALOG_ROOT) ); // strip everything preceding JB_CATALOG_ROOT because for html we need that
$width=0; // nvt
$height=0; // nvt
$size=0; // nvt
$description=""; // nvt
$price=""; // nvt
$firstscanned=$scandatum;
$lastscanned=$scandatum;
$add=TRUE;
} else {
$add=FALSE;
}
} else { // file
if ( (basename(dirname($af[$i]))<>"_functionality") and (basename(dirname($af[$i]))<>"_colimages") ) { // De file is niet in _functionality of _colimages
$name=basename($af[$i]);
$isfirst=0;
$isdir=0;
$dp=dirname($af[$i]) . "/"; // because catalog is /catalog/
$dirpath=substr( dirname($af[$i]), strpos($dp,JB_CATALOG_ROOT) ); // strip everything preceding JB_CATALOG_ROOT because for html we need that
$imgSpecs=getimagesize($af[$i]);
$width=$imgSpecs[0];
$height=$imgSpecs[1];
$size=filesize($af[$i]);
$description="";
$price="";
$firstscanned=$scandatum;
$lastscanned=$scandatum;
// we moeten de eerste images per directory weten als het een .jpg is
// is het een jpg, hebben we de dir al gehad?
if (substr($name,strlen($name)-3,3)=="jpg") { // ja image
if (!array_key_exists($dirpath, $firsts)) { // eerste image want we kennen de dir nog niet
$isfirst=1;
$firsts[$dirpath]=1; // directory gehad
}
}
$add=TRUE;
} else {
$add=FALSE;
}
}
// voeg toe aan fsf (of update) ALLEEN INDIEN dir is niet _functionality en niet _colimages
if ($add) {
// jb_fsf_add( $name, $isfirst, $isdir, $dirpath, $width, $height, $size, $description, $price, $firstscanned, $lastscanned );
// if (jb_fsf_exists( $f_name )) { // exist, so update, except |name|description|price|firstscanned| (watch for 's in dirnames like [tracy's case])
$recordexists=FALSE;
$sql="SELECT fsf_name FROM fsf WHERE (fsf_name=" . '"' . $name . '")';
$answer = mysqli_query($handle,$sql);
if (!$answer) { // sql failed
die("SSH: recordexists invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
$recordexists = ($row=mysqli_fetch_row( $answer ));
}
if ($recordexists) {
$sql= "UPDATE fsf " .
"SET fsf_isfirst='$isfirst'," .
"fsf_isdir='$isdir'," .
"fsf_dirpath=" . '"' . $dirpath . '",' .
"fsf_width='$width'," .
"fsf_height='$height'," .
"fsf_size='$size'," .
"fsf_lastscanned='$lastscanned' " .
"WHERE (fsf_name=" . '"' . $name . '"' . ");";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query invalid!
die("SSH: UPDATE invalid: [" . $sql . "] ERROR : " . mysqli_error($handle));
}
} else { // INSERT new record (watch out for 's in dirnames like [tracy's case])
$sql= "INSERT INTO fsf " .
"SET fsf_name=" . '"' . $name . '"' . "," .
"fsf_isfirst='$isfirst'," .
"fsf_isdir='$isdir'," .
"fsf_dirpath=" . '"' . $dirpath . '",' .
"fsf_width='$width'," .
"fsf_height='$height'," .
"fsf_size='$size'," .
"fsf_description='$description'," .
"fsf_price='$price'," .
"fsf_firstscanned='$firstscanned'," .
"fsf_lastscanned='$lastscanned';";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query invalid!
die("SSH: INSERT invalid: [" . $sql . "] ERROR : " . mysqli_error($handle));
}
}
}
} // for
// Special situation: Add the catalog dir to be able to define a collection on that level too
//jb_fsf_add( "catalog", 0, 1, "", 0, 0, 0, "", "", $scandatum, $scandatum );
$recordexists=FALSE;
$sql="SELECT fsf_name FROM fsf WHERE (fsf_name=" . '"' . "catalog" . '")';
$answer = mysqli_query($handle,$sql);
if (!$answer) { // sql failed
die("SSH: catalog recordexists invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
$recordexists = ($row=mysqli_fetch_row( $answer ));
}
if ($recordexists) {
$sql= "UPDATE fsf " .
"SET fsf_isfirst='0'," .
"fsf_isdir='1'," .
"fsf_dirpath=" . '"' . "" . '",' .
"fsf_width='0'," .
"fsf_height='0'," .
"fsf_size='0'," .
"fsf_lastscanned='$lastscanned' " .
"WHERE (fsf_name=" . '"' . "catalog" . '"' . ");";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query invalid!
die("SSH: catalog UPDATE invalid: [" . $sql . "] ERROR : " . mysqli_error($handle));
}
} else { // INSERT new record (watch out for 's in dirnames like [tracy's case])
$sql= "INSERT INTO fsf " .
"SET fsf_name=" . '"' . "catalog" . '"' . "," .
"fsf_isfirst='0'," .
"fsf_isdir='1'," .
"fsf_dirpath=" . '"' . "" . '",' .
"fsf_width='0'," .
"fsf_height='0'," .
"fsf_size='0'," .
"fsf_description=''," .
"fsf_price=''," .
"fsf_firstscanned='$f_firstscanned'," .
"fsf_lastscanned='$f_lastscanned';";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query invalid!
die("SSH: catalog INSERT invalid: [" . $sql . "] ERROR : " . mysqli_error($handle));
}
}
//
$end_time = jb_misc_microtime();
$used_time = $end_time - $start_time;
// Bewaar benodigde tijd en tijdstip laatste update in stm
jb_stm_set_scandata($lastscanned,$used_time);
// Delete all entries where lastscanned does not equual scandatum, because they've been removed from disk
$sql="DELETE FROM fsf WHERE (fsf_lastscanned<>'$scandatum');";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query invalid!
die("jb_update_fsf : [" .$sql . "] ERROR : " . mysqli_error($handle));
}
} // jb_fsf_update()
function jb_fsf_dircount() {
$handle=jb_connect("jb_fsf_dircount"); // or die
$sql="SELECT COUNT(*) AS totaal FROM fsf WHERE (fsf_isdir='1')";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_fsf_dircount : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
if ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
return $row["totaal"]; // aantal
} else {
return 0; // geen directories gevonden
}
}
} // jb_fsf_dircount
function jb_fsf_dirs() {
$handle=jb_connect("jb_fsf_dirs"); // or die
$sql="SELECT fsf_name, fsf_dirpath FROM fsf WHERE (fsf_isdir='1') ORDER BY fsf_name ASC";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_fsf_dirs : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
$lindex=0;
while ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $lindex ][ "fsf_name" ] = $row[ "fsf_name" ];
$lar[ $lindex ][ "fsf_dirpath" ] = $row[ "fsf_dirpath" ];
$lindex++;
}
}
return $lar;
} // jb_fsf_dircount
function jb_fsf_imagecount() {
$handle=jb_connect("jb_fsf_imagecount"); // or die
$sql="SELECT COUNT(*) AS totaal FROM fsf WHERE ((fsf_isdir='0') and (RIGHT(fsf_name,3)='jpg'))";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_fsf_imagecount : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
if ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
return $row["totaal"]; // aantal
} else {
return 0; // geen jpg images gevonden
}
}
} // jb_fsf_imagecount
function jb_fsf_firstimages() {
$handle=jb_connect("jb_fsf_firstimages"); // or die
$sql="SELECT fsf_name, fsf_dirpath FROM fsf WHERE (fsf_isfirst='1') ORDER BY fsf_name";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_fsf_firstimages : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
$lindex=0;
while ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $lindex ][ "fsf_name" ] = $row["fsf_name"];
$lar[ $lindex ][ "fsf_dirpath" ] = $row["fsf_dirpath"];
$lindex++;
}
}
return $lar;
}
function jb_fsf_caseimages( $f_dirpath ) {
$handle=jb_connect("jb_fsf_caseimages"); // or die
$sql="SELECT fsf_name, fsf_dirpath, fsf_width, fsf_height, fsf_size FROM fsf WHERE ((fsf_dirpath=\"" . $f_dirpath . "\") AND (fsf_isdir=0)) ORDER BY fsf_name";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_fsf_caseimages : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
$lindex=0;
$lar=Array();
while ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $lindex ][ "fsf_name" ] = $row["fsf_name"];
$lar[ $lindex ][ "fsf_dirpath" ] = $row["fsf_dirpath"];
$lar[ $lindex ][ "fsf_width" ] = $row["fsf_width"];
$lar[ $lindex ][ "fsf_height" ] = $row["fsf_height"];
$lar[ $lindex ][ "fsf_size" ] = $row["fsf_size"];
$lindex++;
}
}
return $lar;
}
function jb_fsf_firstimages_under_dir( $f_dirpath ) { // in de subdirs under dir (one level deep) all first images
// Get all subdirs under the dirpath one level deep
$sql="SELECT B.fsf_name, B.fsf_dirpath FROM fsf AS B WHERE ((B.fsf_isfirst=1) and (B.fsf_dirpath IN (SELECT CONCAT('" . $f_dirpath . "','/',A.fsf_name) FROM fsf AS A WHERE ((A.fsf_dirpath='" . $f_dirpath . "') and (A.fsf_isdir=1))))) ORDER BY B.fsf_dirpath";
$handle=jb_connect("jb_fsf_firstimages_under_dir"); // or die
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_fsf_firstimages_under_dir : [" . $sql . "] ERROR : " . mysqli_error($handle));
} else {
$lar=Array();
while ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $row["fsf_name"] ] = $row["fsf_dirpath"];
}
}
return $lar;
}
function jb_fsf_images_in_dir( $f_dirpath ) { // in de subdirs under dir (one level deep) all first images
// Get all subdirs under the dirpath one level deep
$sql="SELECT fsf_name, fsf_dirpath FROM fsf WHERE ((fsf_isdir=0) and (fsf_dirpath='" . $f_dirpath . "')) ORDER BY fsf_name";
$handle=jb_connect("jb_fsf_images_in_dir"); // or die
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_fsf_images_in_dir : [" . $sql . "] ERROR : " . mysqli_error($handle));
} else {
$lar=Array();
$lindex=0;
while ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $lindex ] = $row["fsf_dirpath"] . "/" . $row["fsf_name"];
$lindex++;
}
}
return $lar;
}
/* ====================================================================================================
stm - system file
====================================================================================================
jb_stm_get() get the system record
jb_stm_set_timeout( $f_timeout
) sets the session timeout in seconds
jb_stm_set_scandata( $f_lastscanned,
$f_lastscanduration
) sets statistics of last scan performed
jb_stm_set_scanstatus( $f_scanstatus ) SCHEDULED | BUSY | DONE
=================================================================================================== */
function jb_stm_get() { // get the system record
$handle=jb_connect("jb_stm_get"); // or die
$sql="SELECT * FROM stm WHERE (stm_id='1')";
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_stm_get invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
if ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
return $row; // bestaat
} else {
return Array(); // bestaat niet
}
}
} // jb_stm_get
function jb_stm_set_timeout( $f_timeout ) { // sets the session timeout in seconds
$handle=jb_connect("jb_stm_set_timeout"); // or die
$sql="UPDATE stm SET stm_timeout='$f_timeout' WHERE (stm_id='1');";
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_stm_set_timeout invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
}
} // jb_stm_set_timeout
function jb_stm_set_scandata( $f_lastscanned, $f_lastscanduration ) { // sets statistics of last scan performed
$handle=jb_connect("jb_stm_set_scandata"); // or die
$sql="UPDATE stm SET stm_lastscanned='$f_lastscanned', stm_lastscanduration='$f_lastscanduration' WHERE (stm_id='1');";
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_stm_set_scandata invalid: [" . $sql . "]\n ERROR: " . mysqli_error($handle) . "\n");
}
} // jb_stm_set_scandata
function jb_stm_set_scanstatus( $f_scanstatus ) { // sets statistics of last scan performed
$handle=jb_connect("jb_stm_set_scanstatus"); // or die
$sql="UPDATE stm SET stm_scanstatus='$f_scanstatus' WHERE (stm_id='1');";
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_stm_set_scanstatus invalid: [" . $sql . "]\n ERROR: " . mysqli_error($handle) . "\n");
}
} // jb_stm_set_scandata
/* ====================================================================================================
sss - sessions
====================================================================================================
jb_sss_add( $f_sss_id,
$f_sss_timer,
$f_sss_ipaddress not used here
) add/insert record
jb_sss_exists( $f_sss_id
) doe key exist?
jb_sss_get( $f_sss_id
) get record for key
jb_sss_delete(
$f_sss_id
) delete record for key
jb_sss_delete_expired_sessions() delete all expired sessions
jb_sss_valid( $f_sss_id
) session (still) valid? TRUE/FALSE
jb_sss_refresh(
$f_sss_id
) refresh session (update starttime)
jb_sss_new() return new stored active session id
==================================================================================================== */
function jb_sss_add( $f_sss_id, $f_sss_timer, $f_sss_ipaddress ) {
$handle=jb_connect("jb_sss_add"); // or die
if (jb_sss_exists( $f_sss_id )) { // bestaat reeds
$sql= "UPDATE sss " .
"SET sss_timer='$f_sss_timer'," .
"sss_ipaddress='$f_sss_ipaddress'" .
"WHERE (sss_id=" . '"' . $f_sss_id . '"' . ")";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_sss_add - UPDATE : [" . $sql . "]\n ERROR : " . mysqli_error($handle));
}
} else { // bestaat nog niet, dus insert als nieuw record (pas op voo 's in namen zoals tracy's case)
$sql= "INSERT INTO sss " .
"SET sss_id='$f_sss_id'," .
"sss_timer='$f_sss_timer'," .
"sss_ipaddress='$f_sss_ipaddress'";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_sss_add - INSERT : [" . $sql . "]\n ERROR : " . mysqli_error($handle));
}
}
} // jb_sss_add
function jb_sss_exists( $f_sss_id ) {
$handle=jb_connect("jb_sss_exists"); // or die
// Is het record aanwezig in de tabel ?
$sql="SELECT sss_id FROM sss WHERE (sss_id=" . '"' . $f_sss_id . '")';
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_sss_exists invalid: [" . $sql . "]\n ERROR: " . mysqli_error($handle) . "\n");
} else {
if ($row=mysqli_fetch_row( $answer )) {
return TRUE; // bestaat
} else {
return FALSE; // bestaat niet
}
}
} // jb_sss_exists
function jb_sss_get( $f_sss_id ) {
$handle=jb_connect("jb_sss_exists"); // or die
$sql="SELECT * FROM sss WHERE (sss_id='$f_sss_id')";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query opdracht is ongeldig bevonden!
die("jb_sss_get : [" .$sql . "]");
} else {
if ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
return $row; // record als array retourneren
} else {
return FALSE; // record niet gevonden
}
}
} // jb_sss_get
function jb_sss_delete( $f_sss_id ) {
$handle=jb_connect("jb_sss_exists"); // or die
if (jb_sss_exists( $_fsss_id )) { // record bestaat, verwijderen dus
$sql="DELETE FROM iris_sss WHERE (sss_id='$f_sss_id')";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_sss_delete : [" .$sql . "]\n ERROR : " . mysqli_error($handle));
}
} // else hij is al weg en dat was de bedoeling {
} // jb_sss_delete
function jb_sss_delete_expired_sessions() {
$lstm = jb_stm_get();
$handle=jb_connect("jb_sss_delete_expired_sessions"); // of we zijn al dood
$sql="DELETE FROM sss WHERE ((sss_timer + " . $lstm["stm_timeout"] . ") < " . jb_misc_microtime() . ");";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query opdracht is ongeldig bevonden!
die("jb_delete_expired_sessions : [" .$sql . "]\n ERROR : " . mysqli_error($handle));
}
} // jb_delete_expired_sessions
function jb_sss_valid( $f_sss_id ) {
// start tijd + timeout < nu
$lnu=jb_misc_microtime();
$lstm=jb_stm_get();
$retval=FALSE;
if ($lsss=jb_sss_get( $f_sss_id )) { // session found
if ( ($lsss["sss_timer"]+$lstm["stm_timeout"]) > $lnu ) { // valid
$retval=TRUE;
}
}
return $retval;
} // jb_sss_valid
function jb_sss_refresh( $f_sss_id ) { // refresh session
// vervang de starttijd
$lnu=jb_misc_microtime();
$sql="UPDATE sss SET sss_timer='$lnu' WHERE (sss_id='$f_sss_id');";
$handle=jb_connect("jb_sss_exists"); // or die
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_sss_refresh : [" .$sql . "] ERROR : " . mysqli_error($handle));
}
}
function jb_sss_new() { // return new stored active session id
$lnu=jb_misc_microtime();
$lretval=jb_misc_create_randomstring(15);
jb_sss_add($lretval, $lnu, NULL);
return $lretval;
}
/* ====================================================================================================
cltc - collection contents : the first images from the cases that are in the collection
====================================================================================================
- jb_cltc_add( $f_name, $f_imagefq ) - add to cltc
- jb_cltc_exists( $f_name ) - key exists TRUE/FALSE
- jb_cltc_delete( $f_name ) - remove complete collection : clti/cltv also
- jb_cltc_contents( $f_name ) - get collection contents (catalog images): array[0..n] = imagefq
- jb_cltc_getall() - get all collections and contents (catalog images)
array[cltc_name][0..n] = cltc_imagefq
- jb_cltc_caseincollection( $f_name, $f_imagefq ) - Returns TRUE/FALSE
==================================================================================================== */
function jb_cltc_add( $f_name, $f_imagefq ) {
$handle=jb_connect("jb_cltc_add"); // or die
if (!jb_cltc_caseincollection( $f_name, $f_imagefq )) { // only add if not yet there (no other fields)
$sql= "INSERT INTO cltc " .
"SET cltc_name='$f_name'," .
"cltc_imagefq='$f_imagefq'";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cltc_add - ADD : [" . $sql . "] ERROR : " . mysqli_error($handle));
}
}
} // jb_cltc_add
function jb_cltc_exists( $f_name ) { // Does the collection exist
$handle=jb_connect("jb_cltc_exists"); // or die
$sql="SELECT cltc_name FROM cltc WHERE (cltc_name=" . '"' . $f_name . '")';
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_cltc_exists invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
if ($row=mysqli_fetch_row( $answer )) {
return TRUE; // bestaat
} else {
return FALSE; // bestaat niet
}
}
} // jb_cltc_exists
function jb_cltc_delete( $f_name ) {
$handle=jb_connect("jb_cltc_delete"); // or die
if (jb_cltc_exists( $f_name )) { // record bestaat, verwijderen dus
$sql="DELETE FROM cltc WHERE (cltc_name='$f_name')";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cltc_delete : [" . $sql . "] ERROR : " . mysqli_error($handle));
}
} // else hij is al weg en dat was de bedoeling {
} // jb_cltc_delete
function jb_cltc_contents( $f_name ) { // for $f_name all imagefq
$handle=jb_connect("jb_cltc_contents"); // or die
$sql='SELECT * FROM cltc WHERE (cltc_name="' . $f_name . '")';
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_cltc_contents : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
$lindex=0;
$lar=array();
while ($row=mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $lindex ] = $row[ "cltc_imagefq" ];
$lindex++;
}
}
return $lar;
}
function jb_cltc_getall() { // get all collections and their contents sorted on cltc_name
$handle=jb_connect("jb_cltc_getall"); // or die
$sql="SELECT * FROM cltc ORDER BY cltc_name";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_cltc_getall : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
$lar=array();
$lindex=-1; // to please the loop
$currentname="";
while ($row=mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
if ($currentname<>$row["cltc_name"]) {
$lindex=0; // different collectionname
$currentname=$row["cltc_name"];
} else {
$lindex=$lindex + 1;
}
$lar[ $row["cltc_name"] ][ $lindex ] = $row[ "cltc_imagefq" ];
}
}
return $lar; // or we are dead already
}
function jb_cltc_caseincollection( $f_name, $f_imagefq ) { // is the case in the collection?
$handle=jb_connect("jb_cltc_exists"); // or die
$sql="SELECT cltc_name FROM cltc WHERE ( (cltc_name=" . '"' . $f_name . '") and (cltc_imagefq="' . $f_imagefq . '") )';
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_cltc_caseincollection invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
if ($row=mysqli_fetch_row( $answer )) {
return TRUE; // bestaat
} else {
return FALSE; // bestaat niet
}
}
} // jb_cltc_exists
/* ====================================================================================================
clti - collection images : the 1 image that represents the collection (can be any image)
====================================================================================================
- jb_clti_add( $f_name, $f_imagefq ) - add/update to clti
- jb_clti_exists( $f_name ) - key exists TRUE/FALSE
- jb_clti_delete( $f_name ) - remove collection : cltc/cltv also
- jb_clti_image( $f_name ) - get collection imagefq (catalog images)
- jb_clti_getall() - get all collections and contents (catalog images)
array[0..n][clti_name] = clti_name
array[0..n][clti_imagefq] = imagefq
- jb_clti_collectioncount() - returns the number of self-defined collections
==================================================================================================== */
function jb_clti_add( $f_name, $f_imagefq ) {
$handle=jb_connect("jb_clti_add"); // or die
if (jb_clti_exists( $f_name )) { // bestaat reeds
$sql= "UPDATE clti " .
"SET clti_imagefq='$f_imagefq' " .
"WHERE (clti_name=" . '"' . $f_name . '"' . ")";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_clti_add - UPDATE : [" . $sql . "]\n ERROR : " . mysqli_error($handle));
}
} else { // bestaat nog niet, dus insert als nieuw record (pas op voo 's in namen zoals tracy's case)
$sql= "INSERT INTO clti " .
"SET clti_name='$f_name'," .
"clti_imagefq='$f_imagefq'";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_clti_add - INSERT : [" . $sql . "] ERROR : " . mysqli_error($handle));
}
}
} // jb_clti_add
function jb_clti_exists( $f_name ) {
$handle=jb_connect("jb_clti_exists"); // or die
$sql="SELECT clti_name FROM clti WHERE (clti_name=" . '"' . $f_name . '")';
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_clti_exists invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
if ($row=mysqli_fetch_row( $answer )) {
return TRUE; // bestaat
} else {
return FALSE; // bestaat niet
}
}
} // jb_clti_exists
function jb_clti_delete( $f_name ) {
$handle=jb_connect("jb_clti_delete"); // or die
if (jb_clti_exists( $f_name )) { // record bestaat, verwijderen dus
$sql="DELETE FROM clti WHERE (clti_name='$f_name')";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_clti_delete : [" .$sql . "] ERROR : " . mysqli_error($handle));
}
} // else hij is al weg en dat was de bedoeling {
} // jb_clti_delete
function jb_clti_image( $f_name ) {
$handle=jb_connect("jb_clti_image"); // or die
$sql='SELECT * FROM clti WHERE (clti_name="' . $f_name . '")';
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query opdracht is ongeldig bevonden!
die("jb_clti_image : [" .$sql . "]");
} else {
if ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
return $row["clti_imagefq"]; // imagefq retoruneren
} else {
return FALSE; // record niet gevonden
}
}
} // jb_clti_image
function jb_clti_getall() { // get the collection catalog image for all collections (1 image per collection)
$handle=jb_connect("jb_clti_getall"); // or die
$sql="SELECT * FROM clti ORDER BY clti_name ASC";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_clti_getall : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
$lar=array();
$lindex=0;
while ($row=mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $lindex ]["clti_name"] = $row["clti_name"];
$lar[ $lindex ]["clti_imagefq"] = $row["clti_imagefq"];
$lindex=$lindex+1;
}
}
return $lar; // or we are dead already
} // jb_clti_getall
function jb_clti_collectioncount() {
$handle=jb_connect("jb_clti_collectioncount"); // or die
$sql="SELECT COUNT(*) AS totaal FROM clti";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_clti_collectioncount : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
if ($row = mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
return $row["totaal"]; // aantal
} else {
return 0; // no self-defined collections found
}
}
} // jb_clti_collectioncount
/* ====================================================================================================
cltv - collections visibility : the directories where the collection should show up
====================================================================================================
- jb_cltv_add( $f_name, $f_dirfq ) - add to cltv
- jb_cltv_exists( $f_name, $f_dirfq ) - key exists TRUE/FALSE
- jb_cltv_delete( $f_name, $f_dirfq ) - remove combination
- jb_cltv_delete_all( $f_name ) - remove complete collection visibility
- jb_cltv_get_collections_for_dir( $f_dirfq ) - returns array of cltv_name that must be shown for f_dirfq
array[0..n] = cltv_name
- jb_cltv_get_dirs_for_collection( $f_name ) - returns array of cltv_dirfq where collection is shown
array[0..n] = cltv_dirfq
==================================================================================================== */
function jb_cltv_add( $f_name, $f_dirfq ) {
$handle=jb_connect("jb_cltv_add"); // or die
if (!jb_cltv_exists( $f_name, $f_dirfq )) { // only add if not yet there (no other fields)
$sql= "INSERT INTO cltv " .
"SET cltv_name='$f_name'," .
"cltv_dirfq='$f_dirfq'";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cltv_add - ADD : [" . $sql . "] ERROR : " . mysqli_error($handle));
}
}
} // jb_cltv_add
function jb_cltv_exists( $f_name, $f_dirfq ) {
$handle=jb_connect("jb_cltv_exists"); // or die
$sql="SELECT cltv_name FROM cltv WHERE ((cltv_name=" . '"' . $f_name . '"' . ') and (cltv_dirfq="' . $f_dirfq . '"))';
//print "jb_cltv_exists: [" . $sql . "]\n";
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_cltv_exists invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
if ($row=mysqli_fetch_row( $answer )) {
return TRUE; // bestaat
} else {
return FALSE; // bestaat niet
}
}
} // jb_cltv_exists
function jb_cltv_delete( $f_name, $f_dirfq ) {
$handle=jb_connect("jb_cltv_delete"); // or die
if (jb_cltv_exists( $f_name, $f_dirfq )) { // record bestaat, verwijderen dus
$sql="DELETE FROM cltv WHERE ((cltv_name=" . '"' . $f_name . '"' . ') and (cltv_dirfq="' . $f_dirfq . '"))';
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cltv_delete : [" .$sql . "] ERROR : " . mysqli_error($handle));
}
} // else hij is al weg en dat was de bedoeling {
} // jb_cltv_delete
function jb_cltv_delete_all( $f_name ) {
$handle=jb_connect("jb_cltv_delete_all"); // or die
$sql="DELETE FROM cltv WHERE (cltv_name='$f_name')";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cltv_delete_all : [" .$sql . "] ERROR : " . mysqli_error($handle));
}
} // jb_cltv_delete_all
function jb_cltv_get_collections_for_dir( $f_dirfq ) {
$handle=jb_connect("jb_cltv_get_collections_for_dir"); // or die
$sql="SELECT * FROM cltv WHERE (cltv_dirfq='$f_dirfq')";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cltv_get_collections_for_dir : [" .$sql . "]");
} else {
$lar=array();
$lindex=0;
while ($row=mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $lindex ] = $row["cltv_name"];
$lindex=$lindex+1;
}
}
return $lar;
} // jb_cltv_get_collections_for_dir
function jb_cltv_get_dirs_for_collection( $f_name) {
$handle=jb_connect("jb_cltv_get_dirs_for_collection"); // or die
$sql="SELECT * FROM cltv WHERE (cltv_name='$f_name') ORDER BY cltv_dirfq";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cltv_get_dirs_for_collection : [" .$sql . "]");
} else {
$lar=array();
$lindex=0;
while ($row=mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $lindex ] = $row["cltv_dirfq"];
$lindex=$lindex+1;
}
}
return $lar;
} // jb_cltv_get_collections_for_dir
/* ====================================================================================================
pct - price categories : the price (or a description) per category
====================================================================================================
- jb_pct_add( $f_name, $f_price ) - add/update to pct
- jb_pct_exists( $f_name ) - key exists TRUE/FALSE
- jb_pct_delete( $f_name ) - remove price category
- jb_pct_get( $f_name ) - get category price or "" if category not present
- jb_pct_getall() - get all categories ar[0..n][field]
==================================================================================================== */
function jb_pct_add( $f_name, $f_price ) {
$handle=jb_connect("jb_pct_add"); // or die
if (jb_pct_exists( $f_name )) { // bestaat reeds
$sql= "UPDATE pct " .
"SET pct_price='$f_price' " .
"WHERE (pct_name=" . '"' . $f_name . '"' . ")";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_pct_add - UPDATE : [" . $sql . "]\n ERROR : " . mysqli_error($handle));
}
} else { // bestaat nog niet, dus insert als nieuw record (pas op voo 's in namen zoals tracy's case)
$sql= "INSERT INTO pct " .
"SET pct_name='$f_name'," .
"pct_price='$f_price'";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_pct_add - INSERT : [" . $sql . "] ERROR : " . mysqli_error($handle));
}
}
} // jb_pct_add
function jb_pct_exists( $f_name ) {
$handle=jb_connect("jb_pct_exists"); // or die
$sql="SELECT pct_name FROM pct WHERE (pct_name=" . '"' . $f_name . '")';
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_pct_exists invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
if ($row=mysqli_fetch_row( $answer )) {
return TRUE; // bestaat
} else {
return FALSE; // bestaat niet
}
}
} // jb_pct_exists
function jb_pct_delete( $f_name ) {
$handle=jb_connect("jb_pct_delete"); // or die
if (jb_pct_exists( $f_name )) { // record bestaat, verwijderen dus
$sql="DELETE FROM pct WHERE (pct_name='$f_name')";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_pct_delete : [" .$sql . "] ERROR : " . mysqli_error($handle));
}
} // else hij is al weg en dat was de bedoeling
} // jb_clti_delete
function jb_pct_get( $f_name ) { // get the price for f_name or "" if not present
$handle=jb_connect("jb_pct_get"); // or die
$sql='SELECT pct_price FROM pct WHERE (pct_name="' . $f_name . '")';
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_pct_get : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
if ($row=mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
return $row["pct_price"];
} else {
return " "; // price category not found
}
}
} // jb_pct_get
function jb_pct_getall() { // get all price categories
$handle=jb_connect("jb_pct_getall"); // or die
$sql="SELECT * FROM pct ORDER BY pct_name ASC";
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_pct_getall : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
$lar=array();
$lindex=0;
while ($row=mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
$lar[ $lindex ]["pct_name"] = $row["pct_name"];
$lar[ $lindex ]["pct_price"] = $row["pct_price"];
$lindex++;
}
}
return $lar; // or we are dead already
} // jb_pct_getall
/* ====================================================================================================
cse - cases : Displayname, description and price category per case image
====================================================================================================
- jb_cse_add( $f_name,
$f_displayname,
$f_description, - |link|thelink| support
$f_pct_name ) - add/update to cse
- jb_cse_exists( $f_name ) - key exists TRUE/FALSE
- jb_cse_delete( $f_name ) - remove case image information
- jb_cse_get( $f_name ) - get case information or empty array
==================================================================================================== */
function jb_cse_add( $f_name, $f_displayname, $f_description, $f_pct_name ) {
$handle=jb_connect("jb_cse_add"); // or die
if (jb_cse_exists( $f_name )) { // bestaat reeds
$sql= "UPDATE cse " .
"SET cse_displayname=" . '"' . $f_displayname . '"' . ", " .
"cse_description=" . '"' . $f_description . '"' . ", " .
"cse_pct_name='$f_pct_name' " .
"WHERE (cse_name=" . '"' . $f_name . '"' . ")";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cse_add - UPDATE : [" . $sql . "]\n ERROR : " . mysqli_error($handle));
}
} else { // bestaat nog niet, dus insert als nieuw record (pas op voor 's in namen zoals tracy's case)
$sql= "INSERT INTO cse " .
"SET cse_name='$f_name', " .
"cse_displayname=" . '"' . $f_displayname . '"' . ", " .
"cse_description=" . '"' . $f_description . '"' . ", " .
"cse_pct_name='$f_pct_name'";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cse_add - INSERT : [" . $sql . "] ERROR : " . mysqli_error($handle));
}
}
} // jb_cse_add
function jb_cse_exists( $f_name ) {
$handle=jb_connect("jb_cse_exists"); // or die
$sql="SELECT cse_name FROM cse WHERE (cse_name=" . '"' . $f_name . '")';
$answer = mysqli_query($handle,$sql);
if (!$answer) { // opdracht mislukt
die("jb_cse_exists invalid: [" . $sql . "] ERROR: " . mysqli_error($handle) . "\n");
} else {
if ($row=mysqli_fetch_row( $answer )) {
return TRUE; // bestaat
} else {
return FALSE; // bestaat niet
}
}
} // jb_cse_exists
function jb_cse_delete( $f_name ) {
$handle=jb_connect("jb_cse_delete"); // or die
if (jb_cse_exists( $f_name )) { // record bestaat, verwijderen dus
$sql="DELETE FROM cse WHERE (cse_name='$f_name')";
if (!($answer = mysqli_query($handle,$sql))) { // ERROR: Query opdracht is ongeldig bevonden!
die("jb_cse_delete : [" .$sql . "] ERROR : " . mysqli_error($handle));
}
} // else hij is al weg en dat was de bedoeling
} // jb_clti_delete
function jb_cse_get( $f_name ) { // get the cse record for f_name or empty array if not present
$handle=jb_connect("jb_cse_get"); // or die
$sql='SELECT * FROM cse WHERE (cse_name="' . $f_name . '")';
if (!($answer = mysqli_query($handle,$sql))) { // // ERROR: Query invalid!
die("jb_cse_get : [" .$sql . "] ERROR : " . mysqli_error($handle));
} else {
if ($row=mysqli_fetch_array( $answer, MYSQL_ASSOC )) {
return $row;
} else {
return array(); // case not found
}
}
} // jb_cse_get
/* ====================================================================================================
jb_misc... - Miscellaneous routines
====================================================================================================
jb_misc_microtime()
jb_misc_create_randomstring( $f_length)
jb_misc_read_files($pattern, $flags = 0)
==================================================================================================== */
function jb_misc_microtime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function jb_misc_create_randomstring( $f_length ) {
$destring="";
$nietuniek = TRUE;
while ($nietuniek) {
$destring="";
srand((double) microtime()*1000000); // init random seed generator
while (strlen($destring) <> $f_length) { // length of string to create
$destring.=chr(rand(65,89));
}
// Zo en nu nog even zeker weten dat er geen sessie bestaat met dit id
$nietuniek = jb_sss_exists( $destring ); // stoppen als hij nog niet bestaat
}
return $destring;
}
function jb_misc_read_files($pattern, $flags = 0) { // lees complete fs boom met alle bestanden
$allFiles = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$allFiles = array_merge($allFiles, jb_misc_read_files($dir.'/'.basename($pattern), $flags));
}
return $allFiles;
}
?>