Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
asset_manager_edit_fns.inc
1 <?php
17 require_once SQ_LIB_PATH.'/html_form/html_form.inc';
18 
30 {
31 
36  var $am;
37 
42  var $backend;
43 
44 
51  function Asset_Manager_Edit_Fns(&$am, &$backend)
52  {
53  $this->MySource_Object();
54  $this->am = $am;
55  $this->backend = $backend;
56 
57  }//end constructor
58 
59 
66  function paintBackend()
67  {
68  $o = $this->backend->out;
69 
70  if (!isset($_REQUEST['am_section'])) {
71  if (isset($_GET['sq_from_frontend'])) {
72  $_REQUEST['am_section'] = 'edit_asset';
73  } else if (SQ_IN_LIMBO) {
74  $_REQUEST['am_section'] = 'limbo';
75  } else {
76  $_REQUEST['am_section'] = '';
77  }
78  }
79 
80  $o->addFormActionGetVar('am_section', $_REQUEST['am_section']);
81  $o->addHiddenField('am_form_submitted', '1');
82 
83  switch ($_REQUEST['am_section']) {
84 
85  case 'add_asset' :
86 
87  $parent = $this->am->getAsset($_REQUEST['parent_assetid']);
88  if (is_null($parent)) {
89  trigger_localised_error('SYS0200', E_USER_WARNING, $_REQUEST['parent_assetid']);
90  break;
91  }
92 
93  // make sure that we are allowed to link this type to the parent
94  if (($err_msg = $GLOBALS['SQ_SYSTEM']->am->canLinkToType($parent, $_REQUEST['type_code'], $_REQUEST['link_type'])) !== TRUE) {
95  trigger_localised_error('SYS0303', E_USER_WARNING, $err_msg);
96  break;
97  }
98 
99  $o->addFormActionGetVar('parent_assetid', $_REQUEST['parent_assetid']);
100  $o->addFormActionGetVar('pos', $_REQUEST['pos']);
101  $o->addFormActionGetVar('type_code', $_REQUEST['type_code']);
102  $o->addFormActionGetVar('link_type', $_REQUEST['link_type']);
103 
104  $this->am->includeAsset($_REQUEST['type_code']);
105  $asset = new $_REQUEST['type_code']();
106 
107  // if the form has been submitted then, process it
108  if (!empty($_REQUEST['process_form']) && !empty($_REQUEST['am_form_submitted'])) {
109 
110  // start the transaction to create the asset and initial link
111  $link = Array(
112  'asset' => &$parent,
113  'link_type' => $_REQUEST['link_type'],
114  'value' => '',
115  'sort_order' => $_REQUEST['pos'],
116  );
117 
118  $GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
119  $GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
120  $success = $asset->processBackend($this->backend->out, $link);
121 
122  if ($success) {
123  $o->addFormActionGetVar('am_section', 'edit_asset');
124  $o->addFormActionGetVar('assetid', $asset->id);
125  $GLOBALS['SQ_SYSTEM']->doTransaction('COMMIT');
126  } else {
127  // the asset was not created fully or linking failed
128  $GLOBALS['SQ_SYSTEM']->doTransaction('ROLLBACK');
129  }
130 
131  $GLOBALS['SQ_SYSTEM']->restoreDatabaseConnection();
132  }
133 
134  $asset->paintBackend($this->backend->out);
135 
136  break;
137 
138  case 'edit_asset' :
139  case 'limbo' :
140 
141  $asset = $this->am->getAsset($_REQUEST['assetid']);
142  if (is_null($asset)) {
143  trigger_localised_error('SYS0195', E_USER_WARNING, $_REQUEST['assetid']);
144  return;
145  }
146  if (SQ_IN_LIMBO) {
147  $limbo_asset = $this->am->getAsset($_REQUEST['limbo_assetid']);
148  // if the limbo asset is invalid, just use the current asset
149  if (is_null($limbo_asset)) $limbo_asset = $asset;
150  $o->addFormActionGetVar('limbo_assetid', $limbo_asset->id, TRUE);
151  }
152 
153  $o->addFormActionGetVar('assetid', $asset->id);
154  $o->addHiddenField('backend_assetid', $asset->id);
155 
156  // if the form has been submitted then, process it
157  $link = Array();
158  if (!empty($_POST['process_form']) && !empty($_POST['am_form_submitted'])) {
159 
160  $do_process_backend = TRUE;
161 
162  // try to acquire a lock on this asset?
163  if (!empty($_POST['sq_lock_acquire']) && !empty($_POST['sq_lock_type'])) {
164  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
165  $vars = Array(
166  'assetids' => Array($asset->id,),
167  'lock_type' => $_POST['sq_lock_type'],
168  'forceably_acquire' => (bool) $_POST['sq_lock_acquire_by_force'],
169  );
170  $hh->queueHipo('hipo_job_acquire_locks', $vars);
171  $do_process_backend = FALSE;
172  }
173 
174  // try to release a lock on this asset?
175  if (!empty($_POST['sq_lock_release_manual']) && !empty($_POST['sq_lock_type'])) {
176  $this->am->releaseLock($asset->id, $_POST['sq_lock_type']);
177 
178  // limbo might require more locks so release them
179  if (SQ_IN_LIMBO && !empty($_POST['sq_limbo_lock_type'])) {
180  foreach (unserialize(urldecode($_POST['sq_limbo_lock_type'])) as $limbo_lock_type) {
181  if ($limbo_lock_type != $_POST['sq_lock_type']) {
182  $this->am->releaseLock($asset->id, $limbo_lock_type);
183  }
184  }
185  }
186  $do_process_backend = FALSE;
187  }
188 
189  //Bug #5143: Commiting from "approved to go live" causes some attributes on some assets to be cleared.
190  //To safeguard against this, there is no point of having locks if we are Archived/Safe Edit Approved as write access will be blocked.
191  if ($do_process_backend && !$asset->accessEffective()){
192  if (!$this->am->releaseLock($asset->id, 'attributes')) {
193  trigger_localised_error('SYS0182', E_USER_WARNING, 'attributes', $asset->name);
194  $do_process_backend = FALSE;
195  }
196  }
197 
198  if ($do_process_backend && $asset->processBackend($this->backend->out, $link)) {
199 
200  if (!empty($_POST['sq_lock_release']) && !empty($_POST['sq_lock_type'])) {
201  // committing changes and releasing the lock
202  if (!$this->am->releaseLock($asset->id, $_POST['sq_lock_type'])) {
203  trigger_localised_error('SYS0182', E_USER_WARNING, $_POST['sq_lock_type'], $asset->name);
204  }
205  } else {
206  // not releasing the lock, so re-acquire
207  if (!$this->am->updateLock($asset->id, $_POST['sq_lock_type'])) {
208  trigger_localised_error('SYS0181', E_USER_WARNING, $_POST['sq_lock_type'], $asset->name);
209  }
210  }
211  }//end if
212 
213  // the backend of the asset has been processed so lets see if we have any HIPO
214  // jobs that need to be run
215  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
216  $url = $hh->runQueuedJobs();
217  if (!empty($url)) $o->setRedirect($url);
218  }//end if process form and form submission
219 
220  if (SQ_IN_LIMBO) {
221  $limbo_asset->initLimbo();
222  $limbo_asset->printFrontend();
223  } else {
224  $asset->paintBackend($this->backend->out);
225  }
226 
227  break;
228 
229  case 'forceably_acquire_lock' :
230  $this->_forceablyAcquireLock();
231  break;
232 
233  default :
234  $this->_printAssetTypeList();
235 
236  }//end switch
237 
238  }//end paintBackend()
239 
240 
248  {
249  $o = $this->backend->out;
250 
251  if (isset($_GET['forceably_acquire_confirm'])) {
252  // they have confirmed their intention to forceably acquire the lock on this asset
253  $asset = $this->am->getAsset($_GET['assetid']);
254  if (is_null($asset)) {
255  trigger_localised_error('SYS0086', E_USER_WARNING, $_GET['assetid']);
256  return;
257  }
258 
259  // check that they entered the correct security key
260  if (!validate_security_key()) {
261  // the security key entered is wrong
262  $o->openSection(translate('security_key_incorrect'));
263  $o->openField('&nbsp;');
264  echo '<b><i>'.translate('security_key_incorrect_message', $asset->name).'</i></b>';
265  $o->closeSection();
266  } else {
267  $o->addOnLoad('window.opener.parent.frames["sq_main"].set_hidden_field(\'sq_lock_acquire_by_force\', \'1\'); window.opener.parent.frames["sq_main"].set_hidden_field(\'sq_lock_acquire\', \'1\'); window.opener.parent.frames["sq_main"].set_hidden_field(\'sq_lock_type\', \''.addslashes($_GET['sq_lock_type']).'\'); window.opener.parent.frames["sq_main"].submit_form(); window.close();');
268  return;
269  }
270  }
271 
272  $o->addFormActionGetVar('assetid', $_GET['assetid']);
273  $o->addFormActionGetVar('sq_lock_type', $_GET['sq_lock_type']);
274  $o->addFormActionGetVar('forceably_acquire_confirm', '1');
275  $o->addFormActionGetVar('ignore_frames', '1');
276  $asset = $this->am->getAsset($_GET['assetid']);
277  if (is_null($asset)) {
278  trigger_localised_error('SYS0086', E_USER_WARNING, $_GET['assetid']);
279  return;
280  }
281 
282  $locks = $this->am->getLockInfo($asset->id, $_GET['sq_lock_type'], TRUE, TRUE);
283  $got_locks = FALSE;
284  foreach ($locks as $lock_type => $lock) {
285  if (!empty($lock)) {
286  $got_locks = TRUE;
287  break;
288  }
289  }
290  if (!$got_locks) {
291  $o->addOnLoad('alert(js_translate("no_lock_held", "'.addslashes($asset->name).'")); window.close();');
292  return;
293  }
294 
295  $o->openSection(translate('forcibly_acquire'));
296  $o->openField('');
297  $o->note(translate('forcibly_acquire_lock_can_cause_losses', htmlspecialchars($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET), htmlspecialchars($asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET)));
298  $o->openField('');
299  ?>
300  <table border="0">
301  <tr>
302  <td>
303  <?php echo translate('enter_eight_character_security_string'); ?>
304  </td>
305  </tr>
306  <tr>
307  <td valign="top"><?php security_key(8, 20, 2.5); ?></td>
308  </tr>
309  </table>
310  <table class="sq-backend-table" style="width: auto;">
311  <tr>
312  <td class="sq-backend-table-header">
313  <?php echo translate('lock_type'); ?>
314  </td>
315  <td class="sq-backend-table-header">
316  &nbsp;
317  </td>
318  <td class="sq-backend-table-header">
319  <?php echo translate('other_assets_in_chain'); ?>
320  </td>
321  </tr>
322  <?php
323 
324  foreach ($locks as $lock_type => $lock) {
325  if (empty($lock)) continue;
326  // if this lock is held the current user, we aren't really forcing this one
327  if ($lock['userid'] == $GLOBALS['SQ_SYSTEM']->currentUserId()) {
328  continue;
329  }
330  ?>
331  <tr>
332  <td class="sq-backend-table-cell">
333  <?php echo ucwords(str_replace('_', ' ', $lock_type)); ?>
334  </td>
335  <td class="sq-backend-table-cell">
336  <?php
337 
338  // this asset is currently locked
339  // so display message to the user
340  $user = $GLOBALS['SQ_SYSTEM']->am->getAsset($lock['userid']);
341  $editing = $GLOBALS['SQ_SYSTEM']->am->getAsset($lock['source_assetid']);
342 
343  if (SQ_ROLLBACK_VIEW) {
344  $now = strtotime($_SESSION['sq_rollback_view']['rollback_time']);
345  } else {
346  $now = time();
347  }
348 
349  if (is_null($lock['expires'])) {
350  $expires_in = translate('lock_held_indefinitely');
351  } else {
352  require_once SQ_FUDGE_PATH.'/general/datetime.inc';
353  $expires_in = easy_time_total(($lock['expires'] - $now), TRUE);
354  if (!$expires_in) {
355  $expires_in = '1 '.translate('second');
356  }
357  $expires_in = translate('due_to_expire', $expires_in);
358  }
359 
360  ?>
361  <p class="sq-backend-locked-by-someone-else">
362  Held by user "<?php echo htmlspecialchars($user->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET); ?>" at "<?php echo htmlspecialchars($editing->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET); ?>".<br>
363  <?php echo $expires_in; ?>
364  </p>
365  </td>
366  <td class="sq-backend-table-cell">
367  <?php
368  if (empty($lock['chained_assets'])) {
369  echo '<i>No other assets are in this lock chain.</i>';
370  } else {
371  echo '<ul>';
372  foreach ($lock['chained_assets'] as $chained_info) {
373  $chained_asset = $this->am->getAsset($chained_info['assetid']);
374  if (is_null($chained_asset)) {
375  trigger_localised_error('SYS0086', E_USER_WARNING, $chained_info['assetid']);
376  continue;
377  }
378  echo '<li class="sq-backend-data">'.htmlspecialchars($chained_asset->name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET).'</li>';
379  }//end foreach
380  echo '</ul>';
381  }//end if
382  ?>
383  </td>
384  </tr>
385  <?php
386  }//end foreach lock types
387  ?>
388 
389  </table>
390  <?php
391  $o->closeSection();
392 
393  $o->openField('', 'commit');
394  normal_button('cancel', translate('cancel'), 'window.close()');
395  echo '&nbsp;';
396  submit_button('commit', SQ_CONF_COMMIT_BUTTON_TEXT);
397 
398  }//end _forceablyAcquireLock()
399 
400 
408  {
409  $o = $this->backend->out;
410 
411  $o->setHeading('Asset Types', sq_get_icon($o->filesPath('/images/icons/header/asset_tree.png'), 20, 20, 'Asset Tree'));
412  $o->setPageTitle('Asset Types');
413 
414  $o->addHiddenField('am_action');
415  $o->addHiddenField('am_new_type_code');
416 
417  $o->openSection(translate('asset_types'));
418  $o->openField('', 'new_line');
419 
420 
421  $offspring = Array();
422  for (reset($this->am->_asset_types); NULL !== ($type_code = key($this->am->_asset_types)); next($this->am->_asset_types)) {
423  $parent = $this->am->_asset_types[$type_code]['parent_type'];
424  if (!isset($offspring[$parent])) {
425  $offspring[$parent] = Array();
426  }
427  $offspring[$parent][] = $type_code;
428  }//end for
429 
430  for (reset($offspring); NULL !== ($type_code = key($offspring)); next($offspring)) {
431  sort($offspring[$type_code]);
432  }
433 
434  ?>
435  <table cellpadding="0" cellspacing="0" border="0">
436  <tr>
437  <td><img src="<?php echo $o->filesPath('/images/blank.gif'); ?>" width="1" height="20" border="0" alt="branch" /></td>
438  <td>
439  &nbsp;Asset
440  </td>
441  </tr>
442  <tr>
443  <td><img src="<?php echo $o->filesPath('/images/blank.gif'); ?>" width="1" height="1" alt="blank" /></td>
444  <td>
445  <?php
446  $this->_recursePrintAssetList($offspring, 'asset');
447  ?>
448  </td>
449  </tr>
450  <tr>
451  <td><img src="<?php echo $o->filesPath('/images/blank.gif'); ?>" width="1" height="1" alt="blank" /></td>
452  </tr>
453  </table>
454  <?php
455  $o->closeSection();
456 
457  }//end _printAssetTypeList()
458 
459 
469  function _recursePrintAssetList(&$offspring, $parent)
470  {
471  $o = $this->backend->out;
472 
473  ?>
474  <table cellpadding="0" cellspacing="0" border="0">
475  <?php
476  $num_kids = count($offspring[$parent]);
477  for ($i = 0; $i < $num_kids; $i++) {
478 
479  $type_code = $offspring[$parent][$i];
480  $end = ($i == $num_kids - 1);
481  $bg = ($end) ? '' : 'background="'.$o->filesPath('/images/tree/stalk.gif').'"';
482  ?>
483  <tr>
484  <td <?php echo $bg; ?>><img src="<?php echo $o->filesPath('/images/tree/branch.gif');?>" width="20" height="20" border="0" alt="branch" /></td>
485  <td>
486  <?php sq_print_icon($this->am->getAssetIconURL($type_code), "16", "16", ""); ?>&nbsp;&nbsp;<?php echo $this->am->_asset_types[$type_code]['name'].' ('.$type_code.')';?>
487  </td>
488  </tr>
489  <?php
490  if (!empty($offspring[$type_code])) {
491  ?>
492  <tr>
493  <td <?php echo $bg; ?>><img src="<?php echo $o->filesPath('/images/blank.gif'); ?>" width="1" height="1" alt="blank" /></td>
494  <td>
495  <?php
496  $this->_recursePrintAssetList($offspring, $type_code);
497  ?>
498  </td>
499  </tr>
500  <?php
501  }//end if
502 
503  }//end for
504  ?>
505  </table>
506  <?php
507 
508  }//end _recursePrintAssetList()
509 
510 
511 }//end class
512 
513 ?>