Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_manager_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 
19 
33 {
34 
35 
41  {
42  $this->Asset_Edit_Fns();
43 
44  // disable all static screens
45  $this->static_screens = Array();
46 
47  // enable just the details
48  $this->static_screens['details']['name'] = translate('details');
49  $this->static_screens['details']['force_unlock'] = FALSE;
50 
51  }//end constructor
52 
53 
66  function paintTriggerScreen(&$tm, &$o, $prefix)
67  {
68  $write_access = $tm->writeAccess('attributes');
69 
70  $o->openField('');
71 
72  $o->sectionNote(translate('trigger_subscreen_add_or_edit'));
73 
74  // we now only display a list of triggers for editing
75  $this->_paintSubScreenList($tm, $o, $prefix, $write_access);
76 
77  $o->closeField();
78  return $write_access;
79 
80  }//end paintTriggerScreen()
81 
82 
95  function processTriggerScreen(&$tm, &$o, $prefix)
96  {
97  return $tm->writeAccess('attributes');
98 
99  }//end processTriggerScreen()
100 
101 
113  function _paintSubScreenList(&$tm, &$o, $prefix, $write_access)
114  {
115  $o->closeSection();
116  $list = $tm->_getTriggerInfoList();
117 
118  $o->openSection(translate('trigger_list'));
119  $o->openField('');
120  ?>
121  <script type="text/javascript">
122  //<![CDATA[
123  var deleteCheckedCount = 0;
124 
125  function confirmDelete()
126  {
127  var result = true;
128 
129  if (deleteCheckedCount > 0) {
130  result = confirm (js_translate('confirm_delete_trigger', deleteCheckedCount));
131  }
132 
133  return result;
134  }
135 
136  function checkDelete(checked)
137  {
138  if (checked) {
139  deleteCheckedCount++;
140  } else {
141  deleteCheckedCount--;
142  }
143  }
144  //]]>
145  </script>
146  <table class="sq-backend-table">
147  <tr>
148  <td width="50" class="sq-backend-table-header" style="font-weight: bold;"><?php echo translate('id'); ?></td>
149  <td class="sq-backend-table-header" style="font-weight: bold;"><?php echo translate('name'); ?></td>
150  <td class="sq-backend-table-header" style="font-weight: bold;"><?php echo translate('description'); ?></td>
151  <td width="50" class="sq-backend-table-header" style="font-weight: bold;"><?php echo translate('status'); ?></td>
152  </tr>
153 
154  <?php
155 
156  foreach ($list as $trigger) {
157  $trigger_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset(implode(':', Array($tm->id, $trigger['id'])));
158  if (is_null($trigger_asset)) continue;
159 
160  $trigger_url = $trigger_asset->getBackendHref('details');
161  $active_text = $trigger['active'] ? '<strong>'.translate('active').'</strong>' : '<span style="color: red">'.translate('inactive').'</span>';
162  ?>
163  <tr>
164  <td class="sq-backend-table-cell"><?php echo $trigger['id']; ?></td>
165  <td class="sq-backend-table-cell"><a href="<?php echo $trigger_url; ?>"><?php echo $trigger['name']; ?></a></td>
166  <td class="sq-backend-table-cell"><?php echo $trigger['description']; ?></td>
167  <td class="sq-backend-table-cell"><strong><?php echo $active_text; ?></strong></td>
168  </tr>
169  <?php
170  }
171  ?>
172  </table>
173  <?php
174 
175  $o->closeSection();
176  $o->addOnsubmit('return confirmDelete();');
177 
178  return TRUE;
179 
180  }//end _paintSubScreenList()
181 
182 
193  function paintBatching(&$tm, &$o, $prefix)
194  {
195  $write_access = $tm->writeAccess('attributes');
196  if ($write_access) {
197  $o->openField(translate('trigger_ids'));
198  multiple_asset_finder($prefix.'[trigger_ids]', array_get_index($this->_tmp, 'trigger_ids', Array()), Array('trigger' => 'I'));
199  $o->note(translate('trigger_ids_note'));
200 
201  $o->openField(translate('target_node'));
202  asset_finder($prefix.'[target_node]', array_get_index($this->_tmp, 'target_id'));
203 
204  $o->openField(translate('children'));
205  check_box($prefix.'[include_children]', 'yes', array_get_index($this->_tmp, 'include_children', TRUE));
206  label(translate('include_children_question'), $prefix.'[include_children]');
207 
208  $o->openField(translate('events'));
209  $event_type_list = $tm->_getEventList();
210  $events = array_get_index($this->_tmp, 'selected_events');
211  // paint a tickbox list of all the events in the system
212  $event_prefix = $prefix.'[selected_events]';
213  foreach ($event_type_list as $e_type => $e_name) {
214  if (isset($events[$e_type])) {
215  $checked = TRUE;
216  } else {
217  $checked = FALSE;
218  }
219  check_box($event_prefix.'['.$e_type.']', $e_type, $checked);
220  label($e_name, $event_prefix.'['.$e_type.']');
221  ?><br /> <?php
222  }
223  return TRUE;
224  } else {
225  return FALSE;
226  }
227 
228  }//end paintBatching()
229 
230 
243  function processBatching(&$tm, &$o, $prefix)
244  {
245  $error = FALSE;
246 
247  $request_data = array_get_index($_REQUEST, $prefix, Array());
248 
249  $target_node = array_get_index($request_data, 'target_node');
250  $target_id = array_get_index($target_node, 'assetid');
251 
252  $triggers = array_get_index($request_data, 'trigger_ids');
253  $trigger_ids = Array();
254  foreach ($triggers as $trigger_id) {
255  if ($trigger_id['assetid']) {
256  $trigger_ids[] = substr($trigger_id['assetid'], strpos($trigger_id['assetid'], ':') + 1);
257  }
258  }
259 
260  $events = array_get_index($request_data, 'selected_events', Array());
261  $propagate = isset($request_data['include_children']);
262 
263  $this->_tmp['target_id'] = $target_id;
264  $this->_tmp['trigger_ids'] = $trigger_ids;
265  $this->_tmp['selected_events'] = $events;
266  $this->_tmp['include_children'] = $propagate;
267 
268  if (empty($target_id)) {
269  trigger_localised_error('CORE0132', E_USER_WARNING);
270  $error = TRUE;
271  }
272 
273  if (empty($events)) {
274  trigger_localised_error('CORE0126', E_USER_WARNING);
275  $error = TRUE;
276  }
277 
278  if ($error) return FALSE;
279 
280  // grab all the children of the target if applicable, then add the target itself
281  $all_targets = Array();
282  if ($propagate) {
283  $all_targets = $GLOBALS['SQ_SYSTEM']->am->getChildren($target_id);
284  }
285  $target_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($target_id);
286  $all_targets[$target_id] = $target_asset->type();
287 
288  // convert from id->type to index->id
289  $all_targets = array_keys($all_targets);
290 
291  // start up the HIPO
292  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
293  $vars = Array(
294  'assets' => $all_targets,
295  'events' => $events,
296  'event_parameters' => Array('specified_trigger_ids' => $trigger_ids),
297  'codename_target' => $target_id,
298  'codename_propagate' => ($propagate ? '1' : '0'),
299  );
300  $hh->queueHipo('hipo_job_trigger_batch_events', $vars);
301 
302  return TRUE;
303 
304  }//end processBatching()
305 
306 
307 }//end class
308 
309 ?>