Commit 736de6343ca13e1a9ddff92c5026b1fa75748574

Authored by rob
1 parent ef37ec7f

Initial revision. Functionality require to create/delete folders


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@204 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/foldermanagement/FolderManager.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 + $sName = addslashes($sName);
  31 + global $default, $lang_err_database;
  32 + //if the folder doesn't exist
  33 + if (!(FolderNamager::folderExistsName($sName, $iParentID)) {
  34 + $sql = new Owl_DB();
  35 + $result = $sql->query("INSERT INTO " . $default->owl_folders_table . " (name, description, parent_id, creator_id, document_type_id, unit_id, is_public) " .
  36 + "VALUES (" . $sName . . $sDescription . . $iParentID . . $iCreatorID .. $iDocumentTypeID .. $UnitID .. $bIsPublice")");
  37 + if (!$result) {
  38 + $_SESSION["errorMessage"] = $lang_err_database;
  39 + return false;
  40 + }
  41 + return true;
  42 + }
  43 + //error message set in folderExistsName
  44 + return false;
  45 +
  46 + }
  47 +
  48 + /**
  49 + * Delete and existing folder
  50 + *
  51 + * $iFolderID Primary key of folder to delete
  52 + *
  53 + * @return true on successfuly deletion, false otherwise and set $_SESSION["errorMessage"]
  54 + */
  55 + function deleteFolder($iFolderID) {
  56 + global $default,$lang_err_folder_not_exist;
  57 + //if the folder exists
  58 + if (folderExistsID($iFolderID)) {
  59 + $sql = new Owl_DB();
  60 + $result = $sql->query("DELETE FROM " . $default->owl_folders_table . " WHERE id = " . $iFolderID);
  61 + if (!$result) {
  62 + $_SESSION["errorMessage"] = $lang_err_database;
  63 + return false;
  64 + }
  65 + return true;
  66 + }
  67 + $_SESSION["errorMessage"] = $lang_err_folder_not_exist . "id " . $iFolderID;
  68 + return false;
  69 + }
  70 +
  71 +
  72 + /**
  73 + * Checks if a given folder already exists using the folder name
  74 + *
  75 + * @param $sName Name of folder
  76 + * @param $iParentID Primary key of parent folder
  77 + *
  78 + * @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"]
  79 + */
  80 + function folderExistsName($sName, $iParentID) {
  81 + $sName = addslashes($sName);
  82 + global $default, $lang_err_folder_exist;
  83 + $sql = new Owl_DB();
  84 + $sql->query("SELECT * FROM " . $default->owl_folders_table . " WHERE name = '" . $sName . "' AND parent_id = " . $iParentID);
  85 + if ($sql->next_record()) {
  86 + return true;
  87 + }
  88 + $_SESSION["errorMessage"] = $lang_err_folder_exist . $sName . " parent_id " . $iParentID;
  89 + return false;
  90 + }
  91 +
  92 + /**
  93 + * Checks if a given folder already exists using the folder name
  94 + *
  95 + * @param $iFolderID Primary key of folder
  96 + *
  97 + * @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"]
  98 + */
  99 + function folderExistsID($iFolderID) {
  100 + global $default, $lang_err_folder_exist;
  101 + $sql = new Owl_DB();
  102 + $sql->query("SELECT * FROM " . $default->owl_folders_table . " WHERE id = " . $iFolderID);
  103 + if ($sql->next_record()) {
  104 + return true;
  105 + }
  106 + $_SESSION["errorMessage"] =$lang_err_folder_exist . "id " . $iFolderID;
  107 + return false;
  108 + }
  109 +
  110 + /**
  111 + * Get a folder's primary key using the folder name and the parent id
  112 + *
  113 + * @param $sName Name of folder
  114 + * @param $iParentID Primary key of parent folder
  115 + *
  116 + * @return id integer on successful lookup, false otherwise and set $_SESSION["errorMessage"]
  117 + *
  118 + */
  119 + function getFolderID($sName, $iParentID) {
  120 + $sName = addslashes($sName);
  121 + gobal $default, $lang_err_folder_exist;
  122 + $sql = new Owl_DB();
  123 + $sql->query("SELECT id FROM " . $default->owl_folders_table . " WHERE name = '" . $sName . "' AND parent_id = " $iParentID);
  124 + if ($sql->next_record()) {
  125 + return $sql->f("id");
  126 + }
  127 + $_SESSION["errorMessage"] = $lang_err_folder_exist . $sName;
  128 + return false;
  129 + }
  130 +
  131 +
  132 +
  133 +}
  134 +
  135 +?>
  136 +
... ...