Location: PHPKode > projects > PHP File Database > fdat/sources/functions.php
<?php
/*
###############################################################################
# functions.php                                                               #
###############################################################################
# FDat (File Database) Beta Version                                           #
# Open-Source Project by Jeffrey Gelens (hide@address.com)                  #
# =========================================================================== #
# Copyright (c) 2001 Jeffrey Gelens - All Rights Reserved                     #
#                                                                             #
# This program is free software; you can redistribute it and/or               #
# modify it under the terms of the GNU General Public License                 #
# as published by the Free Software Foundation; either version 2              #
# of the License, or (at your option) any later version.                      #
###############################################################################
*/

function get_Links($fdatdir) {
$sql = "SELECT * FROM links_subjects";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
echo "<a href='$fdatdir/links.php?link=" . $row["id"] . "'>" . $row["name"] . "</a><br>";

}
}


function get_Subjects($which) {
echo "<select name='which_subject'>";
if ($which != "upload") {
  echo "<option value='allsubs'>All Subjects</option>";
}

$sql = "SELECT * FROM subjects";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
  echo "<option value='" . $row["short_name"] . "'>" . $row["name"] . "</option>";
}
echo "
  </select><br>
";
}


function get_Date($what) {

$month_array = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$date = date("j ") . $month_array[date("n") - 1] . date(" Y");
$time = date("H:i:s");
$day_array = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$day = $day_array[date("w")];

switch ($what) {
  case "time":
    echo $time;
    break;
  case "date":
    echo $date;
    break;
  case "day":
    echo $day;
    break;
   }
}

function head() {
global $title, $bgcolor, $textcolor, $linkcolor, $alinkcolor, $vlinkcolor, $table_bgcolor, $table_bordercolor, $fdatdir, $koekje;

echo "
<HTML>
<HEAD>
  <TITLE>$title</TITLE>
<style type=\"text/css\">
<!--
  A:hover
{
 background-color: #0AEA98;
;
}
-->
</style>
<script language='JavaScript'>
<!--
function jumpMenu(targ,selObj,restore){
if (selObj.options[selObj.selectedIndex].value != '') {
  eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
}
  if (restore) selObj.selectedIndex=0;

}
//-->
</script>
</HEAD>
<BODY bgcolor='$bgcolor' text='$textcolor' link='$linkcolor' alink='$alinkcolor' vlink='$vlinkcolor'>
<TABLE border='1' align='left' bordercolor='#003399' width='100%'>
  <TR>
    <TD width='100' align='left' valign='top' bgcolor='$table_bgcolor' bordercolor='$table_bordercolor'>
      <A href='$fdatdir/fdat.php'>Home</A> <BR>
      ";

      if ((!isset($koekje)) || ($koekje == "Guest")) {
        echo "<A href='$fdatdir/fdat.php?login=1'>Inloggen</A> <BR>";

      }
      if ((isset($koekje)) && ($koekje != "Guest")) {

          $userRank = get_UserData($koekje);
          if ($userRank == "a") {
            echo "<A href='$fdatdir/admin.php'>Admin</A><BR>";
          }
          echo "
          <A href='$fdatdir/profile.php'>Profile</A><br>
          <font color=\"#0AEA98\"><br>Links:</font><br>
          ";
          get_links("$fdatdir");
          echo"
          <br>
          <font color=\"#0AEA98\">Files:<br></font>
          <A href='$fdatdir/files.php?files=add'>Add</A><BR>
          <A href='$fdatdir/files.php?files=show'>View</A><BR>
          <A href='$fdatdir/files.php?files=search'>Search</A><BR>
          <br><br><a href=\"sources/logInOut.php\">Logout</a><br><br>
          ";
          }


}

function head2() {
global $fdatdir;
echo " </TD>
       <TD bordercolor='#000099' bgcolor='#330033' width='90%' valign='top'>
";
}

function foot() {
echo "
<p><font size=\"2\">Copyright &copy; 2001 Jeffrey Gelens</font></p></TD>
</TR>
</TABLE>

</BODY>
</HTML>
";
}

function read_dir($dir) {
$i = 0;
$handle=opendir($dir);
while (false!==($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
        $file_array[$i] = $file;
        $i++;
    }
}
closedir($handle);
sort($file_array);
return $file_array;
}

function search_file($dir, $search) {
$found = 0;
$i = 0;
$handle = opendir($dir);

while (false!==($file = readdir($handle))) {
  if ($file != "." && $file != "..") {
      $fp = fopen("$dir/$file", "r");
        if (!fp) {
          echo "Can't open file.";
  }
  $data = fread($fp, filesize("$dir/$file"));
  fclose ($fp);
  $pos = stristr ($data, $search);
  if ($pos == false) {
    //niks gevonden
  }
  else {
  $found = 1;
    $file_array[$i] = $file;
    $i++;
    }
}
}
if ($found == 0) {
  echo "<br>No files found :-(";
}
return $file_array;
}

function get_UserData($koekje) {
if ((isset($koekje)) && ($koekje != "Guest")) {
  $koekje2 = base64_decode($koekje);
  $sql = "SELECT * FROM logged_in WHERE username = '$koekje2'";
  $result = mysql_query($sql);
  if ($result) {
    $sql = "SELECT rank FROM users WHERE username = '$koekje2'";
    $result = mysql_query($sql);
    $rank = mysql_result($result, '');
    return $rank;
  }
  else {
    return "Guest";
  }
}
}

function get_User($koekje) {
if ((isset($koekje)) && ($koekje != "Guest")) {
  $koekje2 = base64_decode($koekje);
  $sql = "SELECT * FROM logged_in WHERE username = '$koekje2'";
  $result = mysql_query($sql);

  if ($result) {
    return $koekje2;
  }
  else {
    return "Guest";
  }
}
}

function check($url) {
global $koekje;
ereg(".+(\/{1})(.+)$", $url, $reg);
$url = $reg[2];
if ((isset($koekje)) && ($koekje != "Guest")) {
  $koekje2 = base64_decode($koekje);
  $sql = "SELECT * FROM logged_in WHERE username = '$koekje2'";
  $result = mysql_query($sql);
  $result = mysql_result($result , '', "username");

  if ($result != "") {
     return true;
  }
  else {
    if ($url != "fdat.php") {
      return false;
    }
    else {
      return true;
    }
  }
}
else {
 if ($url != "fdat.php") {
      return false;
 }
 else {
    return true;
 }
}
}

function set_Subject($which_subject, $school) {
if (eregi("(.+)(_)([a-z])(_)([a-z]$)", $filename, $reg)) {
  echo $reg[1];
}
else {
  echo "verkeerd";
}
}
?>

Return current item: PHP File Database