Commit d23cd89928d9a8a94ebf6fba35166aa3a0b045e7
1 parent
c027d65e
Intial revision. Email a link
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@719 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
147 additions
and
0 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/emailBL.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | +* Business logic to email link to a document | ||
| 4 | +* | ||
| 5 | +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | ||
| 6 | +* @date 31 January 2003 | ||
| 7 | +* @package presentation.lookAndFeel.knowledgeTree.documentmanagement | ||
| 8 | +* | ||
| 9 | +*/ | ||
| 10 | + | ||
| 11 | +require_once("../../../../config/dmsDefaults.php"); | ||
| 12 | +if (checkSession()) { | ||
| 13 | + if (isset($fDocumentID)) { | ||
| 14 | + require_once("$default->owl_fs_root/lib/security/permission.inc"); | ||
| 15 | + require_once("$default->owl_fs_root/lib/documentmanagement/Document.inc"); | ||
| 16 | + require_once("$default->owl_fs_root/lib/email/Email.inc"); | ||
| 17 | + require_once("$default->owl_fs_root/lib/users/User.inc"); | ||
| 18 | + require_once("$default->owl_fs_root/lib/documentmanagement/PhysicalDocumentManager.inc"); | ||
| 19 | + require_once("$default->owl_fs_root/lib/documentmanagement/DocumentTransaction.inc"); | ||
| 20 | + require_once("$default->owl_fs_root/lib/foldermanagement/Folder.inc"); | ||
| 21 | + require_once("$default->owl_fs_root/presentation/Html.inc"); | ||
| 22 | + require_once("$default->owl_fs_root/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); | ||
| 23 | + require_once("emailUI.inc"); | ||
| 24 | + | ||
| 25 | + //get the document to send | ||
| 26 | + $oDocument = Document::get($fDocumentID); | ||
| 27 | + | ||
| 28 | + //if the user can view the document, they can email a link to it | ||
| 29 | + if (Permission::userHasDocumentReadPermission($fDocumentID)) { | ||
| 30 | + if (isset($fSendEmail)) { | ||
| 31 | + //if we're going to send a mail, first make sure the to address is set | ||
| 32 | + if (isset($fToEmail)) { | ||
| 33 | + if (validateEmailAddress($fToEmail)) { | ||
| 34 | + //if the to address is valid, send the mail | ||
| 35 | + global $default; | ||
| 36 | + $oUser = User::get($_SESSION["userID"]); | ||
| 37 | + if (isset($fToName)) { | ||
| 38 | + $sMessage = "$fToName,\n\nYour colleauge, " . $oUser->getName() . ", wishes you to view the document entitled '" . $oDocument->getName() . "'.\n Click on the hyperlink below to view it"; | ||
| 39 | + } else { | ||
| 40 | + $sMessage = "Your colleauge, " . $oUser->getName() . ", wishes you to view the document entitled '" . $oDocument->getName() . "'.\n Click on the hyperlink below to view it"; | ||
| 41 | + } | ||
| 42 | + $sHyperlink = "$default->owl_root_url/control.php?action=viewDocument&fDocumentID=$fDocumentID"; | ||
| 43 | + //email the hyperlink | ||
| 44 | + Email::sendHyperlink($default->owl_email_from, "MRC DMS", $fToEmail, "Document link", $sMessage, $sHyperlink); | ||
| 45 | + //go back to the document view page | ||
| 46 | + redirect("$default->owl_root_url/control.php?action=viewDocument&fDocumentID=$fDocumentID"); | ||
| 47 | + } else { | ||
| 48 | + //ask the user to enter a valid email address | ||
| 49 | + require_once("$default->owl_fs_root/presentation/webpageTemplate.inc"); | ||
| 50 | + require_once("$default->owl_fs_root/lib/visualpatterns/PatternCustom.inc"); | ||
| 51 | + | ||
| 52 | + | ||
| 53 | + $oPatternCustom = & new PatternCustom(); | ||
| 54 | + $oPatternCustom->setHtml(getDocumentEmailPage($oDocument)); | ||
| 55 | + $main->setErrorMessage("The email address you entered was invalid. Please enter<br> " . | ||
| 56 | + "an email address of the form someone@somewhere.some postfix"); | ||
| 57 | + $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1"); | ||
| 58 | + $main->setCentralPayload($oPatternCustom); | ||
| 59 | + $main->render(); | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + } else { | ||
| 63 | + //ask for an email address | ||
| 64 | + require_once("$default->owl_fs_root/presentation/webpageTemplate.inc"); | ||
| 65 | + require_once("$default->owl_fs_root/lib/visualpatterns/PatternCustom.inc"); | ||
| 66 | + | ||
| 67 | + $oPatternCustom = & new PatternCustom(); | ||
| 68 | + $oPatternCustom->setHtml(getDocumentEmailPage($oDocument)); | ||
| 69 | + //$main->setErrorMessage("Please enter an email address of the form someone@somewhere.some postfix"); | ||
| 70 | + $main->setCentralPayload($oPatternCustom); | ||
| 71 | + $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1"); | ||
| 72 | + $main->render(); | ||
| 73 | + } | ||
| 74 | + } else { | ||
| 75 | + require_once("$default->owl_fs_root/presentation/webpageTemplate.inc"); | ||
| 76 | + require_once("$default->owl_fs_root/lib/visualpatterns/PatternCustom.inc"); | ||
| 77 | + $oPatternCustom = & new PatternCustom(); | ||
| 78 | + $oPatternCustom->setHtml(""); | ||
| 79 | + $main->setErrorMessage("You do not have the permission to email a link to this document\n"); | ||
| 80 | + $main->setCentralPayload($oPatternCustom); | ||
| 81 | + $main->render(); | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +/** use regex to validate the format of the email address */ | ||
| 88 | +function validateEmailAddress($sEmailAddress){ | ||
| 89 | + $Result = ereg ("^[^@ ]+@[^@ ]+\.[^@ \.]+$", $sEmailAddress ); | ||
| 90 | + if ($Result) { | ||
| 91 | + return TRUE; | ||
| 92 | + } else { | ||
| 93 | + return FALSE; | ||
| 94 | + } | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +?> |
presentation/lookAndFeel/knowledgeTree/documentmanagement/emailUI.inc
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | +* Business logic to email a link to a document to a colleauge | ||
| 4 | +* | ||
| 5 | +* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa | ||
| 6 | +* @date 31 January 2003 | ||
| 7 | +* @package presentation.lookAndFeel.knowledgeTree.documentmanagement | ||
| 8 | +* | ||
| 9 | +*/ | ||
| 10 | + | ||
| 11 | +function getDocumentPath($oDocument) { | ||
| 12 | + global $default; | ||
| 13 | + $sDocumentPath = displayFolderPathLink(Folder::getFolderPathAsArray($oDocument->getFolderID()), "$default->owl_root_url/control.php?action=browse") . " > " . $oDocument->getName(); | ||
| 14 | + return "<table border=1 width = 100%><tr><td>$sDocumentPath</td></tr></table>\n"; | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +function getEmailPage($oDocument) { | ||
| 18 | + $sToRender = "<table>\n" . | ||
| 19 | + $sToRender .= "<tr>\n" . | ||
| 20 | + $sToRender .= "<td><b>Document:</b></td><td>" . getDocumentPath($oDocument) . "</td>\n" . | ||
| 21 | + $sToRender .= "</tr>\n" . | ||
| 22 | + $sToRender .= "</table>\n"; | ||
| 23 | + /* | ||
| 24 | + $sToRender .= "<tr>\n" . | ||
| 25 | + $sToRender .= "<td><b>Recipient's name:</b></td><td><input type=\"text\" name=\"fToName\" /></td>\n" . | ||
| 26 | + $sToRender .= "</tr>\n" . | ||
| 27 | + $sToRender .= "<tr>\n" . | ||
| 28 | + $sToRender .= "<td><b>Recipient's email address:</b></td><td><input type=\"text\" name=\"fToEmailAddress\" /></td>\n" . | ||
| 29 | + $sToRender .= "</tr>\n" . | ||
| 30 | + $sToRender .= "<tr>\n" . | ||
| 31 | + $sToRender .= "<td><input type=\"Submit\" value=\"Send link\" /></td>\n" . | ||
| 32 | + $sToRender .= "</tr>\n" . | ||
| 33 | + $sToRender .= "</table>\n";*/ | ||
| 34 | + return $sToRender; | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +function getDocumentEmailPage($oDocument) { | ||
| 38 | + $sToRender = getDocumentPath($oDocument) . "\n<br>\n"; | ||
| 39 | + $sToRender .= "<table>\n"; | ||
| 40 | + $sToRender .= "<th colspan=\"2\" align=\"left\">Email details</th>\n"; | ||
| 41 | + $sToRender .= "<tr><td> </td><td> </td></tr>\n"; | ||
| 42 | + $sToRender .= "<tr><td>Recipient name:</td><td><input type=\"text\" name=\"fToName\" /></td></tr>\n"; | ||
| 43 | + $sToRender .= "<tr><td>Email address:</td><td><input type=\"text\" name=\"fToEmail\" /></td></tr>\n"; | ||
| 44 | + $sToRender .= "<tr><td> </td><td> </td></tr>\n"; | ||
| 45 | + $sToRender .= "<tr><td><input type=\"submit\" value=\"Send link\"</td><td> </td></tr>\n"; | ||
| 46 | + $sToRender .= "</table>\n"; | ||
| 47 | + return $sToRender; | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +?> |