function displayForm($gift_id)
    {
        global $wgUploadPath;
        $form = '<div><b><a href="' . $this->getTitle()->escapeFullURL() . '">' . wfMsg('ga-viewlist') . '</a></b></div>';
        if ($gift_id) {
            $gift = SystemGifts::getGift($gift_id);
        }
        $form .= '<form action="" method="post" enctype="multipart/form-data" name="gift">
		<table border="0" cellpadding="5" cellspacing="0" width="500">
			<tr>
				<td width="200" class="view-form">' . wfMsg('ga-giftname') . '</td>
				<td width="695"><input type="text" size="45" class="createbox" name="gift_name" value="' . (isset($gift['gift_name']) ? $gift['gift_name'] : '') . '"/></td>
			</tr>
			<tr>
				<td width="200" class="view-form" valign="top">' . wfMsg('ga-giftdesc') . '</td>
				<td width="695"><textarea class="createbox" name="gift_description" rows="2" cols="30">' . (isset($gift['gift_description']) ? $gift['gift_description'] : '') . '</textarea></td>
			</tr>
			<tr>
				<td width="200" class="view-form">' . wfMsg('ga-gifttype') . '</td>
				<td width="695">
					<select name="gift_category">' . "\n";
        $g = new SystemGifts();
        foreach ($g->getCategories() as $category => $id) {
            $sel = '';
            if (isset($gift['gift_category']) && $gift['gift_category'] == $id) {
                $sel = ' selected="selected"';
            }
            $indent = "\t\t\t\t\t\t";
            $form .= $indent . '<option' . $sel . " value=\"{$id}\">{$category}</option>\n";
        }
        $form .= "\t\t\t\t\t" . '</select>
				</td>
			</tr>
		<tr>
			<td width="200" class="view-form">' . wfMsg('ga-threshold') . '</td>
			<td width="695"><input type="text" size="25" class="createbox" name="gift_threshold" value="' . (isset($gift['gift_threshold']) ? $gift['gift_threshold'] : '') . '"/></td>
		</tr>';
        if ($gift_id) {
            $sgml = SpecialPage::getTitleFor('SystemGiftManagerLogo');
            $gift_image = '<img src="' . $wgUploadPath . '/awards/' . SystemGifts::getGiftImage($gift_id, 'l') . '" border="0" alt="gift" />';
            $form .= '<tr>
			<td width="200" class="view-form" valign="top">' . wfMsg('ga-giftimage') . '</td>
			<td width="695">' . $gift_image . '<a href="' . $sgml->escapeFullURL('gift_id=' . $gift_id) . '">' . wfMsg('ga-img') . '</a>
			</td>
			</tr>';
        }
        if (isset($gift['gift_id'])) {
            $button = wfMsg('edit');
        } else {
            $button = wfMsg('ga-create-gift');
        }
        $form .= '<tr>
		<td colspan="2">
			<input type="hidden" name="id" value="' . (isset($gift['gift_id']) ? $gift['gift_id'] : '') . '" />
			<input type="button" class="createbox" value="' . $button . '" size="20" onclick="document.gift.submit()" />
			<input type="button" class="createbox" value="' . wfMsg('cancel') . '" size="20" onclick="history.go(-1)" />
		</td>
		</tr>
		</table>

		</form>';
        return $form;
    }
Exemplo n.º 2
0
 /**
  * Increase a given social statistic field by $val.
  *
  * @param $field String: field name in user_stats database table
  * @param $val Integer: increase $field by this amount, defaults to 1
  */
 function incStatField($field, $val = 1)
 {
     global $wgUser, $wgMemc, $wgSystemGifts, $wgUserStatsTrackWeekly, $wgUserStatsTrackMonthly;
     if (!$wgUser->isAllowed('bot') && !$wgUser->isAnon() && $this->stats_fields[$field]) {
         $dbw = wfGetDB(DB_MASTER);
         $dbw->update('user_stats', array($this->stats_fields[$field] . '=' . $this->stats_fields[$field] . "+{$val}"), array('stats_user_id' => $this->user_id), __METHOD__);
         $this->updateTotalPoints();
         $this->clearCache();
         // update weekly/monthly points
         if (isset($this->point_values[$field]) && !empty($this->point_values[$field])) {
             if ($wgUserStatsTrackWeekly) {
                 $this->updateWeeklyPoints($this->point_values[$field]);
             }
             if ($wgUserStatsTrackMonthly) {
                 $this->updateMonthlyPoints($this->point_values[$field]);
             }
         }
         $s = $dbw->selectRow('user_stats', array($this->stats_fields[$field]), array('stats_user_id' => $this->user_id), __METHOD__);
         $stat_field = $this->stats_fields[$field];
         $field_count = $s->{$stat_field};
         $key = wfForeignMemcKey('huiji', '', 'system_gift', 'id', $field . '-' . $field_count);
         $data = $wgMemc->get($key);
         if ($data != '' && is_int($data)) {
             wfDebug("Got system gift ID from cache\n");
             $systemGiftID = $data;
         } else {
             $g = new SystemGifts();
             $repeatableGift = $g->getRepeatableGifts();
             $categories = array_flip($g->getCategories());
             $systemGiftID = $g->doesGiftExistForThreshold($field, $field_count);
             // echo $field;die;
             if ($systemGiftID) {
                 $wgMemc->set($key, $systemGiftID, 60 * 30);
             }
         }
         if (isset($systemGiftID) && $field != "points_winner_weekly" && $field != "points_winner_monthly") {
             $sg = new UserSystemGifts($this->user_name);
             $sg->sendSystemGift($systemGiftID);
         }
     }
 }