register_error(elgg_echo('odt_editor:error:file_removed')); } forward(REFERER); } // user must be able to edit file if (!$file->canEdit()) { register_error(elgg_echo('You do no longer have write access to the file that is edited.')); forward(REFERER); } // save folder guid in parameter to make sure file_tools_object_handler does not overwrite the relationship $relationships = get_entity_relationships($file->guid, FILE_TOOLS_RELATIONSHIP, true); if (elgg_is_active_plugin('file_tools') && count($relationships) > 0) { set_input('folder_guid', $relationships[0]->guid_one); } // recreate lock, user closed window but cancelled if ($lock_set && !odt_editor_locking_is_locked($file)) { trigger_error("Restored lock", E_USER_WARNING); odt_editor_locking_create_lock($file, $user_guid, $lock_guid); forward(REFERER); } // check for lost lock if (odt_editor_locking_lock_guid($file) != $lock_guid) { $lock_owner_guid = odt_editor_locking_lock_owner_guid($file); if ($lock_owner_guid != $user_guid) { $locking_user = get_entity($lock_owner_guid); $locking_user_name = $locking_user ? $locking_user->name : elgg_echo("odt_editor:unknown_user"); register_error(elgg_echo('odt_editor:lock_lost_to', array($locking_user_name))); } else { register_error(elgg_echo('odt_editor:lock_lost_to_self')); } forward(REFERER);
$download_url = elgg_get_site_url() . "odt_editor/gettemplate"; $edit_mode = "readwrite"; } else { $file = get_entity($file_guid); // TODO: is there a way to get the original filename when uploaded? $file_name = $file->getFilename(); $user_guid = elgg_get_logged_in_user_guid(); $edit_mode = "readonly"; if ($file->canEdit()) { // save folder guid in parameter to make sure file_tools_object_handler does not overwrite the relationship $relationships = get_entity_relationships($file->guid, FILE_TOOLS_RELATIONSHIP, true); if (elgg_is_active_plugin('file_tools') && count($relationships) > 0) { set_input('folder_guid', $relationships[0]->guid_one); } // currently locked? if (odt_editor_locking_is_locked($file)) { $locking_user = get_entity(odt_editor_locking_lock_owner_guid($file)); $locking_user_name = $locking_user ? $locking_user->name : elgg_echo("odt_editor:unknown_user"); system_message(elgg_echo("odt_editor:document_locked_by", array($locking_user_name))); } else { $lock_guid = odt_editor_locking_create_lock($file, $user_guid); if ($file->save()) { $edit_mode = "readwrite"; } else { register_error(elgg_echo("odt_editor:error:cannotwritelock")); } } } else { system_message(elgg_echo("odt_editor:read_only")); } $title = $file->title;