Guest User

Untitled

a guest
Sep 14th, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. <?php
  2. /*+***********************************************************************************
  3. * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4. * ("License"); You may not use this file except in compliance with the License
  5. * The Original Code is: vtiger CRM Open Source
  6. * The Initial Developer of the Original Code is vtiger.
  7. * Portions created by vtiger are Copyright (C) vtiger.
  8. * All Rights Reserved.
  9. *************************************************************************************/
  10.  
  11. class ContactsHandler extends VTEventHandler {
  12.  
  13. function handleEvent($eventName, $entityData) {
  14. global $log, $adb;
  15. if($eventName == 'vtiger.entity.aftersave.final') {
  16. $moduleName = $entityData->getModuleName();
  17. if ($moduleName == 'Contacts') {
  18. $recordId = $entityData->getId();
  19. $email = $entityData->get('email');
  20. $sql = "SELECT id, user_name, user_password, isactive FROM vtiger_portalinfo WHERE id=?";
  21. $result = $adb->pquery($sql, array($recordId));
  22. if($adb->num_rows($result) > 0){
  23. $sql = "UPDATE vtiger_portalinfo SET user_name=? WHERE id=?";
  24. $adb->pquery($sql, array($email, $recordId));
  25. }
  26. }
  27. }
  28. }
  29. }
  30.  
  31. function Contacts_sendCustomerPortalLoginDetails($entityData){
  32. $adb = PearDatabase::getInstance();
  33. $moduleName = $entityData->getModuleName();
  34. $wsId = $entityData->getId();
  35. $parts = explode('x', $wsId);
  36. $entityId = $parts[1];
  37.  
  38. $email = $entityData->get('email');
  39.  
  40. if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
  41. $sql = "SELECT id, user_name, user_password, isactive FROM vtiger_portalinfo WHERE id=?";
  42. $result = $adb->pquery($sql, array($entityId));
  43. $insert = false;
  44. if($adb->num_rows($result) == 0){
  45. $insert = true;
  46. }else{
  47. $dbusername = $adb->query_result($result,0,'user_name');
  48. $isactive = $adb->query_result($result,0,'isactive');
  49. if($email == $dbusername && $isactive == 1 && !$entityData->isNew()){
  50. $update = false;
  51. } else if($entityData->get('portal') == 'on' || $entityData->get('portal') == '1'){
  52. $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=1 WHERE id=?";
  53. $adb->pquery($sql, array($email, $entityId));
  54. $password = $adb->query_result($result,0,'user_password');
  55. $update = true;
  56. } else {
  57. $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?";
  58. $adb->pquery($sql, array($email, 0, $entityId));
  59. $update = false;
  60. }
  61. }
  62. if($insert == true){
  63. $password = makeRandomPassword();
  64. $sql = "INSERT INTO vtiger_portalinfo(id,user_name,user_password,type,isactive) VALUES(?,?,?,?,?)";
  65. $params = array($entityId, $email, $password, 'C', 1);
  66. $adb->pquery($sql, $params);
  67. }
  68.  
  69. if($insert == true || $update == true) {
  70. global $current_user,$HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME;
  71. require_once("modules/Emails/mail.php");
  72. $emailData = Contacts::getPortalEmailContents($entityData,$password,'LoginDetails');
  73. $subject = $emailData['subject'];
  74. $contents = $emailData['body'];
  75. send_mail('Contacts', $entityData->get('email'), $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $contents,'','','','','',true);
  76. }
  77. } else {
  78. $sql = "UPDATE vtiger_portalinfo SET user_name=?,isactive=0 WHERE id=?";
  79. $adb->pquery($sql, array($email, $entityId));
  80. }
  81. }
  82. ?>
Add Comment
Please, Sign In to add comment