Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_delete_bmail_user.inc
1 <?php
16 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
17 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
18 require_once SQ_SYSTEM_ROOT.'/core/attributes/parameter_map/parameter_map.inc';
19 require_once SQ_FUDGE_PATH.'/general/www.inc';
20 
32 {
33 
34 
53  public static function execute($settings, &$state)
54  {
55  // check for required settings
56  if (!isset($settings['emails'])) return FALSE;
57 
58  $parameter_map_value = array_get_index($settings, 'parameter_map_target_asset', serialize(Array()));
59  $attr_parameter_map = new Asset_Attribute_Parameter_Map(0, $parameter_map_value);
60  $map_assetid = $attr_parameter_map->getParameterValue('asset');
61  $map_emails = $attr_parameter_map->getParameterValue('emails');
62  $map_link_assetid = $attr_parameter_map->getParameterValue('link_asset');
63 
64  if (empty($settings['assetid']) && empty($map_assetid)) {
65  return FALSE;
66  }
67 
68  if (empty($settings['emails']) && empty($map_emails)) {
69  return FALSE;
70  }
71 
72  if (!$GLOBALS['SQ_SYSTEM']->am->assetExists($settings['assetid'])) {
73  return FALSE;
74  }
75 
76  if (!is_null($map_assetid) && !$GLOBALS['SQ_SYSTEM']->am->assetExists($map_assetid)) {
77  return FALSE;
78  }
79 
80  // whether we use the parameter map value or the settings value
81  $assetid = is_null($map_assetid) ? $settings['assetid'] : $map_assetid;
82  $emails = is_null($map_emails) ? $settings['emails'] : $map_emails;
83  $link_assetid = is_null($map_link_assetid) ? $settings['link_assetid'] : $map_link_assetid;
84 
85  // check the emails string and make an array with the valid ones only
86  $emails = explode(",",$emails);
87  foreach ($emails as $key => $value) {
88  if (!valid_email(trim($value))) unset($emails[$key]);
89  }
90 
91  // return if there are no emails after validation
92  if (empty($emails)) return FALSE;
93 
94  // link instead deleting when link assetid was supplied
95  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
96  if (!empty($link_assetid)) {
97  $vars = Array(
98  'root_nodes' => Array($assetid),
99  'email_list' => $emails,
100  'link_asset' => Array(
101  'assetid' => $link_assetid,
102  'link_type' => $settings['link_type'],
103  ),
104  );
105  $link_errors = $hh->freestyleHipo('hipo_job_tool_delete_bmail_users', $vars, SQ_PACKAGES_PATH.'/bulkmail/hipo_jobs');
106  if (!empty($link_errors)) return FALSE;
107  } else {
108  $vars = Array(
109  'root_nodes' => Array($assetid),
110  'email_list' => $emails,
111  );
112  $delete_errors = $hh->freestyleHipo('hipo_job_tool_delete_bmail_users', $vars, SQ_PACKAGES_PATH.'/bulkmail/hipo_jobs');
113  if (!empty($delete_errors)) return FALSE;
114  }
115  return TRUE;
116 
117  }//end execute()
118 
119 
130  public static function getInterface($settings, $prefix, $write_access=FALSE)
131  {
132  // check settings, set defaults if necessary
133  $selected_assetid = array_get_index($settings, 'assetid', 0);
134  $emails = array_get_index($settings, 'emails', '');
135  $selected_link_assetid = array_get_index($settings, 'link_assetid', 0);
136  $selected_link_type = array_get_index($settings, 'link_type', SQ_LINK_TYPE_1);
137 
138  if (!$write_access) {
139  $form_element_extras = 'disabled="disabled"';
140  } else {
141  $form_element_extras = '';
142  }
143 
144  ob_start();
145  if ($write_access) {
146  asset_finder($prefix.'[assetid]', $selected_assetid);
147  } else {
148  if ($selected_assetid) {
149  $selected_assetname = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($selected_assetid), Array(), TRUE, 'name');
150  text_box($prefix.'[assetid]', $selected_assetname[$selected_assetid].' (#'.$selected_assetid.')', '', '', FALSE, $form_element_extras);
151  } else {
152  text_box($prefix.'[assetid]', '', '', '', FALSE, $form_element_extras);
153  }
154  }
155  $basic_part_1 = ob_get_contents();
156  ob_end_clean();
157 
158  ob_start();
159  text_box($prefix.'[emails]', $emails, 100, '', '', $form_element_extras);
160  $basic_part_2 = ob_get_contents();
161  ob_end_clean();
162 
163  ob_start();
164  if ($write_access) {
165  asset_finder($prefix.'[link_assetid]', $selected_link_assetid);
166  } else {
167  if ($selected_link_assetid) {
168  $selected_assetname = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($selected_link_assetid), Array(), TRUE, 'name');
169  text_box($prefix.'[link_assetid]', $selected_assetname[$selected_link_assetid].' (#'.$selected_link_assetid.')', '', '', FALSE, $form_element_extras);
170  } else {
171  text_box($prefix.'[link_assetid]', '', '', '', FALSE, $form_element_extras);
172  }
173  }
174  $basic_part_3 = ob_get_contents();
175  ob_end_clean();
176 
177  $link_type_list = get_link_type_names();
178 
179  ob_start();
180  combo_box($prefix.'[link_type]', $link_type_list, FALSE, $selected_link_type, NULL, $form_element_extras);
181  $basic_part_4 = ob_get_contents();
182  ob_end_clean();
183 
184  // attribute friendly prefix
185  $new_prefix = str_replace(array('[',']'), '_', $prefix);
186  hidden_field($prefix.'[new_prefix]', $new_prefix);
187 
188  // parameter map options
189  ob_start();
190  $parameter_map_value = array_get_index($settings, 'parameter_map_target_asset', serialize(Array()));
191  $attr_parameter_map = new Asset_Attribute_Parameter_Map(0, $parameter_map_value);
192  $attr_parameter_map->setParameter('asset', 'Root node');
193  $attr_parameter_map->setParameter('emails', 'Emails');
194  $attr_parameter_map->setParameter('link_asset', 'Link under node');
195  echo $attr_parameter_map->paint($new_prefix.'_parameter_map', !$write_access);
196  $basic_part_5 = ob_get_contents();
197  ob_end_clean();
198 
199  $contents = translate('trigger_delete_bmail_user_asset', $basic_part_1).'<br />'.translate('trigger_delete_bmail_user_email', $basic_part_2).
200  '<br />'.translate('trigger_delete_bmail_user_link', $basic_part_3, $basic_part_4).'<br />'.$basic_part_5;
201 
202  return $contents;
203 
204  }//end getInterface()
205 
206 
218  public static function processInterface(&$settings, $request_data)
219  {
220  // make sure the assetid isn't blank
221  if (empty($request_data['assetid']['assetid'])) {
222  return 'Asset ID not specified';
223  }
224 
225  $new_prefix = str_replace(array('[',']'), '_', array_get_index($request_data, 'new_prefix', ''));
226  $attr_parameter_map = new Asset_Attribute_Parameter_Map();
227  $attr_parameter_map->process($new_prefix.'_parameter_map');
228  $settings['parameter_map_target_asset'] = $attr_parameter_map->value;
229 
230  $settings['assetid'] = $request_data['assetid']['assetid'];
231  $settings['emails'] = array_get_index($request_data, 'emails', '');
232  $settings['link_assetid'] = array_get_index($request_data['link_assetid'], 'assetid', '');
233  $settings['link_type'] = array_get_index($request_data, 'link_type', SQ_LINK_TYPE_1);
234 
235  return FALSE;
236 
237  }//end processInterface()
238 
239 
249  public static function getLocks($settings, &$state)
250  {
251  return Array($state['assetid'] => Array('lookups'));
252 
253  }//end getLocks()
254 
255 
256 }//end class
257 
258 ?>