Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
bulkmail_manager_edit_fns.inc
1 <?php
17 require_once SQ_PACKAGES_PATH.'/bulkmail/bulkmail_post_office/bulkmail_post_office_edit_fns.inc';
18 
19 
36 {
37 
38 
43  function __construct()
44  {
45  parent::__construct();
46 
47  unset($this->static_screens['settings']);
48  unset($this->static_screens['preview']);
49  unset($this->static_screens['lookupValues']);
50  unset($this->static_screens['metadata']);
51  unset($this->static_screens['metadataSchemas']);
52  unset($this->static_screens['workflow']);
53  unset($this->static_screens['tagging']);
54  unset($this->static_screens['dependants']);
55  unset($this->static_screens['linking']);
56  unset($this->static_screens['roles']);
57  unset($this->static_screens['permissions']);
58  unset($this->static_screens['layouts']);
59 
60  }//end constructor
61 
62 
73  function paintJobQueue(&$asset, &$o, $prefix)
74  {
75  $write_access = $asset->writeAccess('attributes');
76 
77  $o->openField('');
78  $jobs = $asset->getQueuedJobs();
79  $this->_paintJobQueue($asset, $jobs);
80  $o->closeField();
81 
82  return $write_access;
83 
84  }//end paintJobQueue()
85 
86 
97  function processJobQueue(&$asset, &$o, $prefix)
98  {
99  $write_access = $asset->writeAccess('attributes');
100 
101  if (!$write_access) return;
102 
103  $jobs = $asset->getQueuedJobs();
104  $this->_processJobQueue($asset, $jobs);
105 
106  return TRUE;
107 
108  }//end processJobQueue()
109 
110 
120  function _processJobQueue(&$asset, $jobs)
121  {
122  $bulkmail_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('bulkmail_manager');
123 
124  foreach ($jobs as $job_id => $job_info) {
125  $prefix = $asset->getPrefix();
126  if (!empty($_REQUEST[$prefix.'_'.$job_id])) {
127  switch ($_REQUEST[$prefix.'_'.$job_id]) {
128  case 'resume':
129  $bulkmail_manager->updateJob($job_id, BML_JOB_STATE_NOT_RUNNING);
130  break;
131  case 'pause':
132  $bulkmail_manager->updateJob($job_id, BML_JOB_STATE_PAUSED);
133  break;
134  case 'cancel':
135  // log a message if this is not an ad-hoc job
136  $job_id_parts = explode(':', $job_id);
137  if (!isset($job_id_parts[1])) {
138  $msg_reps = Array(
139  'user_id' => $GLOBALS['SQ_SYSTEM']->currentUserId(),
140  );
141  $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
142  $message = $ms->newMessage(Array(), 'bulkmail.job.cancelled', $msg_reps);
143  $message->parameters['assetid'] = $job_id;
144  $message->send();
145  }
146  $bulkmail_manager->deleteJob($job_id);
147  break;
148  }
149  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($bulkmail_manager);
150  }
151  }
152 
153  return;
154 
155  }//end _processJobQueue()
156 
157 
169  function _paintJobQueue(&$asset, $jobs)
170  {
171  if (empty($jobs)) return;
172 
173  $write_access = $asset->writeAccess('attributes');
174 
175  $bulkmail_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('bulkmail_manager');
176 
177  ?>
178  <table class="sq-backend-table">
179  <tr>
180  <th class="sq-backend-table-header"><?php echo translate('bm_job_table_header_id'); ?></th>
181  <th class="sq-backend-table-header"><?php echo translate('bm_job_table_header_job'); ?></th>
182  <th class="sq-backend-table-header"><?php echo translate('bm_job_table_header_post_office'); ?></th>
183  <th class="sq-backend-table-header"><?php echo translate('bm_job_table_header_state'); ?></th>
184  <th class="sq-backend-table-header"><?php echo translate('bm_job_table_header_progress'); ?></th>
185  <?php
186  if ($write_access) {
187  ?><th class="sq-backend-table-header"><?php echo translate('bm_job_table_header_control'); ?></th><?php
188  }
189  ?>
190  <tr>
191  <?php
192  foreach ($jobs as $jobid => $job_info) {
193  $jobid_parts = explode(':', $jobid);
194  if (isset($jobid_parts[1])) {
195  $name = translate('bm_adhoc_job_name');
196  } else {
197  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($jobid), Array(), TRUE, 'name');
198  $name = array_shift($asset_info);
199  }
200 
201  $progress = $job_info['progress'];
202  $progress_string = translate('bm_job_progress_none');
203  if (!empty($progress) && $progress['total_count'] != 0) {
204  $percent_done = round(($progress['current_count'] / $progress['total_count']) * 100, 2).'%';
205  $progress_string = translate('bm_job_progress', number_format($progress['current_count']), number_format($progress['total_count']), $percent_done);
206  }
207  ?>
208  <tr>
209  <td align="left" class="sq-backend-table-cell"><?php echo $jobid; ?></td>
210  <td align="left" class="sq-backend-table-cell"><?php echo $name; ?></td>
211  <td align="left" class="sq-backend-table-cell"><?php echo get_asset_tag_line($job_info['po_id']); ?></td>
212  <td align="left" class="sq-backend-table-cell">
213  <?php
214  switch ($job_info['status']) {
215  case BML_JOB_STATE_RUNNING:
216  echo translate('bm_state_running');
217  break;
218  case BML_JOB_STATE_NOT_RUNNING:
219  echo translate('bm_state_not_running');
220  break;
221  case BML_JOB_STATE_PAUSED:
222  echo translate('bm_state_paused');
223  break;
224  case BML_JOB_STATE_SLEEPING:
225  echo translate('bm_state_sleeping');
226  break;
227  default:
228  echo translate('bm_state_unknown');
229  break;
230  }
231  ?>
232  </td>
233  <td align="left" class="sq-backend-table-cell"><?php echo $progress_string; ?></td>
234  <?php
235  if ($write_access) {
236  ?>
237  <td align="left" class="sq-backend-table-cell">
238  <?php
239  $options = Array(
240  '' => '',
241  'cancel' => translate('bm_state_action_cancel'),
242  );
243  switch ($job_info['status']) {
244  case BML_JOB_STATE_RUNNING:
245  case BML_JOB_STATE_NOT_RUNNING:
246  $options['pause'] = translate('bm_state_action_pause');
247  break;
248  case BML_JOB_STATE_PAUSED:
249  $options['resume'] = translate('bm_state_action_resume');
250  break;
251  default:
252  }
253 
254  combo_box($asset->getPrefix().'_'.$jobid, $options, FALSE, '');
255  ?>
256  </td>
257  <?php
258  }
259  ?>
260  <tr>
261  <?php
262  $GLOBALS['SQ_SYSTEM']->am->forgetAsset($post_office);
263  }//end foreach
264  ?>
265  </table>
266  <?php
267 
268  }//end _paintJobQueue()
269 
270 
280  function showProgressSection(&$asset, $prefix)
281  {
282  $jobs = $asset->getQueuedJobs();
283  return (empty($jobs) ? FALSE : TRUE);
284 
285  }//end showProgressSection()
286 
287 
298  function paintThresholdSettingCheckBox(&$asset, &$o, $prefix)
299  {
300  $write_access = $asset->writeAccess('attributes');
301  $use_bm_threshold = $asset->attr('use_bm_threshold');
302 
303  // paint checkbox
304  if ($write_access) {
305  check_box($prefix.'_use_bm_threshold', TRUE, $use_bm_threshold);
306  } else {
307  ?>
308  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $use_bm_threshold ? 'tick' : 'cross'; ?>.gif" width="15" height="15" />
309  <?php
310  }
311 
312  return $write_access;
313 
314  }//end paintThresholdSettingCheckBox()
315 
316 
327  function processThresholdSettingCheckBox(&$asset, &$o, $prefix)
328  {
329  if (!$asset->writeAccess('attributes')) return FALSE;
330  // save whether to use bulkmail manager threshold settings
331  $use_bm_threshold = isset($_POST[$prefix.'_use_bm_threshold']);
332  $asset->setAttrValue('use_bm_threshold', $use_bm_threshold);
333 
334  return TRUE;
335 
336  }//end processThresholdSettingCheckBox()
337 
338 
339 }//end class
340 ?>