Exemplo n.º 1
0
function register_vote(&$options, $poll_id, $opt_id, $mid)
{
    /* invalid option or previously voted */
    if (!isset($options[$opt_id]) || q_singleval('SELECT id FROM phpgw_fud_poll_opt_track WHERE poll_id=' . $poll_id . ' AND user_id=' . _uid)) {
        return;
    }
    if (db_li('INSERT INTO phpgw_fud_poll_opt_track(poll_id, user_id, poll_opt) VALUES(' . $poll_id . ', ' . _uid . ', ' . $opt_id . ')', $a)) {
        q('UPDATE phpgw_fud_poll_opt SET count=count+1 WHERE id=' . $opt_id);
        q('UPDATE phpgw_fud_poll SET total_votes=total_votes+1 WHERE id=' . $poll_id);
        poll_cache_rebuild($opt_id, $options);
        q('UPDATE phpgw_fud_msg SET poll_cache=' . strnull(addslashes(@serialize($options))) . ' WHERE id=' . $mid);
    }
    return 1;
}
Exemplo n.º 2
0
 function sync($id, $frm_id, $message_threshold, $perm)
 {
     if (!db_locked()) {
         db_lock('phpgw_fud_poll_opt WRITE, phpgw_fud_forum WRITE, phpgw_fud_msg WRITE, phpgw_fud_thread WRITE, phpgw_fud_thread_view WRITE');
         $ll = 1;
     }
     $file_id = write_body($this->body, $length, $offset);
     /* determine if preview needs building */
     if ($message_threshold && $message_threshold < strlen($this->body)) {
         $thres_body = trim_html($this->body, $message_threshold);
         $file_id_preview = write_body($thres_body, $length_preview, $offset_preview);
     } else {
         $file_id_preview = $offset_preview = $length_preview = 0;
     }
     poll_cache_rebuild($this->poll_id, $poll_cache);
     $poll_cache = $poll_cache ? @serialize($poll_cache) : null;
     q("UPDATE phpgw_fud_msg SET\n\t\t\tfile_id=" . $file_id . ",\n\t\t\tfoff=" . (int) $offset . ",\n\t\t\tlength=" . (int) $length . ",\n\t\t\tmlist_msg_id=" . strnull(addslashes($this->mlist_msg_id)) . ",\n\t\t\tfile_id_preview=" . $file_id_preview . ",\n\t\t\toffset_preview=" . $offset_preview . ",\n\t\t\tlength_preview=" . $length_preview . ",\n\t\t\tupdated_by=" . $id . ",\n\t\t\tmsg_opt=" . $this->msg_opt . ",\n\t\t\tattach_cnt=" . (int) $this->attach_cnt . ",\n\t\t\tpoll_id=" . (int) $this->poll_id . ",\n\t\t\tupdate_stamp=" . __request_timestamp__ . ",\n\t\t\ticon=" . strnull(addslashes($this->icon)) . " ,\n\t\t\tpoll_cache=" . strnull(addslashes($poll_cache)) . ",\n\t\t\tsubject=" . strnull(addslashes($this->subject)) . "\n\t\tWHERE id=" . $this->id);
     /* determine wether or not we should deal with locked & sticky stuff
      * current approach may seem a little redundant, but for (most) users who
      * do not have access to locking & sticky this eliminated a query.
      */
     $th_data = db_saq('SELECT orderexpiry, thread_opt, root_msg_id FROM phpgw_fud_thread WHERE id=' . $this->thread_id);
     $locked = (int) isset($_POST['thr_locked']);
     if (isset($_POST['thr_ordertype'], $_POST['thr_orderexpiry']) || ($th_data[1] ^ $locked) & 1) {
         $thread_opt = (int) $th_data[1];
         $orderexpiry = isset($_POST['thr_orderexpiry']) ? (int) $_POST['thr_orderexpiry'] : 0;
         /* confirm that user has ability to change lock status of the thread */
         if ($perm & 4096) {
             if ($locked && !($thread_opt & $locked)) {
                 $thread_opt |= 1;
             } else {
                 if (!$locked && $thread_opt & 1) {
                     $thread_opt &= ~1;
                 }
             }
         }
         /* confirm that user has ability to change sticky status of the thread */
         if ($th_data[2] == $this->id && isset($_POST['thr_ordertype'], $_POST['thr_orderexpiry']) && $perm & 64) {
             if (!$_POST['thr_ordertype'] && $thread_opt > 1) {
                 $orderexpiry = 0;
                 $thread_opt &= ~6;
             } else {
                 if ($thread_opt < 2 && (int) $_POST['thr_ordertype']) {
                     $thread_opt |= $_POST['thr_ordertype'];
                 } else {
                     if (!($thread_opt & (int) $_POST['thr_ordertype'])) {
                         $thread_opt = $_POST['thr_ordertype'] | $thread_opt & 1;
                     }
                 }
             }
         }
         /* Determine if any work needs to be done */
         if ($thread_opt != $th_data[1] || $orderexpiry != $th_data[0]) {
             q("UPDATE phpgw_fud_thread SET thread_opt=" . $thread_opt . ", orderexpiry=" . $orderexpiry . " WHERE id=" . $this->thread_id);
             /* Avoid rebuilding the forum view whenever possible, since it's a rather slow process
              * Only rebuild if expiry time has changed or message gained/lost sticky status
              */
             $diff = $thread_opt ^ $th_data[1];
             if ($diff > 1 && !($diff & 6) || $orderexpiry != $th_data[0]) {
                 rebuild_forum_view($frm_id);
             }
         }
     }
     if (isset($ll)) {
         db_unlock();
     }
     if ($GLOBALS['FUD_OPT_1'] & 16777216) {
         delete_msg_index($this->id);
         index_text(preg_match('!^Re: !i', $this->subject) ? '' : $this->subject, $this->body, $this->id);
     }
 }