Mailinglist
 All Data Structures Files Functions Variables Pages
MailinglistMembersOperation.class.php
Go to the documentation of this file.
1 <?php
11 
31  function form(&$form, &$form_state, $list) {
32  $section = $form_state['build_info']['args'][2];
33  $chunksize = 30; //@todo: make configurable
34  $listname = $list->admin_name;
35 
36 // Admin Progress line, only show to those with 'administer mailinglist members' permission
37  if (user_access('administer mailinglist members')) {
38  if ($section == "test") {
40  }
41  $ScanStart = format_date(_mailinglist_datetime_ts($list->parameters['ScanStart']), 'long');
42  $progress = 'Progress: ' . $ScanStart . ' : ';
43  $next = $list->parameters['ScanNext'];
44  if (is_array($next)) {
45  foreach ($next as $item) {
46  $progress .= (string)$item . ' ';
47  }
48  }
49  else {
50  if($next === TRUE) {
51  $progress .= 'Cleanup';
52  }
53  elseif ($next === FALSE) {
54  $progress .= 'Done';
55  }
56  else {
57  $progress .= (string)$next;
58  }
59  }
60  $form['progress'] = array('#markup' => $progress . '<br>');
61  }
62 
63  $sub_types = array(
64  MAILINGLIST_SUB_NO => "Not Subscribed",
65  MAILINGLIST_SUB_NOMAIL => "No Mail",
66  MAILINGLIST_SUB_INDEX => "Index:",
67  MAILINGLIST_SUB_DIGEST => 'Digest',
68  MAILINGLIST_SUB_MIME_DIGEST => 'Mime Digest',
69  MAILINGLIST_SUB_NORMAL => 'Individual Messages',
70  );
71 
72 // If don't have 'mailinglist $listname member details" or not in a section
73 // Display a summary of members.
74  if (!user_access('mailinglist ' . $listname . ' member details')
75  or 0 == strlen($section) or $section == 'test') {
76 
77  $sql = 'SELECT sub_type, COUNT(sub_type) as cnt' .
78  ' FROM {mailinglist_members_subscribers__' . $listname . '}' .
79  ' WHERE sub_type > 0 GROUP BY sub_type ORDER BY cnt DESC';
80  $result = db_query($sql, array());
81  $total = 0;
82  while ($row = $result -> fetchAssoc()) {
83  $cat = $row['sub_type'];
84  $cnt = $row['cnt'];
85  $subs[$sub_types[$cat]] = $cnt;
86  $total += $cnt;
87  }
88 
89  $form['Member Total'] =
90  array('#markup' => 'Membership Summary: ' . $total . ' Members<br>');
91  $form['Sub Types'] = array(
92  '#theme' => 'table',
93  '#header' => array(
94  array('data' => t('Subscription Type')),
95  array('data' => t('Percentage')),
96  ),
97  '#rows' => array(),
98  );
99  foreach ($subs as $type => $cnt) {
100  $form['Sub Types']['#rows'][$type] = array($type, number_format(100*$cnt/$total, 1) . '%');
101  }
102 
103  $form['Domains'] = array(
104  '#theme' => 'table',
105  '#header' => array(
106  array('data' => t('Domain')),
107  array('data' => t('Percentage')),
108  ),
109  '#rows' => array(),
110  );
111 
112  $sql = 'SELECT domain, COUNT(sub_type) as cnt' .
113  ' FROM {mailinglist_members_subscribers__' . $listname . '}' .
114  ' WHERE sub_type > 0 GROUP BY domain HAVING cnt >= 20 ORDER BY cnt DESC LIMIT 10' ;
115  $result = db_query($sql, array());
116 
117  while ($row = $result -> fetchAssoc()) {
118  $domain = $row['domain'];
119  $cnt = $row['cnt'];
120  $form['Domains']['#rows'][$domain] = array($domain, number_format(100*$cnt/$total, 1) . '%');
121  }
122  }
123 
124 // Details Section, only show if have 'mailinglist $listname member details'
125 
126  if (user_access('mailinglist ' . $listname . ' member details')) {
127  // Header, with list of letters used
128 
129  $base = variable_get('mailinglist_base', 'mailinglist');
130 
131  $form['details']['home'] = array('#markup' => l('Summary', "$base/$listname/members") . ' ');
132  $sql = 'SELECT SUBSTRING(email, 1, 1) as c' .
133  ' FROM {mailinglist_members_subscribers__' . $listname . '}' .
134  ' GROUP BY c';
135  $result = db_query($sql, array());
136  while ($row = $result -> fetchAssoc()) {
137  $letter = $row['c'];
138  $form['details']['letters'][$letter] =
139  array('#markup' => l($letter, "$base/$listname/members/$letter") . ' ');
140  }
141 
142  if (user_access('administer mailinglist members')) {
143  $form['details']['test'] = array('#markup' => l('Test', "$base/$listname/members/test"));
144  }
145  // Detail block
148  if (0 < strlen($section) and $section != 'test') {
149  $letter = $section[0];
150  $nextletter = $letter . 'zzzzzzzzzzzzzzzzzz'; /* chr(ord($letter)+1); */
151  if(strlen($section) >1) {
152  $skip = $chunksize * (int)substr($section, 1);
153  } else {
154  $skip = 0;
155  }
156  $form['details']['members'] = array(
157  '#theme' => 'table',
158  '#header' => array(
159  'email' => array('data' => t('EMail')),
160  'type' => array('data' => t('Type')),
161  'moderated' => array('data' => t('Moderated')),
162  ),
163  '#rows' => array(),
164  );
165 
166  $sql = 'SELECT email, sub_type, moderated, options' .
167  ' FROM {mailinglist_members_subscribers__' . $listname . '}' .
168  ' WHERE sub_type > 0 and \'' .$letter .'\' <= email and email < \'' . $nextletter . '\'' .
169  ' ORDER BY email ASC';
170  $result = db_query($sql, array());
171  $index = 0;
172  $building = 0;
173  $chunk = 0;
174  while($row = $result -> fetchAssoc()){
175  if(!$building) {
176  $building = 1;
177  $firstname = $row['email'];
178  }
179  if($skip > 0) {
180  $skip--;
181  }
182  else if($index < $chunksize) {
183  $options = unserialize($row['options']);
184  $form['details']['members']['#rows'][$index] = array(
185  'email' => $row['email'],
186  'type' => $sub_types[$row['sub_type']],
187  'moderated' => $row['moderated'] ? 'Moderated' : '',
188  );
189  foreach($options as $key => $value) {
190  $form['details']['members']['#header'][$key] = array('data' => t($key));
191  if($value === False) {
192  $value = '-';
193  }
194  if($value === True) {
195  $value = $key;
196  }
197  $form['details']['members']['#rows'][$index][$key] = $value;
198  }
199  $index++;
200  }
201  else {
202  $index++;
203  }
204  if(($skip + $index) % $chunksize == 0) {
205  $form['details']['index'][$chunk] =
206  array('#markup' => l($firstname . ' - ' . $row['email'],
207  "$base/$listname/members/$letter$chunk") . '<br>');
208  $chunk++;
209  $building = 0;
210  }
211  } // End while($row)
212  }
213  }
214  } // End function form()
215 
223  function validate(&$form, &$form_state, $list) {
224  }
225 
233  function submit(&$form, &$form_state, $list) {
234  }
235 
237 }
Base Class for Mailinglist extensions.
const MAILINGLIST_SUB_MIME_DIGEST
const MAILINGLIST_SUB_NO
Defines for sub_types (subscription types)
submit(&$form, &$form_state, $list)
Operation page form submission.
Base Class for Mailinglist extensions.
const MAILINGLIST_SUB_NOMAIL
const MAILINGLIST_SUB_DIGEST
form(&$form, &$form_state, $list)
Operation page form generation.
const MAILINGLIST_SUB_INDEX
mailinglist_members_scan($list)
Process a partial scan of members for a mailinglist.
validate(&$form, &$form_state, $list)
Operation page form validation.
const MAILINGLIST_SUB_NORMAL
_mailinglist_datetime_ts($time)
Convert a 'datetime' field into a timestamp.