MyBB Community Forums

Full Version: Query not writing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I tend to stick to theme designing, but thought I'd give plugins a go. At the moment I'm attempting to write an array and just a usual query to the database but not having much luck. The array I'm doing is within plugin activation and it's to create a new group. Is there an easier way to do this? At the moment I've just named the array and gone through the structure of the usergroup table (type, title, description, namestyle etc.) and then used the following to try and write it to the usergroups table:

$db->insert_query('usergroups', $random_create_groups);
  rebuild_settings();

I'm having a similar problem with the following bit of code too (won't query to database):
// Reset
function random_reset() {
  global $db;
if ($mybb->settings['random_reset'] == 1){
$db->write_query("UPDATE TABLE ".TABLE_PREFIX."settings SET value='' WHERE name='random_userbar'");
$db->write_query("UPDATE TABLE ".TABLE_PREFIX."settings SET value='1' WHERE name='random_uid'");
$db->write_query("UPDATE TABLE ".TABLE_PREFIX."settings SET value='0' WHERE name IN('random_enable', 'random_reset')");
rebuild_settings();
}
}

Random_reset is a setting created in the plugin activation which produces a yesno option on the settings page. Any possible solutions?
remove the word table before update.

then test it.
(2017-07-30, 01:05 AM)Whiteneo Wrote: [ -> ]remove the word table before update.

then test it.

I literally added that in for testing purposes. Makes no difference. I was thinking I may be missing hooks or something. At the moment I've only put in a global_start hook.
// Reset
function random_reset() {
  global $mybb, $db;
if ($mybb->settings['random_reset'] == 1){
$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='' WHERE name='random_userbar'");
$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='1' WHERE name='random_uid'");
$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='0' WHERE name IN('random_enable', 'random_reset')");
rebuild_settings();
}
}

This should be the right code.

other removed stuff is not necesary due you have to rebuild settings file on install or activate function.

Cheers...

I do not know what do you whant to do, but without the entire code who can knows what do you wanna do, only you Smile
(2017-07-30, 01:30 AM)Whiteneo Wrote: [ -> ]
// Reset
function random_reset() {
  global $mybb, $db;
if ($mybb->settings['random_reset'] == 1){
$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='' WHERE name='random_userbar'");
$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='1' WHERE name='random_uid'");
$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='0' WHERE name IN('random_enable', 'random_reset')");
rebuild_settings();
}
}

This should be the right code.

other removed stuff is not necesary due you have to rebuild settings file on install or activate function.

Cheers...

I do not know what do you whant to do, but without the entire code who can knows what do you wanna do, only you Smile

Still not working. the function random_reset is meant to basically reset the plugin settings page to default values when the yesno random_reset option has the value of 1 (yes). Here's the full code:

<?php
if(!defined("IN_MYBB"))
{
    die("You Cannot Access This File Directly. Please Make Sure IN_MYBB Is Defined.");
} 

// Hooks
$plugins->add_hook('global_start', 'random_global_start'); 
$plugins->add_hook('admin_user_groups_add', 'random_activate'); 

function random_info()
{
return array(
        "name"  => "Random Userbar Game",
        "description"=> "Steal a userbar from someone when repping them",
        "website"        => "http://softwaysandre.com",
        "author"        => "Wires",
        "authorsite"    => "http://softwaysandre.com",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "18*"
    );
} 
// Activate
function random_activate() {
global $db;

$random_group = array(
        'gid'    => 'NULL',
        'name'  => 'random',
        'title'      => 'Random Userbar Game',
        'description'    => 'Settings For My First Plugin',
        'disporder'    => "1",
        'isdefault'  => "0",
    ); 

$db->insert_query('settinggroups', $random_group);
 $gid = $db->insert_id(); 

$random_setting_1 = array(
        'sid'            => 'NULL',
        'name'        => 'random_enable',
        'title'            => 'Power on?',
        'description'    => 'If you set this option to yes, this plugin be active on your board.',
        'optionscode'    => 'yesno',
        'value'        => '0',
        'disporder'        => 1,
        'gid'            => intval($gid),
    ); 

$random_setting_2 = array(
        'sid'            => 'NULL',
        'name'        => 'random_userbar',
        'title'            => 'Userbar URL',
        'description'    => 'Set IMG url to userbar',
        'optionscode'    => 'text',
        'value'        => '',
        'disporder'        => 2,
        'gid'            => intval($gid),
    ); 
    
$random_setting_3 = array(
        'sid'            => 'NULL',
        'name'        => 'random_reset',
        'title'            => 'Reset',
        'description'    => 'Reset and rebuild settings page.',
        'optionscode'    => 'yesno',
        'value'        => '0',
        'disporder'        => 4,
        'gid'            => intval($gid),
    ); 
    
$random_setting_4 = array(
        'sid'            => 'NULL',
        'name'        => 'random_uid',
        'title'            => 'Set UID',
        'description'    => 'Give a user the userbar to begin with.',
        'optionscode'    => 'text',
        'value'        => '',
        'disporder'        => 3,
        'gid'            => intval($gid),
    ); 
    
// Create usergroup
$random_create_group = array(
        'type'            => '1',
        'title'            => 'Lucky Usergroup',
        'description'    => 'You stole the userbar.',
        'namestyle'    => '{username}',
        'usertitle'        => '',
        'stars'         => '0',
        'starimage'         => 'images/stars.png',
        'image'        => 'test',
        'disporder'        => 0,
        'isbannedgroup'        => 0,
        'canview'        => 1,
        'canviewthreads'        => 1,
        'canviewprofiles'        => 1,
        'candlattachments'        => 1,
        'canviewboardclosed'        => 0,
        'canpostthreads'        => 1,
        'canpostreplys'        => 1,
        'canpostattachments'        => 1,
        'canratethreads'        => 1,
        'modposts'        => 0,
        'modthreads'        => 0,
        'mod_edit_posts'        => 0,
        'modattachments'        => 0,
        'caneditposts'        => 1,
        'candeleteposts'        => 1,
        'candeletethreads'        => 1,
        'caneditattachments'        => 1,
        'canviewdeletionnotice'        => 1,
        'canpostpolls'        => 1,
        'canvotepolls'        => 1,
        'canundovotes'        => 0,
        'canusepms'        => 1,
        'cansendpms'        => 1,
        'cantrackpms'        => 1,
        'candenypmreceipts'        => 1,
        'pmquota'        => '200',
        'maxpmreceipients'        => '5',
        'cansendemail'        => 1,
        'cansendemailoverride'        => 0,
        'maxemails'        => '5',
        'emailfloodtime'        => '5',
        'canviewmemberlist'        => 1,
        'canviewcalender'        => 1,
        'canaddevents'        => 1,
        'canbypasseventmod'        => 0,
        'canmoderateevents'        => 0,
        'canviewonline'        => 1,
        'canviewwolinvis'        => 0,
        'canviewonlineips'        => 0,
        'cancp'        => 0,
        'issupermod'        => 0,
        'cansearch'        => 1,
        'canusercp'        => 1,
        'canuploadavatars'        => 1,
        'canratemembers'        => 1,
        'canchangename'        => 0,
        'canbereported'        => 1,
        'canchangewebsite'        => 1,
        'showforumteam'        => 0,
        'usereputationsystem'        => 1,
        'cangivereputations'        => 1,
        'candeletereputations'        => 1,
        'reputationpower'        => '1',
        'maxreputationsday'        => '5',
        'maxreputationsperuser'        => '0',
        'maxreputationsperthread'        => '0',
        'candisplaygroup'        => 1,
        'attachquota'        => '0',
        'cancustomtitle'        => 1,
        'canwarnusers'        => 0,
        'canreceivewarnings'        => 1,
        'maxwarningsday'        => '0',
        'canmodcp'        => 0,
        'showinbirthdaylist'        => 1,
        'canoverridepm'        => 0,
        'canusesig'        => 1,
        'canusesigxposts'        => 0,
        'signofollow'        => 0,
        'canedittimelimit'        => 0,
        'maxposts'        => 0,
        'showmemberlist'        => 1,
        'canmanageannounce'        => 0,
        'canmanagemodqueue'        => 0,
        'canmanagereporedcontent'        => 0,
        'canviewmodlogs'        => 0,
        'caneditprofiles'        => 0,
        'canbanusers'        => 0,
        'canviewwarnlogs'        => 0,
        'canuseipsearch'        => 0,
        'gid'            => intval($gid),
    );
    
$db->insert_query('settings', $random_setting_1);
$db->insert_query('settings', $random_setting_2);
$db->insert_query('settings', $random_setting_3);
$db->insert_query('settings', $random_setting_4);
$db->insert_query('usergroups', $random_create_groups);
  rebuild_settings();
} 
// Disable
function random_deactivate()
  {
  global $db;
 $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('random_enable', 'random_userbar', 'random_reset', 'random_uid')");
    $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='random'");
rebuild_settings();
    $db->query("DELETE FROM ".TABLE_PREFIX."usergroups WHERE title='Lucky Usergroup'");
rebuild_settings();
 } 
 // Start Hook
 function random_global_start(){
global $mybb;

if ($mybb->settings['random_enable'] == 1){
 echo "My first plugin works!";
}
} 
// Reset
function random_reset() {
  global $mybb, $db;
if ($mybb->settings['random_reset'] == 1){
$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='' WHERE name='random_userbar'");
$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='1' WHERE name='random_uid'");
$db->write_query("UPDATE ".TABLE_PREFIX."settings SET value='0' WHERE name IN('random_enable', 'random_reset')");
rebuild_settings();
}
}
// Give userbar to UID

?>

Both the create groups function and random_reset function doesn't seem to work.
Change
$mybb->settings['random_reset'] == 1
to
$mybb->settings['random_reset'] == '1'
in random_reset() and see if that fixes anything.
(2017-07-30, 08:12 AM)fizz Wrote: [ -> ]Change
$mybb->settings['random_reset'] == 1
to
$mybb->settings['random_reset'] == '1'
in random_reset() and see if that fixes anything.

Doesn't seem to of worked.
The function random_reset() is never executed in your code.
(2017-07-30, 10:27 AM)chack1172 Wrote: [ -> ]The function random_reset() is never executed in your code.

This is probably the 2nd plugin I've attempted. Mind explaining a little more?
(2017-07-30, 10:27 AM)chack1172 Wrote: [ -> ]The function random_reset() is never executed in your code.
Oh lol can't believe I didn't notice that.

(2017-07-30, 10:31 AM)Wires Wrote: [ -> ]This is probably the 2nd plugin I've attempted. Mind explaining a little more?
Nowhere in your plugin do you call random_reset(). It's just a function that's defined and never used right now.
Also side note: you shouldn't include the closing tag "?>" at the end of the file as PHP will auto-append it to all files automatically by default.
Pages: 1 2