Commit 7dd5ce8733f44fff6ea4b5459c0313ca2cc0c178
1 parent
295d6650
Updated so that only document table entries are edited here
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1211 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
111 additions
and
90 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyBL.php
| @@ -16,24 +16,64 @@ if (checkSession()) { | @@ -16,24 +16,64 @@ if (checkSession()) { | ||
| 16 | require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); | 16 | require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); |
| 17 | require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); | 17 | require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); |
| 18 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); | 18 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); |
| 19 | + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc"); | ||
| 19 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); | 20 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); |
| 20 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableListFromQuery.inc"); | 21 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableListFromQuery.inc"); |
| 21 | require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyUI.inc"); | 22 | require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyUI.inc"); |
| 22 | - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); | ||
| 23 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | 23 | + require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); |
| 24 | require_once("$default->fileSystemRoot/presentation/Html.inc"); | 24 | require_once("$default->fileSystemRoot/presentation/Html.inc"); |
| 25 | 25 | ||
| 26 | - $aDocumentDataArray; | ||
| 27 | - settype($aDocumentDataArray, "array"); | ||
| 28 | - | ||
| 29 | - $oDocument = & Document::get($fDocumentID); | ||
| 30 | - $oPatternCustom = & new PatternCustom(); | ||
| 31 | - $oPatternCustom->setHtml(renderPage($oDocument)); | ||
| 32 | - $main->setCentralPayload($oPatternCustom); | ||
| 33 | - $main->setHasRequiredFields(true); | ||
| 34 | - $main->setFormAction("../store.php?fReturnURL=" . urlencode("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID() . "&fFireSubscription=1")); | ||
| 35 | - $main->setHasRequiredFields(true); | ||
| 36 | - $main->render(); | 26 | + if (Permission::userHasDocumentWritePermission($fDocumentID)) { |
| 27 | + //if the user has write permission | ||
| 28 | + $oDocument = & Document::get($fDocumentID); | ||
| 29 | + if (isset($fForUpdate)) { | ||
| 30 | + //if the user is updating the values | ||
| 31 | + $oDocument->setName($fDocumentName); | ||
| 32 | + | ||
| 33 | + if ($oDocument->getDocumentTypeID() != $fDocumentTypeID) { | ||
| 34 | + //the user has changed the document type | ||
| 35 | + //get rid of all the old document type entries | ||
| 36 | + $oDocument->removeInvalidDocumentTypeEntries(); | ||
| 37 | + $oDocument->setDocumentTypeID($fDocumentTypeID); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + if ($oDocument->update()) { | ||
| 41 | + //on successful update, redirect to the view page | ||
| 42 | + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID()); | ||
| 43 | + } else { | ||
| 44 | + //display the update page with an error message | ||
| 45 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 46 | + $oPatternCustom = & new PatternCustom(); | ||
| 47 | + $oPatternCustom->setHtml(renderPage($oDocument, $oDocument->getDocumentTypeID())); | ||
| 48 | + $main->setCentralPayload($oPatternCustom); | ||
| 49 | + $main->setHasRequiredFields(true); | ||
| 50 | + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForUpdate=1"); | ||
| 51 | + $main->setHasRequiredFields(true); | ||
| 52 | + $main->setErrorMessage("An error occured while attempting to update the document"); | ||
| 53 | + $main->render(); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + } else { | ||
| 57 | + //display the update page | ||
| 58 | + $oDocument = & Document::get($fDocumentID); | ||
| 59 | + $oPatternCustom = & new PatternCustom(); | ||
| 60 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 61 | + $oPatternCustom->setHtml(renderPage($oDocument, $oDocument->getDocumentTypeID())); | ||
| 62 | + $main->setCentralPayload($oPatternCustom); | ||
| 63 | + $main->setHasRequiredFields(true); | ||
| 64 | + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForUpdate=1"); | ||
| 65 | + $main->setHasRequiredFields(true); | ||
| 66 | + $main->render(); | ||
| 67 | + } | ||
| 68 | + } else { | ||
| 69 | + //user doesn't have permission to edit this page | ||
| 70 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | ||
| 71 | + $oPatternCustom = & new PatternCustom(); | ||
| 72 | + $oPatternCustom->setHtml(""); | ||
| 73 | + $main->setCentralPayload($oPatternCustom); | ||
| 74 | + $main->setErrorMessage("You do not have permission to edit this document"); | ||
| 75 | + $main->render(); | ||
| 76 | + } | ||
| 37 | } | 77 | } |
| 38 | 78 | ||
| 39 | ?> | 79 | ?> |
presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyUI.inc
| @@ -14,90 +14,63 @@ function renderDocumentPath($oDocument) { | @@ -14,90 +14,63 @@ function renderDocumentPath($oDocument) { | ||
| 14 | return "<table border=1 width = 100%><tr><td>$sDocumentPath</td></tr></table>\n"; | 14 | return "<table border=1 width = 100%><tr><td>$sDocumentPath</td></tr></table>\n"; |
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | -function renderEditableDocumentData($oDocument) { | 17 | +function renderEditableDocumentData($oDocument, $iDocumentTypeID) { |
| 18 | global $default; | 18 | global $default; |
| 19 | - $sQuery = "SELECT D.id AS id, D.name AS name " . | 19 | + $sQuery = "SELECT D.id AS id, D.name AS name, D.document_type_id AS document_type_id " . |
| 20 | "FROM $default->owl_documents_table AS D " . | 20 | "FROM $default->owl_documents_table AS D " . |
| 21 | "WHERE D.id = " . $oDocument->getID(); | 21 | "WHERE D.id = " . $oDocument->getID(); |
| 22 | - | ||
| 23 | - $aDisplayColumns = array("name"); | ||
| 24 | - $aStoreColumns = array("name"); | ||
| 25 | - $aColumnNames = array("Document Title"); | ||
| 26 | - $aDisplayColumnTypes = array(1); | ||
| 27 | - $aDatabaseColumnTypes = array(1); | ||
| 28 | - | ||
| 29 | - $oPatternEditableListFromQuery = & new PatternEditableListFromQuery($sQuery, $default->owl_documents_table, $aDisplayColumns, $aStoreColumns, $aColumnNames, $aDisplayColumnTypes, $aDatabaseColumnTypes); | ||
| 30 | - $oPatternEditableListFromQuery->setUniqueName("dd"); | ||
| 31 | - $oPatternEditableListFromQuery->setTableHeading("Document Data"); | ||
| 32 | - $oPatternEditableListFromQuery->setColumnsRequired(array(1)); | ||
| 33 | - return $oPatternEditableListFromQuery->render(); | 22 | + |
| 23 | + $sql = $default->db; | ||
| 24 | + $sql->query($sQuery); | ||
| 25 | + $sToRender; | ||
| 26 | + if ($sql->next_record()) { | ||
| 27 | + $sToRender = "<table>\n"; | ||
| 28 | + $sToRender .= "<tr>\n"; | ||
| 29 | + $sToRender .= "<td>\n"; | ||
| 30 | + $sToRender .= "<b>Document Title </b>\n"; | ||
| 31 | + $sToRender .= "</td>\n"; | ||
| 32 | + $sToRender .= "<td>\n"; | ||
| 33 | + $sToRender .= "<input type=\"text\" name=\"fDocumentName\" value=\"" . $sql->f("name") . "\" />\n"; | ||
| 34 | + $sToRender .= "</td>\n"; | ||
| 35 | + $sToRender .= "</tr>\n"; | ||
| 36 | + $sToRender .= "<tr>\n"; | ||
| 37 | + $sToRender .= "<td>\n"; | ||
| 38 | + $sToRender .= "<b>Document Type </b>\n"; | ||
| 39 | + $sToRender .= "</td>\n"; | ||
| 40 | + $sToRender .= "<td>\n"; | ||
| 41 | + $sToRender .= getDocumentType($oDocument->getFolderID(), $iDocumentTypeID); | ||
| 42 | + $sToRender .= "</td>\n"; | ||
| 43 | + $sToRender .= "</tr>\n"; | ||
| 44 | + $sToRender .= "</table>\n"; | ||
| 45 | + | ||
| 46 | + return $sToRender; | ||
| 47 | + } | ||
| 48 | + return ""; | ||
| 34 | } | 49 | } |
| 35 | 50 | ||
| 36 | -function renderEditableGenericMetaData($oDocument) { | ||
| 37 | - global $default; | ||
| 38 | - $sQuery = "SELECT " . $oDocument->getID() . " AS document_id, COALESCE(DFL.id, -1) AS id, DF.name AS name, DF.id as document_field_id, COALESCE(DFL.value, null) AS value " . | ||
| 39 | - "FROM $default->owl_fields_table AS DF LEFT OUTER JOIN $default->owl_document_fields_table AS DFL ON DFL.document_field_id = DF.id " . | ||
| 40 | - "RIGHT OUTER JOIN documents AS D ON D.id = DFL.document_id " . | ||
| 41 | - "WHERE DF.is_generic = 1 " . | ||
| 42 | - "AND D.id = " . $oDocument->getID(); | ||
| 43 | - | ||
| 44 | - $aStoreColumnNames = array("document_id", "document_field_id","value"); | ||
| 45 | - $aDisplayColumnNames = array("document_id", "name", "value"); | ||
| 46 | - $aColumnsEditable = array(0,0,1); | ||
| 47 | - $aColumnsVisible = array(0,1,1); | ||
| 48 | - $aColumnDisplayTypes = array(1,1,1); | ||
| 49 | - $aColumnDatabaseTypes = array(0,0,1); | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes); | ||
| 53 | - $oPatternTableSqlQuery->setRequiredColumnNames(array("value")); | ||
| 54 | - $oPatternTableSqlQuery->setTableCaption("Generic Meta Data"); | ||
| 55 | - $oPatternTableSqlQuery->setUniqueName("gmd"); | ||
| 56 | - return $oPatternTableSqlQuery->render(); | ||
| 57 | - | 51 | +function getDocumentType($iFolderID, $iDocumentTypeID) { |
| 52 | + global $default; | ||
| 53 | + $sWhereClause = "FDL.folder_id = $iFolderID"; | ||
| 54 | + $oPatternListBox = & new PatternListBox("$default->owl_document_types_table", "name", "id", "fDocumentTypeID",$sWhereClause); | ||
| 55 | + $oPatternListBox->setIncludeDefaultValue(false); | ||
| 56 | + $oPatternListBox->setFromClause("INNER JOIN $default->owl_folder_doctypes_table AS FDL ON ST.id = FDL.document_type_id"); | ||
| 57 | + //$oPatternListBox->setPostBackOnChange(true); | ||
| 58 | + if (isset($iDocumentTypeID)) { | ||
| 59 | + $oPatternListBox->setSelectedValue($iDocumentTypeID); | ||
| 60 | + } | ||
| 61 | + //$oPatternListBox->setOnChangeAction("setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "&fDocumentID=$iDocumentID')"); | ||
| 62 | + return $oPatternListBox->render(); | ||
| 58 | } | 63 | } |
| 59 | 64 | ||
| 60 | -function renderEditableTypeSpecificMetaData($oDocument) { | ||
| 61 | - global $default; | ||
| 62 | - $sQuery = "SELECT COALESCE(DFL.id, -1) AS id, " . $oDocument->getID() . " AS document_id, DTFL.document_type_id AS document_type_id, DTL.name AS document_type_name, DTFL.field_id AS document_field_id, DF.name AS field_name, DFL.value AS value, DTFL.is_mandatory AS is_mandatory " . | ||
| 63 | - "FROM $default->owl_document_type_fields_table AS DTFL INNER JOIN $default->owl_folders_table AS F ON F.document_type_id = DTFL.document_type_id " . | ||
| 64 | - "INNER JOIN $default->owl_documents_table AS D ON D.folder_id = F.id " . | ||
| 65 | - "INNER JOIN $default->owl_document_types_table AS DTL ON DTL.id = DTFL.document_type_id " . | ||
| 66 | - "INNER JOIN $default->owl_fields_table AS DF ON DTFL.field_id = DF.id " . | ||
| 67 | - "LEFT OUTER JOIN $default->owl_document_fields_table AS DFL ON DFL.document_field_id = DF.id " . | ||
| 68 | - "WHERE D.id = " . $oDocument->getID() . " " . | ||
| 69 | - "AND DF.is_generic = 0 "; | ||
| 70 | - | ||
| 71 | - $aStoreColumnNames = array("document_id", "document_field_id", "value"); | ||
| 72 | - $aDisplayColumnNames = array("document_id", "field_name", "value"); | ||
| 73 | - $aColumnsEditable = array(0,0,1); | ||
| 74 | - $aColumnsVisible = array(0,1,1); | ||
| 75 | - $aColumnDisplayTypes = array(1,1,1); | ||
| 76 | - $aColumnDatabaseTypes = array(0,0,1); | ||
| 77 | 65 | ||
| 78 | - $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes); | ||
| 79 | - $oPatternTableSqlQuery->setTableCaption("Type specific meta data"); | ||
| 80 | - $oPatternTableSqlQuery->setUniqueName("tsmd"); | ||
| 81 | - return $oPatternTableSqlQuery->render(); | ||
| 82 | -} | ||
| 83 | 66 | ||
| 84 | -function renderPage($oDocument) { | 67 | +function renderPage($oDocument, $iDocumentTypeID) { |
| 85 | global $default; | 68 | global $default; |
| 86 | $sToRender = "<table border = 0>\n"; | 69 | $sToRender = "<table border = 0>\n"; |
| 87 | $sToRender .= "<tr>\n"; | 70 | $sToRender .= "<tr>\n"; |
| 88 | $sToRender .= "<td>\n"; | 71 | $sToRender .= "<td>\n"; |
| 89 | - $sToRender .= wrapInTable(renderEditableDocumentData($oDocument)) . "\n"; | ||
| 90 | - $sToRender .= "</tr>\n"; | ||
| 91 | - $sToRender .= "<tr>\n"; | ||
| 92 | - $sToRender .= "<td>\n"; | ||
| 93 | - $sToRender .= wrapInTable(renderEditableGenericMetaData($oDocument)) . "\n"; | ||
| 94 | - $sToRender .= "</td>\n"; | ||
| 95 | - $sToRender .= "</tr>\n"; | ||
| 96 | - $sToRender .= "<tr>\n"; | ||
| 97 | - $sToRender .= "<td>\n"; | ||
| 98 | - $sToRender .= wrapInTable(renderEditableTypeSpecificMetaData($oDocument)) . "\n"; | ||
| 99 | - $sToRender .= "</td>\n"; | ||
| 100 | - $sToRender .= "</tr>\n"; | 72 | + $sToRender .= wrapInTable(renderEditableDocumentData($oDocument, $iDocumentTypeID)) . "\n"; |
| 73 | + $sToRender .= "</tr>\n"; | ||
| 101 | $sToRender .= "</table>\n"; | 74 | $sToRender .= "</table>\n"; |
| 102 | $sToRender .= "<table>\n"; | 75 | $sToRender .= "<table>\n"; |
| 103 | $sToRender .= "<tr>\n"; | 76 | $sToRender .= "<tr>\n"; |
| @@ -106,13 +79,21 @@ function renderPage($oDocument) { | @@ -106,13 +79,21 @@ function renderPage($oDocument) { | ||
| 106 | $sToRender .= "</tr>\n"; | 79 | $sToRender .= "</tr>\n"; |
| 107 | $sToRender .= "</table>\n"; | 80 | $sToRender .= "</table>\n"; |
| 108 | 81 | ||
| 109 | - return $sToRender; | 82 | + return $sToRender . getValidationJavaScript(); |
| 110 | } | 83 | } |
| 111 | 84 | ||
| 112 | -function wrapInTable($sHtml) { | ||
| 113 | - return "\n\t\t\t<table border = 1, width = 100%><tr><td>$sHtml</td></tr></table>\n"; | 85 | +function getValidationJavaScript() { |
| 86 | + $sToRender .= "\n\n<script language=\"javascript\">\n<!--\n"; | ||
| 87 | + $sToRender .= "function validateForm(theForm) {\n"; | ||
| 88 | + $sToRender .= "\tif (!(validRequired(document.MainForm.fDocumentName, 'Document Title'))) {\n"; | ||
| 89 | + $sToRender .= "\t\treturn false;\n"; | ||
| 90 | + $sToRender .= "\t}\n"; | ||
| 91 | + $sToRender .= "return true;\n}\n"; | ||
| 92 | + $sToRender .= "//-->\n</script>\n\n"; | ||
| 93 | + | ||
| 94 | + return $sToRender; | ||
| 114 | } | 95 | } |
| 115 | 96 | ||
| 116 | - | ||
| 117 | - | ||
| 118 | -?> | 97 | +function wrapInTable($sHtml) { |
| 98 | + return "\n\t\t\t<table border = 1, width = 100%><tr><td>$sHtml</td></tr></table>\n"; | ||
| 99 | +}?> |