Advertisement
tribulant

send-mailinglists.php

Sep 13th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.45 KB | None | 0 0
  1. <div class="submitbox">
  2.     <div>
  3.         <div class="misc-pub-section">
  4.        
  5.             <div id="groupsdiv">
  6.                 <?php if ($groups = $wpmlGroup -> select()) : ?>
  7.                     <div><label class="selectit" style="font-weight:bold;"><input type="checkbox" id="groupsselectall" name="groupsselectall" value="1" onclick="jqCheckAll(this, 'post', 'groups'); update_subscribers();" /> <?php _e('Select All Groups', $this -> plugin_name); ?></label></div>
  8.                     <div class="scroll-list">
  9.                         <?php foreach ($groups as $group_id => $group_title) : ?>
  10.                             <div><label class="selectit"><input onclick="update_subscribers();" <?php echo (!empty($_POST['groups']) && is_array($_POST['groups']) && in_array($group_id, $_POST['groups'])) ? 'checked="checked"' : ''; ?> type="checkbox" name="groups[]" id="checklist<?php echo $group_id; ?>" value="<?php echo $group_id; ?>" /> <?php echo __($group_title); ?> (<?php echo $Mailinglist -> count(array('group_id' => $group_id)); ?> <?php _e('lists', $this -> plugin_name); ?>)</label></div>
  11.                         <?php endforeach; ?>
  12.                     </div>
  13.                     <br/>
  14.                 <?php else : ?>
  15.                
  16.                 <?php endif; ?>
  17.             </div>
  18.             <div id="listsdiv">
  19.                 <?php if ($mailinglists = $Mailinglist -> select(true)) : ?>
  20.                     <div><label class="selectit" style="font-weight:bold;"><input type="checkbox" id="mailinglistsselectall" name="mailinglistsselectall" value="1" onclick="jqCheckAll(this, 'post', 'mailinglists'); update_subscribers();" /> <?php _e('Select All Lists', $this -> plugin_name); ?></label></div>
  21.                     <div class="scroll-list">
  22.                         <?php foreach ($mailinglists as $list_id => $list_title) : ?>
  23.                             <div><label class="selectit"><input onclick="update_subscribers();" <?php echo (!empty($_POST['mailinglists']) && is_array($_POST['mailinglists']) && in_array($list_id, $_POST['mailinglists'])) ? 'checked="checked"' : ''; ?> type="checkbox" name="mailinglists[]" id="checklist<?php echo $list_id; ?>" value="<?php echo $list_id; ?>" /> <?php echo $list_title; ?> (<?php echo $SubscribersList -> count(array('list_id' => $list_id, 'active' => "Y")); ?> <?php _e('active', $this -> plugin_name); ?>)</label></div>
  24.                         <?php endforeach; ?>
  25.                     </div>
  26.                 <?php else : ?>
  27.                     <p class="<?php echo $this -> pre; ?>error"><?php _e('No lists are available', $this -> plugin_name); ?></p>
  28.                 <?php endif; ?>
  29.             </div>
  30.         </div>
  31.        
  32.         <!-- Mailing Lists Errors -->
  33.         <?php global $errors, $wpdb; ?>
  34.         <?php if (!empty($errors['mailinglists'])) : ?>
  35.             <p class="<?php echo $this -> pre; ?>error"><?php echo $errors['mailinglists']; ?></p>
  36.         <?php endif; ?>
  37.        
  38.         <div class="misc-pub-section">
  39.             <h4><label><input onclick="update_subscribers(); if (this.checked == true) { jQuery('#daterange_div').show(); } else { jQuery('#daterange_div').hide(); }" <?php echo (!empty($_POST['daterange']) && $_POST['daterange'] == "Y") ? 'checked="checked"' : ''; ?> type="checkbox" name="daterange" value="Y" id="daterange" /> <?php _e('Specify date range', $this -> plugin_name); ?></label>
  40.             <?php echo $Html -> help(__('Specify a date range with a from/to date that subscribers subscribed to include in this newsletter. Both the From and To dates are required and should be in the format YYYY-MM-DD (without time).', $this -> plugin_name)); ?></h4>
  41.            
  42.             <div id="daterange_div" style="display:<?php echo (!empty($_POST['daterange']) && $_POST['daterange'] == "Y") ? 'block' : 'none'; ?>;">
  43.                 <p>
  44.                     <label for="daterangefrom"><?php _e('From Date', $this -> plugin_name); ?></label>
  45.                     <input onkeyup="update_subscribers();" type="text" name="daterangefrom" value="<?php echo esc_attr(stripslashes($_POST['daterangefrom'])); ?>" id="daterangefrom" class="widefat" style="width:120px;" />
  46.                 </p>
  47.                 <p>
  48.                     <label for="daterangeto"><?php _e('To Date', $this -> plugin_name); ?></label>
  49.                     <input onkeyup="update_subscribers();" type="text" name="daterangeto" value="<?php echo esc_attr(stripslashes($_POST['daterangeto'])); ?>" id="daterangeto" class="widefat" style="width:120px;" />
  50.                 </p>
  51.             </div>
  52.            
  53.             <script type="text/javascript">
  54.             jQuery(document).ready(function() {
  55.                 jQuery('#daterangefrom').datepicker({showButtonPanel:true, numberOfMonths:1, changeMonth:true, changeYear:true, defaultDate:"<?php echo $_POST['daterangefrom']; ?>", dateFormat:"yy-mm-dd"});
  56.                 jQuery('#daterangeto').datepicker({showButtonPanel:true, numberOfMonths:1, changeMonth:true, changeYear:true, defaultDate:"<?php echo $_POST['daterangeto']; ?>", dateFormat:"yy-mm-dd"});
  57.             });
  58.             </script>
  59.         </div>
  60.        
  61.         <?php $Db -> model = $Field -> model; ?>
  62.         <?php $fieldsquery = "SELECT `id`, `title`, `type`, `slug`, `fieldoptions` FROM `" . $wpdb -> prefix . $Field -> table . "` WHERE `type` = 'text' OR `type` = 'radio' OR `type` = 'select' OR `type` = 'pre_country' OR `type` = 'pre_gender' ORDER BY `order` ASC"; ?>
  63.         <?php if ($fields = $wpdb -> get_results($fieldsquery)) : ?>
  64.             <div class="misc-pub-section">
  65.                 <h4><label><input <?php echo (!empty($_POST['dofieldsconditions']) || !empty($_POST['conditions'])) ? 'checked="checked"' : ''; ?> type="checkbox" name="dofieldsconditions" value="1" id="dofieldsconditions" onclick="update_subscribers(); if (this.checked == true) { jQuery('#fieldsconditions').show(); } else { jQuery('#fieldsconditions').hide(); }" /> <?php _e('Fields Conditions', $this -> plugin_name); ?></label>
  66.                 <?php echo $Html -> help(__('The fields conditions work on the custom fields of your subscribers. You can filter or segment the subscribers in the chosen mailing list(s) to queue/send to subscribers with specific custom field values only. For example, with a "Gender" custom field, you can choose "Male" here under fields conditions to send only to male subscribers.', $this -> plugin_name)); ?></h4>
  67.                
  68.                 <div id="fieldsconditions" style="display:<?php echo (!empty($_POST['dofieldsconditions']) || !empty($_POST['conditions'])) ? 'block' : 'none'; ?>;">
  69.                     <p>
  70.                         <?php _e('Match', $this -> plugin_name); ?>
  71.                         <select onchange="update_subscribers();" name="fieldsconditionsscope" id="fieldsconditionsscope">
  72.                             <option <?php echo (empty($_POST['conditionsscope']) || $_POST['conditionsscope'] == "all") ? 'selected="selected"' : ''; ?> value="all"><?php _e('all', $this -> plugin_name); ?></option>
  73.                             <option <?php echo (!empty($_POST['conditionsscope']) && $_POST['conditionsscope'] == "any") ? 'selected="selected"' : ''; ?> value="any"><?php _e('any', $this -> plugin_name); ?></option>
  74.                         </select>
  75.                         <?php _e('of these conditions:', $this -> plugin_name); ?>
  76.                     </p>
  77.                
  78.                     <?php foreach ($fields as $field) : ?>
  79.                         <?php $supportedfields = array('text', 'radio', 'select', 'pre_country', 'pre_gender'); ?>
  80.                         <?php if (!empty($field -> type) && in_array($field -> type, $supportedfields)) : ?>
  81.                             <p>
  82.                                 <label for="fields_<?php echo $field -> id; ?>" style="font-weight:normal;"><?php echo __($field -> title); ?></label><br/>
  83.                                 <?php
  84.                                
  85.                                 switch ($field -> type) {
  86.                                     case 'text'             :
  87.                                         ?>
  88.                                        
  89.                                         <input onkeyup="update_subscribers();" type="text" name="fields[<?php echo $field -> slug; ?>]" value="<?php echo esc_attr(stripslashes($_POST['fields'][$field -> slug])); ?>" id="fields_<?php echo $field -> id; ?>" />
  90.                                        
  91.                                         <?php
  92.                                         break;
  93.                                     case 'radio'            :                                  
  94.                                         ?>
  95.                                        
  96.                                         <?php if ($fieldoptions = unserialize($field -> fieldoptions)) : ?>
  97.                                             <?php $r = 1; ?>
  98.                                             <label><input <?php echo (empty($_POST['fields'][$field -> slug])) ? 'checked="checked"' : ''; ?> type="radio" name="fields[<?php echo $field -> slug; ?>]" value="" onclick="update_subscribers();" id="fields_<?php echo $field -> id; ?>-0" /> <?php _e('ALL', $this -> plugin_name); ?></label><br/>
  99.                                             <?php foreach ($fieldoptions as $fieldoption_key => $fieldoption_val) : ?>
  100.                                                 <label><input <?php echo (!empty($_POST['fields'][$field -> slug]) && $_POST['fields'][$field -> slug] == $fieldoption_key) ? 'checked="checked"' : ''; ?> onclick="update_subscribers();" type="radio" name="fields[<?php echo $field -> slug; ?>]" value="<?php echo $fieldoption_key; ?>" id="fields_<?php echo $field -> id; ?>-<?php echo $r; ?>"  /> <?php echo __($fieldoption_val); ?></label><br/>
  101.                                                 <?php $r++; ?>
  102.                                             <?php endforeach; ?>
  103.                                         <?php endif; ?>
  104.                                        
  105.                                         <?php
  106.                                         break;
  107.                                     case 'select'           :
  108.                                         ?><select style="max-width:250px;" name="fields[<?php echo $field -> slug; ?>]" id="fields_<?php echo $field -> id; ?>" onchange="update_subscribers();">
  109.                                         <option value=""><?php _e('- Select -', $this -> plugin_name); ?></option>
  110.                                         <?php
  111.                                        
  112.                                         $fieldoptions = @unserialize($field -> fieldoptions);
  113.                                         foreach ($fieldoptions as $fieldoption_key => $fieldoption_val) {
  114.                                             ?><option <?php echo (!empty($_POST['fields'][$field -> slug]) && $_POST['fields'][$field -> slug] == $fieldoption_key) ? 'selected="selected"' : ''; ?> value="<?php echo $fieldoption_key; ?>"><?php echo __($fieldoption_val); ?></option><?php 
  115.                                         }
  116.                                        
  117.                                         ?>
  118.                                         </select><?php
  119.                                         break;
  120.                                     case 'pre_country'      :
  121.                                         ?>
  122.                                        
  123.                                         <?php if ($countries = $wpmlCountry -> select()) : ?>
  124.                                             <select style="max-width:250px;" name="fields[<?php echo $field -> slug; ?>]" id="fields_<?php echo $field -> id; ?>" onchange="update_subscribers();">
  125.                                                 <option value=""><?php _e('- Select Country -', $this -> plugin_name); ?></option>
  126.                                                 <?php foreach ($countries as $country_id => $country_name) : ?>
  127.                                                     <option <?php echo (!empty($_POST['fields'][$field -> slug]) && $_POST['fields'][$field -> slug] == $country_id) ? 'selected="selected"' : ''; ?> value="<?php echo $country_id; ?>"><?php echo $country_name; ?></option>
  128.                                                 <?php endforeach; ?>
  129.                                             </select>
  130.                                         <?php endif; ?>
  131.                                        
  132.                                         <?php
  133.                                         break;
  134.                                     case 'pre_gender'       :
  135.                                         ?>
  136.                                        
  137.                                         <select style="max-width:250px;" name="fields[<?php echo $field -> slug; ?>]" id="fields_<?php echo $field -> id; ?>" onchange="update_subscribers();">
  138.                                             <option value=""><?php _e('- Select Gender -', $this -> plugin_name); ?></option>
  139.                                             <option <?php echo (!empty($_POST['fields'][$field -> slug]) && $_POST['fields'][$field -> slug] == "male") ? 'selected="selected"' : ''; ?> value="male"><?php _e('Male', $this -> plugin_name); ?></option>
  140.                                             <option <?php echo (!empty($_POST['fields'][$field -> slug]) && $_POST['fields'][$field -> slug] == "female") ? 'selected="selected"' : ''; ?> value="female"><?php _e('Female', $this -> plugin_name); ?></option>
  141.                                         </select>
  142.                                        
  143.                                         <?php
  144.                                         break; 
  145.                                 }
  146.                                
  147.                                 ?>
  148.                             </p>
  149.                         <?php endif; ?>
  150.                     <?php endforeach; ?>
  151.                 </div>
  152.             </div>
  153.         <?php endif; ?>
  154.        
  155.         <div class="misc-pub-section misc-pub-section-last">
  156.             <div id="subscriberscount">
  157.                 <p><?php _e('0 subscribers total', $this -> plugin_name); ?></p>
  158.             </div>
  159.            
  160.             <p>
  161.                 <a class="button button-secondary" id="updatesubscriberscountbutton" href="javascript:update_subscribers();"><?php _e('Update Count', $this -> plugin_name); ?></a>
  162.                 <?php echo $Html -> help(__('Click this button to update the subscribers count above in real-time. The subscribers count is an accurate count of how many subscribers this newsletter will be sent to based on the group, mailing list, fields conditions and other selections made.', $this -> plugin_name)); ?>  
  163.             </p>
  164.         </div>
  165.     </div>
  166. </div>
  167.  
  168. <script type="text/javascript">
  169. var srequest = false;
  170.  
  171. jQuery(document).ready(function() {
  172.     <?php if (!empty($_POST['mailinglists'])) : ?>
  173.         update_subscribers();
  174.     <?php endif; ?>
  175. });
  176.  
  177. function update_subscribers() {
  178.     var data = {action:"subscribercount", fieldsconditionsscope:jQuery('#fieldsconditionsscope').val(), mailinglists:[], groups:[], fields:[]};
  179.     if (srequest) { srequest.abort(); }
  180.     jQuery('#updatesubscriberscountbutton').attr('disabled', "disabled");
  181.    
  182.     jQuery('input:checkbox[name="mailinglists[]"]:checked').each(function() {
  183.         var mailinglist_id = jQuery(this).val();
  184.         data['mailinglists'].push(mailinglist_id);
  185.     });
  186.    
  187.     jQuery('input:checkbox[name="groups[]"]:checked').each(function() {
  188.         var group_id = jQuery(this).val();
  189.         data['groups'].push(group_id); 
  190.     });
  191.    
  192.     if (jQuery('#daterange').is(':checked')) {
  193.         data['daterange'] = "Y";
  194.         data['daterangefrom'] = jQuery('#daterangefrom').val();
  195.         data['daterangeto'] = jQuery('#daterangeto').val();
  196.     }
  197.    
  198.     if (jQuery('input:checkbox[id="dofieldsconditions"]:checked').length > 0) {        
  199.         var fieldsarray = new Array();
  200.         var f = 0;
  201.         jQuery('[name^="fields"]').each(function() {
  202.             if (jQuery(this).attr('type') == "radio") {                
  203.                 if (jQuery(this).is(":checked")) {
  204.                     fieldsarray[f] = new Array(jQuery(this).attr('id'), jQuery(this).val());   
  205.                 }
  206.             } else {
  207.                 fieldsarray[f] = new Array(jQuery(this).attr('id'), jQuery(this).val());
  208.             }
  209.            
  210.             f++;
  211.         });
  212.        
  213.         data['fields'] = fieldsarray;
  214.     }
  215.    
  216.     jQuery("#subscriberscount").html('<p><img src="<?php echo $this -> url(); ?>/images/loading.gif" /> <?php echo addslashes(__('loading subscriber count...', $this -> plugin_name)); ?></p>');
  217.        
  218.     srequest = jQuery.post(ajaxurl, data, function(response) {
  219.         if (response == "0") {
  220.             jQuery('#sendbutton').attr('disabled', "disabled");
  221.             jQuery('#subscriberscount').html('<?php echo addslashes(__('No subscribers available.', $this -> plugin_name)); ?>');
  222.         } else {
  223.             delete data.action;
  224.             //newresponse = '<p><a href="" onclick="jQuery.colorbox({href:\'' + ajaxurl + '?action=subscribercountdisplay&' + jQuery.param(data) + '\'}); return false;">' + response + '</a></p>';
  225.             newresponse = '<p>' + response + '</p>';
  226.             jQuery('#sendbutton').removeAttr('disabled');
  227.             jQuery('#subscriberscount').html(newresponse);
  228.             jQuery('#updatesubscriberscountbutton').removeAttr('disabled');
  229.         }
  230.     });
  231. }
  232. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement