Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
page_upcoming_events_list_edit_fns.inc
1 <?php
18 require_once SQ_CORE_PACKAGE_PATH.'/page/page_edit_fns.inc';
19 
20 
33 {
34 
35 
40  function __construct()
41  {
42  parent::__construct();
43  }//end constructor
44 
55  function paintEventSources(&$asset, &$o, $prefix)
56  {
57  if ($asset->writeAccess('attributes')) {
58  multiple_asset_finder($prefix.'_event_sources', array_keys($asset->attr('root_nodes')));
59  return TRUE;
60  } else {
61  $infos = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(array_keys($asset->attr('root_nodes')), '', TRUE, 'name');
62  ?><ul style="margin: 1px 15px;"><?php
63  foreach ($infos as $id => $name) {
64  echo '<li>'.get_asset_tag_line($id).'</li>';
65  }
66  ?></ul><?php
67  return FALSE;
68  }
69 
70  }//end paintEventSources()
71 
72 
83  function processEventSources(&$asset, &$o, $prefix)
84  {
85  if (isset($_POST[$prefix.'_event_sources'])) {
86  $root_nodes = Array();
87  foreach ($_POST[$prefix.'_event_sources'] as $source) {
88  if (!empty($source['assetid'])) {
89  $root_nodes[$source['assetid']] = 1;
90  }
91  }
92  return $asset->setAttrValue('root_nodes', $root_nodes);
93  }
94  return FALSE;
95 
96  }//end processEventSources()
97 
98 
109  function paintDefaultFormatLinks(&$asset, &$o, $prefix)
110  {
111  ?>
112  <table class="sq-backend-table">
113  <tr>
114  <th><?php echo translate('edit_format') ?></th>
115  <th><?php echo translate('note') ?></th>
116  </tr>
117  <?php
118  $this->_paintDefaultFormatLink($asset->id, 'page_contents', translate('calendar_upcoming_events_page_contents_desc'));
119  ?>
120  </table>
121  <?php
122 
123  return FALSE;
124 
125  }//end paintDefaultFormatLinks()
126 
127 
140  function _paintDefaultFormatLink($root_assetid, $bodycopy_name, $bodycopy_description, $type_code='bodycopy', $screen='contents')
141  {
142  $link = $GLOBALS['SQ_SYSTEM']->am->getLink($root_assetid, SQ_LINK_TYPE_2, $type_code, TRUE, $bodycopy_name);
143  if (!empty($link)) {
144  $info = Array($link['minorid'] => 'contents');
145  $href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($info);
146  ?>
147  <tr>
148  <td>
149  <?php echo get_asset_tag_line($link['minorid'], $screen); ?>
150  </td>
151  <td>
152  <?php echo $bodycopy_description; ?>
153  </td>
154  </tr>
155  <?php
156  }
157 
158  }//end _paintDefaultFormatLink()
159 
160 
171  function paintTypeFormats(&$asset, &$o, $prefix)
172  {
173  $write_access = $asset->writeAccess('links');
174  $types = $this->_getAvailableTypes($asset);
175  $formats = $asset->getFormats('type_formats');
176  if (count($formats) > 0) {
177  ?>
178  <table class="sq-backend-table">
179  <tr>
180  <th><?php echo translate('asset_type') ?></th>
181  <th><?php echo translate('edit_format') ?></th>
182  <?php
183  if ($write_access) {
184  ?>
185  <th><?php echo translate('delete_question') ?></th>
186  <?php
187  }
188  ?>
189  </tr>
190  <?php
191  foreach ($formats as $minorid => $value) {
192  if ($value == 'default_format') continue;
193 
194  $info = Array($minorid => 'contents');
195  $href = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref($info);
196  $type_name = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($value, 'name');
197  ?>
198  <tr>
199  <td style="width: 200px;">
200  <?php
201  echo get_asset_type_icon($value);
202  echo $type_name;
203  ?>
204  </td>
205  <td>
206  <?php
207  echo get_asset_tag_line($minorid, 'contents');
208  ?>
209  </td>
210  <?php
211  if ($write_access) {
212  ?>
213  <td style="width: 100px;">
214  <?php
215  check_box($prefix.'_delete_type['.$value.']');
216  ?>
217  </td>
218  <?php
219  }
220  ?>
221  </tr>
222  <?php
223  }//end foreach
224  ?>
225  </table>
226  <?php
227  } else {
228  echo translate('calendar_upcoming_events_no_type_formats');
229  }//end if cutomised formats
230 
231  if ($write_access) {
232  $new_format_options = Array('' => '');
233  foreach ($types as $type => $inherit) {
234  if (in_array($type, $formats)) continue;
235  $new_format_options[$type] = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type, 'name');
236  }
237  if (count($new_format_options) > 0) {
238  echo '<p><b>'.translate('calendar_upcoming_events_new_type_format').'</b> ';
239  combo_box($prefix.'_new_type', $new_format_options, FALSE, '');
240  echo '</p>';
241  }
242  }
243 
244  return $write_access;
245 
246  }//end paintTypeFormats()
247 
248 
259  function processTypeFormats(&$asset, &$o, $prefix)
260  {
261  $folder = $asset->getFolder('type_formats');
262  $types = $this->_getAvailableTypes($asset);
263 
264  $deleted_formats = array_get_index($_POST, $prefix.'_delete_type', Array());
265  $new_type = array_get_index($_POST, $prefix.'_new_type', '');
266  if (isset($deleted_formats[$new_type])) {
267  trigger_localised_error('CMS0042', E_USER_WARNING, $new_type);
268  unset($deleted_formats[$new_type]);
269  $new_type = '';
270  }
271 
272  foreach ($deleted_formats as $type => $on) {
273  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $type);
274  if (empty($current_link)) {
275  trigger_localised_error('CMS0043', E_USER_WARNING, $type);
276  } else {
277  if (!$GLOBALS['SQ_SYSTEM']->am->deleteAssetLink($current_link['linkid'])) {
278  trigger_localised_error('CMS0044', E_USER_WARNING, $type);
279  }
280  }
281  }
282 
283  // check that the new type is valid
284  if ($new_type != '' && !isset($types[$new_type])) {
285  trigger_localised_error('CMS0045', E_USER_WARNING, $new_type);
286  $new_type = '';
287  }
288 
289  if ($new_type != '') {
290  // check that this type isnt already customised
291  $current_link = $GLOBALS['SQ_SYSTEM']->am->getLink($folder->id, SQ_LINK_TYPE_2, 'bodycopy', TRUE, $new_type);
292  if (empty($current_link)) {
293  // create a new format bodycopy for this type
294  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
295  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
296  $GLOBALS['SQ_SYSTEM']->am->includeAsset('bodycopy');
297 
298  $copy_link = Array('asset' => &$folder, 'value' => $new_type, 'link_type' => SQ_LINK_TYPE_2, 'is_dependant' => 1, 'is_exclusive' => 1);
299 
300  $bodycopy = new Bodycopy();
301  $bodycopy->setAttrValue('name', $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($new_type, 'name').' Format');
302 
303  if (!$bodycopy->create($copy_link)) {
304  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
305  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
306  return FALSE;
307  }
308  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
309  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
310  } else {
311  trigger_localised_error('CMS0046', E_USER_WARNING, $new_type);
312  }
313  }
314  if (isset($asset->_tmp['formats']['type_formats'])) {
315  unset($asset->_tmp['formats']['type_formats']);
316  }
317 
318  return TRUE;
319 
320  }//end processTypeFormats()
321 
322 
334  function _getAvailableTypes(&$asset)
335  {
336  $types = $asset->attr('types');
337 
338  // For each of these types, grab direct descendent asset types
339  foreach ($types as $base_asset_type => $inherit) {
340  $descendents = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($base_asset_type);
341 
342  if (is_array($descendents) && (count($descendents) > 0)) {
343  foreach ($descendents as $descendent_type) {
344  $types[$descendent_type] = 0;
345  }
346  }
347  }
348 
349  return $types;
350 
351  }//end _getAvailableTypes()
352 
353 
354 }//end class
355 ?>