Commit c7b99f885d7123baa48227e3b85528bd3b381a6e

Authored by mukhtar
1 parent f182aa34

added remove doc type only if not belonging to any folders


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1354 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/documentmanagement/DocumentType.inc
@@ -129,14 +129,27 @@ class DocumentType { @@ -129,14 +129,27 @@ class DocumentType {
129 function delete() { 129 function delete() {
130 global $default, $lang_err_database, $lang_err_object_key; 130 global $default, $lang_err_database, $lang_err_object_key;
131 //only delete the object if it exists in the database 131 //only delete the object if it exists in the database
132 - if ($this->iId >= 0) { 132 + if ($this->iId > 0) {
  133 + //check to see if name exsits
133 $sql = $default->db; 134 $sql = $default->db;
134 - $result = $sql->query("DELETE FROM " . $default->owl_document_types_table . " WHERE id = $this->iId");  
135 - if ($result) {  
136 - return true; 135 + $query = "SELECT folder_id FROM ". $default->owl_folder_doctypes_table ." WHERE document_type_id = '" . $this->iId . "'";
  136 + $sql->query($query);
  137 + $rows = $sql->num_rows($sql);
  138 +
  139 + if ($rows > 0){
  140 + // duplicate username
  141 + $_SESSION["errorMessage"] = "DocTypes::Assigned to DocFolder name " . $this->iId . " is already exists!";
  142 + return false;
  143 +
  144 + }else{
  145 + $sql = $default->db;
  146 + $result = $sql->query("DELETE FROM " . $default->owl_document_types_table . " WHERE id = '" . $this->iId . "'");
  147 + if ($result) {
  148 + return true;
  149 + }
  150 + $_SESSION["errorMessage"] = $lang_err_database;
  151 + return false;
137 } 152 }
138 - $_SESSION["errorMessage"] = $lang_err_database;  
139 - return false;  
140 } 153 }
141 $_SESSION["errorMessage"] = $lang_err_object_key; 154 $_SESSION["errorMessage"] = $lang_err_object_key;
142 return false; 155 return false;