/
MailManager.php
141 lines (131 loc) · 5.72 KB
/
MailManager.php
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
<?php
/*+**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
************************************************************************************/
require_once 'include/Webservices/Query.php';
require_once 'data/CRMEntity.php';
class MailManager {
public $moduleIcon = array('library' => 'standard', 'containerClass' => 'slds-icon_container slds-icon-standard-contact', 'class' => 'slds-icon', 'icon'=>'email');
public $crmentityTable = 'vtiger_crmentity';
public $crmentityTableAlias;
public $denormalized = false;
public static function updateMailAssociation($mailuid, $emailid, $crmid) {
global $adb;
$adb->pquery('INSERT INTO vtiger_mailmanager_mailrel (mailuid, emailid, crmid) VALUES (?,?,?)', array($mailuid, $emailid, $crmid));
}
public static function lookupMailInVtiger($searchTerm, $user) {
$handler = vtws_getModuleHandlerFromName('Emails', $user);
$meta = $handler->getMeta();
$moduleFields = $meta->getModuleFields();
$parentIdFieldInstance = $moduleFields['parent_id'];
$referenceModules = $parentIdFieldInstance->getReferenceList();
$filteredResult = array();
foreach ($referenceModules as $referenceModule) {
$referenceModuleHandler = vtws_getModuleHandlerFromName($referenceModule, $user);
$referenceModuleMeta = $referenceModuleHandler->getMeta();
$referenceModuleEmailFields = $referenceModuleMeta->getEmailFields();
$referenceModuleEntityFields = $referenceModuleMeta->getNameFields();
$referenceModuleEntityFieldsArray = explode(',', $referenceModuleEntityFields);
$searchFieldList = array_merge($referenceModuleEmailFields, $referenceModuleEntityFieldsArray);
if (!empty($searchFieldList) && !empty($referenceModuleEmailFields)) {
$searchFieldListString = implode(',', $referenceModuleEmailFields);
$where = null;
for ($i=0; $i<count($searchFieldList); $i++) {
if ($i == count($searchFieldList) - 1) {
$where .= sprintf($searchFieldList[$i]." like '%s'", $searchTerm);
} else {
$where .= sprintf($searchFieldList[$i]." like '%s' or ", $searchTerm);
}
}
if (!empty($where)) {
$where = "WHERE $where";
}
$result = vtws_query("select $searchFieldListString from $referenceModule $where;", $user);
foreach ($result as $record) {
foreach ($searchFieldList as $searchField) {
if (!empty($record[$searchField])) {
$filteredResult[] = array(
'id' => $record[$searchField],
'name' => $record[$searchField].' - '.getTranslatedString($referenceModule, $referenceModule),
'record' => $record['id'],
'module' => $referenceModule
);
}
}
}
}
}
return $filteredResult;
}
public static function lookupMailAssociation($mailuid) {
global $adb;
$crmEntityTable = CRMEntity::getcrmEntityTableAlias('MailManager');
// Mail could get associated with two-or-more records if they get deleted after linking.
$result = $adb->pquery(
'SELECT vtiger_mailmanager_mailrel.*
FROM vtiger_mailmanager_mailrel
INNER JOIN '.$crmEntityTable.' ON vtiger_crmentity.crmid=vtiger_mailmanager_mailrel.crmid
AND vtiger_crmentity.deleted=0 AND vtiger_mailmanager_mailrel.mailuid=?
LIMIT 1',
array(decode_html($mailuid))
);
if ($adb->num_rows($result)) {
return $adb->fetch_array($result);
}
return false;
}
public static function isEMailAssociatedWithCRMID($mailuid, $crmid) {
global $adb;
$crmEntityTable = CRMEntity::getcrmEntityTableAlias('MailManager');
$result = $adb->pquery(
'SELECT vtiger_mailmanager_mailrel.*
FROM vtiger_mailmanager_mailrel
INNER JOIN '.$crmEntityTable.' ON vtiger_crmentity.crmid=vtiger_mailmanager_mailrel.crmid
AND vtiger_crmentity.deleted=0 AND vtiger_mailmanager_mailrel.mailuid=? and vtiger_mailmanager_mailrel.crmid=?
LIMIT 1',
array(decode_html($mailuid),$crmid)
);
return ($adb->num_rows($result)>0);
}
public static function checkModuleWriteAccessForCurrentUser($module) {
return (isPermitted($module, 'EditView') == 'yes' && vtlib_isModuleActive($module));
}
public static function checkModuleCreateAccessForCurrentUser($module) {
return (isPermitted($module, 'CreateView') == 'yes' && vtlib_isModuleActive($module));
}
/**
* function to check the read access for the current user
* @global Users Instance $current_user
* @param string $module - Name of the module
* @return Boolean
*/
public static function checkModuleReadAccessForCurrentUser($module) {
return (isPermitted($module, 'DetailView') == 'yes' && vtlib_isModuleActive($module));
}
/**
* Invoked when special actions are performed on the module.
* @param string $modulename - Module name
* @param string $event_type - Event Type (module.postinstall, module.disabled, module.enabled, module.preuninstall)
*/
public function vtlib_handler($modulename, $event_type) {
if ($event_type == 'module.postinstall') {
// Handle actions when this module is installed.
} elseif ($event_type == 'module.disabled') {
// Handle actions when this module is disabled.
} elseif ($event_type == 'module.enabled') {
// Handle actions when this module is enabled.
} elseif ($event_type == 'module.preuninstall') {
// Handle actions when this module is about to be deleted.
} elseif ($event_type == 'module.preupdate') {
// Handle actions before this module is updated.
} elseif ($event_type == 'module.postupdate') {
// Handle actions when this module is updated.
}
}
}
?>