Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
metadataSchemas.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 
39 function paintInlineMetadataSchemas(Asset $owner, Backend_Outputter $o, Asset_Edit_Interface $ei, array $keywords=NULL)
40 {
41  $prefix = $owner->getPrefix();
42 
43  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
44  $schemas = $mm->getAssetSchemaInfo($owner->id, NULL, TRUE, FALSE);
45 
46  $direct = Array();
47  foreach ($schemas as $schemaid => $granted) {
48  if (!isset($direct[$granted])) {
49  $direct[$granted] = Array();
50  }
51  $direct[$granted][] = $schemaid;
52  }
53  ksort($direct);
54 
55  if (empty($direct)) return FALSE;
56 
57  $o->openSection(translate('metadata_schemas'));
58  $o->openField('&nbsp;');
59  ?>
60  <table class="sq-backend-table">
61  <tr>
62  <td class="sq-backend-table-header">
63  <?php echo translate('metadata_schema'); ?>
64  </td>
65  <td class="sq-backend-table-header" align="right">
66  <?php echo translate('access'); ?>
67  </td>
68  </tr>
69 
70  <?php
71  foreach ($direct as $granted => $schemaids) {
72  foreach ($schemaids as $schemaid) {
73  if ($schemaid) {
74  $schema = $GLOBALS['SQ_SYSTEM']->am->getAsset($schemaid);
75  if (!$schema->id || !($schema instanceof Metadata_Schema)) {
76  continue;
77  }
78  }
79 
80  ?>
81  <tr>
82  <td class="sq-backend-table-cell">
83  <?php
84  echo get_asset_tag_line($schemaid);
85  ?>
86  </td>
87  <td class="sq-backend-table-cell" align="right">
88  <span style="color: <?php echo (($granted == '0') ? 'red' : 'green'); ?>; font-weight: bold; "><?php echo (($granted == '0') ? translate('denied') : translate('applied')) ?></span>
89  </td>
90  </tr>
91  <?php
92  }
93  }
94 
95  ?></table><?php
96  $o->closeField();
97  $o->closeSection();
98 
99  return TRUE;
100 
101 }//end paintInlineMetadataSchemas()
102 
103 
114 function paintMetadataSchemas(Asset $owner, Backend_Outputter $o, Asset_Edit_Interface $ei)
115 {
116  $prefix = $owner->getPrefix();
117 
118  $admin_access = $owner->adminAccess('metadata');
119 
120  $o->openSection(translate('metadata_schemas'));
121 
122  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
123  $schemas = $mm->getAssetSchemaInfo($owner->id);
124 
125  $direct = Array();
126  foreach ($schemas as $schemaid => $schema_info) {
127  $granted = $schema_info['granted'];
128  if (!isset($direct[$granted])) {
129  $direct[$granted] = Array();
130  }
131  $direct[$granted][$schemaid] = $schema_info;
132  }
133  ksort($direct);
134 
135 
136  if (!empty($direct)) {
137  $o->openRaw();
138  foreach ($direct as $granted => $schema_list) {
139  ?>
140  <table class="sq-backend-table">
141  <tr>
142  <td class="sq-backend-table-header">
143  <span style="color: <?php echo (($granted == '0') ? 'red' : 'green'); ?>"><?php echo (($granted == '0') ? translate('denied') : translate('applied')) ?></span>
144  </td>
145  <td align="center" width="100" class="sq-backend-table-header">
146  <?php echo translate('cascade_question'); ?>
147  </td>
148  <?php
149  if ($admin_access) {
150  ?><td align="center" width="100" class="sq-backend-table-header"><?php echo translate('delete_question'); ?></td><?php
151  }
152  ?>
153  </tr>
154  <?php
155  foreach ($schema_list as $schemaid => $schema_detail) {
156  if ($schemaid) {
157  $schema_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($schemaid), 'metadata_schema', FALSE);
158  if (empty($schema_info)) continue;
159  }
160  ?>
161  <tr>
162  <td class="sq-backend-table-cell">
163  <?php
164  echo get_asset_tag_line($schemaid);
165  ?>
166  </td>
167  <td align="center" width="100" class="sq-backend-table-cell">
168  <?php
169  if ($admin_access) {
170  check_box($prefix.'_metadata[cascades]['.$schemaid.']', 1, $schema_detail['cascades']);
171  } else {
172  ?>
173  <img src="<?php echo sq_web_path('lib'); ?>/web/images/<?php echo ($schema_detail['cascades'] ? 'tick' : 'cross'); ?>.gif" width="15" height="15" />
174  <?php
175  }
176  ?>
177  </td>
178  <?php
179  if ($admin_access) {
180  ?><td align="center" width="100" class="sq-backend-table-cell"><?php
181  check_box($prefix.'_metadata[delete]['.$schemaid.']');
182  ?></td><?php
183  }
184  ?>
185  </tr>
186  <?php
187  }// end foreach data
188  ?>
189  </table>
190  <br>
191  <?php
192  }//end foreach inherited
193 
194  $o->closeRaw();
195 
196  }//end if
197 
198  if ($admin_access) {
199  $o->openField(translate('new_question'), 'new_line');
200  combo_box($prefix.'_metadata[new][granted]', Array('' => '', '1' => translate('apply'), '0' => translate('deny')), FALSE, '');
201  echo ' '.translate('metadata_schema').' ';
202  asset_finder($prefix.'_metadata[new][schemaid]', 0, Array('metadata_schema' => 'D'), 'sq_sidenav', FALSE, 'null', Array('clear'));
203  $o->closeField();
204  $o->openField(translate('cascade_question'), 'new_line');
205  check_box($prefix.'_metadata[new][cascades]', 1, TRUE);
206  ?> Cascade this new schema to newly-created children<?php
207  $o->closeField();
208  }
209 
210  $o->closeSection();
211 
212  if ($admin_access) {
213  $kiddies = $GLOBALS['SQ_SYSTEM']->am->getChildren($owner->id);
214  if (count($kiddies)) {
215  $o->openSection(translate('cascade_options'));
216  $o->openField('Note');
217  echo translate('action_affects_assets_below_this', count($kiddies), htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
218  $o->closeField();
219  $o->openField('&nbsp;');
220  check_box($prefix.'_metadata[cascade_changes]', '1', TRUE);
221  label(translate('cascade_schema_changes'), $prefix.'_metadata[cascade_changes]');
222  echo '<br/>';
223  check_box($prefix.'_metadata[manual_cascade]');
224  label(translate('manually_cascade_schema'), $prefix.'_metadata[manual_cascade]');
225  $o->closeField();
226  $o->closeSection();
227  }
228  }
229 
230  return $admin_access;
231 
232 }//end paintMetadataSchemas()
233 
234 
247 function processMetadataSchemas(Asset $owner, Backend_Outputter $o, Asset_Edit_Interface $ei)
248 {
249  // if we dont have admin access, go away
250  if ($owner->id && !$owner->adminAccess('')) {
251  $GLOBALS['SQ_SYSTEM']->paintLogin(translate('login'), translate('cannot_access_asset', htmlspecialchars($owner->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)));
252  exit();
253  }
254 
255  // if we dont have admin access, dont process anything
256  if (!$owner->adminAccess('metadata')) return FALSE;
257 
258  $prefix = $owner->getPrefix();
259  if (!isset($_POST[$prefix.'_metadata'])) return FALSE;
260 
261  $mm = $GLOBALS['SQ_SYSTEM']->getMetadataManager();
262 
263  // are we cascading these schema changes to our children?
264  $cascade_changes = FALSE;
265  if (isset($_POST[$prefix.'_metadata']['cascade_changes']) && $_POST[$prefix.'_metadata']['cascade_changes']) {
266  $cascade_changes = TRUE;
267  }
268 
269  $schema_vars = Array();
270  $post_data = $_POST[$prefix.'_metadata'];
271 
272  // apply a schema
273  if (!empty($post_data['new']['schemaid']['assetid'])) {
274  if (!isset($post_data['new']['granted']) || $post_data['new']['granted'] == '') {
275  trigger_localised_error('SYS0268', E_USER_NOTICE, $post_data['new']['schemaid']['assetid']);
276  } else {
277  // Only cascade changes to lower assets if "cascade to new assets"
278  // is set.
279  if ($cascade_changes && isset($post_data['new']['cascades'])) {
280  // cascading access of some kind, so queue it up for the HIPO
281  $schema_vars[] = Array(
282  'assetids' => Array($owner->id),
283  'granted' => (int)$post_data['new']['granted'],
284  'schemaid' => (int)$post_data['new']['schemaid']['assetid'],
285  'cascades' => (int)(isset($post_data['new']['cascades']) ? 1 : 0),
286  'previous_access' => NULL,
287  );
288  } else {
289  // lets do this ourselves
290  if (!$mm->setSchema($owner->id, (int)$post_data['new']['schemaid']['assetid'], (int)$post_data['new']['granted'], (isset($post_data['new']['cascades']) ? 1 : 0))) {
291  return FALSE;
292  }
293  }
294  }
295  }
296 
297  // revoke [deny] schema (apply or deny can be revoked)
298  if (!empty($post_data['delete'])) {
299  foreach ($post_data['delete'] as $schemaid => $on) {
300  $schemaid = (int)$schemaid;
301  $schema_info = $mm->getAssetSchemaInfo($owner->id, $schemaid);
302  if ($cascade_changes && $schema_info['cascades']) {
303  $current_access = $schema_info['granted'];
304  $schema_vars[] = Array(
305  'assetids' => Array($owner->id),
306  'granted' => -1,
307  'schemaid' => $schemaid,
308  'cascades' => $cascade_changes,
309  'previous_access' => $current_access,
310  );
311  } else {
312  if (!$mm->deleteSchema($owner->id, $schemaid)) {
313  return FALSE;
314  }
315  }
316  }
317  }
318 
319  // Set cascades here
320  $schemas = $mm->getAssetSchemaInfo($owner->id);
321  foreach ($schemas as $schemaid => $schema_info) {
322  // Prevent new schema from getting applied twice
323  if (isset($post_data['new']['schemaid']['assetid']) && $post_data['new']['schemaid']['assetid'] == $schemaid) {
324  continue;
325  }
326 
327  $cascades = isset($post_data['cascades'][$schemaid]);
328  if ((boolean)$cascades != (boolean)$schema_info['cascades']) {
329  if (!$mm->setSchema($owner->id, (int)$schemaid, (int)$schema_info['granted'], (int)$cascades)) {
330  return FALSE;
331  }
332  }
333  }
334 
335  if (isset($_POST[$prefix.'_metadata']['manual_cascade']) && $_POST[$prefix.'_metadata']['manual_cascade']) {
336  $schemas = $mm->getAssetSchemaInfo($owner->id, NULL, TRUE);
337  foreach ($schemas as $schemaid => $schema_info) {
338  $schema_vars[] = Array(
339  'assetids' => Array($owner->id),
340  'granted' => $schema_info['granted'],
341  'cascades' => TRUE,
342  'schemaid' => $schemaid,
343  'previous_access' => NULL,
344  );
345  }
346  }
347 
348 
349  if (!empty($schema_vars)) {
350  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
351  $vars = Array('schema_changes' => $schema_vars);
352  $hh->queueHipo('hipo_job_edit_metadata_schemas', $vars);
353  }
354 
355  return TRUE;
356 
357 }//end processMetadataSchemas()
358 
359 
360 ?>