News:

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

Main Menu

Struggling to use DB stuff in 2.0

Started by Largo_npc, September 02, 2009, 09:18:23 PM

Previous topic - Next topic

Arantor

Re white screen: have a look in the forum and server error logs.

So this is outside regular post moderation?

Largo_npc

I got Approve to work! Awesome! I just had to get rid of the SSI include, obviously cause it's been fetched already by the caller of my php file and alter the function slightly.

All I need to do now is the decline and reason. That's where the main bother is for me.

Largo_npc

Nope, everything I tried to pass the Reason doesn't work.

Didn't notice your reply there Arantor.
Erm, I guess so, since it's only available for one Board where members post their applications.

Anyway, this is my WORKING Decline action before I started messing with it to get Reasons to pass.
function denyApp()
{
/*
Change Topic Title to prefix with [DECLINE]
Write message saying Sorry but NO!
Lock thread.
*/
global $db_prefix;
global $txt, $board, $topic, $scripturl, $sourcedir, $modSettings, $context;
global $boards, $language, $user_info, $smcFunc;

$passID = $topic;

$reason = "Reasons are currently not available.";

isAllowedTo('process');

if (empty($topic))
fatal_lang_error(1);

if ($board != 6)
fatal_lang_error(1);

$result = $smcFunc['db_query']('','
SELECT
t.id_member_started AS member_id,
m.subject AS topic_name,
m.id_board AS board_id,
m.poster_name AS topic_author_name,
m.id_msg AS message
FROM {db_prefix}topics t
LEFT JOIN {db_prefix}messages m ON m.id_msg = t.id_first_msg
WHERE t.id_topic = {int:topic}
LIMIT 1',
array(
'topic' => $passID,
)
);

if($smcFunc['db_num_rows']($result)) { // actually were rows
$row = $smcFunc['db_fetch_assoc']($result);
$smcFunc['db_free_result']($result);
// now $row['subject'] contains what you want.
}

$tmpSub = $row['topic_name'];
if(!strstr( $tmpSub, "[TRIAL]" ))
{
$trial = false;
$tmpSub = "[DECLINED] " . $tmpSub;
}
else
{
$find = '[TRIAL] ';
$pos1 = stripos($tmpSub, $find);
$tmpSub2 = explode($find, $tmpSub);
foreach($tmpSub as $test)
echo $test;
$tmpSub = $tmpSub2[1];
$tmpSub = "[DECLINED] " . $tmpSub;
$trial = true;
}

$memberID = $row['member_id'];
$messageID = $row['message'];

$smcFunc['db_query']('', '
UPDATE {db_prefix}messages
SET subject = {string:subject}, icon = {string:new_icon}
WHERE id_msg = {int:message}',
array(
'subject' => $tmpSub,
'message' => $messageID,
'new_icon' => "thumbdown",
)
);
if($trial)
{
$newGroup = array(
'id_group' => 0,
);
$msgBody = $row['topic_author_name'] . ",\n\nUnfortunately, you have not passed your trial because: " . $reason . "\n\nThank you for your interest in .//npc and we'd like to wish you all the best.";
updateMemberData($memberID, $newGroup);
}
else
{
$msgBody = $row['topic_author_name'] . ",\n\nUnfortunately, you were not selected for a trial this time because: " . $reason . "\n\nThank you for your interest in .//npc and we'd like to wish you all the best.";

}


$postMessage = array(
'body' => $msgBody,
'subject' => "RE: " . $tmpSub,
);
$postOptions = array(
'board' => $row['board_id'],
'id' => $passID,
'lock_mode' => 1,
);
$postPoster = array(
'id' => 17,
);
createPost($postMessage, $postOptions, $postPoster);
redirectexit('topic=' . $topic . '.0');
}


Arantor

Looking good.

So is the reason box in the UI currently?

Largo_npc

Nope, I removed all references to Reason other than setting the variable in the function now.
Everything I tried just didn't work and didn't make sense at all.

I have one more thing I'm going to try googling for and if that doesn't work, I'm screwed xD.

Largo_npc

Nope, that idea is out of the window. PHP doesn't have a popup which can take input (not that I can find anyway) and it doesn't seem to be possible to set a PHP veriable with the value of a javascript variable.

Arantor

The only way you can do is to have a <form> that sends the data - there is no other way to do it. But that doesn't mean it can't be done.

OK, here's how you'd do it.

Take the decline link and add this attribute: onclick="javascript:decline_form(); return false;"

Then create a JS function called decline_form() that simply creates a <form> on the page dynamically and adds it to the HTML.

The form's action would be index.php, with <input type="hidden" name="action" value="decline"> and <input type="hidden" name="topic" value="...topic id...">, then have a text box (<input type="text" name="decline_reason">) and a submit button.

When that's triggered, that would trigger index.php?action=decline with the parameters, then $_POST['decline_reason'] should contain the reason.

Largo_npc

Where would I add onclick="javascript:decline_form(); return false;"?
I assume that would be in this line in Display.template.php?
'decline_app' => array('test' => 'can_process', 'text' => 'decline_app', 'image' => 'admin_copy.gif', 'lang' => true, 'url' => $scripturl . '?action=decline;topic=' . $context['current_topic'] . ''),


Largo_npc

Done it!

When Decline is clicked, it takes you to a new page which gets the reason using a text area then $reason is set using $_POST['reason'].

I just had to make a new function to handle the calling of the form.

Thanks for the help Arantor.

Arantor

That works too :)

Good to hear it's sorted for you.

Advertisement: