Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
php warning and fatal error on voucher plugin
#1
Fatal error: Uncaught Error: [] operator not supported for strings in /home/forumsoft/public_html/inc/plugins/redeem.php:435 Stack trace: #0 /home/forumsoft/public_html/inc/class_plugins.php(142): redeem_admin(true) #1 /home/forumsoft/public_html/admin/index.php(819): pluginSystem->run_hooks(Array) #2 {main} thrown in /home/forumsoft/public_html/inc/plugins/redeem.php on line 435

php Developers please help me fix 

Thank you
[Image: Screenshot_491.png]

code : redeem.php


<?php
/**
 * Premium Plugin: Code Redeem System
 *
 * Website: http://modmybb.com
 * Author: Kevin Van Ryckegem
 * Support: http://modmybb.com (If offline: http://signaware.com)
 *
 */

if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('admin_load', 'redeem_admin');
$plugins->add_hook('admin_user_menu', 'redeem_admin_user_menu');
$plugins->add_hook('admin_user_action_handler', 'redeem_admin_user_action_handler');
$plugins->add_hook('admin_user_permissions', 'redeem_user_permissions');

function redeem_info()
{
    return array(
        "name"            => "Group Vouchers <span style='color: orange;'>Premium Plugin</span>",
        "description"    => "Allows user to redeem a code in exchange for a usergroup membership.",
        "website"        => "http://modmybb.com",
        "author"        => "ModMyBB.com",
        "authorsite"    => "http://modmybb.com",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "18*"
    );
}


function redeem_activate()
{

}

function redeem_activate_settings()
{
    global $db;
    $group = array(
        "name" => "redeem",
        "title" => "Group Vouchers",
        "description" => "Allows user to redeem a code in exchange for a usergroup membership.",
        "disporder" => 1,
        "isdefault" => 0
    );
    $gid = $db->insert_query("settinggroups", $group);

	$setting = array(
            "sid"            => NULL,
            "name"            => "redeem_changeug",
            "title"            => "Change primary usergroup after redeeming?",
            "description"    => "This will override the current usergroup of the user.",
            "optionscode"    => "yesno",
            "value"            => "0",
            "disporder"        => 1,
            "gid"            => $gid
        );
        $db->insert_query("settings", $setting);

		$setting = array(
            "sid"            => NULL,
            "name"            => "redeem_newug",
            "title"            => "Primary usergroup to override after redeeming?",
            "description"    => "The usergroup ID. Only if the above settings is on.",
            "optionscode"    => "numeric",
            "value"            => "",
            "disporder"        => 2,
            "gid"            => $gid
        );
        $db->insert_query("settings", $setting);

		$setting = array(
            "sid"            => NULL,
            "name"            => "redeem_changeags",
            "title"            => "Add additional usergroup(s) after redeeming?",
            "description"    => "This will add the new usergroups to the additional groups of the user.",
            "optionscode"    => "yesno",
            "value"            => "0",
            "disporder"        => 3,
            "gid"            => $gid
        );
        $db->insert_query("settings", $setting);

		$setting = array(
            "sid"            => NULL,
            "name"            => "redeem_newags",
            "title"            => "Additional usergroups to add",
            "description"    => "IDs Comma separated. Only if the previous setting is on.",
            "optionscode"    => "text",
            "value"            => "",
            "disporder"        => 4,
            "gid"            => $gid
        );
        $db->insert_query("settings", $setting);

		$setting = array(
            "sid"            => NULL,
            "name"            => "redeem_expire",
            "title"            => "Expiration time for codes",
            "description"    => "In minutes. Default: 60.",
            "optionscode"    => "numeric",
            "value"            => "60",
            "disporder"        => 5,
            "gid"            => $gid
        );
        $db->insert_query("settings", $setting);

		$setting = array(
            "sid"            => NULL,
            "name"            => "redeem_click",
            "title"            => "Manage the codes.",
            "description"    => "<a href=\'index.php?module=user-redeem\'>Manage the Codes</a> - <a href=\'../myredeem.php?action=clean\'>Prune expired codes</a>",
            "optionscode"    => "text",
            "value"            => "N/A",
            "disporder"        => 0,
            "gid"            => $gid
        );
        $db->insert_query("settings", $setting);

    rebuild_settings();
}


function redeem_deactivate()
{

}



function redeem_install()
{
    redeem_activate_settings();
    redeem_install_tables();
}

function redeem_install_tables()
{
    // Change table details manually -- todo
    global $db;

	//Create db table
	if(!$db->table_exists("redeem"))
    {
		$db->write_query("CREATE TABLE `".TABLE_PREFIX."redeem` (
		  `cid` int(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
		  `code` varchar(128) UNIQUE NULL,
		  `gendate` INT(10) NOT NULL
			) ENGINE=MyISAM" . $db->build_create_table_collation());
	}

}

function redeem_uninstall()
{
    global $db;

    // Delete settings
    $db->delete_query("settinggroups", "name = \"redeem\"");

    $query = "name IN ( \"redeem\", \"redeem_changeug\", \"redeem_newug\", \"redeem_changeags\", \"redeem_newags\", \"redeem_expire\", \"redeem_click\" )";
    $db->delete_query("settings", $query);

    rebuild_settings();

    redeem_uninstall_tables();
}

function redeem_uninstall_tables()
{
    // Uninstall table -- todo
    global $db;

	// Remove table
	if($db->table_exists('redeem'))
	{
		$db->drop_table('redeem');
	}

}

function redeem_is_installed()
{
    global $db;

    if($db->table_exists("redeem"))
        return true;
    return false;
}

function redeem_templates($template, $find, $replace)
{
    require_once MYBB_ROOT."/inc/adminfunctions_templates.php";
    find_replace_templatesets(
        $template,
        "#".preg_quote($find)."#",
        $replace
    );
}

function redeem_addtemplate($title, $template, $sid = -1)
{
    global $db;
    $templatearray = array(
        "title" => $title,
        "template" => $db->escape_string($template),
        "sid" => $sid
    );

    $db->insert_query("templates", $templatearray);
}

// Delete expired codes
function redeem_prune()
{
	global $mybb, $db;

	$now = time();
	$expiration = $now - ($mybb->settings['redeem_expire'] * 60);

	$query = $db->simple_select('redeem', '*');
	$expired = array();
	while($code = $db->fetch_array($query))
	{
		$ctime = $code['gendate'];
		if($ctime < $expiration)
		{
			// expired!
			$expired[] = "'" . intval($code['cid']) . "'";
		}
	}

	if(count($expired) > 0)
	{
		$delete = implode(',', $expired);
		$db->delete_query('redeem', "cid IN ( " . $delete . " )");
	}
}

function redeem_doredeem($code)
{
	global $db, $mybb;

	// valid?
	if(!redeem_valid($code))
		return false;

	// Now, get the redeeming settings.
	$changeug = (bool)$mybb->settings['redeem_changeug'];
	$changeags = (bool)$mybb->settings['redeem_changeags'];
	$newug = intval($mybb->settings['redeem_newug']);
	$newags = explode(',', $mybb->settings['redeem_newags']);
	foreach($newags as $newag)
	{
		$newag = intval($newag);
	}

	$uid = intval($mybb->user['uid']);
	if($changeug)
	{
		$db->update_query('users', array('usergroup' => intval($newug)), "uid='" . intval($uid) . "'");
	}

	if($changeags)
	{
		$ags = explode(',', $mybb->user['additionalgroups']);
		$toadd = array();
		foreach($newags as $newag)
		{
			if(!in_array($newag, $ags))
				$toadd[] = intval($newag);
		}

		$newags = implode(',', $toadd);
		$newags = $mybb->user['additionalgroups'] . ',' . $newags;

		$db->update_query('users', array('additionalgroups' => $newags), "uid='" . intval($uid) . "'");
	}

	$db->delete_query('redeem', "code='" . $db->escape_string($code) . "'");

	return true;
}

function redeem_get_code($code)
{
	global $db;

	$query = $db->simple_select('redeem', '*', "code='" . $db->escape_string($code) . "'");
	$fetch = $db->fetch_array($query);

	return $fetch;
}

function redeem_valid($code)
{
	global $db, $mybb;

	$now = time();
	$expiration = $now - ($mybb->settings['redeem_expire'] * 60);

	$code = redeem_get_code($code);
	$ctime = $code['gendate'];
	if($ctime < $expiration)
	{
		return false;
	}

	return true;
}



// *********** Administration Panel Functions **************


function redeem_admin_user_menu(&$sub_menu)
{
	$sub_menu[] = array('id' => 'redeem', 'title' => 'Code Redeem', 'link' => 'index.php?module=user-redeem');
}

function redeem_admin_user_action_handler(&$actions)
{
	$actions['redeem'] = array('active' => 'redeem', 'file' => 'redeem');
}

function redeem_user_permissions(&$admin_permissions)
{
  	global $db, $mybb;

	$admin_permissions['redeem'] = 'Can manage the Code Redeem System?';
}

function redeem_admin()
{
	global $db, $lang, $mybb, $page, $run_module, $action_file, $cache;

	if($run_module == 'user' && $action_file == 'redeem')
	{
		$sub_tabs['thrtemp'] = array(
			'title'			=> 'Code Redeem System',
			'link'			=> 'index.php?module=user-redeem',
			'description'	=> 'Manage codes'
		);

		$sub_tabs['edit'] = array(
			'title'			=> 'New Code',
			'link'			=> 'index.php?module=user-redeem&amp;action=new',
			'description'	=> 'Generate a new code'
		);

		if($mybb->request_method == 'post')
		{
			switch ($mybb->input['action'])
			{
				case 'do_new':
					if(!isset($mybb->input['code']) || empty($mybb->input['code']))
					{
						flash_message('An error occurred. Please try again!', 'error');
						admin_redirect("index.php?module=user-redeem");
					}

					$now = time();
					$code = $db->escape_string($mybb->input['code']);

					$result = $db->insert_query("redeem", array('code' => $code, 'gendate' => $now));
					if($result)
					{
						$cache->update_forums();
						flash_message('Code Saved!', 'success');
						admin_redirect("index.php?module=user-redeem");
					}
					else
					{
						flash_message('Error saving code...', 'error');
						admin_redirect("index.php?module=user-redeem");
					}
					break;
			}
		}

		$page->add_breadcrumb_item('Code Redeem System', 'index.php?module=user-redeem');

		$page->output_header('Code Redeem System');

		if(!$mybb->input['action'])
		{
			$page->output_nav_tabs($sub_tabs, 'redeem');
			// Manage existing WOLs or show error if no WOLs available;
			$table = new Table;
			$table->construct_header('Code', array('class' => 'align_center'));
			$table->construct_header('Expired?', array('class' => 'align_center'));
			//$table->construct_row();
			$select = $db->simple_select('redeem', '*');

			if($db->num_rows($select) == 0)
			{
				$table->construct_cell('There are no codes.', array('colspan' => 2));
				$table->construct_row();
			}
			else
			{
				while($fetch = $db->fetch_array($select))
				{
					$table->construct_cell(htmlspecialchars($fetch['code']), array('class' => 'align_center'));

					if(redeem_valid($fetch['code']))
					{
						$table->construct_cell('<span style="color: green;">Active</span>', array('class' => 'align_center'));
					}
					else
					{
						$table->construct_cell('<span style="color: grey;">Expired</span>', array('class' => 'align_center'));
					}
					$table->construct_row();
				}
			}
			$table->output('Manage Codes');
		}
		elseif($mybb->input['action'] == 'new')
		{
			$page->output_nav_tabs($sub_tabs, 'new');

			$form = new Form("index.php?module=user-redeem&amp;action=do_new&amp;fid={$fid}&amp;my_post_key={$mybb->post_code}", 'post');
			$container = new FormContainer('New Code');
			$container->output_row('Code '.'<em>*</em>', 'Enter your new code', $form->generate_text_box('code', $template, array('id' => 'code', 'name' => 'code')), 'code');
			$container->end();

			$submit = "";
			$submit[] = $form->generate_submit_button('Add Code');
			$form->output_submit_wrapper($submit);
			$form->end();
		}

		$page->output_footer();
	}
}

?>
----------------------------No -------- Signature ---------------------------------
Reply
#2
<?php

/**
* Premium Plugin: Code Redeem System
*
* Website: http://modmybb.com
* Author: Kevin Van Ryckegem
* Support: http://modmybb.com (If offline: http://signaware.com)
*
*/

Is this a really premium plugin? If yes, please go to support website: http://signaware.com/
Best regards, Peter.
PHP Developer.


#gitlab #myplugins
Reply
#3
(12-30-2019, 09:58 PM)Salvation Wrote:
<?php

/**
* Premium Plugin: Code Redeem System
*
* Website: http://modmybb.com
* Author: Kevin Van Ryckegem
* Support: http://modmybb.com (If offline: http://signaware.com)
*
*/

Is this a really premium plugin? If yes, please go to support website: http://signaware.com/

sir i am actually try to contact them never reply nearly 1 month never getting response and they are down totally maybe they left this business and they switch to other business i think
----------------------------No -------- Signature ---------------------------------
Reply
#4
Try and replace (#432 - #436)
$container->end();

$submit = "";
$submit[] = $form->generate_submit_button('Add Code');
$form->output_submit_wrapper($submit);

with:
$container->end();
$buttons[] = $form->generate_submit_button('Add Code');
$form->output_submit_wrapper($buttons);
Reply
#5
(12-31-2019, 12:14 AM)SvePu Wrote: Try and replace (#432 - #436)
$container->end();

$submit = "";
$submit[] = $form->generate_submit_button('Add Code');
$form->output_submit_wrapper($submit);

with:
$container->end();
$buttons[] = $form->generate_submit_button('Add Code');
$form->output_submit_wrapper($buttons);
fixed thank u bro
----------------------------No -------- Signature ---------------------------------
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)