В xfields.php сделал
Мультивыбор работает, но добавляется в базу последние выбранное значения, как занести в базу все выбранные значения select
PHP:
$select = "<select multiple=\"multiple\" style=\"width:350px;height:140px;\" id=\"category\" name=\"xfield[$fieldname]\">";
PHP:
}
} elseif ($value[3] == "select") {
if ($xfieldmode == "site") {
$select = "<select multiple=\"multiple\" style=\"width:350px;height:140px;\" id=\"category\" name=\"xfield[$fieldname]\">";
} else {
$select = "<select class=\"uniform\" name=\"xfield[$fieldname]\">";
}
if ( !isset($fieldvalue) ) $fieldvalue = "";
$fieldvalue = str_replace('&', '&', $fieldvalue);
foreach (explode("\r\n", htmlspecialchars($value[4], ENT_QUOTES, $config['charset'] )) as $index1 => $value1) {
$value1 = explode("|", $value1);
if( count($value1) < 2) $value1[1] = $value1[0];
$select .= "<option value=\"$index1\"" . ($fieldvalue == $value1[0] ? " selected" : "") . ">{$value1[1]}</option>\r\n";
}
$select .= "</select>";
if ($xfieldmode == "site") {
$output .= <<<HTML
<tr id="$holderid">
<td class="addnews">$value[1]:</td>
<td class="xfields" colspan="2">{$select} {$value[18]}</td>
</tr>
HTML;
$xfieldinput[$fieldname] = $select;
} else {
$output .= <<<HTML
<div id="$holderid" class="form-group">
<label class="control-label col-sm-2">{$value[1]}:</label>
<div class="col-sm-10">{$select} {$value[18]}
</div>
</div>
HTML;
}
} elseif( $value[3] == "yesorno" ) {
if ( !isset($fieldvalue) OR $fieldvalue === '') $fieldvalue = $value[17];
$fieldvalue = intval($fieldvalue);
if ($xfieldmode == "site") {
$select = "<select name=\"xfield[$fieldname]\">";
$select .= "<option value=\"1\"" . ($fieldvalue == 1 ? " selected" : "") . ">{$lang['xfield_xyes']}</option>\r\n";
$select .= "<option value=\"0\"" . ($fieldvalue == 0 ? " selected" : "") . ">{$lang['xfield_xno']}</option>\r\n";
$select .= "</select>";
$output .= <<<HTML
<tr id="$holderid">
<td class="addnews">$value[1]:</td>
<td class="xfields" colspan="2">{$select} {$value[18]}</td>
</tr>
HTML;
$xfieldinput[$fieldname] = $select;
} else {
$selected = $fieldvalue ? "checked" : "";
if ($value[18]) $value[18] = "<i class=\"help-button visible-lg-inline-block text-primary-600 fa fa-question-circle position-right position-left\" style=\"position: relative;top: -8px;\" data-rel=\"popover\" data-trigger=\"hover\" data-placement=\"right\" data-content=\"{$help_text}\" ></i>";
$output .= <<<HTML
<div id="$holderid" class="form-group">
<label class="control-label col-sm-2">{$value[1]}:</label>
<div class="col-sm-10"><input class="switch" type="checkbox" name="xfield[$fieldname]" value="1" {$selected}>{$value[18]}
</div>
</div>
HTML;
}
} elseif( $value[3] == "image" ) {
$max_file_size = (int)($value[10] * 1024);
$fieldvalue = str_replace('&', '&', $fieldvalue);
if( $fieldvalue ) {
$path_parts = pathinfo($fieldvalue);
if( $value[12] AND file_exists(ROOT_DIR . "/uploads/posts/" .$path_parts['dirname']."/thumbs/".$path_parts['basename']) ) {
$img_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/thumbs/".$path_parts['basename'];
} else {
$img_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/".$path_parts['basename'];
}
$filename = explode("_", $path_parts['basename']);
unset($filename[0]);
$filename = implode("_", $filename);
$up_image = "<div class=\"uploadedfile\"><div class=\"info\">{$filename}</div><div class=\"uploadimage\"><img style=\"width:auto;height:auto;max-width:100px;max-height:90px;\" src=\"" . $img_url . "\" /></div><div class=\"info\"><a href=\"#\" onclick=\"xfimagedelete(\\'".$fieldname."\\',\\'".$fieldvalue."\\');return false;\">{$lang['xfield_xfid']}</a></div></div>";
} else $up_image = "";
if (!$value[5]) {
$params = "rel=\"essential\" ";
$uid = "uid=\"essential\" ";
} else {
$params = "";
$uid = "";
}
$uploadscript = <<<HTML
new qq.FileUploader({
element: document.getElementById('xfupload_{$fieldname}'),
action: 'engine/ajax/upload.php',
maxConnections: 1,
multiple: false,
allowdrop: false,
encoding: 'multipart',
sizeLimit: {$max_file_size},
allowedExtensions: ['gif', 'jpg', 'jpeg', 'png'],
params: {"PHPSESSID" : "{$sess_id}", "subaction" : "upload", "news_id" : "{$news_id}", "area" : "xfieldsimage", "author" : "{$author}", "xfname" : "{$fieldname}", "user_hash" : "{$dle_login_hash}"},
template: '<div class="qq-uploader">' +
'<div id="uploadedfile_{$fieldname}">{$up_image}</div>' +
'<div class="qq-upload-button btn btn-green bg-teal btn-sm btn-raised" style="width: auto;">{$lang['xfield_xfim']}</div>' +
'<ul class="qq-upload-list" style="display:none;"></ul>' +
'</div>',
onSubmit: function(id, fileName) {
$('<div id="uploadfile-'+id+'" class="file-box"><span class="qq-upload-file-status">{$lang['media_upload_st6']}</span><span class="qq-upload-file"> '+fileName+'</span> <span class="qq-status"><span class="qq-upload-spinner"></span><span class="qq-upload-size"></span></span><div class="progress "><div class="progress-bar progress-blue" style="width: 0%"><span>0%</span></div></div></div>').appendTo('#xfupload_{$fieldname}');
},
onProgress: function(id, fileName, loaded, total){
$('#uploadfile-'+id+' .qq-upload-size').text(DLEformatSize(loaded)+' {$lang['media_upload_st8']} '+DLEformatSize(total));
var proc = Math.round(loaded / total * 100);
$('#uploadfile-'+id+' .progress-bar').css( "width", proc + '%' );
$('#uploadfile-'+id+' .qq-upload-spinner').css( "display", "inline-block");
},
onComplete: function(id, fileName, response){
if ( response.success ) {
var returnbox = response.returnbox;
var returnval = response.xfvalue;
returnbox = returnbox.replace(/</g, "<");
returnbox = returnbox.replace(/>/g, ">");
returnbox = returnbox.replace(/&/g, "&");
$('#uploadfile-'+id+' .qq-status').html('{$lang['media_upload_st9']}');
$('#uploadedfile_{$fieldname}').html( returnbox );
$('#xf_{$fieldname}').val(returnval);
$('#xfupload_{$fieldname} .qq-upload-button, #xfupload_{$fieldname} .qq-upload-button input').attr("disabled","disabled");
setTimeout(function() {
$('#uploadfile-'+id).fadeOut('slow', function() { $(this).remove(); });
}, 1000);
} else {
$('#uploadfile-'+id+' .qq-status').html('{$lang['media_upload_st10']}');
if( response.error ) $('#uploadfile-'+id+' .qq-status').append( '<br /><span class="text-danger">' + response.error + '</span>' );
setTimeout(function() {
$('#uploadfile-'+id).fadeOut('slow');
}, 4000);
}
},
messages: {
typeError: "{$lang['media_upload_st11']}",
sizeError: "{$lang['media_upload_st12']}",
emptyError: "{$lang['media_upload_st13']}"
},
debug: false
});
if($('#xf_{$fieldname}').val() != "" ) {
$('#xfupload_{$fieldname} .qq-upload-button, #xfupload_{$fieldname} .qq-upload-button input').attr("disabled","disabled");
}
HTML;
if ($xfieldmode == "site") {
$onload_scripts[] = <<<HTML
if ($('#xfupload_{$fieldname}').length){
{$uploadscript}
}
HTML;
$output .= <<<HTML
<tr id="$holderid" {$uid}>
<td class="addnews">$value[1]: [not-optional]<span style="color:red;">*</span>[/not-optional]</td>
<td class="xfields" colspan="2"><div id="xfupload_{$fieldname}"></div><input type="hidden" name="xfield[$fieldname]" id="xf_$fieldname" value="{$fieldvalue}" {$params}/>{$value[18]}</td>
</tr>
HTML;
$xfieldinput[$fieldname] = "<div id=\"xfupload_{$fieldname}\"></div><input type=\"hidden\" name=\"xfield[$fieldname]\" id=\"xf_$fieldname\" value=\"{$fieldvalue}\" {$params}/>";
} else {
$output .= <<<HTML
<div id="$holderid" class="form-group" {$uid}>
<label class="control-label col-sm-2">{$value[1]}: [not-optional]<span style="color:red;">*</span>[/not-optional] {$value[18]}</label>
<div class="col-sm-10"><div id="xfupload_{$fieldname}"></div><input type="hidden" name="xfield[$fieldname]" id="xf_$fieldname" value="{$fieldvalue}" {$params}/>
<script type="text/javascript">
jQuery(function($){
{$uploadscript}
});
</script>
</div>
</div>
HTML;
}
} elseif( $value[3] == "imagegalery" ) {
$max_file_size = (int)($value[10] * 1024);
$fieldvalue = str_replace('&', '&', $fieldvalue);
if( $fieldvalue ) {
$fieldvalue_arr = explode(',', $fieldvalue);
$up_image = array();
foreach ($fieldvalue_arr as $temp_value) {
$temp_value = trim($temp_value);
if($temp_value == "") continue;
$path_parts = pathinfo($temp_value);
if( $value[12] AND file_exists(ROOT_DIR . "/uploads/posts/" .$path_parts['dirname']."/thumbs/".$path_parts['basename']) ) {
$img_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/thumbs/".$path_parts['basename'];
} else {
$img_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/".$path_parts['basename'];
}
$filename = explode("_", $path_parts['basename']);
unset($filename[0]);
$filename = implode("_", $filename);
$xf_id = md5($temp_value);
$up_image[] = "<div id=\"xf_{$xf_id}\" class=\"uploadedfile\"><div class=\"info\">{$filename}</div><div class=\"uploadimage\"><img style=\"width:auto;height:auto;max-width:100px;max-height:90px;\" src=\"" . $img_url . "\" /></div><div class=\"info\"><a href=\"#\" onclick=\"xfimagegalerydelete_".md5($fieldname)."(\\'".$fieldname."\\',\\'".$temp_value."\\', \\'".$xf_id."\\');return false;\">{$lang['xfield_xfid']}</a></div></div>";
}
$totaluploadedfiles = count($up_image);
$up_image = implode($up_image);
} else { $up_image = ""; $totaluploadedfiles = 0; }
if (!$value[5]) {
$params = "rel=\"essential\" ";
$uid = "uid=\"essential\" ";
} else {
$params = "";
$uid = "";
}
$del_function = <<<HTML
var maxallowfiles_{$fieldcount} = {$value[16]};
var totaluploaded_{$fieldcount} = {$totaluploadedfiles};
var totalqueue_{$fieldcount} = 0;
function xfimagegalerydelete_{$fieldcount} ( xfname, xfvalue, id )
{
DLEconfirm( '{$lang['image_delete']}', '{$lang['p_info']}', function () {
ShowLoading('');
$.post('engine/ajax/upload.php', { subaction: 'deluploads', user_hash: '{$dle_login_hash}', news_id: '{$news_id}', author: '{$author}', 'images[]' : xfvalue }, function(data){
HideLoading('');
var str = $('#xf_'+xfname).val();
var arr = str.split(',');
if( $.inArray(xfvalue, arr) != -1 ){
arr.splice( $.inArray(xfvalue, arr), 1 );
}
if ( arr.length ) {
$('#xf_'+xfname).val(arr.join(','));
} else {
$('#xf_'+xfname).val('');
}
$('#xf_'+id).remove();
totaluploaded_{$fieldcount} --;
$('#xfupload_' + xfname + ' .qq-upload-button, #xfupload_' + xfname + ' .qq-upload-button input').removeAttr('disabled');
});
} );
return false;
};
HTML;
$uploadscript = <<<HTML
var uploader_{$fieldcount} = new qq.FileUploader({
element: document.getElementById('xfupload_{$fieldname}'),
action: 'engine/ajax/upload.php',
maxConnections: 1,
multiple: true,
allowdrop: false,
encoding: 'multipart',
sizeLimit: {$max_file_size},
allowedExtensions: ['gif', 'jpg', 'jpeg', 'png'],
params: {"PHPSESSID" : "{$sess_id}", "subaction" : "upload", "news_id" : "{$news_id}", "area" : "xfieldsimagegalery", "author" : "{$author}", "xfname" : "{$fieldname}", "user_hash" : "{$dle_login_hash}"},
template: '<div class="qq-uploader">' +
'<div id="uploadedfile_{$fieldname}">{$up_image}</div>' +
'<div class="qq-upload-button btn btn-green bg-teal btn-sm btn-raised" style="width: auto;">{$lang['xfield_xfimg']}</div>' +
'<ul class="qq-upload-list" style="display:none;"></ul>' +
'</div>',
onSubmit: function(id, fileName) {
totalqueue_{$fieldcount} ++;
if(maxallowfiles_{$fieldcount} && (totaluploaded_{$fieldcount} + totalqueue_{$fieldcount} ) > maxallowfiles_{$fieldcount} ) {
totalqueue_{$fieldcount} --;
$('#xfupload_{$fieldname} .qq-upload-button, #xfupload_{$fieldname} .qq-upload-button input').attr("disabled","disabled");
return false;
}
$('<div id="uploadfile-'+id+'" class="file-box"><span class="qq-upload-file-status">{$lang['media_upload_st6']}</span><span class="qq-upload-file"> '+fileName+'</span> <span class="qq-status"><span class="qq-upload-spinner"></span><span class="qq-upload-size"></span></span><div class="progress "><div class="progress-bar progress-blue" style="width: 0%"><span>0%</span></div></div></div>').appendTo('#xfupload_{$fieldname}');
},
onProgress: function(id, fileName, loaded, total){
$('#uploadfile-'+id+' .qq-upload-size').text(DLEformatSize(loaded)+' {$lang['media_upload_st8']} '+DLEformatSize(total));
var proc = Math.round(loaded / total * 100);
$('#uploadfile-'+id+' .progress-bar').css( "width", proc + '%' );
$('#uploadfile-'+id+' .qq-upload-spinner').css( "display", "inline-block");
},
onComplete: function(id, fileName, response){
totalqueue_{$fieldcount} --;
if ( response.success ) {
totaluploaded_{$fieldcount} ++;
var fieldvalue = $('#xf_{$fieldname}').val();
var returnbox = response.returnbox;
var returnval = response.xfvalue;
returnbox = returnbox.replace(/</g, "<");
returnbox = returnbox.replace(/>/g, ">");
returnbox = returnbox.replace(/&/g, "&");
$('#uploadfile-'+id+' .qq-status').html('{$lang['media_upload_st9']}');
$('#uploadedfile_{$fieldname}').append( returnbox );
if (fieldvalue == "") {
$('#xf_{$fieldname}').val(returnval);
} else {
fieldvalue += ',' +returnval;
$('#xf_{$fieldname}').val(fieldvalue);
}
if(maxallowfiles_{$fieldcount} && totaluploaded_{$fieldcount} == maxallowfiles_{$fieldcount} ) {
$('#xfupload_{$fieldname} .qq-upload-button, #xfupload_{$fieldname} .qq-upload-button input').attr("disabled","disabled");
}
setTimeout(function() {
$('#uploadfile-'+id).fadeOut('slow', function() { $(this).remove(); });
}, 1000);
} else {
$('#uploadfile-'+id+' .qq-status').html('{$lang['media_upload_st10']}');
if( response.error ) $('#uploadfile-'+id+' .qq-status').append( '<br /><span class="text-danger">' + response.error + '</span>' );
setTimeout(function() {
$('#uploadfile-'+id).fadeOut('slow');
}, 4000);
}
},
messages: {
typeError: "{$lang['media_upload_st11']}",
sizeError: "{$lang['media_upload_st12']}",
emptyError: "{$lang['media_upload_st13']}"
},
debug: false
});
if(maxallowfiles_{$fieldcount} && totaluploaded_{$fieldcount} >= maxallowfiles_{$fieldcount} ) {
$('#xfupload_{$fieldname} .qq-upload-button, #xfupload_{$fieldname} .qq-upload-button input').attr("disabled","disabled");
}
HTML;
if ($xfieldmode == "site") {
$onload_scripts[] = <<<HTML
if ($('#xfupload_{$fieldname}').length){
{$uploadscript}
}
HTML;
$output .= <<<HTML
<tr id="$holderid" {$uid}>
<td class="addnews">$value[1]: [not-optional]<span style="color:red;">*</span>[/not-optional]</td>
<td class="xfields" colspan="2"><div id="xfupload_{$fieldname}"></div><input type="hidden" name="xfield[$fieldname]" id="xf_$fieldname" value="{$fieldvalue}" {$params}/>{$value[18]}
<script type="text/javascript">
{$del_function}
</script>
</td>
</tr>
HTML;
$xfieldinput[$fieldname] = "<div id=\"xfupload_{$fieldname}\"></div><input type=\"hidden\" name=\"xfield[$fieldname]\" id=\"xf_$fieldname\" value=\"{$fieldvalue}\" {$params}/><script type=\"text/javascript\">{$del_function}</script>";
} else {
$output .= <<<HTML
<div id="$holderid" class="form-group" {$uid}>
<label class="control-label col-sm-2">{$value[1]}: [not-optional]<span style="color:red;">*</span>[/not-optional] {$value[18]}</label>
<div class="col-sm-10"><div id="xfupload_{$fieldname}"></div><input type="hidden" name="xfield[$fieldname]" id="xf_$fieldname" value="{$fieldvalue}" {$params}/>
<script type="text/javascript">
{$del_function}
jQuery(function($){
{$uploadscript}
});
</script>
</div>
</div>
HTML;
}
} elseif( $value[3] == "file" ) {
$max_file_size = (int)($value[15] * 1024);
$allowed_files = explode( ',', strtolower( $value[14] ) );
$allowed_files = implode( "', '", $allowed_files );
$fieldvalue = str_replace('&', '&', $fieldvalue);
if (!$value[5]) {
$params = "rel=\"essential\" ";
$uid = "uid=\"essential\" ";
} else {
$params = "";
$uid = "";
}
if( $fieldvalue ) {
$fileid = intval(preg_replace( "'\[attachment=(.*?):(.*?)\]'si", "\\1", $fieldvalue ));
$fileid = " <button class=\"qq-upload-button btn btn-sm btn-red bg-danger btn-raised\" onclick=\"xffiledelete('".$fieldname."','".$fileid."');return false;\">{$lang['xfield_xfid']}</button>";
$show="display:inline-block;";
} else { $show="display:none;"; $fileid="";}
$uploadscript = <<<HTML
new qq.FileUploader({
element: document.getElementById('xfupload_{$fieldname}'),
action: 'engine/ajax/upload.php',
maxConnections: 1,
multiple: false,
allowdrop: false,
encoding: 'multipart',
sizeLimit: {$max_file_size},
allowedExtensions: ['{$allowed_files}'],
params: {"PHPSESSID" : "{$sess_id}", "subaction" : "upload", "news_id" : "{$news_id}", "area" : "xfieldsfile", "author" : "{$author}", "xfname" : "{$fieldname}", "user_hash" : "{$dle_login_hash}"},
template: '<div class="qq-uploader">' +
'<div class="qq-upload-button btn btn-green bg-teal btn-sm btn-raised" style="width: auto;">{$lang['xfield_xfif']}</div>' +
'<ul class="qq-upload-list" style="display:none;"></ul>' +
'</div>',
onSubmit: function(id, fileName) {
$('<div id="uploadfile-'+id+'" class="file-box"><span class="qq-upload-file-status">{$lang['media_upload_st6']}</span><span class="qq-upload-file"> '+fileName+'</span> <span class="qq-status"><span class="qq-upload-spinner"></span><span class="qq-upload-size"></span></span><div class="progress"><div class="progress-bar progress-blue" style="width: 0%"><span>0%</span></div></div></div>').appendTo('#xfupload_{$fieldname}');
},
onProgress: function(id, fileName, loaded, total){
$('#uploadfile-'+id+' .qq-upload-size').text(DLEformatSize(loaded)+' {$lang['media_upload_st8']} '+DLEformatSize(total));
var proc = Math.round(loaded / total * 100);
$('#uploadfile-'+id+' .progress-bar').css( "width", proc + '%' );
$('#uploadfile-'+id+' .qq-upload-spinner').css( "display", "inline-block");
},
onComplete: function(id, fileName, response){
if ( response.success ) {
var returnbox = response.returnbox;
var returnval = response.xfvalue;
returnbox = returnbox.replace(/</g, "<");
returnbox = returnbox.replace(/>/g, ">");
returnbox = returnbox.replace(/&/g, "&");
$('#uploadfile-'+id+' .qq-status').html('{$lang['media_upload_st9']}');
$('#xf_{$fieldname}').show();
$('#uploadedfile_{$fieldname}').html( returnbox );
$('#xf_{$fieldname}').val(returnval);
$('#xfupload_{$fieldname} .qq-upload-button, #xfupload_{$fieldname} .qq-upload-button input').attr("disabled","disabled");
setTimeout(function() {
$('#uploadfile-'+id).fadeOut('slow', function() { $(this).remove(); });
}, 1000);
} else {
$('#uploadfile-'+id+' .qq-status').html('{$lang['media_upload_st10']}');
if( response.error ) $('#uploadfile-'+id+' .qq-status').append( '<br /><span class="text-danger">' + response.error + '</span>' );
setTimeout(function() {
$('#uploadfile-'+id).fadeOut('slow');
}, 4000);
}
},
messages: {
typeError: "{$lang['media_upload_st11']}",
sizeError: "{$lang['media_upload_st12']}",
emptyError: "{$lang['media_upload_st13']}"
},
debug: false
});
if($('#xf_{$fieldname}').val() != "" ) {
$('#xfupload_{$fieldname} .qq-upload-button, #xfupload_{$fieldname} .qq-upload-button input').attr("disabled","disabled");
}
HTML;
if ($xfieldmode == "site") {
$onload_scripts[] = <<<HTML
if ($('#xfupload_{$fieldname}').length){
{$uploadscript}
}
HTML;
$output .= <<<HTML
<tr id="$holderid" {$uid}>
<td class="addnews">$value[1]: [not-optional]<span style="color:red;">*</span>[/not-optional]</td>
<td class="xfields" colspan="2"><input style="{$show}" type="text" name="xfield[$fieldname]" id="xf_$fieldname" value="{$fieldvalue}" {$params}/><span id="uploadedfile_{$fieldname}">{$fileid}</span><div id="xfupload_{$fieldname}"></div>{$value[18]}</td>
</tr>
HTML;
$xfieldinput[$fieldname] = "<input style=\"{$show}\" type=\"text\" name=\"xfield[$fieldname]\" id=\"xf_$fieldname\" value=\"{$fieldvalue}\" {$params}/><span id=\"uploadedfile_{$fieldname}\">{$fileid}</span><div id=\"xfupload_{$fieldname}\"></div>";
} else {
$output .= <<<HTML
<div id="$holderid" class="form-group" {$uid}>
<label class="control-label col-sm-2">{$value[1]}: [not-optional]<span style="color:red;">*</span>[/not-optional] {$value[18]}</label>
<div class="col-sm-10"><input class="form-control width-350 position-left" style="margin-bottom:5px;{$show}" type="text" name="xfield[$fieldname]" id="xf_$fieldname" value="{$fieldvalue}" {$params}/><span id="uploadedfile_{$fieldname}">{$fileid}</span><div id="xfupload_{$fieldname}"></div>
<script type="text/javascript">
jQuery(function($){
{$uploadscript}
});
</script>
</div>
</div>
HTML;
}
}