Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
asset_edit_fns.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 
30 {
31 
36  var $static_screens = Array(
37  'details' => Array(
38  'name' => 'Details',
39  'force_unlock' => TRUE,
40  'lock_type' => 'menu',
41  ),
42  'permissions' => Array(
43  'name' => 'Permissions',
44  'force_unlock' => FALSE,
45  'lock_type' => 'permissions',
46  ),
47  'workflow' => Array(
48  'name' => 'Workflow',
49  'force_unlock' => TRUE,
50  'lock_type' => 'workflow',
51  ),
52  'roles' => Array(
53  'name' => 'Roles',
54  'force_unlock' => TRUE,
55  'lock_type' => 'roles',
56  ),
57  'metadataSchemas' => Array(
58  'name' => 'Metadata Schemas',
59  'force_unlock' => TRUE,
60  'lock_type' => 'metadata',
61  ),
62  'metadata' => Array(
63  'name' => 'Metadata',
64  'force_unlock' => TRUE,
65  'lock_type' => 'metadata',
66  ),
67  'dependants' => Array(
68  'name' => 'Dependants',
69  'force_unlock' => TRUE,
70  'lock_type' => 'none',
71  ),
72  'linking' => Array(
73  'name' => 'Linking',
74  'force_unlock' => TRUE,
75  'lock_type' => 'links',
76  ),
77  'settings' => Array(
78  'name' => 'Settings',
79  'force_unlock' => TRUE,
80  'lock_type' => 'all',
81  ),
82  'history' => Array(
83  'name' => 'History',
84  'force_unlock' => TRUE,
85  'lock_type' => 'none',
86  ),
87  'logs' => Array(
88  'name' => 'Logs',
89  'force_unlock' => TRUE,
90  'lock_type' => 'none',
91  ),
92  'preview' => Array(
93  'name' => 'Preview',
94  'force_unlock' => TRUE,
95  'lock_type' => 'none',
96  ),
97  'lookupValues' => Array(
98  'name' => 'Lookup Settings',
99  'force_unlock' => FALSE,
100  'lock_type' => 'lookupValues',
101  ),
102  'tagging' => Array(
103  'name' => 'Tagging',
104  'force_unlock' => TRUE,
105  'lock_type' => 'menu',
106  ),
107  'layouts' => Array(
108  'name' => 'Layouts',
109  'force_unlock' => FALSE,
110  'lock_type' => 'all',
111  ),
112  );
113 
114 
119  function Asset_Edit_Fns()
120  {
121  $this->MySource_Object();
122 
123  }//end constructor
124 
125 
136  function paintPaths(&$asset, &$o, $prefix)
137  {
138 
139  $wa = $asset->writeAccess('lookups');
140 
141  $paths = $asset->getWebPaths();
142 
143  foreach ($paths as $path) {
144  if ($wa) {
145  text_box($prefix.'_paths[]', $path, 25);
146  } else {
147  echo $path;
148  }
149  echo '<br/>';
150  }
151 
152  if ($wa) text_box($prefix.'_paths[]', '', 25);
153 
154  return $wa;
155 
156  }//end paintPaths()
157 
158 
169  function paintEditRemapURLs(&$asset, &$o, $prefix)
170  {
171  $admin_access = $asset->adminAccess('lookups');
172 
173  $remap_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('remap_manager');
174  $remap_urls = $remap_manager->getRemapURLs($asset);
175 
176  if (empty($remap_urls)) {
177  echo translate('no_associated_remaps');
178  return FALSE;
179  }
180 
181  $num_per_page = 100;
182  $total_assets = count($remap_urls);
183  $num_pages = ceil($total_assets / $num_per_page);
184 
185  $page_num = array_get_index($_POST, $prefix.'_remap_urls_page', 1);
186  $page_num = max($page_num, 1);
187  $page_num = min($page_num, $num_pages);
188 
189  if ($num_pages == 1) {
190  $page_tag = translate('page_number', $page_num, $num_pages);
191  } else {
192  $page_tag = translate('page_number_with_pager', $page_num, $num_pages, $prefix.'_remap_urls_page');
193  }
194  $asset_count_tag = translate('item_range', ($page_num - 1) * $num_per_page + 1, min($total_assets, $page_num * $num_per_page), $total_assets, strtolower(translate('remap_entries')));
195 
196  $remap_urls = array_slice($remap_urls, ($page_num - 1) * $num_per_page, $num_per_page);
197 
198  $links = Array(
199  'first' => '&lt;&lt;',
200  'previous' => '&lt;',
201  'page' => $page_tag,
202  'next' => '&gt;',
203  'last' => '&gt;&gt;',
204  );
205 
206  if ($page_num > 1) {
207  $links['first'] = '<a title="'.translate('pagination_go_to_first').'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.'_remap_urls_page\', 1)">'.$links['first'].'</a>';
208  $links['previous'] = '<a title="'.translate('pagination_go_to_previous').'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.'_remap_urls_page\', '.($page_num - 1).')">'.$links['previous'].'</a>';
209  } else {
210  $links['first'] = '<span title="'.translate('pagination_cannot_go_further_back').'." style="color: #333">'.$links['first'].'</span>';
211  $links['previous'] = '<span title="'.translate('pagination_cannot_go_further_back').'." style="color: #333">'.$links['previous'].'</span>';
212  }
213 
214  if ($page_num < $num_pages) {
215  $links['last'] = '<a title="'.translate('pagination_go_to_last').'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.'_remap_urls_page\', '.$num_pages.')">'.$links['last'].'</a>';
216  $links['next'] = '<a title="'.translate('pagination_go_to_next').'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.'_remap_urls_page\', '.($page_num + 1).')">'.$links['next'].'</a>';
217  } else {
218  $links['last'] = '<span title="'.translate('pagination_cannot_go_further_forward').'." style="color: #333">'.$links['last'].'</span>';
219  $links['next'] = '<span title="'.translate('pagination_cannot_go_further_forward').'." style="color: #333">'.$links['next'].'</span>';
220  }
221 
222  hidden_field($prefix.'_remap_urls_page', $page_num); ?>
223 
224  <table class="sq-backend-table">
225  <tr class="sq-backend-table-row">
226  <td class="sq-backend-table-header-header"><?php echo implode(' &nbsp; &nbsp; ', $links) ?></td>
227  <td class="sq-backend-table-header-header" colspan="<?php echo ($admin_access === TRUE) ? 5 : 4 ?>" style="text-align: right; font-weight: normal"><?php echo $asset_count_tag; ?></span></td>
228  </tr>
229  <tr>
230  <td class="sq-backend-table-header"><?php echo translate('url'); ?></td>
231  <td class="sq-backend-table-header"><?php echo translate('remap_url'); ?></td>
232  <td class="sq-backend-table-header"><?php echo translate('expires'); ?></td>
233  <td class="sq-backend-table-header"><?php echo translate('type'); ?></td>
234  <?php
235  if ($admin_access) {
236  ?>
237  <td class="sq-backend-table-header">
238  <?php
239  check_box($prefix.'_select_all', '1', FALSE, "check_all(document.main_form, '{$prefix}_delete_remap', this.checked);");
240  label(translate('delete_question'), $prefix.'_select_all');
241  ?>
242  </td>
243  <?php
244  }
245  ?>
246  <td class="sq-backend-table-header"><?php echo translate('never_delete'); ?></td>
247  </tr>
248  <?php
249  foreach ($remap_urls as $url_info) {
250  if (empty($url_info['expires'])) {
251  $expires = translate('never');
252  } else {
253  $expires = $GLOBALS['SQ_SYSTEM']->datetime(iso8601_ts($url_info['expires']));
254  }
255  ?>
256  <tr>
257  <td class="sq-backend-table-cell"><?php echo $url_info['url']; ?></td>
258  <td class="sq-backend-table-cell"><?php echo $url_info['remap_url']; ?></td>
259  <td class="sq-backend-table-cell"><?php echo $expires; ?></td>
260  <td class="sq-backend-table-cell"><?php echo ((int)$url_info['auto_remap'] === 1) ? translate('automatic') : (($url_info['auto_remap'] === NULL) ? translate('unknown') : translate('manual')); ?></td>
261  <?php
262  if ($admin_access) {
263  ?>
264  <td class="sq-backend-table-cell">
265  <?php
266  check_box($prefix.'_delete_remap['.$url_info['url'].']', 1, FALSE, '', $url_info['never_delete'] ? 'disabled' : '');
267  ?>
268  </td>
269  <?php
270  }
271  ?>
272 
273  <td class="sq-backend-table-cell"><img src="<?php echo sq_web_path('lib')."/web/images/".($url_info['never_delete'] ? "tick.gif" : "cross.gif"); ?>" width="15" height="15" /></td>
274  </tr>
275  <?php
276  }//end foreach
277  ?>
278  </table>
279 
280  <?php
281 
282  return $admin_access;
283 
284  }//end paintEditRemapURLs()
285 
286 
297  function processPaths(&$asset, &$o, $prefix)
298  {
299  if (!isset($_POST[$prefix.'_paths'])) return FALSE;
300 
301  // Add remaps only if they are to be automatically added when the web path is changed. The default behaviour
302  // is to add remaps. This functionality is controlled by a global switch in the Remap Manager and can be overridden
303  // on the Web Paths screen (per asset) on a one-shot basis when changing web paths
304 
305  $auto_add_remaps = isset($_POST[$prefix.'_remap_upon_webpath_change']);
306 
307  if (!$asset->saveWebPaths(array_values($_POST[$prefix.'_paths']), $auto_add_remaps)) {
308  return FALSE;
309  }
310 
311  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
312  $vars = Array('assetids' => Array($asset->id));
313  $hh->queueHipo('hipo_job_update_lookups', $vars);
314 
315  return TRUE;
316 
317  }//end processPaths()
318 
319 
330  function processEditRemapURLs(&$asset, &$o, $prefix)
331  {
332  if (!$asset->adminAccess('lookups')) return FALSE;
333 
334  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
335  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
336 
337  if (isset($_POST[$prefix.'_delete_remap'])) {
338  $urls = array_keys($_POST[$prefix.'_delete_remap']);
339 
340  $remap_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('remap_manager');
341  $remap_urls = $remap_manager->getRemapURLs($asset);
342 
343  foreach ($remap_urls as $url_info) {
344  foreach ($urls as $index => $url_to_delete) {
345  if ($url_info['url'] === $url_to_delete && $url_info['never_delete']) {
346  unset($urls[$index]);
347  }
348  }
349  }
350 
351  try {
352  $bind_vars = Array('urls' => $urls);
353  MatrixDAL::executeQuery('remap_manager', 'deleteRemapsByURL', $bind_vars);
354  } catch (DALException $e) {
355  throw new Exception('Unable to delete remaps due to database error: '.$e->getMessage());
356  }
357  }
358 
359  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
360  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
361 
362  return TRUE;
363 
364  }//end processEditRemapURLs()
365 
366 
377  function paintURLs(&$asset, &$o, $prefix)
378  {
379  $urls = $asset->getLookups();
380  if (empty($urls)) {
381  echo translate('no_associated_urls');
382  } else {
383  usort($urls, create_function('$a, $b', 'return strcmp($a[\'url\'], $b[\'url\']);'));
384  foreach ($urls as $data) {
385  if ($data['http']) {
386  echo 'http://'.$data['url'], '<br/>';
387  }
388  if ($data['https']) {
389  echo 'https://'.$data['url'], '<br/>';
390  }
391  }
392  }
393 
394  if ($asset->force_secure === '1') {
395  echo '<br>';
396  $o->note(translate('force_secure_set_on_asset'));
397  }
398 
399  }//end paintURLs()
400 
401 
412  function paintAddRemapURLs(&$asset, &$o, $prefix)
413  {
414  if (!$asset->adminAccess('lookups')) return FALSE;
415 
416  $urls = $asset->getURLs();
417  if (empty($urls)) {
418  $o->openField(translate('url_remappings'));
419  label(translate('url_remap_no_associated_asset_urls'));
420  $o->closeField();
421 
422  return FALSE;
423  }
424 
425  foreach ($urls as $url) {
426  if ($url['http'] == 1) {
427  $contents['http://'.$url['url']] = 'http://'.$url['url'];
428  }
429  if ($url['https'] == 1) {
430  $contents['https://'.$url['url']] = 'https://'.$url['url'];
431  }
432  }
433 
434  $remap_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('remap_manager');
435  $never_delete = ($remap_manager->attr('never_delete_remap_default') == FALSE) ? 0 : 1;
436 
437  $o->openField(translate('old_url'));
438  text_box($prefix.'_add_remap_old_url', '', 50);
439  $o->closeField();
440 
441  $o->openField(translate('new_url'));
442  combo_box($prefix.'_add_remap_new_url', $contents);
443  $o->note(translate('url_remap_explanation'));
444  $o->closeField();
445 
446  $o->openField(translate('expires'));
447  text_box($prefix.'_add_remap_expires_days', '', 5);
448  label(translate('days'), $prefix.'_add_remap_expires_days');
449  $o->closeField();
450 
451  $o->openField(translate('never_delete'));
452  check_box($prefix.'_add_remap_never_delete', TRUE, $never_delete);
453  $o->closeField();
454 
455  }//end paintAddRemapURLs()
456 
457 
468  function processAddRemapURLs(&$asset, &$o, $prefix)
469  {
470  if (!$asset->adminAccess('lookups')) return FALSE;
471 
472  // now add a manually set remap if we have on to set
473  if (!isset($_POST[$prefix.'_add_remap_old_url']) || !isset($_POST[$prefix.'_add_remap_new_url'])) {
474  return FALSE;
475  }
476  $old_url = trim($_POST[$prefix.'_add_remap_old_url']);
477  $new_url = trim($_POST[$prefix.'_add_remap_new_url']);
478  $expires = NULL;
479 
480  if (empty($old_url)) return FALSE;
481 
482  if (isset($_POST[$prefix.'_add_remap_expires_days'])) {
483  $expires_days = (int)$_POST[$prefix.'_add_remap_expires_days'];
484  if ($expires_days > 0) {
485  $expires = strtotime('+ '.$expires_days.' days');
486  }
487  }
488 
489  $remap_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('remap_manager');
490  $never_delete = isset($_POST[$prefix.'_add_remap_never_delete']) ? 1 : 0;
491  $remap_manager->addRemapURL($old_url, $new_url, $expires, $never_delete, FALSE);
492 
493  return TRUE;
494 
495  }//end processAddRemapURLs()
496 
497 
506  function isWorkflowComplete(&$asset)
507  {
508  return $GLOBALS['SQ_SYSTEM']->getWorkflowManager()->isWorkflowComplete($asset->id);
509 
510  }//end isWorkflowComplete()
511 
512 
527  function paintNoticeLinkedAsset(&$asset, $link_value, $type_codes=Array(), $field_name='', $multiple=FALSE)
528  {
529  if ($multiple) {
530  $links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, '', FALSE, 'major', $link_value);
531  } else {
532  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', FALSE, $link_value);
533  $links = empty($link) ? Array() : Array($link);
534  }
535 
536  if (empty($field_name)) {
537  $field_name = $asset->getPrefix().'_'.str_replace(' ', '_', strtolower($link_value));
538  }
539 
540  if (!$asset->writeAccess('links')) {
541  if (empty($links)) {
542  echo '<i>'.translate('none').'</i>';
543  } else {
544  foreach ($links as $link) {
545  echo get_asset_tag_line($link['minorid']);
546  }
547  }
548  return FALSE;
549  } else {
550  if ($multiple) {
551  $current = Array();
552  foreach ($links as $link) {
553  $current[] = $link['minorid'];
554  }
555  multiple_asset_finder($field_name, $current, $type_codes);
556  } else {
557  $current = empty($links) ? 0 : $links[0]['minorid'];
558  asset_finder($field_name, $current, $type_codes);
559  }
560  return TRUE;
561  }
562 
563  }//end paintNoticeLinkedAsset()
564 
565 
577  function processNoticeLinkedAsset(&$asset, $link_value, $field_name='', $multiple=FALSE)
578  {
579  if (empty($field_name)) {
580  $field_name = $asset->getPrefix().'_'.str_replace(' ', '_', strtolower($link_value));
581  }
582  if (!isset($_POST[$field_name])) return FALSE;
583 
584  if ($multiple) {
585 
586  $submitted_minorids = Array();
587  foreach ($_POST[$field_name] as $elt) {
588  if (!empty($elt['assetid'])) {
589  $submitted_minorids[] = $elt['assetid'];
590  }
591  }
592  $submitted_minorids = array_unique($submitted_minorids);
593 
594  $existing_minorids = Array();
595  $to_delete = Array();
596  $links = $GLOBALS['SQ_SYSTEM']->am->getLinks($asset->id, SQ_LINK_NOTICE, '', FALSE, 'major', $link_value);
597  foreach ($links as $link) {
598  if (in_array($link['minorid'], $submitted_minorids)) {
599  $existing_minorids[] = $link['minorid'];
600  } else {
601  $to_delete[] = $link['linkid'];
602  }
603  }
604  $to_add = array_diff($submitted_minorids, $existing_minorids);
605  $to_delete = array_unique($to_delete);
606 
607  if (empty($to_add) && empty($to_delete)) {
608  return FALSE;
609  }
610 
611  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
612  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
613  $success = TRUE;
614 
615  foreach ($to_add as $schemaid) {
616  $schema = $GLOBALS['SQ_SYSTEM']->am->getAsset($schemaid);
617  if (!$GLOBALS['SQ_SYSTEM']->am->createAssetLink($asset, $schema, SQ_LINK_NOTICE, $link_value)) {
618  $success = FALSE;
619  break;
620  }
621  }
622 
623  foreach ($to_delete as $linkid) {
624  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($linkid)) {
625  $success = FALSE;
626  break;
627  }
628  }
629 
630  $GLOBALS['SQ_SYSTEM']->doTransaction($success ? 'COMMIT' : 'ROLLBACK');
631  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
632 
633  } else {
634 
635  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, '', FALSE, $link_value);
636 
637  // if there has been no change, then there is nothing to do
638  if (!empty($link) && $link['minorid'] == $_POST[$field_name]['assetid']) {
639  return FALSE;
640  }
641 
642  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
643  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
644  $success = TRUE;
645 
646  // if there is a current link, we need to delete it
647  if (!empty($link)) {
648  $success = (bool) $asset->deleteLink($link['linkid']);
649  }
650 
651  if ($success && !empty($_POST[$field_name]['assetid'])) {
652  $selected_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($_POST[$field_name]['assetid']);
653  if (!is_null($selected_asset)) {
654  $success = (bool) $asset->createLink($selected_asset, SQ_LINK_NOTICE, $link_value);
655  }
656  }
657 
658  $GLOBALS['SQ_SYSTEM']->doTransaction($success ? 'COMMIT' : 'ROLLBACK');
659  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
660  }
661  return $success;
662 
663  }//end processNoticeLinkedAsset()
664 
665 
675  function isSearchInstalled(&$asset, $prefix)
676  {
677  return $GLOBALS['SQ_SYSTEM']->am->installed('search_manager');
678 
679  }//end isSearchInstalled()
680 
681 
690  function isBeingCreated(&$asset)
691  {
692  return ($asset->id == 0);
693 
694  }//end isBeingCreated()
695 
696 
705  function isNotBeingCreated(&$asset)
706  {
707  return !$this->isBeingCreated($asset);
708 
709  }//end isNotBeingCreated()
710 
711 
722  function paintAutomaticRemapSetting(&$asset, &$o, $prefix)
723  {
724  $write_access = $asset->writeAccess('lookups');
725 
726  if ($write_access) {
727  $o->closeField();
728 
729  $o->openField(translate('web_paths_auto_add_remaps'));
730  $rm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('remap_manager');
731  $remap_upon_webpath_change = $rm->attr('remap_upon_webpath_change');
732 
733  // paint checkbox
734  check_box($prefix.'_remap_upon_webpath_change', TRUE, $remap_upon_webpath_change);
735 
736  $o->note(translate('web_paths_auto_add_remaps_note'));
737  $o->closeField();
738  }
739 
740 
741  return $write_access;
742 
743  }//end paintAutomaticRemapSetting()
744 
745 
756  function paintCreateLink(&$asset, &$o, $prefix)
757  {
758  $editable_link_types = Array(
759  SQ_LINK_TYPE_1 => link_type_name(SQ_LINK_TYPE_1),
760  SQ_LINK_TYPE_2 => link_type_name(SQ_LINK_TYPE_2),
761  );
762 
763  if (isset($_REQUEST['parent_assetid'])){
764  $restricted_sites = $GLOBALS['SQ_SYSTEM']->getUserPrefs('site', 'SQ_CHILD_CREATE_LINK_TYPE_2_RESTRICT');
765  $parent_sites = array_keys($GLOBALS['SQ_SYSTEM']->am->getParents($_REQUEST['parent_assetid'], 'site'));
766  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo($_REQUEST['parent_assetid'], 'site');
767  if (!empty($asset_info)) $parent_sites[] = $_REQUEST['parent_assetid'];
768 
769  if (array_intersect($restricted_sites, $parent_sites) != Array()) {
770  unset($editable_link_types[SQ_LINK_TYPE_1]);
771  $_REQUEST['link_type'] = SQ_LINK_TYPE_2;
772  }
773  }
774 
775  $o->closeField();
776  $o->openField(translate('link_type'));
777  combo_box('link_type', $editable_link_types, FALSE, isset($_REQUEST['link_type']) ? $_REQUEST['link_type'] : SQ_LINK_TYPE_1);
778  $o->closeField();
779  return TRUE;
780 
781  }//end paintCreateLink()
782 
783 }//end class
784 ?>