diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php index 52900b8..b1b799e 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentBL.php @@ -15,6 +15,8 @@ require_once("../../../../config/dmsDefaults.php"); if (checkSession()) { require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMetaData.inc"); + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternEditableTableSqlQuery.inc"); require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); @@ -27,20 +29,22 @@ if (checkSession()) { require_once("$default->fileSystemRoot/presentation/Html.inc"); require_once("$default->fileSystemRoot/lib/subscriptions/SubscriptionEngine.inc"); require_once("addDocumentUI.inc"); + require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/store.inc"); + $default->log->info("before:" . arrayToString($_REQUEST)); if (isset($fFolderID)) { if (Permission::userHasFolderWritePermission($fFolderID)) { //user has permission to add document to this folder - if (isset($fForStore)) { - //user wants to store a document - - // check that the folder has a default document type - if (Folder::getDefaultFolderDocumentType($fFolderID)) { + if (isset($fStore)) { + // check that a document type has been selected + if ($fDocumentTypeID) { //make sure the user actually selected a file first if (strlen($_FILES['fFile']['name']) > 0) { //if the user selected a file to upload //create the document in the database $oDocument = & PhysicalDocumentManager::createDocumentFromUploadedFile($_FILES['fFile'], $fFolderID); + // set the document title + $oDocument->setName($fName); if (!(Document::documentExists($oDocument->getFileName(), $oDocument->getFolderID()))) { if ($oDocument->create()) { //if the document was successfully created in the db, then store it on the file system @@ -82,6 +86,14 @@ if (checkSession()) { } } + // now handle meta data, pass new document id to queries + $aQueries = constructQuery(array_keys($_POST), array("document_id" =>$oDocument->getID())); + for ($i=0; $ilog->info("addDocumentBL.php metaDataQuery=" . $aQueries[$i]); + $sql = $default->db; + $sql->query($aQueries[$i]); + } + // fire subscription alerts for the new document $count = SubscriptionEngine::fireSubscription($fFolderID, SubscriptionConstants::subscriptionAlertType("AddDocument"), SubscriptionConstants::subscriptionType("FolderSubscription"), @@ -89,76 +101,64 @@ if (checkSession()) { "folderName" => Folder::getFolderName($fFolderID))); $default->log->info("addDocumentBL.php fired $count subscription alerts for new document " . $oDocument->getName()); - // TODO: further meta-data processing - //redirect to the document view page - redirect("$default->rootUrl/control.php?action=modifyDocument&fDocumentID=" . $oDocument->getID(). "&fFirstEdit=1"); + //redirect to the document details page + controllerRedirect("viewDocument", "fDocumentID=" . $oDocument->getID()); } else { // couldn't store document in db + $default->log->error("addDocumentBL.php Filesystem error attempting to store document " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . "; id=$fFolderID"); require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + // delete the document from the database $oDocument->delete(); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getBrowseAddPage($fFolderID, $fDependantDocumentID)); + $oPatternCustom->setHtml(getStatusPage($fFolderID, "An error occured while storing the document on the file system, please try again.rootUrl/control.php?action=browse&fFolderID=$fFolderID\">graphicsUrl/widgets/cancel.gif\" border=\"0\">")); $main->setCentralPayload($oPatternCustom); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1" . (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "")); - $main->setFormEncType("multipart/form-data"); - $main->setErrorMessage("An error occured while storing the document on the file system"); - $default->log->error("addDocumentBL.php Filesystem error attempting to store document " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . "; id=$fFolderID"); $main->render(); } } else { // couldn't store document on fs + $default->log->error("addDocumentBL.php DB error storing document in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getBrowseAddPage($fFolderID, $fDependantDocumentID)); + $oPatternCustom->setHtml(getStatusPage($fFolderID, "An error occured while storing the document in the database, please try again.rootUrl/control.php?action=browse&fFolderID=$fFolderID\">graphicsUrl/widgets/cancel.gif\" border=\"0\">")); $main->setCentralPayload($oPatternCustom); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1" . (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "")); - $main->setFormEncType("multipart/form-data"); - $main->setErrorMessage("An error occured while storing the document in the database"); - $default->log->error("addDocumentBL.php DB error storing document in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); $main->render(); } } else { // document already exists in folder + $default->log->error("addDocumentBL.php Document exists with name " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getBrowseAddPage($fFolderID, $fDependantDocumentID)); + $oPatternCustom->setHtml(getStatusPage($fFolderID, "A document with this file name already exists in this folderrootUrl/control.php?action=browse&fFolderID=$fFolderID\">graphicsUrl/widgets/cancel.gif\" border=\"0\">")); $main->setCentralPayload($oPatternCustom); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1" . (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "")); - $main->setFormEncType("multipart/form-data"); - $main->setErrorMessage("A document with this file name already exists in this folder"); - $default->log->error("addDocumentBL.php Document exists with name " . $oDocument->getFileName() . " in folder " . Folder::getFolderPath($fFolderID) . " id=$fFolderID"); $main->render(); } } else { + // no uploaded file require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getBrowseAddPage($fFolderID, $fDependantDocumentID)); + $oPatternCustom->setHtml(getStatusPage($fFolderID, "You did not select a valid document to uploadrootUrl/control.php?action=browse&fFolderID=$fFolderID\">graphicsUrl/widgets/cancel.gif\" border=\"0\">")); $main->setCentralPayload($oPatternCustom); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1" . (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "")); - $main->setFormEncType("multipart/form-data"); - $main->setErrorMessage("Please select a document by first clicking on 'Browse'. Then click 'Add'"); $main->render(); } } else { - // the folder doesn't have a default document type + // no document type was selected require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getBrowsePage($fFolderID, $fDependantDocumentID)); + $oPatternCustom->setHtml(getStatusPage($fFolderID, "A valid document type was not selected.rootUrl/control.php?action=browse&fFolderID=$fFolderID\">graphicsUrl/widgets/cancel.gif\" border=\"0\">")); $main->setCentralPayload($oPatternCustom); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1"); - $main->setFormEncType("multipart/form-data"); - $main->setErrorMessage("The folder you're attempting to add the document to doesn't have a default document type.
Please correct this and try again.rootUrl/control.php?action=browse&fFolderID=$fFolderID\">graphicsUrl/widgets/cancel.gif\" border=\"0\">"); $main->render(); } - } else { //we're still just browsing require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getBrowseAddPage($fFolderID, $fDependantDocumentID)); + $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentTypeID, $fDependantDocumentID)); $main->setCentralPayload($oPatternCustom); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID&fForStore=1" . (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "")); + $main->setFormAction($_SERVER["PHP_SELF"] . "?fFolderID=$fFolderID" . + (isset($fDependantDocumentID) ? "&fDependantDocumentID=$fDependantDocumentID" : "") . + (isset($fDocumentTypeID) ? "&fDocumentTypeID=$fDocumentTypeID" : "")); $main->setFormEncType("multipart/form-data"); + $main->setHasRequiredFields(true); $main->render(); } } else { @@ -166,9 +166,8 @@ if (checkSession()) { //so don't display add button require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getBrowsePage($fFolderID, $fDependantDocumentID)); + $oPatternCustom->setHtml(getStatusPage($fFolderID, "You do not have permission to add a document to this folderrootUrl/control.php?action=browse&fFolderID=$fFolderID\">graphicsUrl/widgets/cancel.gif\" border=\"0\">")); $main->setCentralPayload($oPatternCustom); - $main->setErrorMessage("You do not have permission to add a document to this folderrootUrl/control.php?action=browse&fFolderID=$fFolderID\">graphicsUrl/widgets/cancel.gif\" border=\"0\">"); $main->render(); } } else { @@ -176,11 +175,9 @@ if (checkSession()) { //so display an error message require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml("

No folder to which a document can be added is currently selected

\n"); + $oPatternCustom->setHtml("

You haven't selected a folder to add a document to.

\n"); $main->setCentralPayload($oPatternCustom); $main->render(); } } - - -?> +?> \ No newline at end of file diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc index 19df785..3f12a7a 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/addDocumentUI.inc @@ -8,75 +8,156 @@ * */ -function getDocumentListForFolder($fFolderID) { +function getDocumentType($iFolderID, $iDocumentTypeID) { global $default; - $sQuery = "SELECT D.id AS id, D.folder_id AS folder_id, CONCAT(' ', D.name) AS name, COALESCE(CONCAT('$default->graphicsUrl/', MT.icon_path), '$default->graphicsUrl/unknown.gif') AS image_url " . - "FROM $default->owl_documents_table AS D " . - "INNER JOIN $default->owl_status_table AS SL on D.status_id=SL.id " . - "LEFT OUTER JOIN $default->owl_mime_table AS MT ON D.mime_id = MT.id " . - "WHERE folder_id = $fFolderID " . - "AND SL.name = 'Live' " . - "ORDER BY name ASC"; - $aColumns = array("name"); - $aColumnTypes = array(1); - $aColumnHeaderNames = ("Name"); - $aDBColumns = array("id"); - $aQueryStringVariableNames = array("fDocumentID"); - $oPatternTableSqlQuery = & new PatternTableSqlQuery($sQuery, $aColumns, $aColumnTypes, $aColumnHeaderNames, "100%", "$default->rootUrl/control.php?action=viewDocument", $aDBColumns, $aQueryStringVariableNames); - $oPatternTableSqlQuery->setEmptyTableMessage("This folder contains no documents"); - $oPatternTableSqlQuery->setUseImageURLFromQuery(true); - return $oPatternTableSqlQuery->render(); + $sWhereClause = "FDL.folder_id = $iFolderID"; + $oPatternListBox = & new PatternListBox("$default->owl_document_types_table", "name", "id", "fDocumentTypeID",$sWhereClause); + $oPatternListBox->setIncludeDefaultValue(true); + $oPatternListBox->setFromClause("INNER JOIN $default->owl_folder_doctypes_table AS FDL ON ST.id = FDL.document_type_id"); + $oPatternListBox->setPostBackOnChange(true); + $oPatternListBox->setOnChangeAction("setActionAndSubmit('" . $_SERVER["PHP_SELF"] . "?fFolderID=$iFolderID')"); + if ($iDocumentTypeID) { + $oPatternListBox->setSelectedValue($iDocumentTypeID); + $sHeading = "Document Type"; + } else { + $sHeading = "Please select the document type:"; + } + + return "
$sHeading
" . $oPatternListBox->render() . "
"; } - -function getBrowsePage($fFolderID, $iDependantDocumentID) { - $sToRender = "\n"; - $sToRender .= "\n"; - $sToRender .= "\t\n"; - $sToRender .= "\n"; - $sToRender .= "
" . renderFolderPath($fFolderID, "/control.php?action=addDocument") . "
\n"; +/** + * Displays the file browse widget + */ +function getUploadDocument() { + global $default; $sToRender .= "\n"; $sToRender .= "\n"; - $sToRender .= "\t\n"; - $sToRender .= "\n"; - if (Permission::userHasFolderReadPermission($fFolderID)) { - $sToRender .= "\n"; - } - $sToRender .= ""; - $sToRender .= "
" . renderFolderList($fFolderID, "/control.php?action=addDocument" .(isset($fDependantDocumentID) ? "&fDependantDocumentID=$iDependantDocumentID" : "")) . "\n"; - $sToRender .= "
" . getDocumentListForFolder($fFolderID) . "

\n"; + $sToRender .= "Document to add:\n"; + $sToRender .= "\n"; + $sToRender .= "File\n"; + $sToRender .= "Title\n"; + $sToRender .= "\n"; return $sToRender; +} + +/** + * Displays the generic meta data fields form + */ +function getGenericMetaDataForm() { + global $default; + $sQuery = "SELECT DISTINCT -1 AS document_id, DF.id AS document_field_id, DF.name AS field_name, -1 AS id " . + "FROM document_fields AS DF LEFT OUTER JOIN document_fields_link AS DFL ON DF.id = DFL.document_field_id " . + "WHERE DF.is_generic = 1 "; + + $aStoreColumnNames = array("document_id", "document_field_id", "value"); + $aDisplayColumnNames = array("document_id", "field_name", "value"); + $aMetaDataColumnNames = array(2=>"field_name"); + $aColumnsEditable = array(0,0,1); + $aColumnsVisible = array(0,1,1); + $aColumnDisplayTypes = array(1,1,4); + $aColumnDatabaseTypes = array(4,0,1); + + $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes); + $oPatternTableSqlQuery->setTableCaption("Generic Meta Data"); + $oPatternTableSqlQuery->setUniqueName("gmd"); + $oPatternTableSqlQuery->setRequiredColumnNames(array("value")); + $oPatternTableSqlQuery->setMetaDataFields($aMetaDataColumnNames); + $oPatternTableSqlQuery->setEmptyTableMessage("No Generic Meta Data"); + $oPatternTableSqlQuery->setRenderJavascriptValidation(false); + return $oPatternTableSqlQuery; +} + +/** + * Displays the type specific meta data fields form + */ +function getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID) { + global $default; + $sQuery = "SELECT DISTINCT -1 AS document_id, DF.id AS document_field_id, DF.name AS field_name, DTFL.is_mandatory AS is_mandatory, -1 AS id " . + "FROM document_type_fields_link AS DTFL INNER JOIN document_fields AS DF ON DTFL.field_id = DF.id " . + "LEFT OUTER JOIN document_fields_link AS DFL ON DFL.document_field_id = DTFL.field_id " . + "WHERE DF.is_generic = 0 " . + "AND DTFL.document_type_id = $iDocumentTypeID"; + + $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,4); + $aColumnDatabaseTypes = array(4,0,1); + $aMetaDataColumnNames = array(2=>"field_name"); + + $oPatternTableSqlQuery = & new PatternEditableTableSqlQuery($sQuery, "document_fields_link", $aStoreColumnNames, $aDisplayColumnNames, $aColumnsEditable, $aColumnsVisible, $aColumnDisplayTypes, $aColumnDatabaseTypes); + $oPatternTableSqlQuery->setTableCaption("Type specific meta data"); + $oPatternTableSqlQuery->setEmptyTableMessage("No Type Specific Meta Data"); + $oPatternTableSqlQuery->setUniqueName("tsmd"); + $oPatternTableSqlQuery->setMetaDataFields($aMetaDataColumnNames); + $oPatternTableSqlQuery->setRenderJavascriptValidation(false); + return $oPatternTableSqlQuery; } +function getMetaDataForm($iFolderID, $iDocumentTypeID) { + $oGenericPattern = getGenericMetaDataForm(); + $oTypeSpecificPattern = getTypeSpecificMetaDataForm($iFolderID, $iDocumentTypeID); + $sToRender .= "\n"; + $sToRender .= "\n"; + $sToRender .= ""; + $sToRender .= "
Document Meta Data
" . $oGenericPattern->render() . "" . $oTypeSpecificPattern->render() . "
"; + + // validation starts + $sToRender .= "\n\n\n\n"; -function getBrowseAddPage($fFolderID, $iDependantDocumentID = null) { + return $sToRender; +} +function getPage($iFolderID, $iDocumentTypeID, $iDependantDocumentID = null) { global $default; - $sToRender = "\n"; + $sToRender .= renderHeading("Add Document"); + $sToRender .= renderFolderPath($iFolderID, "", false); + + if ($iDocumentTypeID) { + $sToRender .= "
Document Type
" . lookupName($default->owl_document_types_table, $iDocumentTypeID) . "
"; + $sToRender .= getUploadDocument(); + $sToRender .= getMetaDataForm($iFolderID, $iDocumentTypeID); + $sActionButtons = "graphicsUrl/widgets/add.gif\" border=\"0\"/>"; + $sToRender .= ""; + $sActionButtons .= generateControllerLink("addDocument", "fFolderID=$iFolderID", "graphicsUrl/widgets/back.gif\" border=\"0\"/>") . + generateControllerLink("browse", "fFolderID=$iFolderID", "graphicsUrl/widgets/cancel.gif\" border=\"0\"/>"); + } else { + $sToRender .= getDocumentType($iFolderID, $iDocumentTypeID); + $sActionButtons .= generateControllerLink("browse", "fFolderID=$iFolderID", "graphicsUrl/widgets/cancel.gif\" border=\"0\"/>"); + } + + $sToRender .= "\n"; + $sToRender .= ""; + $sToRender .= "
$sActionButtons
"; + + return $sToRender; +} + +function getStatusPage($iFolderID, $sMessage) { + $sToRender .= renderHeading("Add Document"); + $sToRender .= renderFolderPath($iFolderID, "", false); + + $sToRender .= "\n"; $sToRender .= "\n"; - $sToRender .= "\t\n"; + $sToRender .= "\t\n"; $sToRender .= "\n"; $sToRender .= "
" . renderFolderPath($fFolderID, "/control.php?action=addDocument") . "$sMessage
\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "
Document to add:
graphicsUrl/widgets/add.gif\" border=\"0\" value=\"Add\">rootUrl/control.php?action=browse&fFolderID=$fFolderID\">graphicsUrl/widgets/cancel.gif\" border=\"0\">
\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\t\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= ""; - $sToRender .= "
" . renderFolderList($fFolderID, "/control.php?action=addDocument" . (isset($iDependantDocumentID) ? "&fDependantDocumentID=$iDependantDocumentID" : "")) . "\n"; - $sToRender .= "
" . getDocumentListForFolder($fFolderID) . "

\n"; - return $sToRender; } -?> +?> \ No newline at end of file