This commit is contained in:
vAugagneur
2011-09-22 15:46:42 +00:00
parent 2180359342
commit 1803db6aab
3 changed files with 43 additions and 25 deletions
+28 -15
View File
@@ -729,23 +729,34 @@ if (Tools::isSubmit('syncImapMail'))
OR !$port = Configuration::get('PS_SAV_IMAP_PORT') OR !$port = Configuration::get('PS_SAV_IMAP_PORT')
OR !$user = Configuration::get('PS_SAV_IMAP_USER') OR !$user = Configuration::get('PS_SAV_IMAP_USER')
OR !$password = Configuration::get('PS_SAV_IMAP_PWD')) OR !$password = Configuration::get('PS_SAV_IMAP_PWD'))
die('{"hasError" : true, "errors" : "Configuration is not correct"}'); die('{"hasError" : true, "errors" : ["Configuration is not correct"]}');
if (!function_exists('imap_open'))
die('{"hasError" : true, "errors" : ["imap is not installed on this server"]}');
$mbox = @imap_open('{'.$url.':'.$port.'}', $user, $password); $mbox = @imap_open('{'.$url.':'.$port.'}', $user, $password);
//checks if there is no error when connecting imap server
$errors = imap_errors(); $errors = imap_errors();
$str_errors = '';
$str_error_delete = '';
if (sizeof($errors)) if (sizeof($errors))
{ {
$str_errors = '["'; $str_errors = '["';
foreach($errors as $error) foreach($errors as $error)
$str_errors .= $error.','; $str_errors .= '"'.$error.'",';
$str_errors = rtrim($str_errors, ',').'"]'; $str_errors = rtrim($str_errors, ',').'';
} }
//checks if imap connexion is active
if (!$mbox) if (!$mbox)
die('{"hasError" : true, "errors" : ["Can not connect to the mailbox"]}'); die('{"hasError" : true, "errors" : ["Cannot connect to the mailbox"]}');
//Returns information about the current mailbox. Returns FALSE on failure.
$check = imap_check($mbox); $check = imap_check($mbox);
if ($check)
die('{"hasError" : true, "errors" : ["Fail to get information about the current mailbox"]}');
if ($check->Nmsgs == 0) if ($check->Nmsgs == 0)
die('{"hasError" : true, "errors" : ["NO message to sync"]}'); die('{"hasError" : true, "errors" : ["NO message to sync"]}');
@@ -757,16 +768,18 @@ if (Tools::isSubmit('syncImapMail'))
$subject = $overview->subject; $subject = $overview->subject;
else else
$subject = ''; $subject = '';
$md5 = md5($overview->date.$overview->from.$subject); //Creating an md5 to check if message has been allready processed
$md5 = md5($overview->date.$overview->from.$subject.$overview->msgno);
$exist = Db::getInstance()->getValue( $exist = Db::getInstance()->getValue(
'SELECT md5_header 'SELECT `md5_header`
FROM `'._DB_PREFIX_.'customer_message_sync_imap` FROM `'._DB_PREFIX_.'customer_message_sync_imap`
WHERE md5_header = \''.pSQL($md5).'\''); WHERE `md5_header` = \''.pSQL($md5).'\'');
if ($exist) if ($exist)
{ {
if (Configuration::get('PS_SAV_IMAP_DELETE_MSG')) if (Configuration::get('PS_SAV_IMAP_DELETE_MSG'))
imap_delete($mbox, $overview->msgno); if (!imap_delete($mbox, $overview->msgno))
$str_error_delete = ', "Fail to delete message"';
} }
else else
{ {
@@ -787,12 +800,12 @@ if (Tools::isSubmit('syncImapMail'))
$cm->add(); $cm->add();
} }
} }
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_message_sync_imap` VALUES (\''.pSQL($md5).'\')'); Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_message_sync_imap` (`md5_header`) VALUES (\''.pSQL($md5).'\')');
} }
} }
imap_expunge($mbox); imap_expunge($mbox);
imap_close($mbox); imap_close($mbox);
die('{"hasError" : false, "errors" : '.$str_errors.'}'); die('{"hasError" : false, "errors" : '.$str_errors.$str_errors_delete.'"]}');
} }
/* Modify attribute position */ /* Modify attribute position */
+11 -6
View File
@@ -94,7 +94,7 @@ class AdminCustomerThreads extends AdminTab
'PS_SAV_IMAP_PORT' => array('title' => $this->l('Imap port'), 'desc' => $this->l('Port to use to connect imap server'), 'type' => 'text', 'defaultValue' => 143, 'visibility' => Shop::CONTEXT_ALL), 'PS_SAV_IMAP_PORT' => array('title' => $this->l('Imap port'), 'desc' => $this->l('Port to use to connect imap server'), 'type' => 'text', 'defaultValue' => 143, 'visibility' => Shop::CONTEXT_ALL),
'PS_SAV_IMAP_USER' => array('title' => $this->l('Imap user'), 'desc' => $this->l('User to use to connect imap server'), 'type' => 'text', 'size' => 40, 'visibility' => Shop::CONTEXT_ALL), 'PS_SAV_IMAP_USER' => array('title' => $this->l('Imap user'), 'desc' => $this->l('User to use to connect imap server'), 'type' => 'text', 'size' => 40, 'visibility' => Shop::CONTEXT_ALL),
'PS_SAV_IMAP_PWD' => array('title' => $this->l('Imap password'), 'desc' => $this->l('Password to use to connect imap server'), 'type' => 'text', 'size' => 40, 'visibility' => Shop::CONTEXT_ALL), 'PS_SAV_IMAP_PWD' => array('title' => $this->l('Imap password'), 'desc' => $this->l('Password to use to connect imap server'), 'type' => 'text', 'size' => 40, 'visibility' => Shop::CONTEXT_ALL),
'PS_SAV_IMAP_DELETE_MSG' => array('title' => $this->l('Delete messages'), 'desc' => $this->l('Deletes message after sync. If you do not active this option, the sync will be longer'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'value', 'list' => array( 'PS_SAV_IMAP_DELETE_MSG' => array('title' => $this->l('Deletes messages'), 'desc' => $this->l('Deletes message after sync. If you do not active this option, the sync will be longer'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'value', 'list' => array(
'0' => array('value' => 0, 'name' => $this->l('No')), '0' => array('value' => 0, 'name' => $this->l('No')),
'1' => array('value' => 1, 'name' => $this->l('Yes')) '1' => array('value' => 1, 'name' => $this->l('Yes'))
), 'visibility' => Shop::CONTEXT_ALL) ), 'visibility' => Shop::CONTEXT_ALL)
@@ -196,6 +196,7 @@ class AdminCustomerThreads extends AdminTab
'{reply}' => Tools::nl2br(Tools::getValue('reply_message')), '{reply}' => Tools::nl2br(Tools::getValue('reply_message')),
'{link}' => Tools::url($this->context->link->getPageLink('contact', true), 'id_customer_thread='.(int)($ct->id).'&token='.$ct->token), '{link}' => Tools::url($this->context->link->getPageLink('contact', true), 'id_customer_thread='.(int)($ct->id).'&token='.$ct->token),
); );
//#ct == id_customer_thread #tc == token of thread <== used in the synchronization imap
if (Mail::Send($ct->id_lang, 'reply_msg', Mail::l('An answer to your message is available').' #ct'.$ct->id.'#tc'.$ct->token, if (Mail::Send($ct->id_lang, 'reply_msg', Mail::l('An answer to your message is available').' #ct'.$ct->id.'#tc'.$ct->token,
$params, Tools::getValue('msg_email'), NULL, NULL, NULL, $fileAttachment, NULL, $params, Tools::getValue('msg_email'), NULL, NULL, NULL, $fileAttachment, NULL,
_PS_MAIL_DIR_, true)) _PS_MAIL_DIR_, true))
@@ -644,14 +645,17 @@ class AdminCustomerThreads extends AdminTab
</div> </div>
</fieldset><br/> </fieldset><br/>
<script type="text/javascript"> <script type="text/javascript">
var ajaxQueries = new Array();
function run_sync () { function run_sync () {
$(\'#ajax_error\').html(\'\'); $(\'#ajax_error\').html(\'\');
$(\'#ajax_error\').hide(); $(\'#ajax_error\').hide();
$(\'#ajax_conf\').html(\'\'); $(\'#ajax_conf\').html(\'\');
$(\'#ajax_conf\').hide(); $(\'#ajax_conf\').hide();
for(i = 0; i < ajaxQueries.length; i++)
ajaxQueries[i].abort();
ajaxQueries = new Array();
$(\'#ajax_loader\').html(\'<img src="'._PS_ADMIN_IMG_.'ajax-loader.gif">\'); $(\'#ajax_loader\').html(\'<img src="'._PS_ADMIN_IMG_.'ajax-loader.gif">\');
$.ajax({ ajaxQuery = $.ajax({
type: "POST", type: "POST",
url: "ajax.php", url: "ajax.php",
data: "syncImapMail=1", data: "syncImapMail=1",
@@ -660,7 +664,7 @@ class AdminCustomerThreads extends AdminTab
jsonError = \'\'; jsonError = \'\';
if (jsonData.hasError) if (jsonData.hasError)
{ {
for (i=0;i<jsonData.errors.length;i++) for (i=0;i < jsonData.errors.length;i++)
jsonError = jsonError+\'<li>\'+jsonData.errors[i]+\'</li>\'; jsonError = jsonError+\'<li>\'+jsonData.errors[i]+\'</li>\';
$(\'#ajax_error\').html(\'<ul>\'+jsonError+\'</ul>\'); $(\'#ajax_error\').html(\'<ul>\'+jsonError+\'</ul>\');
$(\'#ajax_error\').fadeIn(); $(\'#ajax_error\').fadeIn();
@@ -668,7 +672,7 @@ class AdminCustomerThreads extends AdminTab
else else
{ {
jsonError = \'<li>'.$this->l('Sync success').'</li>\'; jsonError = \'<li>'.$this->l('Sync success').'</li>\';
for (i=0;i<jsonData.errors.length;i++) for (i=0;i < jsonData.errors.length;i++)
jsonError = jsonError+\'<li>\'+jsonData.errors[i]+\'</li>\'; jsonError = jsonError+\'<li>\'+jsonData.errors[i]+\'</li>\';
$(\'#ajax_conf\').html(\'<ul>\'+jsonError+\'</ul>\'); $(\'#ajax_conf\').html(\'<ul>\'+jsonError+\'</ul>\');
$(\'#ajax_conf\').fadeIn(); $(\'#ajax_conf\').fadeIn();
@@ -677,9 +681,10 @@ class AdminCustomerThreads extends AdminTab
$(\'#ajax_loader\').html(\'\'); $(\'#ajax_loader\').html(\'\');
}, },
error: function(XMLHttpRequest, textStatus, errorThrown) { error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("TECHNICAL ERROR: unable to refresh the cart.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + \'Text status: \' + textStatus); alert("TECHNICAL ERROR: unable to sync.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + \'Text status: \' + textStatus);
} }
}); });
ajaxQueries.push(ajaxQuery);
}; };
</script>'; </script>';
+4 -4
View File
@@ -560,11 +560,11 @@ $_LANGADM['AdminCustomerThreadsa81b40d671a82de3bc3550b878234dd6'] = 'Url pour le
$_LANGADM['AdminCustomerThreadscd16a15c486d2e183732556f779968c9'] = 'Port IMAP'; $_LANGADM['AdminCustomerThreadscd16a15c486d2e183732556f779968c9'] = 'Port IMAP';
$_LANGADM['AdminCustomerThreads8a29ff48f49ffe61e4e886a04cff2eb6'] = 'Port à utiliser pour se connecter le serveur imap'; $_LANGADM['AdminCustomerThreads8a29ff48f49ffe61e4e886a04cff2eb6'] = 'Port à utiliser pour se connecter le serveur imap';
$_LANGADM['AdminCustomerThreads678b57a794c6976ac961df8a32394def'] = 'Utilisateur IMAP'; $_LANGADM['AdminCustomerThreads678b57a794c6976ac961df8a32394def'] = 'Utilisateur IMAP';
$_LANGADM['AdminCustomerThreads0882db19e4fce8cbaff75c9dc2fb1166'] = 'L\'utilisateur à utiliser pour se connecter le serveur IMAP'; $_LANGADM['AdminCustomerThreads0882db19e4fce8cbaff75c9dc2fb1166'] = 'Utilisateur pour se connecter le serveur IMAP';
$_LANGADM['AdminCustomerThreads22e38bd8ea7e850765045720e0b9cf5d'] = 'Mot de passe IMAP'; $_LANGADM['AdminCustomerThreads22e38bd8ea7e850765045720e0b9cf5d'] = 'Mot de passe IMAP';
$_LANGADM['AdminCustomerThreadsa5bf021c18a4c0891b491c07d3555b86'] = 'Mot de passe à utiliser pour se connecter le serveur IMAP'; $_LANGADM['AdminCustomerThreadsa5bf021c18a4c0891b491c07d3555b86'] = 'Mot de passe à utiliser pour se connecter le serveur IMAP';
$_LANGADM['AdminCustomerThreadsca7e64e3f55ef8e0f50818d8117d26cc'] = 'Supprimer des messages'; $_LANGADM['AdminCustomerThreadsfaa07c5eadea7dd34bfc379d7bfd7c67'] = 'Supprime les messages';
$_LANGADM['AdminCustomerThreadsbbd8156a324aee57b7186991acf82d0d'] = 'Supprime le message après la synchronisation. Si vous n\'avez pas active cette option, la synchronisation sera plus long'; $_LANGADM['AdminCustomerThreadsbbd8156a324aee57b7186991acf82d0d'] = 'Supprime le message après la synchronisation. Si vous n\'avez pas activée cette option, la synchronisation sera plus longue';
$_LANGADM['AdminCustomerThreadsbafd7322c6e97d25b6299b5d6fe8920b'] = 'Non'; $_LANGADM['AdminCustomerThreadsbafd7322c6e97d25b6299b5d6fe8920b'] = 'Non';
$_LANGADM['AdminCustomerThreads93cba07454f06a4a960172bbd6e2a435'] = 'Oui'; $_LANGADM['AdminCustomerThreads93cba07454f06a4a960172bbd6e2a435'] = 'Oui';
$_LANGADM['AdminCustomerThreadsd21b5a78517318e6d35414d4217950ce'] = 'Message transmis à'; $_LANGADM['AdminCustomerThreadsd21b5a78517318e6d35414d4217950ce'] = 'Message transmis à';
@@ -628,7 +628,7 @@ $_LANGADM['AdminCustomerThreads694e8d1f2ee056f98ee488bdc4982d73'] = 'Quantité';
$_LANGADM['AdminCustomerThreadsd8e87c0927539672f54462c837be0b7f'] = 'Synchroniser'; $_LANGADM['AdminCustomerThreadsd8e87c0927539672f54462c837be0b7f'] = 'Synchroniser';
$_LANGADM['AdminCustomerThreadsa19330a6fc36ebae6683cc023e295687'] = 'Exécutez la synchronisation'; $_LANGADM['AdminCustomerThreadsa19330a6fc36ebae6683cc023e295687'] = 'Exécutez la synchronisation';
$_LANGADM['AdminCustomerThreads22009610f18142abea939bc2f1836a81'] = 'Cliquez pour synchroniser les mails automatiquement'; $_LANGADM['AdminCustomerThreads22009610f18142abea939bc2f1836a81'] = 'Cliquez pour synchroniser les mails automatiquement';
$_LANGADM['AdminCustomerThreads1e65b02f3464a517e0946a46d496327c'] = 'Synchronisation avec succès'; $_LANGADM['AdminCustomerThreads1e65b02f3464a517e0946a46d496327c'] = 'Synchronisation effectué avec succès';
$_LANGADM['AdminCustomersd1457b72c3fb323a2671125aef3eab5d'] = '?'; $_LANGADM['AdminCustomersd1457b72c3fb323a2671125aef3eab5d'] = '?';
$_LANGADM['AdminCustomersb718adec73e04ce3ec720dd11a06a308'] = 'ID'; $_LANGADM['AdminCustomersb718adec73e04ce3ec720dd11a06a308'] = 'ID';
$_LANGADM['AdminCustomers019ec3132cdf8ee0f2e2a75cf5d3e459'] = 'Sexe'; $_LANGADM['AdminCustomers019ec3132cdf8ee0f2e2a75cf5d3e459'] = 'Sexe';