Commit 07e3e8e26bf09cf989d43f761d8677caf9c47d54

Authored by Michael Joseph
1 parent bf4366b2

add archive settings completed


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1909 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/addArchiveSettingsBL.php
@@ -2,7 +2,12 @@ @@ -2,7 +2,12 @@
2 2
3 require_once("../../../../../config/dmsDefaults.php"); 3 require_once("../../../../../config/dmsDefaults.php");
4 require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); 4 require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
5 -require_once("$default->fileSystemRoot/lib/documentmanagement/ArchiveSettings.inc"); 5 +
  6 +require_once("$default->fileSystemRoot/lib/archiving/DocumentArchiving.inc");
  7 +require_once("$default->fileSystemRoot/lib/archiving/ArchivingUtilisationSettings.inc");
  8 +require_once("$default->fileSystemRoot/lib/archiving/ArchivingDateSettings.inc");
  9 +require_once("$default->fileSystemRoot/lib/archiving/TimePeriod.inc");
  10 +
6 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc"); 11 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternMainPage.inc");
7 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); 12 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
8 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc"); 13 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternTableSqlQuery.inc");
@@ -22,44 +27,87 @@ require_once("$default->uiDirectory/documentmanagement/archiving/archiveSettings @@ -22,44 +27,87 @@ require_once("$default->uiDirectory/documentmanagement/archiving/archiveSettings
22 * @package presentation.lookAndFeel.knowledgeTree.documentmanagement 27 * @package presentation.lookAndFeel.knowledgeTree.documentmanagement
23 */ 28 */
24 29
  30 +class DocumentArchiveSettingsFactory {
  31 + function create($iDocumentID, $iArchivingTypeID, $dExpirationDate, $iDocumentTransactionID, $iTimeUnitID, $iUnits) {
  32 + global $default;
  33 + $sArchivingType = lookupName($default->owl_archiving_type_lookup_table, $iArchivingTypeID);
  34 +
  35 + // search for an existing time period id
  36 + $aTimePeriod = TimePeriod::getList("time_unit_id=$iTimeUnitID AND units=$iUnits");
  37 + if (count($aTimePeriod) > 0) {
  38 + $iTimePeriodID = $aTimePeriod[0]->getID();
  39 + } else {
  40 + // create it
  41 + $oTimePeriod = new TimePeriod($iTimeUnitID, $iUnits);
  42 + if ($oTimePeriod->create()) {
  43 + $iTimePeriodID = $oTimePeriod->getID();
  44 + } else {
  45 + $default->log->error("couldn't create time period- " . arrayToString($oTimePeriod));
  46 + return false;
  47 + }
  48 + }
  49 +
  50 + // construction strings
  51 + switch ($sArchivingType) {
  52 + case "Date" : $sSearchConstruction = "\$aArchiveSettings = ArchivingDateSettings::getList(\"expiration_date='$dExpirationDate' AND time_period_id=$iTimePeriodID\");";
  53 + $sConstruction = "\$oArchiveSettings = new ArchivingDateSettings($dExpirationDate, $iTimePeriodID);";
  54 + break;
  55 + case "Utilisation" : $sSearchConstruction = "\$aArchiveSettings = ArchivingUtilisationSettings::getList(\"document_transaction_id=$iDocumentTransactionID AND time_period_id=$iTimePeriodID\");";
  56 + $sConstruction = "\$oArchiveSettings = new ArchivingUtilisationSettings($iDocumentTransactionID, $iTimePeriodID);";
  57 + break;
  58 + }
  59 +
  60 + // search for the settings first
  61 + eval($sSearchConstruction);
  62 + if (count($aArchiveSettings) > 0) {
  63 + $iArchiveSettingsID = $aArchiveSettings[0]->getID();
  64 + } else {
  65 + // create them
  66 + eval($sConstruction);
  67 + if ($oArchiveSettings->create()) {
  68 + $iArchiveSettingsID = $oArchiveSettings->getID();
  69 + } else {
  70 + $default->log->error("couldn't create archive settings- " . arrayToString($oArchiveSettings));
  71 + return false;
  72 + }
  73 +
  74 + // now link to the documents
  75 + $oDocumentArchiving = new DocumentArchiving($iDocumentID, $iArchivingTypeID, $iArchiveSettingsID);
  76 + if ($oDocumentArchiving->create()) {
  77 + return true;
  78 + } else {
  79 + $default->log->error("couldn't create document archiving - " . arrayToString($oDocumentArchiving));
  80 + return false;
  81 + }
  82 + }
  83 + }
  84 +}
  85 +
25 if (checkSession()) { 86 if (checkSession()) {
26 global $default; 87 global $default;
27 88
28 // instantiate my content pattern 89 // instantiate my content pattern
29 $oContent = new PatternCustom(); 90 $oContent = new PatternCustom();
30 - $default->log->info(arrayToString($_POST)); 91 + $default->log->info(arrayToString($_REQUEST));
31 if ($fStore) { 92 if ($fStore) {
32 - // setting archiving by date  
33 - if (isset($fExpirationDate) || isset($fExpirationUnits) && isset($fExpirationDatePart)) {  
34 - if ($fExpirationDate) {  
35 - $dExpirationDate = $fExpirationDate;  
36 - } else if ($fExpirationUnits && $fExpirationDatePart) {  
37 - $dExpirationDate = date() + $fExpirationUnits*$fExpirationDatePart;  
38 - }  
39 - $oArchiveSettings = new ArchiveSettings($fDocumentID, $fExpirationDate, 0, 0);  
40 - if ($oArchiveSettings->create()) {  
41 - // created, redirect to view page  
42 - } else {  
43 - $default->log->error("addArchiveSettingsBL.php error adding archive settings:" . arrayToString($oArchiveSettings));  
44 - }  
45 - // setting by utilisation  
46 - } else if (isset($fDocumentTransactionID) && isset($fUtilisationUnits) && isset($fUtilisationDatePart)) {  
47 - $iUtilisationThreshold = $fUtilisationUnits*$oArchiveSettings->aDateUnits[$fUtilisationDatePart];  
48 - $oArchiveSettings = new ArchiveSettings($fDocumentID, "", $iUtilisationThreshold, $fDocumentTransactionID);  
49 - if ($oArchiveSettings->create()) {  
50 - // created, redirect to view page  
51 - redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID");  
52 - } else {  
53 - $default->log->error("addArchiveSettingsBL.php error adding archive settings:" . arrayToString($oArchiveSettings));  
54 - }  
55 - } else {  
56 - // all params not present, so display an error message  
57 - $oContent->setHtml(renderAddArchiveSettingsPage(null, "Please complete the form before submitting."));  
58 - }  
59 - } else { 93 + if (DocumentArchiveSettingsFactory::create($fDocumentID, $fArchivingTypeID, $fExpirationDate, $fDocumentTransactionID, $fTimeUnitID, $fUnits)) {
  94 + // created, redirect to view page
  95 + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID");
  96 + } else {
  97 + // error
  98 + $default->log->error("addArchiveSettingsBL.php error adding archive settings");
  99 + // display form with error
  100 + $oContent->setHtml(renderAddArchiveSettingsPage(null, "The archive settings for this document could not be added"));
  101 + }
  102 +
  103 + } elseif (isset($fArchivingTypeID)) {
  104 + // the archiving type has been chosen, so display the correct form
60 // display the edit/add page 105 // display the edit/add page
61 - $oContent->setHtml(renderEditArchiveSettingsPage(null));  
62 - } 106 + $oContent->setHtml(renderAddArchiveSettingsPage($fArchivingTypeID));
  107 + } else {
  108 + // display the choose archiving type page
  109 + $oContent->setHtml(renderAddArchiveSettingsPage(null));
  110 + }
63 111
64 // build the page 112 // build the page
65 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); 113 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
presentation/lookAndFeel/knowledgeTree/documentmanagement/archiving/archiveSettingsUI.inc
@@ -40,58 +40,113 @@ function renderErrorMessage($sErrorMessage) { @@ -40,58 +40,113 @@ function renderErrorMessage($sErrorMessage) {
40 return $sToRender; 40 return $sToRender;
41 } 41 }
42 42
  43 +
43 function renderDocumentTransactionListBox() { 44 function renderDocumentTransactionListBox() {
44 global $default; 45 global $default;
45 $oPatternListBox = & new PatternListBox($default->owl_transaction_types_table, "name", "id", "fDocumentTransactionID"); 46 $oPatternListBox = & new PatternListBox($default->owl_transaction_types_table, "name", "id", "fDocumentTransactionID");
46 return $oPatternListBox->render(); 47 return $oPatternListBox->render();
47 } 48 }
48 49
  50 +function renderArchivingTypeListBox() {
  51 + global $default, $fArchivingTypeID;
  52 + $oPatternListBox = & new PatternListBox($default->owl_archiving_type_lookup_table, "name", "id", "fArchivingTypeID");
  53 + $oPatternListBox->setPostBackOnChange(true);
  54 + $oPatternListBox->setSelectedValue($fArchivingTypeID);
  55 + return $oPatternListBox->render();
  56 +}
  57 +
  58 +function renderTimeUnitsListBox($sVariableName) {
  59 + global $default;
  60 + $oPatternListBox = & new PatternListBox($default->owl_time_unit_lookup_table, "name", "id", $sVariableName);
  61 + return $oPatternListBox->render();
  62 +}
  63 +
  64 +function renderChooseArchivingTypeForm() {
  65 + global $default, $fDocumentID;
  66 +
  67 + $sToRender = "<table border=\"0\">";
  68 + $sToRender .= "<tr><td colspan=\"2\">Choose the archiving type for this document</td></tr>";
  69 + $sToRender .= "<tr><td>Archiving Type:</td><td>" . renderArchivingTypeListBox() . "</td></tr>";
  70 + // hidden archive settings references
  71 + $sToRender .= "<input type=\"hidden\" name=\"fDocumentID\" value=\"$fDocumentID\">\n";
  72 + $sToRender .= "<tr><td><a href=\"$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\" /></a></td></tr>\n";
  73 + $sToRender .= "</table>";
  74 + return $sToRender;
  75 +}
  76 +
49 /** 77 /**
50 * Displays the edit archive settings form 78 * Displays the edit archive settings form
51 * 79 *
52 * @param ArchiveSettings the archive settings to modify 80 * @param ArchiveSettings the archive settings to modify
53 */ 81 */
54 -function renderAddArchiveSettingsForm($oArchiveSettings) { 82 +function renderAddArchiveSettingsForm($iArchivingTypeID) {
55 global $default, $fDocumentID; 83 global $default, $fDocumentID;
56 - 84 +
  85 + $sArchivingType = lookupName($default->owl_archiving_type_lookup_table, $iArchivingTypeID);
  86 +
57 $sToRender = "<table border=\"0\">"; 87 $sToRender = "<table border=\"0\">";
58 - // TODO: form instructions  
59 - $sToRender .= "<tr><th colspan=\"2\">Archive By Date</th></tr>";  
60 - $sToRender .= "<tr><td>Expiration Date:</td></tr>";  
61 - //$sToRender .= "<tr><td><input type=\"text\" name=\"fExpirationDate\" size=\"11\"></td><td align=\"right\"><a href=\"javascript: void(0);\" onmouseover=\"if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;\" onmouseout=\"if (timeoutDelay) calendarTimeout();window.status='';\" onclick=\"g_Calendar.show(event,'MainForm.fExpirationDate', false, 'yyyy-mm-dd', new Date()); return false;\"><img src=\"$default->graphicsUrl/calendar/calendar.gif\" name=\"imgCalendar\" width=\"34\" height=\"21\" border=\"0\" alt=\"\"></a></td></tr>";  
62 - $sToRender .= "<tr><td><input type=\"text\" name=\"fExpirationDate\" value=\"" . ($oArchiveSettings ? $oArchiveSettings->getExpirationDate() : "2003-06-06") . "\" size=\"11\"></td></tr>";  
63 - $sToRender .= "<tr><td colspan=\"3\">Expiration Period:</td></tr>";  
64 -  
65 - $sToRender .= "<tr><td><input type=\"text\" size=\"11\" name=\"fExpirationUnits\"></td>";  
66 - $sToRender .= "<td><select name=\"fExpirationDatePart\"><option value=\"day\">Days</option><option value=\"month\">Months</option><option value=\"year\">Years</option></select>";  
67 - $sToRender .= "</td></tr>";  
68 -  
69 - $sToRender .= "<tr><th colspan=\"2\">Archive By Utilisation</th></tr>";  
70 - $sToRender .= "<tr><td colspan=\"2\">Utilisation Threshold:</td></tr>";  
71 - $sToRender .= "<tr><td>Document Transaction:</td><td>" . renderDocumentTransactionListBox() . "</td></tr>";  
72 - $sToRender .= "<tr><td><input type=\"text\" size=\"11\" name=\"fUtilisationUnits\"></td>";  
73 - $sToRender .= "<td><select name=\"fUtilisationDatePart\"><option value=\"day\">Days</option><option value=\"month\">Months</option><option value=\"year\">Years</option></select></td></tr>"; 88 + // TODO: form instructions and calendar control integration
  89 + if ($sArchivingType == "Date") {
  90 + $sToRender .= "<tr><th colspan=\"2\">Archive By Date</th></tr>";
  91 + $sToRender .= "<tr><td>Expiration Date:</td></tr>";
  92 + $sToRender .= "<tr><td><input type=\"text\" name=\"fExpirationDate\" size=\"11\"></td><td align=\"right\"><a href=\"javascript: void(0);\" onmouseover=\"if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;\" onmouseout=\"if (timeoutDelay) calendarTimeout();window.status='';\" onclick=\"g_Calendar.show(event,'MainForm.fExpirationDate', false, 'yyyy-mm-dd', new Date()); return false;\"><img src=\"$default->graphicsUrl/calendar/calendar.gif\" name=\"imgCalendar\" width=\"34\" height=\"21\" border=\"0\" alt=\"\"></a></td></tr>";
  93 + $sToRender .= "<tr><td colspan=\"3\">Expiration Period:</td></tr>";
  94 + $sToRender .= "<tr><td><input type=\"text\" size=\"11\" name=\"fUnits\"></td>";
  95 + $sToRender .= "<td>" . renderTimeUnitsListBox("fTimeUnitID") . "</td></tr>";
  96 +
  97 + $sToRender .= "\n\n<script language=\"javascript\">\n<!--\n";
  98 + $sToRender .= "function validateForm(theForm) {\n";
  99 + $sToRender .= "\tif (isBlank(theForm.fExpirationDate) && isBlank(theForm.fUnits) && isBlank(theForm.fTimeUnitID)) {\n";
  100 + $sToRender .= "\t\talert('You must specify an expiration date OR an expiration period');\n";
  101 + $sToRender .= "\t\treturn false;\n";
  102 + $sToRender .= "\t}\n";
  103 +
  104 + $sToRender .= "\tif (!isBlank(theForm.fUnits) || !isBlank(theForm.fTimeUnitID)) {\n";
  105 + $sToRender .= "\t\tif (!validNum(theForm.fUnits, 'Units', true) ) {\n";
  106 + $sToRender .= "\t\t\treturn false;\n";
  107 + $sToRender .= "\t\t}\n";
  108 + $sToRender .= "\t\tif (!validRequired(theForm.fTimeUnitID, 'Date Unit')) {\n";
  109 + $sToRender .= "\t\t\treturn false;\n";
  110 + $sToRender .= "\t\t}\n";
  111 + $sToRender .= "\t} else {\n";
  112 + $sToRender .= "\t\tif (isBlank(theForm.fExpirationDate)) {\n";
  113 + $sToRender .= "\t\t\talert('Please enter a value for the \"Expiration Date\" field');\n";
  114 + $sToRender .= "\t\t\ttheForm.fExpirationDate.focus();\n\t\treturn false;\n";
  115 + $sToRender .= "\t\t}\n";
  116 + $sToRender .= "\t}\n";
  117 + $sToRender .= "\t\treturn true;\n";
  118 + $sToRender .= "}\n";
  119 + $sToRender .= "//-->\n</script>\n\n";
  120 +
  121 +
  122 + } elseif ($sArchivingType == "Utilisation") {
  123 + $sToRender .= "<tr><th colspan=\"2\">Archive By Utilisation</th></tr>";
  124 + $sToRender .= "<tr><td>Document Transaction:</td><td>" . renderDocumentTransactionListBox() . "</td></tr>";
  125 + $sToRender .= "<tr><td>Units</td><td colspan=\"2\"><input type=\"text\" size=\"11\" name=\"fUnits\">" . renderTimeUnitsListBox("fTimeUnitID") . "</td></tr>";
  126 +
  127 + $sToRender .= "\n\n<script language=\"javascript\">\n<!--\n";
  128 + $sToRender .= "function validateForm(theForm) {\n";
  129 + $sToRender .= "\tif (!validRequired(theForm.fDocumentTransactionID,'Document Transaction')) {\n";
  130 + $sToRender .= "\t\treturn false;\n\t}\n";
  131 + $sToRender .= "\tif (!validNum(theForm.fUnits,'Units', true)) {\n";
  132 + $sToRender .= "\t\treturn false;\n\t}\n";
  133 + $sToRender .= "\tif (!validRequired(theForm.fTimeUnitID,'Date Unit')) {\n";
  134 + $sToRender .= "\t\treturn false;\n\t}\n";
  135 + $sToRender .= "return true;\n}\n";
  136 + $sToRender .= "//-->\n</script>\n\n";
  137 + }
74 138
75 // hidden archive settings references 139 // hidden archive settings references
76 - $sToRender .= "<input type=\"hidden\" name=\"fStore\" value=\"1\">\n";  
77 $sToRender .= "<input type=\"hidden\" name=\"fDocumentID\" value=\"$fDocumentID\">\n"; 140 $sToRender .= "<input type=\"hidden\" name=\"fDocumentID\" value=\"$fDocumentID\">\n";
78 - 141 + $sToRender .= "<input type=\"hidden\" name=\"fArchivingTypeID\" value=\"$iArchivingTypeID\">\n";
  142 + $sToRender .= "<input type=\"hidden\" name=\"fStore\" value=\"1\">\n";
79 $sToRender .= "<tr><td><input type=\"image\" src=\"$default->graphicsUrl/widgets/submit.gif\" border=\"0\">\n"; 143 $sToRender .= "<tr><td><input type=\"image\" src=\"$default->graphicsUrl/widgets/submit.gif\" border=\"0\">\n";
80 - $sToRender .= "<a href=\"$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\" /></a></td></tr>\n"; 144 + $sToRender .= $sJavaScript;
  145 + $sToRender .= "<a href=\"$default->rootUrl/control.php?action=addDocumentArchiveSettings&fDocumentID=$fDocumentID\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\" /></a></td></tr>\n";
81 $sToRender .= "</table>"; 146 $sToRender .= "</table>";
82 147
83 - /*  
84 - $sToRender .= "\n\n<script language=\"javascript\">\n<!--\n";  
85 - $sToRender .= "function validateForm(theForm) {\n";  
86 - $sToRender .= "\tif (!(validRequired(theForm.fSynopsis,'Synopsis'))) {\n";  
87 - $sToRender .= "\t\treturn false;\n\t}\n";  
88 - $sToRender .= "\tif (!(validRequired(theForm.fBody,'Body'))) {\n";  
89 - $sToRender .= "\t\treturn false;\n\t}\n";  
90 - $sToRender .= "\tif (!(validNum(theForm.fRank,'Rank')) || !(validRequired(theForm.fRank,'Rank'))) {\n";  
91 - $sToRender .= "\t\treturn false;\n\t}\n";  
92 - $sToRender .= "return true;\n}\n";  
93 - $sToRender .= "//-->\n</script>\n\n";  
94 - */ 148 +
  149 +
95 return $sToRender; 150 return $sToRender;
96 } 151 }
97 152
@@ -116,6 +171,26 @@ function renderEditArchiveSettingsPage($oArchiveSettings, $sErrorMessage = &quot;&quot;) { @@ -116,6 +171,26 @@ function renderEditArchiveSettingsPage($oArchiveSettings, $sErrorMessage = &quot;&quot;) {
116 return $sToRender; 171 return $sToRender;
117 } 172 }
118 173
  174 +/**
  175 + * Displays the add document archive settings page
  176 + */
  177 +function renderAddArchiveSettingsPage($iArchivingTypeID, $sErrorMessage = "") {
  178 + global $default;
  179 +
  180 + $sToRender .= renderHeading("Add Document Archive Settings");
  181 + if (strlen($sErrorMessage) > 0) {
  182 + $sToRender .= renderErrorMessage($sErrorMessage);
  183 + }
  184 + $sToRender .= "<table>\n";
  185 + if ($iArchivingTypeID) {
  186 + $sToRender .= renderAddArchiveSettingsForm($iArchivingTypeID);
  187 + } else {
  188 + $sToRender .= renderChooseArchivingTypeForm();
  189 + }
  190 + $sToRender .= "</table>\n";
  191 + return $sToRender;
  192 +}
  193 +
119 function wrap($html) { 194 function wrap($html) {
120 global $default; 195 global $default;
121 196