17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
39 function paintLinking(&$owner, &$o, &$ei, $static_keywords=NULL)
45 $write_access = $owner->writeAccess(
'links');
48 $prefix = $owner->getPrefix();
50 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
51 $o->openSection(translate(
'current_linking'));
54 $o->openField(translate(
'display_linking_type'));
56 $display_types = Array(
57 'display_linked_parents' => translate(
'display_linked_parents'),
58 'display_linked_children' => translate(
'display_linked_children'),
60 $current_display_type = isset($_POST[$prefix.
'_display_type']) ? $_POST[$prefix.
'_display_type'] :
'display_linked_parents';
61 echo hidden_field($prefix.
'_display_type_changed',
'0');
62 $display_reverse = ($current_display_type ==
'display_linked_children');
63 combo_box($prefix.
'_display_type', $display_types, FALSE, $current_display_type, 0 ,
'onChange="this.form.'.$prefix.
'_display_type_changed.value=1;submit_form(this.form)"');
69 echo
'<i>'.translate(
'link_types_note').
'</i><br/><br/>';
75 $asset_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($owner->id, SQ_SC_LINK_ALL,
'', TRUE, $display_reverse ?
'major' :
'minor');
76 foreach ($asset_links as $link) {
77 $assetids[$link[$display_reverse ?
'minorid' :
'majorid']] = Array();
83 $link_offset = array_get_index($_POST, $prefix.
'_link_offset', 0);
85 if (empty($assetids)) {
90 $assetid_keys = array_keys($assetids);
91 $total_assets = count($assetid_keys);
92 $assetid_keys = array_slice($assetid_keys, $link_offset, $num_per_page);
95 $sql =
'SELECT ct.treeid as our_treeid, cl.minorid, cl.linkid, pt.treeid as parent_treeid, a.name, a.assetid, cl.value
96 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk cl
97 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk_tree ct ON cl.linkid = ct.linkid,
98 '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk pl
99 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk_tree pt ON pl.linkid = pt.linkid
100 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast a ON a.assetid = pl.minorid
104 foreach ($assetid_keys as $assetid_key_index => $assetid_key) {
105 $assetid_keys[$assetid_key_index] =
':assetid_keys_'.$assetid_key_index;
106 $bindVars[
'assetid_keys_'.$assetid_key_index] = (string) $assetid_key;
108 $where =
' where cl.minorid IN ('.implode(
', ', $assetid_keys).
')
109 AND ct.treeid LIKE pt.treeid || \'%\'
110 AND pt.treeid <= ct.treeid';
111 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'cl');
112 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'ct');
113 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'pl');
114 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'pt');
115 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'a');
117 $sql .= $where.
' ORDER BY cl.sort_order, cl.linkid, ct.treeid, pt.treeid';
121 foreach ($bindVars as $bind_var => $bind_value) {
125 }
catch (Exception $e) {
126 throw new Exception($e->getMessage());
132 foreach ($asset_links as $link_data) {
133 $link_info[$link_data[$display_reverse ?
'minorid' :
'majorid']][] =$link_data;
137 $output_lineages = Array();
138 $editing_linkids = Array();
139 foreach ($result as $treeid => $link_tree) {
141 $parent_data = $link_tree[count($link_tree) -1];
142 $majorid = $parent_data[
'assetid'];
143 $linkid = $parent_data[
'linkid'];
145 foreach ($link_info[$majorid] as $link_data) {
147 if($display_reverse && $linkid != $link_data[
'linkid'] && $link_data[
'link_type'] != SQ_LINK_NOTICE)
continue;
149 $output = _printLine($owner, $majorid, $link_data, $parent_data, $link_tree, $editing_linkids, $display_reverse);
150 if (!empty($output)) $output_lineages[] = $output;
157 if (!count($output_lineages)) {
160 $num_pages = ceil($total_assets / $num_per_page);
162 <style type=
"text/css">
163 td.sq-linking-header {
166 .sq-linking-header table.sq-backend-table {
168 margin: 0 8px 8px 8px;
170 .sq-linking-header table.sq-backend-table th {
172 text-decoration: italic;
174 table.sq-backend-table tr td.sq-linking-header-header {
175 background-color: #666;
180 <table
class=
"sq-backend-table">
182 <td
class=
"sq-linking-header-header" colspan=
"7"><b><?php
183 hidden_field($prefix.
'_link_offset', $link_offset);
184 if ($link_offset > 0) {
185 ?><a title=
"<?php echo translate('pagination_go_to_first') ?>" style=
"text-decoration: none; color: #fff" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '0'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
187 ?><span title=
"<?php echo translate('pagination_cannot_go_further_back') ?>" style=
"color: #333"><?php
192 if ($link_offset > 0) {
197 ?> <?php
198 if ($link_offset > 0) {
199 ?><a title=
"<?php echo translate('pagination_go_to_previous') ?>" style=
"text-decoration: none; color: #fff" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '<?php echo $link_offset - $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
201 ?><span title=
"<?php echo translate('pagination_cannot_go_further_back') ?>" style=
"color: #333"><?php
206 if ($link_offset > 0) {
212 <?php echo translate(
'page_number', round(($link_offset + $num_per_page) / $num_per_page), ceil($total_assets / $num_per_page)); ?>
214 if (($link_offset + $num_per_page) < $total_assets) {
215 ?><a title=
"<?php echo translate('pagination_go_to_next') ?>" style=
"text-decoration: none; color: #fff" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '<?php echo $link_offset + $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
217 ?><span title=
"<?php echo translate('pagination_cannot_go_further_forward') ?>" style=
"color: #333"><?php
222 if (($link_offset + $num_per_page) < $total_assets) {
227 ?> <?php
228 if (($link_offset + $num_per_page) < $total_assets) {
229 ?><a title=
"<?php echo translate('pagination_go_to_last') ?>" style=
"text-decoration: none; color: #fff" href=
"#" onClick=
"Javascript: set_hidden_field('<?php echo $prefix ?>_link_offset', '<?php echo ($num_pages - 1) * $num_per_page; ?>'); set_hidden_field('process_form', '0'); submit_form(); return false;"><?php
231 ?><span title=
"<?php echo translate('pagination_cannot_go_further_forward') ?>" style=
"color: #333"><?php
236 if (($link_offset + $num_per_page) < $total_assets) {
245 <th style=
"text-align: center; white-space: nowrap;" width=
"5%"><?php echo translate(
'find'); ?></th>
246 <th style=
"text-align: center; white-space: nowrap;" width=
"5%"><?php echo translate(
'link_id'); ?></th>
247 <th style=
"text-align: center;" width=
"10%"><?php echo translate(
'link_type'); ?></th>
248 <th style=
"text-align: center; white-space: nowrap;" width=
"5%"><?php echo translate(
'assetid'); ?></th>
249 <th style=
"text-align: center; white-space: nowrap;" width=
"5%"><?php echo translate(
'value'); ?></th>
250 <th style=
"text-align: center; white-space: nowrap;" width=
"5%"><?php echo ucwords(strtolower(translate(
'locked'))); ?></th>
251 <th width=
"70"><?php echo translate(
'lineage'); ?></th>
254 foreach ($output_lineages as $null => $lineage_data) {
264 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_lineage');
265 $fl_jobs = call_user_func(Array(
'Cron_Job_Future_Lineage',
'getActiveJobs'), $owner, $display_reverse);
267 if (!empty($fl_jobs)) {
269 $o->openSection(translate(
'future_linking'));
270 if (!empty($fl_jobs)) {
271 $o->openField(
'',
'new_line');
273 <table
class=
"sq-backend-table">
275 <td
class=
"sq-backend-table-header">
276 <?php echo translate(
'action'); ?>
278 <td
class=
"sq-backend-table-header">
279 <?php echo translate(
'when'); ?>
285 <td
class=
"sq-backend-table-header" style=
"text-align: center;"><?php echo translate(
'delete_question'); ?></td>
291 for ($i = 0; $i < count($fl_jobs); $i++) {
294 <td
class=
"sq-backend-table-cell">
295 <?php echo nl2br($fl_jobs[$i]->readableDescription()); ?>
297 <td
class=
"sq-backend-table-cell">
298 <?php echo $fl_jobs[$i]->readableWhen(); ?>
304 <td
class=
"sq-backend-table-cell" style=
"text-align: center;">
306 if ($fl_jobs[$i]->canDelete()) {
307 check_box($prefix.
'_remove_fl[]', $fl_jobs[$i]->id);
339 $fl_create->setAssetInLink($owner, $display_reverse ?
'major' :
'minor');
340 $edit_fns_create = $fl_create->getEditFns();
341 if($display_reverse){
342 $edit_fns_create->paintInLineBackendCreateReverse($fl_create, $o, $prefix.
'_create_reverse');
343 $edit_fns_create->paintInLineBackendDeleteReverse($fl_create, $o, $prefix.
'_delete_reverse');
346 $edit_fns_create->paintInLineBackendCreate($fl_create, $o, $prefix.
'_create');
347 $edit_fns_create->paintInLineBackendDelete($fl_create, $o, $prefix.
'_delete');
368 function processLinking(&$owner, &$o, &$ei)
372 if ($owner->id && !$owner->writeAccess(
'')) {
373 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)));
378 if (!$owner->writeAccess(
'links'))
return FALSE;
381 $prefix = $owner->getPrefix();
383 $current_display_type = isset($_POST[$prefix.
'_display_type']) ? $_POST[$prefix.
'_display_type'] :
'display_linked_parents';
384 $display_reverse = ($current_display_type ==
'display_linked_children');
386 $done_something = FALSE;
388 $asset_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($owner->id, SQ_SC_LINK_ALL,
'', TRUE, $display_reverse ?
'major' :
'minor');
390 foreach ($asset_links as $link) {
392 if (!isset($_POST[$prefix.
'_link_type'][$link[
'linkid']])) {
395 $new_type = $_POST[$prefix.
'_link_type'][$link[
'linkid']];
396 if ($link[
'link_type'] == $new_type) {
402 if (!isset($_POST[$prefix.
'_link_value'][$link[
'linkid']])) {
405 $new_value = $_POST[$prefix.
'_link_value'][$link[
'linkid']];
406 if (html_entity_decode($link[
'value'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET) == $new_value) {
412 if (!isset($_POST[$prefix.
'_link_locked'][$link[
'linkid']])) {
413 $new_lock_status =
'0';
415 $new_lock_status =
'1';
417 $new_lock_status = ($new_lock_status ==
'1') ?
'1' :
'0';
418 if ((isset($_POST[$prefix.
'_display_type_changed']) && $_POST[$prefix.
'_display_type_changed'] == 1) || $link[
'locked'] == $new_lock_status) {
419 $new_lock_status = NULL;
423 if (is_null($new_type) && is_null($new_value) && is_null($new_lock_status)) {
428 if (isset($_POST[$prefix.
'_link_value'][$link[
'linkid']])) {
429 $new_value = $_POST[$prefix.
'_link_value'][$link[
'linkid']];
432 $new_value = (is_null($new_value)) ? NULL : htmlentities($new_value, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
435 $link_to_notice = (($link[
'link_type'] == SQ_LINK_TYPE_1|SQ_LINK_TYPE_2) && $new_type == SQ_LINK_NOTICE);
436 $notice_to_link = (($new_type == SQ_LINK_TYPE_1|SQ_LINK_TYPE_2) && $link[
'link_type'] == SQ_LINK_NOTICE);
437 if (!is_null($new_type) && ($link_to_notice || $notice_to_link)) {
438 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
439 if (isset($link[
'majorid']) && !empty($link[
'majorid'])) {
440 $major = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'majorid']);
441 if (!is_null($major)) {
442 $value = (isset($link[
'value'])) ? $link[
'value'] :
'';
444 if (!$GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($major, $owner, $new_type, $new_value)) {
445 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
449 if (!$GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($link[
'linkid'])) {
450 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
454 $done_something = TRUE;
455 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
460 if (isset($link[
'minorid']) && !empty($link[
'minorid'])) {
461 $minor = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid']);
462 if (!is_null($minor)) {
463 $value = (isset($link[
'value'])) ? $link[
'value'] :
'';
465 if (!$GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($owner, $minor, $new_type, $new_value)) {
466 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
470 if (!$GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($link[
'linkid'])) {
471 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
475 $done_something = TRUE;
476 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
480 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
485 if (!$GLOBALS[
'SQ_SYSTEM']->am->updateLink($link[
'linkid'], $new_type, $new_value, NULL, $new_lock_status)) {
488 $done_something = TRUE;
492 if ($done_something) {
493 $o->addOnLoad(
'if (window.top.frames["sq_sidenav"] && window.top.frames["sq_sidenav"].reload_asset) window.top.frames["sq_sidenav"].reload_asset("'.$owner->id.
'");');
496 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
497 if (!is_null($cron_mgr)) {
499 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_future_lineage');
501 if (!empty($_POST[$prefix.
'_remove_fl'])) {
503 if (!empty($fl_jobs)) {
505 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($cron_mgr->id,
'links')) {
506 for ($i = 0; $i < count($fl_jobs); $i++) {
507 if (in_array($fl_jobs[$i]->
id, $_POST[$prefix.
'_remove_fl'])) {
508 if ($cron_mgr->removeJob($fl_jobs[$i])) {
514 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($cron_mgr->id,
'links');
517 trigger_localised_error(
'SYS0232', E_USER_NOTICE);
524 $edit_fns = $fl->getEditFns();
525 if ($fl->setAssetInLink($owner,
'minor') && $edit_fns->processInLineBackend($fl, $o, $prefix.
'_new_fl')) {
526 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
527 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
528 if ($cron_mgr->addJob($fl, $GLOBALS[
'SQ_SYSTEM']->user)) {
529 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
530 $done_something = TRUE;
532 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
534 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
540 $edit_fns_create = $fl_create->getEditFns();
541 $fl_create->setAssetInLink($owner, $display_reverse ?
'major' :
'minor');
546 if (!$display_reverse && $edit_fns_create->processInLineBackendCreate($fl_create, $o, $prefix.
'_create')) {
547 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
548 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
549 if ($cron_mgr->addJob($fl_create, $GLOBALS[
'SQ_SYSTEM']->user)) {
550 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
551 $done_something = TRUE;
553 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
555 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
561 if (!$display_reverse && $edit_fns_create->processInLineBackendDelete($fl_create, $o, $prefix.
'_delete')) {
562 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
563 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
564 if ($cron_mgr->addJob($fl_create, $GLOBALS[
'SQ_SYSTEM']->user)) {
565 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
566 $done_something = TRUE;
568 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
570 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
576 if ($display_reverse && $edit_fns_create->processInLineBackendCreateReverse($fl_create, $o, $prefix.
'_create_reverse')) {
577 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
578 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
579 if ($cron_mgr->addJob($fl_create, $GLOBALS[
'SQ_SYSTEM']->user)) {
580 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
581 $done_something = TRUE;
583 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
585 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
590 if ($display_reverse && $edit_fns_create->processInLineBackendDeleteReverse($fl_create, $o, $prefix.
'_delete_reverse')) {
591 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
592 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
593 if ($cron_mgr->addJob($fl_create, $GLOBALS[
'SQ_SYSTEM']->user)) {
594 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
595 $done_something = TRUE;
597 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
599 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
604 return $done_something;
623 function _printLine(&$owner, $majorid, $link_data, $parent_data=Array(), $link_tree=Array(), &$editing_linkids=Array(), $display_reverse = FALSE)
625 $write_access = $owner->writeAccess(
'links');
627 $editable_link_types = Array(
628 SQ_LINK_TYPE_1 => link_type_name(SQ_LINK_TYPE_1),
629 SQ_LINK_TYPE_2 => link_type_name(SQ_LINK_TYPE_2),
630 SQ_LINK_NOTICE => link_type_name(SQ_LINK_NOTICE),
634 $prefix = $owner->getPrefix();
635 $link_type = $link_data[
'link_type'];
636 $linkid = $link_data[
'linkid'];
637 $link_value = $link_data[
'value'];
638 $link_locking = array_get_index($link_data,
'locked',
'0');
641 $can_edit = ($write_access && in_array($link_type, array_keys($editable_link_types)) && !in_array($linkid, $editing_linkids));
644 $asset_lineage_ids = Array();
645 foreach ($link_tree as $tree_data) {
646 $asset_lineage_ids[] = $tree_data[
'assetid'];
647 if ($tree_data[
'assetid'] == $majorid)
continue;
648 $asset_lineage .= htmlspecialchars($tree_data[
'name'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
' > ';
651 if(!$display_reverse)
652 $asset_lineage_ids[] = $owner->id;
654 if (!empty($parent_data)) {
655 $asset_lineage .=
'<b>'.htmlspecialchars($parent_data[
'name'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).
'</b>';
657 if (isset($output_lineages[$asset_lineage]) && !$can_edit) {
664 <td
class=
"sq-backend-table-cell" style=
"text-align: center;">
666 if ($link_type & SQ_SC_LINK_BACKEND_NAV) {
669 <?php echo sq_print_icon(sq_web_path(
'lib').
'/web/images/icons/asset_locator.png', 16, 16, translate(
'show_in_asset_map'), translate(
'show_in_asset_map'),
' style="border: 0; cursor: pointer" onclick="'.asset_locator_js($asset_lineage_ids).
'"');
676 <td style=
"text-align: center;">
677 <?php echo $linkid; ?>
679 <td style=
"text-align: center;">
682 echo link_type_name($link_type);
684 combo_box($prefix.
'_link_type['.$linkid.
']', $editable_link_types, FALSE, $link_type);
685 $editing_linkids[] = $linkid;
689 <td style=
"text-align: center;">
690 <?php echo $majorid; ?>
692 <td style=
"text-align: center;">
697 text_box($prefix.
'_link_value['.$linkid.
']', html_entity_decode($link_value, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), 15, FALSE);
701 <td style=
"text-align: center;">
703 if ($link_type <= 2) {
704 $lock_status = ($link_locking ==
'1') ?
'tick' :
'cross';
705 $lock_status_desc = ($link_locking ==
'1') ?
'locked' :
'unlocked';
707 check_box($prefix.
'_link_locked['.$linkid.
']',
'1', (($link_locking ==
'1') ? TRUE : FALSE));
709 echo
'<img class="sq-icon" width="16" height="16" src="'.sq_web_path(
'lib').
'/web/images/'.$lock_status.
'.gif" alt="'.translate($lock_status_desc).
'" style="border: 0;" />';
714 <td><?php echo $asset_lineage; ?></td>
717 $output = ob_get_contents();