Not Solved newpoints coinflip phugin error
#1
Not Solved
i got a flipcoin plugin but when i upload it all website become blank .

here is the code

<?php
/**
 * Copyright 2016, AmN Tech
 * http://amn.tech
 * Skype: askamn786  
 */
if(!defined("IN_MYBB"))
{	
    die("Nope.");
}
define( 'FLIPCOIN_PLUGIN_NAME', 'flipcoin' );
define( 'FLIPCOIN_PLUGIN_FRIENDLY_NAME', 'Flip Coin' );
$plugins->add_hook( 'newpoints_default_menu', FLIPCOIN_PLUGIN_NAME.'_newpoints_default_menu' );
$plugins->add_hook( 'newpoints_start', FLIPCOIN_PLUGIN_NAME.'_newpoints_start' );
/**
 * Plugin Information
 *
 * @return		array 		Array of information
 */
function flipcoin_info()
{
    global $plugins_cache;	
    $pluginfilename = basename( __FILE__, ".php" );
    $plugininfo = array(
                         "name"             => FLIPCOIN_PLUGIN_FRIENDLY_NAME,
                         "description"      => 'A Coin Flipping system, allows your users to wager credits and win/lose accordingly',
                         "website"          => "http://amn.tech/",
                         "author"           => "AmN",
                         "authorsite"       => "http://amn.tech",
                         "version"          => "1.1",
                         "compatibility"    => "*"
    );
	
	if(is_array($plugins_cache) && is_array($plugins_cache['active']) && $plugins_cache['active'][$pluginfilename])
    {
		$plugininfo['description'] = FLIPCOIN_PLUGIN_FRIENDLY_NAME . " is installed and working properly.";
	}
	
    return $plugininfo;
}
/**
 * Called when the plugin is installed
 */
function flipcoin_install()
{
	global $db, $lang;
	$lang->load( FLIPCOIN_PLUGIN_NAME );
	// Templates
	$templatesArray = array( 
		'home' => '<html>
	<head>
		<title>{$mybb->settings[\'bbname\']} - {$lang->flipcoin_newpoints_menu}</title>
		{$headerinclude}
		<script type="text/javascript" src="jscripts/flipcoin.amn.min.js"></script>
		<style>
			.flipcoins-credits {
				float: right;
				/*! border: 1px solid #1C58A2; */
				padding: 5px 10px;
				border-radius: 2px;
				cursor: pointer;
				background: rgba(0,0,0,0.5);
			}
			.flip {
				position: relative;
				overflow: hidden;
				margin: 40px auto;
				width: 100px;
				height: 100px;
				padding: 10px;
			}
			.flip, .flip a {
				width: 100px;
				height: 100px;
				text-align: center;
			}
			.flip a {
				transition: none!important;
				font-size: 20px;
				font-weight: bold;
				line-height: 100px;
				position: absolute;
				top: 0px;
				left: 0px;
				display: block;
				overflow: hidden;
				-webkit-user-select: none;
				-moz-user-select: none;
				-ms-user-select: none;
				user-select: none;
				text-decoration: none;
				border-width: 6px;
				border-style: double;
				-webkit-border-radius: 50%;
				-moz-border-radius: 50%;
				border-radius: 50%;
				outline: none !important;
				-khtml-border-radius: 50%;
				-webkit-text-size-adjust: none;
				-webkit-touch-callout: none;
				-khtml-user-select: none;
				white-space: nowrap;
				/*! color: rgba(242,215,50,1); */
				/*! background: linear-gradient(45deg, rgba(242,215,12,1) 0%,rgba(255,255,255,1) 56%,rgba(252,235,0,1) 96%); */
				box-shadow: 2px 2px 2px 1px rgba(0, 0, 0, .1);
				text-shadow: none;
				font-family: monospace;
			}
			.flip a::after {
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 50%;
				content: '';
			}
			.flip a.flipping:hover {
				cursor: default;
			}
			.notification {
				padding: 10px 15px!important;
				background: transparent!important;
			}
			.notification.success {
				border: 1px solid green;
			}
			.notification.error{
				/*! border: 1px solid #f00; */
			}
			.flipcoin-rules {
				font-style: italic;
				font-size: 12px;
			}
			.flipcoin-rules div {
			}
		</style>
	</head>
	<body>
		{$header}
		<table width="100%" border="0" align="center">
			<tr>
				<td valign="top" width="180">
					<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
						<tr>
							<td class="thead"><strong>{$lang->newpoints_menu}</strong></td>
						</tr>
						{$options}
					</table>
				</td>
				<td valign="top">
					<input type="hidden" name="csrfkey" value="{$mybb->post_code}" />
					<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
						<tr>
							<td class="thead" colspan="2"><strong>{$lang->flipcoin_newpoints_home}</strong></td>
						</tr>
						<tr>
							<td class="trow1" colspan="2">
							<span class="float_left"><div class="flipcoins-credits">{<div class="notification">
								</div></div></span>
								
								<div class="flipcoins-credits">{$mypoints}</div>
								<div class="flip">
									<a title="Flip me!" class="save start" href="javascript:void(0);">HEADS</a>
								</div>
							</td>
						</tr>
						<tr>
							<td class="trow1" width="50%"><strong>Bet Amount:</strong></td>
							<td class="trow1" width="50%">
								<input type="text" name="bet" value="1" class="textbox" />
								<div class="flipcoin-rules">
									<div>Maximum Bet Amount: {$mybb->settings[\'flipcoin_maxwager\']}</div>
									<div>Minimum Bet Amound: {$mybb->settings[\'flipcoin_minwager\']}</div>
								</div>
							</td>
						</tr>
						<tr>
							<td class="trow1" width="50%"><strong>Heads/Tails:</strong></td>
							<td class="trow1" width="50%">
								<select name="choice">
									<option value="HEADS" selected="selected">Heads</option>
									<option value="TAILS">Tails</option>
								</select>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		{$footer}
	</body>
</html>',
	);
	// Insert them in Global Templates
	foreach( $templatesArray AS $name => $data )
	{
		$template = array(
			'title' 		=> $db->escape_string( FLIPCOIN_PLUGIN_NAME . '_' . $name),
			'template' 		=> $db->escape_string( $data ),
			'version' 		=> 1,
			'sid' 			=> -1,
			'dateline' 		=> TIME_NOW
		);
		$db->insert_query( 'templates', $template );
	}
	$name = FLIPCOIN_PLUGIN_NAME . '_setting_group_name';
	$desc = FLIPCOIN_PLUGIN_NAME . '_setting_group_desc';
	$group = array(
		'name' 			=> FLIPCOIN_PLUGIN_NAME,
		'title' 		=> $db->escape_string( $lang->{$name} ),
		'description' 	=> $db->escape_string( $lang->{$desc} ),
		'isdefault' 	=> 0
	);
	// Check if the group already exists.
	$query = $db->simple_select('settinggroups', 'gid', "name='".FLIPCOIN_PLUGIN_NAME."'");
	if($gid = (int)$db->fetch_field($query, 'gid'))
	{
		// We already have a group. Update title and description.
		$db->update_query( 'settinggroups', $group, "gid='{$gid}'" );
	}
	else
	{
		// We don't have a group. Create one with proper disporder.
		$query = $db->simple_select('settinggroups', 'MAX(disporder) AS disporder');
		$group['disporder'] = (int)$db->fetch_field($query, 'disporder');
		$group['disporder']++;
		$gid = (int)$db->insert_query('settinggroups', $group);
	}
	// Deprecate all the old entries in settings.
	$db->update_query('settings', array('description' => 'FLIPCOINDELETE'), "gid='{$gid}'");
	// New settings
	$settings = array(
		// Max Wager
		'maxwager'	=> array(
			'optionscode'	=> 'text',
			'value'			=> '100'
		),
		// Min Wager
		'minwager'	=> array(
			'optionscode'	=> 'text',
			'value'			=> '1'
		),
		// Winning Multiplier
		'multiplier_win' => array(
			'optionscode'   => 'text',
			'value'			=> '2'
		),
		// Loss Multiplier
		'multiplier_loss' => array(
			'optionscode'   => 'text',
			'value'			=> '1'
		),
	);
	$disporder = 0;
	// Create and/or update settings.
	foreach($settings AS $key => $setting)
	{
		// Prefix all keys with group name.
		$title = FLIPCOIN_PLUGIN_NAME."_setting_{$key}";
		$description = FLIPCOIN_PLUGIN_NAME."_setting_{$key}_desc";
		$key = FLIPCOIN_PLUGIN_NAME."_{$key}";
		$setting['title'] = $lang->{$title};
		$setting['description'] = $lang->{$description};
		// Filter valid entries.
		$setting = array_intersect_key($setting,
			array(
				'title' 		=> 0,
				'description' 	=> 0,
				'optionscode' 	=> 0,
				'value' 		=> 0,
			)
		);
		// Escape input values.
		$setting = array_map(array($db, 'escape_string'), $setting);
		// Add missing default values.
		++$disporder;
		$setting = array_merge(
			array(
				'description' 	=> '',
				'optionscode' 	=> 'yesno',
				'value' 		=> 0,
				'disporder' 	=> $disporder
			),
			$setting
		);
		$setting['name'] = $db->escape_string($key);
		$setting['gid'] = $gid;
		// Check if the setting already exists.
		$query = $db->simple_select('settings', 'sid', "gid='{$gid}' AND name='{$setting['name']}'");
		if($sid = $db->fetch_field($query, 'sid'))
		{
			// It exists, update it, but keep value intact.
			unset($setting['value']);
			$db->update_query('settings', $setting, "sid='{$sid}'");
		}
		else
		{
			// It doesn't exist, create it.
			$db->insert_query('settings', $setting);
		}
	}
	// Delete deprecated entries.
	$db->delete_query('settings', "gid='{$gid}' AND description='FLIPCOINDELETE'");
	
	// This is required so it updates the settings.php file as well and not only the database - they must be synchronized!
	rebuild_settings();
}
/**
 * Called when plugin is activated
 *
 * @return 		void
 */
function flipcoin_activate()
{
	global $db;
	// Status Row: 0 = Loss, 1 = Win 
	$db->query( '
		CREATE TABLE IF NOT EXISTS '.TABLE_PREFIX.'flipcoin(
			`gid` 				int(10) 		PRIMARY KEY AUTO_INCREMENT,
			`uid` 				int(10) 		NOT NULL,
			`bet`				int(10)			NOT NULL,
			`choice`			varchar(196)	NOT NULL,
			`status`			int(1)			DEFAULT \'0\' NOT NULL,
			`dateline`			varchar(196) 	NOT NULL
		) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci' 
	);
}
/**
 * Called when plugin is de-activated
 *
 * @return 		void
 */
function flipcoin_deactivate()
{
	global $db;
	$db->drop_table( 'flipcoin' );
} 
/**
 * Called when plugin is uninstalled
 *
 * @return 		void
 */
function flipcoin_uninstall()
{
	global $db, $mybb;
	// Show confirmation
	if($mybb->request_method != 'post')
	{
		global $page, $lang;
		$lang->load( FLIPCOIN_PLUGIN_NAME );
		$page->output_confirm_action('index.php?module=config-plugins&action=deactivate&uninstall=1&plugin=flipcoin', $lang->flipcoin_uninstall_message, $lang->flipcoin_uninstall);
	}
	// Delete settings group
	$gid = $db->fetch_field( $db->simple_select( 'settinggroups', 'gid', 'name=\''.FLIPCOIN_PLUGIN_NAME.'\'' ), 'gid' );
	$db->delete_query('settinggroups', "name='".FLIPCOIN_PLUGIN_NAME."'");
	// Remove settings
	$db->delete_query( 'settings', 'gid=\''.intval( $gid ).'\'' );
	rebuild_settings();
	// Remove Templates
	$db->delete_query( 'templates', 'title LIKE \''.FLIPCOIN_PLUGIN_NAME.'%\'' );
}
/**
 * Is the plugin installed?
 */
function flipcoin_is_installed()
{
	global $db;
	return $db->table_exists( 'flipcoin' );
}
// Newpoints Menu
function flipcoin_newpoints_default_menu( $menu )
{
	global $lang, $mybb;
	$lang->load( FLIPCOIN_PLUGIN_NAME );
	$link = array( '<a href="'.$mybb->settings['bburl'].'/newpoints.php?action=flipcoin">'.$lang->flipcoin_newpoints_menu.'</a>' );
	
	if( $mybb->input['action'] == 'flipcoin' )
	{
		$link[0] = '&raquo; ' . $link[0];
	}
	return array_merge( $menu, $link );
}
// Newpoints Action
function flipcoin_newpoints_start()
{
	global $mybb, $db, $lang, $templates, $header, $footer, $headerinclude, $menu, $plugins, $theme, $options, $mypoints;
	if ($mybb->user['usergroup'] == 7) {
		error('Banned users cannot visit this page');
	}
	if( $mybb->input['action'] != 'flipcoin' )
	{
		return;
	}
	if( $mybb->input['do'] == 'bet' )
	{
		verify_post_check( $mybb->input['key'] );
		
		$mybb->input['bet'] = intval( $mybb->input['bet'] );
		if( $mybb->user['newpoints'] < $mybb->input['bet'] )
		{
			die( json_encode( array( 'success' => 2, 'message' => 'You don\'t have enough points.' ) ) );
		}
		else if( $mybb->input['bet'] < $mybb->settings['flipcoin_minwager'] )
		{
			die( json_encode( array( 'success' => 2, 'message' => 'Minimum bet amount is: ' . $mybb->settings['flipcoin_minwager'] ) ) );
		}
		else if( $mybb->input['bet'] > $mybb->settings['flipcoin_maxwager'] )
		{
			die( json_encode( array( 'success' => 2, 'message' => 'Maximum bet amount is: ' . $mybb->settings['flipcoin_maxwager'] ) ) );
		}
		// Check if the user is spamming
		$spamTime = TIME_NOW - 60;
		$count = $db->fetch_field( $db->simple_select( 'flipcoin', 'COUNT(*) AS `count`', 'uid=\''.$mybb->user['uid'].'\' AND `dateline` > \''.$spamTime.'\'' ), 'count' );
		if( $count > 5 )
		{
			die( json_encode( array( 'success' => 2, 'message' => 'You can play 5 games atmost in a minute! Please try again after sometime.' ) ) );
		}
		$choices = array( 
			0 => 'HEADS', 
			1 => 'TAILS' 
		);
		if( !in_array( $mybb->input['choice'], $choices ) )
		{
			die( json_encode( array( 'success' => 2, 'message' => 'Invalid choice.' ) ) );
		}
		$win = rand(0, 1);
		$inserts = array(
			'dateline'	=> 		TIME_NOW,
			'uid'		=>		$mybb->user['uid'],
			'status'	=> 		0,
			'choice'	=> 		$db->escape_string( $mybb->input['choice'] ),
			'bet'		=> 		$mybb->input['bet'],
		);
		// Won
		if( $mybb->input['choice'] == $choices[$win] )
		{
			newpoints_addpoints( $mybb->user['uid'], $mybb->input['bet']*$mybb->settings['flipcoin_multiplier_win'] );
			$totalcredits = $mybb->input['bet']*$mybb->settings['flipcoin_multiplier_win'] + $mybb->user['newpoints'];
			$winorloss = 1;
			$inserts['status'] = 1;
		}
		// Lost
		else
		{
			newpoints_addpoints( $mybb->user['uid'], -1*$mybb->input['bet']*$mybb->settings['flipcoin_multiplier_loss'] );
			$totalcredits = -1*$mybb->input['bet']*$mybb->settings['flipcoin_multiplier_loss'] + $mybb->user['newpoints'];
			$winorloss = 0;
		}
		$db->insert_query( 'flipcoin', $inserts );
		die( json_encode( array( 'success' => $winorloss, 'winchoice' => $choices[$win], 'points' => newpoints_format_points( $totalcredits ) ) ) );
	}
	//JOIN QUERY :'(
/*	 $joinquery = $db->write_query("
 SELECT u.uid,username,usergroup,displaygroup,dateline,choice,bet,status FROM ".TABLE_PREFIX."users b 
 LEFT JOIN ".TABLE_PREFIX."flipcoin u ON (b.uid=u.uid)
 ORDER BY u.dateline
 DESC LIMIT 5
 ");
foreach ($joinquery as $lastfive)
	{
		if ($lastfive['status'] == 1) {
			$lastfive['status'] = '<span style="color:#449947">Win</span>';
		}
		else{
			$lastfive['status'] = '<span style="color:#E61A1A">Loss</span>';
		}
		$username = format_name($lastfive['username'], $lastfive['usergroup'], $lastfive['displaygroup']);
		$user_link = build_profile_link($username, $lastfive['uid']);
			
            $lastfivebets .= '
            <tr>
            <td class="trow1" id=""  >
                <span class="smalltext">'.$user_link.'</span>
            </td>
			<td class="trow1" id="" >
                <span class="smalltext"><strong>'.$lastfive['bet'].'</strong></span>
            </td>
            			<td class="trow1" id=""  >
                <span class="smalltext"><strong>'.$lastfive['choice'].'</strong></span>
            </td>
			<td class="trow1" id=""  >
                <span class="smalltext"><strong>'.$lastfive['status'].'</strong></span>
            </td>
			</tr>
            ';
    }*/
	$joinquery = $db->write_query("
 SELECT u.uid,username,usergroup,displaygroup,dateline,choice,bet,status FROM ".TABLE_PREFIX."users b 
 LEFT JOIN ".TABLE_PREFIX."flipcoin u ON (b.uid=u.uid)
 ORDER BY u.dateline
 DESC LIMIT 5
 ");
foreach ((array) $joinquery as $lastfive)
	{
    $lastfive = array();
		if ($lastfive['status'] == 1) {
			$lastfive['status'] = '<span style="color:#449947">Win</span>';
		}
		else{
			$lastfive['status'] = '<span style="color:#E61A1A">Loss</span>';
		}
		$username = format_name($lastfive['username'], $lastfive['usergroup'], $lastfive['displaygroup']);
		$user_link = build_profile_link($username, $lastfive['uid']);
			
            $lastfivebets .= '
            <tr>
            <td class="trow1" id=""  >
                <span class="smalltext">'.$user_link.'</span>
            </td>
			<td class="trow1" id="" >
                <span class="smalltext"><strong>'.$lastfive['bet'].'</strong></span>
            </td>
            			<td class="trow1" id=""  >
                <span class="smalltext"><strong>'.$lastfive['choice'].'</strong></span>
            </td>
			<td class="trow1" id=""  >
                <span class="smalltext"><strong>'.$lastfive['status'].'</strong></span>
            </td>
			</tr>
            ';
      
    }
	$lang->load( FLIPCOIN_PLUGIN_NAME );
	eval("\$page = \"".$templates->get('flipcoin_home')."\";");
	output_page( $page );
}
?>
Reply
#2
Not Solved
Bump.
Plz give me solution
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)