Commit 8b51b65b067d5e28fa8f886e7fcace2275a0dbea

Authored by rob
1 parent f3826255

Added delete button to depedant documents


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1884 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/foldermanagement/viewDependantDocumentsBL.php
@@ -15,110 +15,119 @@ @@ -15,110 +15,119 @@
15 require_once("../../../../config/dmsDefaults.php"); 15 require_once("../../../../config/dmsDefaults.php");
16 16
17 if (checkSession()) { 17 if (checkSession()) {
18 - if (isset($fFolderID) && isset($fFolderCollaborationID)) {  
19 - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");  
20 - require_once("$default->fileSystemRoot/lib/foldermanagement/FolderCollaboration.inc");  
21 - require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); 18 + if (isset($fFolderID) && isset($fFolderCollaborationID)) {
  19 +
  20 + //folder and collaboration are selected
  21 + require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
  22 + require_once("$default->fileSystemRoot/lib/foldermanagement/FolderCollaboration.inc");
  23 + require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
22 require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); 24 require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
23 - require_once("$default->fileSystemRoot/lib/users/User.inc");  
24 - require_once("$default->fileSystemRoot/lib/documentmanagement/DependantDocumentTemplate.inc");  
25 - require_once("$default->fileSystemRoot/presentation/Html.inc");  
26 - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc");  
27 - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");  
28 - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc");  
29 - require_once("viewDependantDocumentsUI.inc"); 25 + require_once("$default->fileSystemRoot/lib/users/User.inc");
  26 + require_once("$default->fileSystemRoot/lib/documentmanagement/DependantDocumentTemplate.inc");
  27 + require_once("$default->fileSystemRoot/presentation/Html.inc");
  28 + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc");
  29 + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
  30 + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc");
  31 + require_once("viewDependantDocumentsUI.inc");
30 32
31 - //folder and collaboration are selected  
32 - if (isset($fForStore)) {  
33 - $oDependantDocumentTemplate;  
34 - if ($fTemplateDocumentID == "-1") {  
35 - $oDependantDocumentTemplate = & new DependantDocumentTemplate($fDocumentTitle, $fUserID, $fFolderCollaborationID);  
36 - } else {  
37 - $oDependantDocumentTemplate = & new DependantDocumentTemplate($fDocumentTitle, $fUserID, $fFolderCollaborationID, $fTemplateDocumentID);  
38 - }  
39 - if (!($oDependantDocumentTemplate->create())) {  
40 - include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
41 -  
42 - $oPatternCustom = & new PatternCustom();  
43 - $oPatternCustom->setHtml(getViewPage($fFolderCollaborationID, $fFolderID));  
44 - $main->setCentralPayload($oPatternCustom);  
45 - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForAdd=1");  
46 - $main->setErrorMessage("An error occured attempting to store the depedant document");  
47 - $main->render();  
48 - } else {  
49 - redirect("$default->rootUrl/control.php?action=viewDependantDocument&fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID");  
50 - }  
51 - } else if (isset($fForAdd)) {  
52 - //we are adding a new dependant document  
53 - $oFolderCollaboration = FolderCollaboration::get($fFolderCollaborationID);  
54 - if ($oFolderCollaboration->hasDocumentInProcess()) {  
55 - include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
56 -  
57 - $oPatternCustom = & new PatternCustom();  
58 - $oPatternCustom->setHtml(getViewPage($fFolderCollaborationID, $fFolderID));  
59 - $main->setCentralPayload($oPatternCustom);  
60 - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForAdd=1");  
61 - $main->setErrorMessage("You cannot add a new depedant document as there is currently a document in this folder undergoing collaboration");  
62 - $main->render(); 33 +
  34 + if (Permission::userHasFolderWritePermission($fFolderID)) {
  35 + //user has folder write permission
  36 + if (isset($fForStore)) {
  37 + $oDependantDocumentTemplate;
  38 + if ($fTemplateDocumentID == "-1") {
  39 + $oDependantDocumentTemplate = & new DependantDocumentTemplate($fDocumentTitle, $fUserID, $fFolderCollaborationID);
  40 + } else {
  41 + $oDependantDocumentTemplate = & new DependantDocumentTemplate($fDocumentTitle, $fUserID, $fFolderCollaborationID, $fTemplateDocumentID);
  42 + }
  43 + if (!($oDependantDocumentTemplate->create())) {
  44 + include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
63 45
64 - } else {  
65 - include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); 46 + $oPatternCustom = & new PatternCustom();
  47 + $oPatternCustom->setHtml(getViewPage($fFolderCollaborationID, $fFolderID));
  48 + $main->setCentralPayload($oPatternCustom);
  49 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForAdd=1");
  50 + $main->setErrorMessage("An error occured attempting to store the depedant document");
  51 + $main->render();
  52 + } else {
  53 + redirect("$default->rootUrl/control.php?action=viewDependantDocument&fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID");
  54 + }
  55 + } else if (isset($fForAdd)) {
  56 + //we are adding a new dependant document
  57 + $oFolderCollaboration = FolderCollaboration::get($fFolderCollaborationID);
  58 + if ($oFolderCollaboration->hasDocumentInProcess()) {
  59 + include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
66 60
67 - $oPatternCustom = & new PatternCustom();  
68 - $oPatternCustom->setHtml(getAddPage($fFolderCollaborationID, $fFolderID, (isset($fUnitID) ? $fUnitID : -1), (isset($fDocumentTitle) ? $fDocumentTitle : ""), (isset($fTemplateDocument) ? $fTemplateDocument : ""), (isset($fDocumentID) ? $fDocumentID : "") ));  
69 - $main->setCentralPayload($oPatternCustom);  
70 - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForStore=1");  
71 - $main->setHasRequiredFields(true);  
72 - $main->render();  
73 - }  
74 - } else if (isset($fForEdit)) {  
75 - $oFolderCollaboration = FolderCollaboration::get($fFolderCollaborationID);  
76 - if ($oFolderCollaboration->hasDocumentInProcess()) {  
77 - //can't edit if there is a document currently undergoing collaboration  
78 - include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
79 -  
80 - $oPatternCustom = & new PatternCustom();  
81 - $oPatternCustom->setHtml(getViewPage($fFolderCollaborationID, $fFolderID));  
82 - $main->setCentralPayload($oPatternCustom);  
83 - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForUpdate=1");  
84 - $main->setErrorMessage("You cannot add a new depedant document as there is currently a document in this folder undergoing collaboration");  
85 - $main->render(); 61 + $oPatternCustom = & new PatternCustom();
  62 + $oPatternCustom->setHtml(getViewPage($fFolderCollaborationID, $fFolderID));
  63 + $main->setCentralPayload($oPatternCustom);
  64 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForAdd=1");
  65 + $main->setErrorMessage("You cannot add a new depedant document as there is currently a document in this folder undergoing collaboration");
  66 + $main->render();
  67 +
  68 + } else {
  69 + include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  70 +
  71 + $oPatternCustom = & new PatternCustom();
  72 + $oPatternCustom->setHtml(getAddPage($fFolderCollaborationID, $fFolderID, (isset($fUnitID) ? $fUnitID : -1), (isset($fDocumentTitle) ? $fDocumentTitle : ""), (isset($fTemplateDocument) ? $fTemplateDocument : ""), (isset($fDocumentID) ? $fDocumentID : "") ));
  73 + $main->setCentralPayload($oPatternCustom);
  74 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForStore=1");
  75 + $main->setHasRequiredFields(true);
  76 + $main->render();
  77 + }
  78 + } else if (isset($fForEdit)) {
  79 + $oFolderCollaboration = FolderCollaboration::get($fFolderCollaborationID);
  80 + if ($oFolderCollaboration->hasDocumentInProcess()) {
  81 + //can't edit if there is a document currently undergoing collaboration
  82 + include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
86 83
87 - } else {  
88 - include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); 84 + $oPatternCustom = & new PatternCustom();
  85 + $oPatternCustom->setHtml(getViewPage($fFolderCollaborationID, $fFolderID));
  86 + $main->setCentralPayload($oPatternCustom);
  87 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForUpdate=1");
  88 + $main->setErrorMessage("You cannot add a new depedant document as there is currently a document in this folder undergoing collaboration");
  89 + $main->render();
  90 +
  91 + } else {
  92 + include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  93 +
  94 + $oDependantDocumentTemplate = DependantDocumentTemplate::get($fDependantDocumentTemplateID);
  95 + if ($oDependantDocumentTemplate->getTemplateDocumentID() >= 1) {
  96 + $oDocument = Document::get($oDependantDocumentTemplate->getTemplateDocumentID());
  97 + }
  98 +
  99 + $oPatternCustom = & new PatternCustom();
  100 + $oPatternCustom->setHtml(getEditPage($fFolderID, $fDependantDocumentTemplateID, $fFolderCollaborationID, $oDependantDocumentTemplate->getDocumentTitle(), (isset($oDocument) ? $oDocument->getName() : ""), (isset($oDocument) ? $oDependantDocumentTemplate->getTemplateDocumentID() : null), $oDependantDocumentTemplate->getDefaultUserID()));
  101 + $main->setCentralPayload($oPatternCustom);
  102 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fDependantDocumentTemplateID=$fDependantDocumentTemplateID&fForUpdate=1");
  103 + $main->setHasRequiredFields(true);
  104 + $main->render();
  105 + }
  106 + } else if (isset($fForUpdate)) {
  107 + $oDependantDocumentTemplate = DependantDocumentTemplate::get($fDependantDocumentTemplateID);
  108 + $oDependantDocumentTemplate->setDefaultUserID($fUserID);
  109 + $oDependantDocumentTemplate->setDocumentTitle($fDocumentTitle);
  110 + $oDependantDocumentTemplate->setTemplateDocumentID((isset($fTemplateDocumentID) ? $fTemplateDocumentID : null));
  111 + $oDependantDocumentTemplate->update();
  112 +
  113 + redirect("$default->rootUrl/control.php?action=viewDependantDocument&fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID");
89 114
90 - $oDependantDocumentTemplate = DependantDocumentTemplate::get($fDependantDocumentTemplateID);  
91 - if ($oDependantDocumentTemplate->getTemplateDocumentID() >= 1) {  
92 - $oDocument = Document::get($oDependantDocumentTemplate->getTemplateDocumentID());  
93 - } 115 + } else {
  116 + include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
94 117
95 - $oPatternCustom = & new PatternCustom();  
96 - $oPatternCustom->setHtml(getEditPage($fFolderID, $fDependantDocumentTemplateID, $fFolderCollaborationID, $oDependantDocumentTemplate->getDocumentTitle(), (isset($oDocument) ? $oDocument->getName() : ""), (isset($oDocument) ? $oDependantDocumentTemplate->getTemplateDocumentID() : null), $oDependantDocumentTemplate->getDefaultUserID())); 118 + $oPatternCustom = & new PatternCustom();
  119 + $oPatternCustom->setHtml(getViewPage($fFolderCollaborationID, $fFolderID));
97 $main->setCentralPayload($oPatternCustom); 120 $main->setCentralPayload($oPatternCustom);
98 - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fDependantDocumentTemplateID=$fDependantDocumentTemplateID&fForUpdate=1");  
99 - $main->setHasRequiredFields(true);  
100 - $main->render(); 121 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForAdd=1");
  122 + $main->render();
101 } 123 }
102 - } else if (isset($fForUpdate)) {  
103 - $oDependantDocumentTemplate = DependantDocumentTemplate::get($fDependantDocumentTemplateID);  
104 - $oDependantDocumentTemplate->setDefaultUserID($fUserID);  
105 - $oDependantDocumentTemplate->setDocumentTitle($fDocumentTitle);  
106 - $oDependantDocumentTemplate->setTemplateDocumentID((isset($fTemplateDocumentID) ? $fTemplateDocumentID : null));  
107 - $oDependantDocumentTemplate->update();  
108 -  
109 - redirect("$default->rootUrl/control.php?action=viewDependantDocument&fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID");  
110 -  
111 } else { 124 } else {
112 - include_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
113 -  
114 - $oPatternCustom = & new PatternCustom();  
115 - $oPatternCustom->setHtml(getViewPage($fFolderCollaborationID, $fFolderID));  
116 - $main->setCentralPayload($oPatternCustom);  
117 - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fFolderCollaborationID=$fFolderCollaborationID&fForAdd=1");  
118 - $main->render();  
119 - }  
120 - 125 + //redirect the user back to their start page if they somehow
  126 + //got here without the relevant permission
  127 + redirect($default->root_url . "/control.php");
  128 + }
121 } 129 }
  130 +
122 131
123 } 132 }
124 133
presentation/lookAndFeel/knowledgeTree/foldermanagement/viewDependantDocumentsUI.inc
@@ -23,21 +23,21 @@ function getFolderPath($iFolderID) { @@ -23,21 +23,21 @@ function getFolderPath($iFolderID) {
23 23
24 function getDocumentLinkFolderCollaborationData($iFolderCollaborationID) { 24 function getDocumentLinkFolderCollaborationData($iFolderCollaborationID) {
25 global $default; 25 global $default;
26 - $sQuery = "SELECT DDT.id, GFAL.folder_id AS folder_id, U.name AS username, DDT.document_title, D.name AS template_document_name, D.id AS template_document_id, DDT.group_folder_approval_link_id, 'Edit' AS edit " . 26 + $sQuery = "SELECT DDT.id, GFAL.folder_id AS folder_id, U.name AS username, DDT.document_title, D.name AS template_document_name, D.id AS template_document_id, DDT.group_folder_approval_link_id, 'Edit' AS edit, 'Delete' AS del " .
27 "FROM dependant_document_template AS DDT INNER JOIN groups_folders_approval_link AS GFAL ON DDT.group_folder_approval_link_id = GFAL.id " . 27 "FROM dependant_document_template AS DDT INNER JOIN groups_folders_approval_link AS GFAL ON DDT.group_folder_approval_link_id = GFAL.id " .
28 "INNER JOIN users AS U ON U.id = DDT.default_user_id " . 28 "INNER JOIN users AS U ON U.id = DDT.default_user_id " .
29 "LEFT OUTER JOIN documents AS D ON D.id = DDT.template_document_id " . 29 "LEFT OUTER JOIN documents AS D ON D.id = DDT.template_document_id " .
30 "WHERE DDT.group_folder_approval_link_id = $iFolderCollaborationID"; 30 "WHERE DDT.group_folder_approval_link_id = $iFolderCollaborationID";
31 31
32 //echo $sQuery; 32 //echo $sQuery;
33 - $aColumns = array("document_title", "username", "template_document_name","edit");  
34 - $aColumnHeaders = array("Document title", "Default creator", "Template document", "Edit");  
35 - $aColumnTypes = array(1,1,3,3); 33 + $aColumns = array("document_title", "username", "template_document_name","edit", "del");
  34 + $aColumnHeaders = array("Document title", "Default creator", "Template document");
  35 + $aColumnTypes = array(1,1,3,3,3);
36 //$aDBColumnArray = array("id","group_folder_approval_link_id","template_document_id"); 36 //$aDBColumnArray = array("id","group_folder_approval_link_id","template_document_id");
37 $aDBColumnArray = array("id","group_folder_approval_link_id","folder_id"); 37 $aDBColumnArray = array("id","group_folder_approval_link_id","folder_id");
38 //$aQueryStringVariableNames = array("fDependantDocumentTemplateID", "fFolderCollaborationID", "fDocumentID"); 38 //$aQueryStringVariableNames = array("fDependantDocumentTemplateID", "fFolderCollaborationID", "fDocumentID");
39 $aQueryStringVariableNames = array("fDependantDocumentTemplateID","fFolderCollaborationID","fFolderID"); 39 $aQueryStringVariableNames = array("fDependantDocumentTemplateID","fFolderCollaborationID","fFolderID");
40 - $aLinkURLs = array(2=>"$default->rootUrl/control.php?action=viewDocument", 3=>"$default->rootUrl/control.php?action=viewDependantDocument&fForEdit=1"); 40 + $aLinkURLs = array(2=>"$default->rootUrl/control.php?action=viewDocument", 3=>"$default->rootUrl/control.php?action=viewDependantDocument&fForEdit=1", 4=>"$default->rootUrl/control.php?action=deleteDependantDocument");
41 41
42 $oPatternTableSqlQuery = & new PatternTableSqlQuery($sQuery, $aColumns, $aColumnTypes, $aColumnHeaders, "90%", $aLinkURLs, $aDBColumnArray,$aQueryStringVariableNames); 42 $oPatternTableSqlQuery = & new PatternTableSqlQuery($sQuery, $aColumns, $aColumnTypes, $aColumnHeaders, "90%", $aLinkURLs, $aDBColumnArray,$aQueryStringVariableNames);
43 $oPatternTableSqlQuery->setTableHeading("Dependant Documents"); 43 $oPatternTableSqlQuery->setTableHeading("Dependant Documents");