- Posts:
- 4
- Group:
- Members
- Member
- #392,725
- Joined:
- May 31, 2012
|
Site URL: http://w11.zetaboards.com/Fast_Effigy/index/ Format: Zetaboards Description: There was a thread about mass pming and I got it to work but only if you input the names individually. I would like a code where you select the group and the message goes to everyone in that group.
Here is what I have so far:
Code - Code:
-
<script type="text/javascript"> // JavaScript Document if(location.href.match(/msg\/\?c=[2|3]/)) { var pm = { disallowed : ["Validating","Guests","Removed", "Members*"], // a list of groups not allowed to multi pm, separated with commas and enclosed with quotes state : 1, // 1 = single, 2 = multi, groupsLoaded : 0, errors : 0, add : [], remove : [], groups : [], list : [], single : function(){ this.state = 1; $(".single").show(); $(".multi").hide(); }, multi : function(){ this.state = 2; $(".multi").show(); $(".single").hide(); this.loadGroups(); }, loadGroups : function(){ if(pm.groupsLoaded == 0){ xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET", main_url+"members/",false); xmlhttp.send();
myStr = new String(xmlhttp.responseText); x = myStr.indexOf("<select name='group'>"); myStr = new String(myStr.substr(x)); y = myStr.indexOf("</select>"); myStr = new String(myStr.substr(0,y+9)); x=myStr.indexOf("All Groups"); myStr = new String(myStr.substr(0, x) + "None" + myStr.substr(x+10)); x=myStr.indexOf("'group'"); myStr = new String(myStr.substr(0,x) + "'groups' multiple='multiple'" + myStr.substr(x+7)); c = myStr.toString(); $("#groups").html(c); pm.groupsLoaded = 1; } }, checkAdd : function(){ pm.add = []; pm.errors = 0; var users = $("#add").val().split("\n"); var l = $.trim($("#add").val()); if(l.length > 0){ /*$("#addFault").html('<strong>THESE USERS DO NOT EXIST</strong>')*/ $("#addFault").html(''); pm.checkExists(users,"add"); } else { pm.checkRemove(); } }, checkRemove : function(){ pm.remove = []; pm.errors = 0; var users = $("#remove").val().split("\n"); var l = $.trim($("#remove").val()); if(l.length > 0){ /*$("#removeFault").html('<strong>THESE USERS DO NOT EXIST</strong>')*/ $("#removeFault").html(''); pm.checkExists(users,"remove"); } else { pm.checkNext([],"remove"); } }, checkExists : function(users,type){ var user = $.trim(users[0]); if(user.length == 0){ pm.checkNext(users,type); } else { xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET",main_url+"members/?search_type=start&name="+user+"&group=0&sort=name&order=a",false); xmlhttp.send();
myStr = new String(xmlhttp.responseText); x = myStr.indexOf('<table cellspacing="0" id="member_list_full">'); myStr = new String(myStr.substr(x)); y = myStr.indexOf("</table>"); myStr = new String(myStr.substr(0,y+8));
exist = myStr.indexOf("No members") > 0 ? 0 : 1; if (exist == 1) { a = new String(myStr.substr(myStr.indexOf(user), user.length)); b = new String(myStr.substr(myStr.indexOf("profile/")+8)); b = new String(b.substr(0,b.indexOf("class='member'")-3)); if($.trim(a.toString().toLowerCase()) == $.trim(user.toLowerCase())) { if (type == "add") { pm.add[pm.add.length] = [a, parseInt(b)]; } else { pm.remove[pm.remove.length] = [a, parseInt(b)]; } exist = 1; } else { exist = 0; } } if(exist == 0){ type == "add" ? $("#addFault").append('<strong>'+user+'</strong> DOES NOT EXIST!<br />') : $("#removeFault").append('<strong>'+user+'</strong> DOES NOT EXIST!<br />'); pm.errors++; } pm.checkNext(users,type); } }, checkNext : function(users,type){ if(users.length > 1){ users.reverse();users.pop();users.reverse(); pm.checkExists(users,type); } else if(pm.errors > 0) { type == "add" ? alert("At least one of the users you added to the mailing list does not exist.\nThe PM has not been sent.") : alert("At least one of the users you removed from the mailing list does not exist.\nThe PM has not been sent."); $("button[accesskey=s]").attr("disabled",false); } else if(type == "add") { pm.checkRemove(); } else if((pm.add.length + pm.remove.length == 0) && $("select[name=groups] option:first").attr("selected")===true) { alert("You must choose someone to send the PM to.\nThe PM has not been sent."); $("button[accesskey=s]").attr("disabled",false); } else { pm.formList(); } }, formList : function(){ $("select[name=groups] option").each(function(){ if($(this).attr("selected") === true){ if($(this).attr("value") != 0){ pm.groups[pm.groups.length] = $(this).attr("value"); } } }); if(pm.groups.length > 0){ pm.roamGroup(1); } else { pm.addToList(); } }, roamGroup : function(page){ var group = pm.groups[0]; xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET",main_url+"members/"+page+"/?name=&search_type=start&group="+group+"&order=a&sort=name&joinable=0",false); xmlhttp.send();
myStr = new String(xmlhttp.responseText);
pages = 1; findPages = new String(myStr); findPagesArr = findPages.split("START Above the copyright"); findPages = findPagesArr[0]; findPagesArr = ""; if (findPages.indexOf("<ul class='cat-pages'>") > 0) { findPages = new String(findPages.substr(findPages.indexOf("<ul class='cat-pages'>"))); findPages = new String(findPages.substring(0,findPages.indexOf("</ul>"))); x = findPages.indexOf("<li>"); y = findPages.lastIndexOf("</li>"); findPages = new String(findPages.substring(x,y-x+5)); findPagesArr = findPages.split("<li>"); findPagesArr.shift(); pages = findPagesArr.length; } else { pages = 1; }
myStr = new String(xmlhttp.responseText);
x = myStr.indexOf('<table cellspacing="0" id="member_list_full">'); myStr = new String(myStr.substr(x)); y = myStr.indexOf("</table>"); myStr = new String(myStr.substr(0,y+8));
myStrArr = myStr.split("tr class="); myStrArr.shift(); for (i=0;i<myStrArr.length;i++) { myStrArr[i] = new String(myStrArr[i].substring(myStrArr[i].indexOf("<td>"),myStrArr[i].indexOf("</tr>"))); myStrArr[i] = new String(myStrArr[i].substr(myStrArr[i].indexOf("profile/")+8)); myStrArr[i] = new String(myStrArr[i].substr(0,myStrArr[i].indexOf("class='member'")-3)); pm.list[pm.list.length] = ["",parseInt(myStrArr[i])]; }
if(page < pages){ pm.roamGroup((page+1)); } else if(pm.groups.length > 1) { pm.groups.reverse();pm.groups.pop();pm.groups.reverse(); pm.roamGroup(1); } else { pm.addToList(); } }, addToList : function(){ var l = pm.add.length; pm.add.reverse(); while(l--){ var id = pm.add[l][1]; var uL = pm.list.length; var there = 0; while(uL--){ if(pm.list[uL][1] == id){ there = 1; } } if(there == 0){ pm.list[pm.list.length] = pm.add[l]; } } pm.removeFromList(); }, removeFromList : function(){ var l = pm.remove.length; pm.remove.reverse(); while(l--){ var id = pm.remove[l][1]; var uL = pm.list.length; while(uL--){ if(pm.list[uL][1] == id){ pm.list.splice(uL,1); continue; } } } if(pm.list.length > 0){ pm.startSending(); } else { alert("No one will receive this PM.\nThe PM has not been sent."); $("button[accesskey=s]").attr("disabled",false); } }, startSending : function(){ alert("The PMs will be sent now. Your browser may temporarily freeze to prevent any user interaction which may stop the PM process. You will get another alert when the PMs have all been sent.\nThis process may take a few seconds to a few minutes depending on how many users you are sending the PM to."); $.get(main_url+"msg/?c=2",function(f){ var secure = $("input[name=secure]",f).val(); var xc = $("input[name=xc]",f).val(); pm.snail(secure,xc); }); }, snail : function(secure,xc){ var id = pm.list[0][1]; var title = $("input[name=title]").val(); var content = $("#c_post-text").val(); $.post(main_url+"msg/?c=3&sd=1",{convo:0,draft_edit:0,fwd:0,mid:id,post:content,secure:secure,submit:"",title:title,xc:xc},function(){ $("form[action*='c=20&send=1']").submit(); if(pm.list.length > 1){ pm.list.reverse();pm.list.pop();pm.list.reverse(); pm.snail(secure,xc); } else { alert("All the PMs have been sent!"); location.reload(); } }); } } $.get($("#top_info a:first").attr("href"),function(d){ var myGroup = $.trim($("dl.user_info dt:contains('Group:')",d).next().text().toLowerCase()); var allowed = true, uL = pm.disallowed.length; while(uL--){ if($.trim(pm.disallowed[uL].toLowerCase())==myGroup){ allowed = false; } } if(allowed === true){ $("#pm_compose td.c_desc").next().attr("colspan",2); $("#emot_wrap").parent().next().attr("colspan",2); $("#pm_compose thead tr th,#c_post,#pm_compose tbody tr:last td,#pm_compose th[colspan=2]").attr("colspan",3) $("#pm_compose td.c_desc:first").text("Username").parent().addClass("single").after('<tr class="multi" style="display:none;"><td class="c_desc">Add Groups<br /><small><em>Adds all the members from the selected groups to the message list</em></small></td><td id="groups" colspan="2">Loading groups...</td></tr><tr class="multi" style="display:none;"><td class="c_desc">Add Users<br /><small><em>Add extra users to the mailing list<br />Each user should be added on a new line</em></small></td><td><textarea id="add" rows="3" cols="4"></textarea></td><td id="addFault"></td></tr><tr class="multi" style="display:none;"><td class="c_desc">Remove Users<br /><small><em>Remove pre-selected users from the mailing list<br />Each user should be added on a new line</em></small></td><td><textarea id="remove" rows="3" cols="4"></textarea></td><td id="removeFault"></td></tr></div>').before('<tr><td class="c_desc">Send To</td><td colspan="2"><button name="single" type="button" onclick="pm.single();">Single User</button> <button name="multiple" type="button" onclick="pm.multi();">Multiple Users</button></td></tr>'); $("form[name=posting]").submit(function(e){ pm.state == 2 ? (e.preventDefault ? e.preventDefault() : e.returnValue = false) : true; if(pm.state == 2){ $("button[accesskey=s]").attr("disabled",true); if($("input[name=title]").val().length<=0||$("#c_post-text").val().length<=0){ alert("You must input a title and PM content.\nThe PM has not been sent."); $("button[accesskey=s]").attr("disabled",false); } else if(($("#add").val().length + $("#remove").val().length == 0) && $("select[name=groups] option:first").attr("selected")===true){ alert("You must choose someone to send the PM to.\nThe PM has not been sent."); $("button[accesskey=s]").attr("disabled",false); } else { alert("The system will just check that you have inputted existing users, and then the PM will be sent."); pm.checkAdd(); } } }); } }); } </script>
Edited by mathwizz, Jun 19 2012, 01:40 AM.
|