Ejemplo n.º 1
0
	/**
	 * @param int $id
	 * @return string
	 */
	public static function execute_codebot($id) {
		$id = output::escapeALL($id, true);

		// Include LIB
		require_once(LIB_DIR . DS . 'class.char_code.php');
		require_once(LIB_DIR . DS . 'class.codebot.php');

		// Get own Points
		$points_row = user_points::get(get_phpbb_info::$instance->user_id);
		$product = point_costs::get($id);

		// Check if user has exceded limit of exchange product
		if(points_exchange::getNumByUserId(get_phpbb_info::$instance->user_id, $product["id"]) > $product["aviable_count"] && $product["aviable_count"] != -1)
			return "<span class=\"code_fail\">Du kannst das nicht mehr eintauschen.</span><br><br>";

		// Check if there are enough points
		if($points_row['points_curr'] >= $product["points"] && $product["enabled"]) {
			// Remove Points
			if(user_points::update(get_phpbb_info::$instance->user_id, $product["name"], ($product["points"] * -1)) !== false) {
				$code["result"] = false;
				if($product["function"]) {
					// Run Function
					if (method_exists(__CLASS__, $product["function"]))
						$code = self::$product["function"]($id);
				} else if($product["item_id"] !== null) {
					// Add Item
					$code = codebot::addcode(get_phpbb_info::$instance->username, 0, $product["item_id"], $product["qty"]);
				}

				// Send PM
				if($code["result"] === true && $product["code"] == 1)
					get_phpbb_info::$instance->sendPM(output::getCodeMsg($product, $code["key"]), SYSTEM_USER, "Neuer Code für " . $product["name"]);
				else if($code["result"] === true)
					get_phpbb_info::$instance->sendPM(output::getPointActionsSuccess($product), SYSTEM_USER, $product["name"] . ": Aktion erfolgreich ausgeführt");

				if($code["result"] === "other")
					return $code;
				else if($code["result"] !== true) {
					// Rollback changes on points if code wasn't generated
					user_points::update(get_phpbb_info::$instance->user_id, $product["name"] . " - ROLLBACK", $product["points"]);
					return "<span class=\"code_fail\">" . $code["fail"] . "</span><br><br>";
				} else {
					if($product["code"] == 1)
						return "<span class=\"code_success\">Code wurde erfolgreich erstellt, du erhälst eine PM mit dem Code! <a href=\"ucp.php?i=pm&folder=inbox\" target=\"_blank\">-> Zum Posteingang</a></span><br><br>";
					else {
						// Add exchange product if it has limits
						if($product["aviable_count"] != -1)
							points_exchange::add(get_phpbb_info::$instance->user_id, $product["id"]);

						return "<span class=\"code_success\">Aktion erfolgreich ausgeführt!</span><br><br>";
					}
				}
			}
		} else
			return "<span class=\"code_fail\">Leider hast du dafür nicht genügend Punkte!</span><br><br>";
		return "";
	}
Ejemplo n.º 2
0
	/**
	 * @param string $tablename
	 */
	public static function setTablename($tablename) {
		self::$tablename = $tablename;
	}