cbTabHandler(); } */ # Create form/text/content and insert in frontend! function showForm($userid, $publicmailTableWidth, $publicmailShowIntro, $publicmailShowAddress, $publicmailUseSubject, $publicmailUseCopy, $publicmailTextMaxlength, $publicmailTextRows, $publicmailTextCols) { global $my; # Javascript that checks that form has been filled in echo "\n"; # Javascript that makes maxlength in textarea work! ?> "; $content .= ""; $content .= ""; // Hvilken func i main-switch der skal loades om lidt! $content .= ""; // Her fortælles hvilken type der skal gemmes $itemId = mosGetParam( $_REQUEST, 'itemId', '' ); $content .= ""; // Hvis denne er sat betyder det at det er en edit og ikke en nyt indlæg! # Show the form content $content .= "
"; $content .= $publicmailShowIntro."
"; if ($publicmailShowAddress) { $email = $this->getProfileMail($userid); $content .= _PM_FORM_EMAIL." ".$email.""; } $content .= "
"; $content .= "
"; $content .= _PM_FORM_NAME.": username\" maxlength=\"40\">"; $content .= "
"; $content .= _PM_FORM_MAIL.": email\" maxlength=\"40\">"; $content .= "
"; $content .= _PM_FORM_CONTACT_NUMBER.": "; if ($publicmailUseSubject) { $content .= "
"; $content .= _PM_FORM_SUBJECT.": "; } $content .= "
"; $content .= "
"; $content .= _PM_FORM_MESSAGE.":
"; if ($publicmailUseCopy) { $content .= "
"; $content .= " "._PM_FORM_COPY; } $content .= "
"; $content .= ""; $content .= "
"; $content .= ""; return $content; } # Tjek om en email virkelig er en email function is_email($email){ $emailstatus=false; if(preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $email)) { $emailstatus=true; } return $emailstatus; } # Make the input save-safe function makeTextSafe($text) { $text = strip_tags($text); $text = mysql_escape_string($text); return $text; } # Get profileowners email function getProfileMail($userid) { global $database; # Find users email (perhaps this does not work if too many users has been deleted at recreated etc.) $database->setQuery( "SELECT email FROM #__users WHERE id='$userid'" ); $row = $database->loadObjectList(); $email = $row[0]->email; return $email; } # Get profileowners username function getProfileUsername($userid) { global $database; # Find users username (perhaps this does not work if too many users has been deleted at recreated etc.) $database->setQuery( "SELECT username FROM #__users WHERE id='$userid'" ); $row = $database->loadObjectList(); $username = $row[0]->username; return $username; } # Add/log sendt mail to database function addMailToDB($userid, $is_user, $name, $mail, $contact, $subj, $text) { global $database, $my; # Find all variables for database entry and make them safe if ($is_user) { $senderid = $my->id; } else { $senderid = _PM_LOG_USER_IS_UNKNOWN; }// Find user id $senderip = getenv('REMOTE_ADDR'); // Find user IP. Also $_SERVER['REMOTE_ADDR']; can be used! $sendername = $this->makeTextSafe($name); $sendermail = $this->makeTextSafe($mail); $recieverid = $this->makeTextSafe($userid); $recieverusername = $this->getProfileUsername($userid); $maildate = date("y/m/d g:i:s"); // Find current date and time acoording to the server $mailsubject = $this->makeTextSafe($subj); $mailtext = $this->makeTextSafe($text); $contact = $this->makeTextSafe($contact); # Inserting into database $query="INSERT INTO #__comprofiler_plug_publicmail SET senderid='$senderid', senderip='$senderip', sendername='$sendername', sendermail='$sendermail', recieverid='$recieverid', recieverusername='$recieverusername', maildate='$maildate', mailsubject='$mailsubject', mailtext='$mailtext', contactnumber='$contact'"; $database->setquery($query); // print $database->getQuery(); $database->query(); } # Mail reciever function mailReciever($userid, $name, $mail, $subj, $text, $contact) { global $mosConfig_live_site; # Compose message $reciever = $this->getProfileMail($userid); $subject = $subj; $mailtext = _PM_MAIL_GREETING." ".$this->getProfileUsername($userid)."\r\n\r\n"._PM_RECIEVER_MESSAGE1." ".$mosConfig_live_site." "._PM_RECIEVER_MESSAGE2." ".$name." (".$mail."): \r\n\r\n".$text."\r\n\r\n\r\n\r\n"._PM_RECIEVER_FOOTER; $mailtext = stripslashes($mailtext); $mailtext = wordwrap($mailtext, 70); // Just to be safe that SMTP-send works $subject = stripslashes($subject); $contact = stripslashes($contact); # Send the mail! //mosMail($mail, $name, $reciever, $subject, $mailtext); // http://help.mamboserver.com/api/Mambo/_includes_mambo_php.html @mail($reciever,$mailcontactnumber,$contact,$subject,$mailtext,"From: $mail"); } # Mail copy function mailCopy($userid, $name, $mail, $contact, $subj, $text) { global $mosConfig_live_site, $mosConfig_mailfrom; # Compose message $reciever = $mail; $subject = _PM_COPY_SUBJECT." ".$subj; $mailtext = _PM_MAIL_GREETING." ".$name."\r\n\r\n"._PM_COPY_MESSAGE1." ".$this->getProfileUsername($userid)." "._PM_COPY_MESSAGE2." ".$mosConfig_live_site."\r\n\r\n".$text."\r\n\r\n\r\n\r\n"._PM_MAIL_FOOTER; $mailtext = stripslashes($mailtext); $mailtext = wordwrap($mailtext, 70); // Just to be safe that SMTP-send works $contact = stripslashes($contact); $subject = stripslashes($subject); # Send the mail! // mosMail($mosConfig_mailfrom, $mosConfig_live_site, $reciever, $subject, $mailtext); // http://help.mamboserver.com/api/Mambo/_includes_mambo_php.html @mail($reciever,$contact,$subject,$mailtext,"From: $mosConfig_mailfrom"); } # Mail sender ("thank you") function mailSenderThanks($userid, $is_user, $name, $mail) { global $mosConfig_live_site, $mosConfig_mailfrom; # Compose message $reciever = $mail; $subject = _PM_THANKU_SUBJECT." ".$mosConfig_live_site; $mailtext = _PM_MAIL_GREETING." ".$name."\r\n\r\n"._PM_THANKU_THANKS." ".$mosConfig_live_site."\r\n\r\n"._PM_MAIL_FOOTER; # Send the mail! //mosMail($mosConfig_mailfrom, $mosConfig_live_site, $reciever, $subject, $mailtext); // http://help.mamboserver.com/api/Mambo/_includes_mambo_php.html @mail($reciever,$subject,$mailtext,"From: $mosConfig_mailfrom"); } # Send mails and log function sendMails($userid, $is_user, $publicmailLogMails, $publicmailThankSender, $name, $mail, $contact, $subj, $text, $copy) { # Send mail $this->mailReciever($userid, $name, $mail, $contact, $subj, $text); # Send copy if ($copy=="sendCopy") { $this->mailCopy($userid, $name, $mail, $contact, $subj, $text); } # Send thanks if ($publicmailThankSender) { $this->mailSenderThanks($userid, $is_user, $name, $mail); } # Log mail if ($publicmailLogMails) { $this->addMailToDB($userid, $is_user, $name, $mail, $contact, $subj, $text); } } # Main funtion! function getDisplayTab($tab,$user) { global $mosConfig_absolute_path, $mosConfig_lang, $my; # Get site language if (file_exists($mosConfig_absolute_path.'/components/com_comprofiler/plugin/user/plug_cbpublicmail/languages/'.$mosConfig_lang.'.php')) { include($mosConfig_absolute_path.'/components/com_comprofiler/plugin/user/plug_cbpublicmail/languages/'.$mosConfig_lang.'.php'); } else { include($mosConfig_absolute_path.'/components/com_comprofiler/plugin/user/plug_cbpublicmail/languages/english.php'); } # Load parameters $params=$this->params; $publicmailShowForm = $params->get('publicmailShowForm', "0"); $publicmailTableWidth = $params->get('publicmailTableWidth', "100%"); $publicmailShowIntro = $params->get('publicmailShowIntro', "If you want to contact this person, you may use this email-form:"); $publicmailShowAddress = $params->get('publicmailShowAddress', "0"); $publicmailUseSubject = $params->get('publicmailUseSubject', "1"); $publicmailUseCopy = $params->get('publicmailUseCopy', "0"); $publicmailTextMaxlength= $params->get('publicmailTextMaxlength', "500"); $publicmailTextRows = $params->get('publicmailTextRows', "5"); $publicmailTextCols = $params->get('publicmailTextCols', "40"); $publicmailThankSender = $params->get('publicmailThankSender', "0"); $publicmailLogMails = $params->get('publicmailLogMails', "0"); # Find userlevels $is_user = (strtolower($my->usertype) <> ''); # Active profile $userid = mosGetParam( $_REQUEST, 'user', '' ); # Variables to check if form has been filled in and email(s) needs to be sent $name = $_POST['mailName']; $mail = $_POST['mailMail']; $subj = $_POST['mailSubject']; $text = $_POST['mailText']; $copy = $_POST['sendCopy']; $contact = $_POST['contactnumber']; # Show/load content/plugin if ($name AND $this->is_email($mail) AND $text) { // If an email has been sent $name = $this->makeTextSafe($name); $mail = $this->makeTextSafe($mail); $contact = $this->makeTextSafe($contact); $subj = $this->makeTextSafe($subj); $text = $this->makeTextSafe($text); $this->sendMails($userid, $is_user, $publicmailLogMails, $publicmailThankSender, $name, $mail, $contact, $subj, $text, $copy); $content = _PM_MAIL_HAS_BEEN_SENDT; } else if ($userid==$my->id) { // If own profile is visited $content = _PM_VISITING_OWN_PROFILE; } else if (($publicmailShowForm=="1" AND $is_user) OR $publicmailShowForm=="0") { // Show mail-form to "All registred users!" or "All users!" $content = $this->showForm($userid, $publicmailTableWidth, $publicmailShowIntro, $publicmailShowAddress, $publicmailUseSubject, $publicmailUseCopy, $publicmailTextMaxlength, $publicmailTextRows, $publicmailTextCols); } return $content; } // end getDisplayTab } // end class getPublicMailTab. ?>