Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
site_network_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/folder/folder_edit_fns.inc';
19 
32 {
33 
34 
40  {
41  $this->Folder_Edit_Fns();
42  unset($this->static_screens['dependants']);
43  unset($this->static_screens['preview']);
44 
45  }//end constructor
46 
47 
58  function paintPrimaryURL(&$asset, &$o, $prefix)
59  {
60  $site_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'site', FALSE, 'primary_site');
61  $write_access = $asset->writeAccess('links');
62 
63  if (!$write_access) {
64  $site_asset = NULL;
65  if (!empty($site_link)) {
66  $site_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($site_link['minorid']);
67  }
68  if (!is_null($site_asset)) {
69  echo $asset->getPrimaryURL();
70  echo '<br/ ><i>'.strtolower(translate('from')).' '.get_asset_tag_line($site_asset->id).'</i>';
71  } else {
72  echo translate('core_primary_url_not_set');
73  }
74  } else {
75  asset_finder($prefix.'_primary_site', (!empty($site_link)) ? $site_link['minorid'] : '', Array('site' => 'D'));
76  }
77 
78  return $write_access;
79 
80  }//end paintPrimaryURL()
81 
82 
93  function processPrimaryURL(&$asset, &$o, $prefix)
94  {
95  if (empty($_POST[$prefix.'_primary_site']['assetid'])) {
96  return FALSE;
97  }
98  $new_site = $_POST[$prefix.'_primary_site']['assetid'];
99 
100  $site_link = $GLOBALS['SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE, 'site', FALSE, 'primary_site');
101 
102  // dont process anything if the primary site has not changed
103  if (!empty($site_link) && $site_link['minorid'] == $new_site) {
104  return FALSE;
105  }
106 
107  // make sure this new primary site is in our network
108  $network_link = $GLOBALS['SQ_SYSTEM']->am->getLinkByAsset($asset->id, $new_site, SQ_SC_LINK_SIGNIFICANT);
109  if (empty($network_link)) {
110  trigger_localised_error('CORE0122', E_USER_WARNING);
111  return FALSE;
112  }
113 
114  $ok = TRUE;
115  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
116  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
117 
118  // deleting old primary site if any found...
119  if (!empty($site_link) && !$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($site_link['linkid'])) {
120  $ok = FALSE;
121  } else if ($new_site) {
122  $site = $GLOBALS['SQ_SYSTEM']->am->getAsset($new_site);
123  if (!is_null($site)) {
124  if (!$asset->createLink($site, SQ_LINK_NOTICE, 'primary_site')) {
125  $ok = FALSE;
126  trigger_localised_error('CORE0028', E_USER_WARNING, $site->name, $site->id);
127  }
128  }
129  }
130 
131  if ($ok) {
132  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
133  } else {
134  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
135  }
136 
137  // return FALSE because we dont need our attributes saved
138  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
139  return FALSE;
140 
141  }//end processPrimaryURL()
142 
143 
144 }//end class
145 
146 ?>