News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Admin notepad

Started by ryanbsoftware, February 24, 2005, 02:50:11 AM

Previous topic - Next topic

ryanbsoftware

i belive fopen is whats its called, the system used for the agreement, for my admin nopepad mod would that be beter or worse than storing it in the db, also if i use that how would i tell it to ask for ftp info to chmod the AdminNotes.txt file to 777, or can i not do that?

[Unknown]

I would recommend you use the database, personally - a row in the settings table, for example.  A flat file is better for something that rarely changes, and an "admin notepad" is something I would expect to (if used) change every once and a while.  For that, the database is probably better.

-[Unknown]

ryanbsoftware

ok, and it would require a bit more work ratheer than basically copying the agreement file code over, lol, but ok, now i have to figure out how to setup the query.

Trekkie101


ryanbsoftware

#4
ok i think i got a query

QuoteSELECT value
FROM `smf_settings`
WHERE variable 'AdminPad'
LIMIT 0 , 30
and
QuoteSELECT value
FROM `smf_settings`
WHERE variable IS 'AdminPad'
LIMIT 0 , 30

after adding a valude AdminPad in the settings table with valuse being what is show in the adminpad.  The problem is is that when i try this query in phpmyadmin to make sure it will work i get this error

QuoteMySQL said:
#1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near ''AdminPad' LIMIT 0, 30' at line 1

I thought in the smf_settings table it would find the row where varibale is adminpad and return what the value is.  How would I do that? And http://www.w3schools.com/sql/sql_select.asp didn't really help, that just proved to me i got the basic syantax right.  :-\

Ben_S

Liverpool FC Forum with 14 million+ posts.

ryanbsoftware


Ben_S

Have a look at how smf does it's queries elsewhere, I don't have the sources in front of me right now.
Liverpool FC Forum with 14 million+ posts.

[Unknown]

It's actually very easy ^_^.  Examples:

Get the admin notes:

echo $modSettings['admin_notes'];

Set the admin notes:

updateSettings(array('admin_notes' => $_POST['admin_notes']));

Delete said notes:

updateSettings(array('admin_notes' => ''));

-[Unknown]

ryanbsoftware

ok seems easy enough, here is my code:

echo ("<textarea name=\"adminpad\" height=\"6\" width=\"40\">") echo $modSettings['admin_notes']; echo ("</textarea>") 
echo ("<br> <input name=\"update\" type=\"button\" onclick=\"updateSettings(array('admin_notes' => $_POST['admin_notes']));\">")


Any one wanna bet there are multipule syantax errors in it, lol.

[Unknown]

Quote from: RyanB on February 25, 2005, 12:40:54 AM
ok seems easy enough, here is my code:

echo ("<textarea name=\"adminpad\" height=\"6\" width=\"40\">") echo $modSettings['admin_notes']; echo ("</textarea>") 
echo ("<br> <input name=\"update\" type=\"button\" onclick=\"updateSettings(array('admin_notes' => $_POST['admin_notes']));\">")


Any one wanna bet there are multipule syantax errors in it, lol.

Actually, no, that won't quite work...


if (isset($_POST['adminpad']))
   updateSettings(array('adminpad' => $_POST['adminpad']));

echo '
<form action=", $scripturl, '?action=admin" method="post">
   <textarea name="adminpad" height="6" width="40">', $modSettings['adminpad'], '</textarea><br />
   <input type="submit" value="Update" />
</form>';


-[Unknown]

ryanbsoftware

ok that makes sense, and that goes in admin.php right, then is anything needed in a theme file?
I am almost done...I think...

[Unknown]

Quote from: RyanB on February 25, 2005, 01:41:54 AM
ok that makes sense, and that goes in admin.php right, then is anything needed in a theme file?
I am almost done...I think...

Actually, that could all go in the theme file and it would work.  Otherwise, youi'd have to put the echo part in the template and the other part in Admin.php.

-[Unknown]

ryanbsoftware

ok, yay, then my first mod is nearly done!

ryanbsoftware

ok add_settings.php

<?php
// Set the below to true to overwrite already existing settings with the defaults. (not recommended.)
$overwrite_old_settings false;

// List settings here in the format: setting_key => default_value.  Escape any "s. (" => \")
$mod_settings = array(
'variable' => 'adminpad',
'value' => 'Admin Notepad!',
);

/******************************************************************************/

// If SSI.php is in the same place as this file, and SMF isn't defined, this is being run standalone.
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.');

// Turn the array defined above into a string of MySQL data.
$string '';
foreach (
$mod_settings as $k => $v)
$string .= '
(\'' 
$k '\', \'' $v '\'),';

// Sorted out the array defined above - now insert the data!
if ($string != '')
$result db_query("
. ($overwrite_old_settings 'REPLACE' 'INSERT IGNORE') . " INTO {$db_prefix}settings
(variable, value)
VALUES" 
substr($string0, -1));

// Uh-oh spaghetti-oh!
if ($result === false)
echo '<b>Error:</b> Database modifications failed!';

?>


ok so is that right?

[Unknown]

Yep, that looks fine.  And, for the package-info.xml, etc... all I should note is two things:

1. The id should have your name in it (e.g. ryanb:adminpad)...
2. The id should not have a version number in it, except maybe major.

-[Unknown]

ryanbsoftware

#16
yah i got that much, i tried the add_settings.php file out and got this error

QuoteWarning: Missing argument 2 for db_query() in /home/chf/public_html/forums/Sources/Subs.php on line 216

Warning: Missing argument 3 for db_query() in /home/chf/public_html/forums/Sources/Subs.php on line 216

line 216 of subs.php reads

function db_query($db_string, $file, $line)

[Unknown]

Sorry, that's an older version I think.  Just add:

, __FILE__, __LINE__

To the lines that look like this:

$result = db_query("
" . ($overwrite_old_settings ? 'REPLACE' : 'INSERT IGNORE') . " INTO {$db_prefix}settings
(variable, value)
VALUES" . substr($string, 0, -1));


Like so:

$result = db_query("
" . ($overwrite_old_settings ? 'REPLACE' : 'INSERT IGNORE') . " INTO {$db_prefix}settings
(variable, value)
VALUES" . substr($string, 0, -1), __FILE__, __LINE__);


-[Unknown]

ryanbsoftware

#18
ok thanks i tested it and it worked, thanks for all your help

as for this being moved this is NOT a tip or trick its a mod, i was going to delete it cause i am not quite ready to release it but now the code is here, so if you were going to do this, why did i spend an hour or two packaging it up?

Advertisement: