17 require_once SQ_PACKAGES_PATH.
'/cms/page_templates/page_asset_listing/page_asset_listing.inc';
18 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
19 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
21 define(
'SQ_PAGE_LINK_MGR_PRESET_LINKED',
'Linked');
37 var $bodycopies = Array(
38 'logged_in' =>
'Logged In Layout',
39 'not_logged_in' =>
'Not Logged In Layout',
55 $this->_ser_attrs = TRUE;
56 parent::__construct($assetid);
71 if (!parent::_createBodycopies())
return FALSE;
77 'value' =>
'not_logged_in',
78 'link_type' => SQ_LINK_TYPE_2,
83 $asset->setAttrValue(
'name',
'Page Contents (Not Logged In)');
84 return $asset->create($copy_link, $args);
99 switch ($bodycopy_code) {
100 case 'not_logged_in':
101 return '<p>'.translate(
'cms_link_manager_not_logged_in_msg').
'</p>';
102 case 'page_contents':
103 return '<h2>'.translate(
'cms_link_manager_managing_links_for',
'%managed_asset_asset_name%').
'</h2>%asset_listing%<p>%submit_button%</p>';
104 case 'default_format':
105 return '%Linked_asset_selection% %asset_name%';
107 return parent::_getDefaultBodycopyContent($bodycopy_code);
121 $page_links = parent::_getAllowedLinks();
122 $page_links[SQ_LINK_TYPE_2][
'bodycopy'] = Array(
'card' => 3,
'exclusive' => FALSE);
138 protected function _getName($short_name=FALSE, $contextid=NULL)
141 if ($contextid === NULL) {
142 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
146 $attr = ($short_name) ?
'short_name' :
'name';
147 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName($attr, $this->
type(), Array($this->
id), $contextid);
148 if (empty($values) === TRUE) {
149 return parent::_getName($short_name, $contextid);
151 return $values[$this->id];
173 if (is_null($asset)) {
174 $this->_tmp[
'linked_selections'] = Array();
177 if (!isset($this->_tmp[
'linked_selections'])) {
180 $asset_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($asset->id, $this->attr(
'link_type'),
'', FALSE,
'minor', NULL, NULL, NULL, NULL, SQ_PERMISSION_WRITE);
184 $valid_nodes = Array();
185 foreach ($root_asset_ids as $root_asset_id) {
186 $new_valid_nodes = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($root_asset_id, array_keys($this->
attr(
'types')), FALSE));
187 $valid_nodes = array_merge($valid_nodes, $new_valid_nodes);
190 $current_links = Array();
191 foreach ($asset_links as $id => $link) {
192 if (in_array($link[
'majorid'], $valid_nodes)) {
193 $current_links[$link[
'majorid']] = $link[
'majorid'];
199 unset($this->_tmp[
'linked_selections']);
200 return $current_links;
203 $this->_tmp[
'linked_selections'] = $current_links;
206 return $this->_tmp[
'linked_selections'];
223 $tmp_managed_assetid = $parameter_map->getParameterValue(
'managed_asset');
224 if (!empty($tmp_managed_assetid)) {
225 $return = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($tmp_managed_assetid);
229 if (is_null($return) && $this->
attr(
'managed_asset')) {
230 $return = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
attr(
'managed_asset'));
233 if (is_null($return)) {
234 $return = $GLOBALS[
'SQ_SYSTEM']->user;
272 if ($selection_name == SQ_PAGE_LINK_MGR_PRESET_LINKED) {
277 if (!empty($asset_links[$assetid])) {
280 $selections = $this->
attr(
'asset_selections');
281 if (isset($selections[SQ_PAGE_LINK_MGR_PRESET_LINKED][
'type'])
282 && $selections[SQ_PAGE_LINK_MGR_PRESET_LINKED][
'type'] ==
'radio'
283 && empty($selection[SQ_PAGE_LINK_MGR_PRESET_LINKED][
'options'][
'allow_multiple'])) {
306 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
310 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
324 $public_user = $GLOBALS[
'SQ_SYSTEM']->getPublicUser();
325 if ($GLOBALS[
'SQ_SYSTEM']->currentUser($public_user)) {
328 if (is_null($bodycopy))
return FALSE;
330 require_once SQ_FUDGE_PATH.
'/general/text.inc';
331 $keywords = $bodycopy->getKeywords();
332 $replacements = Array();
333 foreach ($keywords as $keyword) {
336 $bodycopy->setKeywordReplacements($replacements);
337 $bodycopy->printBody();
341 return parent::printContents();
361 $asset_selection_linked = array_get_index($this->
attr(
'asset_selections'), SQ_PAGE_LINK_MGR_PRESET_LINKED, Array());
364 $is_checkbox = array_get_index($asset_selection_linked,
'type',
'radio')
365 && array_get_index(array_get_index($asset_selection_linked,
'options', Array()),
'allow_multiple', 1);
369 if ((!$is_checkbox && isset($_REQUEST[$request_index])) || ($is_checkbox && isset($_REQUEST[
'selection_flag_'.$request_index]))) {
370 $new_links = array_get_index($_REQUEST, $request_index, Array());
373 if (!is_array($new_links)) {
375 $new_links => $new_links,
378 foreach ($new_links as $index => $ticked) {
379 $new_links[$index] = $index;
385 $num_per_page = $this->
attr(
'num_per_page');
386 if ($num_per_page > 0) {
391 if ($this->
attr(
'group_by') ==
'grouped') {
393 $this->
sortGroups($this->
attr(
'asset_grouping'), $children, $children);
396 $asset_result_page_var =
'result_'.$this->id.
'_result_page';
397 $generic_result_page_var =
'result_page';
401 if (isset($_REQUEST[$generic_result_page_var])) {
402 $result_page = (int)$_REQUEST[$generic_result_page_var];
404 if (isset($_REQUEST[$asset_result_page_var])) {
405 $result_page = (int)$_REQUEST[$asset_result_page_var];
408 $num_per_page = $this->
attr(
'num_per_page');
409 if ($result_page <= 0) $result_page = 1;
411 $replacements = Array();
413 $chunk =& $this->
getChunk($children, $replacements, Array(), $result_page, $num_per_page);
414 $flattened_chunk = dal_array_flatten($chunk,
'type_code');
417 foreach ($asset_links as $assetid => $value) {
418 if (!isset($flattened_chunk[$assetid])) {
419 unset($asset_links[$assetid]);
425 $run_level = SQ_RUN_LEVEL_FORCED | SQ_SECURITY_LINK_INTEGRITY;
426 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($run_level);
427 $done = $this->
processMinorLinks($managed_asset->id, $asset_links, $new_links, $this->attr(
'link_type'));
428 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
433 unset($_SESSION[
'sq_user_groups']);
439 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
440 $vars = Array(
'assetids' => Array($managed_asset->id));
441 $hh->freestyleHipo(
'hipo_job_update_lookups', $vars);
463 $cannot_create = Array();
464 $cannot_delete = Array();
465 $to_delete = array_diff($old_links, $new_links);
466 $to_create = array_diff($new_links, $old_links);
467 $minor = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($minor_id);
472 foreach ($to_create as $majorid) {
473 $major = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($majorid);
474 if (!$GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($major, $minor, $link_type)) {
475 $done[
'add_error'][] = $major->id;
477 $done[
'add_success'][] = $major->id;
480 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($major);
483 foreach ($to_delete as $majorid) {
484 $curr_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($majorid, $minor_id, $link_type);
485 $link_id = $curr_link[
'linkid'];
487 if (!$GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($link_id)) {
488 $done[
'delete_error'][] = $majorid;
490 $done[
'delete_success'][] = $majorid;
495 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($minor);
513 foreach ($fail_success as $message_type => $assetids) {
514 switch ($message_type) {
516 case 'delete_success':
544 if (is_null($bodycopy))
return '';
546 $bodycopy->setKeywordReplacements($replacements);
549 $bodycopy->printBody();
550 $html = ob_get_contents();
570 if (array_key_exists($name, $this->bodycopies)) {
571 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $name,
'major',
'1');
572 $bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
590 $public_user = $GLOBALS[
'SQ_SYSTEM']->getPublicUser();
591 if ($GLOBALS[
'SQ_SYSTEM']->currentUser($public_user)) {
597 $keywords = $bodycopy->getKeywords();
598 $replacements = Array();
599 foreach ($keywords as $name) {
602 $bodycopy->setKeywordReplacements($replacements);
605 $bodycopy->printBody();
606 $html = ob_get_contents();
626 foreach ($assetids as $assetid) {
627 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
628 $names[] = $asset->name;
629 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
631 if (!empty($names)) {
633 $string .=
'"'.implode(
'", "', $names).
'"';
659 $keywords = parent::_getContentsKeywords();
663 'error_messages_list' => translate(
'cms_link_manager_error_messages_list'),
664 'success_messages_list' => translate(
'cms_link_manager_success_messages_list'),
669 $managed_keywords = $managed_asset->getAvailableKeywords();
670 foreach ($managed_keywords as $keyword => $description) {
672 $keywords[
'managed_asset_'.$keyword] = str_replace(
'Asset',
'Managed Asset', str_replace(
'asset',
'managed asset', $description));
674 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($managed_asset);
698 if (strpos($keyword,
'managed_asset_') === 0) {
700 if (isset($managed_asset)) {
701 return $managed_asset->getKeywordReplacement(substr($keyword, strlen(
'managed_asset_')));
705 return parent::getKeywordReplacement($keyword);
748 if (!empty($messages)) {
750 foreach ($messages as $message) {
751 $string .=
'<li class="'.$this->getPrefix().
'_'.$suffix.
'">'.$message.
'</li>';
770 return $this->
getPrefix().
'_'.parent::_getSelectionFieldNamePrefix($selection_name);