[903] | 1 | function cIEContacts () { |
---|
| 2 | this.win; |
---|
| 3 | this.el; |
---|
| 4 | this.wWidth = 395; |
---|
| 5 | this.wHeight = 255; |
---|
| 6 | } |
---|
| 7 | |
---|
| 8 | cIEContacts.prototype.changeOptions = function(type){ |
---|
| 9 | if(type == 'i') { |
---|
| 10 | Element('export_span').style.display = 'none'; |
---|
| 11 | Element('import_span').style.display = ''; |
---|
| 12 | } |
---|
| 13 | else{ |
---|
| 14 | Element('import_span').style.display = 'none'; |
---|
| 15 | Element('export_span').style.display = ''; |
---|
| 16 | } |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | cIEContacts.prototype.showFailures = function(data){ |
---|
| 20 | if (data == 'undefined') |
---|
| 21 | return; |
---|
| 22 | if (data){ |
---|
| 23 | var lang_clean = Element('cc_msg_clean').value; |
---|
| 24 | var info_box = document.getElementById('s_info2'); |
---|
| 25 | info_box.innerHTML = data; |
---|
| 26 | info_box.style.visibility = ''; |
---|
| 27 | var cleanButton = document.createElement('input'); |
---|
| 28 | cleanButton.type='button'; |
---|
| 29 | cleanButton.value=lang_clean; |
---|
| 30 | cleanButton.onclick= function() { ccIEContacts.cleanInfo() }; |
---|
| 31 | info_box.appendChild(cleanButton); |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | cIEContacts.prototype.cleanInfo = function(){ |
---|
| 36 | var info_box = document.getElementById('s_info2'); |
---|
| 37 | info_box.innerHTML = ''; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | cIEContacts.prototype.showList = function(){ |
---|
| 41 | |
---|
| 42 | if (!this.el){ |
---|
| 43 | this.el = document.createElement("DIV"); |
---|
| 44 | this.el.style.visibility = "hidden"; |
---|
| 45 | this.el.style.position = "absolute"; |
---|
| 46 | this.el.style.left = "0px"; |
---|
| 47 | this.el.style.top = "0px"; |
---|
| 48 | this.el.style.width = this.wWidth + 'px'; |
---|
| 49 | this.el.style.height = this.wHeight + 'px'; |
---|
| 50 | if(is_ie) { |
---|
| 51 | this.el.style.width = "430"; |
---|
| 52 | this.el.style.overflowY = "auto"; |
---|
| 53 | this.el.style.overflowX = "hidden"; |
---|
| 54 | } |
---|
| 55 | else { |
---|
| 56 | this.el.style.overflow = "-moz-scrollbars-vertical"; |
---|
| 57 | } |
---|
| 58 | this.el.id = 'cc_rectIEContacts'; |
---|
| 59 | document.body.appendChild(this.el); |
---|
| 60 | |
---|
| 61 | var lang_import_contacts = Element('cc_msg_import_contacts').value; |
---|
| 62 | var lang_close_win = Element('cc_msg_close_win').value |
---|
| 63 | var lang_export_contacts = Element('cc_msg_export_contacts').value; |
---|
| 64 | var lang_expresso_info_csv = Element('cc_msg_expresso_info_csv').value; |
---|
| 65 | var lang_expresso_default = Element('cc_msg_expresso_default').value; |
---|
| 66 | var lang_choose_contacts_file = Element('cc_msg_choose_contacts_file').value; |
---|
| 67 | var lang_msg_choose_type = Element('cc_msg_choose_file_type').value; |
---|
| 68 | var lang_msg_expresso_info_csv = Element('cc_msg_expresso_info_csv').value; |
---|
| 69 | var lang_msg_export_csv = Element('cc_msg_export_csv').value; |
---|
| 70 | var lang_msg_automatic = Element('cc_msg_automatic').value; |
---|
| 71 | var lang_close = Element('cc_msg_close').value; |
---|
| 72 | var lang_moz_tb = Element('cc_msg_moz_thunderbird').value; |
---|
| 73 | var lang_outl_pt = Element('cc_msg_outlook_express_pt').value; |
---|
| 74 | var lang_outl_en = Element('cc_msg_outlook_express_en').value; |
---|
| 75 | var lang_outl2k_pt = Element('cc_msg_outlook_2k_pt').value; |
---|
| 76 | var lang_outl2k_en = Element('cc_msg_outlook_2k_en').value; |
---|
| 77 | var lang_expresso_default_csv = Element('cc_msg_expresso_default_csv').value; |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | this.el.innerHTML = |
---|
| 81 | '<div align="left" id="divAppbox"><table width="100%" border=0>'+ |
---|
| 82 | '<tr><td style="border-bottom:1px solid black"><input onclick="javascript:ccIEContacts.changeOptions(this.value)" id="type" type="radio" name="type" value="i" style="border:0" checked>'+lang_import_contacts+ |
---|
| 83 | ' <input onclick="javascript:ccIEContacts.changeOptions(this.value)" id="type" type="radio" name="type" style="border:0" value="e"/>'+lang_export_contacts+' <br></td></tr>'+ |
---|
| 84 | '</table>'+ |
---|
| 85 | '<table border=0 height="208px" width="100%" id="import_span">'+ |
---|
| 86 | '<tr><td>'+ |
---|
| 87 | '<font color="DARKBLUE" size="2">'+lang_expresso_info_csv+'</font></td></tr>'+ |
---|
| 88 | '<tr><td height="75px" valign="top">'+ |
---|
| 89 | '<form name="formCSV" method="POST" enctype="multipart/form-data">'+ lang_msg_choose_type + |
---|
| 90 | ': <select id="typeImport"><option value="auto" selected>'+lang_msg_automatic+'</option>'+ |
---|
| 91 | '<option value="outlook">'+("Outlook Express")+'</option>'+ |
---|
| 92 | '<option value="outlook2000">'+("Outlook 2000")+'</option>'+ |
---|
| 93 | '<option value="thunderbird">'+("Mozilla Thunderbird")+'</option>'+ |
---|
| 94 | '<option value="expresso" selected>'+lang_expresso_default+'</option></select><br>'+ |
---|
| 95 | '<br>'+lang_choose_contacts_file+'<br><br>'+ |
---|
| 96 | '<input id="import_file" type="file" name="import_file">'+ |
---|
| 97 | '</form></td></tr>'+ |
---|
| 98 | '<tr><td height="10px" align="center" nowrap><span style="visibility:hidden" id="s_info"></span></td></tr>'+ |
---|
| 99 | '<tr><td height="10px" align="center"></td></tr>'+ |
---|
| 100 | '<tr><td nowrap><center><input id="import_button" type="button" value='+lang_import_contacts+' onClick="javascript:ccIEContacts.importCSV(this)"> '+ |
---|
| 101 | '<input type="button" value='+lang_close_win+' onClick="javascript:ccIEContacts.close()"></center></td></tr>'+ |
---|
| 102 | '<tr><td height="10px" align="center" nowrap><span style="visibility:hidden" id="s_info2"></span></td></tr></table>'+ |
---|
| 103 | '<table border=0 height="208px" width="100%" style="display:none" id="export_span">'+ |
---|
| 104 | '<tr><td>'+ |
---|
| 105 | '<font color="DARKBLUE" size="2">'+ lang_msg_expresso_info_csv+'</font></td></tr>'+ |
---|
| 106 | '<tr><td height="85px" valign="top">'+lang_msg_export_csv+'<br><br>'+ |
---|
| 107 | '<select id="typeExport">'+ |
---|
| 108 | '<option value="expresso" selected>'+lang_expresso_default_csv+'</option>'+ |
---|
| 109 | '<option value="outlook_pt-BR">'+lang_outl_pt+'</option>'+ |
---|
| 110 | '<option value="outlook_en">'+lang_outl_en+'</option>'+ |
---|
| 111 | '<option value="outlook2000_pt-BR">'+lang_outl2k_pt+'</option>'+ |
---|
| 112 | '<option value="outlook2000_en">'+lang_outl2k_en+'</option>'+ |
---|
| 113 | '<option value="thunderbird">'+lang_moz_tb+'</option>'+ |
---|
| 114 | '</select>'+ |
---|
| 115 | '</td></tr>'+ |
---|
| 116 | '<tr><td align="center"> </td></tr>'+ |
---|
| 117 | '<tr><td nowrap><center><input id="export_button" type="button" value='+lang_export_contacts+ ' onClick="javascript:ccIEContacts.exportCSV(this)"> '+ |
---|
| 118 | '<input type="button" value='+lang_close_win+ ' onClick="javascript:ccIEContacts.close()"></center></td></tr>'+ |
---|
| 119 | '</table></div>'; |
---|
| 120 | } |
---|
| 121 | this.showWindow(); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | cIEContacts.prototype.showWindow = function () |
---|
| 125 | { |
---|
| 126 | if(!this.win) { |
---|
| 127 | |
---|
| 128 | this.win = new dJSWin({ |
---|
| 129 | id: 'ccIEContacts', |
---|
| 130 | content_id: this.el.id, |
---|
| 131 | width: (this.wWidth +(is_ie ? 41 : 0)) +'px', |
---|
| 132 | height: this.wHeight +'px', |
---|
| 133 | title_color: '#3978d6', |
---|
| 134 | bg_color: '#eee', |
---|
| 135 | title: Element('cc_msg_ie_personal').value, |
---|
| 136 | title_text_color: 'white', |
---|
| 137 | button_x_img: '../phpgwapi/images/winclose.gif', |
---|
| 138 | border: true }); |
---|
| 139 | |
---|
| 140 | this.win.draw(); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | this.win.open(); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | cIEContacts.prototype.importWriteStatus = function(args){ |
---|
| 147 | |
---|
| 148 | // array args |
---|
| 149 | // args[0] - status (success, error ou importing) |
---|
| 150 | // args[1] - numero de contatos novos; |
---|
| 151 | // args[2] - numero de contatos falhos; |
---|
| 152 | // args[3] - numero de contatos sobrescritos; |
---|
| 153 | var form = document.formCSV; |
---|
| 154 | var status = ''; |
---|
| 155 | |
---|
| 156 | var lang_import_fail = Element('cc_msg_import_fail').value; |
---|
| 157 | var lang_importing = Element('cc_msg_importing_contacts').value; |
---|
| 158 | var lang_import_finish = Element('cc_msg_import_finished').value; |
---|
| 159 | var lang_new = Element('cc_msg_new').value; |
---|
| 160 | var lang_failure = Element('cc_msg_failure').value; |
---|
| 161 | var lang_exists = Element('cc_msg_exists').value; |
---|
| 162 | var lang_show_more_info = Element('cc_msg_show_more_info').value; |
---|
| 163 | |
---|
| 164 | var l_1 = '<font face="Verdana" size="1" color="GREEN">['+args[1]+lang_new+']</font>'; |
---|
| 165 | var l_2 = '<font face="Verdana" size="1" color="RED">['+args[2]+lang_failure+']</font>'; |
---|
| 166 | var l_3 = '<font face="Verdana" size="1" color="DARKBLUE">['+args[3]+lang_exists+']</font>'; |
---|
| 167 | var l_4 = '<br><a font face="Verdana" size="1" href="javascript:ccIEContacts.showFailures(\''+args[4]+'\')">'+lang_show_more_info+'</a>'; |
---|
| 168 | var l_error = '<span style="height:15px;background:#cc4444"> <font face="Verdana" size="1" color="WHITE">'+lang_import_fail+ ' </font></span>'; |
---|
| 169 | var l_importing = '<span style="height:15px;background:rgb(250, 209, 99)"> <font face="Verdana" size="1" color="DARKBLUE">'+lang_importing + ' </font></span>'; |
---|
| 170 | |
---|
| 171 | if(args[0] == 'success') { |
---|
| 172 | |
---|
| 173 | for(i = 1; i < 5; i++) { |
---|
| 174 | status += " "+eval('l_'+i); |
---|
| 175 | } |
---|
| 176 | Element('s_info').innerHTML = ' <font face="Verdana" size="1" color="BLACK"><b>'+lang_import_finish+'</b></font><br> '+status; |
---|
| 177 | } |
---|
| 178 | else |
---|
| 179 | Element('s_info').innerHTML = eval('l_'+args[0]); |
---|
| 180 | |
---|
| 181 | Element("s_info").style.visibility = ''; |
---|
| 182 | |
---|
| 183 | var recreate_fileupload = function () { |
---|
| 184 | var import_file = document.createElement("INPUT"); |
---|
| 185 | import_file.type = "FILE"; |
---|
| 186 | import_file.name = "import_file"; |
---|
| 187 | import_file.id = "import_file"; |
---|
| 188 | form.appendChild(import_file); |
---|
| 189 | Element('import_button').disabled = false; |
---|
| 190 | form.style.visibility = ''; |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | if(args[0] != 'importing') { |
---|
| 194 | recreate_fileupload(); |
---|
| 195 | setTimeout("Element('s_info').style.visibility = 'hidden'", 12000); |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | cIEContacts.prototype.importCSV = function () |
---|
| 200 | { |
---|
| 201 | var lang_msg_invalid_csv = Element('cc_msg_invalid_csv').value; |
---|
| 202 | var form = document.formCSV; |
---|
| 203 | if ((form.import_file.value.length < 10) || |
---|
| 204 | (form.import_file.value.substring(form.import_file.value.length - 4, form.import_file.value.length).toLowerCase() != ".csv")){ |
---|
| 205 | alert(lang_msg_invalid_csv); |
---|
| 206 | return; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | var _this = this; |
---|
| 210 | Element('import_button').disabled = true; |
---|
| 211 | |
---|
| 212 | var handler_import = function (responseText){ |
---|
| 213 | var args = new Array(); |
---|
| 214 | |
---|
| 215 | var data = unserialize(responseText); |
---|
| 216 | |
---|
| 217 | if(data.error) |
---|
| 218 | args[0] = 'error'; |
---|
| 219 | else { |
---|
| 220 | args[0] = 'success'; |
---|
| 221 | args[1] = data._new ? data._new : 0; |
---|
| 222 | args[2] = data._failure ? data._failure : 0; |
---|
| 223 | args[3] = data._existing ? data._existing : 0; |
---|
| 224 | args[4] = data._failure_status |
---|
| 225 | |
---|
| 226 | } |
---|
| 227 | _this.importWriteStatus(args); |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | if(! (divUpload = Element('divUpload'))) { |
---|
| 231 | divUpload = document.createElement('DIV'); |
---|
| 232 | divUpload.id = 'divUpload'; |
---|
| 233 | document.body.appendChild(divUpload); |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | divUpload.innerHTML= '<iframe style="display:none;width:0px;height:0px" id="importCSVFile" name="importCSVFile"></iframe>'; |
---|
| 237 | |
---|
| 238 | var _onload = function(){ |
---|
| 239 | var typeImport = Element('typeImport').value; |
---|
| 240 | |
---|
| 241 | Connector.newRequest('import_contacts','../index.php?menuaction=contactcenter.ui_data.data_manager&method=import_contacts&typeImport='+typeImport,'GET',handler_import); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | if (Element('importCSVFile').attachEvent) |
---|
| 245 | Element('importCSVFile').attachEvent("onload", _onload); |
---|
| 246 | else |
---|
| 247 | Element('importCSVFile').onload = _onload; |
---|
| 248 | |
---|
| 249 | form.action ="inc/cc_updown.php"; |
---|
| 250 | form.target ="importCSVFile"; |
---|
| 251 | form.submit(); |
---|
| 252 | |
---|
| 253 | form.removeChild(form.import_file); |
---|
| 254 | form.style.visibility = 'hidden'; |
---|
| 255 | this.importWriteStatus(new Array('importing')); |
---|
| 256 | |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | cIEContacts.prototype.close = function() { |
---|
| 260 | this.win.close(); |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | cIEContacts.prototype.exportCSV = function() { |
---|
| 264 | var lang_export_error = Element('cc_msg_export_error'); |
---|
| 265 | var handler_export = function(data) { |
---|
| 266 | if(!data){ |
---|
| 267 | alert(lang_export_error ); |
---|
| 268 | return; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | var div_download = document.getElementById("id_div_download"); |
---|
| 272 | |
---|
| 273 | if (!div_download){ |
---|
| 274 | div_download = document.createElement("DIV"); |
---|
| 275 | div_download.id="id_div_download"; |
---|
| 276 | document.body.appendChild(div_download); |
---|
| 277 | } |
---|
| 278 | div_download.innerHTML="<iframe style='display:none;width:0;height:0' name='attachment' src='inc/cc_updown.php?&file_name=expresso.csv&file_path="+data+"'></iframe>"; |
---|
| 279 | Element('export_button').disabled = false; |
---|
| 280 | } |
---|
| 281 | var typeExport = Element("typeExport"); |
---|
| 282 | Element('export_button').disabled = true; |
---|
| 283 | Connector.newRequest('export_contacts', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=export_contacts', 'POST', handler_export, 'typeExport='+typeExport.value); |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | /* Build the Object */ |
---|
| 287 | var ccIEContacts = new cIEContacts(); |
---|