Location: PHPKode > projects > Whiteboard > whiteboard1.0.3/program/include/documentsinclude.php
<?php
/* Whiteboard Courseware System v1.0.3
   Copyright (C) 2002-2003 Todd Templeton

   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.

   This program is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
   more details.

   You should have received a copy of the GNU General Public License along with
   this program; if not, write to the Free Software Foundation, Inc., 59 Temple
   Place, Suite 330, Boston, MA 02111-1307 USA

   Contact info: my paper address changes often, but you can contact me at
   hide@address.com
*/


/* gets a document
   returns document info (associative array) (returns false on error)
   $docid is the document id
*/
function getdocument ($docid) {
  global $course;
  global $semester;
  global $documentoptions;
  $table = $course . "_" . $semester . "_documents";
  $where = "id = '" . $docid . "' and deleted = '0'";
  $document = getdbfirstmatch ($table, "*", $where);
  $valueoptions = $documentoptions;
  checkdbdata (&$document, "id", $valueoptions, "document", false);
  return $document;
}


/* gets all directories
   returns associative array (by directory id) of directory info
*/
function getalldirs () {
  global $course;
  global $semester;
  global $documentdirectoryoptions;
  $table = $course . "_" . $semester . "_documentdirs";
  $where = "deleted = '0'";
  $dirs = getdbassoc ($table, "*", $where, "parent, name", "id");
  if (is_array ($dirs)) {
    $valueoptions = $documentdirectoryoptions;
    $datatype = "document directory";
    reset ($dirs);
    while ($elementinfo = each ($dirs)) {
      $key = $elementinfo['key'];
      checkdbdata (&$dirs[$key], "id", $valueoptions, $datatype, false);
    }
  }
  return $dirs;
}


/* determines full path (from documents root) of document directory
   returns generated string
   $alldirs is the return value of getalldirs ()
   $dir is a directory id
*/
function fullpath ($alldirs, $dir) {
  if (!isposinteger ($dir) || !isset ($alldirs[$dir]))
    return "";
  $current = $alldirs[$dir];
  $path = $current['name'];
  while (isset ($current['parent']) && isposinteger ($current['parent'])) {
    if (!isset ($alldirs[$current['parent']]))
      break;
    $current = $alldirs[$current['parent']];
    $path = $current['name'] . "/" . $path;
  }
  return $path;
}


/* determines full file system path of document directory
   returns generated string
   $alldirs is the return value of getalldirs ()
   $dir is a directory id
*/
function fulldirpath ($alldirs, $dir) {
  $path = DOCUMENTSDIR;
  if (($temp = fullpath ($alldirs, $dir)) != "")
    $path .= "/" . $temp;
  return $path;
}
?>
Return current item: Whiteboard