News:

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

Main Menu

Merge topic notification

Started by HunterP, May 16, 2011, 12:10:23 AM

Previous topic - Next topic

HunterP


Hi,

I'm trying to get the abandoned mod "Merge topic notification" working on RC5 :

if (isset($_POST['postNotify']))
{
$PostSelectedForMerge = $_POST['TopicSelectedForMerge'];
$PostSelectedForMergeMemberID=$topic_data[$PostSelectedForMerge]['started']['id'];
$PostSelectedForMergeSubject = $topic_data[$PostSelectedForMerge]['subject'];

// Get Merged Into id
foreach ($topic_data as $topic)
if ($topic['id'] != $PostSelectedForMerge)
$PostSelectedForMergeInto = $topic['id'];
$PostSelectedForMergeIntoSubject = $topic_data[$PostSelectedForMergeInto]['subject'];
$mergedIntoId = $id_topic;
$mergedInto_subject = $target_subject;

$pmto = array(
'to' => array($PostSelectedForMergeMemberID),
'bcc' => array(),
);

$pm_subject = $txt['mergetopic_notify_subject'] . $PostSelectedForMergeSubject;
$pm_subject = un_htmlspecialchars($pm_subject);
$pm_subject = preg_replace("/'/",''',$pm_subject);

$pm_words = array('{merged_subject}','{merged_into_subject}','{merged_topic}');       

$pm_merge_topic_body = str_replace($pm_words,array(
$PostSelectedForMergeSubject,
$PostSelectedForMergeIntoSubject,
'[url=http://' . $scripturl . '?topic=' . $mergedIntoId . '.0]' . $mergedInto_subject . '[/url]',
), $_POST['notify']
);

sendpm($pmto, $pm_subject, $pm_merge_topic_body);
}


When merging a topic, I get :

Database error, given array of integer values is empty. (to_members)

ascaland

Are you able to confirm $PostSelectedForMergeMemberID isnt empty?

HunterP

Quote from: Project Evolution on May 16, 2011, 05:24:25 PM
Are you able to confirm $PostSelectedForMergeMemberID isnt empty?

No I can't confirm that. Can you help me out? How do I test this?

ascaland

You could always kill the script to check.
Code (Above) Select
sendpm($pmto, $pm_subject, $pm_merge_topic_body);
Code (Add) Select
die(var_dump($PostSelectedForMergeMemberID));

HunterP

Quote from: Project Evolution on May 16, 2011, 09:49:36 PM
You could always kill the script to check.
Code (Above) Select
sendpm($pmto, $pm_subject, $pm_merge_topic_body);
Code (Add) Select
die(var_dump($PostSelectedForMergeMemberID));

string(0) ""

:(

HunterP

Quote from: HunterP on May 16, 2011, 11:51:12 PM
string(0) ""

The same for :

   $PostSelectedForMerge = $_POST['TopicSelectedForMerge'];

So $_POST['TopicSelectedForMerge'] seems to be incorrect, right?

ascaland

Yes, you need to make sure this data is getting sent to the script from the form or wherever else your sending it from. I havnt looked at this mod but I can help out tomorrow after school if you will still need help by that time. :P

HunterP

Quote from: Project Evolution on May 17, 2011, 12:04:00 AM
Yes, you need to make sure this data is getting sent to the script from the form or wherever else your sending it from. I havnt looked at this mod but I can help out tomorrow after school if you will still need help by that time. :P

If you can help, please :) I managed to get the Move Topic Notification working for 2.0 which works more or less the same, but this Merging seems to be a bit different.

In SplitTopics.template.php the mod adds :

// Merge Topic Notification
echo '
<fieldset id="merge_notify" class="merge_options">
<legend>', $txt['mergetopic_PM'], '</legend>
<label for="postNotify"><input type="checkbox" name="postNotify" id="postNotify" checked="checked" onclick="document.getElementById(\'notifyArea\').style.display = this.checked ? \'block\' : \'none\';" class="input_check" /> ', $txt['moveTopicPM'], '</label><br />
<select name="TopicSelectedForMerge">';

foreach ($context['topics'] as $topic)
echo '
<option value="', $topic['id'], '" selected="selected">', $topic['started']['name'], '</option>';
echo '
</select>

<div id="notifyArea" style="margin: 0;">
<textarea name="notify" rows="4" cols="120">', $txt['mergetopic_notify_body'], '</textarea>
</div>
</fieldset>';
// Merge Topic Notification End


See <select name="TopicSelectedForMerge">';. This should be used for $_POST['TopicSelectedForMerge'], but doesn't seem to work correct :(

Thanks in advance :)

HunterP


Found a little bug (I think), although this doesn't fix my problem.

   <option value="', $topic['id'], '" selected="selected">', $topic['started']['name'], '</option>';

Has to be :

   <option value="', $topic['id'], '"' . ($topic['selected'] ? ' selected="selected"' : '') . '>', $topic['started']['name'], '</option>';

ascaland

It would probably give you an empty value if the value attribute in that selectbox is empty. Can you place,
print_r($context['topics']);
Above the foreach? By the way, those selectboxes show the value(s) from $topic['started']['name'] right?

HunterP

Quote from: Project Evolution on May 17, 2011, 04:28:31 PM
It would probably give you an empty value if the value attribute in that selectbox is empty. Can you place,
print_r($context['topics']);
Above the foreach?

Don't get so see anything. Where does this have to show?

Quote from: Project Evolution on May 17, 2011, 04:28:31 PM
By the way, those selectboxes show the value(s) from $topic['started']['name'] right?

As far as I can see, yes. But the value contains the topic ID

ascaland

Oh sorry,
die(print_r($context['topics']));

But im thinking it would have the id if everything else is being displayed fine (unless there was a slight mistake). The value from the $_POST array should definitely not be blank if there actually is a value in the select boxes.

HunterP

Quote from: Project Evolution on May 17, 2011, 05:28:14 PM
Oh sorry,
die(print_r($context['topics']));

What exactly should this do? It seems as if the array gets emptied, the selectbox is empty, but I don't get to see a blank screen with the content of the array.....

ascaland

That has nothing to do with the selectboxes. Im printing out the array of topics that the selectboxes are getting data from.

HunterP

Quote from: Project Evolution on May 18, 2011, 12:08:42 PM
That has nothing to do with the selectboxes. Im printing out the array of topics that the selectboxes are getting data from.

Ok, but I don't get to see anything...

ascaland

Well that cant be right. I dont know how the select boxes can be getting data from the foreach if there is nothing in the $context['topics'] array. Can you send me the modified mod you currently have through PM?

ascaland

Hehehe, I managed to find the issue. The selectboxes were fine, and so was the POST data that was apparently empty. However I noticed the member id's happened to be missing when I printed the $topic_data array, which explains why no id was being found. The culprit was with $row['ID_MEMBER_STARTED']:
'id' => empty($row['ID_MEMBER_STARTED']) ? '' : $row['ID_MEMBER_STARTED'],
While the query was using id_member_started (case-sensitivity!). So in the mod make sure you apply these changes,
Code (Replace) Select
$row['ID_MEMBER_STARTED']
Code (With) Select
$row['id_member_started']

I also still have the updated mod just incase. :)

HunterP

Quote from: Project Evolution on May 18, 2011, 04:34:39 PM
Hehehe, I managed to find the issue. The selectboxes were fine, and so was the POST data that was apparently empty. However I noticed the member id's happened to be missing when I printed the $topic_data array, which explains why no id was being found. The culprit was with $row['ID_MEMBER_STARTED']:
'id' => empty($row['ID_MEMBER_STARTED']) ? '' : $row['ID_MEMBER_STARTED'],
While the query was using id_member_started (case-sensitivity!). So in the mod make sure you apply these changes,

Ah, stupid! Thats due to the difference between SMF1 and SMF2, I guess :)

Thanks!  8)

HunterP


Another question, I hope you are willing to help me out (again).

Is the selectbox neccessary? I only want to use this option when 2 topics are being merged, with the option "merge topic" in a topic. Not when using checkboxes, that way more than two topics can be merged.

When reading topic 1 and clicking "merge topic" in that topic 1 and selecting to merge this topic with topic-2, than (in 99% of the cases, at least on my forum), the second topic will be the 'main' (new) topic, and the topic starter of topic-1 needs to be notified. How can this be hard-coded, so the selectbox can be removed?

So, the TS of the topic in which "merge topic" needs to be notified and when more than 2 topics are selected, the notification checkbox needs to be invisible.

ascaland

Well, to make the selectbox disappear you could check the request to see if exactly two boxes were selected and if so just hardcode that the poster of the first topic gets notified. Shouldnt be too difficult on that part.

Advertisement: