Customizing SMF > SMF Coding Discussion

AddMembergroup issue !!

<< < (3/3)

Nvb:
Fixed! Thanks for the support.  ;D

Ascot:
How could you fix the issue?
Cause member groups are replaced, not added on my code.
I need to know please. (make me happy)

Thanks in advance.

Nvb:
This was my final code:


--- Code: ---<?php

/**********************************************************************************
* SMFShop item                                                                    *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum                                     *
* =============================================================================== *
* Software Version:           SMFShop 3.0 (Build 12)                              *
* $Date:: 2007-01-18 19:40:57 +1100 (Thu, 18 Jan 2007)                          $ *
* $Id:: PrimaryMemberGroup.php 80 2007-01-18 08:40:57Z daniel15                 $ *
* Software by:                DanSoft Australia (http://www.dansoftaustralia.net/)*
* Copyright 2005-2007 by:     DanSoft Australia (http://www.dansoftaustralia.net/)*
* Support, News, Updates at:  http://www.dansoftaustralia.net/                    *
*                                                                                 *
* Forum software by:          Simple Machines (http://www.simplemachines.org)     *
* Copyright 2006-2007 by:     Simple Machines LLC (http://www.simplemachines.org) *
*           2001-2006 by:     Lewis Media (http://www.lewismedia.com)             *
***********************************************************************************
* This program is free software; you may redistribute it and/or modify it under   *
* the terms of the provided license as published by Simple Machines LLC.          *
*                                                                                 *
* This program is distributed in the hope that it is and will be useful, but      *
* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY    *
* or FITNESS FOR A PARTICULAR PURPOSE.                                            *
*                                                                                 *
* See the "license.txt" file for details of the Simple Machines license.          *
* The latest version of the license can always be found at                        *
* http://www.simplemachines.org.                                                  *
**********************************************************************************/

//File: AddMembergroup2.php
//      Item

if (!defined('SMF'))
   die('Hacking attempt...');

class item_AddMembergroup2 extends itemTemplate 
{
function getItemDetails() 
{
        $this->name = 'Add Membergroup2';
         $this->desc = 'Allows you to add yourself to a membergroup!';
         $this->price = 5000;

        $this->require_input = false;
        $this->can_use_item = true;

}

function getAddInput() 
{
global $smcFunc;

$selectBox = '<select name="info1">';

   // Get all non post-based membergroups

   $result = $smcFunc['db_query']
('','SELECT id_group, group_name
FROM {db_prefix}membergroups
                      WHERE min_Posts = -{int:id}',
                      array('id' => 1,)
);
   
   // For each membergroup, add it to the list
while ($row = $smcFunc['db_fetch_assoc']($result)) 
{
$selectBox .= '<option value="' . $row['id_group'] . '">' . $row['group_name'] . '</option>';
    }

    $selectBox .= '</select>';
         return 'Membergroup: '. $selectBox;
     }
       

    function onUse() {
        global $smcFunc, $user_info, $item_info;

$additionalGroups = mysql_fetch_array(
$smcFunc['db_query']('','
SELECT additional_groups
FROM {db_prefix}members 
WHERE id_member = {int:id}',
           array('id' => $user_info['id'],
         )
      ),MYSQL_ASSOC);

if($additionalGroups['additional_groups']) {
   $additionalGroups['additional_groups'] = $additionalGroups['additional_groups'].",".$item_info[1];
} else {
   $additionalGroups['additional_groups'] = $item_info[1];
}   

echo $additionalGroups['additionalGroups'];          
        $result = $smcFunc['db_query']('','
      UPDATE {db_prefix}members 
      SET additional_groups = {string:agp}
        WHERE id_member= {int:id}',
           array(
         'id' => $user_info['id'],
         'agp' => $additionalGroups['additional_groups'],
         )
      );

        return "Congratulations, you joined the additional mmbergroup {$item_info[1]}!!";
    }
}
?>

--- End code ---

Ascot:
thank you a lot ♥

Navigation

[0] Message Index

[*] Previous page

Go to full version