Seite 1 von 2

Extern private Nachricht verschicken

Verfasst: 22.05.2006 14:57
von meisteralex
Hi Leute, ich möchte gerne von meiner Page, die ich in phpbb intregriert habe eine private Nachricht verschicken, wenn bestimmt aktionen auf der Page ausgelöst werden.

Was muss ich dazu alles machen ? oder hat vielleicht schon jemand eine fertige Funktion nach dem Motto sendprivatemessage($userid, $subject, $text) ????

Verfasst: 22.05.2006 17:03
von Seether
Schau mal hier:
http://www.phpbb.de/doku/doku2.php?mode ... vmsgs_text
und hier nach:
http://www.phpbb.de/doku/doku2.php?mode=priv#privmsgs


Damit hast Du alle Felder, die die DB braucht.


S.

Verfasst: 22.05.2006 17:12
von Gumfuzi
Diese Funktion habe ich noch auf meiner Platte gefunden:

Code: Alles auswählen

function insert_pm(
   $to_id, 
   $message,
   $subject,
   $from_id,
   $html_on = 0,
   $bbcode_on = 1,
   $smilies_on = 1)
{
   global $db, $lang, $user_ip, $board_config, $userdata, $phpbb_root_path, $phpEx;

   if ( !$from_id )
   {
      $from_id = $userdata['user_id'];
   }

   //get varibles ready
   $to_id = intval($to_id);
   $from_id = intval($from_id);
   $msg_time = time();
   $attach_sig = $userdata['user_attachsig'];
   
   //get to users info
   $sql = "SELECT user_id, user_notify_pm, user_email, user_lang, user_active
      FROM " . USERS_TABLE . "
      WHERE user_id = '$to_id'
         AND user_id <> " . ANONYMOUS;
   if ( !($result = $db->sql_query($sql)) )
   {
      $error = TRUE;
      $error_msg = $lang['No_such_user'];
   }

   $to_userdata = $db->sql_fetchrow($result);

   $privmsg_subject = trim(strip_tags($subject));
   if ( empty($privmsg_subject) )
   {
      $error = TRUE;
      $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_subject'];
   }

   if ( !empty($message) )
   {
      if ( !$error )
      {
         if ( $bbcode_on )
         {
            $bbcode_uid = make_bbcode_uid();
         }

         $privmsg_message = prepare_message($message, $html_on, $bbcode_on, $smilies_on, $bbcode_uid);
         $privmsg_message = str_replace('\\\n', '\n', $privmsg_message);

      }
   }
   else
   {
      $error = TRUE;
      $error_msg .= ( ( !empty($error_msg) ) ? '<br />' : '' ) . $lang['Empty_message'];
   }

   //
   // See if recipient is at their inbox limit
   //
   $sql = "SELECT COUNT(privmsgs_id) AS inbox_items, MIN(privmsgs_date) AS oldest_post_time
      FROM " . PRIVMSGS_TABLE . "
      WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
            OR privmsgs_type = " . PRIVMSGS_READ_MAIL . " 
            OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
         AND privmsgs_to_userid = " . $to_userdata['user_id'];
   if ( !($result = $db->sql_query($sql)) )
   {
      message_die(GENERAL_MESSAGE, $lang['No_such_user']);
   }

   $sql_priority = ( SQL_LAYER == 'mysql' ) ? 'LOW_PRIORITY' : '';

   if ( $inbox_info = $db->sql_fetchrow($result) )
   {
      if ( $inbox_info['inbox_items'] >= $board_config['max_inbox_privmsgs'] )
      {
         $sql = "SELECT privmsgs_id FROM " . PRIVMSGS_TABLE . "
            WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
                  OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
                  OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "  )
               AND privmsgs_date = " . $inbox_info['oldest_post_time'] . "
               AND privmsgs_to_userid = " . $to_userdata['user_id'];
         if ( !$result = $db->sql_query($sql) )
         {
            message_die(GENERAL_ERROR, 'Could not find oldest privmsgs (inbox)', '', __LINE__, __FILE__, $sql);
         }
         $old_privmsgs_id = $db->sql_fetchrow($result);
         $old_privmsgs_id = $old_privmsgs_id['privmsgs_id'];
            
         $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TABLE . "
            WHERE privmsgs_id = $old_privmsgs_id";
         if ( !$db->sql_query($sql) )
         {
            message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs (inbox)'.$sql, '', __LINE__, __FILE__, $sql);
         }

         $sql = "DELETE $sql_priority FROM " . PRIVMSGS_TEXT_TABLE . "
            WHERE privmsgs_text_id = $old_privmsgs_id";
         if ( !$db->sql_query($sql) )
         {
            message_die(GENERAL_ERROR, 'Could not delete oldest privmsgs text (inbox)', '', __LINE__, __FILE__, $sql);
         }
      }
   }

   $sql_info = "INSERT INTO " . PRIVMSGS_TABLE . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip, privmsgs_enable_html, privmsgs_enable_bbcode, privmsgs_enable_smilies, privmsgs_attach_sig)
      VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . str_replace("\'", "''", $privmsg_subject) . "', " . $from_id . ", " . $to_userdata['user_id'] . ", $msg_time, '$user_ip', $html_on, $bbcode_on, $smilies_on, $attach_sig)";

   if ( !($result = $db->sql_query($sql_info, BEGIN_TRANSACTION)) )
   {
      message_die(GENERAL_ERROR, "Could not insert/update private message sent info.", "", __LINE__, __FILE__, $sql_info);
   }

   $privmsg_sent_id = $db->sql_nextid();

   $sql = "INSERT INTO " . PRIVMSGS_TEXT_TABLE . " (privmsgs_text_id, privmsgs_bbcode_uid, privmsgs_text)
      VALUES ($privmsg_sent_id, '" . $bbcode_uid . "', '" . str_replace("\'", "''", $privmsg_message) . "')";

   if ( !$db->sql_query($sql, END_TRANSACTION) )
   {
      message_die(GENERAL_ERROR, "Could not insert/update private message sent text.", "", __LINE__, __FILE__, $sql);
   }

   //
   // Add to the users new pm counter
   //
   $sql = "UPDATE " . USERS_TABLE . "
      SET user_new_privmsg = user_new_privmsg + 1, user_last_privmsg = " . time() . " 
      WHERE user_id = " . $to_userdata['user_id'];
   if ( !$status = $db->sql_query($sql) )
   {
      message_die(GENERAL_ERROR, 'Could not update private message new/read status for user', '', __LINE__, __FILE__, $sql);
   }

   if ( $to_userdata['user_notify_pm'] && !empty($to_userdata['user_email']) && $to_userdata['user_active'] )
   {
      $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path']));
      $script_name = ( $script_name != '' ) ? $script_name . '/privmsg.'.$phpEx : 'privmsg.'.$phpEx;
      $server_name = trim($board_config['server_name']);
      $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://';
      $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/';

      include($phpbb_root_path . 'includes/emailer.'.$phpEx);
      $emailer = new emailer($board_config['smtp_delivery']);
               
      $emailer->from($board_config['board_email']);
      $emailer->replyto($board_config['board_email']);

      $emailer->use_template('privmsg_notify', $to_userdata['user_lang']);
      $emailer->email_address($to_userdata['user_email']);
      $emailer->set_subject($lang['Notification_subject']);
               
      $emailer->assign_vars(array(
         'USERNAME' => $to_username,
         'SITENAME' => $board_config['sitename'],
         'EMAIL_SIG' => (!empty($board_config['board_email_sig'])) ? str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']) : '',

         'U_INBOX' => $server_protocol . $server_name . $server_port . $script_name . '?folder=inbox')
      );

      $emailer->send();
      $emailer->reset();
   }

   return;
   
   $msg = $lang['Message_sent'] . '<br /><br />' . sprintf($lang['Click_return_inbox'], '<a href="' . append_sid("privmsg.$phpEx?folder=inbox") . '">', '</a> ') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>');

   message_die(GENERAL_MESSAGE, $msg);

} // insert_pm()
ist von irgend einem Thread hier oder von phpbb.com...

Verfasst: 22.05.2006 20:42
von meisteralex
wat so viel code für ne popelige pn ? was wird da alles gemacht ?

Verfasst: 22.05.2006 21:38
von Gumfuzi
Naja, die Variablen übergeben, Text übergeben, etc.
dann die PN als ausgang beim Versneder eintragen, die PN beim Empfänger eintragen, dann noch den Empf. per Email informieren.

so in der Art...

Die funxtion kann in eine eigene Datei, die Du dann nur vorher includen musst - dann die gefragten Variablen definieren und mit denen die funktion aufrufen (Betreff, text, abs_id, empf_id).

Verfasst: 23.05.2006 07:16
von meisteralex
gut stimmt, hatte ich nicht bedacht
was ist , wenn ich die überprüfung weglasse, ob die mailbox des users voll ist (will das er auf jeden fall ne pn senden). läuft das board sich dann irgendwo nen fehler ?

Verfasst: 23.05.2006 16:25
von Gumfuzi
Müsstest Du testen, aber was spricht dagegen, das drin zulassen (vom Einbau her gesehen, um den es Dir ja IMO geht)?

diese o.a. Funktion muss nur einmal wo per copy&paste reinkopiert werden, das dauert deswegen nicht länger zum "einbauen" - wenn da nun ein paar zeilen weniger zum reinkopieren sind ist es egal, weil es nur ein Arbeitsschritt ist...

Verfasst: 23.05.2006 22:45
von meisteralex
jau die funktion hat mir sehr geholfen, jetzt brauche ich jedoch noch eine , die das gleiche mit einem post mache ? jemand auch nen code-snipple ?

Verfasst: 20.09.2006 02:57
von AngiWaters
Hallo!

Bei der Suche habe ich diese Frage gefunden und festgestellt, dass es genau das ist was ich brauche. Kann mir vll noch einer zeigen, wie ich die variablen definiere und die funktion aufrufe??? am besten per "kopiere das und füge es dort ein..." absoluter php anfänger... :oops:

LG, Angi

Verfasst: 20.09.2006 18:41
von AngiWaters
Hallo!

Kann mir keiner helfen? :(