From 2c4a825c9cf702530809b861bafbeb6fa0b3e853 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 17 Dec 2003 11:28:17 +0000 Subject: [PATCH] #3500 added ability to send to groups and users. --- presentation/lookAndFeel/knowledgeTree/documentmanagement/emailBL.php | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------- presentation/lookAndFeel/knowledgeTree/documentmanagement/emailUI.inc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- presentation/lookAndFeel/knowledgeTree/js/OptionTransfer.js | 472 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 711 insertions(+), 97 deletions(-) create mode 100644 presentation/lookAndFeel/knowledgeTree/js/OptionTransfer.js diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/emailBL.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/emailBL.php index 2b98c9c..3e19d5f 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/emailBL.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/emailBL.php @@ -26,88 +26,164 @@ */ require_once("../../../../config/dmsDefaults.php"); +require_once("$default->fileSystemRoot/lib/security/Permission.inc"); +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); +require_once("$default->fileSystemRoot/lib/email/Email.inc"); +require_once("$default->fileSystemRoot/lib/users/User.inc"); +require_once("$default->fileSystemRoot/lib/groups/Group.inc"); +require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); +require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); +require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); +require_once("$default->fileSystemRoot/presentation/Html.inc"); +require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); +require_once("emailUI.inc"); + +/** + * Sends emails to the selected groups + */ +function sendGroupEmails($aGroupIDs, $oDocument, $sComment = "") { + global $default; + + // loop through groups + for ($i=0; $i 0) { + $oDestGroup = Group::get($aGroupIDs[$i]); + $default->log->info("sendingEmail to group " . $oDestGroup->getName()); + // for each group, retrieve all the users + $aUsers = $oDestGroup->getUsers(); + // FIXME: this should send one email with multiple To: users + for ($j=0; $jlog->info("sendingEmail to group-member " . $aUsers[$j]->getName() . " with email " . $aUsers[$j]->getEmail()); + // the user has an email address and has email notification enabled + if (strlen($aUsers[$j]->getEmail())>0 && $aUsers[$j]->getEmailNotification()) { + //if the to address is valid, send the mail + if (validateEmailAddress($aUsers[$j]->getEmail())) { + sendEmail($aUsers[$j]->getEmail(), $aUsers[$j]->getName(), $oDocument->getID(), $oDocument->getName(), $sComment); + } else { + $default->log->error("email validation failed for " . $aUsers[$j]->getEmail()); + } + } else { + $default->log->info("either " . $aUsers[$j]->getUserName() . " has no email address, or notification is not enabled"); + } + } + } else { + $default->log->info("filtered group id=" . $aGroupIDs[$i]); + } + } +} + +/** + * Sends emails to the selected users + */ +function sendUserEmails($aUserIDs, $oDocument, $sComment = "") { + global $default; + + // loop through users + for ($i=0; $i 0) { + $oDestUser = User::get($aUserIDs[$i]); + $default->log->info("sendingEmail to user " . $oDestUser->getName() . " with email " . $oDestUser->getEmail()); + // the user has an email address and has email notification enabled + if (strlen($oDestUser->getEmail())>0 && $oDestUser->getEmailNotification()) { + //if the to address is valid, send the mail + if (validateEmailAddress($oDestUser->getEmail())) { + sendEmail($oDestUser->getEmail(), $oDestUser->getName(), $oDocument->getID(), $oDocument->getName(), $sComment); + } + } else { + $default->log->info("either " . $oDestUser->getUserName() . " has no email address, or notification is not enabled"); + } + } else { + $default->log->info("filtered user id=" . $aUserIDs[$i]); + } + } +} + +/** + * Constructs the email message text and sends the message + */ +function sendEmail($sDestEmailAddress, $sDestUserName, $fDocumentID, $sDocumentName, $sComment) { + global $default; + $oSendingUser = User::get($_SESSION["userID"]); + + $sMessage = ""; + $sMessage .= $sDestUserName . ",

"; + $sMessage .= "Your colleague, " . $oSendingUser->getName() . ", wishes you to view the document entitled '" . $sDocumentName . "'.\n "; + $sMessage .= "Click on the hyperlink below to view it."; + // add the link to the document to the mail + $sMessage .= "
" . generateControllerLink("viewDocument", "fDocumentID=$fDocumentID", $sDocumentName); + // add optional comment + if (strlen($sComment) > 0) { + $sMessage .= "

Comments:
$sComment"; + } + $sMessage .= "
"; + $sTitle = "Link: " . $sDocumentName . " from " . $sSendingUserName; + //email the hyperlink + $oEmail = new Email(); + if ($oEmail->send($sDestEmailAddress, $sTitle, $sMessage)) { + $default->log->info("Send email ($sTitle) to $sDestEmailAddress"); + } else { + $default->log->error("Error sending email ($sTitle) to $sDestEmailAddress"); + } + + // emailed link transaction + $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Document link emailed to $sDestEmailAddress", EMAIL_LINK); + if ($oDocumentTransaction->create()) { + $default->log->debug("emailBL.php created email link document transaction for document ID=$fDocumentID"); + } else { + $default->log->error("emailBL.php couldn't create email link document transaction for document ID=$fDocumentID"); + } +} + if (checkSession()) { if (isset($fDocumentID)) { - require_once("$default->fileSystemRoot/lib/security/Permission.inc"); - require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); - require_once("$default->fileSystemRoot/lib/email/Email.inc"); - require_once("$default->fileSystemRoot/lib/users/User.inc"); - require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc"); - require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc"); - require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc"); - require_once("$default->fileSystemRoot/presentation/Html.inc"); - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc"); - require_once("emailUI.inc"); - //get the document to send $oDocument = Document::get($fDocumentID); //if the user can view the document, they can email a link to it if (Permission::userHasDocumentReadPermission($fDocumentID)) { if (isset($fSendEmail)) { - //if we're going to send a mail, first make sure the to address is set - if (isset($fToEmail)) { - if (validateEmailAddress($fToEmail)) { - //if the to address is valid, send the mail - global $default; - $oUser = User::get($_SESSION["userID"]); - $sMessage = ""; - if (isset($fToName)) { - $sMessage .= "$fToName,

Your colleague, " . $oUser->getName() . ", wishes you to view the document entitled '" . $oDocument->getName() . "'.\n Click on the hyperlink below to view it."; - } else { - $sMessage .= "Your colleague, " . $oUser->getName() . ", wishes you to view the document entitled '" . $oDocument->getName() . "'.\n Click on the hyperlink below to view it."; - } - // add the link to the document to the mail - $sMessage .= "
" . generateControllerLink("viewDocument", "fDocumentID=$fDocumentID", $oDocument->getName()); - - // add optional comment - if (strlen($fComment) > 0) { - $sMessage .= "

Comments:
$fComment"; - } - $sMessage .= "
"; - - $sTitle = "Link: " . $oDocument->getName() . " from " . $oUser->getName(); - - //email the hyperlink - $oEmail = new Email(); - $oEmail->send($fToEmail, $sTitle, $sMessage); - - // emailed link transaction - $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Document link emailed to $fToEmail", EMAIL_LINK); - if ($oDocumentTransaction->create()) { - $default->log->debug("emailBL.php created email link document transaction for document ID=$fDocumentID"); - } else { - $default->log->error("emailBL.php couldn't create email link document transaction for document ID=$fDocumentID"); - } + // explode group and user ids + $aGroupIDs = explode(",", $groupNewRight); + $aUserIDs = explode(",", $userNewRight); + $default->log->info("Sending email to groups=$groupNewRight; users=$userNewRight"); + + //if we're going to send a mail, first make there is someone to send it to + if ((count($aGroupIDs) > 1) || (count($aUserIDs) > 1)) { + // send group emails + sendGroupEmails($aGroupIDs, $oDocument, $fComment); + // send user emails + sendUserEmails($aUserIDs, $oDocument, $fComment); - //go back to the document view page - redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID"); - } else { - //ask the user to enter a valid email address - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); - - - $oPatternCustom = & new PatternCustom(); - $oUserArray = User::getList(); - $oPatternCustom->setHtml(getDocumentEmailPage($oDocument,$oUserArray)); - $main->setErrorMessage("The email address you entered was invalid. Please enter
" . - "an email address of the form someone@somewhere.some postfix"); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1"); - $main->setCentralPayload($oPatternCustom); - $main->render(); - } - } + //go back to the document view page + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID"); + } else { + // ask the user to specify users or groups to send the mail to + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); + $main->setErrorMessage("You must select either a group or a user to send an email link to."); + $oPatternCustom = & new PatternCustom(); + $oPatternCustom->setHtml(getDocumentEmailPage($oDocument)); + $main->setCentralPayload($oPatternCustom); + $main->setOnLoadJavaScript("optGroup.init(document.forms[0]);optUser.init(document.forms[0]);"); + $main->setHasRequiredFields(true); + $main->setAdditionalJavaScript(initialiseOptionTransferJavaScript()); + $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1"); + $main->setDHTMLScrolling(false); + $main->render(); + } } else { - //ask for an email address + // display form require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); - - $oUserArray = User::getList(); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getDocumentEmailPage($oDocument,$oUserArray)); + $oPatternCustom->setHtml(getDocumentEmailPage($oDocument)); $main->setCentralPayload($oPatternCustom); + $main->setOnLoadJavaScript("optGroup.init(document.forms[0]);optUser.init(document.forms[0]);"); + $main->setHasRequiredFields(true); + $main->setAdditionalJavaScript(initialiseOptionTransferJavaScript()); $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1"); + $main->setDHTMLScrolling(false); $main->render(); } } else { @@ -122,7 +198,29 @@ if (checkSession()) { } } - +function initialiseOptionTransferJavascript() { + return ""; +} /** use regex to validate the format of the email address */ function validateEmailAddress($sEmailAddress) { $aEmailAddresses = array(); diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/emailUI.inc b/presentation/lookAndFeel/knowledgeTree/documentmanagement/emailUI.inc index a9ed83a..c1c1272 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/emailUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/emailUI.inc @@ -33,44 +33,88 @@ function getDocumentPath($oDocument) { return "
$sDocumentPath
\n"; } -function getDocumentEmailPage($oDocument,$oUserArray) { - global $default; - $sToRender = renderHeading("Email Document Link"); - $sToRender .= getDocumentPath($oDocument) . "\n
\n"; - $sToRender .= "\n"; - $sToRender .= ""; + $sToRender .= ""; + $sToRender .= ""; + $sToRender .= ""; + $sToRender .= "\n"; + return $sToRender; +} + +function renderUserPicker() { + $sToRender .= "\n"; + $sToRender .= "\n"; - $sToRender .= "\n"; + $sToRender .= ""; + $sToRender .= ""; + $sToRender .= ""; + $sToRender .= "\n"; + + return $sToRender; +} + +function getDocumentEmailPage($oDocument) { + global $default; + $sToRender = renderHeading("Email Document Link"); + $sToRender .= getDocumentPath($oDocument) . "\n
\n"; + $sToRender .= "
Recipient name:\n"; - $sToRender .= "
Groups
\n"; + $sToRender .= ""; + $sToRender .= ""; + $sToRender .= ""; + $sToRender .= "
Users
Email Addresses:graphicsUrl/widgets/clear.gif\" onMouseDown=\"var oTemp = getObject('fToEmail'); oTemp.value=''; oTemp = getObject('UserSelect'); oTemp.selectedIndex=0;\" onmouseover=\"this.style.cursor='hand'\">
"; + $sToRender .= ""; + $sToRender .= ""; + $sToRender .= "
\n"; + $sToRender .= ""; + $sToRender .= "\n"; + $sToRender .= "
\n"; + $sToRender .= renderGroupPicker(); + $sToRender .= renderUserPicker(); + $sToRender .= "
\n"; + $sToRender .= "";//\n"; + $sToRender .= "\n"; + $sToRender .= "
Comment
graphicsUrl/widgets/email.gif\" border=\"0\" />rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID() . "\">graphicsUrl/widgets/cancel.gif\" border=\"0\"/>
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; + $sToRender .= "
"; - $sToRender .= "(separate multiple addresses with a semicolon)"; - $sToRender .= "Comment\n"; - $sToRender .= "  \n"; - $sToRender .= "
graphicsUrl/widgets/email.gif\" border=\"0\"/>rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID() . "\">graphicsUrl/widgets/cancel.gif\" border=\"0\"/>
\n"; - $sToRender .= "\n"; $sToRender .= "\n"; return $sToRender; } -?> +?> \ No newline at end of file diff --git a/presentation/lookAndFeel/knowledgeTree/js/OptionTransfer.js b/presentation/lookAndFeel/knowledgeTree/js/OptionTransfer.js new file mode 100644 index 0000000..a13ae31 --- /dev/null +++ b/presentation/lookAndFeel/knowledgeTree/js/OptionTransfer.js @@ -0,0 +1,472 @@ +// =================================================================== +// Author: Matt Kruse +// WWW: http://www.mattkruse.com/ +// +// NOTICE: You may use this code for any purpose, commercial or +// private, without any further permission from the author. You may +// remove this notice from your final code if you wish, however it is +// appreciated by the author if at least my web site address is kept. +// +// You may *NOT* re-distribute this code in any way except through its +// use. That means, you can include it in your product, or your web +// site, or any other form where the code is actually being used. You +// may not put the plain javascript up on your site for download or +// include it in your javascript libraries for download. +// If you wish to share this code with others, please just point them +// to the URL instead. +// Please DO NOT link directly to my .js files from your site. Copy +// the files to your server and use them there. Thank you. +// =================================================================== + + +/* SOURCE FILE: selectbox.js */ + +// ------------------------------------------------------------------- +// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false) +// This is a general function used by the select functions below, to +// avoid code duplication +// ------------------------------------------------------------------- +function selectUnselectMatchingOptions(obj,regex,which,only) { + if (window.RegExp) { + if (which == "select") { + var selected1=true; + var selected2=false; + } + else if (which == "unselect") { + var selected1=false; + var selected2=true; + } + else { + return; + } + var re = new RegExp(regex); + for (var i=0; i (b.text+"")) { return 1; } + return 0; + } + ); + + for (var i=0; i object as follows: +// onDblClick="moveSelectedOptions(this,this.form.target) +// This way, when the user double-clicks on a value in one box, it +// will be transferred to the other (in browsers that support the +// onDblClick() event handler). +// ------------------------------------------------------------------- +function moveSelectedOptions(from,to) { + // Unselect matching options, if required + if (arguments.length>3) { + var regex = arguments[3]; + if (regex != "") { + unSelectMatchingOptions(from,regex); + } + } + // Move them over + for (var i=0; i=0; i--) { + var o = from.options[i]; + if (o.selected) { + from.options[i] = null; + } + } + if ((arguments.length<3) || (arguments[2]==true)) { + sortSelect(from); + sortSelect(to); + } + from.selectedIndex = -1; + to.selectedIndex = -1; + } + +// ------------------------------------------------------------------- +// copySelectedOptions(select_object,select_object[,autosort(true/false)]) +// This function copies options between select boxes instead of +// moving items. Duplicates in the target list are not allowed. +// ------------------------------------------------------------------- +function copySelectedOptions(from,to) { + var options = new Object(); + for (var i=0; i 1 option selected, do nothing + var selectedCount=0; + for (i=0; i 1 option selected, do nothing + var selectedCount=0; + for (i=0; i=0; i--) { + var o=from.options[i]; + if (o.selected) { + from.options[i] = null; + } + } + from.selectedIndex = -1; + } + + +/* SOURCE FILE: OptionTransfer.js */ + +/* +OptionTransfer.js +Last Modified: 11/18/2002 + +DESCRIPTION: This widget is used to easily and quickly create an interface +where the user can transfer choices from one select box to another. For +example, when selecting which columns to show or hide in search results. +This object adds value by automatically storing the values that were added +or removed from each list, as well as the state of the final list. + +COMPATABILITY: Should work on all Javascript-compliant browsers. + +USAGE: +// Create a new OptionTransfer object. Pass it the field names of the left +// select box and the right select box. +var ot = new OptionTransfer("from","to"); + +// Optionally tell the lists whether or not to auto-sort when options are +// moved. By default, the lists will be sorted. +ot.setAutoSort(true); + +// Optionally set the delimiter to be used to separate values that are +// stored in hidden fields for the added and removed options, as well as +// final state of the lists. Defaults to a comma. +ot.setDelimiter("|"); + +// These functions assign the form fields which will store the state of +// the lists. Each one is optional, so you can pick to only store the +// new options which were transferred to the right list, for example. +// Each function takes the name of a HIDDEN or TEXT input field. + +// Store list of options removed from left list into an input field +ot.saveRemovedLeftOptions("removedLeft"); +// Store list of options removed from right list into an input field +ot.saveRemovedRightOptions("removedRight"); +// Store list of options added to left list into an input field +ot.saveAddedLeftOptions("addedLeft"); +// Store list of options radded to right list into an input field +ot.saveAddedRightOptions("addedRight"); +// Store all options existing in the left list into an input field +ot.saveNewLeftOptions("newLeft"); +// Store all options existing in the right list into an input field +ot.saveNewRightOptions("newRight"); + +// IMPORTANT: This step is required for the OptionTransfer object to work +// correctly. +// Add a call to the BODY onLoad="" tag of the page, and pass a reference to +// the form which contains the select boxes and input fields. +BODY onLoad="ot.init(document.forms[0])" + +// ADDING ACTIONS INTO YOUR PAGE +// Finally, add calls to the object to move options back and forth, either +// from links in your page or from double-clicking the options themselves. +// See example page, and use the following methods: +ot.transferRight(); +ot.transferAllRight(); +ot.transferLeft(); +ot.transferAllLeft(); + + +NOTES: +1) Requires the functions in selectbox.js + +*/ +function OT_transferLeft() { moveSelectedOptions(this.right,this.left,this.autoSort); this.update(); } +function OT_transferRight() { moveSelectedOptions(this.left,this.right,this.autoSort); this.update(); } +function OT_transferAllLeft() { moveAllOptions(this.right,this.left,this.autoSort); this.update(); } +function OT_transferAllRight() { moveAllOptions(this.left,this.right,this.autoSort); this.update(); } +function OT_saveRemovedLeftOptions(f) { this.removedLeftField = f; } +function OT_saveRemovedRightOptions(f) { this.removedRightField = f; } +function OT_saveAddedLeftOptions(f) { this.addedLeftField = f; } +function OT_saveAddedRightOptions(f) { this.addedRightField = f; } +function OT_saveNewLeftOptions(f) { this.newLeftField = f; } +function OT_saveNewRightOptions(f) { this.newRightField = f; } +function OT_update() { + var removedLeft = new Object(); + var removedRight = new Object(); + var addedLeft = new Object(); + var addedRight = new Object(); + var newLeft = new Object(); + var newRight = new Object(); + for (var i=0;i0) { str=str+delimiter; } + str=str+val; + } + return str; + } +function OT_setDelimiter(val) { this.delimiter=val; } +function OT_setAutoSort(val) { this.autoSort=val; } +function OT_init(theform) { + this.form = theform; + if(!theform[this.left]){alert("OptionTransfer init(): Left select list does not exist in form!");return false;} + if(!theform[this.right]){alert("OptionTransfer init(): Right select list does not exist in form!");return false;} + this.left=theform[this.left]; + this.right=theform[this.right]; + for(var i=0;i