1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
| function upload_media_async(form_name, media_type, file_path, file_url, file_embed, nb_uploads, max_uploads, upload_id) {
var radio_buttons = new Array();
for (var i=0; i<form_name.length; i++)
{
if (form_name.elements[i].type == 'radio' && form_name.elements[i].checked == true)
{
radio_buttons[form_name.elements[i].name] = form_name.elements[i].value;
}
}
jsHttp = new JsHttpRequest();
xmlHttp=GetXmlHttpObject();
if (jsHttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}
var media_name = '';
switch (media_type)
{
case 1:
media_name = 'ad_image';
break;
case 2:
media_name = 'ad_video';
break;
case 3:
media_name = 'ad_dd';
break;
}
media_box_name = 'display_media_boxes_' + media_name;
file_embed = base64Encode(file_embed);
var url = relative_path + 'ajax_files/upload_file.php';
var action = url + '?do=add&media_type=' + media_type + '&file_url=' + file_url +
'&file_embed=' + file_embed + '&nb_uploads=' + nb_uploads + '&upload_id=' + upload_id;
var thumbnail_div = document.getElementById('display_media_boxes_' + media_name);
var new_content = document.createElement('div');
if (file_embed != '')
{
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4)
{
var response = xmlHttp.responseText;
results = response.split('|');
if (results[5] != '')
{
alert (results[5]);
}
else
{
new_content.innerHTML = results[3];
while (new_content.firstChild) {
thumbnail_div.appendChild(new_content.firstChild);
}
var hidden_div = document.getElementById('hidden_media_boxes');
var hidden_content = document.createElement('div');
hidden_content.innerHTML = '<input type="hidden" name="' + results[1] + '[]" id="hidden_' + results[2] + '" value="' + results[4] +
'">';
while (hidden_content.firstChild) {
hidden_div.appendChild(hidden_content.firstChild);
}
nb_uploads++;
}
document.getElementById('div_file_' + media_type).innerHTML = document.getElementById('div_file_' + media_type).innerHTML;
document.getElementById('item_file_url_' + media_type).value = '';
document.getElementById('item_file_embed_' + media_type).value = '';
if (nb_uploads>=max_uploads)
{
document.getElementById('btn_upload_' + media_type).disabled = true;
document.getElementById('item_file_upload_' + media_type).disabled = true;
document.getElementById('item_file_url_' + media_type).disabled = true;
document.getElementById('item_file_embed_' + media_type).disabled = true;
}
document.getElementById('nb_uploads_' + media_type).value = nb_uploads;
}
};
xmlHttp.open("POST", action, true);
xmlHttp.send(null);
}
else
{
jQuery.blockUI({ message: '<p style="padding: 10px; font-size: 16px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold;">' +
upl_progress_msg + '</p>' });
var image_loading = document.createElement('div');
image_loading.innerHTML = '<img src="' + relative_path + 'images/loading-media.gif">';
thumbnail_div.appendChild(image_loading);
jsHttp.onreadystatechange = function() {
if (jsHttp.readyState == 4)
{
var response = jsHttp.responseText;
//alert(response);
results = response.split('|');
if (results[5] != '')
{
thumbnail_div.removeChild(image_loading);
alert (results[5]);
setTimeout(jQuery.unblockUI, 500);
}
else
{
new_content.innerHTML = results[3];
while (new_content.firstChild) {
thumbnail_div.replaceChild(new_content.firstChild, image_loading);
}
setTimeout(jQuery.unblockUI, 500);
var hidden_div = document.getElementById('hidden_media_boxes');
var hidden_content = document.createElement('div');
hidden_content.innerHTML = '<input type="hidden" name="' + results[1] + '[]" id="hidden_' + results[2] + '" value="' + results[4] +
'">';
while (hidden_content.firstChild) {
hidden_div.appendChild(hidden_content.firstChild);
}
nb_uploads++;
}
document.getElementById('div_file_' + media_type).innerHTML = document.getElementById('div_file_' + media_type).innerHTML;
document.getElementById('item_file_url_' + media_type).value = '';
document.getElementById('item_file_embed_' + media_type).value = '';
if (nb_uploads>=max_uploads)
{
document.getElementById('btn_upload_' + media_type).disabled = true;
document.getElementById('item_file_upload_' + media_type).disabled = true;
document.getElementById('item_file_url_' + media_type).disabled = true;
document.getElementById('item_file_embed_' + media_type).disabled = true;
}
document.getElementById('nb_uploads_' + media_type).value = nb_uploads;
for (var i=0; i<form_name.length; i++)
{
if (form_name.elements[i].type == 'radio' && radio_buttons[form_name.elements[i].name] == form_name.elements[i].value)
{
form_name.elements[i].checked = true;
}
}
}
};
jsHttp.open("POST", action, true);
jsHttp.send( { file: file_path } );
}
} |
Partager