54 $backend->out->addJsInclude(sq_web_path(
'lib').
'/asset_map/asset_map.js');
57 <script type=
"text/javascript"><!--
63 <table style=
"height: 100%; width: 100%;">
65 <td
class=
"sq-backend-header-item" style=
"width: 100%;"><img style=
"margin-left: 7px;" src=
"<?php echo sq_web_path('lib'); ?>/web/images/icons/asset_map/matrix_logo.gif" alt=
"MySource Matrix" /></td>
68 <td style=
"height: 100%; width: 100%;" valign=
"top">
91 if (!isset($assetid2) || empty($assetid2) || $assetid1 == $assetid2) {
95 $lineages1 = $GLOBALS[
'SQ_SYSTEM']->am->getLinkLineages($assetid1);
97 $lineages2 = $GLOBALS[
'SQ_SYSTEM']->am->getLinkLineages($assetid2);
99 if (empty($lineages1) && !empty($lineages2)) {
101 }
else if (!empty($lineages1) && empty($lineages2)) {
105 $common_lineage = Array();
106 foreach ($lineages1 as $lineage) {
107 $lineageids = array_keys($lineage[
'lineage']);
108 if ($lineageids[0] == 1) array_shift($lineageids);
109 $lineageids[] = $assetid1;
110 foreach ($lineages2 as $lineage2) {
111 $lineage2ids = array_keys($lineage2[
'lineage']);
112 if ($lineage2ids[0] == 1) array_shift($lineage2ids);
113 $lineage2ids[] = $assetid2;
114 $intersected = array_intersect($lineageids, $lineage2ids);
115 if (count($intersected) > count($common_lineage)) {
116 $common_lineage = $intersected;
121 if (empty($common_lineage))
return 1;
123 return array_pop($common_lineage);
138 $count = count($assetids);
140 if ($count == 1)
return $assetids[0];
142 $parentid = $assetids[0];
143 for ($i=0; $i<$count; $i++) {
144 if ($i == $count-1) {
147 $compare_to = $assetids[$i+1];
150 if ($parentid == 1)
break;
171 $initial_selection_lineage =
'';
172 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL(NULL, NULL, TRUE, TRUE);
174 if (!is_null($asset) && !empty($asset)) {
177 $asset_lineage = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromURL();
178 $asset_link_lineage = $GLOBALS[
'SQ_SYSTEM']->am->getLinkLineages($asset->id);
182 $sort_orders_append =
'';
186 $num_assets = count($asset_lineage);
187 for ($i=0; $i < $num_assets; $i++) {
189 if (!($asset_lineage[$i][
'link_type'] & (SQ_LINK_TYPE_1 | SQ_LINK_TYPE_2))) {
196 $previd = $asset_lineage[$i-1][
'assetid'];
198 $currentid = $asset_lineage[$i][
'assetid'];
200 $assetids .= $currentid.
'|';
203 $sql =
'SELECT l.sort_order FROM sq_ast_lnk l
204 INNER JOIN sq_ast_lookup u ON l.minorid = u.assetid
205 WHERE l.majorid = :previd
206 AND l.minorid = :currentid
215 }
catch (Exception $e) {
216 throw new Exception(
'Unable to get the sort orders for URL: '.$asset_lineage[$i][
'url'].
' due to database error: '.$e->getMessage());
222 if (!empty($sort_order)) {
224 $sql =
'SELECT count(*) FROM sq_ast_lnk
225 WHERE majorid = :previd
226 AND sort_order < :sort_order
233 }
catch (Exception $e) {
234 throw new Exception(
'Unable to adjust real sort order for majorid: '.$previd.
' due to database error: '.$e->getMessage());
236 if ($count > 0) $sort_order = $sort_order - $count;
238 $sort_orders .= $sort_order.
'|';
241 $assetid_lineage = Array();
242 foreach ($asset_lineage as $lineage) {
243 $assetid_lineage[] = $lineage[
'assetid'];
247 array_pop($assetid_lineage);
249 $cur_lineage_num = 0;
250 foreach ($asset_link_lineage as $lineage_num => $lineage_info) {
252 $diff = array_diff($assetid_lineage, array_keys($lineage_info[
'lineage']));
254 $cur_lineage_num = $lineage_num;
260 $num_site_parents = 0;
263 if ($num_assets > 0 && !empty($asset_link_lineage[$cur_lineage_num][
'lineage'])) {
264 foreach ($asset_link_lineage[$cur_lineage_num][
'lineage'] as $assetid => $asset_name) {
265 if ((
int)$assetid != 1 && $asset_lineage[0][
'assetid'] != $assetid) {
266 $tmp_assetids .= $assetid.
'|';
277 if ($num_assets == 1) {
279 $asset_link_lineage[$cur_lineage_num][
'lineage'][$asset_lineage[0][
'assetid']] = $asset_lineage[0][
'name'];
285 if ($site_found && $num_site_parents > 0) {
286 $assetids = $tmp_assetids.$assetids;
290 foreach ($asset_link_lineage[$cur_lineage_num][
'lineage'] as $assetid => $asset_name) {
291 if ($i == $num_site_parents + 1)
break;
293 $previd = (string) $currentid;
294 if ($i == 0) $previd =
'1';
295 $currentid = $assetid;
299 'majorid' => $previd,
300 'minorid' => $currentid,
303 }
catch (Exception $e) {
304 throw new Exception(
'Unable to get sort order for majorid: '.$previd.
' and minorid: '.$currentid.
' due to database error: '. $e->getMessage());
306 $sort_orders_append .=
'|'.$sort_order;
310 $sort_orders = $sort_orders_append.$sort_orders;
311 $assetids = trim($assetids,
'|');
312 $sort_orders = trim($sort_orders,
'|');
314 $initial_selection_lineage = $assetids.
'~'.$sort_orders;
315 }
else if (strtolower($type) ==
'simple') {
317 if (isset($_COOKIE[
'lastSelectedAssetId']) && isset($_COOKIE[
'lastSelectedLinkId'])) {
318 $link_lineages = $GLOBALS[
'SQ_SYSTEM']->am->getLinkLineages($_COOKIE[
'lastSelectedAssetId']);
319 $id_parts = explode(
':', $_COOKIE[
'lastSelectedAssetId']);
320 foreach ($link_lineages as $lineage) {
321 if ($lineage[
'linkid'] == $_COOKIE[
'lastSelectedLinkId'] || (($lineage[
'link_type'] & SQ_SC_LINK_BACKEND_NAV) && isset($id_parts[1]))) {
322 $asset_lineage = array_keys($lineage[
'lineage']);
326 $asset_lineage[] = $_COOKIE[
'lastSelectedAssetId'];
327 $num_assets = count($asset_lineage);
328 for ($i=0; $i < $num_assets; $i++) {
332 $previd = $asset_lineage[$i-1];
335 if ($asset_lineage[$i] == 1)
continue;
336 $assetids .= $asset_lineage[$i].
'|';
337 $sort_orders .=
'-1|';
340 $assetids = trim($assetids,
'|');
341 $sort_orders = trim($sort_orders,
'|');
342 $initial_selection_lineage = $assetids.
'~'.$sort_orders;
349 return $initial_selection_lineage;
381 switch (strtolower($type)) {
383 $classname =
'SimpleAssetMap';
384 $jarname =
'assetmap';
385 if (!defined(
'SQ_PAINTED_SIMPLE_ASSET_MAP')) {
386 define(
'SQ_PAINTED_SIMPLE_ASSET_MAP', TRUE);
390 $classname =
'AssetMap';
391 $jarname =
'complexassetmap';
395 $root_url = sq_web_path(
'root_url');
396 if ($root_url{strlen($root_url) - 1} !=
'/') {
397 $root_url = $root_url.
'/';
401 require_once SQ_INCLUDE_PATH.
'/general.inc';
403 <script type=
"text/javascript" src=
"<?php echo sq_web_path('lib').'/js/detect.js' ?>"></script>
404 <script type=
"text/javascript" src=
"<?php echo sq_web_path('fudge').'/var_serialise/var_serialise.js' ?>"></script>
405 <script type=
"text/javascript" src=
"<?php echo sq_web_path('lib').'/asset_map/asset_map.js';?>"></script>
409 if (isset($GLOBALS[
'SQ_SYSTEM']->user)) {
410 $user = $GLOBALS[
'SQ_SYSTEM']->user;
416 if (is_null($user) || $user instanceof
Public_User || (method_exists($user,
'canAccessBackend') && !($user instanceof
Simple_Edit_User || $user->canAccessBackend()))) {
418 <b>You need Simple Edit access or higher to view the
Asset Map</b>
422 <applet
id=
"sq_asset_map" width=
"<?php echo $width; ?>" height=
"%applet_height%" code=
"net/squiz/matrix/<?php echo ($type == 'simple') ? $jarname : 'assetmap'; ?>/<?php echo $classname; ?>.class" archive=
"<?php echo sq_web_path('lib'); ?>/asset_map/java/<?php echo $jarname; ?>.jar?t=<?php echo time(); ?>" MAYSCRIPT>
426 $prefs = $GLOBALS[
'SQ_SYSTEM']->getUserPrefs(
'user',
'SQ_USER_ASSET_MAP_LINEAGE');
428 $assetids = explode(
',',$prefs);
433 if (!empty($common_parentid)) {
434 $lineages = $GLOBALS[
'SQ_SYSTEM']->am->getLinkLineages($common_parentid);
437 $first_lineage = Array();
438 if (!empty($lineages)) {
439 foreach ($lineages as $lineage) {
440 if ((
int) $lineage[
'link_type'] & SQ_SC_LINK_BACKEND_NAV) {
441 $first_lineage = $lineage;
447 if (!empty($first_lineage)) {
448 $lineage_assetids = array_keys($first_lineage[
'lineage']);
449 $lineage_assetids[] = $common_parentid;
450 $rootlineage = get_asset_lineage_sort_order($lineage_assetids);
454 $initial_selection_lineage =
'';
458 if (empty($rootlineage)) {
464 'parameter.backendsuffix' => SQ_CONF_BACKEND_SUFFIX,
465 'parameter.sessionid' => $_COOKIE[
'SQ_SYSTEM_SESSION'],
466 'parameter.sessionkey' => $GLOBALS[
'SQ_SYSTEM']->getUniqueSessionKey(),
467 'parameter.url.iconurl' =>
'__lib/web/images/icons',
468 'parameter.url.typecodeurl' =>
'__data/asset_types',
469 'parameter.url.notaccessibleicon' =>
'asset_map/not_accessible.png',
470 'parameter.url.type2icon' =>
'asset_map/not_visible.png',
471 'parameter.url.assetmapiconurl' =>
'__lib/web/images/icons/asset_map',
472 'parameter.url.baseurl' => $root_url,
473 'parameter.url.execurl' => $root_url.SQ_CONF_BACKEND_SUFFIX.
'?SQ_ACTION=asset_map_request&SESSION_ID='.$_COOKIE[
'SQ_SYSTEM_SESSION'].
'&SESSION_KEY='.$GLOBALS[
'SQ_SYSTEM']->getUniqueSessionKey(),
474 'parameter.asset.limit' => SQ_CONF_ASSET_MAP_ASSET_LIMIT,
475 'parameter.java.supportedversion' =>
'1.4.2,1.5.0,1.6.0',
476 'parameter.java.sunurl' =>
'http://java.sun.com/webapps/getjava/BrowserRedirect?locale=en&host=www.java.com:80',
477 'parameter.rootlineage' => $rootlineage,
478 'parameter.initialselection' => $initial_selection_lineage,
483 $params = implode(
',', array_keys($parameters));
484 ?><param name=
"parameter.params" value=
"<?php echo $params; ?>" /><?php
486 foreach ($parameters as $parameter => $value) {
487 ?><param name=
"<?php echo $parameter; ?>" value=
"<?php echo $value; ?>" /><?php
490 echo
'<p class="sq-backend-header-item" style="margin: 10px;">';
491 echo translate(
'asset_map_error_jre_latest_version_msg',
'<a class="sq-backend-header-item" style="text-decoration: underline" href="http://java.sun.com/webapps/getjava/BrowserRedirect?locale=en&host=www.java.com:80" target="_blank">Java Runtime Environment</a>');
497 $applet_tag = ob_get_contents();
501 $height =
"' + (document.body.offsetHeight - ".(SQ_IN_LIMBO ? 51 : 70).
") + '";
502 $applet_tag = str_replace(
"\n",
' ', $applet_tag);
504 <script type=
"text/javascript"><!--
506 document.write(
'<?php echo str_replace('%applet_height%
', $height, $applet_tag); ?>');
511 echo str_replace(
'%applet_height%', $height, $applet_tag);
527 header(
'Content-Type: text/xml; encoding=utf-8');
528 echo $output->asXML();
546 if (func_num_args() == 1) {
547 $func_args = Array();
548 }
else if (!is_array($func_args = func_get_arg(1))) {
549 $func_args = func_get_args();
550 $func_args = array_slice($func_args,1);
553 $output = simplexml_load_string(
'<xml></xml>');
554 $responses = $output->addChild(
'error', $GLOBALS[
'SQ_SYSTEM']->lm->getErrorMessage($code, $func_args));
559 $this->
_send($responses);
575 ini_set(
"display_errors", 0);
578 $user = isset($GLOBALS[
'SQ_SYSTEM']->user) ? $GLOBALS[
'SQ_SYSTEM']->user : NULL;
579 if (is_null($user) || $user instanceof
Public_User || (method_exists($user,
'canAccessBackend') && !($user instanceof
Simple_Edit_User || $user->canAccessBackend() || (method_exists($user,
'isShadowSimpleEditUser') && $user->isShadowSimpleEditUser())))) {
584 $GLOBALS[
'SQ_OUTPUT_TYPE'] =
'xml';
586 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
588 $xml = file_get_contents(
"php://input");
590 if (function_exists(
'libxml_disable_entity_loader'))
591 libxml_disable_entity_loader(TRUE);
592 $root = simplexml_load_string($xml);
593 if (function_exists(
'libxml_disable_entity_loader'))
594 libxml_disable_entity_loader(FALSE);
596 switch ($root[
'action']) {
597 case 'get translations' :
607 $this->
_getURL($root, $backend);
619 $this->
_error(
'AMAP0003', (
string)$root->attributes()->action);
637 $current_locale = $GLOBALS[
'SQ_SYSTEM']->lm->getCurrentLocale();
639 header(
'Content-Type: text/xml');
641 echo
'<translations locale="'.$current_locale.
'">'.
"\n";
643 $locales = $GLOBALS[
'SQ_SYSTEM']->lm->getCumulativeLocaleParts($current_locale);
644 foreach ($locales as $locale) {
645 $file_name = SQ_DATA_PATH.
'/private/system/core/java_strings_'.$locale.
'.properties';
646 if (file_exists($file_name)) {
647 echo file_get_contents($file_name).
"\n\n";
651 echo
"</translations>\n";
652 $out = ob_get_contents();
671 $output = simplexml_load_string(
'<xml></xml>');
672 $current_user = $GLOBALS[
'SQ_SYSTEM']->user;
676 $current_user_info = $this->
_getAssetInfo($current_user->id);
678 $root = $output->addChild(
'root');
679 $current_user_node = $root->addChild(
'current_user');
680 foreach ($current_user_info as $key => $value) {
681 if (strlen($value) == 0) $current_user_node->addAttribute($key,
' ');
682 else $current_user_node->addAttribute($key, $value);
685 $current_user_node_info = $current_user_node->addChild(
'asset');
686 $this->
_getChildAssets($current_user_node_info, $current_user->id, TRUE, TRUE);
687 $current_user_xml = $current_user_node->asXML();
692 $assets_node = $root->addChild(
'assets');
694 $root_node_info = $assets_node->addChild(
'asset');
695 foreach ($info as $key => $value) {
696 if (strlen($value) == 0) $root_node_info->addAttribute($key,
' ');
697 else $root_node_info->addAttribute($key, $value);
700 $assets_xml = $assets_node->asXML();
704 header(
'Content-Type: text/xml');
706 echo
"<initialisation>\n";
707 echo
"<asset_types>\n";
708 $dir = SQ_DATA_PATH.
'/private/asset_map';
709 if ($d = @opendir($dir)) {
710 while (($file = readdir($d)) !== FALSE) {
711 if (substr($file, -4) ==
'.xml') {
712 @readfile($dir.
'/'.$file);
718 echo
"</asset_types>\n";
719 echo $current_user_xml;
721 echo
"</initialisation>\n";
722 $out = ob_get_contents();
741 if (function_exists(
'mb_convert_encoding')) {
742 return mb_convert_encoding($string, $charset, SQ_CONF_DEFAULT_CHARACTER_SET);
763 if (FALSE !== strpos($assetid,
':')) {
765 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset(strtok($assetid,
':'));
766 $attrs = $bridge->getAssetMapAssetInfo($assetid);
771 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
773 if (!is_null($asset)) {
775 'assetid' => $assetid,
776 'short_name' => $asset->short_name,
777 'name' => $asset->name,
778 'type_code' => $asset->type(),
780 'status' => $asset->status,
781 'url' => $asset->getURL(),
786 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
788 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($bridge);
790 $attrs[
'assetid'] = urlencode($attrs[
'assetid']);
797 $bind_vars = Array();
799 $assetid = (String)$assetid;
801 if (!$GLOBALS[
'SQ_SYSTEM']->userRoot() && !$GLOBALS[
'SQ_SYSTEM']->userSystemAdmin()) {
802 $user =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
803 $userids = $user->getUserGroups();
804 $public_userid = (String)$GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
805 array_push($userids, $public_userid, (String)$GLOBALS[
'SQ_SYSTEM']->user->id);
806 $userid_cond =
' AND (p.userid IN (';
807 for (reset($userids); NULL !== ($k = key($userids)); next($userids)) {
808 $bind_vars[
'userid_' . $k] = $userids[$k];
809 $userid_cond .=
':userid_' . $k .
',';
811 $userid_cond = rtrim($userid_cond,
',') .
')';
813 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
814 $userid_cond .=
' OR r.userid IN (';
815 for (reset($userids); NULL !== ($k = key($userids)); next($userids)) {
816 $bind_vars[
'role_userid_' . $k] = $userids[$k];
817 $userid_cond .=
':role_userid_' . $k .
',';
819 $userid_cond = rtrim($userid_cond,
',') .
')';
821 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($user);
823 $userid_cond .=
') ';
828 $primary_protocol = current_protocol();
829 if (empty($primary_protocol)) {
830 $primary_protocol =
'http';
833 if ($primary_protocol ==
'http') {
834 $secondary_protocol =
'https';
836 $secondary_protocol =
'http';
839 $sql =
'SELECT l.assetid, l.short_name, l.name, l.type_code, l.status, u.url,
840 l.link_type, l.sort_order, ap.path,
841 (CASE u.'.$primary_protocol.
'
842 WHEN \'1\' THEN :primary_protocol
843 WHEN \'0\' THEN :secondary_protocol
845 $bind_vars[
'primary_protocol'] = $primary_protocol;
846 $bind_vars[
'secondary_protocol'] = $secondary_protocol;
848 if (!empty($userid_cond)) {
849 $sql .=
', p.permission AS accessible';
851 $sql .=
', 1 AS accessible';
854 $u_where =
'l.assetid = u.assetid';
855 $u_where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($u_where,
'u',
'ON');
857 $ap_where =
'l.assetid = ap.assetid';
858 $ap_where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($ap_where,
'ap',
'ON');
860 $sql .=
' FROM '.SQ_TABLE_RUNNING_PREFIX.
'vw_ast_lnk_minor l';
861 if (!empty($userid_cond)) {
862 $sql .=
' LEFT JOIN (SELECT p.assetid, p.permission
863 FROM '.SQ_TABLE_RUNNING_PREFIX.
'vw_ast_lnk_minor l2
864 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_perm p ON l2.assetid = p.assetid';
867 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
868 $sql .=
' LEFT JOIN '.SQ_TABLE_RUNNING_PREFIX.
'vw_ast_role r ON (p.userid = r.roleid AND r.assetid = l2.assetid)';
871 $sql .=
' WHERE l2.assetid = :assetid_1 AND (';
873 (p.permission = :p_permission AND (
874 p.userid <> :p_userid';
876 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
877 $sql .=
' OR r.userid <> :r_userid';
880 $sql .=
' OR (p.userid = :p_userid_1 AND p.granted = \'1\')';
882 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
883 $sql .=
' OR (r.userid = :r_userid_1 AND p.granted = \'1\')';
889 p.permission > :p_permission_1 AND p.granted = \'1\'
891 ) '.$userid_cond.
') GROUP BY p.assetid, p.permission HAVING MIN(p.granted) <> \'0\') p ON (l.assetid = p.assetid) ';
893 $bind_vars[
'p_permission'] = SQ_PERMISSION_READ;
894 $bind_vars[
'p_permission_1'] = SQ_PERMISSION_READ;
895 $bind_vars[
'p_userid'] = $public_userid;
896 $bind_vars[
'p_userid_1'] = $public_userid;
898 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
899 $bind_vars[
'r_userid'] = $public_userid;
900 $bind_vars[
'r_userid_1'] = $public_userid;
903 $bind_vars[
'assetid_1'] = $assetid;
906 $sql .=
' LEFT JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_url u '.$u_where.
' ';
907 $sql .=
' LEFT JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_path ap '.$ap_where.
' ';
909 $where =
' l.assetid = :assetid_2';
910 $bind_vars[
'assetid_2'] = $assetid;
912 if ($linkid && is_numeric($linkid)) {
913 $where .=
' AND l.linkid = :linkid';
914 $bind_vars[
'linkid'] = $linkid;
917 $where .=
' AND l.link_type <= :max_link_type';
918 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'ast_',
'WHERE', FALSE);
919 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'lnk_',
'WHERE', FALSE);
921 $bind_vars[
'max_link_type'] = SQ_LINK_TYPE_2;
925 foreach ($bind_vars as $key => $value) {
930 $asset = (!empty($assets)) ? $assets[0] : Array();
932 }
catch (Exception $e) {
933 throw new Exception(
'Failed to get Asset Info due to database error: '.$e->getMessage());
937 if (empty($asset))
return Array();
939 if (!isset($asset[
'accessible'])) {
940 $asset[
'accessible'] = 0;
942 if (empty($asset[
'accessible']) || $asset[
'accessible'] < 1) {
943 $asset[
'accessible'] = 0;
945 if ($asset[
'accessible'] > 1) {
946 $asset[
'accessible'] = 1;
949 if (!empty($asset[
'url'])) {
950 $asset[
'url'] = $asset[
'protocol'].
'://'.$asset[
'url'];
953 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($asset[
'type_code']);
954 if (implements_interface($asset[
'type_code'],
'bridge')) {
958 $bind_vars = Array();
959 $sql =
'SELECT COUNT(*)
960 FROM '.SQ_TABLE_RUNNING_PREFIX.
'vw_ast_lnk_major';
961 $where =
'majorid = :assetid AND link_type <= :max_link_type';
962 $bind_vars[
'assetid'] = $assetid;
963 $bind_vars[
'max_link_type'] = SQ_LINK_TYPE_2;
964 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'ast_',
'WHERE', FALSE);
965 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'lnk_',
'WHERE', FALSE);
968 foreach ($bind_vars as $key => $value) {
972 $num_kids = (!empty($results)) ? $results : 0;
974 }
catch (Exception $e) {
975 throw new Exception(
'Failed to get kids number due to database error: '.$e->getMessage());
980 'assetid' => urlencode($asset[
'assetid']),
981 'short_name' => $asset[
'short_name'],
982 'name' => $asset[
'name'],
983 'type_code' => $asset[
'type_code'],
984 'link_type' => $asset[
'link_type'],
985 'accessible' => $asset[
'accessible'],
986 'status' => $asset[
'status'],
987 'sort_order' => $asset[
'sort_order'],
988 'url' => $asset[
'url'],
989 'web_path' => $asset[
'path'],
990 'num_kids' => $num_kids,
991 'linkid' => urlencode($linkid),
998 if (isset($attrs[
'short_name'])) {
999 $attrs[
'short_name'] = urlencode($this->
_convertCharset($attrs[
'short_name']));
1022 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1024 $status = $asset->status;
1025 $asset->status = SQ_STATUS_LIVE;
1026 if(!($asset->readAccess())) {
1027 $this->
_error(
'AMAP0047', $asset->name, $asset->id);
1030 $asset->status = $status;
1033 $db_result = Array();
1037 $assetid = (String)$assetid;
1039 $bind_vars = array();
1040 if (!$GLOBALS[
'SQ_SYSTEM']->userRoot() && !$GLOBALS[
'SQ_SYSTEM']->userSystemAdmin()) {
1041 $user =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($GLOBALS[
'SQ_SYSTEM']->currentUserId());
1042 $userids = $user->getUserGroups();
1043 $public_userid = (String)$GLOBALS[
'SQ_SYSTEM']->am->getSystemAssetid(
'public_user');
1045 array_push($userids, $public_userid, (String)$GLOBALS[
'SQ_SYSTEM']->user->id);
1046 $userid_cond =
' AND (p.userid IN (';
1047 for (reset($userids); NULL !== ($k = key($userids)); next($userids)) {
1048 $bind_vars[
'userid_' . $k] = $userids[$k];
1049 $userid_cond .=
':userid_' . $k .
',';
1051 $userid_cond = rtrim($userid_cond,
',') .
')';
1053 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
1054 $userid_cond .=
' OR r.userid IN (';
1055 for (reset($userids); NULL !== ($k = key($userids)); next($userids)) {
1056 $bind_vars[
'role_userid_' . $k] = $userids[$k];
1057 $userid_cond .=
':role_userid_' . $k .
',';
1059 $userid_cond = rtrim($userid_cond,
',') .
')';
1061 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($user);
1063 $userid_cond .=
') ';
1068 $primary_protocol = current_protocol();
1069 if (empty($primary_protocol)) {
1070 $primary_protocol =
'http';
1073 if ($primary_protocol ==
'http') {
1074 $secondary_protocol =
'https';
1076 $secondary_protocol =
'http';
1079 $sql =
'SELECT l.assetid, l.short_name, l.name, l.type_code, l.status,
1080 l.linkid, l.link_type, l.sort_order, l.is_dependant, ap.path, u.url,
1081 (CASE u.'.$primary_protocol.
'
1082 WHEN \'1\' THEN :primary_protocol
1083 WHEN \'0\' THEN :secondary_protocol
1085 $bind_vars[
'primary_protocol'] = $primary_protocol;
1086 $bind_vars[
'secondary_protocol'] = $secondary_protocol;
1088 if (!empty($userid_cond)) {
1089 $sql .=
', p.permission AS accessible';
1091 $sql .=
', 1 AS accessible';
1094 $sql .=
' FROM '.SQ_TABLE_RUNNING_PREFIX.
'vw_ast_lnk_minor l';
1096 if (!empty($userid_cond)) {
1097 $sql .=
' LEFT JOIN (SELECT p.assetid, p.permission
1098 FROM '.SQ_TABLE_RUNNING_PREFIX.
'vw_ast_lnk_minor l2
1099 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_perm p ON l2.assetid = p.assetid';
1101 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
1102 $sql .=
' LEFT JOIN '.SQ_TABLE_RUNNING_PREFIX.
'vw_ast_role r ON (p.userid = r.roleid AND r.assetid = l2.assetid)';
1105 $sql .=
' WHERE l2.majorid = :assetid_1 AND (';
1107 (p.permission = :p_permission AND (
1108 p.userid <> :p_userid';
1110 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
1111 $sql .=
' OR r.userid <> :r_userid';
1114 $sql .=
' OR (p.userid = :p_userid_1 AND p.granted = \'1\')';
1116 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
1117 $sql .=
' OR (r.userid = :r_userid_1 AND p.granted = \'1\')';
1124 p.permission > :p_permission_1 AND p.granted = \'1\'
1126 ) '.$userid_cond.
') GROUP BY p.assetid, p.permission HAVING MIN(p.granted) <> \'0\') p ON (l.assetid = p.assetid) ';
1128 $bind_vars[
'p_permission'] = SQ_PERMISSION_READ;
1129 $bind_vars[
'p_permission_1'] = SQ_PERMISSION_READ;
1130 $bind_vars[
'p_userid'] = $public_userid;
1131 $bind_vars[
'p_userid_1'] = $public_userid;
1133 if (SQ_CONF_ENABLE_ROLES_PERM_SYSTEM ==
'1') {
1134 $bind_vars[
'r_userid'] = $public_userid;
1135 $bind_vars[
'r_userid_1'] = $public_userid;
1138 $bind_vars[
'assetid_1'] = $assetid;
1141 $u_where =
'l.assetid = u.assetid';
1142 $u_where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($u_where,
'u',
'ON');
1143 $sql .=
' LEFT JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_url u '.$u_where;
1145 $ap_where =
'l.assetid = ap.assetid';
1146 $ap_where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($ap_where,
'ap',
'ON');
1147 $sql .=
' LEFT JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_path ap '.$ap_where;
1149 $where =
'l.majorid = :assetid_2';
1150 $bind_vars[
'assetid_2'] = $assetid;
1152 if ($dependants_only) {
1153 $where .=
' AND l.is_dependant = :is_dependant';
1154 $bind_vars[
'is_dependant'] =
'1';
1157 l.link_type <= :max_link_type';
1158 $bind_vars[
'max_link_type'] = SQ_LINK_TYPE_2;
1160 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'ast_',
'WHERE', FALSE);
1161 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'lnk_',
'WHERE', FALSE);
1164 $sql .=
' ORDER BY sort_order';
1167 foreach($bind_vars as $key => $value) {
1172 }
catch (Exception $e) {
1173 throw new Exception(
'Unable to get all the children due to database error: '.$e->getMessage());
1182 foreach ($db_result as $db_result_v) {
1183 if (isset($skipped[$db_result_v[
'assetid']]) ===
true)
continue;
1184 if ($res_count >= $start) {
1185 if (isset($result[$db_result_v[
'assetid']]) ===
true)
continue;
1186 $result[$db_result_v[
'assetid']] = $db_result_v;
1187 if (($limit > 0) && ($added >= $limit-1)) {
1192 $skipped[$db_result_v[
'assetid']] = 1;
1199 $bind_vars = Array();
1201 $sql1 =
'SELECT majorid, COUNT(*) as link_count FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk';
1202 $sql2 =
'SELECT majorid, COUNT(*) as link_count FROM '.SQ_TABLE_RUNNING_PREFIX.
'shdw_ast_lnk';
1204 $sub_sql1 =
'SELECT minorid FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk';
1205 $sub_sql2 =
'SELECT minorid FROM '.SQ_TABLE_RUNNING_PREFIX.
'shdw_ast_lnk';
1206 $sub_where1 =
'majorid = :assetid';
1207 $sub_where2 =
'majorid = :assetid2';
1208 $bind_vars[
'assetid'] = $assetid;
1209 $bind_vars[
'assetid2'] = $assetid;
1210 $sub_where1 = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($sub_where1, NULL,
'WHERE', FALSE);
1211 $sub_where1 = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($sub_where1, NULL,
'WHERE', FALSE);
1212 $sub_where2 = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($sub_where2, NULL,
'WHERE', FALSE);
1213 $sub_where2 = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($sub_where2, NULL,
'WHERE', FALSE);
1214 $sub_sql = $sub_sql1.
' '.$sub_where1.
' GROUP BY minorid UNION ALL '.$sub_sql2.
' '.$sub_where2.
' GROUP BY minorid';
1216 $where_clause =
'majorid IN ('.$sub_sql.
') AND link_type <= :max_link_type';
1217 $bind_vars[
'max_link_type'] = SQ_LINK_TYPE_2;
1219 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where_clause, NULL,
'WHERE', FALSE);
1220 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where_clause, NULL,
'WHERE', FALSE);
1221 $where .=
' GROUP BY majorid ';
1224 foreach ($bind_vars as $key => $value) {
1228 if (!empty($db_result))
1230 foreach ($db_result as $key => $value) {
1231 if (isset($num_kids[$value[
'majorid']])) {
1232 $num_kids[$value[
'majorid']] = $num_kids[$value[
'majorid']] + $value[
'link_count'];
1234 $num_kids[$value[
'majorid']] = $value[
'link_count'];
1238 }
catch (Exception $e) {
1239 throw new Exception(
'Failed to get the number of children due to database error: '.$e->getMessage());
1243 $asset_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($assetid));
1244 $implements_shadow_assets = FALSE;
1246 if (strpos($assetid,
':') !== FALSE) {
1248 $implements_shadow_assets = TRUE;
1249 }
else if (isset($asset_info[$assetid][
'type_code']) && !empty($asset_info[$assetid][
'type_code'])) {
1250 $type_code = $asset_info[$assetid][
'type_code'];
1252 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
1253 $implements_shadow_assets = implements_interface($type_code,
'bridge');
1256 if ($implements_shadow_assets) {
1257 $links_handler = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
1259 if (!is_null($links_handler)) {
1261 if (method_exists($links_handler,
'getAssetMapLinks')) {
1262 $result = array_merge($result, $links_handler->getAssetMapLinks());
1265 for ($i = $start; $i < $start+$limit; $i++) {
1266 if (!isset($result[$i]))
break;
1267 $chunk[$i - $start] = $result[$i];
1274 $links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($assetid, SQ_LINK_TYPE_1 | SQ_LINK_TYPE_2);
1278 foreach ($links as $link_data) {
1281 if (strpos($link_data[
'minorid'],
':') === FALSE) {
1286 if ($start > $skipped) {
1291 if ($limit == $added)
break;
1298 $link_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link_data[
'minorid'], $link_data[
'minor_type_code']);
1301 'assetid' => $link_data[
'minorid'],
1302 'name' => $link_asset->name,
1303 'short_name' => $link_asset->short_name,
1305 'type_code' => $link_data[
'minor_type_code'],
1306 'status' => $link_asset->status,
1307 'linkid' => $link_data[
'majorid'].
':'.$link_data[
'minorid'],
1308 'link_type' => $link_data[
'link_type'],
1310 'sort_order' => $link_data[
'sort_order'],
1311 'url' => $link_asset->getURL(),
1313 'is_dependant' => $link_data[
'is_dependant']
1315 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($link_asset);
1320 foreach ($result as $asset) {
1321 if (!isset($asset[
'num_kids'])) {
1323 if (isset($asset[
'type_code']) && !empty($asset[
'type_code'])) {
1324 $type_code = $asset[
'type_code'];
1325 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($type_code);
1326 if (implements_interface($type_code,
'bridge')) {
1327 $num_kids[$asset[
'assetid']] = -1;
1330 $asset[
'num_kids'] = array_get_index($num_kids, $asset[
'assetid'], $default_kids);
1333 if (!isset($asset[
'accessible'])) {
1334 $asset[
'accessible'] = 0;
1336 if (empty($asset[
'accessible']) || $asset[
'accessible'] < 1) {
1337 $asset[
'accessible'] = 0;
1339 if ($asset[
'accessible'] > 1) {
1340 $asset[
'accessible'] = 1;
1343 if (!empty($asset[
'url']) && isset($asset[
'protocol'])) {
1344 $asset[
'url'] = $asset[
'protocol'].
'://'.$asset[
'url'];
1350 $id_parts = explode(
':', $asset[
'assetid']);
1351 if (isset($id_parts[1]) && !$implements_shadow_assets) {
1352 $bridge = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($id_parts[0]);
1353 $shdw_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset[
'assetid']);
1356 if ($shdw_asset != NULL) {
1357 $asset[
'short_name'] = $shdw_asset->short_name;
1358 $asset[
'type_code'] = $shdw_asset->type();
1360 $asset[
'short_name'] = translate(
'asset_not_found', $asset[
'assetid']);
1361 $asset[
'type_code'] =
'';
1363 $asset[
'status'] = $bridge->status;
1364 $asset[
'num_kids'] = -1;
1365 $asset[
'accessible'] = $bridge->readAccess();
1369 'assetid' => urlencode($asset[
'assetid']),
1370 'type_code' => $asset[
'type_code'],
1371 'link_type' => $asset[
'link_type'],
1372 'accessible' => $asset[
'accessible'],
1373 'status' => $asset[
'status'],
1374 'linkid' => urlencode($asset[
'linkid']),
1375 'num_kids' => $asset[
'num_kids'],
1376 'sort_order' => $asset[
'sort_order'],
1377 'url' => urlencode($asset[
'url']),
1378 'web_path' => urlencode($asset[
'path']),
1379 'is_dependant' => $asset[
'is_dependant'],
1383 if (!$attrs[
'accessible']) $attrs[
'child_count'] = 0;
1385 $tmp_node = $root->addChild(
'asset');
1386 foreach ($attrs as $key => $value) {
1387 if (strlen($value) == 0) $tmp_node->addAttribute($key,
' ');
1388 else $tmp_node->addAttribute($key, $value);
1406 $display_name = SQ_CONF_ASSET_MAP_ASSET_DISPLAY_NAME;
1407 if (!isset($this->_tmp[
'display_name_keywords'])) {
1416 foreach ($keywords as $keyword) {
1417 if (FALSE !== strpos(SQ_CONF_ASSET_MAP_ASSET_DISPLAY_NAME,
'%asset_'.$keyword.
'%')) {
1418 $this->_tmp[
'display_name_keywords'][] = $keyword;
1423 foreach ($this->_tmp[
'display_name_keywords'] as $keyword) {
1424 $replacement_value = array_get_index($asset, $keyword);
1427 $replacement_value = urldecode(array_get_index($asset, $keyword));
1430 $replacement_value = $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($replacement_value,
'name');
1433 $status_names = get_status_names();
1434 $replacement_value = $status_names[$replacement_value];
1437 if ($replacement_value==
'-1') {
1438 $replacement_value =
'N/A';
1442 $display_name = str_replace(
'%asset_'.$keyword.
'%', $replacement_value, $display_name);
1445 return $display_name;
1461 $output = simplexml_load_string(
'<xml></xml>');
1462 $root = $output->addChild(
'assets');
1468 foreach ($input->children() as $k => $v) {
1471 $tmp_info = Array();
1472 foreach ($v->attributes() as $a => $b) {
1473 $tmp_info[$a] = urldecode((
string)$b);
1476 if (empty($tmp_info[
'assetid']))
continue;
1478 if (array_key_exists(urldecode($tmp_info[
'assetid']), $done)) {
1480 $linkid_check = ($done[urldecode($tmp_info[
'assetid'])][
'linkid'] == urldecode($tmp_info[
'linkid']));
1481 $start_check = ($done[urldecode($tmp_info[
'assetid'])][
'start'] == urldecode($tmp_info[
'start']));
1482 $limit_check = ($done[urldecode($tmp_info[
'assetid'])][
'limit'] == urldecode($tmp_info[
'limit']));
1483 if ($linkid_check && $start_check && $limit_check) {
1489 $info = $this->
_getAssetInfo(urldecode($tmp_info[
'assetid']), urldecode($tmp_info[
'linkid']));
1492 $done[urldecode($tmp_info[
'assetid'])] = Array(
1493 'linkid' => urldecode($tmp_info[
'linkid']),
1494 'start' => urldecode($tmp_info[
'start']),
1495 'limit' => urldecode($tmp_info[
'limit']),
1499 $tmp_node = $root->addChild(
'asset');
1500 foreach ($info as $info_k => $info_v) {
1501 if (strlen($info_v) == 0) $tmp_node->addAttribute($info_k,
' ');
1502 else $tmp_node->addAttribute($info_k, $info_v);
1506 $this->
_getChildAssets($tmp_node, $tmp_info[
'assetid'], FALSE, $tmp_info[
'start'], $tmp_info[
'limit']);
1509 $this->
_send($root);
1530 $response_count = 0;
1534 $action_info = Array();
1535 foreach ($input->attributes() as $k => $v) {
1536 $action_info[$k] = (string)$v;
1539 switch ($action_info[
'cmd']) {
1542 $parent_assetid = urldecode($action_info[
'parent_assetid']);
1543 if (empty($parent_assetid) || !isset($action_info[
'pos']) || empty($action_info[
'type_code'])) {
1544 $this->
_error(
'AMAP0007');
1548 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($parent_assetid,
'', TRUE);
1549 if (is_null($parent)) {
1550 $this->
_error(
'AMAP0008', $parent_assetid);
1554 if ($GLOBALS[
'SQ_SYSTEM']->am->assetInTrash($parent_assetid, TRUE)) {
1555 $this->
_error(
'AMAP0009', $attr[
'parent_assetid']);
1559 $trash_folder = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'trash_folder');
1560 if ($trash_folder->id == $parent_assetid) {
1561 $this->
_error(
'AMAP0010');
1566 $error_message =
'';
1567 $link_types = Array(SQ_LINK_TYPE_1, SQ_LINK_TYPE_2);
1568 foreach ($link_types as $link_type) {
1569 if (TRUE === ($error_message = $GLOBALS[
'SQ_SYSTEM']->am->canLinkToType($parent, $action_info[
'type_code'], $link_type))) {
1571 $use_link_type = $link_type;
1576 if (!$use_link_type) {
1577 $this->
_error(
'AMAP0011', $error_message);
1582 if (!$parent->writeAccess(
'')) {
1583 $this->
_error(
'AMAP0012');
1588 $link = current_url().
'?SQ_BACKEND_PAGE=main'
1589 .
'&backend_section=am'
1590 .
'&am_section=add_asset'
1591 .
'&type_code='.urlencode($action_info[
'type_code'])
1592 .
'&link_type='.urlencode($use_link_type)
1593 .
'&parent_assetid='.$parent_assetid
1594 .
'&pos='.urlencode($action_info[
'pos']);
1601 $this->
_error(
'AMAP0013', $input->root->attributes[
'name']);
1605 if (empty($link) || empty($frame)) {
1606 $this->
_error(
'AMAP0014');
1617 $output = simplexml_load_string(
'<xml></xml>');
1618 $responses = $output->addChild(
'responses');
1619 $url_tree = $responses->addChild(
'url', htmlentities($link, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
1620 $url_tree->addAttribute(
'frame', $frame);
1622 $this->
_send($responses);
1639 $output->addRoot(
'responses');
1640 $response_count = 0;
1643 $input->root->attributes[
'to_parent_assetid'] = urldecode($input->root->attributes[
'to_parent_assetid']);
1644 $input->root->attributes[
'from_parent_assetid'] = urldecode($input->root->attributes[
'from_parent_assetid']);
1645 foreach ($input->root->children as $index =>$child) {
1646 $input->root->children[$index]->attributes[
'assetid'] = urldecode($child->attributes[
'assetid']);
1649 $old_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($input->root->attributes[
'from_parent_assetid']);
1650 if (is_null($old_parent)) {
1651 $this->
_error(
'AMAP0015', $input->root->attributes[
'from_parent_assetid']);
1655 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($input->root->attributes[
'linkid'], $old_parent->id);
1658 $this->
_error(
'AMAP0016', $input->root->attributes[
'linkid']);
1665 if ($old_parent->id == $input->root->attributes[
'to_parent_assetid']) {
1668 if (!$GLOBALS[
'SQ_SYSTEM']->am->moveLinkPos($link[
'linkid'], $input->root->attributes[
'to_parent_pos'])) {
1672 $linkid = $link[
'linkid'];
1675 $successTree->addRoot(
'success',
'', Array(
'linkid' => $linkid));
1676 $output->insertChild(Array(
'responses'), $response_count++, $successTree);
1679 if ($link[
'locked'] ==
'1') {
1680 $this->
_error(
'AMAP0046', $link[
'minorid']);
1684 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
1685 if (is_null($asset)) {
1686 $this->
_error(
'AMAP0017', $link[
'minorid']);
1691 if (($err_msg = $old_parent->isDeletableLink($link[
'linkid'])) !== TRUE) {
1692 $this->
_error(
'AMAP0018', $err_msg);
1696 $new_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($input->root->attributes[
'to_parent_assetid']);
1697 if (is_null($new_parent)) {
1698 $this->
_error(
'AMAP0019', $input->root->attributes[
'to_parent_assetid']);
1702 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
1704 'linkid' => $link[
'linkid'],
1705 'parentid' => $new_parent->id,
1706 'old_parentid' => $old_parent->id,
1707 'link_type' => $link[
'link_type'],
1708 'to_parent_pos' => $input->root->attributes[
'to_parent_pos'],
1711 $hh->queueHipo(
'hipo_job_create_link', $vars);
1714 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
1715 $url = $hh->runQueuedJobs(
'Javascript: function closeWindow() { setTimeout(\'window.close()\', 500); } closeWindow();');
1719 $urlTree->addRoot(
'url', $url, Array(
'js_function' =>
'asset_map_popup'));
1720 $output->insertChild(Array(
'responses'), $response_count++, $urlTree);
1726 $this->
_send($output);
1743 $output->addRoot(
'responses');
1744 $response_count = 0;
1747 $input->root->attributes[
'to_parent_assetid'] = urldecode($input->root->attributes[
'to_parent_assetid']);
1748 $input->root->attributes[
'from_parent_assetid'] = urldecode($input->root->attributes[
'from_parent_assetid']);
1749 foreach ($input->root->children as $index =>$child) {
1750 $input->root->children[$index]->attributes[
'assetid'] = urldecode($child->attributes[
'assetid']);
1753 $old_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($input->root->attributes[
'from_parent_assetid']);
1754 if (is_null($old_parent)) {
1755 $this->
_error(
'AMAP0020', $input->root->attributes[
'from_parent_assetid']);
1759 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($input->root->attributes[
'linkid'], $old_parent->id);
1761 $this->
_error(
'AMAP0021', $input->root->attributes[
'linkid']);
1767 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
1768 if (is_null($asset)) {
1769 $this->
_error(
'AMAP0022', $link[
'minorid']);
1774 if (!$asset->canClone()) {
1775 $this->
_error(
'AMAP0023', $asset->name, (ucwords(str_replace(
'_',
' ', $asset->type()))));
1778 $new_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($input->root->attributes[
'to_parent_assetid']);
1779 if (is_null($new_parent)) {
1780 $this->
_error(
'AMAP0024', $input->root->attributes[
'to_parent_assetid']);
1784 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
1786 'assetid' => $asset->id,
1787 'type_code' => $asset->type(),
1788 'to_parent_assetid' => $new_parent->id,
1789 'to_parent_pos' => $input->root->attributes[
'to_parent_pos'],
1791 $hh->queueHipo(
'hipo_job_clone_asset', $vars);
1794 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
1795 $url = $hh->runQueuedJobs(
'Javascript: function closeWindow() { setTimeout(\'window.close()\', 500); } closeWindow();');
1799 $urlTree->addRoot(
'url', $url, Array(
'js_function' =>
'asset_map_popup'));
1800 $output->insertChild(Array(
'responses'), $response_count++, $urlTree);
1803 $this->
_send($output);
1819 $root = $output->addRoot(
'responses');
1820 $response_count = 0;
1823 $input->root->attributes[
'to_parent_assetid'] = urldecode($input->root->attributes[
'to_parent_assetid']);
1824 $input->root->attributes[
'from_parent_assetid'] = urldecode($input->root->attributes[
'from_parent_assetid']);
1825 foreach ($input->root->children as $index =>$child) {
1826 $input->root->children[$index]->attributes[
'assetid'] = urldecode($child->attributes[
'assetid']);
1829 $old_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($input->root->attributes[
'from_parent_assetid']);
1830 if (is_null($old_parent)) {
1831 $this->
_error(
'AMAP0025', $input->root->attributes[
'from_parent_assetid']);
1835 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($input->root->attributes[
'linkid'], $old_parent->id);
1837 $this->
_error(
'AMAP0026', $input->root->attributes[
'linkid']);
1841 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
1842 if (is_null($asset)) {
1843 $this->
_error(
'AMAP0027', $link[
'minorid']);
1847 $new_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($input->root->attributes[
'to_parent_assetid']);
1848 if (is_null($new_parent)) {
1849 $this->
_error(
'AMAP0028', $input->root->attributes[
'to_parent_assetid']);
1853 $trash_folder = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'trash_folder');
1854 if ($trash_folder->id == $input->root->attributes[
'to_parent_assetid']) {
1855 $this->
_error(
'AMAP0029');
1859 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
1861 'assetid' => $asset->id,
1862 'parentid' => $new_parent->id,
1863 'link_type' => $link[
'link_type'],
1864 'to_parent_pos' => $input->root->attributes[
'to_parent_pos'],
1866 $hh->queueHipo(
'hipo_job_create_link', $vars);
1868 $url = $hh->runQueuedJobs(
'Javascript: function closeWindow() { setTimeout(\'window.close()\', 700); } closeWindow();');
1872 $urlTree->addRoot(
'url', $url, Array(
'js_function' =>
'asset_map_popup'));
1873 $root = $output->insertChild(
'responses', $response_count++, $urlTree);
1876 $this->
_send($output);
1905 $output = simplexml_load_string(
'<xml></xml>');
1906 $responses = $output->addChild(
'responses');
1908 $response_count = 0;
1911 $input = $this->_fixUrlencodedAssetids($input);
1913 $new_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
string)$input->attributes()->to_parent_assetid);
1914 $new_parent_pos = (string)$input->attributes()->to_parent_pos;
1916 if (is_null($new_parent)) {
1917 $this->
_error(
'AMAP0030', (
string)$input->attributes()->to_parent_assetid);
1922 $reordered_assets = Array();
1925 foreach ($input->asset as $asset_node) {
1926 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
string)$asset_node->attributes()->assetid);
1927 $old_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset(urldecode((
string)$asset_node->attributes()->parentid));
1928 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById((
string)$asset_node->attributes()->linkid, $old_parent->id);
1930 if (is_null($old_parent)) {
1931 $this->
_error(
'AMAP0031', $input->attributes()->from_parent_assetid);
1936 $this->
_error(
'AMAP0032', $asset_node->attributes()->linkid);
1940 if (($err_msg = $old_parent->isDeletableLink($link[
'linkid'])) !== TRUE) {
1941 $this->
_error(
'AMAP0033', $err_msg);
1945 if ($link[
'locked'] ==
'1') {
1946 $this->
_error(
'AMAP0046', $link[
'minorid']);
1950 if (is_null($asset)) {
1951 $this->
_error(
'AMAP0034', $link[
'minorid']);
1955 if ($old_parent->id == $new_parent->id) {
1956 $reordered_assets[$asset->id] = Array(
1957 'linkid' => $link[
'linkid'],
1958 'sort_order' => $link[
'sort_order'],
1959 'parentid' => $old_parent->id,
1964 if (!isset($assets[$asset->id])) {
1965 $assets[$asset->id] = Array();
1967 $assets[$asset->id][] = Array(
1968 'linkid' => $link[
'linkid'],
1969 'parentid' => $old_parent->id,
1976 foreach ($reordered_assets as $assetid => $link_info) {
1979 if ($GLOBALS[
'SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
1980 $majwa = $old_parent->writeAccess(
'');
1981 $minwa = $asset->writeAccess(
'');
1982 if (!($majwa || $minwa)) {
1983 $reordering_errors = translate(
'cannot_reorder_sig_link_no_perm_either', $asset->name, $asset->id, $old_parent->name, $old_parent->id);
1984 $this->
_error(
'AMAP0045', $reordering_errors);
1985 }
else if (!$majwa) {
1986 $reordering_errors = translate(
'cannot_reorder_sig_link_no_perm_major', $asset->name, $asset->id, $old_parent->name, $old_parent->id);
1987 $this->
_error(
'AMAP0045', $reordering_errors);
1988 }
else if (!$minwa) {
1989 $reordering_errors = translate(
'cannot_reorder_sig_link_no_perm_minor', $asset->name, $asset->id, $old_parent->name, $old_parent->id);
1990 $this->
_error(
'AMAP0045', $reordering_errors);
1995 if (!$GLOBALS[
'SQ_SYSTEM']->am->moveLinkPos($link_info[
'linkid'], $new_parent_pos)) {
1998 if ($new_parent_pos <= $link_info[
'sort_order']) {
2001 $success_node = $responses->addChild(
'success');
2002 $success_node->addAttribute(
'linkid', $link_info[
'linkid']);
2003 $success_node->addAttribute(
'assetid', $assetid);
2014 if (count($assets) == 1 && count(reset($assets)) == 1) {
2015 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
string)$input->asset[0]->attributes()->assetid);
2016 $old_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset(urldecode((
string)$input->asset[0]->attributes()->parentid));
2017 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById((
string)$input->asset[0]->attributes()->linkid);
2018 $link_type = array_get_index($link,
'link_type', SQ_LINK_TYPE_1);
2019 $value = array_get_index($link,
'value',
'');
2020 $dependant = array_get_index($link,
'is_dependant',
'0');
2021 $exclusive = array_get_index($link,
'is_exclusive',
'0');
2022 $sort_order = (string)$input->attributes()->to_parent_pos;
2023 $asset->prepareLink($new_parent,
'minor', $link_type, $value, $sort_order, $dependant, $exclusive);
2024 $new_parent->prepareLink($asset,
'major', $link_type, $value, $sort_order, $dependant, $exclusive);
2025 $can_create = $new_parent->canCreateLink($asset, $link_type, $exclusive);
2026 if ($can_create !== TRUE) {
2027 if ($can_create === FALSE) {
2028 $this->
_error(
'HIPO0020', $asset->id, $new_parent->id);
2030 $this->
_error(
'AMAP0018', $can_create);
2038 if (count($assets) > 0) {
2040 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
2043 'link_action' =>
'move',
2044 'assets' => $assets,
2045 'reordered_assets' => $reordered_assets,
2046 'to_parent_assetid' => $new_parent->id,
2047 'to_parent_pos' => $new_parent_pos,
2050 $hh->queueHipo(
'hipo_job_create_links', $vars);
2054 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
2056 $url = $hh->runQueuedJobs(
'Javascript: function closeWindow() { setTimeout(\'window.close()\', 500); } closeWindow();');
2059 $hipo_node = $responses->addChild(
'url', htmlentities($url, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
2060 $hipo_node->addAttribute(
'js_function',
'asset_map_popup');
2070 $this->
_send($responses);
2100 $output = simplexml_load_string(
'<xml></xml>');
2101 $responses = $output->addChild(
'responses');
2103 $response_count = 0;
2106 $input = $this->_fixUrlencodedAssetids($input);
2108 $new_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
string)$input->attributes()->to_parent_assetid);
2110 if (is_null($new_parent)) {
2111 $this->
_error(
'AMAP0035', $input->attributes()->to_parent_assetid);
2115 $assets = $assets_with_sort_order = Array();
2117 foreach ($input->children() as $asset_node) {
2118 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
string)$asset_node->attributes()->assetid);
2119 $old_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset(urldecode((
string)$asset_node->attributes()->parentid));
2120 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById((
string)$asset_node->attributes()->linkid, $old_parent->id);
2122 if (is_null($old_parent)) {
2123 $this->
_error(
'AMAP0036', (
string)$asset_node->attributes()->parentid);
2128 $this->
_error(
'AMAP0037', (
string)$asset_node->attributes()->linkid);
2132 if (is_null($asset)) {
2133 $this->
_error(
'AMAP0038', (
string)$asset_node->attributes()->assetid);
2138 if (!$asset->canClone()) {
2139 $this->
_error(
'AMAP0039', $asset->name, (ucwords(str_replace(
'_',
' ', $asset->type()))));
2145 $assets_with_sort_order[$link[
'sort_order']][$asset->id] = Array(
2146 'linkid' => $link[
'linkid'],
2147 'parentid' => $old_parent->id,
2154 ksort($assets_with_sort_order);
2156 foreach ($assets_with_sort_order as $sorted_assets) {
2157 foreach ($sorted_assets as $asset_id => $asset_info){
2158 $assets[$asset_id] = $asset_info;
2163 if (count($assets) == 1) {
2164 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
string)$input->asset->attributes()->assetid);
2165 $link_type = SQ_LINK_TYPE_1;
2169 $sort_order = (string)$input->attributes()->to_parent_pos;
2170 $asset->prepareLink($new_parent,
'minor', $link_type, $value, $sort_order, $dependant, $exclusive);
2171 $new_parent->prepareLink($asset,
'major', $link_type, $value, $sort_order, $dependant, $exclusive);
2172 $can_create = $GLOBALS[
'SQ_SYSTEM']->am->canLinkToType($new_parent, $asset->type(), $link_type, $dependant, $exclusive);
2173 if ($can_create !== TRUE) {
2174 $this->
_error(
'AMAP0044', $can_create);
2179 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
2181 'assets' => $assets,
2182 'to_parent_assetid' => $new_parent->id,
2183 'to_parent_pos' => ((
int)$input->attributes()->to_parent_pos)+1,
2186 $hh->queueHipo(
'hipo_job_clone_assets', $vars);
2189 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
2191 $url = $hh->runQueuedJobs(
'Javascript: function closeWindow() { setTimeout(\'window.close()\', 500); } closeWindow();');
2194 $url_tree = $responses->addChild(
'url', htmlentities($url, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
2195 $url_tree->addAttribute(
'js_function',
'asset_map_popup');
2204 $this->
_send($responses);
2233 $output = simplexml_load_string(
'<xml></xml>');
2234 $responses = $output->addChild(
'responses');
2236 $response_count = 0;
2239 $input = $this->_fixUrlencodedAssetids($input);
2241 $new_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
string)$input->attributes()->to_parent_assetid);
2243 if (is_null($new_parent)) {
2244 $this->
_error(
'AMAP0040', (
string)$input->attributes()->to_parent_assetid);
2250 foreach ($input->asset as $asset_node) {
2251 $old_parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset(urldecode((
string)$asset_node->attributes()->parentid));
2252 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById((
string)$asset_node->attributes()->linkid);
2253 $trash_folder = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'trash_folder');
2255 if (is_null($old_parent)) {
2256 $this->
_error(
'AMAP0041', (
string)$asset_node->attributes()->parentid);
2260 if ($trash_folder->id == ((
string)$input->attributes()->to_parent_assetid)) {
2261 $this->
_error(
'AMAP0043');
2265 $link_type = array_get_index($link,
'link_type', SQ_LINK_TYPE_1);
2267 $assets[(string)$asset_node->attributes()->assetid] = Array(
2268 'linkid' => (
string)$asset_node->attributes()->linkid,
2269 'link_type' => $link_type,
2270 'parentid' => $old_parent->id,
2275 if (count($assets) == 1) {
2276 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
string)$input->asset->attributes()->assetid);
2277 $link_type = SQ_LINK_TYPE_1;
2281 $sort_order = (string)$input->attributes()->to_parent_pos;
2282 $asset->prepareLink($new_parent,
'minor', $link_type, $value, $sort_order, $dependant, $exclusive);
2283 $new_parent->prepareLink($asset,
'major', $link_type, $value, $sort_order, $dependant, $exclusive);
2284 $can_create = $new_parent->canCreateLink($asset, $link_type, $exclusive);
2285 if ($can_create !== TRUE) {
2286 if ($can_create === FALSE) {
2287 $this->
_error(
'HIPO0021',
"$asset->name (#$asset->id)",
"$new_parent->name (#$new_parent->id)");
2289 $this->
_error(
'AMAP0011', $can_create);
2295 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
2297 'link_action' =>
'create',
2298 'assets' => $assets,
2299 'to_parent_assetid' => $new_parent->id,
2300 'to_parent_pos' => (
string)$input->attributes()->to_parent_pos,
2302 $hh->queueHipo(
'hipo_job_create_links', $vars);
2305 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
2307 $url = $hh->runQueuedJobs(
'Javascript: function closeWindow() { setTimeout(\'window.close()\', 500); } closeWindow();');
2310 $url_tree = $responses->addChild(
'url', htmlentities($url, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
2311 $url_tree->addAttribute(
'js_function',
'asset_map_popup');
2320 $this->
_send($responses);
2334 private function _fixUrlencodedAssetids($input)
2337 $temp_input =
new SimpleXMLElement(
'<command></command>');
2339 foreach($input->attributes() as $attr_name => $attr_value) {
2341 if ($attr_name ==
'to_parent_assetid') {
2342 $attr_value = urldecode($attr_value);
2344 $temp_input->addAttribute($attr_name, $attr_value);
2347 foreach($input->asset as $asset) {
2348 $new_child = $temp_input->addChild(
'asset',
'');
2349 foreach($asset->attributes() as $attr_name => $attr_value) {
2350 if ($attr_name ==
'assetid') {
2351 $attr_value = urldecode($attr_value);
2353 $new_child->addAttribute($attr_name, $attr_value);