<?php

/**
 * [Discuz!] (C)2001-2099 Discuz! Team
 * This is NOT a freeware, use is subject to license terms
 * https://license.discuz.vip
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

class magic_attachsize {

	var $version = '1.0';
	var $name = 'attachsize_name';
	var $description = 'attachsize_desc';
	var $price = '20';
	var $weight = '20';
	var $useevent = 0;
	var $targetgroupperm = false;
	var $copyright = '<a href="https://www.discuz.vip/" target="_blank">Discuz!</a>';
	var $magic = [];
	var $parameters = [];

	function getsetting(&$magic) {
		$settings = [
			'addsize' => [
				'title' => 'attachsize_addsize',
				'type' => 'select',
				'value' => [
					['5', '5M'],
					['10', '10M'],
					['20', '20M'],
					['50', '50M'],
					['100', '100M'],
				],
				'default' => '10'
			],
		];
		return $settings;
	}

	function setsetting(&$magicnew, &$parameters) {
		$magicnew['addsize'] = in_array($parameters['addsize'], [5, 10, 20, 50, 100]) ? intval($parameters['addsize']) : '10';
	}

	function usesubmit() {
		global $_G;

		$addsize = !empty($this->parameters['addsize']) ? intval($this->parameters['addsize']) : 10;
		table_common_member_field_home::t()->increase($_G['uid'], ['addsize' => $addsize]);
		usemagic($this->magic['magicid'], $this->magic['num']);
		updatemagiclog($this->magic['magicid'], '2', '1', '0', '0', 'uid', $_G['uid']);
		showmessage('magics_attachsize_message', '', ['num' => intval($this->parameters['addsize'])], ['alert' => 'right', 'showdialog' => 1]);
	}

	function show() {
		magicshowtips(lang('magic/attachsize', 'attachsize_info', ['num' => intval($this->parameters['addsize'])]));
	}

}

