diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyBL.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyBL.php
index 4220bd8..bafedbb 100644
--- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyBL.php
+++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyBL.php
@@ -16,24 +16,64 @@ if (checkSession()) {
require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
+ require_once("$default->fileSystemRoot/lib/visualpatterns/PatternListBox.inc");
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc");
require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableListFromQuery.inc");
require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyUI.inc");
- require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
- require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
+ require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
require_once("$default->fileSystemRoot/presentation/Html.inc");
- $aDocumentDataArray;
- settype($aDocumentDataArray, "array");
-
- $oDocument = & Document::get($fDocumentID);
- $oPatternCustom = & new PatternCustom();
- $oPatternCustom->setHtml(renderPage($oDocument));
- $main->setCentralPayload($oPatternCustom);
- $main->setHasRequiredFields(true);
- $main->setFormAction("../store.php?fReturnURL=" . urlencode("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID() . "&fFireSubscription=1"));
- $main->setHasRequiredFields(true);
- $main->render();
+ if (Permission::userHasDocumentWritePermission($fDocumentID)) {
+ //if the user has write permission
+ $oDocument = & Document::get($fDocumentID);
+ if (isset($fForUpdate)) {
+ //if the user is updating the values
+ $oDocument->setName($fDocumentName);
+
+ if ($oDocument->getDocumentTypeID() != $fDocumentTypeID) {
+ //the user has changed the document type
+ //get rid of all the old document type entries
+ $oDocument->removeInvalidDocumentTypeEntries();
+ $oDocument->setDocumentTypeID($fDocumentTypeID);
+ }
+
+ if ($oDocument->update()) {
+ //on successful update, redirect to the view page
+ redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID());
+ } else {
+ //display the update page with an error message
+ require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
+ $oPatternCustom = & new PatternCustom();
+ $oPatternCustom->setHtml(renderPage($oDocument, $oDocument->getDocumentTypeID()));
+ $main->setCentralPayload($oPatternCustom);
+ $main->setHasRequiredFields(true);
+ $main->setFormAction($_SERVER["PHP_SELF"] . "?fForUpdate=1");
+ $main->setHasRequiredFields(true);
+ $main->setErrorMessage("An error occured while attempting to update the document");
+ $main->render();
+ }
+
+ } else {
+ //display the update page
+ $oDocument = & Document::get($fDocumentID);
+ $oPatternCustom = & new PatternCustom();
+ require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
+ $oPatternCustom->setHtml(renderPage($oDocument, $oDocument->getDocumentTypeID()));
+ $main->setCentralPayload($oPatternCustom);
+ $main->setHasRequiredFields(true);
+ $main->setFormAction($_SERVER["PHP_SELF"] . "?fForUpdate=1");
+ $main->setHasRequiredFields(true);
+ $main->render();
+ }
+ } else {
+ //user doesn't have permission to edit this page
+ require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
+ $oPatternCustom = & new PatternCustom();
+ $oPatternCustom->setHtml("");
+ $main->setCentralPayload($oPatternCustom);
+ $main->setErrorMessage("You do not have permission to edit this document");
+ $main->render();
+ }
}
?>
diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyUI.inc b/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyUI.inc
index 89d31d6..33b4eac 100644
--- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyUI.inc
+++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/modifyUI.inc
@@ -14,90 +14,63 @@ function renderDocumentPath($oDocument) {
return "
\n";
}
-function renderEditableDocumentData($oDocument) {
+function renderEditableDocumentData($oDocument, $iDocumentTypeID) {
global $default;
- $sQuery = "SELECT D.id AS id, D.name AS name " .
+ $sQuery = "SELECT D.id AS id, D.name AS name, D.document_type_id AS document_type_id " .
"FROM $default->owl_documents_table AS D " .
"WHERE D.id = " . $oDocument->getID();
-
- $aDisplayColumns = array("name");
- $aStoreColumns = array("name");
- $aColumnNames = array("Document Title");
- $aDisplayColumnTypes = array(1);
- $aDatabaseColumnTypes = array(1);
-
- $oPatternEditableListFromQuery = & new PatternEditableListFromQuery($sQuery, $default->owl_documents_table, $aDisplayColumns, $aStoreColumns, $aColumnNames, $aDisplayColumnTypes, $aDatabaseColumnTypes);
- $oPatternEditableListFromQuery->setUniqueName("dd");
- $oPatternEditableListFromQuery->setTableHeading("Document Data");
- $oPatternEditableListFromQuery->setColumnsRequired(array(1));
- return $oPatternEditableListFromQuery->render();
+
+ $sql = $default->db;
+ $sql->query($sQuery);
+ $sToRender;
+ if ($sql->next_record()) {
+ $sToRender = "\n";
+
+ return $sToRender;
+ }
+ return "";
}
-function renderEditableGenericMetaData($oDocument) {
- global $default;
- $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 " .
- "FROM $default->owl_fields_table AS DF LEFT OUTER JOIN $default->owl_document_fields_table AS DFL ON DFL.document_field_id = DF.id " .
- "RIGHT OUTER JOIN documents AS D ON D.id = DFL.document_id " .
- "WHERE DF.is_generic = 1 " .
- "AND D.id = " . $oDocument->getID();
-
- $aStoreColumnNames = array("document_id", "document_field_id","value");
- $aDisplayColumnNames = array("document_id", "name", "value");
- $aColumnsEditable = array(0,0,1);
- $aColumnsVisible = array(0,1,1);
- $aColumnDisplayTypes = array(1,1,1);
- $aColumnDatabaseTypes = array(0,0,1);
-
-
- $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes);
- $oPatternTableSqlQuery->setRequiredColumnNames(array("value"));
- $oPatternTableSqlQuery->setTableCaption("Generic Meta Data");
- $oPatternTableSqlQuery->setUniqueName("gmd");
- return $oPatternTableSqlQuery->render();
-
+function getDocumentType($iFolderID, $iDocumentTypeID) {
+ global $default;
+ $sWhereClause = "FDL.folder_id = $iFolderID";
+ $oPatternListBox = & new PatternListBox("$default->owl_document_types_table", "name", "id", "fDocumentTypeID",$sWhereClause);
+ $oPatternListBox->setIncludeDefaultValue(false);
+ $oPatternListBox->setFromClause("INNER JOIN $default->owl_folder_doctypes_table AS FDL ON ST.id = FDL.document_type_id");
+ //$oPatternListBox->setPostBackOnChange(true);
+ if (isset($iDocumentTypeID)) {
+ $oPatternListBox->setSelectedValue($iDocumentTypeID);
+ }
+ //$oPatternListBox->setOnChangeAction("setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "&fDocumentID=$iDocumentID')");
+ return $oPatternListBox->render();
}
-function renderEditableTypeSpecificMetaData($oDocument) {
- global $default;
- $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 " .
- "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 " .
- "INNER JOIN $default->owl_documents_table AS D ON D.folder_id = F.id " .
- "INNER JOIN $default->owl_document_types_table AS DTL ON DTL.id = DTFL.document_type_id " .
- "INNER JOIN $default->owl_fields_table AS DF ON DTFL.field_id = DF.id " .
- "LEFT OUTER JOIN $default->owl_document_fields_table AS DFL ON DFL.document_field_id = DF.id " .
- "WHERE D.id = " . $oDocument->getID() . " " .
- "AND DF.is_generic = 0 ";
-
- $aStoreColumnNames = array("document_id", "document_field_id", "value");
- $aDisplayColumnNames = array("document_id", "field_name", "value");
- $aColumnsEditable = array(0,0,1);
- $aColumnsVisible = array(0,1,1);
- $aColumnDisplayTypes = array(1,1,1);
- $aColumnDatabaseTypes = array(0,0,1);
- $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes);
- $oPatternTableSqlQuery->setTableCaption("Type specific meta data");
- $oPatternTableSqlQuery->setUniqueName("tsmd");
- return $oPatternTableSqlQuery->render();
-}
-function renderPage($oDocument) {
+function renderPage($oDocument, $iDocumentTypeID) {
global $default;
$sToRender = "\n";
$sToRender .= "\n";
$sToRender .= "| \n";
- $sToRender .= wrapInTable(renderEditableDocumentData($oDocument)) . "\n";
- $sToRender .= " |
\n";
- $sToRender .= "\n";
- $sToRender .= "| \n";
- $sToRender .= wrapInTable(renderEditableGenericMetaData($oDocument)) . "\n";
- $sToRender .= " | \n";
- $sToRender .= "
\n";
- $sToRender .= "\n";
- $sToRender .= "| \n";
- $sToRender .= wrapInTable(renderEditableTypeSpecificMetaData($oDocument)) . "\n";
- $sToRender .= " | \n";
- $sToRender .= "
\n";
+ $sToRender .= wrapInTable(renderEditableDocumentData($oDocument, $iDocumentTypeID)) . "\n";
+ $sToRender .= "\n";
$sToRender .= "
\n";
$sToRender .= "\n";
$sToRender .= "\n";
@@ -106,13 +79,21 @@ function renderPage($oDocument) {
$sToRender .= "
\n";
$sToRender .= "
\n";
- return $sToRender;
+ return $sToRender . getValidationJavaScript();
}
-function wrapInTable($sHtml) {
- return "\n\t\t\t\n";
+function getValidationJavaScript() {
+ $sToRender .= "\n\n\n\n";
+
+ return $sToRender;
}
-
-
-?>
+function wrapInTable($sHtml) {
+ return "\n\t\t\t\n";
+}?>