Commit 2c4a825c9cf702530809b861bafbeb6fa0b3e853

Authored by michael
1 parent 97d0a6f4

#3500 added ability to send to groups and users.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2809 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/emailBL.php
@@ -26,88 +26,164 @@ @@ -26,88 +26,164 @@
26 */ 26 */
27 27
28 require_once("../../../../config/dmsDefaults.php"); 28 require_once("../../../../config/dmsDefaults.php");
  29 +require_once("$default->fileSystemRoot/lib/security/Permission.inc");
  30 +require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");
  31 +require_once("$default->fileSystemRoot/lib/email/Email.inc");
  32 +require_once("$default->fileSystemRoot/lib/users/User.inc");
  33 +require_once("$default->fileSystemRoot/lib/groups/Group.inc");
  34 +require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc");
  35 +require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc");
  36 +require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");
  37 +require_once("$default->fileSystemRoot/presentation/Html.inc");
  38 +require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");
  39 +require_once("emailUI.inc");
  40 +
  41 +/**
  42 + * Sends emails to the selected groups
  43 + */
  44 +function sendGroupEmails($aGroupIDs, $oDocument, $sComment = "") {
  45 + global $default;
  46 +
  47 + // loop through groups
  48 + for ($i=0; $i<count($aGroupIDs); $i++) {
  49 + // validate the group id
  50 + if ($aGroupIDs[$i] > 0) {
  51 + $oDestGroup = Group::get($aGroupIDs[$i]);
  52 + $default->log->info("sendingEmail to group " . $oDestGroup->getName());
  53 + // for each group, retrieve all the users
  54 + $aUsers = $oDestGroup->getUsers();
  55 + // FIXME: this should send one email with multiple To: users
  56 + for ($j=0; $j<count($aUsers); $j++) {
  57 + $default->log->info("sendingEmail to group-member " . $aUsers[$j]->getName() . " with email " . $aUsers[$j]->getEmail());
  58 + // the user has an email address and has email notification enabled
  59 + if (strlen($aUsers[$j]->getEmail())>0 && $aUsers[$j]->getEmailNotification()) {
  60 + //if the to address is valid, send the mail
  61 + if (validateEmailAddress($aUsers[$j]->getEmail())) {
  62 + sendEmail($aUsers[$j]->getEmail(), $aUsers[$j]->getName(), $oDocument->getID(), $oDocument->getName(), $sComment);
  63 + } else {
  64 + $default->log->error("email validation failed for " . $aUsers[$j]->getEmail());
  65 + }
  66 + } else {
  67 + $default->log->info("either " . $aUsers[$j]->getUserName() . " has no email address, or notification is not enabled");
  68 + }
  69 + }
  70 + } else {
  71 + $default->log->info("filtered group id=" . $aGroupIDs[$i]);
  72 + }
  73 + }
  74 +}
  75 +
  76 +/**
  77 + * Sends emails to the selected users
  78 + */
  79 +function sendUserEmails($aUserIDs, $oDocument, $sComment = "") {
  80 + global $default;
  81 +
  82 + // loop through users
  83 + for ($i=0; $i<count($aUserIDs); $i++) {
  84 + if ($aUserIDs[$i] > 0) {
  85 + $oDestUser = User::get($aUserIDs[$i]);
  86 + $default->log->info("sendingEmail to user " . $oDestUser->getName() . " with email " . $oDestUser->getEmail());
  87 + // the user has an email address and has email notification enabled
  88 + if (strlen($oDestUser->getEmail())>0 && $oDestUser->getEmailNotification()) {
  89 + //if the to address is valid, send the mail
  90 + if (validateEmailAddress($oDestUser->getEmail())) {
  91 + sendEmail($oDestUser->getEmail(), $oDestUser->getName(), $oDocument->getID(), $oDocument->getName(), $sComment);
  92 + }
  93 + } else {
  94 + $default->log->info("either " . $oDestUser->getUserName() . " has no email address, or notification is not enabled");
  95 + }
  96 + } else {
  97 + $default->log->info("filtered user id=" . $aUserIDs[$i]);
  98 + }
  99 + }
  100 +}
  101 +
  102 +/**
  103 + * Constructs the email message text and sends the message
  104 + */
  105 +function sendEmail($sDestEmailAddress, $sDestUserName, $fDocumentID, $sDocumentName, $sComment) {
  106 + global $default;
  107 + $oSendingUser = User::get($_SESSION["userID"]);
  108 +
  109 + $sMessage = "<font face=\"arial\" size=\"2\">";
  110 + $sMessage .= $sDestUserName . ",<br><br>";
  111 + $sMessage .= "Your colleague, " . $oSendingUser->getName() . ", wishes you to view the document entitled '" . $sDocumentName . "'.\n ";
  112 + $sMessage .= "Click on the hyperlink below to view it.";
  113 + // add the link to the document to the mail
  114 + $sMessage .= "<br>" . generateControllerLink("viewDocument", "fDocumentID=$fDocumentID", $sDocumentName);
  115 + // add optional comment
  116 + if (strlen($sComment) > 0) {
  117 + $sMessage .= "<br><br>Comments:<br>$sComment";
  118 + }
  119 + $sMessage .= "</font>";
  120 + $sTitle = "Link: " . $sDocumentName . " from " . $sSendingUserName;
  121 + //email the hyperlink
  122 + $oEmail = new Email();
  123 + if ($oEmail->send($sDestEmailAddress, $sTitle, $sMessage)) {
  124 + $default->log->info("Send email ($sTitle) to $sDestEmailAddress");
  125 + } else {
  126 + $default->log->error("Error sending email ($sTitle) to $sDestEmailAddress");
  127 + }
  128 +
  129 + // emailed link transaction
  130 + $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Document link emailed to $sDestEmailAddress", EMAIL_LINK);
  131 + if ($oDocumentTransaction->create()) {
  132 + $default->log->debug("emailBL.php created email link document transaction for document ID=$fDocumentID");
  133 + } else {
  134 + $default->log->error("emailBL.php couldn't create email link document transaction for document ID=$fDocumentID");
  135 + }
  136 +}
  137 +
29 if (checkSession()) { 138 if (checkSession()) {
30 if (isset($fDocumentID)) { 139 if (isset($fDocumentID)) {
31 - require_once("$default->fileSystemRoot/lib/security/Permission.inc");  
32 - require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc");  
33 - require_once("$default->fileSystemRoot/lib/email/Email.inc");  
34 - require_once("$default->fileSystemRoot/lib/users/User.inc");  
35 - require_once("$default->fileSystemRoot/lib/documentmanagement/PhysicalDocumentManager.inc");  
36 - require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransaction.inc");  
37 - require_once("$default->fileSystemRoot/lib/foldermanagement/Folder.inc");  
38 - require_once("$default->fileSystemRoot/presentation/Html.inc");  
39 - require_once("$default->fileSystemRoot/presentation/lookAndFeel/knowledgeTree/foldermanagement/folderUI.inc");  
40 - require_once("emailUI.inc");  
41 -  
42 //get the document to send 140 //get the document to send
43 $oDocument = Document::get($fDocumentID); 141 $oDocument = Document::get($fDocumentID);
44 142
45 //if the user can view the document, they can email a link to it 143 //if the user can view the document, they can email a link to it
46 if (Permission::userHasDocumentReadPermission($fDocumentID)) { 144 if (Permission::userHasDocumentReadPermission($fDocumentID)) {
47 if (isset($fSendEmail)) { 145 if (isset($fSendEmail)) {
48 - //if we're going to send a mail, first make sure the to address is set  
49 - if (isset($fToEmail)) {  
50 - if (validateEmailAddress($fToEmail)) {  
51 - //if the to address is valid, send the mail  
52 - global $default;  
53 - $oUser = User::get($_SESSION["userID"]);  
54 - $sMessage = "<font face=\"arial\" size=\"2\">";  
55 - if (isset($fToName)) {  
56 - $sMessage .= "$fToName,<br><br>Your colleague, " . $oUser->getName() . ", wishes you to view the document entitled '" . $oDocument->getName() . "'.\n Click on the hyperlink below to view it.";  
57 - } else {  
58 - $sMessage .= "Your colleague, " . $oUser->getName() . ", wishes you to view the document entitled '" . $oDocument->getName() . "'.\n Click on the hyperlink below to view it.";  
59 - }  
60 - // add the link to the document to the mail  
61 - $sMessage .= "<br>" . generateControllerLink("viewDocument", "fDocumentID=$fDocumentID", $oDocument->getName());  
62 -  
63 - // add optional comment  
64 - if (strlen($fComment) > 0) {  
65 - $sMessage .= "<br><br>Comments:<br>$fComment";  
66 - }  
67 - $sMessage .= "</font>";  
68 -  
69 - $sTitle = "Link: " . $oDocument->getName() . " from " . $oUser->getName();  
70 -  
71 - //email the hyperlink  
72 - $oEmail = new Email();  
73 - $oEmail->send($fToEmail, $sTitle, $sMessage);  
74 -  
75 - // emailed link transaction  
76 - $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Document link emailed to $fToEmail", EMAIL_LINK);  
77 - if ($oDocumentTransaction->create()) {  
78 - $default->log->debug("emailBL.php created email link document transaction for document ID=$fDocumentID");  
79 - } else {  
80 - $default->log->error("emailBL.php couldn't create email link document transaction for document ID=$fDocumentID");  
81 - } 146 + // explode group and user ids
  147 + $aGroupIDs = explode(",", $groupNewRight);
  148 + $aUserIDs = explode(",", $userNewRight);
  149 + $default->log->info("Sending email to groups=$groupNewRight; users=$userNewRight");
  150 +
  151 + //if we're going to send a mail, first make there is someone to send it to
  152 + if ((count($aGroupIDs) > 1) || (count($aUserIDs) > 1)) {
  153 + // send group emails
  154 + sendGroupEmails($aGroupIDs, $oDocument, $fComment);
  155 + // send user emails
  156 + sendUserEmails($aUserIDs, $oDocument, $fComment);
82 157
83 - //go back to the document view page  
84 - redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID");  
85 - } else {  
86 - //ask the user to enter a valid email address  
87 - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");  
88 - require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");  
89 -  
90 -  
91 - $oPatternCustom = & new PatternCustom();  
92 - $oUserArray = User::getList();  
93 - $oPatternCustom->setHtml(getDocumentEmailPage($oDocument,$oUserArray));  
94 - $main->setErrorMessage("The email address you entered was invalid. Please enter<br> " .  
95 - "an email address of the form someone@somewhere.some postfix");  
96 - $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1");  
97 - $main->setCentralPayload($oPatternCustom);  
98 - $main->render();  
99 - }  
100 - } 158 + //go back to the document view page
  159 + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=$fDocumentID");
  160 + } else {
  161 + // ask the user to specify users or groups to send the mail to
  162 + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
  163 + require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
  164 + $main->setErrorMessage("You must select either a group or a user to send an email link to.");
  165 + $oPatternCustom = & new PatternCustom();
  166 + $oPatternCustom->setHtml(getDocumentEmailPage($oDocument));
  167 + $main->setCentralPayload($oPatternCustom);
  168 + $main->setOnLoadJavaScript("optGroup.init(document.forms[0]);optUser.init(document.forms[0]);");
  169 + $main->setHasRequiredFields(true);
  170 + $main->setAdditionalJavaScript(initialiseOptionTransferJavaScript());
  171 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1");
  172 + $main->setDHTMLScrolling(false);
  173 + $main->render();
  174 + }
101 } else { 175 } else {
102 - //ask for an email address 176 + // display form
103 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); 177 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
104 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); 178 require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc");
105 -  
106 - $oUserArray = User::getList();  
107 $oPatternCustom = & new PatternCustom(); 179 $oPatternCustom = & new PatternCustom();
108 - $oPatternCustom->setHtml(getDocumentEmailPage($oDocument,$oUserArray)); 180 + $oPatternCustom->setHtml(getDocumentEmailPage($oDocument));
109 $main->setCentralPayload($oPatternCustom); 181 $main->setCentralPayload($oPatternCustom);
  182 + $main->setOnLoadJavaScript("optGroup.init(document.forms[0]);optUser.init(document.forms[0]);");
  183 + $main->setHasRequiredFields(true);
  184 + $main->setAdditionalJavaScript(initialiseOptionTransferJavaScript());
110 $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1"); 185 $main->setFormAction($_SERVER["PHP_SELF"] . "?fDocumentID=$fDocumentID&fSendEmail=1");
  186 + $main->setDHTMLScrolling(false);
111 $main->render(); 187 $main->render();
112 } 188 }
113 } else { 189 } else {
@@ -122,7 +198,29 @@ if (checkSession()) { @@ -122,7 +198,29 @@ if (checkSession()) {
122 } 198 }
123 199
124 } 200 }
125 - 201 +function initialiseOptionTransferJavascript() {
  202 + return "<script LANGUAGE=\"JavaScript\">\n" .
  203 + "var optGroup = new OptionTransfer(\"groupSelect\",\"chosenGroups\");\n" .
  204 + "optGroup.setAutoSort(true);\n" .
  205 + "optGroup.setDelimiter(\",\");\n" .
  206 + "optGroup.saveNewLeftOptions(\"groupNewLeft\");\n" .
  207 + "optGroup.saveNewRightOptions(\"groupNewRight\");\n" .
  208 + "optGroup.saveRemovedLeftOptions(\"groupRemovedLeft\");\n" .
  209 + "optGroup.saveRemovedRightOptions(\"groupRemovedRight\");\n" .
  210 + "optGroup.saveAddedLeftOptions(\"groupAddedLeft\");\n" .
  211 + "optGroup.saveAddedRightOptions(\"groupAddedRight\");\n" .
  212 +
  213 + "var optUser = new OptionTransfer(\"userSelect\",\"chosenUsers\");\n" .
  214 + "optUser.setAutoSort(true);\n" .
  215 + "optUser.setDelimiter(\",\");\n" .
  216 + "optUser.saveNewLeftOptions(\"userNewLeft\");\n" .
  217 + "optUser.saveNewRightOptions(\"userNewRight\");\n" .
  218 + "optUser.saveRemovedLeftOptions(\"userRemovedLeft\");\n" .
  219 + "optUser.saveRemovedRightOptions(\"userRemovedRight\");\n" .
  220 + "optUser.saveAddedLeftOptions(\"userAddedLeft\");\n" .
  221 + "optUser.saveAddedRightOptions(\"userAddedRight\");\n" .
  222 + "</SCRIPT>";
  223 +}
126 /** use regex to validate the format of the email address */ 224 /** use regex to validate the format of the email address */
127 function validateEmailAddress($sEmailAddress) { 225 function validateEmailAddress($sEmailAddress) {
128 $aEmailAddresses = array(); 226 $aEmailAddresses = array();
presentation/lookAndFeel/knowledgeTree/documentmanagement/emailUI.inc
@@ -33,44 +33,88 @@ function getDocumentPath($oDocument) { @@ -33,44 +33,88 @@ function getDocumentPath($oDocument) {
33 return "<table border=\"0\" width = 100%><tr><td bgcolor=\"$sTDBGColour\">$sDocumentPath</td></tr></table>\n"; 33 return "<table border=\"0\" width = 100%><tr><td bgcolor=\"$sTDBGColour\">$sDocumentPath</td></tr></table>\n";
34 } 34 }
35 35
36 -function getDocumentEmailPage($oDocument,$oUserArray) {  
37 - global $default;  
38 - $sToRender = renderHeading("Email Document Link");  
39 - $sToRender .= getDocumentPath($oDocument) . "\n<br>\n";  
40 - $sToRender .= "<table>\n";  
41 - $sToRender .= "<tr><td>Recipient name:</td><td>\n";  
42 - $sToRender .= "<select name=\"UserSelect\" id=\"UserSelect\" onchange=\"javascript: var oUserSelect = getObject('UserSelect');" .  
43 - "var sColon; " .  
44 - "var oTemp = getObject('fToEmail'); " .  
45 - "if (oTemp.value.length > 0) {sColon=';'; } else {sColon=''; } " .  
46 - "if (oUserSelect[oUserSelect.selectedIndex].value!=1 && oUserSelect[oUserSelect.selectedIndex].value!='' && oUserSelect[oUserSelect.selectedIndex].value!=' ') { " .  
47 - " oTemp.value=oTemp.value + sColon + oUserSelect[oUserSelect.selectedIndex].value; " .  
48 - "}\">\n";  
49 - $sToRender .= "<OPTION value=\"1\">\n";  
50 - $sToRender .= "Select Recipient</OPTION>\n"; 36 +function renderGroupPicker() {
  37 +
  38 + $sToRender .= "<tr><td valign=\"top\" colspan=\"3\"><strong>Groups</strong></td></tr>";
  39 + $sToRender .= "<tr><td valign=\"top\" width=1%>\n";
  40 + $sToRender .= "<select name=\"groupSelect\" size=\"4\" multiple>\n";
  41 + // retrieve all groups
  42 + $aGroups = Group::getList("WHERE 1=1 ORDER BY name");
  43 + for ($i = 0; $i < count($aGroups); $i++) {
  44 + $sToRender .= "<OPTION value=\"" . $aGroups[$i]->getID() . "\" onDblClick=\"optGroup.transferRight()\" >\n";
  45 + $sToRender .= $aGroups[$i]->getName();
  46 + $sToRender .= "</OPTION>\n";
  47 + }
  48 + $sToRender .= "</select></td>";
  49 + $sToRender .= "<td width=1%>";
  50 + $sToRender .= "<input TYPE=\"button\" NAME=\"right\" VALUE=\"&gt;&gt;\" ONCLICK=\"optGroup.transferRight()\">";
  51 + $sToRender .= "<input TYPE=\"button\" NAME=\"left\" VALUE=\"&lt;&lt;\" ONCLICK=\"optGroup.transferLeft()\">";
  52 + $sToRender .= "</td>";
  53 + $sToRender .= "<td><select name=\"chosenGroups\" size=\"5\" multiple>";
  54 + $sToRender .= "<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";
  55 + $sToRender .= "</select></td>";
  56 + $sToRender .= "</tr>\n";
  57 + return $sToRender;
  58 +}
  59 +
  60 +function renderUserPicker() {
  61 + $sToRender .= "<tr><td colspan=\"3\"><strong>Users</strong></td><tr>\n";
  62 + $sToRender .= "<tr><td><select name=\"userSelect\" size=\"4\" multiple>\n";
  63 + $oUserArray = User::getList("WHERE 1=1 ORDER BY name");
51 for ($i = 0; $i < count($oUserArray); $i++) { 64 for ($i = 0; $i < count($oUserArray); $i++) {
52 if(strlen($oUserArray[$i]->getEmail())>0){ // if an email address exists 65 if(strlen($oUserArray[$i]->getEmail())>0){ // if an email address exists
53 - $sToRender .= "<OPTION value=\"" . $oUserArray[$i]->getEmail() . "\" onclick=\"javascript: getObject(\"fToEmail\").value=getObject(\"fToEmail\").value + ';'\" >\n"; 66 + $sToRender .= "<OPTION value=\"" . $oUserArray[$i]->getID() . "\" onDblClick=\"optUser.transferRight()\">\n";
54 $sToRender .= $oUserArray[$i]->getName(); 67 $sToRender .= $oUserArray[$i]->getName();
55 $sToRender .= "</OPTION>\n"; 68 $sToRender .= "</OPTION>\n";
56 } 69 }
57 } 70 }
58 - $sToRender .= "</select></td></tr>\n";  
59 - $sToRender .= "<tr><td>Email Addresses:</td><td><input type=\"text\" name=\"fToEmail\" style=\"width:270\"/></td><td><img src=\"$default->graphicsUrl/widgets/clear.gif\" onMouseDown=\"var oTemp = getObject('fToEmail'); oTemp.value=''; oTemp = getObject('UserSelect'); oTemp.selectedIndex=0;\" onmouseover=\"this.style.cursor='hand'\"></td></tr>\n"; 71 + $sToRender .= "</select></td>";
  72 + $sToRender .= "<td>";
  73 + $sToRender .= "<input TYPE=\"button\" NAME=\"right\" VALUE=\"&gt;&gt;\" ONCLICK=\"optUser.transferRight()\">";
  74 + $sToRender .= "<input TYPE=\"button\" NAME=\"left\" VALUE=\"&lt;&lt;\" ONCLICK=\"optUser.transferLeft()\">";
  75 + $sToRender .= "</td>";
  76 + $sToRender .= "<td width=\"30%\"><select name=\"chosenUsers\" size=\"5\" multiple>";
  77 + $sToRender .= "<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>";
  78 + $sToRender .= "</select></td>";
  79 + $sToRender .= "</tr>\n";
  80 +
  81 + return $sToRender;
  82 +}
  83 +
  84 +function getDocumentEmailPage($oDocument) {
  85 + global $default;
  86 + $sToRender = renderHeading("Email Document Link");
  87 + $sToRender .= getDocumentPath($oDocument) . "\n<br>\n";
  88 + $sToRender .= "<table width=\"100%\">\n";
  89 + $sToRender .= "<tr><td><table>\n";
  90 + $sToRender .= renderGroupPicker();
  91 + $sToRender .= renderUserPicker();
  92 + $sToRender .= "</table></td></tr>";
  93 + $sToRender .= "<tr><td><table>\n";
  94 + $sToRender .= "<tr><td valign=\"top\">Comment</td><td><textarea rows=\"5\" cols=\"30\" name=\"fComment\"></textarea></td>";//</tr>\n";
  95 + $sToRender .= "<td valign=\"bottom\"><table><tr><td><input type=\"image\" src=\"$default->graphicsUrl/widgets/email.gif\" border=\"0\" /></td><td><a href=\"$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID() . "\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"/></a></td></tr></table></td></tr>\n";
  96 + $sToRender .= "</table></td></tr>\n";
  97 + $sToRender .= "</table>";
  98 + $sToRender .= "<input type=\"hidden\" name=\"groupNewLeft\"/><br>";
  99 + $sToRender .= "<input type=\"hidden\" name=\"groupNewRight\"/><br>";
  100 + $sToRender .= "<input type=\"hidden\" name=\"groupRemovedLeft\"/><br>";
  101 + $sToRender .= "<input type=\"hidden\" name=\"groupRemovedRight\"/><br>";
  102 + $sToRender .= "<input type=\"hidden\" name=\"groupAddedLeft\"/><br>";
  103 + $sToRender .= "<input type=\"hidden\" name=\"groupAddedRight\"/><br>";
  104 + $sToRender .= "<input type=\"hidden\" name=\"userNewLeft\"/><br>";
  105 + $sToRender .= "<input type=\"hidden\" name=\"userNewRight\"/><br>";
  106 + $sToRender .= "<input type=\"hidden\" name=\"userRemovedLeft\"/><br>";
  107 + $sToRender .= "<input type=\"hidden\" name=\"userRemovedRight\"/><br>";
  108 + $sToRender .= "<input type=\"hidden\" name=\"userAddedLeft\"/><br>";
  109 + $sToRender .= "<input type=\"hidden\" name=\"userAddedRight\"/><br>";
60 110
61 - $sToRender .= "<tr><td></td><td>(separate multiple addresses with a semicolon)</td></tr>";  
62 - $sToRender .= "<tr><td>Comment</td><td><textarea rows=\"5\" cols=\"30\" name=\"fComment\"></textarea></td></tr>\n";  
63 - $sToRender .= "<tr><td>&nbsp</td><td>&nbsp</td></tr>\n";  
64 - $sToRender .= "<tr><td><table><tr><td><input type=\"image\" src=\"$default->graphicsUrl/widgets/email.gif\" border=\"0\"/></td><td><a href=\"$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $oDocument->getID() . "\"><img src=\"$default->graphicsUrl/widgets/cancel.gif\" border=\"0\"/></a></td></tr></table></td>\n";  
65 - $sToRender .= "</table>\n";  
66 $sToRender .= "<script language='javascript'>\n"; 111 $sToRender .= "<script language='javascript'>\n";
67 - $sToRender .= "function getObject(sObjName){\n"; //Function to return an html object(Netscape 4.7 compatable)  
68 - $sToRender .= " var oSelect;\n";  
69 - $sToRender .= " oSelect = document.forms[0].elements[sObjName];";  
70 - $sToRender .= " return oSelect;\n";  
71 - $sToRender .= "}\n"; 112 + $sToRender .= "function validateForm(theForm) {\n";
  113 + $sToRender .= "\tif (isBlank(theForm.groupNewRight) && isBlank(theForm.userNewRight)) {\n";
  114 + $sToRender .= "\t\talert(\"Please choose either at least one Group or User to email a link to this document.\");return false;\n\t}\n";
  115 + $sToRender .= "return true;\n}\n";
72 $sToRender .= "</script >\n"; 116 $sToRender .= "</script >\n";
73 return $sToRender; 117 return $sToRender;
74 } 118 }
75 119
76 -?> 120 -?>
  121 +?>
77 \ No newline at end of file 122 \ No newline at end of file
presentation/lookAndFeel/knowledgeTree/js/OptionTransfer.js 0 โ†’ 100644
  1 +// ===================================================================
  2 +// Author: Matt Kruse <matt@mattkruse.com>
  3 +// WWW: http://www.mattkruse.com/
  4 +//
  5 +// NOTICE: You may use this code for any purpose, commercial or
  6 +// private, without any further permission from the author. You may
  7 +// remove this notice from your final code if you wish, however it is
  8 +// appreciated by the author if at least my web site address is kept.
  9 +//
  10 +// You may *NOT* re-distribute this code in any way except through its
  11 +// use. That means, you can include it in your product, or your web
  12 +// site, or any other form where the code is actually being used. You
  13 +// may not put the plain javascript up on your site for download or
  14 +// include it in your javascript libraries for download.
  15 +// If you wish to share this code with others, please just point them
  16 +// to the URL instead.
  17 +// Please DO NOT link directly to my .js files from your site. Copy
  18 +// the files to your server and use them there. Thank you.
  19 +// ===================================================================
  20 +
  21 +
  22 +/* SOURCE FILE: selectbox.js */
  23 +
  24 +// -------------------------------------------------------------------
  25 +// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
  26 +// This is a general function used by the select functions below, to
  27 +// avoid code duplication
  28 +// -------------------------------------------------------------------
  29 +function selectUnselectMatchingOptions(obj,regex,which,only) {
  30 + if (window.RegExp) {
  31 + if (which == "select") {
  32 + var selected1=true;
  33 + var selected2=false;
  34 + }
  35 + else if (which == "unselect") {
  36 + var selected1=false;
  37 + var selected2=true;
  38 + }
  39 + else {
  40 + return;
  41 + }
  42 + var re = new RegExp(regex);
  43 + for (var i=0; i<obj.options.length; i++) {
  44 + if (re.test(obj.options[i].text)) {
  45 + obj.options[i].selected = selected1;
  46 + }
  47 + else {
  48 + if (only == true) {
  49 + obj.options[i].selected = selected2;
  50 + }
  51 + }
  52 + }
  53 + }
  54 + }
  55 +
  56 +// -------------------------------------------------------------------
  57 +// selectMatchingOptions(select_object,regex)
  58 +// This function selects all options that match the regular expression
  59 +// passed in. Currently-selected options will not be changed.
  60 +// -------------------------------------------------------------------
  61 +function selectMatchingOptions(obj,regex) {
  62 + selectUnselectMatchingOptions(obj,regex,"select",false);
  63 + }
  64 +// -------------------------------------------------------------------
  65 +// selectOnlyMatchingOptions(select_object,regex)
  66 +// This function selects all options that match the regular expression
  67 +// passed in. Selected options that don't match will be un-selected.
  68 +// -------------------------------------------------------------------
  69 +function selectOnlyMatchingOptions(obj,regex) {
  70 + selectUnselectMatchingOptions(obj,regex,"select",true);
  71 + }
  72 +// -------------------------------------------------------------------
  73 +// unSelectMatchingOptions(select_object,regex)
  74 +// This function Unselects all options that match the regular expression
  75 +// passed in.
  76 +// -------------------------------------------------------------------
  77 +function unSelectMatchingOptions(obj,regex) {
  78 + selectUnselectMatchingOptions(obj,regex,"unselect",false);
  79 + }
  80 +
  81 +// -------------------------------------------------------------------
  82 +// sortSelect(select_object)
  83 +// Pass this function a SELECT object and the options will be sorted
  84 +// by their text (display) values
  85 +// -------------------------------------------------------------------
  86 +function sortSelect(obj) {
  87 + var o = new Array();
  88 + if (obj.options==null) { return; }
  89 + for (var i=0; i<obj.options.length; i++) {
  90 + o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
  91 + }
  92 + if (o.length==0) { return; }
  93 + o = o.sort(
  94 + function(a,b) {
  95 + if ((a.text+"") < (b.text+"")) { return -1; }
  96 + if ((a.text+"") > (b.text+"")) { return 1; }
  97 + return 0;
  98 + }
  99 + );
  100 +
  101 + for (var i=0; i<o.length; i++) {
  102 + obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
  103 + }
  104 + }
  105 +
  106 +// -------------------------------------------------------------------
  107 +// selectAllOptions(select_object)
  108 +// This function takes a select box and selects all options (in a
  109 +// multiple select object). This is used when passing values between
  110 +// two select boxes. Select all options in the right box before
  111 +// submitting the form so the values will be sent to the server.
  112 +// -------------------------------------------------------------------
  113 +function selectAllOptions(obj) {
  114 + for (var i=0; i<obj.options.length; i++) {
  115 + obj.options[i].selected = true;
  116 + }
  117 + }
  118 +
  119 +// -------------------------------------------------------------------
  120 +// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
  121 +// This function moves options between select boxes. Works best with
  122 +// multi-select boxes to create the common Windows control effect.
  123 +// Passes all selected values from the first object to the second
  124 +// object and re-sorts each box.
  125 +// If a third argument of 'false' is passed, then the lists are not
  126 +// sorted after the move.
  127 +// If a fourth string argument is passed, this will function as a
  128 +// Regular Expression to match against the TEXT or the options. If
  129 +// the text of an option matches the pattern, it will NOT be moved.
  130 +// It will be treated as an unmoveable option.
  131 +// You can also put this into the <SELECT> object as follows:
  132 +// onDblClick="moveSelectedOptions(this,this.form.target)
  133 +// This way, when the user double-clicks on a value in one box, it
  134 +// will be transferred to the other (in browsers that support the
  135 +// onDblClick() event handler).
  136 +// -------------------------------------------------------------------
  137 +function moveSelectedOptions(from,to) {
  138 + // Unselect matching options, if required
  139 + if (arguments.length>3) {
  140 + var regex = arguments[3];
  141 + if (regex != "") {
  142 + unSelectMatchingOptions(from,regex);
  143 + }
  144 + }
  145 + // Move them over
  146 + for (var i=0; i<from.options.length; i++) {
  147 + var o = from.options[i];
  148 + if (o.selected) {
  149 + to.options[to.options.length] = new Option( o.text, o.value, false, false);
  150 + }
  151 + }
  152 + // Delete them from original
  153 + for (var i=(from.options.length-1); i>=0; i--) {
  154 + var o = from.options[i];
  155 + if (o.selected) {
  156 + from.options[i] = null;
  157 + }
  158 + }
  159 + if ((arguments.length<3) || (arguments[2]==true)) {
  160 + sortSelect(from);
  161 + sortSelect(to);
  162 + }
  163 + from.selectedIndex = -1;
  164 + to.selectedIndex = -1;
  165 + }
  166 +
  167 +// -------------------------------------------------------------------
  168 +// copySelectedOptions(select_object,select_object[,autosort(true/false)])
  169 +// This function copies options between select boxes instead of
  170 +// moving items. Duplicates in the target list are not allowed.
  171 +// -------------------------------------------------------------------
  172 +function copySelectedOptions(from,to) {
  173 + var options = new Object();
  174 + for (var i=0; i<to.options.length; i++) {
  175 + options[to.options[i].text] = true;
  176 + }
  177 + for (var i=0; i<from.options.length; i++) {
  178 + var o = from.options[i];
  179 + if (o.selected) {
  180 + if (options[o.text] == null || options[o.text] == "undefined") {
  181 + to.options[to.options.length] = new Option( o.text, o.value, false, false);
  182 + }
  183 + }
  184 + }
  185 + if ((arguments.length<3) || (arguments[2]==true)) {
  186 + sortSelect(to);
  187 + }
  188 + from.selectedIndex = -1;
  189 + to.selectedIndex = -1;
  190 + }
  191 +
  192 +// -------------------------------------------------------------------
  193 +// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
  194 +// Move all options from one select box to another.
  195 +// -------------------------------------------------------------------
  196 +function moveAllOptions(from,to) {
  197 + selectAllOptions(from);
  198 + if (arguments.length==2) {
  199 + moveSelectedOptions(from,to);
  200 + }
  201 + else if (arguments.length==3) {
  202 + moveSelectedOptions(from,to,arguments[2]);
  203 + }
  204 + else if (arguments.length==4) {
  205 + moveSelectedOptions(from,to,arguments[2],arguments[3]);
  206 + }
  207 + }
  208 +
  209 +// -------------------------------------------------------------------
  210 +// copyAllOptions(select_object,select_object[,autosort(true/false)])
  211 +// Copy all options from one select box to another, instead of
  212 +// removing items. Duplicates in the target list are not allowed.
  213 +// -------------------------------------------------------------------
  214 +function copyAllOptions(from,to) {
  215 + selectAllOptions(from);
  216 + if (arguments.length==2) {
  217 + copySelectedOptions(from,to);
  218 + }
  219 + else if (arguments.length==3) {
  220 + copySelectedOptions(from,to,arguments[2]);
  221 + }
  222 + }
  223 +
  224 +// -------------------------------------------------------------------
  225 +// swapOptions(select_object,option1,option2)
  226 +// Swap positions of two options in a select list
  227 +// -------------------------------------------------------------------
  228 +function swapOptions(obj,i,j) {
  229 + var o = obj.options;
  230 + var i_selected = o[i].selected;
  231 + var j_selected = o[j].selected;
  232 + var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
  233 + var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
  234 + o[i] = temp2;
  235 + o[j] = temp;
  236 + o[i].selected = j_selected;
  237 + o[j].selected = i_selected;
  238 + }
  239 +
  240 +// -------------------------------------------------------------------
  241 +// moveOptionUp(select_object)
  242 +// Move selected option in a select list up one
  243 +// -------------------------------------------------------------------
  244 +function moveOptionUp(obj) {
  245 + // If > 1 option selected, do nothing
  246 + var selectedCount=0;
  247 + for (i=0; i<obj.options.length; i++) {
  248 + if (obj.options[i].selected) {
  249 + selectedCount++;
  250 + }
  251 + }
  252 + if (selectedCount!=1) {
  253 + return;
  254 + }
  255 + // If this is the first item in the list, do nothing
  256 + var i = obj.selectedIndex;
  257 + if (i == 0) {
  258 + return;
  259 + }
  260 + swapOptions(obj,i,i-1);
  261 + obj.options[i-1].selected = true;
  262 + }
  263 +
  264 +// -------------------------------------------------------------------
  265 +// moveOptionDown(select_object)
  266 +// Move selected option in a select list down one
  267 +// -------------------------------------------------------------------
  268 +function moveOptionDown(obj) {
  269 + // If > 1 option selected, do nothing
  270 + var selectedCount=0;
  271 + for (i=0; i<obj.options.length; i++) {
  272 + if (obj.options[i].selected) {
  273 + selectedCount++;
  274 + }
  275 + }
  276 + if (selectedCount != 1) {
  277 + return;
  278 + }
  279 + // If this is the last item in the list, do nothing
  280 + var i = obj.selectedIndex;
  281 + if (i == (obj.options.length-1)) {
  282 + return;
  283 + }
  284 + swapOptions(obj,i,i+1);
  285 + obj.options[i+1].selected = true;
  286 + }
  287 +
  288 +// -------------------------------------------------------------------
  289 +// removeSelectedOptions(select_object)
  290 +// Remove all selected options from a list
  291 +// (Thanks to Gene Ninestein)
  292 +// -------------------------------------------------------------------
  293 +function removeSelectedOptions(from) {
  294 + for (var i=(from.options.length-1); i>=0; i--) {
  295 + var o=from.options[i];
  296 + if (o.selected) {
  297 + from.options[i] = null;
  298 + }
  299 + }
  300 + from.selectedIndex = -1;
  301 + }
  302 +
  303 +
  304 +/* SOURCE FILE: OptionTransfer.js */
  305 +
  306 +/*
  307 +OptionTransfer.js
  308 +Last Modified: 11/18/2002
  309 +
  310 +DESCRIPTION: This widget is used to easily and quickly create an interface
  311 +where the user can transfer choices from one select box to another. For
  312 +example, when selecting which columns to show or hide in search results.
  313 +This object adds value by automatically storing the values that were added
  314 +or removed from each list, as well as the state of the final list.
  315 +
  316 +COMPATABILITY: Should work on all Javascript-compliant browsers.
  317 +
  318 +USAGE:
  319 +// Create a new OptionTransfer object. Pass it the field names of the left
  320 +// select box and the right select box.
  321 +var ot = new OptionTransfer("from","to");
  322 +
  323 +// Optionally tell the lists whether or not to auto-sort when options are
  324 +// moved. By default, the lists will be sorted.
  325 +ot.setAutoSort(true);
  326 +
  327 +// Optionally set the delimiter to be used to separate values that are
  328 +// stored in hidden fields for the added and removed options, as well as
  329 +// final state of the lists. Defaults to a comma.
  330 +ot.setDelimiter("|");
  331 +
  332 +// These functions assign the form fields which will store the state of
  333 +// the lists. Each one is optional, so you can pick to only store the
  334 +// new options which were transferred to the right list, for example.
  335 +// Each function takes the name of a HIDDEN or TEXT input field.
  336 +
  337 +// Store list of options removed from left list into an input field
  338 +ot.saveRemovedLeftOptions("removedLeft");
  339 +// Store list of options removed from right list into an input field
  340 +ot.saveRemovedRightOptions("removedRight");
  341 +// Store list of options added to left list into an input field
  342 +ot.saveAddedLeftOptions("addedLeft");
  343 +// Store list of options radded to right list into an input field
  344 +ot.saveAddedRightOptions("addedRight");
  345 +// Store all options existing in the left list into an input field
  346 +ot.saveNewLeftOptions("newLeft");
  347 +// Store all options existing in the right list into an input field
  348 +ot.saveNewRightOptions("newRight");
  349 +
  350 +// IMPORTANT: This step is required for the OptionTransfer object to work
  351 +// correctly.
  352 +// Add a call to the BODY onLoad="" tag of the page, and pass a reference to
  353 +// the form which contains the select boxes and input fields.
  354 +BODY onLoad="ot.init(document.forms[0])"
  355 +
  356 +// ADDING ACTIONS INTO YOUR PAGE
  357 +// Finally, add calls to the object to move options back and forth, either
  358 +// from links in your page or from double-clicking the options themselves.
  359 +// See example page, and use the following methods:
  360 +ot.transferRight();
  361 +ot.transferAllRight();
  362 +ot.transferLeft();
  363 +ot.transferAllLeft();
  364 +
  365 +
  366 +NOTES:
  367 +1) Requires the functions in selectbox.js
  368 +
  369 +*/
  370 +function OT_transferLeft() { moveSelectedOptions(this.right,this.left,this.autoSort); this.update(); }
  371 +function OT_transferRight() { moveSelectedOptions(this.left,this.right,this.autoSort); this.update(); }
  372 +function OT_transferAllLeft() { moveAllOptions(this.right,this.left,this.autoSort); this.update(); }
  373 +function OT_transferAllRight() { moveAllOptions(this.left,this.right,this.autoSort); this.update(); }
  374 +function OT_saveRemovedLeftOptions(f) { this.removedLeftField = f; }
  375 +function OT_saveRemovedRightOptions(f) { this.removedRightField = f; }
  376 +function OT_saveAddedLeftOptions(f) { this.addedLeftField = f; }
  377 +function OT_saveAddedRightOptions(f) { this.addedRightField = f; }
  378 +function OT_saveNewLeftOptions(f) { this.newLeftField = f; }
  379 +function OT_saveNewRightOptions(f) { this.newRightField = f; }
  380 +function OT_update() {
  381 + var removedLeft = new Object();
  382 + var removedRight = new Object();
  383 + var addedLeft = new Object();
  384 + var addedRight = new Object();
  385 + var newLeft = new Object();
  386 + var newRight = new Object();
  387 + for (var i=0;i<this.left.options.length;i++) {
  388 + var o=this.left.options[i];
  389 + newLeft[o.value]=1;
  390 + if (typeof(this.originalLeftValues[o.value])=="undefined") {
  391 + addedLeft[o.value]=1;
  392 + removedRight[o.value]=1;
  393 + }
  394 + }
  395 + for (var i=0;i<this.right.options.length;i++) {
  396 + var o=this.right.options[i];
  397 + newRight[o.value]=1;
  398 + if (typeof(this.originalRightValues[o.value])=="undefined") {
  399 + addedRight[o.value]=1;
  400 + removedLeft[o.value]=1;
  401 + }
  402 + }
  403 + if (this.removedLeftField!=null) { this.removedLeftField.value = OT_join(removedLeft,this.delimiter); }
  404 + if (this.removedRightField!=null) { this.removedRightField.value = OT_join(removedRight,this.delimiter); }
  405 + if (this.addedLeftField!=null) { this.addedLeftField.value = OT_join(addedLeft,this.delimiter); }
  406 + if (this.addedRightField!=null) { this.addedRightField.value = OT_join(addedRight,this.delimiter); }
  407 + if (this.newLeftField!=null) { this.newLeftField.value = OT_join(newLeft,this.delimiter); }
  408 + if (this.newRightField!=null) { this.newRightField.value = OT_join(newRight,this.delimiter); }
  409 + }
  410 +function OT_join(o,delimiter) {
  411 + var val; var str="";
  412 + for(val in o){
  413 + if (str.length>0) { str=str+delimiter; }
  414 + str=str+val;
  415 + }
  416 + return str;
  417 + }
  418 +function OT_setDelimiter(val) { this.delimiter=val; }
  419 +function OT_setAutoSort(val) { this.autoSort=val; }
  420 +function OT_init(theform) {
  421 + this.form = theform;
  422 + if(!theform[this.left]){alert("OptionTransfer init(): Left select list does not exist in form!");return false;}
  423 + if(!theform[this.right]){alert("OptionTransfer init(): Right select list does not exist in form!");return false;}
  424 + this.left=theform[this.left];
  425 + this.right=theform[this.right];
  426 + for(var i=0;i<this.left.options.length;i++) {
  427 + this.originalLeftValues[this.left.options[i].value]=1;
  428 + }
  429 + for(var i=0;i<this.right.options.length;i++) {
  430 + this.originalRightValues[this.right.options[i].value]=1;
  431 + }
  432 + if(this.removedLeftField!=null) { this.removedLeftField=theform[this.removedLeftField]; }
  433 + if(this.removedRightField!=null) { this.removedRightField=theform[this.removedRightField]; }
  434 + if(this.addedLeftField!=null) { this.addedLeftField=theform[this.addedLeftField]; }
  435 + if(this.addedRightField!=null) { this.addedRightField=theform[this.addedRightField]; }
  436 + if(this.newLeftField!=null) { this.newLeftField=theform[this.newLeftField]; }
  437 + if(this.newRightField!=null) { this.newRightField=theform[this.newRightField]; }
  438 + this.update();
  439 + }
  440 +// -------------------------------------------------------------------
  441 +// OptionTransfer()
  442 +// This is the object interface.
  443 +// -------------------------------------------------------------------
  444 +function OptionTransfer(l,r) {
  445 + this.form = null;
  446 + this.left=l;
  447 + this.right=r;
  448 + this.autoSort=true;
  449 + this.delimiter=",";
  450 + this.originalLeftValues = new Object();
  451 + this.originalRightValues = new Object();
  452 + this.removedLeftField = null;
  453 + this.removedRightField = null;
  454 + this.addedLeftField = null;
  455 + this.addedRightField = null;
  456 + this.newLeftField = null;
  457 + this.newRightField = null;
  458 + this.transferLeft=OT_transferLeft;
  459 + this.transferRight=OT_transferRight;
  460 + this.transferAllLeft=OT_transferAllLeft;
  461 + this.transferAllRight=OT_transferAllRight;
  462 + this.saveRemovedLeftOptions=OT_saveRemovedLeftOptions;
  463 + this.saveRemovedRightOptions=OT_saveRemovedRightOptions;
  464 + this.saveAddedLeftOptions=OT_saveAddedLeftOptions;
  465 + this.saveAddedRightOptions=OT_saveAddedRightOptions;
  466 + this.saveNewLeftOptions=OT_saveNewLeftOptions;
  467 + this.saveNewRightOptions=OT_saveNewRightOptions;
  468 + this.setDelimiter=OT_setDelimiter;
  469 + this.setAutoSort=OT_setAutoSort;
  470 + this.init=OT_init;
  471 + this.update=OT_update;
  472 + }