News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

PHP script to change ranks/autoreply

Started by alexandervba, June 01, 2009, 05:11:42 PM

Previous topic - Next topic

alexandervba

Please refer to my last reply on this topic, the original topic has already been solved, but I wanted to add something after 2 years



I want to create a script in PHP that can do the following. Just make a button, or a selection dropdown box called 'approve' inside display.template.php, so when ur viewing someone's topic. Once selected/Pressed:

- It changes the topic create's rank to Applicant.
- It puts an automatic generated reply to the topic (eg: Gratz, youve been accepted!)
- Additional optoins to close/unpin topic ect...

I dont really know how to start off at all... Ive been into learning php for like a month now, but Im a fast learner and a curious person. I hope you guys can give me a good start.

[SiNaN]

You can achieve the first two easily by addMembersToGroup() and createPost() functions.

./Sources/Display.php

Code (End) Select
function ApproveApplication()
{
global $db_prefix, $topic, $context, $sourcedir;

if (empty($topic))
fatal_lang_error(472, false);

isAllowedTo('admin_forum');

checkSession('get');

$request = db_query("
SELECT ID_MEMBER_STARTED, ID_BOARD
FROM {$db_prefix}topics
WHERE ID_TOPIC = $topic
LIMIT 1", __FILE__, __LINE__);
list ($starter, $board) = mysql_fetch_row($request);
mysql_free_result($request);

if (empty($starter))
fatal_lang_error(472, false);

require_once('Subs-Members.php');
addMembersToGroup($starter, 9);

$msgOptions = array(
'id' => 0,
'subject' => 'Approved',
'body' => 'Your application is approved.',
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(),
);
$topicOptions = array(
'id' => $topic,
'board' => $board,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => $context['user']['id'],
'update_post_count' => 1,
);

require_once($sourcedir . '/Subs-Post.php');
createPost($msgOptions, $topicOptions, $posterOptions);

redirectexit('topic=' . $topic . '.' . $_REQUEST['start']);
}


./index.php

Code (Find) Select
'announce' => array('Post.php', 'AnnounceTopic'),

Code (Replace) Select
'announce' => array('Post.php', 'AnnounceTopic'),
'approveapplication' => array('Display.php', 'ApproveApplication'),


./Themes/{your_theme}/Display.template.php

Code (Find) Select
if ($context['can_remove_post'] && !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)

Code (Replace) Select
$context['can_approve_application'] = allowedTo('admin_forum');
$txt['approve_application'] = 'Approve';
$mod_buttons['approve_application'] = array('test' => 'can_approve_application', 'text' => 'approve_application', 'image' => 'approve.gif', 'lang' => true, 'url' => $scripturl . '?action=approveapplication;topic=' . $context['current_topic'] . '.' . $context['start'] . ';sesc=' . $context['session_id']);

if ($context['can_remove_post'] && !empty($options['display_quick_mod']) && $options['display_quick_mod'] == 1)


You just need to set 9 as the id of group you want to put the topic starter in and 'subject' and 'body' indexes in $msgOptions array in first added codes.

I'm not sure what you mean by the third but if you need more features, I suggest making a request in Mod Requests board.
Former SMF Core Developer | My Mods | SimplePortal

alexandervba

#2
This is perfect. Just getting 1 annoying error. And I think I know why. The error is the following:

8: Undefined index: description
File: /data/www/localhost/htdocs/foe/forums/Sources/Subs-Post.php
Line: 1534


I believe because I have installed the topic description mod: http://custom.simplemachines.org/mods/index.php?mod=606

It creates the autoreply, but it doesnt change the rank...

(including subs-post.php)

----------------------------------

Second thing, just a small thing. I only need this script to work in 2 particilar forums, any way I can add, if forum ID = 1 || forum ID = 2 THEN do script, else show nothing?

thx!

alexandervba


[SiNaN]

For the error:

Code (Find) Select
      'attachments' => array(),

Code (Replace) Select
      'attachments' => array(),
      'description' => '',


SMF doesn't have ranks, it has member groups instead. If user has a primary group set, the new group will be added as an additional group. If you want the new group to be the primary group:

Code (Find) Select
addMembersToGroup($starter, 9);

Code (Replace) Select
addMembersToGroup($starter, 9, 'force_primary');

For making this available for only board with ids 1 and 2:

Code (Find) Select
$context['can_approve_application'] = allowedTo('admin_forum');

Code (Replace) Select
$context['can_approve_application'] = allowedTo('admin_forum') && in_array($context['current_board'], array(1, 2));
Former SMF Core Developer | My Mods | SimplePortal

alexandervba

thx! this is percect!

Any chance we can automatically move the topic to another board? Once a topic is approved, it needs to be moved to a subforum called 'approved topics'.

alexandervba

can any1 help me create a (move_topic) function, so If I press my accept button, it gets moved?

alexandervba

Also looking for a way to keep the original subject please? Because now when I approve it, the subject title is changed to "approved", any way I can keep the original one?

alexandervba

If I leave subject open, it sais topic tile: N/A :s

alexandervba

If I removed the subject line I get error :s



alexandervba

I found this topic: http://www.simplemachines.org/community/index.php?topic=315463.0

It looks like something I can use, but I have no idea how to convert it in the way I need it?

Can I just use $movetopic($topic, $board) or what is all that?

alexandervba

and theres a function like $topic_info['subject'] ?

alexandervba

ok... finally got the move function... Now how can I keep the same topic title? O.o

alexandervba


alexandervba

sorry to keep bumping this but, im sure it cant be that hard to do :( altho whatever I do, it keeps saying not defined or some error stuff :s I really need some help...




Advertisement: