Commit f03e5e0fd350999dbe72ddc2deba6bab01739844

Authored by rob
1 parent 0c43a0ce

Initial revision. Static functions to handle insertion/deletion/updating of fol…

…der information in the db.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@193 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/foldermanagement/FolderManagemer.inc 0 → 100644
  1 +<?php
  2 +
  3 +/**
  4 +* Class FolderManager
  5 +*
  6 +* Contains static functions concerned with the insert, update and deletion of folders in
  7 +* the database.
  8 +*
  9 +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
  10 +* @date 15 January 2003
  11 +*/
  12 +
  13 +class FolderManager {
  14 +
  15 +
  16 + /**
  17 + * Insert a new folder into the database
  18 + *
  19 + * @param $sName Folder name
  20 + * @param $sDescription Short description of folder
  21 + * @param $iParentID Primary key of parent folder
  22 + * @param $iCreatorID ID of user who created the folder
  23 + * @param $iDocumentTypeID Document type this folder will store
  24 + * @param $iUnitID Unit to which the folder belongs
  25 + * @param $bIsPublic Is the folder public (default = false);
  26 + *
  27 + * @return true on sucessful insertion, false otherwise and set $_SESSION["errorMessage"]
  28 + */
  29 + function insertFolder($sName, $sDescription, $iParentID, $iCreatorID, $iDocumentTypeID, $iUnitID, $bIsPublic = false) {
  30 + global $default, $lang_err_database;
  31 + if (!(FolderNamager::folderExistsName($sName, $iParentID)) {
  32 + $sql = new Owl_DB();
  33 + $result = $sql->query("INSERT INTO " . $default->owl_folders_table . " (name, description, parent_id, creator_id, document_type_id, unit_id, is_public) " .
  34 + "VALUES (" . $sName . . $sDescription . . $iParentID . . $iCreatorID .. $iDocumentTypeID .. $UnitID .. $bIsPublice")");
  35 + if (!$result) {
  36 + $_SESSION["errorMessage"] = $lang_err_database;
  37 + return false;
  38 + }
  39 + return true;
  40 + }
  41 + //error message set in folderExistsName
  42 + return false;
  43 +
  44 + }
  45 +
  46 + /**
  47 + * Delete and existing folder
  48 + *
  49 + * $iFolderID Primary key of folder to delete
  50 + *
  51 + * @return true on successfuly deletion, false otherwise and set $_SESSION["errorMessage"]
  52 + */
  53 + function deleteFolder($iFolderID) {
  54 + global $default,
  55 + if (folderExistsID($iFolderID)) {
  56 + $sql = new Owl_DB();
  57 + $result = $sql->query("DELETE FROM " . $default->owl_folders_table . " WHERE id = " . $iFolderID);
  58 + if (!$result) {
  59 + $_SESSION["errorMessage"] = $lang_err_database;
  60 + return false;
  61 + }
  62 + return true;
  63 + }
  64 + $_SESSION["errorMessage"] = $lang_err_folder_not_exist . "id " . $iFolderID;
  65 + return false;
  66 + }
  67 +
  68 + /**
  69 + * Checks if a given folder already exists using the folder name
  70 + *
  71 + * @param $sName Name of folder
  72 + * @param $iParentID Primary key of parent folder
  73 + *
  74 + * @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"]
  75 + */
  76 + function folderExistsName($sName, $iParentID) {
  77 + global $default, $lang_err_folder_exist;
  78 + $sql = new Owl_DB();
  79 + $sql->query("SELECT * FROM " . $default->owl_folders_table . " WHERE name = '" . $sName . "' AND parent_id = " . $iParentID);
  80 + if ($sql->next_record()) {
  81 + return true;
  82 + }
  83 + $_SESSION["errorMessage"] =$lang_err_folder_exist . $sName;
  84 + return false;
  85 + }
  86 +
  87 + /**
  88 + * Checks if a given folder already exists using the folder name
  89 + *
  90 + * @param $iFolderID Primary key of folder
  91 + *
  92 + * @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"]
  93 + */
  94 + function folderExistsID($iFolderID) {
  95 + global $default, $lang_err_folder_exist;
  96 + $sql = new Owl_DB();
  97 + $sql->query("SELECT * FROM " . $default->owl_folders_table . " WHERE id = " . $iFolderID);
  98 + if ($sql->next_record()) {
  99 + return true;
  100 + }
  101 + $_SESSION["errorMessage"] =$lang_err_folder_exist . $sName;
  102 + return false;
  103 + }
  104 +
  105 +
  106 +
  107 +}
  108 +
  109 +?>
  110 +
... ...