diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/addArchiveSettingsBL.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/addArchiveSettingsBL.php index 706f6c6..cd5e541 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/addArchiveSettingsBL.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/addArchiveSettingsBL.php @@ -3,10 +3,7 @@ require_once("../../../../../config/dmsDefaults.php"); require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); -require_once("$default->fileSystemRoot/lib/archiving/DocumentArchiving.inc"); -require_once("$default->fileSystemRoot/lib/archiving/ArchivingUtilisationSettings.inc"); -require_once("$default->fileSystemRoot/lib/archiving/ArchivingDateSettings.inc"); -require_once("$default->fileSystemRoot/lib/archiving/TimePeriod.inc"); +require_once("$default->fileSystemRoot/lib/archiving/DocumentArchiveSettingsFactory.inc"); require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc"); require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); @@ -27,70 +24,16 @@ require_once("$default->uiDirectory/documentmanagement/archiving/archiveSettings * @package presentation.lookAndFeel.knowledgeTree.documentmanagement */ -class DocumentArchiveSettingsFactory { - function create($iDocumentID, $iArchivingTypeID, $dExpirationDate, $iDocumentTransactionID, $iTimeUnitID, $iUnits) { - global $default; - $sArchivingType = lookupName($default->owl_archiving_type_lookup_table, $iArchivingTypeID); - - // search for an existing time period id - $aTimePeriod = TimePeriod::getList("time_unit_id=$iTimeUnitID AND units=$iUnits"); - if (count($aTimePeriod) > 0) { - $iTimePeriodID = $aTimePeriod[0]->getID(); - } else { - // create it - $oTimePeriod = new TimePeriod($iTimeUnitID, $iUnits); - if ($oTimePeriod->create()) { - $iTimePeriodID = $oTimePeriod->getID(); - } else { - $default->log->error("couldn't create time period- " . arrayToString($oTimePeriod)); - return false; - } - } - - // construction strings - switch ($sArchivingType) { - case "Date" : $sSearchConstruction = "\$aArchiveSettings = ArchivingDateSettings::getList(\"expiration_date='$dExpirationDate' AND time_period_id=$iTimePeriodID\");"; - $sConstruction = "\$oArchiveSettings = new ArchivingDateSettings($dExpirationDate, $iTimePeriodID);"; - break; - case "Utilisation" : $sSearchConstruction = "\$aArchiveSettings = ArchivingUtilisationSettings::getList(\"document_transaction_id=$iDocumentTransactionID AND time_period_id=$iTimePeriodID\");"; - $sConstruction = "\$oArchiveSettings = new ArchivingUtilisationSettings($iDocumentTransactionID, $iTimePeriodID);"; - break; - } - - // search for the settings first - eval($sSearchConstruction); - if (count($aArchiveSettings) > 0) { - $iArchiveSettingsID = $aArchiveSettings[0]->getID(); - } else { - // create them - eval($sConstruction); - if ($oArchiveSettings->create()) { - $iArchiveSettingsID = $oArchiveSettings->getID(); - } else { - $default->log->error("couldn't create archive settings- " . arrayToString($oArchiveSettings)); - return false; - } - - // now link to the documents - $oDocumentArchiving = new DocumentArchiving($iDocumentID, $iArchivingTypeID, $iArchiveSettingsID); - if ($oDocumentArchiving->create()) { - return true; - } else { - $default->log->error("couldn't create document archiving - " . arrayToString($oDocumentArchiving)); - return false; - } - } - } -} - if (checkSession()) { global $default; // instantiate my content pattern $oContent = new PatternCustom(); - $default->log->info(arrayToString($_REQUEST)); + if ($fStore) { - if (DocumentArchiveSettingsFactory::create($fDocumentID, $fArchivingTypeID, $fExpirationDate, $fDocumentTransactionID, $fTimeUnitID, $fUnits)) { + $oDASFactory = new DocumentArchiveSettingsFactory($fArchivingTypeID); + + if ($oDASFactory->create($fDocumentID, $fExpirationDate, $fDocumentTransactionID, $fTimeUnitID, $fUnits)) { // created, redirect to view page redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID"); } else { @@ -102,10 +45,9 @@ if (checkSession()) { } elseif (isset($fArchivingTypeID)) { // the archiving type has been chosen, so display the correct form - // display the edit/add page $oContent->setHtml(renderAddArchiveSettingsPage($fArchivingTypeID)); } else { - // display the choose archiving type page + // display the select archiving type page $oContent->setHtml(renderAddArchiveSettingsPage(null)); } diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/archiveSettingsUI.inc b/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/archiveSettingsUI.inc index e33d8a9..f64ae41 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/archiveSettingsUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/archiveSettingsUI.inc @@ -40,10 +40,12 @@ function renderErrorMessage($sErrorMessage) { return $sToRender; } - -function renderDocumentTransactionListBox() { +function renderDocumentTransactionListBox($iDocumentTransactionID) { global $default; $oPatternListBox = & new PatternListBox($default->owl_transaction_types_table, "name", "id", "fDocumentTransactionID"); + if (isset($iDocumentTransactionID)) { + $oPatternListBox->setSelectedValue($iDocumentTransactionID); + } return $oPatternListBox->render(); } @@ -55,9 +57,12 @@ function renderArchivingTypeListBox() { return $oPatternListBox->render(); } -function renderTimeUnitsListBox($sVariableName) { +function renderTimeUnitsListBox($iTimeUnitID) { global $default; - $oPatternListBox = & new PatternListBox($default->owl_time_unit_lookup_table, "name", "id", $sVariableName); + $oPatternListBox = & new PatternListBox($default->owl_time_unit_lookup_table, "name", "id", "fTimeUnitID"); + if (isset($iTimeUnitID)) { + $oPatternListBox->setSelectedValue($iTimeUnitID); + } return $oPatternListBox->render(); } @@ -74,99 +79,155 @@ function renderChooseArchivingTypeForm() { return $sToRender; } +function getDateArchivingJavascript() { + $sToRender .= "\n\n\n\n"; + return $sToRender; +} + +function getUtilisationArchivingJavascript() { + $sToRender .= "\n\n\n\n"; + return $sToRender; +} + +function renderTimePeriod($sHeading, $oTimePeriod = null) { + global $default; + if (strlen($sHeading) > 0) { + $sToRender .= "$sHeading:"; + } + $sToRender .= "getUnits() : "") . "\">"; + $sToRender .= "  " . renderTimeUnitsListBox( ($oTimePeriod ? $oTimePeriod->getTimeUnitID() : null) ); + $sToRender .= "  graphicsUrl/widgets/clear.gif\" border=\"0\">"; + return $sToRender; +} + /** * Displays the edit archive settings form * - * @param ArchiveSettings the archive settings to modify + * @param integer the archive settings to modify, null display an add form */ -function renderAddArchiveSettingsForm($iArchivingTypeID) { +function renderArchiveSettingsForm($oDocumentArchiving = null) { global $default, $fDocumentID; + if (is_a($oDocumentArchiving, "DocumentArchiving")) { + $sToRender .= "(in order to change the archiving type for this document, click the 'Remove' button and add new archiving settings)"; + $iArchivingTypeID = $oDocumentArchiving->getArchivingTypeID(); + } else { + $iArchivingTypeID = (integer)$oDocumentArchiving; + unset($oDocumentArchiving); + } $sArchivingType = lookupName($default->owl_archiving_type_lookup_table, $iArchivingTypeID); - - $sToRender = ""; - // TODO: form instructions and calendar control integration - if ($sArchivingType == "Date") { - $sToRender .= ""; - $sToRender .= ""; - $sToRender .= ""; - $sToRender .= ""; - $sToRender .= ""; - $sToRender .= ""; - - $sToRender .= "\n\n\n\n"; - + + $sToRender .= "
Archive By Date
Expiration Date:
graphicsUrl/calendar/calendar.gif\" name=\"imgCalendar\" width=\"34\" height=\"21\" border=\"0\" alt=\"\">
Expiration Period:
" . renderTimeUnitsListBox("fTimeUnitID") . "
"; + // TODO: calendar control integration + switch ($sArchivingType) { + case "Date" : + + if ($oDocumentArchiving) { + // get date settings from document archiving + $oDateArchivingSettings = ArchivingDateSettings::get($oDocumentArchiving->getArchivingSettingsID()); + } + $sToRender .= ""; + $sToRender .= ""; + $sToRender .= ""; + + if ($oDateArchivingSettings) { + $oTimePeriod = TimePeriod::get($oDateArchivingSettings->getTimePeriodID()); + $sToRender .= renderTimePeriod("Expires after", $oTimePeriod); + } else { + $sToRender .= renderTimePeriod("Expires after"); + } + $sToRender .= getDateArchivingJavascript(); + break; + case "Utilisation" : + if ($oDocumentArchiving) { + // get date settings from document archiving + $oUtilisationArchivingSettings = ArchivingUtilisationSettings::get($oDocumentArchiving->getArchivingSettingsID()); + $iDocumentTransactionID = $oUtilisationArchivingSettings->getDocumentTransactionID(); + } + + $sToRender .= ""; + $sToRender .= ""; - } elseif ($sArchivingType == "Utilisation") { - $sToRender .= ""; - $sToRender .= ""; - $sToRender .= ""; - - $sToRender .= "\n\n\n\n"; + if ($oUtilisationArchivingSettings) { + $oTimePeriod = TimePeriod::get($oUtilisationArchivingSettings->getTimePeriodID()); + $sToRender .= renderTimePeriod("Time since last transaction", $oTimePeriod); + } else { + $sToRender .= renderTimePeriod("Time since last transaction"); + } + $sToRender .= getUtilisationArchivingJavascript(); + break; } // hidden archive settings references $sToRender .= "\n"; $sToRender .= "\n"; - $sToRender .= "\n"; - $sToRender .= "\n"; + $sToRender .= "\n"; + if ($oDocumentArchiving) { + $sToRender .= "\n"; $sToRender .= "
Archive By Date
Expiration Date:
getExpirationDate() == "0000-00-00" ? "" : $oDateArchivingSettings->getExpirationDate()) : "") . "\">"; + $sToRender .= "  graphicsUrl/calendar/calendar.gif\" name=\"imgCalendar\" width=\"34\" height=\"21\" border=\"0\" alt=\"\">"; + $sToRender .= "  graphicsUrl/widgets/clear.gif\" border=\"0\">
Archive By Utilisation
Document Transaction:" . + renderDocumentTransactionListBox($iDocumentTransactionID) . + "
Archive By Utilisation
Document Transaction:" . renderDocumentTransactionListBox() . "
Units" . renderTimeUnitsListBox("fTimeUnitID") . "
graphicsUrl/widgets/submit.gif\" border=\"0\">\n"; - $sToRender .= $sJavaScript; - $sToRender .= "rootUrl/control.php?action=addDocumentArchiveSettings&fDocumentID=$fDocumentID\">graphicsUrl/widgets/cancel.gif\" border=\"0\" />
graphicsUrl/widgets/update.gif\" border=\"0\">\n"; + $sToRender .= "rootUrl/control.php?action=modifyDocumentArchiveSettings&fDocumentID=$fDocumentID&fDelete=1\">graphicsUrl/widgets/remove.gif\" border=\"0\" />\n"; + } else { + $sToRender .= "
graphicsUrl/widgets/submit.gif\" border=\"0\">\n"; + } + $sToRender .= "rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID\">graphicsUrl/widgets/cancel.gif\" border=\"0\" />
"; - - return $sToRender; } /** * Displays the edit document archive settings page */ -function renderEditArchiveSettingsPage($oArchiveSettings, $sErrorMessage = "") { +function renderEditArchiveSettingsPage($oDocumentArchiving, $sErrorMessage = "") { global $default; - //$sToRender .= "" . renderHeading("Edit Document Archive Settings") . "
"; $sToRender .= renderHeading("Edit Document Archive Settings"); if (strlen($sErrorMessage) > 0) { $sToRender .= renderErrorMessage($sErrorMessage); } $sToRender .= "\n"; - if ($oArchiveSettings) { - $sToRender .= renderEditArchiveSettingsForm($oArchiveSettings); - } else { - $sToRender .= renderAddArchiveSettingsForm($oArchiveSettings); - } + $sToRender .= renderArchiveSettingsForm($oDocumentArchiving); $sToRender .= "
\n"; return $sToRender; } @@ -183,7 +244,7 @@ function renderAddArchiveSettingsPage($iArchivingTypeID, $sErrorMessage = "") { } $sToRender .= "\n"; if ($iArchivingTypeID) { - $sToRender .= renderAddArchiveSettingsForm($iArchivingTypeID); + $sToRender .= renderArchiveSettingsForm($iArchivingTypeID); } else { $sToRender .= renderChooseArchivingTypeForm(); } diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/modifyArchiveSettingsBL.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/modifyArchiveSettingsBL.php index c8a5d79..6fcd8ef 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/modifyArchiveSettingsBL.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/modifyArchiveSettingsBL.php @@ -2,7 +2,9 @@ require_once("../../../../../config/dmsDefaults.php"); require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); -require_once("$default->fileSystemRoot/lib/documentmanagement/ArchiveSettings.inc"); + +require_once("$default->fileSystemRoot/lib/archiving/DocumentArchiveSettingsFactory.inc"); + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc"); require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); @@ -27,34 +29,38 @@ if (checkSession()) { // instantiate my content pattern $oContent = new PatternCustom(); + $default->log->info(arrayToString($_REQUEST)); if ($fDocumentID) { - $oArchiveSettings = ArchiveSettings::getFromDocumentID($fDocumentID); - if ($fStore) { - // we're updating the settings- check the parameters - if (isset($fExpirationDate) || isset($fExpirationUnits) && isset($fExpirationDatePart)) { - // setting archiving by date - // update the object - if ($fExpirationDate) { - $oArchiveSettings->setExpirationDate($fExpirationDate); - } else if ($fExpirationUnits && $fExpirationDatePart) { - $oArchiveSettings->setExpirationDate(time() + $fExpirationUnits*$oArchiveSettings->aDateUnits[$fExpirationDatePart]); - } - } else if (isset($fDocumentTransactionID) && isset($fUtilisationUnits) && isset($fUtilisationDatePart)) { - // setting by utilisation - - // update the object - $oArchiveSettings->setDocumentTransactionID($fDocumentTransactionID); - $oArchiveSettings->setUtilisationThreshold($fUtilisationUnits*$oArchiveSettings->aDateUnits[$fUtilisationDatePart]); - } else { - // all params not present, so display an error message - $oContent->setHtml(renderEditArchiveSettingsPage($oArchiveSettings, "Please complete the form before submitting.")); - } - } else { - // display the edit page - $oContent->setHtml(renderEditArchiveSettingsPage($oArchiveSettings)); - } + // retrieve the appropriate settings given the document id + $oDocumentArchiving = DocumentArchiving::getFromDocumentID($fDocumentID); + if ($oDocumentArchiving) { + if ($fStore) { + $oDASFactory = new DocumentArchiveSettingsFactory($oDocumentArchiving->getArchivingTypeID()); + + if ($oDASFactory->update($oDocumentArchiving, $fExpirationDate, $fDocumentTransactionID, $fTimeUnitID, $fUnits)) { + $default->log->info("modifyArchiveSettingsBL.php successfully updated archive settings (documentID=$fDocumentID)"); + // created, redirect to view page + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID"); + } else { + $default->log->error("modifyArchiveSettingsBL.php error updating archive settings (documentID=$fDocumentID)"); + } + } elseif ($fDelete) { + if ($oDocumentArchiving->delete()) { + $default->log->info("modifyArchiveSettingsBL.php successfully deleted archive settings (documentID=$fDocumentID)"); + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID"); + } else { + $default->log->error("modifyArchiveSettingsBL.php error deleting archive settings (documentID=$fDocumentID)"); + } + } else { + // display the edit page + $oContent->setHtml(renderEditArchiveSettingsPage($oDocumentArchiving)); + } + } else { + // no archiving settings for this document + $oContent->setHtml(renderEditArchiveSettingsPage(null, "No document has been selected.")); + } } else { - // document id missing + // document id missing $oContent->setHtml(renderEditArchiveSettingsPage(null, "No document has been selected.")); }