Skip to content

Instantly share code, notes, and snippets.

@argnist
Created December 3, 2013 08:37
Show Gist options
  • Save argnist/7765914 to your computer and use it in GitHub Desktop.
Save argnist/7765914 to your computer and use it in GitHub Desktop.
<?php
// change:
/* handle file fields */
foreach ($origFields as $k => $v) {
$attachmentIndex = 0;
if (is_array($v) && !empty($v['tmp_name']) && isset($v['error']) && $v['error'] == UPLOAD_ERR_OK) {
if (empty($v['name'])) {
$v['name'] = 'attachment'.$attachmentIndex;
}
$this->modx->mail->mailer->AddAttachment($v['tmp_name'],$v['name'],'base64',!empty($v['type']) ? $v['type'] : 'application/octet-stream');
$attachmentIndex++;
}
}
// to
/* handle file fields */
$attachmentIndex = 0;
foreach ($origFields as $k => $v) {
if (is_array($v) && !empty($v['tmp_name']) && isset($v['error'])) {
for ($i = 0; $i < count($v['name']); $i++) {
if ($v['error'][$i] == UPLOAD_ERR_OK) {
if (empty($v['name'][$i])) {
$v['name'][$i] = 'attachment'.$attachmentIndex;
}
$this->modx->mail->mailer->AddAttachment($v['tmp_name'][$i],$v['name'][$i],'base64',!empty($v['type'][$i]) ? $v['type'][$i] : 'application/octet-stream');
$attachmentIndex++;
}
}
}
}
/* javascript:
(function() {
$(document).ready(function(){
$('option[data-id=' + location.search.split('=')[1] + ']', '#direction').attr("selected", "selected");
$('#direction').customSelect();
});
$(document).on('change', '.fileupload', function(e, data){
var $this = $(this);
if (!$this.hasClass('choosed')) {
var clon = $('<span class="btn btn-default fileinput-button"><i class="glyphicon glyphicon-paperclip"></i> <span>Прикрепить фотографии</span><input class="fileupload" type="file" name="files[]" multiple></span>');
clon.insertAfter($this.parent());
var files = $(this)[0].files;
var name = $this.val();
var n = files.length;
if (n > 1) {
name = files.length + " файл";
if ((n % 10 >= 2) && (n %10 <= 4) && (n % 100 < 10 || n % 100 >= 20)) {
name += 'а';
} else {
name += 'ов';
}
}
$this.parent().find('span').html(name);
$this.addClass('choosed');
}
});
$('.validateForm').on('submit', function(e){
var v = $(this).validationEngine('validate');
if (!v) {
e.preventDefault();
}
});
}());
*/
/* css:
.fileinput-button {
position: relative;
overflow: hidden;
margin-right: 10px;
}
.fileinput-button input {
position: absolute;
top: 0;
right: 0;
margin: 0;
opacity: 0;
filter: alpha(opacity=0);
transform: translate(-300px, 0) scale(4);
font-size: 23px;
direction: ltr;
cursor: pointer;
}
.fileinput-button > span {
vertical-align: middle;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment