17 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/system/triggers/trigger_action/trigger_action.inc';
55 public static function execute($settings, &$state)
58 if (empty($settings[
'link_type']) || empty($settings[
'assetid']) || empty($settings[
'relation'])) {
64 if (empty($state[
'asset'])) {
66 if (empty($state[
'assetid'])) {
69 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
72 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($settings[
'assetid']);
73 if (is_null($asset))
return FALSE;
76 $am = $GLOBALS[
'SQ_SYSTEM']->am;
77 if ($settings[
'relation'] ==
'minor') {
78 $major_asset = $state[
'asset'];
79 $minor_asset = $asset;
81 $major_asset = $asset;
82 $minor_asset = $state[
'asset'];
84 $links = $am->getLinks($major_asset->id, $settings[
'link_type'], $minor_asset->type(), TRUE,
'major');
86 foreach ($links as $link) {
87 if (isset($link[
'minorid']) && ($link[
'minorid'] == $minor_asset->id)) {
89 $linkid = $link[
'linkid'];
94 if (!empty($linkid)) {
95 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
96 if (is_null($cron_mgr))
return FALSE;
98 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_lineage');
102 if (!empty($settings[
'attribute']) && !empty($settings[
'asset_type']) && ($state[
'asset'] instanceof $settings[
'asset_type'])) {
104 $attr = $state[
'asset']->getAttribute($settings[
'attribute']);
107 $datetime = $attr->value;
110 $time = substr($datetime, 10);
111 if ($time ==
' --:--:--') {
113 $datetime = substr($datetime, 0, 10).$time;
117 $time = ltrim($time);
120 (
int) substr($time,0,2),
121 (
int) substr($time,3,2),
122 (
int) substr($time,6,2),
123 (
int) substr($datetime,5,2),
124 (
int) substr($datetime,8,2),
125 (
int) substr($datetime,0,4)
127 $parsed_datetime = date(
'Y-m-d H:i:s', $timestamp);
128 if (strcmp($parsed_datetime, $datetime) != 0) {
129 trigger_localised_error(
'SYS0311', E_USER_NOTICE, $datetime);
133 $fs->setAttrValue(
'when',
'OO='.$parsed_datetime);
135 $fs->setAttrValue(
'when', $settings[
'when']);
139 $fs->setAttrValue(
'delete_linkid', $linkid);
141 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
142 $user_for_status_change = $GLOBALS[
'SQ_SYSTEM']->user;
145 $user_for_status_change = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
148 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
149 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
150 if ($fs->setAssetInLink($minor_asset,
'minor')) {
151 if ($cron_mgr->addJob($fs, $user_for_status_change)) {
152 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
153 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
156 'userid' => $user_for_status_change->id,
157 'major_assetid' => $settings[
'assetid'],
158 'when' => $fs->attr(
'when'),
162 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
163 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
183 public static function getInterface($settings, $prefix, $write_access=FALSE)
186 $munge_prefix = str_replace(
'[',
'_', $prefix);
187 $munge_prefix = str_replace(
']',
'', $munge_prefix);
190 $settings[
'when'] = array_get_index($settings,
'when');
191 $settings[
'link_type'] = array_get_index($settings,
'link_type');
192 $settings[
'assetid'] = array_get_index($settings,
'assetid');
193 $settings[
'relation'] = array_get_index($settings,
'relation',
'major');
194 $settings[
'asset_type'] = array_get_index($settings,
'asset_type');
195 $settings[
'prefix'] = $munge_prefix;
197 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
200 $editable_link_types = Array(
201 SQ_LINK_TYPE_1 => link_type_name(SQ_LINK_TYPE_1),
202 SQ_LINK_TYPE_2 => link_type_name(SQ_LINK_TYPE_2),
204 $relationships = Array(
212 hidden_field($prefix.
'[prefix]', $munge_prefix);
214 <table border=
"0" cellpadding=
"4" cellspacing=
"0">
220 combo_box($prefix.
'[link_type]', $editable_link_types, FALSE, $settings[
'link_type']);
222 if (isset($settings[
'link_type']) && !empty($settings[
'link_type'])) {
223 echo $editable_link_types[$settings[
'link_type']];
225 echo $editable_link_types[SQ_LINK_TYPE_1];
228 $link_type_interface = ob_get_clean();
230 <tr><td><strong><?php echo translate(
'link_type'); ?></strong></td><td><?php echo $link_type_interface; ?></td></tr>
236 asset_finder($prefix.
'[assetid]', $settings[
'assetid'], Array(),
'sq_sidenav', FALSE,
'null', Array(
'clear'));
238 if (isset($settings[
'assetid']) && !empty($settings[
'assetid'])) {
239 echo get_asset_tag_line($settings[
'assetid']);
241 echo
'<em>'.translate(
'no_asset_selected').
'</em>';
246 combo_box($prefix.
'[relation]', $relationships, FALSE, $settings[
'relation']);
248 if (isset($settings[
'relation']) && !empty($settings[
'relation'])) {
249 echo $relationships[$settings[
'relation']];
251 echo $relationships[
'major'];
254 echo
' of the Current Asset';
255 $asset_interface = ob_get_clean();
257 <tr><td><strong><?php echo translate(
'asset'); ?></strong></td><td><?php echo $asset_interface; ?></td></tr>
262 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_lineage');
264 $temporary_edit_fns = $temporary_cron_job->getEditFns();
270 $temporary_edit_fns->_paintWhenBox($temporary_cron_job, $o, $munge_prefix, $settings[
'when']);
272 echo
'<br />or by the date/time value from the ';
273 $selected_type = array_get_index($settings,
'asset_type',
'');
275 asset_type_chooser($prefix.
'[asset_type]', FALSE, Array($selected_type), TRUE);
277 echo
'<b>'.$selected_type.
'</b>';
281 if ($selected_type ==
'') {
282 echo
'<b>['.translate(
'asset_type_not_selected').
']</b';
284 $attribute = array_get_index($settings,
'attribute',
'');
285 $attrs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeAttributes($selected_type);
287 echo
'<b>['.translate(
'asset_type_no_attributes_found').
']</b>';
290 $attr_options = Array();
291 foreach ($attrs as $attr_name => $attr_type) {
292 if ($attr_type[
'type'] ==
'datetime') {
293 $attr_options[$attr_name] = $attr_name;
296 if (count($attr_options) > 0) {
297 combo_box($prefix.
'[attribute]', $attr_options, FALSE, $attribute);
299 echo
'<b>['.translate(
'asset_type_no_attributes_found').
']</b>';
302 echo
'<b>'.$attribute.
'</b>';
306 $future_interface = ob_get_clean();
308 <tr><td><strong><?php echo translate(
'at'); ?></strong></td><td><?php echo $future_interface; ?></td></tr>
315 $interface = ob_get_clean();
335 $munge_prefix = $request_data[
'prefix'];
336 $link_type = $request_data[
'link_type'];
337 $assetid = $request_data[
'assetid'][
'assetid'];
338 $relation = $request_data[
'relation'];
340 if (!$assetid)
return 'Asset not specified';
342 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_lineage');
344 $edit_fns = $fs->getEditFns();
347 $settings[
'when'] = $edit_fns->_processWhenBox($fs, $o, $munge_prefix);
349 $type_code = array_get_index($request_data,
'asset_type', FALSE);
351 $settings[
'asset_type'] = $type_code;
352 $settings[
'attribute'] = array_get_index($request_data,
'attribute',
'');
354 if (!empty($settings[
'attribute']) && !empty($settings[
'asset_type'])) {
355 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($settings[
'asset_type']);
356 $dummy_asset =
new $settings[
'asset_type'];
357 $attr = $dummy_asset->getAttribute($settings[
'attribute']);
358 if (is_null($attr) || (get_class($attr) !=
'Asset_Attribute_DateTime')) {
360 $settings[
'attribute'] =
'';
365 $settings[
'prefix'] = $munge_prefix;
367 $settings[
'link_type'] = $link_type;
368 $settings[
'assetid'] = $assetid;
369 $settings[
'relation'] = $relation;