Index: admin_templates/incs/form_blocks.tpl
===================================================================
--- admin_templates/incs/form_blocks.tpl (revision 13862)
+++ admin_templates/incs/form_blocks.tpl (working copy)
@@ -286,9 +286,9 @@
names : '',
sizes : '',
flashsid : '',
- uploadURL : '',
- deleteURL : '',
- tmp_url : '',
+ uploadURL : '',
+ deleteURL : '',
+ tmp_url : '',
// Button settings
buttonImageURL: 'img/upload.png', // Relative to the Flash file
@@ -538,12 +538,12 @@
-
+
Index: admin_templates/js/uploader/upload_manager.js
===================================================================
--- admin_templates/js/uploader/upload_manager.js (revision 13862)
+++ admin_templates/js/uploader/upload_manager.js (working copy)
@@ -23,9 +23,14 @@
}
UploadsManager._initAll = function() {
- this._createHooks();
+ var $hook_set = false;
for (var i in this._Uploaders) {
+ if (!$hook_set) {
+ this._createHooks(i);
+ $hook_set = true;
+ }
+
this._Uploaders[i].init();
}
}
@@ -84,10 +89,17 @@
return null;
}
-UploadsManager._createHooks = function () {
+UploadsManager._createHooks = function ($uploader_id) {
var $me = this;
- $('#' + $form_name).submit(
+ if ($uploader_id !== undefined) {
+ var $form = $('#' + jq($uploader_id)).parents('form:first');
+ }
+ else {
+ var $form = $('#' + $form_name);
+ }
+
+ $form.submit(
function ($e) {
if ($me._hasQueue()) {
submitted = false;
@@ -111,7 +123,7 @@
}
UploadsManager.DeleteFile = function(uploader_id, fname, confirmed) {
- if (!confirmed && !confirm('Are you sure you want to delete "' + fname + '" file?')) {
+ if (!confirmed && !confirm('Are you sure you want to delete "' + fname.replace(/^.*\//, '') + '" file?')) {
return false;
}
@@ -121,6 +133,7 @@
$uploader.deleteURL.replace('#FILE#', encodeURIComponent(fname)).replace('#FIELD#', $uploader.params.field),
false, '',
function(req, fname, $uploader) {
+ $uploader.setDeleted();
$uploader.removeFile({id:fname})
$uploader.deleted.push(fname);
$uploader.updateInfo(undefined, true);
Index: admin_templates/js/uploader/uploader.js
===================================================================
--- admin_templates/js/uploader/uploader.js (revision 13862)
+++ admin_templates/js/uploader/uploader.js (working copy)
@@ -32,6 +32,7 @@
Uploader.prototype._ensureDefaultValues = function() {
// Upload backend settings
var $defaults = {
+ categoryItemVirtual: false,
baseUrl: '',
uploadURL : '',
useQueryString : false,
@@ -81,7 +82,7 @@
var names = '';
for (var f = 0; f < this.files.length; f++) {
- if (isset(this.files[f].uploaded) && !isset(this.files[f].temp)) {
+ if ((this.files[f].uploaded !== undefined) && (this.files[f].temp === undefined)) {
continue;
}
@@ -175,6 +176,8 @@
}
)
+ // this.renderBrowseButton();
+
if (this.params.urls != '') {
var urls = this.params.urls.split('|');
var names = this.params.names.split('|');
@@ -263,10 +266,10 @@
Uploader.prototype.getQueueElement = function($file) {
var $ret = '';
var $icon_image = this.getFileIcon($file.name);
- var $file_label = $file.name + ' (' + this._formatSize($file.size) + ')';
+ var $file_label = $file.name.replace(/^.*\//, '') + ' (' + this._formatSize($file.size) + ')';
var $need_preview = false;
- if (isset($file.uploaded)) {
+ if ($file.uploaded !== undefined) {
// add deletion checkbox
$need_preview = (this.params.thumb_format.length > 0) && this.isImage($file.name);
$ret += '
';
@@ -383,6 +386,33 @@
$('#' + this.files[$file_index].id + '_progress').html($progress_code);
}
+Uploader.prototype.setDeleted = function ($deleted) {
+ if ( parseInt(this.params.multiple) != 1 || !this.params.categoryItemVirtual ) {
+ return ;
+ }
+
+ if ($deleted === undefined) {
+ $deleted = true;
+ }
+
+ // set Delete checkbox to delete record from Images table
+ var $hidden_id = this.id.replace(this.params.field, 'Delete' + this.params.field);
+ $('#' + jq($hidden_id)).val($deleted ? 1 : 0);
+
+ // set anything to the field, so Images table record will be deleted
+ var $field = $('#' + jq(this.id + '[upload]'));
+ var $field_value = $field.val();
+
+ if ($deleted) {
+ $field_value += '|to_delete.jpg';
+ }
+ else {
+ $field_value = $field_value.replace('|to_delete.jpg', '');
+ }
+
+ $field.val($field_value);
+}
+
Uploader.prototype.removeFile = function (file) {
var count = 0;
var n_files = new Array();
@@ -410,7 +440,7 @@
Uploader.prototype.hasQueue = function() {
for (var f = 0; f < this.files.length; f++) {
- if (isset(this.files[f].uploaded)) {
+ if (this.files[f].uploaded !== undefined) {
continue;
}
@@ -485,6 +515,8 @@
this.files[$file_index].temp = 1;
this.files[$file_index].url = this.params.tmp_url.replace('#ID#', file.id).replace('#FILE#', encodeURIComponent(file.name)).replace('#FIELD#', this.params.field);
this.updateInfo($file_index);
+
+ this.setDeleted(false);
}
// upload next file in queue
Index: kernel/db/cat_event_handler.php
===================================================================
--- kernel/db/cat_event_handler.php (revision 13862)
+++ kernel/db/cat_event_handler.php (working copy)
@@ -33,6 +33,7 @@
'OnCancelAction' => Array ('self' => true),
'OnItemBuild' => Array ('self' => true),
'OnMakeVote' => Array ('self' => true),
+ 'OnProcessSelected' => Array('self' => true), // to enable front-end uploads
);
$this->permMapping = array_merge($this->permMapping, $permissions);
@@ -989,6 +990,8 @@
$this->processAdditionalCategories($object, 'update');
}
}
+
+ parent::OnAfterItemUpdate($event);
}
/**
@@ -1023,6 +1026,8 @@
$this->processAdditionalCategories($object, 'create');
}
}
+
+ parent::OnAfterItemCreate($event);
}
/**
Index: kernel/db/db_event_handler.php
===================================================================
--- kernel/db/db_event_handler.php (revision 13862)
+++ kernel/db/db_event_handler.php (working copy)
@@ -1602,15 +1602,7 @@
return ;
}
- // Deleteing files scheduled for delete
- $var_name = $event->getPrefixSpecial().'_file_pending_actions'.$this->Application->GetVar('m_wid');
- $schedule = $this->Application->RecallVar($var_name);
- $schedule = $schedule ? unserialize($schedule) : array();
- foreach ($schedule as $data) {
- if ($data['action'] == 'delete') {
- unlink($data['file']);
- }
- }
+ $this->applyFilePendingActions($event);
if ($live_ids) {
// ensure, that newly created item ids are avalable as if they were selected from grid
@@ -1637,6 +1629,29 @@
}
}
+ /**
+ * Deleteing files scheduled for delete
+ *
+ * @param kEvent $event
+ * @param bool $delete_queue
+ */
+ function applyFilePendingActions(&$event, $delete_queue = false)
+ {
+ $var_name = $event->getPrefixSpecial().'_file_pending_actions'.$this->Application->GetVar('m_wid');
+ $schedule = $this->Application->RecallVar($var_name);
+ $schedule = $schedule ? unserialize($schedule) : array();
+
+ foreach ($schedule as $data) {
+ if ($data['action'] == 'delete' && file_exists($data['file'])) {
+ unlink($data['file']);
+ }
+ }
+
+ if ($delete_queue) {
+ $this->Application->RemoveVar($var_name);
+ }
+ }
+
function SaveLoggedChanges($changes_var_name, $save = true)
{
// 1. get changes, that were made
@@ -2097,7 +2112,12 @@
*/
function OnAfterItemCreate(&$event)
{
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+ if ( !$object->IsTempTable() ) {
+ $this->applyFilePendingActions($event, true);
+ }
}
/**
@@ -2119,7 +2139,12 @@
*/
function OnAfterItemUpdate(&$event)
{
+ $object =& $event->getObject();
+ /* @var $object kDBItem */
+ if ( !$object->IsTempTable() ) {
+ $this->applyFilePendingActions($event, true);
+ }
}
/**
@@ -2733,18 +2758,23 @@
function OnDeleteFile(&$event)
{
$event->status = erSTOP;
+ $filename = $this->Application->GetVar('file');
- if (strpos($this->Application->GetVar('file'), '../') !== false) {
+ if (strpos($filename, '../') !== false) {
return ;
}
$object =& $event->getObject( Array ('skip_autoload' => true) );
- $options = $object->GetFieldOptions( $this->Application->GetVar('field') );
+ /* @var $object kDBItem */
$var_name = $event->getPrefixSpecial() . '_file_pending_actions' . $this->Application->GetVar('m_wid');
$schedule = $this->Application->RecallVar($var_name);
$schedule = $schedule ? unserialize($schedule) : Array ();
- $schedule[] = Array ('action' => 'delete', 'file' => $path = FULL_PATH . $options['upload_dir'] . $this->Application->GetVar('file'));
+
+ $field = $this->Application->GetVar('field');
+ $object->SetDBField($field, $filename);
+ $schedule[] = Array ('action' => 'delete', 'file' => $object->GetField($field, 'full_path'));
+
$this->Application->StoreVar($var_name, serialize($schedule));
}
Index: kernel/utility/formatters/upload_formatter.php
===================================================================
--- kernel/utility/formatters/upload_formatter.php (revision 13862)
+++ kernel/utility/formatters/upload_formatter.php (working copy)
@@ -251,15 +251,15 @@
$options = $object->GetFieldOptions($field_name);
$upload_dir = isset($options['upload_dir']) ? $options['upload_dir'] : $this->DestinationPath;
+ if (array_key_exists('include_path', $options) && $options['include_path']) {
+ // relative path is already included in field
+ $upload_dir = '';
+ }
+
if (preg_match('/resize:([\d]*)x([\d]*)/', $format, $regs)) {
$image_helper =& $this->Application->recallObject('ImageHelper');
/* @var $image_helper ImageHelper */
- if (array_key_exists('include_path', $options) && $options['include_path']) {
- // relative path is already included in field
- $upload_dir = '';
- }
-
return $image_helper->ResizeImage($value ? FULL_PATH . str_replace('/', DIRECTORY_SEPARATOR, $upload_dir) . $value : '', $format);
}
@@ -272,7 +272,8 @@
$url_params = Array (
'no_amp' => 1, 'pass' => 'm,'.$object->Prefix,
$object->Prefix . '_event' => 'OnViewFile',
- 'file' => rawurlencode($value), 'field' => $field_name
+ 'file' => rawurlencode($value), 'field' => $field_name,
+ '__NO_REWRITE__' => 1,
);
return $this->Application->HREF('', '', $url_params);
Index: units/helpers/file_helper.php
===================================================================
--- units/helpers/file_helper.php (revision 13862)
+++ units/helpers/file_helper.php (working copy)
@@ -155,12 +155,27 @@
);
if ($is_image) {
+ // for flash uploader
+ $field_options['max_size'] = MAX_UPLOAD_SIZE;
+ $field_options['file_types'] = '*.jpg;*.gif;*.png;*.bmp';
+ $field_options['files_description'] = '!lu_hint_ImageFiles!';
+ $field_options['multiple'] = false;
+ $field_options['thumb_format'] = 'resize:100x100';
+
+ // for regular uploader
$field_options['formatter'] = 'kPictureFormatter';
$field_options['include_path'] = 1;
$field_options['allowed_types'] = Array ('image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif', 'image/bmp');
$field_prefix = 'Image';
}
else {
+ // for flash uploader
+ $field_options['max_size'] = MAX_UPLOAD_SIZE;
+ $field_options['file_types'] = '*.pdf;*.xls;*.doc;*.ppt';
+ $field_options['files_description'] = '!lu_hint_DocumentFiles!';
+ $field_options['multiple'] = false;
+
+ // for regular uploader
$field_options['formatter'] = 'kUploadFormatter';
$field_options['upload_dir'] = ITEM_FILES_PATH;
$field_options['allowed_types'] = Array ('application/pdf', 'application/msexcel', 'application/msword', 'application/mspowerpoint');
Index: units/users/users_event_handler.php
===================================================================
--- units/users/users_event_handler.php (revision 13862)
+++ units/users/users_event_handler.php (working copy)
@@ -42,6 +42,7 @@
'OnRecommend' => Array('self' => true),
'OnItemBuild' => Array('self' => true),
+ 'OnProcessSelected' => Array('self' => true), // to enable front-end uploads
'OnMassResetSettings' => Array('self' => 'edit'),
'OnMassCloneUsers' => Array('self' => 'add'),
);
@@ -297,6 +298,7 @@
function OnAfterItemCreate(&$event)
{
$this->saveUserImages($event);
+ parent::OnAfterItemCreate($event);
if ($this->Application->GetVar('skip_set_primary')) return;
$is_subscriber = $this->Application->GetVar('IsSubscriber');
@@ -1263,6 +1265,7 @@
function OnAfterItemUpdate(&$event)
{
$this->saveUserImages($event);
+ parent::OnAfterItemUpdate($event);
$object =& $event->getObject();
/* @var $object UsersItem */