Ejemplo n.º 1
0
	function sendNewMessage($fromid, $toid, $message, $sendnotification=0, $updatelastsent=0) {

		if ($this->config->cryptmode>=1)
			$savemessage = strip_tags($message);
		else
			$savemessage = addslashes(strip_tags($message));

		$date  = uddetime($this->config->timezone);
		$replyid = 0;
		$cryptmode = $this->config->cryptmode;
		$insID = uddeIMsaveRAWmessage($fromid, $toid, $replyid, $savemessage, $date, $this->config, $cryptmode);

		if ($updatelastsent) {
			if (!uddeIMexistsEMN((int)$fromid))
				uddeIMinsertEMNdefaults((int)$fromid, $this->config);
			uddeIMupdateEMNlastsent($fromid, $date);
		}

		if ($sendnotification) {
			// Check if E-Mail notification or popups are enabled by default, if so create a record for the receiver.
			// Note: Not necessary for "copy to myself" sind the record for the current user has been set at the very beginning...
			if ($this->config->notifydefault>0 || $this->config->popupdefault>0 || $this->config->pubfrontenddefault>0 || $this->config->autoresponder>0 || $this->config->autoforward>0) {
				if (!uddeIMexistsEMN($toid))
					uddeIMinsertEMNdefaults($toid, $this->config);
			}
		}

		// get the group ID of the recipient
		$gid = uddeIMgetGID((int)$toid);

		// ##################################################################################################
		// autoforward code
		// ##################################################################################################
		if ($this->config->autoforward==1 || 
		   ($this->config->autoforward==2 && (uddeIMisAdmin($gid)   || uddeIMisAdmin2($gid, $this->config))) ||
		   ($this->config->autoforward==3 && (uddeIMisSpecial($gid) || uddeIMisSpecial2($my_gid, $this->config))) ) {
			$ison = uddeIMgetEMNautoforward($toid);						// recipient has autoforward enabled
			if ($ison==1) {
				$autoforwardid = uddeIMgetEMNautoforwardid($toid);	// new recipient

				if (uddeIMgetUserExists($autoforwardid)) {
					if (!uddeIMgetUserBlock($autoforwardid)) {
						$temp = uddeIMgetNameFromID($toid, $this->config);
						$temp = (($this->config->cryptmode>=1) ? $temp : addslashes($temp));
						if ($this->config->allowbb)
							$forwardheader="\n\n[i]("._UDDEIM_THISISAFORWARD.$temp.")[/i]";
						else
							$forwardheader="\n\n("._UDDEIM_THISISAFORWARD.$temp.")";
						$savemessagecopy = $savemessage.$forwardheader;
						$insIDforward = uddeIMsaveRAWmessage($fromid, $autoforwardid, 0, $savemessagecopy, $date, $this->config, $this->config->cryptmode, "");
					}
				}
			}
		}

		// ##################################################################################################
		// copy to myself?
		// ##################################################################################################

		// nothing to do

		// ##################################################################################################
		// autoresponder
		// ##################################################################################################

		// nothing to do

		// ##################################################################################################
		// email notification
		// ##################################################################################################

		if ($sendnotification) {
			$currentlyonline = uddeIMisOnline($toid);

			if ($this->config->cryptmode>=1) {
				$email = stripslashes($savemessage);
			} else {
				$email = stripslashes(stripslashes($savemessage));
			}
			
			if($this->config->allowemailnotify==1) {
				$ison = uddeIMgetEMNstatus($toid);
				if (($ison==1) || ($ison==2 && !$currentlyonline) || $ison==10 || ($ison==20 && !$currentlyonline)) {
					uddeIMdispatchEMN($insID, $item_id, $cryptmode, $fromid, $toid, $email, 0, $this->config);
				}
			} elseif($this->config->allowemailnotify==2) {
				if (uddeIMisAdmin($gid) || uddeIMisAdmin2($gid, $this->config)) {
					$ison = uddeIMgetEMNstatus($toid);
					if (($ison==1) || ($ison==2 && !$currentlyonline) || $ison==10  || ($ison==20 && !$currentlyonline)) {
						uddeIMdispatchEMN($insID, $item_id, $cryptmode, $fromid, $toid, $email, 0, $this->config);
					}
				}
			}
		}
		return $insID;
	}
Ejemplo n.º 2
0
function uddeIMtoPublicSaveMessage($myself, $pmessage, $tobedeleted, $tobedeletedsent, $forceembedded, $item_id, $messageid, $copytome, $cryptpass, $backto, $config) {
	$mosConfig_sitename = uddeIMgetSitename();
	$pathtosite  = uddeIMgetPath('live_site');

	$database = uddeIMgetDatabase();
	$my_gid = $config->usergid;

	if($config->inboxlimit) {
		if ($config->allowarchive) {		// have an archive and an "archive and inbox" limit, so get number of messages in inbox and archive
			$total = uddeIMgetInboxArchiveCount($myself);
		} else {							// user has switched of archive but there is an limit for "inbox and archive", so count inbox messages only
			$total = uddeIMgetInboxCount($myself);
		}
		if($total>$config->maxarchive && !uddeIMisAdmin($my_gid) && !uddeIMisAdmin2($my_gid, $config)) {
			$mosmsg=_UDDEIM_MSGLIMITREACHED;
			uddeJSEFredirect("index.php?option=com_uddeim&task=inbox&Itemid=".$item_id, $mosmsg);
		}
	}

	$lastsent = uddeIMgetEMNlastsent($myself);
	$flooding = 0;
	if ($config->timedelay>0) {
		if (uddeIMisReggedOnly($config->usergid)) {
			if ($lastsent) {
				$delay = uddetime($config->timezone) - $lastsent;
				if ($delay <= $config->timedelay)
					$flooding = 1;
			}
		}
	}
	if($flooding) {
		// write the uddeim menu
		uddeIMprintMenu($myself, 'new', $item_id, $config);
		echo "<div id='uddeim-m'>\n";
		$pmessage=stripslashes($pmessage);
		uddeIMdrawWriteform($myself, $my_gid, $item_id, "", "", $pmessage, $messageid, 1, 14, 0, $config);	// reply!!!
		echo "</div>\n<div id='uddeim-bottomborder'>".uddeIMcontentBottomborder($myself, $item_id, 'standard', 'none', $config)."</div>\n";
		return;
	}
	
	// select the message I write a reply to
	// I need the email address and the sender name of the public user (the message id is $messageid and I am $myself)
	// das war vorher... a.toid=b.id??? richtig sollte a.fromid=b.id sein, also selectInboxMessage nehmen
	// $sql = "SELECT a.*, b.".($config->realnames ? "name" : "username")." AS fromname FROM #__uddeim AS a LEFT JOIN #__users AS b ON a.toid=b.id WHERE a.toid=".(int)$myself." AND a.id=".(int)$messageid;
	$displaymessages = 	uddeIMselectInboxMessage($myself, $messageid, $config);
	if (count($displaymessages)<1) {
		echo _UDDEIM_MESSAGENOACCESS;
		return;
	}
	foreach($displaymessages as $displaymessage) {
		$var_toname = $displaymessage->publicname;
		$var_tomail = $displaymessage->publicemail;
	}
	if (!$var_toname || $var_toname==NULL)
		$var_toname = _UDDEIM_PUBLICUSER;
	
	if(!$pmessage) {
		// write the uddeim menu
		uddeIMprintMenu($myself, 'new', $item_id, $config);
		echo "<div id='uddeim-m'>\n";
		$pmessage=stripslashes($pmessage);
		uddeIMdrawWriteform($myself, $my_gid, $item_id, "", "", $pmessage, $messageid, 1, 4, 0, $config);	// reply!!!
		echo "</div>\n<div id='uddeim-bottomborder'>".uddeIMcontentBottomborder($myself, $item_id, 'standard', 'none', $config)."</div>\n";
		return;
	}

	// CAPTCHA (first check for all other errors and then the CAPTCHA)
	if (!uddeIMcheckCAPTCHA($my_gid, $config)) {
		uddeIMprintMenu($myself, 'new', $item_id, $config);
		echo "<div id='uddeim-m'>\n";
		$pmessage=stripslashes($pmessage);
		uddeIMdrawWriteform($myself, $my_gid, $item_id, "", "", $pmessage, $messageid, 1, 7, 0, $config);	// reply!!!
		echo "</div>\n<div id='uddeim-bottomborder'>".uddeIMcontentBottomborder($myself, $item_id, 'standard', 'none', $config)."</div>\n";
		return;
	}

	if (!uddeIMcheckCSRF($config)) {
		uddeIMprintMenu($myself, 'new', $item_id, $config);
		echo "<div id='uddeim-m'>\n";
		$pmessage=stripslashes($pmessage);
		uddeIMdrawWriteform($myself, $my_gid, $item_id, "", "", $pmessage, $messageid, 1, 15, 0, $config);	// reply!!!
		echo "</div>\n<div id='uddeim-bottomborder'>".uddeIMcontentBottomborder($myself, $item_id, 'standard', 'none', $config)."</div>\n";
		return;
	}

	$savedatum  = uddetime($config->timezone);
	$savetoid   = 0;			// reveiver is a public user

	// CRYPT
	if ($config->cryptmode>=1) {	// because of encoding do not use slashes
		$savemessage=strip_tags($pmessage);
	} else {
		$savemessage=addslashes(strip_tags($pmessage));   // original 0.6+
	}
	// strip XSS code
	$savemessage = uddeIMRemoveXSS($savemessage);

	// strip bbcodes
	if (!$config->allowbb)
		$savemessage=uddeIMbbcode_strip($savemessage);

	// set message max length
	if ($config->maxlength>0)		// because if 0 do not use any maxlength
		$savemessage=uddeIM_utf8_substr($config->languagecharset, $savemessage, 0, $config->maxlength);

	uddeIMemit("onSavePublicMessage", Array( "fromid" => $myself, "toid" => $savetoid, "replyid" => $replyid ) );
	// we have all we need, now save it
	// CRYPT
	// maybe its an reply to a message from a public user
	$replyid = $messageid;
	$fromname=addslashes(strip_tags($var_toname));
	$fromemail=addslashes(strip_tags($var_tomail));
	if ($config->cryptmode==1) {
		$cm = uddeIMencrypt($savemessage,$config->cryptkey,CRYPT_MODE_BASE64);
		$sql="INSERT INTO #__uddeim (publicname, publicemail, fromid, toid, replyid, message, datum, totrash, totrashdate, toread, cryptmode, crypthash) VALUES ('".$fromname."', '".$fromemail."', ".(int)$myself.", ".(int)$savetoid.", ".(int)$replyid.", '".$cm."', ".$savedatum.",1,".$savedatum.",1,1,'".md5($config->cryptkey)."')";
	} elseif ($config->cryptmode==2) {
		$themode=2;
		$thepass=$cryptpass;
		if (!$thepass) {	// no password entered, then fallback to obfuscating
			$themode=1;
			$thepass=$config->cryptkey;
		}
		$cm = uddeIMencrypt($savemessage,$thepass,CRYPT_MODE_BASE64);
		$sql="INSERT INTO #__uddeim (publicname, publicemail, fromid, toid, replyid, message, datum, totrash, totrashdate, toread, cryptmode, crypthash) VALUES ('".$fromname."', '".$fromemail."', ".(int)$myself.", ".(int)$savetoid.", ".(int)$replyid.", '".$cm."', ".$savedatum.",1,".$savedatum.",1,".$themode.",'".md5($thepass)."')";
	} elseif ($config->cryptmode==3) {
		$cm = uddeIMencrypt($savemessage,"",CRYPT_MODE_STOREBASE64);
		$sql="INSERT INTO #__uddeim (publicname, publicemail, fromid, toid, replyid, message, datum, totrash, totrashdate, toread, cryptmode) VALUES ('".$fromname."', '".$fromemail."', ".(int)$myself.", ".(int)$savetoid.", ".(int)$replyid.", '".$cm."', ".$savedatum.",1,".$savedatum.",1,3)";
	} elseif ($config->cryptmode==4) {
		$themode=4;
		$thepass=$cryptpass;
		$cipher = CRYPT_MODE_3DESBASE64;
		if (!$thepass) {	// no password entered, then fallback to obfuscating
			$themode=1;
			$thepass=$config->cryptkey;
			$cipher = CRYPT_MODE_BASE64;
		}
		$cm = uddeIMencrypt($savemessage,$thepass,$cipher);
		$sql="INSERT INTO #__uddeim (publicname, publicemail, fromid, toid, replyid, message, datum, totrash, totrashdate, toread, cryptmode, crypthash) VALUES ('".$fromname."', '".$fromemail."', ".(int)$myself.", ".(int)$savetoid.", ".(int)$replyid.", '".$cm."', ".$savedatum.",1,".$savedatum.",1,".$themode.",'".md5($thepass)."')";
	} else {
		$sql="INSERT INTO #__uddeim (publicname, publicemail, fromid, toid, replyid, message, datum, totrash, totrashdate, toread) VALUES ('".$fromname."', '".$fromemail."', ".(int)$myself.", ".(int)$savetoid.", ".(int)$replyid.", '".$savemessage."', ".$savedatum.",1,".$savedatum.",1)";
	}
	$database->setQuery($sql);
	if (!$database->query()) {
		die("SQL error when attempting to save a message" . $database->stderr(true));
	}
	$insID = $database->insertid();

	// update lastsent field (record already exists since we check this at the very beginning of this component)
	uddeIMupdateEMNlastsent($myself, uddetime($config->timezone));

	// copy to myself?
	if($copytome && $config->allowcopytome) {

		$temp = (($config->cryptmode>=1) ? $var_toname : addslashes($var_toname));
		if ($config->allowbb)
			$copyheader="\n\n[i]("._UDDEIM_THISISACOPY.$temp.")[/i]";
		else
			$copyheader="\n\n("._UDDEIM_THISISACOPY.$temp.")";

		// also copy2me messages can be replies
		$replyid = $messageid;
		$savemessagecopy = $savemessage.$copyheader;
		$copyname = _UDDEIM_TO_SMALL." ".$temp;			// "to username" in systemmsg
		// if($config->allowarchive) { $archiveflag=1; }

		// it is a copy to myself, so assume that the message has already been trashed in the senders outbox (remember: system messages are not shown in the outbox)
		// so set totrashoutbox=1, totrashdateoutbox=uddetime($config->timezone)
		// CRYPT
		if ($config->cryptmode==1) {
			$cm = uddeIMencrypt($savemessagecopy,$config->cryptkey,CRYPT_MODE_BASE64);
			$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, archived, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$myself.", ".(int)$myself.", ".(int)$replyid.", 1, '".$cm."', ".$savedatum.", 1, 2, '".$copyname."', 0, 1,".$savedatum.",1,'".md5($config->cryptkey)."')";
		} elseif ($config->cryptmode==2) {
			$themode=2;
			$thepass=$cryptpass;
			if (!$thepass) {	// no password entered, then fallback to obfuscating
				$themode=1;
				$thepass=$config->cryptkey;
			}
			$cm = uddeIMencrypt($savemessagecopy,$thepass,CRYPT_MODE_BASE64);
			$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, archived, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$myself.", ".(int)$myself.", ".(int)$replyid.", 1, '".$cm.             "', ".$savedatum.", 1, 2, '".$copyname."', 0, 1,".$savedatum.",".$themode.",'".md5($thepass)."')";
		} elseif ($config->cryptmode==3) {
			$cm = uddeIMencrypt($savemessagecopy,"",CRYPT_MODE_STOREBASE64);
			$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, archived, totrashoutbox, totrashdateoutbox, cryptmode) VALUES (".(int)$myself.", ".(int)$myself.", ".(int)$replyid.", 1, '".$cm."', ".$savedatum.", 1, 2, '".$copyname."', 0, 1,".$savedatum.",3)";
		} elseif ($config->cryptmode==4) {
			$themode=4;
			$thepass=$cryptpass;
			$cipher = CRYPT_MODE_3DESBASE64;
			if (!$thepass) {	// no password entered, then fallback to obfuscating
				$themode=1;
				$thepass=$config->cryptkey;
				$cipher = CRYPT_MODE_BASE64;
			}
			$cm = uddeIMencrypt($savemessagecopy,$thepass,$cipher);
			$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, archived, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$myself.", ".(int)$myself.", ".(int)$replyid.", 1, '".$cm.             "', ".$savedatum.", 1, 2, '".$copyname."', 0, 1,".$savedatum.",".$themode.",'".md5($thepass)."')";
		} else {
			$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, archived, totrashoutbox, totrashdateoutbox) VALUES (".(int)$myself.", ".(int)$myself.", ".(int)$replyid.", 1, '".$savemessagecopy."', ".$savedatum.", 1, 2, '".$copyname."', 0, 1,".$savedatum.")";
		}
		$database->setQuery($sql);
		if (!$database->query()) {
			die("SQL error when attempting to save a message" . $database->stderr(true));
		}
	}

	// send notification (message) to public user
	// check if we have an email address
	//	uddeIMdispatchEMN(msgid, $myself, 0, $savemessage, 0, $config);
	// if e-mail traffic stopped, don't send.
	if($config->emailtrafficenabled && $var_tomail) {

		$var_fromname = uddeIMgetNameFromID($myself, $config);
		if (!$var_fromname)
			$var_fromname=$config->sysm_username;

		$var_body = _UDDEIM_EMN_BODY_PUBLICWITHMESSAGE;
		$var_body = str_replace("%livesite%", $pathtosite, $var_body);
		$var_body = str_replace("%you%", $var_toname, $var_body);
		$var_body = str_replace("%site%", $mosConfig_sitename, $var_body);
		$var_body = str_replace("%user%", $var_fromname, $var_body);
		$var_body = str_replace("%pmessage%", $savemessage, $var_body);

		$subject = _UDDEIM_EMN_SUBJECT;
		$subject = str_replace("%livesite%", $pathtosite, $subject);
		$subject = str_replace("%site%", $mosConfig_sitename, $subject);
		$subject = str_replace("%you%", $var_toname, $subject);
		$subject = str_replace("%user%", $var_fromname, $subject);

		$replyto = $var_tomail;
		$replytoname = "";

		if(uddeIMsendmail($config->emn_sendername, $config->emn_sendermail, $var_toname, $var_tomail, $subject, $var_body, $replyto, $replytoname, "", $config)) {
			// maybe a code here that the email cound not have been sent
		}
	}

	if ($tobedeletedsent) {
		$deletetime=uddetime($config->timezone);
		uddeIMdeleteMessageFromOutbox($myself, $insID, $deletetime);
	}

	// delete the original message?
	if ($tobedeleted) {
		$deletetime=uddetime($config->timezone);
		uddeIMdeleteMessageFromInbox($myself, $messageid, $deletetime);
	}

	if($messageid) {
		$mosmsg=_UDDEIM_MESSAGE_REPLIEDTO;
	} else {
		$mosmsg=_UDDEIM_MESSAGE_SENT;
	}
	if ($tobedeleted) {
		$mosmsg.=_UDDEIM_MOVEDTOTRASH;
	}

	if($backto) {
		uddeIMmosRedirect($backto, $mosmsg);
	}
	uddeJSEFredirect("index.php?option=com_uddeim&task=inbox&Itemid=".$item_id, $mosmsg);
}