function send_pmsg()
 {
     $this->pmsg_opt |= 16 | 32;
     $this->pmsg_opt &= 16 | 32 | 1 | 2 | 4;
     foreach ($GLOBALS['recv_user_id'] as $v) {
         $id = db_qid("INSERT INTO phpgw_fud_pmsg (\n\t\t\t\tto_list,\n\t\t\t\touser_id,\n\t\t\t\tip_addr,\n\t\t\t\thost_name,\n\t\t\t\tpost_stamp,\n\t\t\t\ticon,\n\t\t\t\tfldr,\n\t\t\t\tsubject,\n\t\t\t\tattach_cnt,\n\t\t\t\tfoff,\n\t\t\t\tlength,\n\t\t\t\tduser_id,\n\t\t\t\tref_msg_id,\n\t\t\t\tpmsg_opt\n\t\t\t) VALUES (\n\t\t\t\t" . strnull(addslashes($this->to_list)) . ",\n\t\t\t\t" . $this->ouser_id . ",\n\t\t\t\t'" . $this->ip_addr . "',\n\t\t\t\t" . $this->host_name . ",\n\t\t\t\t" . $this->post_stamp . ",\n\t\t\t\t" . strnull($this->icon) . ",\n\t\t\t\t1,\n\t\t\t\t'" . addslashes($this->subject) . "',\n\t\t\t\t" . intzero($this->attach_cnt) . ",\n\t\t\t\t" . $this->foff . ",\n\t\t\t\t" . $this->length . ",\n\t\t\t\t" . $v . ",\n\t\t\t\t" . strnull($this->ref_msg_id) . ",\n\t\t\t\t" . $this->pmsg_opt . ")");
         $GLOBALS['send_to_array'][] = array($v, $id);
         $um[$v] = $id;
     }
     $c = uq('SELECT id, email, users_opt, icq FROM phpgw_fud_users WHERE id IN(' . implode(',', $GLOBALS['recv_user_id']) . ') AND users_opt>=64 AND (users_opt & 64) > 0');
     $from = $GLOBALS['usr']->alias;
     reverse_fmt($from);
     $subject = $this->subject;
     reverse_fmt($subject);
     while ($r = db_rowarr($c)) {
         /* do not send notifications about messages sent to self */
         if ($r[0] == $this->ouser_id) {
             continue;
         }
         if (!($r[2] & 4)) {
             $r[1] = $r[3] . '@pager.icq.com';
         }
         send_pm_notification($r[1], $um[$r[0]], $subject, $from, $r[2]);
     }
 }
    function approve($id, $unlock_safe = false)
    {
        /* fetch info about the message, poll (if one exists), thread & forum */
        $mtf = db_sab('SELECT
					m.id, m.poster_id, m.apr, m.subject, m.foff, m.length, m.file_id, m.thread_id, m.poll_id, m.attach_cnt,
					m.post_stamp, m.reply_to, m.mlist_msg_id,
					t.forum_id, t.last_post_id, t.root_msg_id, t.last_post_date,
					m2.post_stamp AS frm_last_post_date,
					f.name AS frm_name,
					u.alias, u.email, u.sig,
					n.id AS nntp_id, ml.id AS mlist_id
				FROM phpgw_fud_msg m
				INNER JOIN phpgw_fud_thread t ON m.thread_id=t.id
				INNER JOIN phpgw_fud_forum f ON t.forum_id=f.id
				LEFT JOIN phpgw_fud_msg m2 ON f.last_post_id=m2.id
				LEFT JOIN phpgw_fud_users u ON m.poster_id=u.id
				LEFT JOIN phpgw_fud_mlist ml ON ml.forum_id=f.id
				LEFT JOIN phpgw_fud_nntp n ON n.forum_id=f.id
				WHERE m.id=' . $id . ' AND m.apr=0');
        /* nothing to do or bad message id */
        if (!$mtf) {
            return;
        }
        if ($mtf->alias) {
            reverse_fmt($mtf->alias);
        } else {
            $mtf->alias = $GLOBALS['ANON_NICK'];
        }
        if (!db_locked()) {
            db_lock('phpgw_fud_thread_view WRITE, phpgw_fud_level WRITE, phpgw_fud_users WRITE, phpgw_fud_forum WRITE, phpgw_fud_thread WRITE, phpgw_fud_msg WRITE');
            $ll = 1;
        }
        q("UPDATE phpgw_fud_msg SET apr=1 WHERE id=" . $mtf->id);
        if ($mtf->poster_id) {
            user_set_post_count($mtf->poster_id);
        }
        $last_post_id = $mtf->post_stamp > $mtf->frm_last_post_date ? $mtf->id : 0;
        if ($mtf->root_msg_id == $mtf->id) {
            /* new thread */
            rebuild_forum_view($mtf->forum_id);
            $threads = 1;
        } else {
            /* reply to thread */
            if ($mtf->post_stamp > $mtf->last_post_date) {
                th_inc_post_count($mtf->thread_id, 1, $mtf->id, $mtf->post_stamp);
            } else {
                th_inc_post_count($mtf->thread_id, 1);
            }
            rebuild_forum_view($mtf->forum_id, q_singleval('SELECT page FROM phpgw_fud_thread_view WHERE forum_id=' . $mtf->forum_id . ' AND thread_id=' . $mtf->thread_id));
            $threads = 0;
        }
        /* update forum thread & post count as well as last_post_id field */
        frm_updt_counts($mtf->forum_id, 1, $threads, $last_post_id);
        if ($unlock_safe || isset($ll)) {
            db_unlock();
        }
        if ($mtf->poll_id) {
            poll_activate($mtf->poll_id, $mtf->forum_id);
        }
        $mtf->body = read_msg_body($mtf->foff, $mtf->length, $mtf->file_id);
        if ($GLOBALS['FUD_OPT_1'] & 16777216) {
            index_text(preg_match('!Re: !i', $mtf->subject) ? '' : $mtf->subject, $mtf->body, $mtf->id);
        }
        /* handle notifications */
        if ($mtf->root_msg_id == $mtf->id) {
            if (empty($mtf->frm_last_post_date)) {
                $mtf->frm_last_post_date = 0;
            }
            /* send new thread notifications to forum subscribers */
            $c = uq('SELECT u.email, u.icq, u.users_opt
					FROM phpgw_fud_forum_notify fn
					INNER JOIN phpgw_fud_users u ON fn.user_id=u.id
					LEFT JOIN phpgw_fud_forum_read r ON r.forum_id=fn.forum_id AND r.user_id=fn.user_id
					INNER JOIN phpgw_fud_group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id=' . $mtf->forum_id . '
					LEFT JOIN phpgw_fud_group_cache g2 ON g2.user_id=fn.user_id AND g2.resource_id=' . $mtf->forum_id . '
				WHERE
					fn.forum_id=' . $mtf->forum_id . ' AND fn.user_id!=' . (int) $mtf->poster_id . '
					AND (CASE WHEN (r.last_view IS NULL AND (u.last_read=0 OR u.last_read >= ' . $mtf->frm_last_post_date . ')) OR r.last_view > ' . $mtf->frm_last_post_date . ' THEN 1 ELSE 0 END)=1
					AND ((CASE WHEN g2.id IS NOT NULL THEN g2.group_cache_opt ELSE g1.group_cache_opt END) & 2) > 0');
            $notify_type = 'frm';
        } else {
            /* send new reply notifications to thread subscribers */
            $c = uq('SELECT u.email, u.icq, u.users_opt, r.msg_id, u.id
					FROM phpgw_fud_thread_notify tn
					INNER JOIN phpgw_fud_users u ON tn.user_id=u.id
					LEFT JOIN phpgw_fud_read r ON r.thread_id=tn.thread_id AND r.user_id=tn.user_id
					INNER JOIN phpgw_fud_group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id=' . $mtf->forum_id . '
					LEFT JOIN phpgw_fud_group_cache g2 ON g2.user_id=tn.user_id AND g2.resource_id=' . $mtf->forum_id . '
				WHERE
					tn.thread_id=' . $mtf->thread_id . ' AND tn.user_id!=' . (int) $mtf->poster_id . '
					AND (r.msg_id=' . $mtf->last_post_id . ' OR (r.msg_id IS NULL AND ' . $mtf->post_stamp . ' > u.last_read))
					AND ((CASE WHEN g2.id IS NOT NULL THEN g2.group_cache_opt ELSE g1.group_cache_opt END) & 2) > 0');
            $notify_type = 'thr';
        }
        while ($r = db_rowarr($c)) {
            if ($r[2] & 16) {
                $to['EMAIL'] = $r[0];
            } else {
                $to['ICQ'] = $r[1] . '@pager.icq.com';
            }
            if (isset($r[4]) && is_null($r[3])) {
                $tl[] = $r[4];
            }
        }
        unset($c);
        if (isset($tl)) {
            /* this allows us to mark the message we are sending notification about as read, so that we do not re-notify the user
             * until this message is read.
             */
            q('INSERT INTO phpgw_fud_read (thread_id, msg_id, last_view, user_id) SELECT ' . $mtf->thread_id . ', 0, 0, id FROM phpgw_fud_users WHERE id IN(' . implode(',', $tl) . ')');
        }
        if (isset($to)) {
            send_notifications($to, $mtf->id, $mtf->subject, $mtf->alias, $notify_type, $notify_type == 'thr' ? $mtf->thread_id : $mtf->forum_id, $mtf->frm_name, $mtf->forum_id);
        }
        // Handle Mailing List and/or Newsgroup syncronization.
        if (($mtf->nntp_id || $mtf->mlist_id) && !$mtf->mlist_msg_id) {
            fud_use('email_msg_format.inc', true);
            reverse_fmt($mtf->alias);
            $from = $mtf->poster_id ? $mtf->alias . ' <' . $mtf->email . '>' : $GLOBALS['ANON_NICK'] . ' <' . $GLOBALS['NOTIFY_FROM'] . '>';
            $body = $mtf->body . ($mtf->msg_opt & 1 && $mtf->sig ? "\n--\n" . $mtf->sig : '');
            plain_text($body);
            plain_text($subject);
            if ($mtf->reply_to) {
                $replyto_id = q_singleval('SELECT mlist_msg_id FROM phpgw_fud_msg WHERE id=' . $mtf->reply_to);
            } else {
                $replyto_id = 0;
            }
            if ($mtf->attach_cnt) {
                $r = uq("SELECT a.id, a.original_name,\n\t\t\t\t\t\tCASE WHEN m.mime_hdr IS NULL THEN 'application/octet-stream' ELSE m.mime_hdr END\n\t\t\t\t\t\tFROM phpgw_fud_attach a\n\t\t\t\t\t\tLEFT JOIN phpgw_fud_mime m ON a.mime_type=m.id\n\t\t\t\t\t\tWHERE a.message_id=" . $mtf->id . " AND a.attach_opt=0");
                while ($ent = db_rowarr($r)) {
                    $attach[$ent[1]] = file_get_contents($GLOBALS['FILE_STORE'] . $ent[0] . '.atch');
                    if ($mtf->mlist_id) {
                        $attach_mime[$ent[1]] = $ent[2];
                    }
                }
            } else {
                $attach_mime = $attach = null;
            }
            if ($mtf->nntp_id) {
                fud_use('nntp.inc', true);
                $nntp_adm = db_sab('SELECT * FROM phpgw_fud_nntp WHERE id=' . $mtf->nntp_id);
                $nntp = new fud_nntp();
                $nntp->server = $nntp_adm->server;
                $nntp->newsgroup = $nntp_adm->newsgroup;
                $nntp->port = $nntp_adm->port;
                $nntp->timeout = $nntp_adm->timeout;
                $nntp->nntp_opt = $nntp_adm->nntp_opt;
                $nntp->login = $nntp_adm->login;
                $nntp->pass = $nntp_adm->pass;
                define('sql_p', 'phpgw_fud_');
                $lock = $nntp->get_lock();
                $nntp->post_message($mtf->subject, $body, $from, $mtf->id, $replyto_id, $attach);
                $nntp->close_connection();
                $nntp->release_lock($lock);
            } else {
                fud_use('mlist_post.inc', true);
                $GLOBALS['CHARSET'] = 'ISO-8859-15';
                $r = db_saq('SELECT name, additional_headers FROM phpgw_fud_mlist WHERE id=' . $mtf->mlist_id);
                mail_list_post($r[0], $from, $mtf->subject, $body, $mtf->id, $replyto_id, $attach, $attach_mime, $r[1]);
            }
        }
    }
function decode_uent(&$uent)
{
    reverse_fmt($uent->home_page);
    reverse_fmt($uent->bio);
    reverse_fmt($uent->interests);
    reverse_fmt($uent->occupation);
    reverse_fmt($uent->location);
    reverse_fmt($uent->user_image);
    $uent->aim = urldecode($uent->aim);
    $uent->yahoo = urldecode($uent->yahoo);
    $uent->msnm = urldecode($uent->msnm);
    $uent->jabber = urldecode($uent->jabber);
    $uent->affero = urldecode($uent->affero);
}
			FROM phpgw_fud_attach a
			INNER JOIN phpgw_fud_pmsg pm ON a.message_id=pm.id AND a.attach_opt=1
			LEFT JOIN phpgw_fud_mime mm ON mm.id=a.mime_type
			WHERE a.attach_opt=1 AND a.id=' . $id);
    if (!$r) {
        invl_inp_err();
    }
    if (!($usr->users_opt & 1048576) && $r[4] != _uid) {
        std_error('access');
    }
}
if ($FUD_OPT_2 & 4194304 && !empty($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $WWW_ROOT) === false) {
    header("HTTP/1.0 404 Not Found");
    exit;
}
reverse_fmt($r[1]);
if (!$r[0]) {
    $r[0] = 'application/ocet-stream';
    $append = 'attachment; ';
} else {
    if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') && preg_match('!^(audio|video|image)/!i', $r[0])) {
        $append = 'inline; ';
    } else {
        if (strncmp($r[0], "image/", 6)) {
            $append = 'attachment; ';
        } else {
            $append = '';
        }
    }
}
/* if we encounter a compressed file and PHP's output compression is enabled do not
function html_to_tags($fudml)
{
    while (preg_match('!<span name="php">(.*?)</span>!is', $fudml, $res)) {
        $tmp = trim(html_entity_decode(strip_tags(str_replace('<br />', "\n", $res[1]))));
        $m = md5($tmp);
        $php[$m] = $tmp;
        $fudml = str_replace($res[0], "[php]\n" . $m . "\n[/php]", $fudml);
    }
    if (strpos($fudml, '<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1"><tr><td class="SmallText"><b>') !== false) {
        $fudml = str_replace(array('<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1"><tr><td class="SmallText"><b>', '</b></td></tr><tr><td class="quote"><br>', '<br></td></tr></table>'), array('[quote title=', ']', '[/quote]'), $fudml);
    }
    if (preg_match('!<div class="dashed" style="padding: 3px;" align="center" width="100%"><a href="javascript://" OnClick="javascript: layerVis\\(\'.*?\', 1\\);">Mostra lo spoiler</a><div align="left" id=".*?" style="visibility: hidden;">!is', $fudml)) {
        $fudml = preg_replace('!\\<div class\\="dashed" style\\="padding: 3px;" align\\="center" width\\="100%"\\>\\<a href\\="javascript://" OnClick\\="javascript: layerVis\\(\'.*?\', 1\\);">Mostra lo spoiler\\</a\\>\\<div align\\="left" id\\=".*?" style\\="visibility: hidden;"\\>!is', '[spoiler]', $fudml);
        $fudml = str_replace('</div></div>', '[/spoiler]', $fudml);
    }
    while (preg_match('!<font (color|face|size)=".+?">.*?</font>!is', $fudml)) {
        $fudml = preg_replace('!<font (color|face|size)="(.+?)">(.*?)</font>!is', '[\\1=\\2]\\3[/\\1]', $fudml);
    }
    while (preg_match('!<(o|u)l type=".+?">.*?</\\1l>!is', $fudml)) {
        $fudml = preg_replace('!<(o|u)l type="(.+?)">(.*?)</\\1l>!is', '[list type=\\2]\\3[/list]', $fudml);
    }
    $fudml = str_replace(array('<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<s>', '</s>', '<sub>', '</sub>', '<sup>', '</sup>', '<div class="pre"><pre>', '</pre></div>', '<div align="center">', '<div align="left">', '<div align="right">', '</div>', '<ul>', '</ul>', '<span name="notag">', '</span>', '<li>', '&#64;', '&#58;&#47;&#47;', '<br />', '<pre>', '</pre>'), array('[b]', '[/b]', '[i]', '[/i]', '[/u]', '[/u]', '[s]', '[/s]', '[sub]', '[/sub]', '[sup]', '[/sup]', '[code]', '[/code]', '[align=center]', '[align=left]', '[align=right]', '[/align]', '[list]', '[/list]', '[notag]', '[/notag]', '[*]', '@', '://', '', '[pre]', '[/pre]'), $fudml);
    while (preg_match('!<img src="(.*?)" border=0 alt="\\1">!is', $fudml)) {
        $fudml = preg_replace('!<img src="(.*?)" border=0 alt="\\1">!is', '[img]\\1[/img]', $fudml);
    }
    while (preg_match('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', $fudml)) {
        $fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', '[email]\\1[/email]', $fudml);
    }
    while (preg_match('!<a href="(.+?)" target="_blank">\\1</a>!is', $fudml)) {
        $fudml = preg_replace('!<a href="(.+?)" target="_blank">\\1</a>!is', '[url]\\1[/url]', $fudml);
    }
    if (strpos($fudml, '<img src="') !== false) {
        $fudml = preg_replace('!<img src="(.*?)" border=0 alt="(.*?)">!is', '[img=\\1]\\2[/img]', $fudml);
    }
    if (strpos($fudml, '<a href="mailto:') !== false) {
        $fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">(.+?)</a>!is', '[email=\\1]\\2[/email]', $fudml);
    }
    if (strpos($fudml, '<a href="') !== false) {
        $fudml = preg_replace('!<a href="(.+?)" target="_blank">(.+?)</a>!is', '[url=\\1]\\2[/url]', $fudml);
    }
    if (isset($php)) {
        $fudml = str_replace(array_keys($php), array_values($php), $fudml);
    }
    /* unhtmlspecialchars */
    reverse_fmt($fudml);
    return $fudml;
}
        $a = unserialize($o->attach_cache);
        if (is_array($a) && @count($a)) {
            foreach ($a as $i) {
                $attch[] = array('id' => $i[0], 'name' => $i[1], 'nd' => $i[3]);
            }
            $fpdf->add_attacments($attch);
        }
    }
    /* handle polls */
    if ($o->poll_name && $o->poll_cache) {
        $pc = @unserialize($o->poll_cache);
        if (is_array($pc) && count($pc)) {
            reverse_fmt($o->poll_name);
            foreach ($pc as $opt) {
                $opt[0] = strip_tags(post_to_smiley($opt[0], $re));
                reverse_fmt($opt[0]);
                $votes[] = array('name' => $opt[0], 'votes' => $opt[1]);
            }
            $fpdf->add_poll($o->poll_name, $votes, $o->total_votes);
        }
    }
    $fpdf->end_message();
} while ($o = db_rowobj($c));
un_register_fps();
$fpdf->end_page();
pdf_close($fpdf->pdf);
$pdf = pdf_get_buffer($fpdf->pdf);
header('Content-type: application/pdf');
header('Content-length: ' . strlen($pdf));
header('Content-disposition: inline; filename=FUDforum' . date('Ymd') . '.pdf');
echo $pdf;