Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
linking.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 
39 function paintLinking(&$owner, &$o, &$ei, $static_keywords=NULL)
40 {
41  // We are ignoring live edit access because changes to links are not reliant on
42  // status of the asset (because the are not safe edited)
43  $created = FALSE;
44 
45  $write_access = $owner->writeAccess('links');
46 
47  // prefix for all the form vars
48  $prefix = $owner->getPrefix();
49 
50  require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
51  $o->openSection(translate('current_linking'));
52 
53  // which display type?
54  $o->openField(translate('display_linking_type'));
55 
56  $display_types = Array(
57  'display_linked_parents' => translate('display_linked_parents'),
58  'display_linked_children' => translate('display_linked_children'),
59  );
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)"');
64 
65  $o->closeField();
66 
67 
68  $o->openField('');
69  echo '<i>'.translate('link_types_note').'</i><br/><br/>';
70 
71  $db = MatrixDAL::getDb();
72  $assetids = Array();
73 
74 
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();
78  }
79 
80 
81  $total_assets = 0;
82  $num_per_page = 50;
83  $link_offset = array_get_index($_POST, $prefix.'_link_offset', 0);
84 
85  if (empty($assetids)) {
86  $result = Array();
87  } else {
88  $result = Array();
89 
90  $assetid_keys = array_keys($assetids);
91  $total_assets = count($assetid_keys);
92  $assetid_keys = array_slice($assetid_keys, $link_offset, $num_per_page);
93  // Chunk Norris this query because the IN part will bomb with >1000
94  // assets on Oracle
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
101  ';
102 
103  $bindVars = array();
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;
107  }
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');
116 
117  $sql .= $where.' ORDER BY cl.sort_order, cl.linkid, ct.treeid, pt.treeid';
118 
119  try {
120  $query = MatrixDAL::preparePdoQuery($sql);
121  foreach ($bindVars as $bind_var => $bind_value) {
122  MatrixDAL::bindValueToPdo($query, $bind_var, $bind_value);
123  }
124  $result = MatrixDAL::executePdoGroupedAssoc($query);
125  } catch (Exception $e) {
126  throw new Exception($e->getMessage());
127  }
128 
129  }//end else
130 
131 
132  foreach ($asset_links as $link_data) {
133  $link_info[$link_data[$display_reverse ? 'minorid' : 'majorid']][] =$link_data;
134  }
135 
136 
137  $output_lineages = Array();
138  $editing_linkids = Array();
139  foreach ($result as $treeid => $link_tree) {
140  // work out some values we are going to need
141  $parent_data = $link_tree[count($link_tree) -1];
142  $majorid = $parent_data['assetid'];
143  $linkid = $parent_data['linkid'];
144 
145  foreach ($link_info[$majorid] as $link_data) {
146  // to display linked children, we don't want to show entire lineage of children, just show lineage via current asset
147  if($display_reverse && $linkid != $link_data['linkid'] && $link_data['link_type'] != SQ_LINK_NOTICE) continue;
148 
149  $output = _printLine($owner, $majorid, $link_data, $parent_data, $link_tree, $editing_linkids, $display_reverse);
150  if (!empty($output)) $output_lineages[] = $output;
151  }//end foreach
152 
153  }//end foreach result
154 
155 
156 
157  if (!count($output_lineages)) {
158  echo 'None';
159  } else {
160  $num_pages = ceil($total_assets / $num_per_page);
161  ?>
162  <style type="text/css">
163  td.sq-linking-header {
164  padding-top: 0px;
165  }
166  .sq-linking-header table.sq-backend-table {
167  border-top: 0px;
168  margin: 0 8px 8px 8px;
169  }
170  .sq-linking-header table.sq-backend-table th {
171  font-weight: normal;
172  text-decoration: italic;
173  }
174  table.sq-backend-table tr td.sq-linking-header-header {
175  background-color: #666;
176  color: #fff;
177  font-size: 11px;
178  }
179  </style>
180  <table class="sq-backend-table">
181  <tr>
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
186  } else {
187  ?><span title="<?php echo translate('pagination_cannot_go_further_back') ?>" style="color: #333"><?php
188  }
189  ?>
190  &lt;&lt;
191  <?php
192  if ($link_offset > 0) {
193  ?></a><?php
194  } else {
195  ?></span><?php
196  }
197  ?> &nbsp; &nbsp; <?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
200  } else {
201  ?><span title="<?php echo translate('pagination_cannot_go_further_back') ?>" style="color: #333"><?php
202  }
203  ?>
204  &lt;
205  <?php
206  if ($link_offset > 0) {
207  ?></a><?php
208  } else {
209  ?></span><?php
210  }
211  ?>
212  &nbsp; &nbsp; <?php echo translate('page_number', round(($link_offset + $num_per_page) / $num_per_page), ceil($total_assets / $num_per_page)); ?> &nbsp; &nbsp;
213  <?php
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
216  } else {
217  ?><span title="<?php echo translate('pagination_cannot_go_further_forward') ?>" style="color: #333"><?php
218  }
219  ?>
220  &gt;
221  <?php
222  if (($link_offset + $num_per_page) < $total_assets) {
223  ?></a><?php
224  } else {
225  ?></span><?php
226  }
227  ?> &nbsp; &nbsp; <?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
230  } else {
231  ?><span title="<?php echo translate('pagination_cannot_go_further_forward') ?>" style="color: #333"><?php
232  }
233  ?>
234  &gt;&gt;
235  <?php
236  if (($link_offset + $num_per_page) < $total_assets) {
237  ?></a><?php
238  } else {
239  ?></span><?php
240  }
241  ?></b>
242  </td>
243  </tr>
244  <tr>
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>
252  </tr>
253  <?php
254  foreach ($output_lineages as $null => $lineage_data) {
255  echo $lineage_data;
256  }
257  ?>
258  </table>
259  <?php
260  }//end else
261 
262  $o->closeSection();
263 
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);
266 
267  if (!empty($fl_jobs)) {
268  $created = TRUE;
269  $o->openSection(translate('future_linking'));
270  if (!empty($fl_jobs)) {
271  $o->openField('', 'new_line');
272  ?>
273  <table class="sq-backend-table">
274  <tr>
275  <td class="sq-backend-table-header">
276  <?php echo translate('action'); ?>
277  </td>
278  <td class="sq-backend-table-header">
279  <?php echo translate('when'); ?>
280  </td>
281  <?php
282  if ($write_access) {
283  $created = TRUE;
284  ?>
285  <td class="sq-backend-table-header" style="text-align: center;"><?php echo translate('delete_question'); ?></td>
286  <?php
287  }
288  ?>
289  </tr>
290  <?php
291  for ($i = 0; $i < count($fl_jobs); $i++) {
292  ?>
293  <tr>
294  <td class="sq-backend-table-cell">
295  <?php echo nl2br($fl_jobs[$i]->readableDescription()); ?>
296  </td>
297  <td class="sq-backend-table-cell">
298  <?php echo $fl_jobs[$i]->readableWhen(); ?>
299  </td>
300  <?php
301  if ($write_access) {
302  $created = TRUE;
303  ?>
304  <td class="sq-backend-table-cell" style="text-align: center;">
305  <?php
306  if ($fl_jobs[$i]->canDelete()) {
307  check_box($prefix.'_remove_fl[]', $fl_jobs[$i]->id);
308  } else {
309  echo '&nbsp;';
310  }
311  ?>
312  </td>
313  <?php
314  }
315  ?>
316  </tr>
317  <?php
318  }//end for
319  ?>
320  </table>
321  <br/>
322  <?php
323  $o->closeField();
324  }//end if future lineage jobs
325 
326  $o->closeSection();
327 
328 
329 
330  }//end if future lineage jobs or write access
331 
332  // if the user got the write access we add two sections
333  // create linking and delete linking
334  if ($write_access) {
335  // use the cron Job future linage asset to print the
336  // create new link screen
337 
338  $fl_create = new Cron_Job_Future_Lineage();
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');
344  }
345  else {
346  $edit_fns_create->paintInLineBackendCreate($fl_create, $o, $prefix.'_create');
347  $edit_fns_create->paintInLineBackendDelete($fl_create, $o, $prefix.'_delete');
348  }
349  $created = TRUE;
350 
351  }
352  return $created;
353  return TRUE;
354 
355 }//end paintLinking()
356 
357 
368 function processLinking(&$owner, &$o, &$ei)
369 {
370 
371  // if we dont have admin access, go away
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)));
374  exit();
375  }
376 
377  // if we dont have effective write access, dont process anything
378  if (!$owner->writeAccess('links')) return FALSE;
379 
380  // prefix for all the form vars
381  $prefix = $owner->getPrefix();
382 
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');
385 
386  $done_something = FALSE;
387 
388  $asset_links = $GLOBALS['SQ_SYSTEM']->am->getLinks($owner->id, SQ_SC_LINK_ALL, '', TRUE, $display_reverse ? 'major' : 'minor');
389  // process link_type changes
390  foreach ($asset_links as $link) {
391  // Find out the type
392  if (!isset($_POST[$prefix.'_link_type'][$link['linkid']])) {
393  $new_type = NULL;
394  } else {
395  $new_type = $_POST[$prefix.'_link_type'][$link['linkid']];
396  if ($link['link_type'] == $new_type) {
397  $new_type = NULL;
398  }
399  }
400 
401  // Find out the value
402  if (!isset($_POST[$prefix.'_link_value'][$link['linkid']])) {
403  $new_value = NULL;
404  } else {
405  $new_value = $_POST[$prefix.'_link_value'][$link['linkid']]; // Set the value for testing
406  if (html_entity_decode($link['value'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET) == $new_value) {
407  $new_value = NULL;
408  }
409  }
410 
411  // Find out the value
412  if (!isset($_POST[$prefix.'_link_locked'][$link['linkid']])) {
413  $new_lock_status = '0';
414  } else {
415  $new_lock_status = '1'; // Set the value for testing
416  }//end if
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;
420  }//end if
421 
422  // Nothing to do let's continue
423  if (is_null($new_type) && is_null($new_value) && is_null($new_lock_status)) {
424  continue;
425  }
426 
427  // Actually set the value
428  if (isset($_POST[$prefix.'_link_value'][$link['linkid']])) {
429  $new_value = $_POST[$prefix.'_link_value'][$link['linkid']];
430  }
431  // Cleanup any html
432  $new_value = (is_null($new_value)) ? NULL : htmlentities($new_value, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
433 
434  // Change LINK 1 or 2 to a NOTICE link
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'] : '';
443  // Create the new link
444  if (!$GLOBALS['SQ_SYSTEM']->am->createAssetLink($major, $owner, $new_type, $new_value)) {
445  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
446  continue;
447  }
448  // Delete the original link
449  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($link['linkid'])) {
450  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
451  continue;
452  }
453  // All done commit changes and leave nice
454  $done_something = TRUE;
455  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
456  continue;
457  }
458  }
459  // change link type for linked children $link_to_notice || $notice_to_link
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'] : '';
464  // Create the new link
465  if (!$GLOBALS['SQ_SYSTEM']->am->createAssetLink($owner, $minor, $new_type, $new_value)) {
466  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
467  continue;
468  }
469  // Delete the original link
470  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($link['linkid'])) {
471  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
472  continue;
473  }
474  // All done commit changes and leave nice
475  $done_something = TRUE;
476  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
477  continue;
478  }
479  }
480  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
481  continue;
482  }
483 
484  // Change from LINK 1 to a LINK 2 (or changing a value/lock status only)
485  if (!$GLOBALS['SQ_SYSTEM']->am->updateLink($link['linkid'], $new_type, $new_value, NULL, $new_lock_status)) {
486  continue;
487  }
488  $done_something = TRUE;
489  }//end foreach
490 
491  // Refresh the Asset Map to show linking changes
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.'");');
494  }
495 
496  $cron_mgr = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
497  if (!is_null($cron_mgr)) {
498 
499  $GLOBALS['SQ_SYSTEM']->am->includeAsset('cron_job_future_lineage');
500 
501  if (!empty($_POST[$prefix.'_remove_fl'])) {
502  $fl_jobs = Cron_Job_Future_Lineage::getActiveJobs($owner,$display_reverse);
503  if (!empty($fl_jobs)) {
504 
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])) {
509  $is_updated = TRUE;
510  }
511  }
512  }
513 
514  $GLOBALS['SQ_SYSTEM']->am->releaseLock($cron_mgr->id, 'links');
515 
516  } else {
517  trigger_localised_error('SYS0232', E_USER_NOTICE);
518  }
519 
520  }// end if
521  }// end if
522 
523  $fl = new Cron_Job_Future_Lineage();
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;
531  } else {
532  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
533  }
534  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
535  }
536 
537  }//end if
538 
539  $fl_create = new Cron_Job_Future_Lineage();
540  $edit_fns_create = $fl_create->getEditFns();
541  $fl_create->setAssetInLink($owner, $display_reverse ? 'major' : 'minor');
542 
543 
544  // we process the create new link
545  // if all the parameters are set properly we add to the cron manager the new job
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;
552  } else {
553  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
554  }
555  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
556 
557  }
558 
559  // we process the deletion of links
560  // if all the parameters for the cron are set properly
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;
567  } else {
568  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
569  }
570  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
571 
572  }
573 
574 
575  // we process the create new link for linked children
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;
582  } else {
583  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
584  }
585  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
586 
587  }
588 
589  // we process the deletion of links for linked children
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;
596  } else {
597  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
598  }
599  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
600 
601  }
602 
603 
604  return $done_something;
605 
606 }//end processLinking()
607 
608 
623 function _printLine(&$owner, $majorid, $link_data, $parent_data=Array(), $link_tree=Array(), &$editing_linkids=Array(), $display_reverse = FALSE)
624 {
625  $write_access = $owner->writeAccess('links');
626 
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),
631  );
632 
633  // prefix for all the form vars
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');
639 
640  // work out if the user can change the link types
641  $can_edit = ($write_access && in_array($link_type, array_keys($editable_link_types)) && !in_array($linkid, $editing_linkids));
642 
643  $asset_lineage = '';
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).' &gt; ';
649  }
650 
651  if(!$display_reverse)
652  $asset_lineage_ids[] = $owner->id;
653 
654  if (!empty($parent_data)) {
655  $asset_lineage .= '<b>'.htmlspecialchars($parent_data['name'], ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).'</b>';
656  }
657  if (isset($output_lineages[$asset_lineage]) && !$can_edit) {
658  return '';
659  }
660 
661  ob_start();
662  ?>
663  <tr>
664  <td class="sq-backend-table-cell" style="text-align: center;">
665  <?php
666  if ($link_type & SQ_SC_LINK_BACKEND_NAV) {
667  ?>
668  <a href="#">
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).'"');
670  ?>
671  </a>
672  <?php
673  }
674  ?>
675  </td>
676  <td style="text-align: center;">
677  <?php echo $linkid; ?>
678  </td>
679  <td style="text-align: center;">
680  <?php
681  if (!$can_edit) {
682  echo link_type_name($link_type);
683  } else {
684  combo_box($prefix.'_link_type['.$linkid.']', $editable_link_types, FALSE, $link_type);
685  $editing_linkids[] = $linkid;
686  }
687  ?>
688  </td>
689  <td style="text-align: center;">
690  <?php echo $majorid; ?>
691  </td>
692  <td style="text-align: center;">
693  <?php
694  if (!$can_edit) {
695  echo $link_value;
696  } else {
697  text_box($prefix.'_link_value['.$linkid.']', html_entity_decode($link_value, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), 15, FALSE);
698  }
699  ?>
700  </td>
701  <td style="text-align: center;">
702  <?php
703  if ($link_type <= 2) {
704  $lock_status = ($link_locking == '1') ? 'tick' : 'cross';
705  $lock_status_desc = ($link_locking == '1') ? 'locked' : 'unlocked';
706  if ($can_edit) {
707  check_box($prefix.'_link_locked['.$linkid.']', '1', (($link_locking == '1') ? TRUE : FALSE));
708  } else {
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;" />';
710  }//end if
711  }//end if
712  ?>
713  </td>
714  <td><?php echo $asset_lineage; ?></td>
715  </tr>
716  <?php
717  $output = ob_get_contents();
718  ob_end_clean();
719 
720  return $output;
721 
722 }//end _printLine()
723 
724 
725 ?>