| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Rev$ | $LastChangedBy$ |
|---|
| 4 | $LastChangedDate$ |
|---|
| 5 | +-------------------------------------------------------------------------+ |
|---|
| 6 | | Copyright (c) 2004 - 2010, Kreotek LLC | |
|---|
| 7 | | All rights reserved. | |
|---|
| 8 | +-------------------------------------------------------------------------+ |
|---|
| 9 | | | |
|---|
| 10 | | Redistribution and use in source and binary forms, with or without | |
|---|
| 11 | | modification, are permitted provided that the following conditions are | |
|---|
| 12 | | met: | |
|---|
| 13 | | | |
|---|
| 14 | | - Redistributions of source code must retain the above copyright | |
|---|
| 15 | | notice, this list of conditions and the following disclaimer. | |
|---|
| 16 | | | |
|---|
| 17 | | - Redistributions in binary form must reproduce the above copyright | |
|---|
| 18 | | notice, this list of conditions and the following disclaimer in the | |
|---|
| 19 | | documentation and/or other materials provided with the distribution. | |
|---|
| 20 | | | |
|---|
| 21 | | - Neither the name of Kreotek LLC nor the names of its contributore may | |
|---|
| 22 | | be used to endorse or promote products derived from this software | |
|---|
| 23 | | without specific prior written permission. | |
|---|
| 24 | | | |
|---|
| 25 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|---|
| 26 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|---|
| 27 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
|---|
| 28 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
|---|
| 29 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
|---|
| 30 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
|---|
| 31 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
|---|
| 32 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
|---|
| 33 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
|---|
| 34 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
|---|
| 35 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|---|
| 36 | | | |
|---|
| 37 | +-------------------------------------------------------------------------+ |
|---|
| 38 | */ |
|---|
| 39 | |
|---|
| 40 | require_once("../../include/session.php"); |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | function sendNoticeEmail($db, $noteid) { |
|---|
| 44 | |
|---|
| 45 | $querystatement=" |
|---|
| 46 | SELECT |
|---|
| 47 | subject, |
|---|
| 48 | assignedtoid, |
|---|
| 49 | assignedbyid, |
|---|
| 50 | content, |
|---|
| 51 | type, |
|---|
| 52 | assignedtodate, |
|---|
| 53 | assignedtotime, |
|---|
| 54 | startdate, |
|---|
| 55 | starttime, |
|---|
| 56 | enddate, |
|---|
| 57 | endtime |
|---|
| 58 | FROM |
|---|
| 59 | notes |
|---|
| 60 | WHERE |
|---|
| 61 | id=".((int) $noteid); |
|---|
| 62 | |
|---|
| 63 | $queryresult = $db->query($querystatement); |
|---|
| 64 | $therecord = $db->fetchArray($queryresult); |
|---|
| 65 | |
|---|
| 66 | $querystatement = " |
|---|
| 67 | SELECT |
|---|
| 68 | firstname, |
|---|
| 69 | lastname, |
|---|
| 70 | email |
|---|
| 71 | FROM |
|---|
| 72 | users |
|---|
| 73 | WHERE |
|---|
| 74 | uuid='".$therecord["assignedtoid"]."'"; |
|---|
| 75 | |
|---|
| 76 | $queryresult=$db->query($querystatement); |
|---|
| 77 | $torecord=$db->fetchArray($queryresult); |
|---|
| 78 | |
|---|
| 79 | if($torecord["email"]=="") |
|---|
| 80 | return "Assignee has no e-mail address set."; |
|---|
| 81 | |
|---|
| 82 | $querystatement = " |
|---|
| 83 | SELECT |
|---|
| 84 | firstname, |
|---|
| 85 | lastname, |
|---|
| 86 | email |
|---|
| 87 | FROM |
|---|
| 88 | users |
|---|
| 89 | WHERE uuid = '".$therecord["assignedbyid"]."'"; |
|---|
| 90 | |
|---|
| 91 | $queryresult=$db->query($querystatement); |
|---|
| 92 | $fromrecord=$db->fetchArray($queryresult); |
|---|
| 93 | if($fromrecord["email"]=="") |
|---|
| 94 | return "You have no e-mail address set."; |
|---|
| 95 | |
|---|
| 96 | $from="".trim($fromrecord["firstname"]." ".$fromrecord["lastname"])." <".$fromrecord["email"].">"; |
|---|
| 97 | |
|---|
| 98 | $subject=APPLICATION_NAME." Assignment: ".$therecord["subject"]; |
|---|
| 99 | switch($therecord["type"]){ |
|---|
| 100 | case "NT": |
|---|
| 101 | $therecord["type"]="note"; |
|---|
| 102 | break; |
|---|
| 103 | case "TS": |
|---|
| 104 | $therecord["type"]="task"; |
|---|
| 105 | break; |
|---|
| 106 | case "EV": |
|---|
| 107 | $therecord["type"]="event"; |
|---|
| 108 | break; |
|---|
| 109 | case "SY": |
|---|
| 110 | $therecord["type"]="system message"; |
|---|
| 111 | break; |
|---|
| 112 | } |
|---|
| 113 | if($_SERVER["SERVER_PORT"] == 443) |
|---|
| 114 | $protocol = "https"; |
|---|
| 115 | else |
|---|
| 116 | $protocol = "http"; |
|---|
| 117 | |
|---|
| 118 | $themessage= "You have received an e-mail notification of a ".$therecord["type"]." that has been assigned to you. To log in and view more details go to ".$protocol."://".$_SERVER["HTTP_HOST"].APP_PATH."\n\n"; |
|---|
| 119 | $themessage.="Title: ".$therecord["subject"]."\n\n"; |
|---|
| 120 | if($therecord["assignedtodate"]) { |
|---|
| 121 | $themessage.="Follow Up: ".$therecord["assignedtodate"]; |
|---|
| 122 | if($therecord["assignedtotime"]) |
|---|
| 123 | $themessage.=" ".$therecord["assignedtotime"]; |
|---|
| 124 | $themessage.="\n\n"; |
|---|
| 125 | } |
|---|
| 126 | if($therecord["type"]=="task"){ |
|---|
| 127 | if($therecord["startdate"]){ |
|---|
| 128 | $themessage.="Start Date: ".$therecord["startdate"]; |
|---|
| 129 | if($therecord["starttime"]) |
|---|
| 130 | $themessage.=" ".$therecord["starttime"]; |
|---|
| 131 | $themessage.="\n"; |
|---|
| 132 | } |
|---|
| 133 | if($therecord["enddate"]){ |
|---|
| 134 | $themessage.="Due Date: ".$therecord["enddate"]; |
|---|
| 135 | if($therecord["endtime"]) |
|---|
| 136 | $themessage.=" ".$therecord["endtime"]; |
|---|
| 137 | $themessage.="\n"; |
|---|
| 138 | } |
|---|
| 139 | $themessage.="\n"; |
|---|
| 140 | } |
|---|
| 141 | if($therecord["type"]=="event"){ |
|---|
| 142 | $themessage.="Start Date: ".$therecord["startdate"]; |
|---|
| 143 | if($therecord["starttime"]) |
|---|
| 144 | $themessage.=" ".$therecord["starttime"]; |
|---|
| 145 | $themessage.="\n"; |
|---|
| 146 | $themessage.="End Date: ".$therecord["enddate"]; |
|---|
| 147 | if($therecord["endtime"]) |
|---|
| 148 | $themessage.=" ".$therecord["endtime"]; |
|---|
| 149 | $themessage.="\n\n"; |
|---|
| 150 | } |
|---|
| 151 | $themessage.="Memo:\n".$therecord["content"]; |
|---|
| 152 | |
|---|
| 153 | if(! @ mail($torecord["email"],$subject,$themessage,"From: ".$from)) |
|---|
| 154 | return "Error Processing E-Mail."; |
|---|
| 155 | |
|---|
| 156 | return "E-Mail Sent."; |
|---|
| 157 | |
|---|
| 158 | }//end function |
|---|
| 159 | |
|---|
| 160 | //================================================================================================= |
|---|
| 161 | if(isset($_GET["cm"])){ |
|---|
| 162 | $thereturn=""; |
|---|
| 163 | switch($_GET["cm"]){ |
|---|
| 164 | case "sendemail": |
|---|
| 165 | $thereturn=sendNoticeEmail($db,$_GET["id"]); |
|---|
| 166 | break; |
|---|
| 167 | } |
|---|
| 168 | echo $thereturn; |
|---|
| 169 | } |
|---|
| 170 | ?> |
|---|