Advertisement:

Author Topic: Admin notepad  (Read 16491 times)

ryanbsoftware

  • Guest
Admin notepad
« on: February 24, 2005, 02:50:11 AM »
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?

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: fopen or db
« Reply #1 on: February 24, 2005, 04:21:56 AM »
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

  • Guest
Re: fopen or db
« Reply #2 on: February 24, 2005, 11:27:40 AM »
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.

Offline Trekkie101

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,157
  • Gender: Male
  • Ad Astra!
    • https://www.facebook.com/DLRPRoundup on Facebook
    • @dlrproundup on Twitter
    • DLRP Roundup
Re: fopen or db
« Reply #3 on: February 24, 2005, 11:39:21 AM »

ryanbsoftware

  • Guest
Re: fopen or db
« Reply #4 on: February 24, 2005, 12:05:50 PM »
ok i think i got a query

Quote
SELECT value
FROM `smf_settings`
WHERE variable 'AdminPad'
LIMIT 0 , 30
and
Quote
SELECT 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

Quote
MySQL 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.  :-\
« Last Edit: February 24, 2005, 12:08:48 PM by RyanB »

Offline Ben_S

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,725
  • xxx
Re: fopen or db
« Reply #5 on: February 24, 2005, 12:30:34 PM »
Maybe something like this:

http://www.w3schools.com/sql/sql_insert.asp
http://www.w3schools.com/sql/sql_update.asp
http://www.w3schools.com/sql/sql_create.asp

im still learning but those are useful.

If it's for SMF, you would be better off using the SMF database functions.
Liverpool FC Forum with 14 million+ posts.

ryanbsoftware

  • Guest
Re: fopen or db
« Reply #6 on: February 24, 2005, 12:33:35 PM »
ok....those would be?

Offline Ben_S

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 11,725
  • xxx
Re: fopen or db
« Reply #7 on: February 24, 2005, 01:17:15 PM »
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.

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: fopen or db
« Reply #8 on: February 24, 2005, 08:11:43 PM »
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

  • Guest
Re: fopen or db
« Reply #9 on: February 25, 2005, 12:40:54 AM »
ok seems easy enough, here is my code:

Code: [Select]
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.

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: fopen or db
« Reply #10 on: February 25, 2005, 01:35:58 AM »
ok seems easy enough, here is my code:

Code: [Select]
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...

Code: [Select]
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

  • Guest
Re: fopen or db
« Reply #11 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...

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: fopen or db
« Reply #12 on: February 25, 2005, 01:46:11 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

  • Guest
Re: fopen or db
« Reply #13 on: February 25, 2005, 01:48:48 AM »
ok, yay, then my first mod is nearly done!

ryanbsoftware

  • Guest
Re: fopen or db
« Reply #14 on: February 25, 2005, 02:08:24 AM »
ok add_settings.php

Code: [Select]
<?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(
&#39;variable&#39; => &#39;adminpad&#39;,
&#39;value&#39; => &#39;Admin Notepad!&#39;,
);

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

// If SSI.php is in the same place as this file, and SMF isn&#39;t defined, this is being run standalone.
if (file_exists(dirname(__FILE__) . &#39;/SSI.php&#39;) && !defined(&#39;SMF&#39;))
require_once(dirname(__FILE__) . &#39;/SSI.php&#39;);
// Hmm... no SSI.php and no SMF?
elseif (!defined(&#39;SMF&#39;))
die(&#39;<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\&#39;s index.php.&#39;);

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

// Sorted out the array defined above - now insert the data!
if ($string != &#39;&#39;)
$result db_query("
. ($overwrite_old_settings ? &#39;REPLACE&#39; : &#39;INSERT IGNORE&#39;) . " INTO {$db_prefix}settings
(variablevalue)
VALUES" . substr($string, 0, -1));

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

?>

ok so is that right?

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Admin notepad
« Reply #15 on: February 25, 2005, 02:26:13 AM »
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

  • Guest
Re: Admin notepad
« Reply #16 on: February 25, 2005, 02:33:05 AM »
yah i got that much, i tried the add_settings.php file out and got this error

Quote
Warning: 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

Code: [Select]
function db_query($db_string, $file, $line)
« Last Edit: February 25, 2005, 02:37:24 AM by RyanB »

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Admin notepad
« Reply #17 on: February 25, 2005, 02:53:48 AM »
Sorry, that's an older version I think.  Just add:

, __FILE__, __LINE__

To the lines that look like this:

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

Like so:

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

-[Unknown]

ryanbsoftware

  • Guest
Re: Admin notepad
« Reply #18 on: February 25, 2005, 03:02:55 AM »
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?
« Last Edit: February 25, 2005, 03:04:53 AM by RyanB »