Jump to content

Mass Mailer[SOLVED]


joeri

Recommended Posts

  • Moderators

hello all

i have a quick question would it be possible to add a line to the massmailer to only mail to active pilots(not inactive in phpvms but retired in the database) as the autoretire function doesn't put the retired pilots it inactive in the admin.

gr joeri

Link to comment
Share on other sites

Guest lorathon

I had the same problem. So I wrote a script to check all of the pilots and compare to the active/inactive groups. I run this with the cron we run every Sunday.

What this does is check each pilot. If that pilot is retired it ensures that he/she is in the inactive pilot group. It then does the same with active pilots but ensures that they are in the active group.

The following was added to admin/modules/Maintenance.php

public function checkPilotGroups()
{
	$activeGroup = PilotGroups::getGroupID('Active Pilots');
	$inactiveGroup = PilotGroups::getGroupID('Inactive');


	$params = array(
			'retired' 	=> '1',
			'groupid'	=> $activeGroup
			);

	$sql = 'SELECT p.*,
				p.pilotid as pilotid, p.firstname as firstname, p.lastname as lastname, g.groupid as groupid, g.id as id							
			FROM '.TABLE_PREFIX.'pilots p
			LEFT JOIN '.TABLE_PREFIX.'groupmembers g ON g.pilotid = p.pilotid';

	$sql .= DB::build_where($params);

	$results = DB::get_results($sql);

		if($results)
		{
			foreach($results as $result)
			{ 		
				PilotGroups::RemoveUserFromGroup($result->pilotid, $activeGroup);
				if(!PilotGroups::CheckUserInGroup($result->pilotid, $inactiveGroup)) PilotGroups::AddUsertoGroup($result->pilotid, $inactiveGroup);
			echo '<strong>'.$result->firstname.' '.$result->lastname.'</strong> - Removed from Active Group and reassigned to Inactive Group<br/>';		
		}
	}
	else
	{
		echo "No retired pilot in Active Group";
	}
	echo "<p></p><p></p>";

	$params = array(
			'retired' 	=> '0',
			'groupid'	=> $inactiveGroup
			);

	$sql = 'SELECT p.*,
				p.pilotid as pilotid, p.firstname as firstname, p.lastname as lastname, g.groupid as groupid, g.id as id							
			FROM '.TABLE_PREFIX.'pilots p
			LEFT JOIN '.TABLE_PREFIX.'groupmembers g ON g.pilotid = p.pilotid';

	$sql .= DB::build_where($params);

	$results = DB::get_results($sql);

		if($results)
		{
		foreach($results as $result)
			{ 		
				PilotGroups::RemoveUserFromGroup($result->pilotid, $inactiveGroup);
				if(!PilotGroups::CheckUserInGroup($result->pilotid, $activeGroup)) PilotGroups::AddUsertoGroup($result->pilotid, $activeGroup); 
			echo '<strong>'.$result->firstname.' '.$result->lastname.'</strong> - Removed from Inactive Group and reassigned to Active Group<br/>';
		}
	}
	else
	{
		echo "No active pilots in Inactive Group";
	}
}

The following was added to /admin/maintenance.php

MainController::Run('Maintenance', 'checkPilotGroups');

I also added the following to the /admin/templates/maintenance_options.tpl This allows admin to manually run the script.

<tr>
<td><strong>
	<a href="<?php echo adminurl('/maintenance/checkPilotGroups');?>">Check Pilot User Groups</a>
	</strong>
</td>
<td>This will update pilots to ensure they are in the proper groups(Active/Inactive).<br /></td>
</tr>

Link to comment
Share on other sites

Guest lorathon

NOTE -

The above posts assumes that the following groups have these group id's Be sure to check first. If the you change the group numbers than you will have problems

Active - Group id #2

Inactive - Group id #4

I probably should have put a check group in the beginning. Maybe I will change it to check the groups just in case they change.

Link to comment
Share on other sites

Guest lorathon

I changed the original code to include a group name check. The names of the groups have to be

Active Pilots

Inactive

Both of these are the default groups that phpVMS installs. If you rename the groups you will need to change the first two lines of code to match your new group names.

Link to comment
Share on other sites

  • Moderators

thanks Jeff going to try it lateron

on a second hand did you ever recived my email regarding the tnt acars iff not let me know the i can resend it

ok tried it but getting this error

Parse error: syntax error, unexpected T_PUBLIC in /home/tntvirtua/domains/tnt-virtual.be/public_html/admin/modules/Maintenance/Maintenance.php on line 332

i probably do something verry stupid an easy wrong but i cant find it :-)

gr joeri

Link to comment
Share on other sites

  • Moderators

ok but the main problem is when a pilot gets retired using the autoretire the inactive/active part off phpvms doesn't take that out the the retire table from the database so when doing a mass mail it sends it to all the pilots in the database and not only to the still active as i did not make them inactive in the admin.

gr joeri

ps still struggeling on the code i must be missing something verry stupid :P

Link to comment
Share on other sites

Guest lorathon

I cant see anything wrong with the code. it looks the same as what I have and use. Try uncommenting it again and see what happens. I dont see the final closing bracket at the very end but maybe you just forgot to paste that in.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...