/** * Automatically called each time the form loads. * * Checks the show_form variable to determine if the deletion page should be shown. * Displays each entity that will be deleted with the site, in the format * <h4>Type</h4> <ul> <li> Entity <a href = "Preview of entity"> Preview </a> </li> </ul> * * Contains javascript to display a confirmation window after delete is submitted. **/ function show_form() { if ($this->show_form) { $site = new entity($this->get_value('id')); $action_word = 'Deleting'; if ('Deleted' == $site->get_value('state')) { $action_word = 'Expunging'; } echo $action_word . " a site will delete all entities it owns. For " . $site->get_value('name') . " this includes:<br>"; $borrowing_array = $this->get_borrowing_list(); foreach ($borrowing_array as $type_id => $entities) { $type_entity = new entity($type_id); $type_name = $type_entity->get_value('plural_name') ? $type_entity->get_value('plural_name') : $type_entity->get_value('name'); $temp_string = "\n<h4>" . $type_name . "</h4>\n<ul>"; foreach (array_keys($entities) as $entity_id) { $link_address = '<a href="?site_id=' . $site->id() . '&type_id=' . $type_id . '&id=' . $entity_id . '&cur_module=Preview" target="_blank">Preview</a> (id: ' . $entity_id . ')'; $entity_object = new entity($entity_id); $entity_name = $entity_object->get_display_name(); $temp_string .= "\n<li>" . $entity_name . " " . $link_address . "</li>"; } $temp_string .= "\n</ul>"; echo $temp_string; } parent::show_form(); echo "<script>"; echo "\n\$(document).ready(function(){"; echo "\n\$('form#disco_form').submit(function(event){"; echo "\nif(window.confirm('" . $action_word . " this site will delete all entities listed. Are you sure you want to proceed?')){"; echo "\n}"; echo "\nelse{"; echo "\nevent.preventDefault();"; echo "\ncancelDisableSubmit();"; echo "\n}"; echo "\n});"; echo "\n});"; /* echo "\ndocument.getElementById('disco_form')[0].onsubmit=function() {return displayWarning(this)}"; echo "\nfunction displayWarning(item)\n{\n\na = window.confirm('Deleting this site will delete all entities listed. Are you sure you want to proceed?')\nif(a!=true)\n{\nreturn false\n}\n}"; */ echo "\n</script>"; } else { echo $this->no_show_form(); } }