Skip to content

Commit

Permalink
Allowed to upload multiple files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Nov 8, 2014
1 parent 231bae8 commit 00503bf
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 45 deletions.
7 changes: 7 additions & 0 deletions ContributionPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function hookInstall()
`item_type_id` INT UNSIGNED NOT NULL,
`display_name` VARCHAR(255) NOT NULL,
`file_permissions` ENUM('Disallowed', 'Allowed', 'Required') NOT NULL DEFAULT 'Disallowed',
`multiple_files` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `item_type_id` (`item_type_id`)
) ENGINE=MyISAM;";
Expand Down Expand Up @@ -213,6 +214,12 @@ public function hookUpgrade($args)

$this->_db->query($sql);
}

if (version_compare($oldVersion, '3.1', '<')) {
$db = $this->_db;
$sql = "ALTER TABLE `$db->ContributionType` ADD COLUMN `multiple_files` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0'";
$db->query($sql);
}
}

public function hookUninstallMessage()
Expand Down
16 changes: 10 additions & 6 deletions controllers/ContributionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function _setupContributeSubmit($typeId)

/**
* Creates the reCAPTCHA object and returns it.
*
*
* @return Zend_Captcha_Recaptcha|null
*/
protected function _setupCaptcha()
Expand Down Expand Up @@ -235,7 +235,7 @@ protected function _processForm($post)
$itemMetadata['collection_id'] = (int) $collectionId;
}

$fileMetadata = $this->_processFileUpload($contributionType);
$fileMetadata = $this->_processFilesUpload($contributionType);

// This is a hack to allow the file upload job to succeed
// even with the synchronous job dispatcher.
Expand Down Expand Up @@ -301,10 +301,14 @@ protected function _processUserProfile($post, $user)
/**
* Deals with files specified on the contribution form.
*
* @todo Check if multiple files are allowed.
* @todo Error when option is required and when multiple files are allowed: an empty contributed_file input generate an error.
*
* @param ContributionType $contributionType Type of contribution.
* @return array File upload array.
* @return array Files upload array.
*/
protected function _processFileUpload($contributionType) {
protected function _processFilesUpload($contributionType)
{
if ($contributionType->isFileAllowed()) {
$options = array();
if ($contributionType->isFileRequired()) {
Expand Down Expand Up @@ -377,13 +381,13 @@ protected function _addElementTextsToItem($item, $elements)
*/
protected function _validateContribution($post)
{

// ReCaptcha ignores the first argument.
if ($this->_captcha and !$this->_captcha->isValid(null, $_POST)) {
$this->_helper->flashMessenger(__('Your CAPTCHA submission was invalid, please try again.'), 'error');
return false;
}

if ($post['terms-agree'] == 0) {
$this->_helper->flashMessenger(__('You must agree to the Terms and Conditions.'), 'error');
return false;
Expand Down
17 changes: 10 additions & 7 deletions models/ContributionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ class ContributionType extends Omeka_Record_AbstractRecord
public $item_type_id;
public $display_name;
public $file_permissions = 'Disallowed';

protected $_related = array('ContributionTypeElements' => 'getTypeElements',
'ItemType' => 'getItemType');
public $multiple_files;

protected $_related = array(
'ContributionTypeElements' => 'getTypeElements',
'ItemType' => 'getItemType',
);

protected function filterPostData($post)
{
Expand All @@ -34,7 +37,7 @@ protected function filterPostData($post)
}
return $post;
}

protected function _validate()
{
if(empty($this->item_type_id)) {
Expand All @@ -47,7 +50,7 @@ protected function _initializeMixins()
$this->_mixins[] = new Mixin_ContributionOrder($this,
'ContributionTypeElement', 'type_id', 'Elements');
}

/**
* Get the type elements associated with this type.
*
Expand All @@ -57,7 +60,7 @@ public function getTypeElements()
{
return $this->_db->getTable('ContributionTypeElement')->findByType($this);
}

/**
* Get the item type associated with this type.
*
Expand Down Expand Up @@ -173,7 +176,7 @@ public function getPossibleTypeElements()
}
return $options;
}

public function getRecordUrl($action = 'show')
{
return url("contribution/types/$action/id/{$this->id}");
Expand Down
24 changes: 12 additions & 12 deletions plugin.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[info]
name="Contribution"
author="Roy Rosenzweig Center for History & New Media"
description="Allows collecting items from visitors"
link="http://omeka.org/codex/Plugins/Contribution"
support_link="http://omeka.org/forums/forum/plugins"
omeka_minimum_version="2.2.2"
omeka_target_version="2.2.2"
version="3.0.1"
tags="social, items"
license="GPLv3"
required_plugins="GuestUser"
optional_plugins="UserProfiles"
name = "Contribution"
author = " Roy Rosenzweig Center for History & New Media"
description = "Allows collecting items from visitors"
link = "http://omeka.org/codex/Plugins/Contribution"
support_link = "http://omeka.org/forums/forum/plugins"
omeka_minimum_version = "2.2.2"
omeka_tested_against = "2.2.2"
version = "3.1"
tags = "social, items"
license = "GPLv3"
required_plugins = "GuestUser"
optional_plugins = "UserProfiles"
28 changes: 19 additions & 9 deletions views/admin/types/form.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
<?php
$itemTypeOptions = get_db()->getTable('ContributionType')->getPossibleItemTypes();
$itemTypeOptions = array('' => 'Select an Item Type') + $itemTypeOptions;
?>
<form method='post'>
<form method='post'>
<section class='seven columns alpha'>
<?php if($action == 'add'): ?>
<div class="field">
Expand Down Expand Up @@ -42,17 +42,27 @@
<?php echo $this->formSelect('file_permissions', __('%s', $contribution_type->file_permissions), array(), ContributionType::getPossibleFilePermissions()); ?>
</div>
</div>
</div>

</div>

<div class="field">
<div class="two columns alpha">
<label><?php echo __("Allow Multiple File Upload"); ?></label>
</div>
<div class="inputs five columns omega">
<p class="explanation"><?php echo __("Allow to upload multiple files for one item."); ?></p>
<div class="input-block">
<?php echo $this->formCheckbox("multiple_files", null, array('checked' => $contribution_type->multiple_files)); ?>
</div>
</div>
</div>


<div id="element-list" class="seven columns alpha">
<ul id="contribution-type-elements" class="sortable">
<?php
foreach ($contributionTypeElements as $contributionElement):
if ($contributionElement):
?>

<li class="element">
<div class="sortable-item">
<strong><?php echo html_escape($contributionElement->Element->name); ?></strong><span class='prompt'><?php echo __('Prompt'); ?></span>
Expand All @@ -65,7 +75,7 @@
<a id="remove-element-link-<?php echo html_escape($contributionElement->id); ?>" href="" class="delete-element"><?php echo __('Remove'); ?></a>
<?php endif; ?>
</div>

<div class="drawer-contents">
<div class="element-description"><?php echo html_escape($contributionElement->Element->description); ?></div>
</div>
Expand Down Expand Up @@ -96,7 +106,7 @@
?>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; // end for each $elementInfos ?>
<?php endforeach; // end for each $elementInfos ?>
<li>
<div class="add-new">
<?php echo __('Add Element'); ?>
Expand All @@ -112,7 +122,7 @@

<section class='three columns omega'>
<div id='save' class='panel'>

<input type="submit" class="big green button" value="<?php echo __('Save Changes');?>" id="submit" name="submit">
<?php if($contribution_type->exists()): ?>
<?php echo link_to($contribution_type, 'delete-confirm', __('Delete'), array('class' => 'big red button delete-confirm')); ?>
Expand Down
19 changes: 15 additions & 4 deletions views/public/contribution/contribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* @package Contribution
*/

queue_js_file('contribution-public-form');
$contributionPath = get_option('contribution_page_path');
if(!$contributionPath) {
$contributionPath = 'contribution';
}
queue_css_file('form');

queue_js_file('contribution-public-form');
//load user profiles js and css if needed
if(get_option('contribution_user_profile_type') && plugin_is_active('UserProfiles') ) {
queue_js_file('admin-globals');
Expand All @@ -32,14 +32,14 @@

<div id="primary">
<?php echo flash(); ?>

<h1><?php echo $head['title']; ?></h1>

<?php if(!get_option('contribution_simple') && !$user = current_user()) :?>
<?php $session = new Zend_Session_Namespace;
$session->redirect = absolute_url();
?>
<p>You must <a href='<?php echo url('guest-user/user/register'); ?>'>create an account</a> or <a href='<?php echo url('guest-user/user/login'); ?>'>log in</a> before contributing. You can still leave your identity to site visitors anonymous.</p>
<p>You must <a href='<?php echo url('guest-user/user/register'); ?>'>create an account</a> or <a href='<?php echo url('guest-user/user/login'); ?>'>log in</a> before contributing. You can still leave your identity to site visitors anonymous.</p>
<?php else: ?>
<form method="post" action="" enctype="multipart/form-data">
<fieldset id="contribution-item-metadata">
Expand All @@ -51,7 +51,18 @@
<input type="submit" name="submit-type" id="submit-type" value="Select" />
</div>
<div id="contribution-type-form">
<?php if(isset($type)) { include('type-form.php'); }?>
<?php if (isset($type)) {
$partialOptions = array();
$partialOptions['type'] = $type;
$partialOptions['item'] = $item;
if (isset($profileType)) {
$partialOptions['profileType'] = $profileType;
}
if (isset($profile)) {
$partialOptions['profile'] = $profile;
}
echo $this->partial('contribution/type-form.php', $partialOptions);
}?>
</div>
</fieldset>

Expand Down
51 changes: 47 additions & 4 deletions views/public/contribution/type-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,36 @@
<h2><?php echo __('Contribute a %s', $type->display_name); ?></h2>

<?php
$allow_multiple_files = (boolean) $type->multiple_files;

if ($type->isFileRequired()):
$required = true;
?>

<?php if ($allow_multiple_files) : ?>
<script type="text/javascript" charset="utf-8">
jQuery(window).load(function () {
Omeka.Items.enableAddFiles(<?php echo js_escape(__('Add Another File')); ?>);
});
</script>
<div id="files-form" class="field drawer-contents">
<?php echo $this->formLabel('contributed_file', __('Upload a file'), array(
'id' => 'file-inputs',
)); ?>
<div id="files-metadata" class="field">
<div id="upload-files" class="files"><?php /* four columns omega */ ?>
<?php echo $this->formFile('contributed_file[0]', array('class' => 'fileinput button')); ?>
<p><?php echo __('The maximum files size is %s.', max_file_size()); ?></p>
</div>
</div>
</div>
<?php else: ?>
<div class="field">
<?php echo $this->formLabel('contributed_file', __('Upload a file')); ?>
<?php echo $this->formFile('contributed_file', array('class' => 'fileinput')); ?>
<?php echo $this->formLabel('contributed_file', __('Upload a file')); ?>
<?php echo $this->formFile('contributed_file', array('class' => 'fileinput button')); ?>
<p><?php echo __('The maximum file size is %s.', max_file_size()); ?></p>
</div>
<?php endif; ?>

<?php endif; ?>

Expand All @@ -25,12 +47,33 @@
<?php
if (!isset($required) && $type->isFileAllowed()):
?>
<?php if ($allow_multiple_files) : ?>
<script type="text/javascript" charset="utf-8">
jQuery(window).load(function () {
Omeka.Items.enableAddFiles(<?php echo js_escape(__('Add Another File')); ?>);
});
</script>
<div id="files-form" class="field drawer-contents">
<?php echo $this->formLabel('contributed_file', __('Upload a file (Optional)'), array(
'id' => 'file-inputs',
)); ?>
<div id="files-metadata" class="field">
<div id="upload-files" class="files"><?php /* four columns omega */ ?>
<?php echo $this->formFile('contributed_file[0]', array('class' => 'fileinput button')); ?>
<p><?php echo __('The maximum files size is %s.', max_file_size()); ?></p>
</div>
</div>
</div>
<?php else: ?>
<div class="field">
<?php echo $this->formLabel('contributed_file', __('Upload a file (Optional)')); ?>
<?php echo $this->formFile('contributed_file', array('class' => 'fileinput')); ?>
<?php echo $this->formLabel('contributed_file', __('Upload a file (Optional)')); ?>
<?php echo $this->formFile('contributed_file', array('class' => 'fileinput button')); ?>
<p><?php echo __('The maximum file size is %s.', max_file_size()); ?></p>
</div>
<?php endif; ?>

<?php endif; ?>

<?php $user = current_user(); ?>
<?php if(get_option('contribution_simple') && !$user) : ?>
<div class="field">
Expand Down
7 changes: 5 additions & 2 deletions views/public/css/form.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

div#contribution-type-form div.inputs {
width: 60%;

}

div#location_form {
Expand All @@ -24,4 +24,7 @@ p#contribution-userprofile-visibility {

div.contribution-userprofile.exists {
display: none;
}
}
#upload-files input {
display: block;
}
Loading

0 comments on commit 00503bf

Please sign in to comment.