function cIEContacts () {
this.win;
this.el;
this.wWidth = 395;
this.wHeight = 240;
}
cIEContacts.prototype.changeOptions = function(type){
if(type == 'i') {
Element('export_span').style.display = 'none';
Element('import_span').style.display = '';
}
else{
Element('import_span').style.display = 'none';
Element('export_span').style.display = '';
}
}
cIEContacts.prototype.showList = function(){
if (!this.el){
this.el = document.createElement("DIV");
this.el.style.visibility = "hidden";
this.el.style.position = "absolute";
this.el.style.left = "0px";
this.el.style.top = "0px";
this.el.style.width = this.wWidth + 'px';
this.el.style.height = this.wHeight + 'px';
if(is_ie) {
this.el.style.width = "430";
this.el.style.overflowY = "auto";
this.el.style.overflowX = "hidden";
}
else {
this.el.style.overflow = "-moz-scrollbars-vertical";
}
this.el.id = 'cc_rectIEContacts';
document.body.appendChild(this.el);
var lang_import_contacts = Element('cc_msg_import_contacts').value;
var lang_export_contacts = Element('cc_msg_export_contacts').value;
var lang_expresso_info_csv = Element('cc_msg_expresso_info_csv').value;
var lang_expresso_default = Element('cc_msg_expresso_default').value;
var lang_choose_contacts_file = Element('cc_msg_choose_contacts_file').value;
var lang_msg_choose_type = Element('cc_msg_choose_file_type').value;
var lang_msg_expresso_info_csv = Element('cc_msg_expresso_info_csv').value;
var lang_msg_export_csv = Element('cc_msg_export_csv').value;
var lang_close = Element('cc_msg_close').value;
var lang_moz_tb = Element('cc_msg_moz_thunderbird').value;
var lang_outl_pt = Element('cc_msg_outlook_express_pt').value;
var lang_outl_en = Element('cc_msg_outlook_express_en').value;
var lang_outl2k_pt = Element('cc_msg_outlook_2k_pt').value;
var lang_outl2k_en = Element('cc_msg_outlook_2k_en').value;
var lang_expresso_default_csv = Element('cc_msg_expresso_default_csv').value;
this.el.innerHTML =
'
';
}
this.showWindow();
}
cIEContacts.prototype.showWindow = function ()
{
if(!this.win) {
this.win = new dJSWin({
id: 'ccIEContacts',
content_id: this.el.id,
width: (this.wWidth +(is_ie ? 41 : 0)) +'px',
height: this.wHeight +'px',
title_color: '#3978d6',
bg_color: '#eee',
title: Element('cc_msg_ie_personal').value,
title_text_color: 'white',
button_x_img: '../phpgwapi/images/winclose.gif',
border: true });
this.win.draw();
}
this.win.open();
}
cIEContacts.prototype.importWriteStatus = function(args){
// array args
// args[0] - status (success, error ou importing)
// args[1] - numero de contatos novos;
// args[2] - numero de contatos falhos;
// args[3] - numero de contatos sobrescritos;
var form = document.formCSV;
var status = '';
var lang_import_fail = Element('cc_msg_import_fail').value;
var lang_importing = Element('cc_msg_importing_contacts').value;
var lang_import_finish = Element('cc_msg_import_finished').value;
var l_1 = '['+args[1]+' novos]';
var l_2 = '['+args[2]+' falharam]';
var l_3 = '['+args[3]+' já existiam]';
var l_error = ' '+lang_import_fail+ ' ';
var l_importing = ' '+lang_importing + ' ';
if(args[0] == 'success') {
for(i = 1; i < 4; i++) {
status += " "+eval('l_'+i);
}
Element('s_info').innerHTML = ' '+lang_import_finish+'
'+status;
}
else
Element('s_info').innerHTML = eval('l_'+args[0]);
Element("s_info").style.visibility = '';
var recreate_fileupload = function () {
var import_file = document.createElement("INPUT");
import_file.type = "FILE";
import_file.name = "import_file";
import_file.id = "import_file";
form.appendChild(import_file);
Element('import_button').disabled = false;
form.style.visibility = '';
}
if(args[0] != 'importing') {
recreate_fileupload();
setTimeout("Element('s_info').style.visibility = 'hidden'", 12000);
}
}
cIEContacts.prototype.importCSV = function ()
{
var lang_csv_msg = Element('cc_msg_chosse_valid_csv');
var form = document.formCSV;
if ((form.import_file.value.length < 10) ||
(form.import_file.value.substring(form.import_file.value.length - 4, form.import_file.value.length).toLowerCase() != ".csv")){
alert(lang_csv_msg);
return;
}
var _this = this;
Element('import_button').disabled = true;
var handler_import = function (responseText){
var args = new Array();
var data = unserialize(responseText);
if(data.error)
args[0] = 'error';
else {
args[0] = 'success';
args[1] = data._new ? data._new : 0;
args[2] = data._failure ? data._failure : 0;
args[3] = data._existing ? data._existing : 0;
}
_this.importWriteStatus(args);
}
if(! (divUpload = Element('divUpload'))) {
divUpload = document.createElement('DIV');
divUpload.id = 'divUpload';
document.body.appendChild(divUpload);
}
divUpload.innerHTML= '';
var _onload = function(){
var typeImport = Element('typeImport').value;
Connector.newRequest('import_contacts','../index.php?menuaction=contactcenter.ui_data.data_manager&method=import_contacts&typeImport='+typeImport,'GET',handler_import);
}
if (Element('importCSVFile').attachEvent)
Element('importCSVFile').attachEvent("onload", _onload);
else
Element('importCSVFile').onload = _onload;
form.action ="inc/cc_updown.php";
form.target ="importCSVFile";
form.submit();
form.removeChild(form.import_file);
form.style.visibility = 'hidden';
this.importWriteStatus(new Array('importing'));
}
cIEContacts.prototype.close = function() {
this.win.close();
}
cIEContacts.prototype.exportCSV = function() {
var lang_export_error = Element('cc_msg_export_error');
var handler_export = function(data) {
if(!data){
alert(lang_export_error );
return;
}
var div_download = document.getElementById("id_div_download");
if (!div_download){
div_download = document.createElement("DIV");
div_download.id="id_div_download";
document.body.appendChild(div_download);
}
div_download.innerHTML="";
Element('export_button').disabled = false;
}
var typeExport = Element("typeExport");
for(var index = 0; index < 5; index++){
if(Element('typeExport_'+index).checked)
break;
}
Element('export_button').disabled = true;
Connector.newRequest('export_contacts', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=export_contacts', 'POST', handler_export, 'typeExport='+Element('typeExport_'+index).value);
}
/* Build the Object */
var ccIEContacts = new cIEContacts();