General Community > Scripting Help
Datafield code problem
(1/1)
The Wizard:
Hello:
I'm trying to make a SMF Shop Item and I just can't seem to get the dog picure ifo saved in the datafield.
Any ideas as to whats wrong?
--- Quote ---if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
// Hmm... no SSI.php and no SMF?
elseif (!defined('SMF'))
die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php.');
//The Flag field in the member table
$smcFunc['db_query']('', 'ALTER TABLE `{$db_prefix}members` ADD `shop_Dog` TEXT NOT NULL', __FILE__, __LINE__);
//Add the item :)
$smcFunc['db_query']('', "INSERT INTO `{$db_prefix}shop_items` (`name` , `desc` , `price` , `module` , `stock`, `input_needed`, `can_use_item`) VALUES ('Dog Image', 'Show an image next to your posts', '100.00', 'Dog', '50', 1, 1')", __FILE__, __LINE__);
--- End quote ---
--- Quote ---/**********************************************************************************
* SMFShop item *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum *
* =============================================================================== *
* Software Version: SMFShop 3.0 (Build 12) *
* $Date:: 2007-01-18 09:26:55 +0100 (do, 18 jan 2007) $ *
* $Id:: testitem2.php 79 2007-01-18 08:26:55Z 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. *
**********************************************************************************/
// This is just to make sure that the item is used through SMF, and people aren't accessing it directly
// Additionally, this is used elsewhere in SMF (in almost all the files)
if (!defined('SMF'))
die('Hacking attempt...');
/*
* This is a test item that gets some input from the person using it.
* Most likely, you'll base your item off this one.
* Note that all items should try to follow the SMF Coding Guidelines, available
* from http://custom.simplemachines.org/mods/guidelines.php
*
* Your class should always be called item_filename, eg. if your file is
* myCoolItem.php then the class should be called 'item_myCoolItem'. This
* class should always extend itemTemplate.
*/
class item_myDog extends itemTemplate
{
// When this function is called, you should set all the item's
// variables (see inside this example)
function getItemDetails() {
// The author's name
$this->authorName = 'The Wizard';
// The author's email address
$this->authorEmail = 'anybodys_guess@yahoo.com';
// --- Values changeable from within the SMFShop admin panel ---
// The name of the item
$this->name = "My Dog";
// The item's description
$this->desc = "Here is a picture of My Dog Sparkey.";
// The item's price
$this->price = 1;
// --- Unchageable values ---
// These values can not be changed when adding the item, they are stuck on what you set them to here.
// Whether inputs are required by this item. In this case, we get some inputs,
// so set this to 'true'.
$this->require_input = true;
// Set this to 'false' if the item is unusable. This is good for display
// items.
$this->can_use_item = true;
}
/*
* This function is called when the user tries to use the item.
* If your item needs any further user input then you can get that
* input here (eg. if it's a "Change username" item then you have
* to ask the user what they'd like to change their username to).
* Any text you return will get shown to the user (DON'T ECHO STUFF).
*/
function getUseInput() {
global $boardurl, $boarddir, $scripturl;
//Lots of this code is borrowed from the admin panel echoSelectImage() function,
//located in ShopAdmin.php
$image_array = array();
if ($handle = opendir("$boarddir/Sources/shop/dog_images")) {
while (false !== ($file = readdir($handle))) {
if ($file !== "." && $file !== ".." && $file !== "thumbs.db") {
$image_array[] = array('filename' => $file,
'filetitle' => substr($file, 0, -4)
);
}
}
sort($image_array);
} else {
die("ERROR: Can't open Sources/shop/dog_images directory!");
}
$return = "
</form>
<form action='{$scripturl}?action=shop;do=inv3;id={$_GET['id']}' method='POST' name='theDogForm'>
Please choose a dog picture: <img name='dog_preview' src='' border='1'>
<select name='dog' onChange='show_image()'>";
foreach ($image_array as $tempitem) {
$return .= "<option value='{$tempitem['filename']}'>{$tempitem['filetitle']}</option>";
}
$return .= "
</select><br>
<script language='javascript'>
<!--
function show_image() {
var image_url = '{$boardurl}/Sources/shop/dog_images/' + document.theDogForm.dog.value;
document.images['dog_preview'].src = image_url;
}
show_image();
//-->
</script>";
return $return;
}
// This is where all the fun begins. This function is called when
// the user actually uses the item. Return stuff, DON'T ECHO!
function onUse() {
global $smcFunc;
$result = $smcFunc['db_query']('', '
UPDATE {$db_prefix}members
SET shop_Dog = $_POST['dog']
WHERE id_msg = {int:id_msg}
LIMIT 1',);
return "Successfully set your dog image to {$_POST['dog']}!";
}
}
--- End quote ---
The Wizard:
To Any Admin or Mod please delete this post as I have found where my problem is and am starting a new post.
Sorry
Thanks
Wiz
Navigation
[0] Message Index
Go to full version