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[
'major_assetid'])) {
63 if (empty($state[
'asset'])) {
65 if (empty($state[
'assetid'])) {
68 $state[
'asset'] = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($state[
'assetid']);
72 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
73 if (is_null($cron_mgr))
return FALSE;
75 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_lineage');
79 $link_info = $fs->attr(
'link_info');
80 $link_info[
'link_type'] = $settings[
'link_type'];
83 if (!empty($settings[
'attribute']) && !empty($settings[
'asset_type']) && ($state[
'asset'] instanceof $settings[
'asset_type'])) {
84 $attr = $state[
'asset']->getAttribute($settings[
'attribute']);
87 $datetime = $attr->value;
90 $time = substr($datetime, 10);
91 if ($time ==
' --:--:--') {
93 $datetime = substr($datetime, 0, 10).$time;
100 (
int) substr($time,0,2),
101 (
int) substr($time,3,2),
102 (
int) substr($time,6,2),
103 (
int) substr($datetime,5,2),
104 (
int) substr($datetime,8,2),
105 (
int) substr($datetime,0,4)
107 $parsed_datetime = date(
'Y-m-d H:i:s', $timestamp);
108 if (strcmp($parsed_datetime, $datetime) != 0) {
109 trigger_localised_error(
'SYS0311', E_USER_NOTICE, $datetime);
113 $fs->setAttrValue(
'when',
'OO='.$parsed_datetime);
115 $fs->setAttrValue(
'when', $settings[
'when']);
118 $fs->setAttrValue(
'link_info', $link_info);
119 $fs->setAttrValue(
'delete_link_all', $settings[
'delete_link_all']);
121 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
122 $user_for_status_change = $GLOBALS[
'SQ_SYSTEM']->user;
125 $user_for_status_change = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
128 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
129 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
130 $major_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($settings[
'major_assetid']);
131 if ($fs->setAssetInLink($state[
'asset'],
'minor') && $fs->setAssetInLink($major_asset,
'major')) {
132 if ($cron_mgr->addJob($fs, $user_for_status_change)) {
133 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
134 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
137 'userid' => $user_for_status_change->id,
138 'major_assetid' => $settings[
'major_assetid'],
139 'when' => $fs->attr(
'when'),
143 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
144 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
160 public static function getInterface($settings, $prefix, $write_access=FALSE)
163 $munge_prefix = str_replace(
'[',
'_', $prefix);
164 $munge_prefix = str_replace(
']',
'', $munge_prefix);
167 $settings[
'when'] = array_get_index($settings,
'when');
168 $settings[
'link_type'] = array_get_index($settings,
'link_type');
169 $settings[
'major_assetid'] = array_get_index($settings,
'major_assetid');
170 $settings[
'delete_link_all'] = array_get_index($settings,
'delete_link_all', FALSE);
171 $settings[
'prefix'] = $munge_prefix;
173 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
176 $editable_link_types = Array(
177 SQ_LINK_TYPE_1 => link_type_name(SQ_LINK_TYPE_1),
178 SQ_LINK_TYPE_2 => link_type_name(SQ_LINK_TYPE_2),
181 combo_box($prefix.
'[link_type]', $editable_link_types, FALSE, $settings[
'link_type']);
182 $output[
'new_link_type'] = ob_get_clean();
186 asset_finder($prefix.
'[major_assetid]', $settings[
'major_assetid'], Array(),
'sq_sidenav', FALSE,
'null', Array(
'clear'));
188 check_box($prefix.
'[delete_link_all]', 1, $settings[
'delete_link_all']);
190 label(translate(
'cron_fl_delete_all_existing_links_long'), $prefix.
'[delete_link_all]');
191 $output[
'new_link_parent'] = ob_get_clean();
194 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_lineage');
196 $temporary_edit_fns = $temporary_cron_job->getEditFns();
201 $temporary_edit_fns->_paintWhenBox($temporary_cron_job, $o, $munge_prefix, $settings[
'when']);
203 echo
'<br />or by the date/time value from the ';
204 $selected_type = array_get_index($settings,
'asset_type',
'');
206 asset_type_chooser($prefix.
'[asset_type]', FALSE, Array($selected_type), TRUE);
208 echo
'<b>'.$selected_type.
'</b>';
212 if ($selected_type ==
'') {
213 echo
'<b>['.translate(
'asset_type_not_selected').
']</b';
215 $attribute = array_get_index($settings,
'attribute',
'');
216 $attrs = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypeAttributes($selected_type);
218 echo
'<b>['.translate(
'asset_type_no_attributes_found').
']</b>';
221 $attr_options = Array();
222 foreach ($attrs as $attr_name => $attr_type) {
223 if ($attr_type[
'type'] ==
'datetime') {
224 $attr_options[$attr_name] = $attr_name;
227 if (count($attr_options) > 0) {
228 combo_box($prefix.
'[attribute]', $attr_options, FALSE, $attribute);
230 echo
'<b>['.translate(
'asset_type_no_attributes_found').
']</b>';
233 echo
'<b>'.$attribute.
'</b>';
238 $output[
'at'] = ob_get_clean();
241 hidden_field($prefix.
'[prefix]', $munge_prefix);
243 if (!$write_access)
return '';
247 ?><table border=
"0" cellpadding=
"4" cellspacing=
"0"><?php
248 foreach ($output as $title => $text) {
249 ?><tr><td><strong><?php echo translate($title); ?></strong></td><td><?php echo $text; ?></td></tr><?php
252 return ob_get_clean();
270 $munge_prefix = $request_data[
'prefix'];
271 $link_type = $request_data[
'link_type'];
272 $major_assetid = $request_data[
'major_assetid'][
'assetid'];
274 $delete_link_all = FALSE;
275 if (isset($request_data[
'delete_link_all'])) {
276 $delete_link_all = TRUE;
279 if (!$major_assetid)
return 'New parent not specified';
281 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_lineage');
283 $edit_fns = $fs->getEditFns();
286 $settings[
'when'] = $edit_fns->_processWhenBox($fs, $o, $munge_prefix);
288 $type_code = array_get_index($request_data,
'asset_type', FALSE);
290 $settings[
'asset_type'] = $type_code;
291 $settings[
'attribute'] = array_get_index($request_data,
'attribute',
'');
293 if (!empty($settings[
'attribute']) && !empty($settings[
'asset_type'])) {
294 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($settings[
'asset_type']);
295 $dummy_asset =
new $settings[
'asset_type'];
296 $attr = $dummy_asset->getAttribute($settings[
'attribute']);
297 if (is_null($attr) || (get_class($attr) !=
'Asset_Attribute_DateTime')) {
299 $settings[
'attribute'] =
'';
304 $settings[
'prefix'] = $munge_prefix;
306 $settings[
'link_type'] = $link_type;
307 $settings[
'major_assetid'] = $major_assetid;
308 $settings[
'delete_link_all'] = $delete_link_all;