Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php class CTWhatsApp_Record_Model extends Vtiger_Record_Model { public functi..
Decoded Output download
<?php
class CTWhatsApp_Record_Model extends Vtiger_Record_Model
{
public function getWhatsappIcon($sourceModule)
{
global $adb, $current_user;
$currenUserID = $current_user->id;
$isAdmin = $current_user->is_admin;
$roleID = $current_user->roleid;
$getUserGrous = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE users_groups != ''");
$usersGroups = explode(",", $adb->query_result($getUserGrous, 0, "users_groups"));
$userid = in_array($currenUserID, $usersGroups);
if ($userid) {
$num_rows = 1;
} else {
$queryGetGroupId = $adb->pquery("SELECT * FROM vtiger_group2role WHERE roleid = ?", array(
$roleID
));
$groupid = $adb->query_result($queryGetGroupId, 0, "groupid");
$existGroup = in_array($groupid, $usersGroups);
if ($existGroup) {
$num_rows = 1;
} else {
$num_rows = 0;
}
}
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$apiurl = str_replace("/api/", '', $configurationData["api_url"]);
$apiUrl = $apiurl . "/" . $configurationData["authtoken"];
$iconactive = $configurationData["iconactive"];
$whatsappStatus = $configurationData["whatsappstatus"];
$inappNotification = $configurationData["inapp_notification"];
$themeView = CTWhatsApp_Record_Model::getWhatsappTheme();
if ($themeView == "RTL") {
$picStyle1 = "margin: 0px 0px 0px 10px;float: right;";
$picStyle2 = "margin: 0px 0px 0px 10px;float: right;";
$divStyle = "style='direction: rtl;text-align: right;'";
$timeStyle = "float: left;direction: ltr;";
} else {
$picStyle1 = "margin: 0px 19px 0px 0px;float: left;";
$picStyle2 = "margin: 0px 19px 0px 0px;float: left;";
$divStyle = '';
$timeStyle = "float: right;";
}
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$unreadmsgCountsQuery = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.message_type = 'Recieved' AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups'");
$unreadCountCounts = $adb->num_rows($unreadmsgCountsQuery);
$unreadmsgQuery = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.message_type = 'Recieved' ORDER BY vtiger_ctwhatsapp.whatsapp_datetime DESC LIMIT 0, 5");
$unreadCountRow = $adb->num_rows($unreadmsgQuery);
$notificationHTML = '';
for ($i = 0; $i < $unreadCountRow; $i ++) {
$recordId = $adb->query_result($unreadmsgQuery, $i, "whatsapp_contactid");
if ($recordId == '') {
$label = $adb->query_result($unreadmsgQuery, $i, "whatsapp_withccode");
$lastBody = $adb->query_result($unreadmsgQuery, $i, "message_body");
$lastDateTime = $adb->query_result($unreadmsgQuery, $i, "whatsapp_datetime");
if ($label != "Groups") {
$individulMessageID = "id="whatsapp"";
$class = '';
$imageIcon = "layouts/v7/modules/CTWhatsApp/image/AvtarIcon.png";
$messagename = $adb->query_result($unreadmsgQuery, $i, "whatsapp_withccode");
} else {
$individulMessageID = '';
$class = "receivednewmessages";
$imageIcon = "layouts/v7/modules/CTWhatsApp/image/groups.png";
$messagename = $adb->query_result($unreadmsgQuery, $i, "whatsapp_chatid");
}
$notificationHTML .= "<li class="whatsapp_new_messages " . $class . "" " . $individulMessageID . " data-recordid="" . $label . "" style="width: 100%;display: inline-block;float: left;border-bottom: 1px solid rgb(44 59 73 / 15%);">
<a href="#" style="padding: 10px 10px !important;color: #333 !important;display: inline-block;float: left;width: 100%;">
\x9\x9 <div class="pic" style="display: inline-block;padding-right: 10px;width: 50px;height: 50px;border-radius: 50%;box-shadow: 0 0 5px rgb(68 80 100 / 0.25);max-width: 36px;max-height : 36px;margin : 0;" . $picStyle1 . "">\xa <img src="" . $imageIcon . "" style="width: 40px;max-width: 36px;max-height : 36px;margin : 0;border-radius: 50%;background: #4ebb46;"/>
\x9 </div>
\x9 <div " . $divStyle . ">
\x9 <span class=""><b style="font-size: 14px; !important;">" . $messagename . "</b></span>
\x9 <p style="max-width: 300px;font-size: 12px;max-width: 200px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">" . $lastBody . "</p>
\x9 <span class="" style="font-size: 12px;line-height: 16px;font-weight: 400;display: block;" . $timeStyle . "">" . Vtiger_Util_Helper::formatDateDiffInStrings($lastDateTime) . "</span>\xa\x9\x9 </div>\xa \x9 </a>
\x9 </li>";
} else {
$setype = VtigerCRMObject::getSEType($recordId);
$deleteRecord = CTWhatsApp_Record_Model::recordDelete($recordId);
if ($deleteRecord == 0) {
if ($recordId) {
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $setype);
$label = $recordModel->get("label");
}
$profileImage = CTWhatsApp_Record_Model::getImageDetails($recordId, $setype);
$imageTag = 1;
if ($profileImage == '') {
$labelExplode = explode(" ", $label);
$profileImage = mb_substr($labelExplode[0], 0, 1, "UTF-8") . mb_substr($labelExplode[1], 0, 1, "UTF-8");
$imageTag = 0;
}
$lastBody = $adb->query_result($unreadmsgQuery, $i, "message_body");
$lastDateTime = $adb->query_result($unreadmsgQuery, $i, "whatsapp_datetime");
$notificationHTML .= "<li class="whatsapp_new_messages" id="whatsapp" data-recordid="" . $recordId . "" data-setype="" . $setype . "" style="width: 100%;display: inline-block;float: left;border-bottom: 1px solid rgb(44 59 73 / 15%);">\xa <a href="#" style="padding: 10px 10px !important;color: #333 !important;display: inline-block;float: left;width: 100%;">\xa \x9 <div class="pic" style="display: inline-block;float: left; width: 36px;height: 36px;border-radius: 50%;box-shadow: 0 0 5px rgb(68 80 100 / 0.25); " . $picStyle2 . " text-align: center; color: #4ebb46;">";
if ($imageTag == 1) {
$notificationHTML .= "<img src="" . $profileImage . "" style=" width: 100%;margin: 0;height: 100%;border-radius: 50%;"/>";
} else {
$notificationHTML .= "<span class="imagename" id="imagename" style="font-size: 15px;line-height: 36px;"><b>" . $profileImage . "</b></span>";
}
$notificationHTML .= "</div>\xa \x9 <div " . $divStyle . ">
\x9 <span class=""><b style="font-size: 14px; !important;">" . $label . "</b></span>
\x9\x9 <p style="max-width: 300px;font-size: 12px;max-width: 200px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">" . $lastBody . "</p>
\x9\x9 <span class="" style="font-size: 12px;line-height: 16px;font-weight: 400;display: block;" . $timeStyle . "">" . Vtiger_Util_Helper::formatDateDiffInStrings($lastDateTime) . "</span>\xa\x9 </div>\xa \x9 </a>
\x9\x9 </li>";
}
}
}
$currentdate = date("Y-m-d");
$getexpiredate = $adb->pquery("SELECT * FROM vtiger_ctwhatsapp_license_setting");
$expirydate = $adb->query_result($getexpiredate, 0, "expirydate");
$licenseKey = $adb->query_result($getexpiredate, 0, "license_key");
$date = Settings_CTWhatsApp_ConfigurationDetail_View::encrypt_decrypt($expirydate, $action = "d");
$allwModules = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($sourceModule);
$moduleMassMessage = $allwModules["rows"];
$moduleIconActive = $allwModules["moduleIconActive"];
$phoneField = $allwModules["phoneField"];
if ($licenseKey != '' && strtotime($date) > strtotime($currentdate)) {
$whatsappModuleData = array(
"moduleMassMessage" => $moduleMassMessage,
"apiUrl" => $apiUrl,
"whatsappicon" => $num_rows,
"unread_count" => $unreadCountCounts,
"currentdate" => strtotime($currentdate),
"licensedate" => strtotime($date),
"whatsappStatus" => $whatsappStatus,
"moduleIconActive" => $moduleIconActive,
"phoneField" => $phoneField,
"inappNotification" => $inappNotification,
"notificationHTML" => $notificationHTML,
"isAdmin" => $isAdmin,
"themeView" => $themeView,
"iconactive" => $iconactive
);
}
return $whatsappModuleData;
}
function getScanQRCodeURL()
{
global $adb, $current_user;
$currentUserID = $current_user->id;
$isAdmin = $current_user->is_admin;
$queryUserExist = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield3 LIKE '%" . $currentUserID . "%'", array());
$numRowsUsers = $adb->num_rows($queryUserExist);
if ($numRowsUsers == 0) {
$queryGetGroupId = $adb->pquery("SELECT * FROM vtiger_group2role INNER JOIN vtiger_user2role ON vtiger_user2role.roleid = vtiger_group2role.roleid WHERE vtiger_user2role.userid = ?", array(
$currentUserID
));
$groupid = $adb->query_result($queryGetGroupId, 0, "groupid");
if ($groupid != '') {
$queryGroupExist = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield3 LIKE '%" . $groupid . "%'", array());
}
$numRowsUsers = $adb->num_rows($queryGroupExist);
}
if ($isAdmin == "on") {
$scanQRCode = "index.php?module=CTWhatsApp&parent=Settings&view=ConfigurationDetail";
} else {
$scanQRCode = "index.php?module=CTWhatsApp&view=DashBoard&mode=moduleDashBoard&showqrcode=1";
}
return $scanQRCode;
}
function getWhatsappAllowModules()
{
global $adb;
$whatsappModuleQuery = $adb->pquery("SELECT * FROM vtiger_ctwharsappallow_whatsappmodule WHERE active = 1");
$rows = $adb->num_rows($whatsappModuleQuery);
$whatsaappModule = array();
for ($i = 0; $i < $rows; $i ++) {
$module = $adb->query_result($whatsappModuleQuery, $i, "module");
$data = CTWhatsApp_Record_Model::checkPermissionModule($module);
if ($data == 1) {
$moduleIsEnable = CTWhatsApp_Record_Model::getmoduleIsEnable($module);
if ($moduleIsEnable == 0) {
$whatsaappModuleData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($module);
$phoneField = $whatsaappModuleData["phoneField"];
$serach = '';
$moduleQuery = CTWhatsApp_Record_Model::moduleQuery($module, $phoneField, $serach);
$query = $adb->pquery($moduleQuery);
$row = $adb->num_rows($query);
if ($row == '') {
$row = 0;
}
$whatsaappModule[] = array(
"module" => $module,
"rows" => $row,
"phoneField" => $phoneField
);
}
}
}
return $whatsaappModule;
}
function getmoduleIsEnable($moduleName)
{
global $adb;
$moduleQuery = $adb->pquery("SELECT * FROM vtiger_tab WHERE name = ?", array(
$moduleName
));
return $presence = $adb->query_result($moduleQuery, 0, "presence");
}
function getWhatsappAllowModuleFields($sourceModule)
{
global $adb;
$getAllowModule = $adb->pquery("SELECT * FROM vtiger_ctwharsappallow_whatsappmodule WHERE module = ?", array(
$sourceModule
));
$rows = $adb->num_rows($getAllowModule);
$moduleIconActive = $adb->query_result($getAllowModule, 0, "active");
$phoneField = $adb->query_result($getAllowModule, 0, "phone_field");
$allwModules = array(
"moduleIconActive" => $moduleIconActive,
"phoneField" => $phoneField,
"rows" => $rows
);
return $allwModules;
}
function moduleQuery($modulename, $phoneField, $searchValue)
{
global $adb, $current_user;
$currenUserID = $current_user->id;
$moduleModel = CRMEntity::getInstance($modulename);
$moduleInstance = Vtiger_Module::getInstance($modulename);
$baseTable = $moduleInstance->basetable;
$baseTableid = $moduleInstance->basetableid;
if ($searchValue) {
$searchQuery = " AND vtiger_crmentity.label LIKE '%" . $searchValue . "%'";
} else {
$searchQuery = '';
}
$mainTable = 0;
$query = "SELECT * FROM " . $baseTable;
foreach ($moduleModel->tab_name_index as $key => $value) {
$mainTable = $mainTable + 1;
if ($mainTable != 2) {
if ($key != "vtiger_seproductsrel" && $key != "vtiger_producttaxrel") {
$query .= " INNER JOIN " . $key . " ON " . $key . "." . $value . " = " . $baseTable . "." . $baseTableid;
}
}
}
$isAdmin = $current_user->is_admin;
if ($isAdmin != "on") {
$tabid = getTabid($modulename);
if ($tabid) {
$getRecordPermissionQuery = $adb->pquery("SELECT * FROM vtiger_def_org_share WHERE tabid = ?", array(
$tabid
));
$permission = $adb->query_result($getRecordPermissionQuery, 0, "permission");
if ($permission == "3") {
$assignQuery = " AND vtiger_crmentity.smownerid = '{$currenUserID}'";
}
}
}
$query .= " LEFT JOIN vtiger_users ON vtiger_crmentity.smownerid = vtiger_users.id LEFT JOIN vtiger_groups ON vtiger_crmentity.smownerid = vtiger_groups.groupid ";
$query .= " LEFT JOIN\xa\x9\x9 (
\x9\x9\x9 SELECT whatsapp_contactid, max(whatsapp_datetime) as whatsapp_date
\x9\x9 FROM vtiger_ctwhatsapp
\x9 group by whatsapp_contactid\xa \x9\x9) last_shared on (last_shared.whatsapp_contactid = " . $baseTable . "." . $baseTableid . " )";
$query .= " WHERE vtiger_crmentity.deleted=0 AND " . $baseTable . "." . $baseTableid . " > 0 AND " . $phoneField . " != ''" . $searchQuery . " " . $assignQuery . " GROUP BY " . $phoneField . " ORDER BY coalesce(last_shared.whatsapp_date) DESC";
return $query;
}
public function unreadQuery()
{
$query = "SELECT * FROM vtiger_ctwhatsapp \xa \x9 INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapp.ctwhatsappid
\x9\x9WHERE vtiger_crmentity.deleted = 0";
return $query;
}
public function getUnreadMessagesCount()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.message_type = 'Recieved' AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups'");
$rows = $adb->num_rows($query);
return $rows;
}
public function getImportantMessagesCounts()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_important = 1 GROUP BY vtiger_ctwhatsapp.whatsapp_contactid, vtiger_ctwhatsapp.whatsapp_withccode", array());
$rows = $adb->num_rows($query);
$delete = 0;
for ($i = 0; $i < $rows; $i ++) {
$relatedRecordId = $adb->query_result($query, $i, "whatsapp_contactid");
if ($relatedRecordId != '') {
$deleteRecord = CTWhatsApp_Record_Model::recordDelete($relatedRecordId);
if ($deleteRecord == 1) {
$delete = $delete + 1;
}
}
}
$rows = $rows - $delete;
return $rows;
}
public function getNewMessagesCounts()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_withccode != '' AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.message_type = 'Recieved' AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups' GROUP BY vtiger_ctwhatsapp.whatsapp_contactid, vtiger_ctwhatsapp.whatsapp_withccode ORDER BY vtiger_crmentity.createdtime", array());
$rows = $adb->num_rows($query);
$allNewMessageCountquery = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_withccode != '' AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.message_type = 'Recieved' AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups'", array());
$allRows = $adb->num_rows($allNewMessageCountquery);
$result = array(
"rows" => $rows,
"allRows" => $allRows
);
return $result;
}
public function getAllMessagesCounts()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$allQuery = $unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_withccode != '' AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups' GROUP BY vtiger_ctwhatsapp.whatsapp_contactid, vtiger_ctwhatsapp.whatsapp_withccode";
$unreadQuery = $unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_withccode != '' AND vtiger_ctwhatsapp.message_type = 'Recieved' AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups' GROUP BY vtiger_ctwhatsapp.whatsapp_contactid, vtiger_ctwhatsapp.whatsapp_withccode";
$allUnreadMessageCount = $adb->pquery($allQuery);
$row = $adb->num_rows($allUnreadMessageCount);
$delete = 0;
for ($i = 0; $i < $row; $i ++) {
$relatedRecordId = $adb->query_result($allUnreadMessageCount, $i, "whatsapp_contactid");
if ($relatedRecordId != '') {
$deleteRecord = CTWhatsApp_Record_Model::recordDelete($relatedRecordId);
if ($deleteRecord == 1) {
$delete = $delete + 1;
}
}
}
$rows = $row - $delete;
$allUnreadCount = $adb->pquery($unreadQuery);
$allRows = $adb->num_rows($allUnreadCount);
$result = array(
"rows" => $allRows,
"allRows" => $rows
);
return $result;
}
public function getUnknownMessagesCounts()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_contactid = '' AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups' AND vtiger_ctwhatsapp.message_type = 'Recieved' GROUP BY vtiger_ctwhatsapp.whatsapp_withccode", array());
$unknownRows = $adb->num_rows($query);
if ($unknownRows == '') {
$unknownRows = 0;
}
$allUnknownquery = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_contactid = '' AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups' GROUP BY vtiger_ctwhatsapp.whatsapp_withccode", array());
$allUnknownRows = $adb->num_rows($allUnknownquery);
if ($allUnknownRows == '') {
$allUnknownRows = 0;
}
$result = array(
"unknownRows" => $unknownRows,
"allUnknownRows" => $allUnknownRows
);
return $result;
}
public function getModuleRecrods($request)
{
$moduleName = $request->getModule();
$whatsappmodule = $request->get("whatsappmodule");
$searchValue = $request->get("searchValue");
$start = $request->get("start");
$end = $request->get("end");
$html = '';
if ($whatsappmodule == "Important") {
$importantMessages = "yes";
$moduleMessages = CTWhatsApp_Record_Model::getNewMessagesData($importantMessages, $start, $end, $searchValue, $whatsappmodule);
} else {
if ($whatsappmodule == "NewMessages") {
$importantMessages = "no";
$moduleMessages = CTWhatsApp_Record_Model::getNewMessagesData($importantMessages, $start, $end, $searchValue, $whatsappmodule);
} else {
if ($whatsappmodule == "Unknown") {
$moduleMessages = CTWhatsApp_Record_Model::getUnknownMessagesData($start, $end, $searchValue);
} else {
if ($whatsappmodule == "AllMessages") {
$importantMessages = "no";
$moduleMessages = CTWhatsApp_Record_Model::getNewMessagesData($importantMessages, $start, $end, $searchValue, $whatsappmodule);
} else {
if ($whatsappmodule == "Groups") {
$moduleMessages = CTWhatsApp_Record_Model::getWhatsappGroup();
} else {
$moduleMessages = CTWhatsApp_Record_Model::getModuleMessagesData($whatsappmodule, $start, $end, $searchValue);
}
}
}
}
}
$index = 0;
foreach ($moduleMessages as $key => $value) {
if ($value["unreadMessageCount"] == 0) {
$read = '';
$count = '';
} else {
$read = "unRead";
$count = "<span class="counterMsg" style="top: 0px !important;margin-left: 40px; !important">" . $value["unreadMessageCount"] . "</span>";
}
if ($index == 0) {
$bydefaulOpenChat = "bydefaulOpenChat";
} else {
$bydefaulOpenChat = '';
}
if ($whatsappmodule == "Groups") {
$html .= "<div class="profile showChatMessages " . $bydefaulOpenChat . "" data-recordid="" . $value["recordId"] . "" data-label="" . $value["label"] . "" data-groupid="" . $value["groupid"] . "" style="cursor: pointer;">";
if ($value["imagetag"] == 1) {
$html .= "<div class="pic"><img src="" . $value["profileImage"] . "" style="width: 100%;"/></div>";
} else {
$html .= "<div class="pic"><span class="imagename" id="imagename" style="margin: 7px;font-size: 28px;margin: 2px;color: teal;"><b>" . $value["profileImage"] . "</b></span></div>";
}
$html .= "<div class="pText">\xa\x9\x9\x9\x9 \x9\x9 <span>" . $value["label"] . "</span>" . $count . "<p>" . $value["lastBody"] . "</p>\xa \x9 \x9 </div>\xa \x9\x9\x9\x9</div>";
} else {
$html .= "<div class="profile showChatMessages " . $bydefaulOpenChat . "" data-recordid="" . $value["recordId"] . "" style="cursor: pointer;">";
if ($value["imagetag"] == 1) {
$html .= "<div class="pic"><img src="" . $value["profileImage"] . "" style="width: 100%;"/></div>";
} else {
$html .= "<div class="pic"><span class="imagename" id="imagename" style="margin: 7px;font-size: 28px;margin: 2px;color: teal;"><b>" . $value["profileImage"] . "</b></span></div>";
}
$html .= "<div class="pText">
\x9 \x9 <span>" . $value["label"] . "</span>" . $count . "<p>" . $value["lastBody"] . "</p>\xa \x9 \x9 </div>
\x9\x9 <div class="dateTime">" . $value["lastDateTime"] . "</div>
\x9\x9 </div>";
}
$index = $index + 1;
}
$html .= "</div>\xa\x9\x9\x9 </div>";
if (empty($moduleMessages)) {
return '';
} else {
return $html;
}
}
public function recordDelete($recordId)
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_crmentity WHERE crmid = ?", array(
$recordId
));
$deleted = $adb->query_result($query, 0, "deleted");
return $deleted;
}
public function getNewMessagesData($importantMessages, $start, $end, $searchValue, $whatsappmodule)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
if ($searchValue) {
$searchQuery = " AND vtiger_ctwhatsapp.whatsapp_withccode LIKE '%" . $searchValue . "%'";
} else {
$searchQuery = '';
}
if ($whatsappmodule != "AllMessages") {
$customQuery = " AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread'";
}
if ($whatsappmodule == "NewMessages") {
$customUnreadQuery = " AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.message_type = 'Recieved'";
}
if ($importantMessages == "yes") {
$importantQuery = $searchQuery . " AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups' AND vtiger_ctwhatsapp.whatsapp_important = 1 GROUP BY vtiger_ctwhatsapp.whatsapp_withccode, vtiger_ctwhatsapp.whatsapp_contactid ORDER BY vtiger_ctwhatsapp.whatsapp_datetime DESC";
} else {
$importantQuery = $searchQuery . " " . $customQuery . " " . $customUnreadQuery . " AND vtiger_ctwhatsapp.whatsapp_withccode != 'Groups' GROUP BY vtiger_ctwhatsapp.whatsapp_contactid, vtiger_ctwhatsapp.whatsapp_withccode ORDER BY vtiger_ctwhatsapp.whatsapp_datetime DESC";
}
if ($searchValue) {
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.ctwhatsappid IN(SELECT max(vtiger_ctwhatsapp.ctwhatsappid) FROM vtiger_ctwhatsapp GROUP BY vtiger_ctwhatsapp.whatsapp_withccode, vtiger_ctwhatsapp.whatsapp_contactid) AND vtiger_ctwhatsapp.whatsapp_withccode != ''" . $importantQuery);
} else {
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.ctwhatsappid IN(SELECT max(vtiger_ctwhatsapp.ctwhatsappid) FROM vtiger_ctwhatsapp GROUP BY vtiger_ctwhatsapp.whatsapp_withccode, vtiger_ctwhatsapp.whatsapp_contactid) AND vtiger_ctwhatsapp.whatsapp_withccode != ''" . $importantQuery . " LIMIT 0, " . $start);
}
$rows = $adb->num_rows($query);
$newMessagearray = array();
for ($i = 0; $i < $rows; $i ++) {
$recordId = $adb->query_result($query, $i, "whatsapp_contactid");
if ($recordId == '') {
$label = $adb->query_result($query, $i, "whatsapp_withccode");
$recordId = $label;
$profileImage = "layouts/v7/modules/CTWhatsApp/image/AvtarIcon.png";
$imagetag = 1;
$messageData = CTWhatsApp_Record_Model::getWhatsappUnReadNewMessageCounts($label);
$unreadMessageCount = $messageData["unreadCount"];
$avgMessageDay = $messageData["avgMessageDay"];
$lastWhatsappMessageData = CTWhatsApp_Record_Model::getLastWhatsappNewMessageData($label);
$lastBody = $lastWhatsappMessageData["body"];
$lastDateTime = $lastWhatsappMessageData["dateTime"];
$newMessagearray[$label] = array(
"recordId" => $recordId,
"label" => $label,
"profileImage" => $profileImage,
"imagetag" => $imagetag,
"unreadMessageCount" => $unreadMessageCount,
"avgMessageDay" => $avgMessageDay,
"lastBody" => $lastBody,
"lastDateTime" => $lastDateTime
);
} else {
$setype = VtigerCRMObject::getSEType($recordId);
$actionName = "EditView";
if (! Users_Privileges_Model::isPermitted($setype, $actionName, $recordId)) {
$permissionRecord = "0";
} else {
$permissionRecord = "1";
}
if ($permissionRecord == 1) {
$moduleIsEnable = CTWhatsApp_Record_Model::getmoduleIsEnable($setype);
if ($moduleIsEnable == 0) {
$deleteRecord = CTWhatsApp_Record_Model::recordDelete($recordId);
if ($deleteRecord == 0) {
if ($recordId) {
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $setype);
$label = $recordModel->get("label");
}
$profileImage = CTWhatsApp_Record_Model::getImageDetails($recordId, $setype);
$imagetag = 1;
if ($profileImage == '') {
$labelExplode = explode(" ", $label);
$profileImage = mb_substr($labelExplode[0], 0, 1, "UTF-8") . mb_substr($labelExplode[1], 0, 1, "UTF-8");
$imagetag = 0;
}
$messageData = CTWhatsApp_Record_Model::getWhatsappUnReadMessageCounts($recordId);
$unreadMessageCount = $messageData["unreadCount"];
$avgMessageDay = $messageData["avgMessageDay"];
$lastWhatsappMessageData = CTWhatsApp_Record_Model::getLastWhatsappMessageData($recordId);
$lastBody = $lastWhatsappMessageData["body"];
$lastDateTime = $lastWhatsappMessageData["dateTime"];
$newMessagearray[$label] = array(
"recordId" => $recordId,
"label" => $label,
"profileImage" => $profileImage,
"imagetag" => $imagetag,
"unreadMessageCount" => $unreadMessageCount,
"avgMessageDay" => $avgMessageDay,
"lastBody" => $lastBody,
"lastDateTime" => $lastDateTime
);
}
}
}
}
}
return $newMessagearray;
}
public function getWhatsappUnReadNewMessageCounts($phonenumber)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.whatsapp_withccode = ? AND vtiger_ctwhatsapp.message_type = 'Recieved'", array(
$phonenumber
));
$unreadCount = $adb->num_rows($query);
$allMessageQuery = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_withccode = ?", array(
$phonenumber
));
$rows = $adb->num_rows($allMessageQuery);
$totalDays = 30;
$avgMessageDay = $rows / $totalDays;
$result = array(
"unreadCount" => $unreadCount,
"avgMessageDay" => number_format($avgMessageDay, 2)
);
return $result;
}
public function getLastWhatsappNewMessageData($phonenumber)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_withccode = ? ORDER BY vtiger_ctwhatsapp.ctwhatsappid DESC LIMIT 0,1", array(
$phonenumber
));
$body = $adb->query_result($query, 0, "message_body");
if ($adb->query_result($query, 0, "whatsapp_datetime")) {
$dateTime = Vtiger_Util_Helper::formatDateDiffInStrings($adb->query_result($query, 0, "whatsapp_datetime"));
} else {
$dateTime == '';
}
$whatsappData = array(
"body" => $body,
"dateTime" => $dateTime
);
return $whatsappData;
}
public function getImageDetails($recordId, $setype)
{
global $root_directory;
$db = PearDatabase::getInstance();
$imageDetails = array();
if ($recordId) {
$sql = "SELECT vtiger_attachments.*, vtiger_crmentity.setype FROM vtiger_attachments\xa \x9 \x9 \x9INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid\xa \x9\x9\x9 INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_attachments.attachmentsid\xa\x9 \x9 WHERE vtiger_seattachmentsrel.crmid = ?";
$result = $db->pquery($sql, array(
$recordId
));
$imageId = $db->query_result($result, 0, "attachmentsid");
$imagePath = $db->query_result($result, 0, "path");
$imageName = $db->query_result($result, 0, "name");
$imageOriginalName = urlencode(decode_html($imageName));
if (! empty($imageName)) {
$imageDetails[] = array(
"id" => $imageId,
"orgname" => $imageOriginalName,
"path" => $imagePath . $imageId,
"name" => $imageName
);
$imagePath = $imagePath . $imageId . "_" . $imageName;
}
}
return $imagePath;
}
public function getWhatsappUnReadMessageCounts($recordId)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.whatsapp_contactid = ? AND vtiger_ctwhatsapp.message_type = 'Recieved'", array(
$recordId
));
$unreadCount = $adb->num_rows($query);
$allMessageQuery = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_contactid = ?", array(
$recordId
));
$rows = $adb->num_rows($allMessageQuery);
$totalDays = 30;
$avgMessageDay = $rows / $totalDays;
$result = array(
"unreadCount" => $unreadCount,
"avgMessageDay" => number_format($avgMessageDay, 2)
);
return $result;
}
public function getLastWhatsappMessageData($recordId)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . " AND vtiger_ctwhatsapp.whatsapp_contactid = ? ORDER BY vtiger_ctwhatsapp.ctwhatsappid DESC LIMIT 0,1", array(
$recordId
));
$body = $adb->query_result($query, 0, "message_body");
if ($adb->query_result($query, 0, "whatsapp_datetime")) {
$dateTime = Vtiger_Util_Helper::formatDateDiffInStrings($adb->query_result($query, 0, "whatsapp_datetime"));
} else {
$dateTime == '';
}
$whatsappData = array(
"body" => $body,
"dateTime" => $dateTime
);
return $whatsappData;
}
public function getUnknownMessagesData($start, $end, $searchValue)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
if ($searchValue) {
$customQuery = " AND vtiger_ctwhatsapp.whatsapp_withccode LIKE '%" . $searchValue . "%'";
$query = $adb->pquery($unreadQuery . " AND (vtiger_ctwhatsapp.whatsapp_withccode != 'Groups' AND vtiger_ctwhatsapp.whatsapp_withccode != '') AND vtiger_ctwhatsapp.whatsapp_contactid = '' " . $customQuery . " GROUP BY vtiger_ctwhatsapp.whatsapp_withccode ORDER BY vtiger_crmentity.createdtime DESC");
} else {
$searchQuery = " ORDER BY vtiger_crmentity.createdtime DESC LIMIT 0, " . $start;
$query = $adb->pquery($unreadQuery . " AND (vtiger_ctwhatsapp.whatsapp_withccode != 'Groups' AND vtiger_ctwhatsapp.whatsapp_withccode != '') AND vtiger_ctwhatsapp.whatsapp_contactid = '' GROUP BY vtiger_ctwhatsapp.whatsapp_withccode" . $searchQuery);
}
$rows = $adb->num_rows($query);
$newMessagearray = array();
for ($i = 0; $i < $rows; $i ++) {
$label = $adb->query_result($query, $i, "whatsapp_withccode");
$recordId = $label;
$profileImage = "layouts/v7/modules/CTWhatsApp/image/AvtarIcon.png";
$imagetag = 1;
$messageData = CTWhatsApp_Record_Model::getWhatsappUnReadNewMessageCounts($label);
$unreadMessageCount = $messageData["unreadCount"];
$avgMessageDay = $messageData["avgMessageDay"];
$lastWhatsappMessageData = CTWhatsApp_Record_Model::getLastWhatsappNewMessageData($label);
$lastBody = $lastWhatsappMessageData["body"];
$lastDateTime = $lastWhatsappMessageData["dateTime"];
$newMessagearray[$label] = array(
"recordId" => $recordId,
"label" => $label,
"profileImage" => $profileImage,
"imagetag" => $imagetag,
"unreadMessageCount" => $unreadMessageCount,
"avgMessageDay" => $avgMessageDay,
"lastBody" => $lastBody,
"lastDateTime" => $lastDateTime
);
}
return $newMessagearray;
}
public function getModuleMessagesData($whatsappmodule, $start, $end, $searchValue)
{
global $adb;
$whatsaappModuleData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($whatsappmodule);
$phoneField = $whatsaappModuleData["phoneField"];
$moduleQuery = CTWhatsApp_Record_Model::moduleQuery($whatsappmodule, $phoneField, $searchValue);
if ($searchValue) {
$query = $adb->pquery($moduleQuery);
} else {
$query = $adb->pquery($moduleQuery . " LIMIT 0, " . $start);
}
$rows = $adb->num_rows($query);
$moduleRecordData = array();
for ($i = 0; $i < $rows; $i ++) {
$recordId = $adb->query_result($query, $i, "crmid");
$label = $adb->query_result($query, $i, "label");
$setype = $adb->query_result($query, $i, "setype");
$profileImage = CTWhatsApp_Record_Model::getImageDetails($recordId, $setype);
$imagetag = 1;
if ($profileImage == '') {
$labelExplode = explode(" ", $label);
$profileImage = mb_substr($labelExplode[0], 0, 1, "UTF-8") . mb_substr($labelExplode[1], 0, 1, "UTF-8");
$imagetag = 0;
}
$messageData = CTWhatsApp_Record_Model::getWhatsappUnReadMessageCounts($recordId);
$unreadMessageCount = $messageData["unreadCount"];
$avgMessageDay = $messageData["avgMessageDay"];
$lastWhatsappMessageData = CTWhatsApp_Record_Model::getLastWhatsappMessageData($recordId);
$lastBody = $lastWhatsappMessageData["body"];
$lastDateTime = $lastWhatsappMessageData["dateTime"];
$moduleRecordData[] = array(
"recordId" => $recordId,
"label" => $label,
"profileImage" => $profileImage,
"imagetag" => $imagetag,
"unreadMessageCount" => $unreadMessageCount,
"avgMessageDay" => $avgMessageDay,
"lastBody" => $lastBody,
"lastDateTime" => $lastDateTime
);
}
return $moduleRecordData;
}
public function getModuleRecordData($recordId, $setype, $whatsappModule, $groupid)
{
global $adb;
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $setype);
$label = $recordModel->get("label");
$phoneFieldData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($setype);
$phoneField = $phoneFieldData["phoneField"];
$phone = $recordModel->get($phoneField);
$profileImage = CTWhatsApp_Record_Model::getImageDetails($recordId, $setype);
$imagetag = 1;
if ($profileImage == '') {
$labelExplode = explode(" ", $label);
$profileImage = mb_substr($labelExplode[0], 0, 1, "UTF-8") . mb_substr($labelExplode[1], 0, 1, "UTF-8");
$imagetag = 0;
}
$getWhatsappMessages = CTWhatsApp_Record_Model::getWhatsappMessages($recordId, $setype, $whatsappModule, $groupid);
$whatsappMessageHTML = $getWhatsappMessages["whatsappMessageHTML"];
$totalSent = $getWhatsappMessages["totalSent"];
$totalReceived = $getWhatsappMessages["totalReceived"];
$recentComments = $getWhatsappMessages["commentHTML"];
$messageImportant = $getWhatsappMessages["messageImportant"];
$moduleIsEnable = $getWhatsappMessages["moduleIsEnable"];
$tabid = getTabid($setype);
$query = $adb->pquery("SELECT * FROM vtiger_field WHERE tabid = ? AND summaryfield = ? AND uitype NOT IN ('10', '51')", array(
$tabid,
1
));
$rows = $adb->num_rows($query);
$keyFields = array();
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $setype);
$commentModule = CTWhatsApp_Record_Model::checkCommentModuleEnable($setype);
$ModCommentsEnable = CTWhatsApp_Record_Model::checkPermissionModule("ModComments");
$actionName = "EditView";
if (! Users_Privileges_Model::isPermitted($setype, $actionName, $recordId)) {
$permissionRecord = "0";
} else {
$permissionRecord = "1";
}
$themeView = CTWhatsApp_Record_Model::getWhatsappTheme();
$keyFieldsHTML = '';
if ($permissionRecord == 1) {
for ($i = 0; $i < $rows; $i ++) {
if ($i < 4) {
$fieldlabel = vtranslate($adb->query_result($query, $i, "fieldlabel"), $setype);
$fieldname = $adb->query_result($query, $i, "fieldname");
$fieldvalue = $recordModel->get($fieldname);
if ($fieldname == "assigned_user_id") {
$getusername = $adb->pquery("SELECT * FROM vtiger_users WHERE id=?", array(
$fieldvalue
));
$userrows = $adb->num_rows($getusername);
if ($userrows == 0) {
$getgroup = $adb->pquery("SELECT * FROM vtiger_groups WHERE groupid=?", array(
$fieldvalue
));
$grouprows = $adb->num_rows($getgroup);
$fieldvalue = $adb->query_result($getgroup, 0, "groupname");
} else {
$fieldvalue = $adb->query_result($getusername, 0, "first_name") . " " . $adb->query_result($getusername, 0, "last_name");
}
}
if ($themeView == "RTL") {
$keyFieldsHTML .= "<p><span class="">" . $fieldvalue . "</span> : " . $fieldlabel . "</p>";
} else {
$keyFieldsHTML .= "<p>" . $fieldlabel . " : <span class="">" . $fieldvalue . "</span></p>";
}
}
}
}
$relatedModules = CTWhatsApp_Record_Model::getRelatedModules($setype);
$relatedModuleHTML = '';
foreach ($relatedModules as $key => $value) {
$relatedModule = vtranslate($value["relatedModule"], $value["relatedModule"]);
$moduleURL = "index.php?module=" . $value["relatedModule"] . "&view=QuickCreateAjax&" . $value["relatedFieldName"] . "=" . $recordId;
$relatedModuleHTML .= "<a id="menubar_quickCreate_" . $value["relatedModule"] . "" class="dropdown-item quickCreateModule" href="#" data-name="" . $value["relatedModule"] . "" data-url="" . $moduleURL . "">" . $relatedModule . "</a>";
}
$moduleRecrodData = array(
"recordId" => $recordId,
"label" => $label,
"phone" => $phone,
"profileImage" => $profileImage,
"imagetag" => $imagetag,
"whatsappMessages" => $whatsappMessageHTML,
"keyFieldsHTML" => $keyFieldsHTML,
"totalSent" => $totalSent,
"totalReceived" => $totalReceived,
"recentComments" => $recentComments,
"relatedModuleHTML" => $relatedModuleHTML,
"messageImportant" => $messageImportant,
"setype" => $setype,
"commentModule" => $commentModule,
"moduleIsEnable" => $moduleIsEnable,
"ModCommentsEnable" => $ModCommentsEnable,
"permissionRecord" => $permissionRecord
);
return $moduleRecrodData;
}
public function getMessagesRecordData($recordId, $whatsappModule, $groupid)
{
global $adb;
$label = $recordId;
if ($groupid) {
$profileImage = "layouts/v7/modules/CTWhatsApp/image/groups.png";
} else {
$profileImage = "layouts/v7/modules/CTWhatsApp/image/AvtarIcon.png";
}
$imagetag = 1;
$getWhatsappMessages = CTWhatsApp_Record_Model::getWhatsappMessages($recordId, $setype, $whatsappModule, $groupid);
$whatsappMessageHTML = $getWhatsappMessages["whatsappMessageHTML"];
$totalSent = $getWhatsappMessages["totalSent"];
$totalReceived = $getWhatsappMessages["totalReceived"];
$messageImportant = $getWhatsappMessages["messageImportant"];
$moduleIsEnable = $getWhatsappMessages["moduleIsEnable"];
$recentComments = '';
$themeView = CTWhatsApp_Record_Model::getWhatsappTheme();
if ($themeView == "RTL") {
$keyFieldsHTML = "<p><span class="">" . $recordId . "</span> : " . vtranslate("LBL_PHONE_NUMBER", "Vtiger") . "</p>";
} else {
$keyFieldsHTML = "<p>" . vtranslate("LBL_PHONE_NUMBER", "Vtiger") . " : <span class="">" . $recordId . "</span></p>";
}
$relatedModules = CTWhatsApp_Record_Model::getWhatsappAllowModules();
$commentModule = CTWhatsApp_Record_Model::checkCommentModuleEnable($setype);
$ModCommentsEnable = CTWhatsApp_Record_Model::checkPermissionModule("ModComments");
$relatedModuleHTML = '';
foreach ($relatedModules as $key => $value) {
$relatedModule = vtranslate($value["module"], $value["module"]);
$moduleURL = "index.php?module=" . $value["module"] . "&view=QuickCreateAjax&" . $value["phoneField"] . "=" . $recordId;
$relatedModuleHTML .= "<a id="menubar_quickCreate_" . $value["module"] . "" class="dropdown-item quickCreateModule" href="#" data-name="" . $value["module"] . "" data-url="" . $moduleURL . "">" . $relatedModule . "</a>";
}
$moduleRecrodData = array(
"label" => $label,
"phone" => $recordId,
"profileImage" => $profileImage,
"imagetag" => $imagetag,
"whatsappMessages" => $whatsappMessageHTML,
"totalSent" => $totalSent,
"totalReceived" => $totalReceived,
"keyFieldsHTML" => $keyFieldsHTML,
"recentComments" => $recentComments,
"relatedModuleHTML" => $relatedModuleHTML,
"messageImportant" => $messageImportant,
"commentModule" => $commentModule,
"moduleIsEnable" => $moduleIsEnable,
"ModCommentsEnable" => $ModCommentsEnable
);
return $moduleRecrodData;
}
public function getWhatsappMessages($recordId, $setype, $whatsappModule, $groupid)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
if ($whatsappModule == "Groups") {
$customQuery = " AND msgid = ?";
$query = $adb->pquery($unreadQuery . $customQuery, array(
$groupid
));
} else {
if ($setype) {
$customQuery = " AND whatsapp_contactid = ?";
$query = $adb->pquery($unreadQuery . $customQuery, array(
$recordId
));
} else {
$recordId = preg_replace("/[^A-Za-z0-9]/", '', $recordId);
$customQuery = " AND whatsapp_withccode LIKE "%" . $recordId . "%"";
$query = $adb->pquery($unreadQuery . $customQuery, array());
}
}
$rows = $adb->num_rows($query);
$totalSent = 0;
$totalReceived = 0;
$whatsappMessage = array();
$whatsappMessageHTML = "<div class="chatDiv">";
$imgExts = array(
"gif",
"jpg",
"jpeg",
"png",
"tiff",
"tif"
);
$fileExts = array(
"pdf",
"txt",
"php",
"zip",
"csv",
"docx",
"https"
);
for ($i = 0; $i < $rows; $i ++) {
$ctWhatsappId = $adb->query_result($query, $i, "ctwhatsappid");
$messageImportant = $adb->query_result($query, $i, "whatsapp_important");
$messageType = $adb->query_result($query, $i, "message_type");
$messageReadUnRead = $adb->query_result($query, $i, "whatsapp_unreadread");
$messageSenderame = $adb->query_result($query, $i, "whatsapp_sendername");
$isGroup = $adb->query_result($query, $i, "whatsapp_withccode");
if ($ctWhatsappId) {
if ($messageReadUnRead == "Unread" && $messageType == "Recieved") {
$recordModel = Vtiger_Record_Model::getInstanceById($ctWhatsappId, "CTWhatsApp");
$recordModel->set("mode", "edit");
$recordModel->set("id", $ctWhatsappId);
$recordModel->set("whatsapp_unreadread", "Read");
$recordModel->save();
}
}
$messageBody = nl2br(preg_replace("#\*([^*]+)\*#", "<b>$1</b>", $adb->query_result($query, $i, "message_body")));
$urlExt = pathinfo($messageBody, PATHINFO_EXTENSION);
if (in_array($urlExt, $imgExts)) {
$messageBody = "<image src="" . $messageBody . "" style="height: 60px;">";
} else {
if (in_array($urlExt, $fileExts)) {
$messageBody = "<a href="" . $messageBody . "" target="_black">" . $messageBody . "</a>";
}
}
$createdTime = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($adb->query_result($query, $i, "whatsapp_datetime"));
$whatsappMessage[] = array(
"messageType" => $messageType,
"messageBody" => $messageBody,
"createdTime" => $createdTime
);
if ($messageType == "Send" || $messageType == "Mass Message") {
$totalSent = $totalSent + 1;
$whatsappMessageHTML .= "<div class="sendChat">
\x9\x9\x9 \x9\x9\x9\x9\x9\x9<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
\x9 \x9\x9\x9 \x9\x9</div>
\x9 \x9\x9\x9 \x9\x9\x9\x9<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">\xa\x9\x9\x9\x9 \x9\x9\x9</div>\xa \x9 \x9\x9\x9\x9\x9<div class="col-xs-10 col-sm-8 col-md-8 col-lg-8"> \xa \x9\x9\x9 \x9\x9\x9\x9\x9\x9\x9<div class="bubble send">\xa\x9 \x9 \x9 \x9\x9<p style="word-wrap: break-word;">" . $messageBody . "</p>\xa \x9 \x9 \x9 \x9\x9 </div>\xa\x9 \x9 \x9\x9 \x9\x9\x9 <span class="chatTime">" . $createdTime . '';
if ($messageReadUnRead == "Read") {
$whatsappMessageHTML .= "<img src="layouts/v7/modules/CTWhatsApp/image/read.png">";
} else {
$whatsappMessageHTML .= "<img src="layouts/v7/modules/CTWhatsApp/image/unread.png">";
}
$whatsappMessageHTML .= "</span></div>\xa\x9\x9\x9\x9 </div>";
} else {
if ($messageType == "Recieved") {
$totalReceived = $totalReceived + 1;
$whatsappMessageHTML .= "<div class="replyChat">
\x9 \x9\x9\x9 <div class="col-xs-10 col-sm-8 col-md-8 col-lg-8">\xa \x9\x9 \x9\x9\x9 \x9\x9<div class="bubble reply">";
if ($isGroup == "Groups") {
$whatsappMessageHTML .= "<span><b>" . $messageSenderame . "</b></span>";
}
$whatsappMessageHTML .= "<p style="word-wrap: break-word;">" . $messageBody . "</p>
\x9\x9 \x9\x9\x9\x9\x9</div>\xa\x9\x9\x9\x9\x9 \x9\x9 \x9\x9<span class="chatTime" style="width: 35%; !important">" . $createdTime . '';
if ($messageReadUnRead == "Read") {
$whatsappMessageHTML .= "<img src="layouts/v7/modules/CTWhatsApp/image/read.png">";
} else {
$whatsappMessageHTML .= "<img src="layouts/v7/modules/CTWhatsApp/image/unread.png">";
}
$whatsappMessageHTML .= "</span></div>";
if ($setype) {
if (in_array($urlExt, $imgExts)) {
$whatsappMessageHTML .= '';
} else {
$whatsappMessageHTML .= "
\x9 <span class="editField" style="cursor: pointer;">
\x9\x9<img style="float: left;margin-left: -2px;width: 15px; !important" src="layouts/v7/modules/CTWhatsApp/image/editcontent.png" title="" . vtranslate("LBL_EDITFIELD", "CTWhatsApp") . " " . vtranslate($setype, $setype) . "">\xa\x9\x9 \x9 </span>";
}
}
$whatsappMessageHTML .= "<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">\xa\x9 \x9 \x9 \x9\x9</div>
\xa\x9\x9\x9 \x9\x9\x9\x9\x9\x9</div>";
}
}
}
$whatsappMessageHTML .= "</div>";
$moduleIsEnable = CTWhatsApp_Record_Model::getmoduleIsEnable($setype);
if ($setype) {
$pagingModel = new Vtiger_Paging_Model();
$recentComments = ModComments_Record_Model::getRecentComments($recordId, $pagingModel);
$comments = array();
$commentHTML = '';
foreach ($recentComments as $key => $value) {
if ($key < 2) {
$commentcontent = $recentComments[$key]->get("commentcontent");
$createdtime = $recentComments[$key]->get("createdtime");
$smownerid = $recentComments[$key]->get("smownerid");
$commentHTML .= "<div class="comment1">\xa \x9\x9 \x9 \x9\x9 <!-- <div class="pic"><img src="layouts/v7/modules/CTWhatsApp/image/pic4.png" /></div> -->
\x9\x9\x9\x9\x9 <div class="pName">\xa \x9 \x9 \x9 \x9<div class="pText">
\x9\x9 \x9 \x9\x9\x9<span>" . Vtiger_Functions::getUserName($smownerid) . "</span>\xa \x9 \x9 \x9\x9<span class="time">" . Vtiger_Util_Helper::formatDateDiffInStrings($createdtime) . "</span>
\x9\x9\x9 \x9 \x9 \x9 \x9<p>" . decode_html($commentcontent) . "</p>\xa\x9\x9\x9\x9 \x9 \x9\x9</div>
\x9 \x9 \x9\x9 </div>
\x9\x9\x9 \x9\x9 </div>";
}
if ($key > 3) {
$moreCommentLink = "<span class='pull-right' style='color: blue;'><a href='index.php?module=" . $setype . "&relatedModule=ModComments&view=Detail&record=" . $recordId . "&mode=showRelatedList' target='_black'>" . vtranslate("LBL_SHOW_MORE", "Vtiger") . "</a><span>";
}
}
}
$messageData = array(
"whatsappMessageHTML" => $whatsappMessageHTML,
"totalSent" => $totalSent,
"totalReceived" => $totalReceived,
"commentHTML" => $commentHTML . $moreCommentLink,
"messageImportant" => $messageImportant,
"moduleIsEnable" => $moduleIsEnable
);
return $messageData;
}
function getRelatedModules($moduleName)
{
global $adb;
$tabid = getTabid($moduleName);
$getRelatedModuleQuery = $adb->pquery("SELECT * FROM vtiger_relatedlists WHERE tabid = ? AND presence = 0 AND related_tabid NOT IN(8,9,10,20,21,22,23,35,43) AND actions LIKE '%ADD%'", array(
$tabid
));
$relatedModulesRows = $adb->num_rows($getRelatedModuleQuery);
$relatedModuleArray = array();
for ($j = 0; $j < $relatedModulesRows; $j ++) {
$relatedModuleTabid = $adb->query_result($getRelatedModuleQuery, $j, "related_tabid");
$getModuleNameQuery = $adb->pquery("SELECT * FROM vtiger_tab WHERE tabid = ? AND presence = 0", array(
$relatedModuleTabid
));
$relatedModule = $adb->query_result($getModuleNameQuery, 0, "name");
if ($relatedModule != '') {
$data = CTWhatsApp_Record_Model::checkPermissionModule($relatedModule);
if ($data == 1) {
$getRelatedFieldNameQuery = $adb->pquery("SELECT vtiger_field.fieldname FROM vtiger_relatedlists INNER JOIN vtiger_field ON vtiger_field.fieldid = vtiger_relatedlists.relationfieldid WHERE vtiger_relatedlists.related_tabid = ? AND vtiger_relatedlists.tabid = ?", array(
$relatedModuleTabid,
$tabid
));
$relatedFieldName = $adb->query_result($getRelatedFieldNameQuery, 0, "fieldname");
$relatedModuleArray[$relatedModule] = array(
"relatedModule" => $relatedModule,
"relatedFieldName" => $relatedFieldName
);
}
}
}
return $relatedModuleArray;
}
public function checkPermissionModule($moduleName)
{
$moduleName = $moduleName;
$record = '';
$actionName = "CreateView";
if (! Users_Privileges_Model::isPermitted($moduleName, $actionName, $record)) {
return 0;
} else {
return 1;
}
}
public function setMessagesImportant($recordId, $messagesImportant)
{
global $adb;
$setype = VtigerCRMObject::getSEType($recordId);
if ($messagesImportant == 0) {
$query = "UPDATE vtiger_ctwhatsapp SET whatsapp_important = 1";
} else {
$query = "UPDATE vtiger_ctwhatsapp SET whatsapp_important = 0";
}
if ($setype) {
$customQuery = " WHERE whatsapp_contactid = ?";
} else {
$customQuery = " WHERE whatsapp_withccode = ?";
}
$updateQuery = $adb->pquery($query . $customQuery, array(
$recordId
));
return 1;
}
public function getAllNewUnreadMessages($recordId, $moduleName, $individulMessage)
{
global $adb;
$setype = VtigerCRMObject::getSEType($recordId);
if ($setype) {
$customQuery = " AND whatsapp_contactid = ?";
} else {
if (strpos($recordId, "@g.us") !== false) {
$customQuery = " AND msgid = ?";
} else {
$customQuery = " AND whatsapp_withccode = ?";
}
}
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $unreadQuery . $customQuery . " AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread' AND vtiger_ctwhatsapp.message_type = 'Recieved'";
$queryResult = $adb->pquery($query, array(
$recordId
));
$rows = $adb->num_rows($queryResult);
$whatsappMessageHTML = '';
$imgExts = array(
"gif",
"jpg",
"jpeg",
"png",
"tiff",
"tif"
);
$fileExts = array(
"pdf",
"txt",
"php",
"zip",
"csv"
);
for ($i = 0; $i < $rows; $i ++) {
$ctwhatsappId = $adb->query_result($queryResult, $i, "ctwhatsappid");
$senderName = $adb->query_result($queryResult, $i, "whatsapp_sendername");
$messageType = $adb->query_result($queryResult, $i, "message_type");
$messageReadUnRead = $adb->query_result($queryResult, $i, "whatsapp_unreadread");
$messageBody = nl2br(preg_replace("#\*([^*]+)\*#", "<b>$1</b>", $adb->query_result($queryResult, $i, "message_body")));
if ($ctwhatsappId) {
if ($messageReadUnRead == "Unread" && $messageType == "Recieved") {
$recordModel = Vtiger_Record_Model::getInstanceById($ctwhatsappId, "CTWhatsApp");
$recordModel->set("mode", "edit");
$recordModel->set("id", $ctwhatsappId);
$recordModel->set("whatsapp_unreadread", "Read");
$recordModel->save();
}
}
$urlExt = pathinfo($messageBody, PATHINFO_EXTENSION);
if ($urlExt) {
if (in_array($urlExt, $imgExts)) {
$messageBody = "<image src="" . $messageBody . "" style="height: 60px;">";
} else {
if (in_array($urlExt, $fileExts)) {
$messageBody = "<a href="" . $messageBody . "" target="_black">" . $messageBody . "</a>";
}
}
} else {
$messageBody = $messageBody;
if ($individulMessage == 1) {
$style = " ";
} else {
$style = "style='float: left;margin-left: -2px;width: 15px;'";
}
if ($setype) {
$editFieldHTML = "
<span class='editField'><img src='layouts/v7/modules/CTWhatsApp/image/editcontent.png' title='{vtranslate('LBL_EDITFIELD','CTWhatsaApp')} {vtranslate(" . $moduleName . "," . $moduleName . ")}' " . $style . "></span>";
}
}
$createdTime = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($adb->query_result($queryResult, $i, "whatsapp_datetime"));
if ($individulMessage == 1) {
$whatsappMessageHTML .= "<div class="message received">\xa\x9\x9 \x9 \x9 \x9 " . $messageBody . "
<span class="metadata">
\x9 \x9 \x9\x9\x9 \x9<span class="time"><b>" . $senderName . "</b> " . $createdTime . "</span> ";
if ($messageReadUnRead == "Unread") {
$whatsappMessageHTML .= "<img src="layouts/v7/modules/CTWhatsApp/image/unread.png"/>";
} else {
$whatsappMessageHTML .= "<img src="layouts/v7/modules/CTWhatsApp/image/read.png"/>";
}
$whatsappMessageHTML .= "</span> \xa </div>";
$whatsappMessageHTML .= $editFieldHTML;
} else {
$whatsappMessageHTML .= "<div class="replyChat">
\x9\x9\x9\x9\x9 \x9\x9 <div class="col-xs-10 col-sm-8 col-md-8 col-lg-8">\xa\x9\x9\x9 \x9\x9 \x9<div class="bubble reply">
\x9\x9 \x9\x9 \x9 <span><b>" . $senderName . "</b></span>
\x9 \x9 \x9 <p>" . $messageBody . "</p>
\x9 \x9 \x9\x9 </div>\xa \x9 \x9\x9 \x9 \x9<span class="chatTime" style="width: 35%; !important">" . $createdTime . '';
if ($messageReadUnRead == "Unread") {
$whatsappMessageHTML .= "<img src="layouts/v7/modules/CTWhatsApp/image/unread.png"/>";
} else {
$whatsappMessageHTML .= "<img src="layouts/v7/modules/CTWhatsApp/image/read.png"/>";
}
$whatsappMessageHTML .= "</span> </div>";
$whatsappMessageHTML .= $editFieldHTML;
$whatsappMessageHTML .= "<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
\x9 \x9\x9 \x9\x9</div>\xa\x9\x9 \x9\x9 \x9\x9</div>";
}
}
$unreadArray = array(
"rows" => $rows,
"whatsappMessageHTML" => $whatsappMessageHTML
);
return $unreadArray;
}
public function getIndividualMessages($recordId)
{
global $adb;
$whatsappQuery = CTWhatsApp_Record_Model::unreadQuery();
$setype = VtigerCRMObject::getSEType($recordId);
if ($setype) {
$query = $whatsappQuery . " AND vtiger_ctwhatsapp.whatsapp_contactid = ?";
$queryResult = $adb->pquery($query, array(
$recordId
));
} else {
$recordId = preg_replace("/[^A-Za-z0-9]/", '', $recordId);
$query = $whatsappQuery . " AND vtiger_ctwhatsapp.whatsapp_withccode LIKE "%" . $recordId . "%"";
$queryResult = $adb->pquery($query, array());
}
$rows = $adb->num_rows($queryResult);
$imgExts = array(
"gif",
"jpg",
"jpeg",
"png",
"tiff",
"tif"
);
$fileExts = array(
"pdf",
"txt",
"php",
"zip",
"csv"
);
$whatsappMessages = array();
for ($i = 0; $i < $rows; $i ++) {
$ctwhatsappId = $adb->query_result($queryResult, $i, "ctwhatsappid");
$messageType = $adb->query_result($queryResult, $i, "message_type");
$senderName = $adb->query_result($queryResult, $i, "whatsapp_sendername");
$messageReadUnRead = $adb->query_result($queryResult, $i, "whatsapp_unreadread");
if ($ctwhatsappId) {
if ($messageReadUnRead == "Unread" && $messageType == "Recieved") {
$recordModel = Vtiger_Record_Model::getInstanceById($ctwhatsappId, "CTWhatsApp");
$recordModel->set("mode", "edit");
$recordModel->set("id", $ctwhatsappId);
$recordModel->set("whatsapp_unreadread", "Read");
$recordModel->save();
}
}
$messageBody = nl2br(preg_replace("#\*([^*]+)\*#", "<b>$1</b>", $adb->query_result($queryResult, $i, "message_body")));
$urlExt = pathinfo($messageBody, PATHINFO_EXTENSION);
if (in_array($urlExt, $imgExts)) {
$messageBody = "<image src="" . $messageBody . "" style="height: 60px;">";
} else {
if (in_array($urlExt, $fileExts)) {
$messageBody = "<a href="" . $messageBody . "" target="_black">" . $messageBody . "</a>";
}
}
$createdTime = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($adb->query_result($queryResult, $i, "whatsapp_datetime"));
$whatsappMessages[] = array(
"messageType" => $messageType,
"messageBody" => $messageBody,
"createdTime" => $createdTime,
"senderName" => $senderName,
"messageReadUnRead" => $messageReadUnRead
);
}
return $whatsappMessages;
}
public function checkCommentModuleEnable($sourceModuleName)
{
global $adb;
$modCommentQuery = $adb->pquery("SELECT * FROM vtiger_tab WHERE name = 'ModComments' AND presence = 0", array());
$commentRows = $adb->num_rows($modCommentQuery);
if ($commentRows) {
$commentTabid = $adb->query_result($modCommentQuery, 0, "tabid");
$sourceModuleTabid = getTabid($sourceModuleName);
$enableCommentQuery = $adb->pquery("SELECT * FROM vtiger_relatedlists WHERE related_tabid = ? AND tabid = ?", array(
$commentTabid,
$sourceModuleTabid
));
$commentModuleEnable = $adb->num_rows($enableCommentQuery);
}
return $commentModuleEnable;
}
public function sendIndividulMessage($request)
{
global $adb, $site_URL, $current_user, $root_directory;
$moduleName = $request->getModule();
$whatsappModule = $request->get("whatsappModule");
$wptemplateid = $request->get("wptemplateid");
if ($whatsappModule == "Groups") {
$mobileno = $request->get("mobileno");
} else {
$mobileno = preg_replace("/[^A-Za-z0-9]/", '', $request->get("mobileno"));
}
$msgbody = html_entity_decode($request->get("msgbody"));
$moduleRecordid = $request->get("moduleRecordid");
if ($moduleRecordid == '') {
$moduleRecordid = $request->get("module_recordid");
}
$base64imagedata = $request->get("base64imagedata");
$filename = $request->get("filename");
$filetype = $request->get("filetype");
$fileURL = '';
$date_var = date("Y-m-d H:i:s");
$currenUserID = $current_user->id;
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$api_url = $configurationData["api_url"];
$auth_token = $configurationData["authtoken"];
$customfield1 = $configurationData["customfield1"];
$whatsappScanNo = $configurationData["whatsappno"];
$whatsappStatus = $configurationData["whatsappstatus"];
$mobilenoLen = strlen($mobileno);
if ($mobilenoLen > 10 && $customfield1 != '') {
$withoutcode = substr($mobileno, - 10);
$mobileno = $customfield1 . $withoutcode;
} else {
$mobileno = $customfield1 . $mobileno;
}
if ($base64imagedata != '' || $wptemplateid != '') {
$whatsappFolderPath = "/modules/CTWhatsApp/CTWhatsAppStorage/";
$year = date("Y");
$month = date("F");
$day = date("j");
$week = '';
if (! is_dir($root_directory . $whatsappFolderPath)) {
mkdir($root_directory . $whatsappFolderPath);
chmod($root_directory . $whatsappFolderPath, 511);
}
if (! is_dir($root_directory . $whatsappFolderPath . $year)) {
mkdir($root_directory . $whatsappFolderPath . $year);
chmod($root_directory . $whatsappFolderPath . $year, 511);
}
if (! is_dir($root_directory . $whatsappFolderPath . $year . "/" . $month)) {
mkdir($root_directory . $whatsappFolderPath . "{$year}/{$month}/");
chmod($root_directory . $whatsappFolderPath . "{$year}/{$month}/", 511);
}
if ($day > 0 && $day <= 7) {
$week = "week1";
} elseif ($day > 7 && $day <= 14) {
$week = "week2";
} elseif ($day > 14 && $day <= 21) {
$week = "week3";
} elseif ($day > 21 && $day <= 28) {
$week = "week4";
} else {
$week = "week5";
}
if (! is_dir($root_directory . $whatsappFolderPath . $year . "/" . $month . "/" . $week)) {
mkdir($root_directory . $whatsappFolderPath . "{$year}/{$month}/{$week}/");
chmod($root_directory . $whatsappFolderPath . "{$year}/{$month}/{$week}/", 511);
}
}
if ($wptemplateid) {
$getWhatsappTemplateQuery = $adb->pquery("SELECT * FROM vtiger_ctwhatsapptemplates \xa\x9\x9 \x9INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapptemplates.ctwhatsapptemplatesid
INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.crmid = vtiger_ctwhatsapptemplates.ctwhatsapptemplatesid \xa \x9\x9 INNER JOIN vtiger_attachments ON vtiger_attachments.attachmentsid = vtiger_seattachmentsrel.attachmentsid\xa\x9 \x9\x9WHERE vtiger_crmentity.deleted = 0 AND vtiger_ctwhatsapptemplates.ctwhatsapptemplatesid = ?", array(
$wptemplateid
));
$isTemplates = $adb->num_rows($getWhatsappTemplateQuery);
if ($isTemplates) {
$templatesID = $adb->query_result($getWhatsappTemplateQuery, 0, "ctwhatsapptemplatesid");
$templateMsg = $adb->query_result($getWhatsappTemplateQuery, 0, "wptemplate_text");
$wptemplateImage = $adb->query_result($getWhatsappTemplateQuery, 0, "name");
if ($moduleRecordid) {
$bodydata = str_replace("\r\n", " ", html_entity_decode($templateMsg));
$setype = VtigerCRMObject::getSEType($moduleRecordid);
$msgbody = getMergedDescription($bodydata, $moduleRecordid, $setype);
} else {
$msgbody = str_replace("\r\n", " ", html_entity_decode($templateMsg));
}
$getAttachmentQuery = $adb->pquery("SELECT vtiger_attachments.*, vtiger_crmentity.setype FROM vtiger_attachments\xa\x9\x9\x9\x9 INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid\xa\x9\x9 INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_attachments.attachmentsid\xa \x9 \x9WHERE vtiger_seattachmentsrel.crmid = ? AND vtiger_crmentity.deleted = 0", array(
$templatesID
));
$imageId = $adb->query_result($getAttachmentQuery, 0, "attachmentsid");
$imagePath = $adb->query_result($getAttachmentQuery, 0, "path");
$imageName = $adb->query_result($getAttachmentQuery, 0, "name");
$attachmentPath = $root_directory . $imagePath . $imageId . "_" . $imageName;
$newfile = $root_directory . $whatsappFolderPath . "{$year}/{$month}/{$week}/" . $imageName;
copy($attachmentPath, $newfile);
$newfileURL = $site_URL . $whatsappFolderPath . "{$year}/{$month}/{$week}/" . $imageName;
$url = $api_url . "/" . $auth_token . "/sendwithcaption";
$postfields = array(
"number" => $mobileno,
"msg" => urlencode(htmlspecialchars_decode($msgbody, ENT_QUOTES)),
"url" => $newfileURL
);
}
} else {
if ($base64imagedata != '') {
$documentpath = "storage";
$filepath = "storage/";
$year = date("Y");
$month = date("F");
$day = date("j");
$week = '';
if (! is_dir($root_directory . $filepath . $year)) {
mkdir($root_directory . $filepath . $year);
chmod($root_directory . $filepath . $year, 511);
}
if (! is_dir($root_directory . $filepath . $year . "/" . $month)) {
mkdir($root_directory . $filepath . "{$year}/{$month}");
chmod($root_directory . $filepath . "{$year}/{$month}", 511);
}
if ($day > 0 && $day <= 7) {
$week = "week1";
} elseif ($day > 7 && $day <= 14) {
$week = "week2";
} elseif ($day > 14 && $day <= 21) {
$week = "week3";
} elseif ($day > 21 && $day <= 28) {
$week = "week4";
} else {
$week = "week5";
}
if (! is_dir($root_directory . $filepath . $year . "/" . $month . "/" . $week)) {
mkdir($root_directory . $filepath . "{$year}/{$month}/{$week}");
chmod($root_directory . $filepath . "{$year}/{$month}/{$week}", 511);
}
$target_file = $root_directory . $filepath . $year . "/" . $month . "/" . $week . "/";
list ($type, $base64imagedata) = explode(";", $base64imagedata);
list (, $base64imagedata) = explode(",", $base64imagedata);
$base64imagedata = base64_decode($base64imagedata);
$filemove = file_put_contents($target_file . $filename, $base64imagedata);
if ($filemove) {
$Document = Vtiger_Record_Model::getCleanInstance("Documents");
$Document->set("mode", '');
$Document->set("assigned_user_id", $current_user->id);
$Document->set("folderid", 1);
$Document->set("filelocationtype", "I");
$Document->set("filestatus", 1);
$Document->set("filename", $filename);
$Document->save();
$documentid = $Document->getId();
$current_id = $adb->getUniqueID("vtiger_crmentity");
$sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?, ?, ?, ?, ?, ?, ?)";
$params1 = array(
$current_id,
$current_user->id,
1,
"Documents Attachment",
'',
$adb->formatDate($date_var, true),
$adb->formatDate($date_var, true)
);
$adb->pquery($sql1, $params1);
rename($target_file . $filename, $target_file . $current_id . "_" . $filename);
chmod($target_file, 511);
$sql2 = "insert into vtiger_attachments(attachmentsid, name, description, type, path) values(?, ?, ?, ?, ?)";
$params2 = array(
$current_id,
$filename,
'',
'',
$filepath . $year . "/" . $month . "/" . $week . "/"
);
$result = $adb->pquery($sql2, $params2);
$sql3 = "insert into vtiger_seattachmentsrel values(?,?)";
$adb->pquery($sql3, array(
$documentid,
$current_id
));
$sql4 = "insert into vtiger_senotesrel values(?,?)";
$adb->pquery($sql4, array(
$moduleRecordid,
$documentid
));
}
$fileURL = $site_URL . $filepath . $year . "/" . $month . "/" . $week . "/" . $current_id . "_" . $filename;
$oldfile = $root_directory . $filepath . $year . "/" . $month . "/" . $week . "/" . $current_id . "_" . $filename;
$filename = str_replace(" ", '', $filename);
$newfile = $root_directory . $whatsappFolderPath . "{$year}/{$month}/{$week}/" . $filename;
copy($oldfile, $newfile);
$newfileURL = $site_URL . $whatsappFolderPath . "{$year}/{$month}/{$week}/" . $filename;
}
if ($fileURL) {
if ($filetype == "image/jpeg" || $filetype == "image/jpg" || $filetype == "image/png") {
$url = $api_url . "/" . $auth_token . "/sendfileurl";
$postfields = array(
"number" => $mobileno,
"url" => $newfileURL
);
} else {
$url = $api_url . "/" . $auth_token . "/sendfileurl";
$postfields = array(
"number" => $mobileno,
"url" => urlencode($newfileURL)
);
}
} else {
$url = $api_url . "/" . $auth_token . "/send";
$postfields = array(
"number" => $mobileno,
"msg" => urlencode($msgbody)
);
}
}
if ($whatsappStatus == 1) {
$val = CTWhatsApp_WhatsappChat_View::callCURL($url, $postfields);
if ($val) {
$getLicenseDetail = CTWhatsApp_Record_Model::getWhatsAppLicenseDetail();
$licenseKey = $getLicenseDetail["licenseKey"];
$getWhatsappAccount = CTWhatsApp_Record_Model::getWhatsappAccountDetail($licenseKey);
$oneDayMessages = CTWhatsApp_Record_Model::getOneDaysMessages();
$module_Name = "CTWhatsApp";
$currentusername = $current_user->first_name . " " . $current_user->last_name;
$recordModel = Vtiger_Record_Model::getCleanInstance($module_Name);
$recordModel->set("whatsapp_sendername", $currentusername);
$recordModel->set("whatsapp_chatid", $val["message"]);
if ($whatsappModule == "Groups") {
$recordModel->set("msgid", $mobileno);
$recordModel->set("whatsapp_withccode", "Groups");
} else {
$recordModel->set("msgid", $val["id"]["id"]);
$recordModel->set("whatsapp_withccode", $mobileno);
}
$recordModel->set("message_type", "Send");
if ($fileURL) {
$recordModel->set("message_body", $newfileURL);
} else {
$recordModel->set("message_body", $msgbody);
}
$recordModel->set("whatsapp_contactid", $moduleRecordid);
$recordModel->set("whatsapp_unreadread", "Unread");
$recordModel->set("whatsapp_fromno", $whatsappScanNo);
$recordModel->set("whatsapp_datetime", $adb->formatDate($date_var, true));
if ($getWhatsappAccount == "free" && $oneDayMessages < "100") {
$recordModel->save();
} else {
if ($getWhatsappAccount == "premium") {
$recordModel->save();
}
}
}
$currenDatTime = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($date_var);
}
return $currenDatTime;
}
public function getallowToWhatsAppModule($request)
{
global $adb, $current_user;
$moduleName = $request->getModule();
$sourceModuleName = $request->get("source_module");
$recordid = $request->get("recordid");
$allowModuleData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($sourceModuleName);
$active = $allowModuleData["moduleIconActive"];
$phoneField = $allowModuleData["phoneField"];
$whatsappQuery = CTWhatsApp_Record_Model::unreadQuery();
$getUreadMsgQuery = $adb->pquery($whatsappQuery . " AND vtiger_ctwhatsapp.whatsapp_contactid = ? AND vtiger_ctwhatsapp.message_type = 'Recieved' AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Unread'", array(
$recordid
));
$unreadmsg = $adb->num_rows($getUreadMsgQuery);
$currenUserID = $current_user->id;
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$iconActive = $configurationData["iconactive"];
$api_url = $configurationData["api_url"];
$auth_token = $configurationData["authtoken"];
$currentDate = date("Y-m-d");
$getexpiredate = $adb->pquery("SELECT * FROM vtiger_ctwhatsapp_license_setting");
$expirydate = $adb->query_result($getexpiredate, 0, "expirydate");
$licenseKey = $adb->query_result($getexpiredate, 0, "license_key");
$date = Settings_CTWhatsApp_ConfigurationDetail_View::encrypt_decrypt($expirydate, $action = "d");
if (strtotime($currentDate) >= strtotime($date)) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.crmtiger.com/whatsapp/checkl.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13",
CURLOPT_POSTFIELDS => array(
"license_key" => $licenseKey
)
));
$response = curl_exec($curl);
curl_close($curl);
$resultResponse = json_decode($response, true);
if (strtotime($resultResponse["expirydate"]) >= strtotime($date)) {
$newdate = Settings_Whatsapp_ConfigurationDetail_View::encrypt_decrypt($resultResponse["expirydate"], $action = "e");
$adb->pquery("UPDATE vtiger_ctwhatsapp_license_setting set expirydate = '{$newdate}'");
}
}
$recordModel = Vtiger_Record_Model::getInstanceById($recordid, $source_module);
$fieldValue = preg_replace("/[^A-Za-z0-9]/", '', $recordModel->get($phoneField));
$result = array(
"iconActive" => $iconActive,
"date" => $date,
"currentDate" => $currentDate,
"active" => $active,
"unreadmsg" => $unreadmsg,
"fieldValue" => $fieldValue
);
return $result;
}
public function getWhatsAppLicenseDetail()
{
global $adb;
$getexpiredate = $adb->pquery("SELECT * FROM vtiger_ctwhatsapp_license_setting");
$rows = $adb->num_rows($getexpiredate);
$expiryDate = $adb->query_result($getexpiredate, 0, "expirydate");
$licenseKey = $adb->query_result($getexpiredate, 0, "license_key");
$domain = $adb->query_result($getexpiredate, 0, "domain");
return $licenseDetail = array(
"rows" => $rows,
"expiryDate" => $expiryDate,
"licenseKey" => $licenseKey,
"domain" => $domain
);
}
public function updateAuthCode($request)
{
global $adb, $current_user;
$currenUserID = $current_user->id;
$authTokenKey = $request->get("authtokenkey");
$configurationQuery = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield5 = ?", array(
$currenUserID
));
$row = $adb->num_rows($configurationQuery);
if ($row) {
if ($authTokenKey) {
$updatequery = $adb->pquery("UPDATE vtiger_ctwhatsappconfiguration SET auth_token=? WHERE customfield5 = ?", array(
$authTokenKey,
$currenUserID
));
}
}
}
public function getWhatsAppStatus($request)
{
global $adb, $current_user;
$currenUserID = $current_user->id;
$whatsappbot = $request->get("whatsappbot");
if ($whatsappbot == "yes") {
$getWhatsappStatusQuery = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield5 = 'whatsappBot'", array());
} else {
$getWhatsappStatusQuery = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield5 = ?", array(
$currenUserID
));
}
$whatsappStatus = $adb->query_result($getWhatsappStatusQuery, 0, "whatsappstatus");
$whatsappNo = $adb->query_result($getWhatsappStatusQuery, 0, "whatsappno");
$whatsappStatusArray = array(
"whatsappStatus" => $whatsappStatus,
"whatsappNo" => $whatsappNo
);
return $whatsappStatusArray;
}
public function getMassMessageData()
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappmassbatch");
$batch = $adb->query_result($query, 0, "batch");
$timeinterval = $adb->query_result($query, 0, "timeinterval");
$crondatetime = $adb->query_result($query, 0, "crondatetime");
$getMassMessageDetail = array(
"batch" => $batch,
"timeinterval" => $timeinterval,
"crondatetime" => $crondatetime
);
return $getMassMessageDetail;
}
public function sendMassMessages($request)
{
global $adb, $site_URL, $current_user;
$moduleName = $request->getModule();
$source_module = $request->get("source_module");
$templatesid = $request->get("templatesid");
$sendNowLater = $request->get("sendNowLater");
$laterDateTime = explode(" ", $request->get("laterDateTime"));
$cvid = $request->get("cvid");
$whatsappModuleFieldsData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($source_module);
$phoneField = $whatsappModuleFieldsData["phoneField"];
$selected_ids = $request->get("selected_ids");
if ($selected_ids == "all") {
$customViewModel = CustomView_Record_Model::getInstanceById($cvid);
$customViewModel->set("search_params", $request->get("searchvalue"));
$selected_ids = $customViewModel->getRecordIds($excludedIds, $source_module);
} else {
$selected_ids = $request->get("selected_ids");
}
if ($templatesid) {
$templatesID = $templatesid;
} else {
$templatesID = "0";
}
$msg_body = $request->get("msgbody");
$date_var = date("Y-m-d H:i:s");
$currentDate = date("Y-m-d H:i:s");
$currenUserID = $current_user->id;
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$api_url = $configurationData["api_url"];
$auth_token = $configurationData["authtoken"];
$customfield1 = $configurationData["customfield1"];
$getMassBatchConfiguration = Settings_CTWhatsApp_ConfigurationDetail_View::getMassBatchConfigurationData();
$selectBatch = $getMassBatchConfiguration["batch"];
if ($selectBatch) {
$getScheduleSendMsgidQuery = $adb->pquery("SELECT * FROM vtiger_ctwhatsappmassmessage GROUP BY massmessageid DESC LIMIT 0,1");
$schedulesendmsgid = $adb->query_result($getScheduleSendMsgidQuery, 0, "massmessageid") + 1;
if ($sendNowLater == "later") {
$cronDate_Time = $laterDateTime[0] . " " . Vtiger_Time_UIType::getTimeValueWithSeconds($laterDateTime[1] . " " . $laterDateTime[2]);
$cronDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($cronDate_Time);
$insertQuery = $adb->pquery("INSERT INTO vtiger_ctwhatsappmassmessage(massmessageid, templatesid, whatsappmessage, sendmessagedate, massmsgdatetime) VALUES (?,?,?,?,?)", array(
$schedulesendmsgid,
$templatesID,
$msg_body,
$currentDate,
$cronDateTime
));
} else {
$insertQuery = $adb->pquery("INSERT INTO vtiger_ctwhatsappmassmessage(massmessageid, templatesid, whatsappmessage, sendmessagedate, massmsgdatetime) VALUES (?,?,?,?,?)", array(
$schedulesendmsgid,
$templatesID,
$msg_body,
$currentDate,
''
));
}
foreach ($selected_ids as $key => $value) {
$scheduleSendmsgQuery = $adb->pquery("INSERT INTO vtiger_ctwhatsappschedulesendmsg(schedulesendmsgid, recordid, body, status, send_msg, datesendmessage) VALUES (?,?,?,?,?,?)", array(
$schedulesendmsgid,
$value,
$msg_body,
0,
0,
''
));
}
} else {
foreach ($selected_ids as $key => $value) {
$recordModelModel = Vtiger_Record_Model::getInstanceById($value, $source_module);
$mobileno = preg_replace("/[^A-Za-z0-9]/", '', $recordModelModel->get($phoneField));
$msgbody = getMergedDescription($msg_body, $value, $source_module);
$mobilenoLen = strlen($mobileno);
if ($mobilenoLen > 10 && $customfield1 != '') {
$withoutcode = substr($mobileno, - 10);
$sendsmsnumber = $customfield1 . $withoutcode;
} else {
$sendsmsnumber = $customfield1 . $mobileno;
}
$url = $api_url . "/" . $auth_token . "/send";
$postfields = array(
"number" => $sendsmsnumber,
"msg" => urlencode($msgbody)
);
$val = CTWhatsApp_WhatsappChat_View::callCURL($url, $postfields);
$currentusername = $current_user->first_name . " " . $current_user->last_name;
$module_Name = "CTWhatsApp";
$recordModel = Vtiger_Record_Model::getCleanInstance($module_Name);
$recordModel->set("whatsapp_sendername", $currentusername);
$recordModel->set("whatsapp_chatid", $val["message"]);
$recordModel->set("msgid", $val["id"]["id"]);
$recordModel->set("message_type", "Send");
$recordModel->set("message_body", $msgbody);
$recordModel->set("whatsapp_contactid", $value);
$recordModel->set("whatsapp_unreadread", "Unread");
$recordModel->set("whatsapp_withccode", $sendsmsnumber);
$recordModel->set("whatsapp_datetime", $adb->formatDate($date_var, true));
$recordModel->save();
}
}
}
public function getWhatsAppTemplateData($request)
{
global $adb, $root_directory;
$moduleName = $request->getModule();
$templatesid = $request->get("templatesid");
if ($templatesid) {
$recordModel = Vtiger_Record_Model::getInstanceById($templatesid, "CTWhatsAppTemplates");
$getAttachmentQuery = $adb->pquery("SELECT vtiger_attachments.*, vtiger_crmentity.setype FROM vtiger_attachments\xa \x9INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid\xa\x9 \x9INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_attachments.attachmentsid\xa\x9 \x9 WHERE vtiger_seattachmentsrel.crmid = ? AND vtiger_crmentity.deleted = 0", array(
$templatesid
));
$imageId = $adb->query_result($getAttachmentQuery, 0, "attachmentsid");
$imagePath = $adb->query_result($getAttachmentQuery, 0, "path");
$fileName = $adb->query_result($getAttachmentQuery, 0, "name");
$type = $adb->query_result($getAttachmentQuery, 0, "type");
if (strpos($type, "image") !== false) {
$fileType = 1;
} else {
$fileType = 0;
}
$attachmentPath = $imagePath . $imageId . "_" . $fileName;
$templateData = array(
"templatesid" => $templatesid,
"message" => decode_html($recordModel->get("wptemplate_text")),
"image" => $attachmentPath,
"fileType" => $fileType,
"fileName" => $fileName
);
}
return $templateData;
}
public function createWhatsappUser($currenUserID)
{
global $adb, $site_URL;
if ($currenUserID == "yes") {
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield5 = 'whatsappBot'", array());
} else {
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield5 = ?", array(
$currenUserID
));
}
$numrows = $adb->num_rows($query);
if ($numrows == 0) {
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$adminApiUrl = $configurationData["api_url"];
$contryCode = $configurationData["customfield1"];
$iconActive = $configurationData["iconactive"];
if ($currenUserID == "yes") {
$insertQuery = $adb->pquery("INSERT INTO vtiger_ctwhatsappconfiguration SET api_url='{$adminApiUrl}', customfield5='whatsappBot', customfield1='{$contryCode}', iconactive='{$iconActive}'", array());
} else {
$insertQuery = $adb->pquery("INSERT INTO vtiger_ctwhatsappconfiguration SET api_url='{$adminApiUrl}', customfield5='{$currenUserID}', customfield1='{$contryCode}', iconactive='{$iconActive}'", array());
}
}
$configurationUserData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$apiUrl = $configurationUserData["api_url"];
$whatsappStatus = $configurationUserData["whatsappstatus"];
$whatsappNo = $configurationData["whatsappno"];
if ($whatsappNo == '') {
$whatsappNo = $adb->query_result($query, 0, "whatsappno");
}
$getLicenseDetail = CTWhatsApp_DashBoard_View::getLicenseDetail();
$licenseKey = $getLicenseDetail["licenseKey"];
if ($whatsappNo == '') {
$qrcodeurl = $apiUrl . "/init";
$fields = array(
"url" => $site_URL . "/modules/CTWhatsApp/CTWhatAppReceiver.php",
"licenceKey" => $licenseKey,
"statusurl" => $site_URL . "/modules/CTWhatsApp/WhatsappStatus.php?userid=" . $currenUserID
);
foreach ($fields as $key => $value) {
$fieldsString .= $key . "=" . $value . "&";
}
rtrim($fieldsString, "&");
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $qrcodeurl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13",
CURLOPT_POSTFIELDS => $fieldsString
));
$result = curl_exec($curl);
$response = json_decode($result);
curl_close($curl);
$qrcodeurl = $response->qr;
$authTokenKey = $response->key;
$scanMessage = $response->message;
if ($authTokenKey) {
if ($currenUserID == "yes") {
$updatequery = $adb->pquery("UPDATE vtiger_ctwhatsappconfiguration SET auth_token=? WHERE customfield5 = 'whatsappBot'", array(
$authTokenKey
));
} else {
$updatequery = $adb->pquery("UPDATE vtiger_ctwhatsappconfiguration SET auth_token=? WHERE customfield5 = ?", array(
$authTokenKey,
$currenUserID
));
}
}
}
$qrCodeDetail = array(
"qrcodeurl" => $qrcodeurl,
"authTokenKey" => $authTokenKey,
"whatsappNo" => $whatsappNo,
"scanMessage" => $scanMessage
);
return $qrCodeDetail;
}
public function getWhatsappGroup()
{
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$apiUrl = $configurationData["api_url"];
$authToken = $configurationData["authtoken"];
$customfield1 = $configurationData["customfield1"];
$whatsappScanNo = $configurationData["whatsappno"];
$url = $apiUrl . "/" . $authToken . "/chatlist";
$postfields = array(
"number" => $whatsappScanNo
);
if ($whatsappScanNo) {
$getAllGroups = CTWhatsApp_WhatsappChat_View::callCURL($url, $postfields);
}
$groupsData = array();
foreach ($getAllGroups as $key => $value) {
if ($value["groupMetadata"]) {
$recordId = '';
$label = $value["name"];
$labelExplode = explode(" ", $label);
$profileImage = "layouts/v7/modules/CTWhatsApp/image/groups.png";
$imagetag = 1;
$groupid = $value["id"]["_serialized"];
$groupsData[$groupid] = array(
"recordId" => $recordId,
"label" => $label,
"profileImage" => $profileImage,
"imagetag" => $imagetag,
"groupid" => $groupid
);
}
if ($value["id"]["server"] == "broadcast") {
$recordId = '';
$label = $value["name"];
$labelExplode = explode(" ", $label);
$profileImage = "layouts/v7/modules/CTWhatsApp/image/groups.png";
$imagetag = 1;
$groupid = $value["id"]["_serialized"];
$groupsData[$groupid] = array(
"recordId" => $recordId,
"label" => $label,
"profileImage" => $profileImage,
"imagetag" => $imagetag,
"groupid" => $groupid
);
}
}
return $groupsData;
}
public function updateWhatsappRecords($request)
{
global $adb;
$phone = $request->get("phone");
$recordId = $request->get("recordId");
$updateQuery = $adb->pquery("UPDATE vtiger_ctwhatsapp SET whatsapp_contactid = ? WHERE whatsapp_withccode = ?", array(
$recordId,
$phone
));
}
public function getWhatsappTemplates()
{
global $adb;
$getWhatsappTemplateQuery = $adb->pquery("SELECT * FROM vtiger_ctwhatsapptemplates INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapptemplates.ctwhatsapptemplatesid WHERE vtiger_crmentity.deleted = 0", array());
$whatsappTemplateRows = $adb->num_rows($getWhatsappTemplateQuery);
$templatesArray = array();
for ($j = 0; $j < $whatsappTemplateRows; $j ++) {
$templatesID = $adb->query_result($getWhatsappTemplateQuery, $j, "ctwhatsapptemplatesid");
$templateTitle = $adb->query_result($getWhatsappTemplateQuery, $j, "wptemplate_title");
$templatesArray[$templatesID] = $templateTitle;
}
return $templatesArray;
}
public function getRelatedToId($mobileno)
{
global $adb;
$whatsappModuleQuery = $adb->pquery("SELECT * FROM vtiger_ctwharsappallow_whatsappmodule WHERE active = 1");
$rows = $adb->num_rows($whatsappModuleQuery);
$whatsaappModule = array();
for ($i = 0; $i < $rows; $i ++) {
$modulename = $adb->query_result($whatsappModuleQuery, $i, "module");
$moduleIsEnable = CTWhatsApp_Record_Model::getmoduleIsEnable($modulename);
if ($moduleIsEnable == 0) {
$whatsaappModuleData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($modulename);
$phoneField = $whatsaappModuleData["phoneField"];
$moduleModel = CRMEntity::getInstance($modulename);
$moduleInstance = Vtiger_Module::getInstance($modulename);
$baseTable = $moduleInstance->basetable;
$baseTableid = $moduleInstance->basetableid;
$mainTable = 0;
$query = "SELECT * FROM " . $baseTable;
foreach ($moduleModel->tab_name_index as $key => $value) {
$mainTable = $mainTable + 1;
if ($mainTable != 2) {
if ($key != "vtiger_seproductsrel" && $key != "vtiger_producttaxrel") {
$query .= " INNER JOIN " . $key . " ON " . $key . "." . $value . " = " . $baseTable . "." . $baseTableid;
}
}
}
$query .= " WHERE REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(" . $phoneField . ", ')', ''), '(', ''),'-',''),' ',''),'.','') LIKE '%" . $mobileno . "%' AND vtiger_crmentity.deleted=0";
$queryResult = $adb->pquery($query);
$row = $adb->num_rows($queryResult);
if ($row) {
$relatedTo = $adb->query_result($queryResult, 0, $baseTableid);
$smownerid = $adb->query_result($queryResult, 0, "smownerid");
}
}
}
$resultData = array(
"relatedTo" => $relatedTo,
"smownerid" => $smownerid
);
return $resultData;
}
public function getWhatsAppStoragePath()
{
global $root_directory;
$year = date("Y");
$month = date("F");
$day = date("j");
$week = '';
$whatsappfolderpath = "modules/CTWhatsApp/CTWhatsAppStorage/";
if (! is_dir($root_directory . $whatsappfolderpath)) {
mkdir($root_directory . $whatsappfolderpath);
chmod($root_directory . $whatsappfolderpath, 511);
}
if (! is_dir($root_directory . $whatsappfolderpath . $year)) {
mkdir($root_directory . $whatsappfolderpath . $year);
chmod($root_directory . $whatsappfolderpath . $year, 511);
}
if (! is_dir($root_directory . $whatsappfolderpath . $year . "/" . $month)) {
mkdir($root_directory . $whatsappfolderpath . "{$year}/{$month}/");
chmod($root_directory . $whatsappfolderpath . "{$year}/{$month}/", 511);
}
if ($day > 0 && $day <= 7) {
$week = "week1";
} elseif ($day > 7 && $day <= 14) {
$week = "week2";
} elseif ($day > 14 && $day <= 21) {
$week = "week3";
} elseif ($day > 21 && $day <= 28) {
$week = "week4";
} else {
$week = "week5";
}
if (! is_dir($root_directory . $whatsappfolderpath . $year . "/" . $month . "/" . $week)) {
mkdir($root_directory . $whatsappfolderpath . "{$year}/{$month}/{$week}/");
chmod($root_directory . $whatsappfolderpath . "{$year}/{$month}/{$week}/", 511);
}
$target_file = $root_directory . $whatsappfolderpath . "{$year}/{$month}/{$week}/";
return $target_file;
}
public function getWhatsAppTemplatesData($recordid)
{
global $adb;
$getWhatsappTemplateQuery = $adb->pquery("SELECT * FROM vtiger_ctwhatsapptemplates
\x9 \x9INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapptemplates.ctwhatsapptemplatesid
\x9 INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.crmid = vtiger_ctwhatsapptemplates.ctwhatsapptemplatesid
\x9\x9INNER JOIN vtiger_attachments ON vtiger_attachments.attachmentsid = vtiger_seattachmentsrel.attachmentsid
\x9\x9 WHERE vtiger_crmentity.deleted = 0 AND vtiger_ctwhatsapptemplates.ctwhatsapptemplatesid = ?", array(
$recordid
));
$isTemplates = $adb->num_rows($getWhatsappTemplateQuery);
if ($isTemplates) {
$templatesID = $adb->query_result($getWhatsappTemplateQuery, 0, "ctwhatsapptemplatesid");
$message = $adb->query_result($getWhatsappTemplateQuery, 0, "wptemplate_text");
$templateMsg = $adb->query_result($getWhatsappTemplateQuery, 0, "wptemplate_msg");
$wptemplateImage = $adb->query_result($getWhatsappTemplateQuery, 0, "name");
}
$whatsAppTemplateData = array(
"templatesID" => $templatesID,
"message" => $message,
"templateMsg" => $templateMsg,
"wptemplateImage" => $wptemplateImage
);
return $whatsAppTemplateData;
}
public function getAttachmentData($templatesID)
{
global $adb;
$getAttachmentQuery = $adb->pquery("SELECT vtiger_attachments.*, vtiger_crmentity.setype FROM vtiger_attachments
\x9 INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid
\x9 INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_attachments.attachmentsid\xa \x9 WHERE vtiger_seattachmentsrel.crmid = ? AND vtiger_crmentity.deleted = 0", array(
$templatesID
));
$imageId = $adb->query_result($getAttachmentQuery, 0, "attachmentsid");
$imagePath = $adb->query_result($getAttachmentQuery, 0, "path");
$imageName = $adb->query_result($getAttachmentQuery, 0, "name");
$attachmentData = array(
"imageId" => $imageId,
"imagePath" => $imagePath,
"imageName" => $imageName
);
return $attachmentData;
}
public function getWhatsAppRecordQuery($startdate, $enddate)
{
$whatsappQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $whatsappQuery . " AND vtiger_ctwhatsapp.whatsapp_contactid = ? AND DATE(vtiger_crmentity.createdtime) BETWEEN '{$startdate}' AND '{$enddate}'";
return $query;
}
public function getPhoneFieldLabel($tabid, $phoneField)
{
global $adb;
$getFieldsLabel = $adb->pquery("SELECT * FROM vtiger_field WHERE tabid=? AND fieldname=?", array(
$tabid,
$phoneField
));
$phonefield = $adb->query_result($getFieldsLabel, 0, "fieldlabel");
return $phonefield;
}
public function userConfigurationData($currenUserID)
{
global $adb;
$queryUserExist = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield3 LIKE '%" . $currenUserID . "%'", array());
$numRowsUsers = $adb->num_rows($queryUserExist);
if ($numRowsUsers == 0) {
$queryGetGroupId = $adb->pquery("SELECT * FROM vtiger_group2role INNER JOIN vtiger_user2role ON vtiger_user2role.roleid = vtiger_group2role.roleid WHERE vtiger_user2role.userid = ?", array(
$currenUserID
));
$groupid = $adb->query_result($queryGetGroupId, 0, "groupid");
if ($groupid != '') {
$queryGroupExist = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield3 LIKE '%" . $groupid . "%'", array());
}
$numRowsUsers = $adb->num_rows($queryGroupExist);
}
return $numRowsUsers;
}
public function updateWhatsAppSatatus($currenUserID)
{
global $adb;
$udpateStatusQuery = $adb->pquery("UPDATE vtiger_ctwhatsappconfiguration SET whatsappstatus = 0, whatsappno = '' WHERE customfield5 = ?", array(
$currenUserID
));
}
public function createNewUser($currenUserID, $adminApiUrl, $contryCode, $iconActive)
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield5 = ?", array(
$currenUserID
));
$numrows = $adb->num_rows($query);
if ($numrows == 0) {
$insertQuery = $adb->pquery("INSERT INTO vtiger_ctwhatsappconfiguration SET api_url='{$adminApiUrl}', customfield5='{$currenUserID}', customfield1='{$contryCode}', iconactive='{$iconActive}'", array());
}
}
public function getLastMessageDataTime($massMessageid)
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappschedulesendmsg WHERE schedulesendmsgid = {$massMessageid} AND vtiger_ctwhatsappschedulesendmsg.status = 1 AND send_msg = 1 AND datesendmessage != '' ORDER BY datesendmessage DESC LIMIT 0,1");
$lastMessageDataTime = $adb->query_result($query, 0, "datesendmessage");
return $lastMessageDataTime;
}
public function getSendQueueMessages($request)
{
global $adb;
$progress = $request->get("progress");
if ($progress == "Completed") {
$progressMessages = " AND status = 1";
} else {
if ($progress == "InProgress") {
$progressMessages = " AND status = 0";
} else {
if ($progress == "Hold") {
$progressMessages = " AND status = 2";
} else {
if ($progress == "All") {
$progressMessages = " AND status IN (0,1,2)";
}
}
}
}
$date_var = date("Y-m-d H:i:s");
$currenDateTime = $adb->formatDate($date_var, true);
$getMassMessageDetail = CTWhatsApp_DashBoard_View::getMassMessageDetail();
$batch = $getMassMessageDetail["batch"];
$timeinterval = $getMassMessageDetail["timeinterval"];
$periodData = CTWhatsApp_DashBoard_View::getPeriodDataQuery($request, "sendmessagedate");
$selectPeriodData = $request->get("periodData");
if ($selectPeriodData == "alltime") {
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappmassmessage ORDER BY massmessageid DESC");
} else {
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappmassmessage WHERE " . $periodData . " ORDER BY massmessageid DESC LIMIT 0,5");
}
$rows = $adb->num_rows($query);
$sendqueueMessages = array();
for ($i = 0; $i < $rows; $i ++) {
$status = '';
$expcompdate = '';
$readRows = 0;
$massMessageid = $adb->query_result($query, $i, "massmessageid");
$whatsappMessage = $adb->query_result($query, $i, "whatsappmessage");
$massmsgdatetime = $adb->query_result($query, $i, "massmsgdatetime");
$templatesid = $adb->query_result($query, $i, "templatesid");
$sendMessageDate = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($adb->query_result($query, $i, "sendmessagedate"));
$getLastMessageDataTime = CTWhatsApp_Record_Model::getLastMessageDataTime($massMessageid);
if ($getLastMessageDataTime != '') {
$lastMessageDate = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($getLastMessageDataTime);
} else {
$lastMessageDate = "-";
}
$queryScheduleSendmsg = $adb->pquery("SELECT * FROM vtiger_ctwhatsappschedulesendmsg WHERE schedulesendmsgid = ? {$progressMessages}", array(
$massMessageid
));
$rowScheduleSendmsg = $adb->num_rows($queryScheduleSendmsg);
$totalSend = 0;
$totalQueue = 0;
for ($j = 0; $j < $rowScheduleSendmsg; $j ++) {
$send_msg = $adb->query_result($queryScheduleSendmsg, $j, "send_msg");
$whatsappRecordid = $adb->query_result($queryScheduleSendmsg, $j, "recordid");
$sendMessageStatus = $adb->query_result($queryScheduleSendmsg, $j, "status");
$scheduleSendmsgID = $adb->query_result($queryScheduleSendmsg, $j, "schedulesendmsgid");
$getReadQuery = $adb->pquery("SELECT * FROM vtiger_ctwhatsapp INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapp.ctwhatsappid WHERE vtiger_crmentity.deleted = 0 AND vtiger_ctwhatsapp.whatsapp_contactid = ? AND vtiger_ctwhatsapp.message_type = 'Mass Message' AND vtiger_ctwhatsapp.whatsapp_unreadread = 'Read' AND vtiger_ctwhatsapp.whatsapp_withoccode = ?", array(
$whatsappRecordid,
$scheduleSendmsgID
));
$readRows = $readRows + $adb->num_rows($getReadQuery);
$deleteCheckQuery = $adb->pquery("SELECT * FROM vtiger_crmentity WHERE crmid = ?", array(
$whatsappRecordid
));
if ($adb->query_result($deleteCheckQuery, 0, "deleted") == 0) {
$setype = VtigerCRMObject::getSEType($whatsappRecordid);
}
if ($send_msg == 1) {
$totalSend = $totalSend + 1;
}
$totalQueue = $rowScheduleSendmsg - $totalSend;
}
if ($totalQueue != 0) {
$total = $rowScheduleSendmsg / $batch;
if ($massmsgdatetime) {
$currentdatetime = $massmsgdatetime;
} else {
$currentdatetime = date("Y-m-d H:i:s");
}
if ($total <= 1) {
$expexteddatetime = strtotime($currentdatetime . " + " . $timeinterval . " minute");
} else {
$totalminutes = $total * $timeinterval;
$expexteddatetime = strtotime($currentdatetime . " + " . round($totalminutes) . " minute");
}
}
if ($sendMessageStatus == 2) {
$status = "Hold";
$expcompdate = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat(date("Y-m-d H:i:s", $expexteddatetime));
} else {
if ($sendMessageStatus == 1) {
$status = "Completed";
$expcompdate = "-";
} else {
$status = "InProgress";
$expcompdate = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat(date("Y-m-d H:i:s", $expexteddatetime));
}
}
$getWhatsappTemplateQuery = $adb->pquery("SELECT * FROM vtiger_ctwhatsapptemplates INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapptemplates.ctwhatsapptemplatesid WHERE vtiger_crmentity.deleted = 0 AND vtiger_ctwhatsapptemplates.ctwhatsapptemplatesid = ?", array(
$templatesid
));
$isTemplates = $adb->num_rows($getWhatsappTemplateQuery);
if ($isTemplates) {
$whatsappMessage = '';
$whatsappMessage = $adb->query_result($getWhatsappTemplateQuery, 0, "wptemplate_text");
$templatesId = $adb->query_result($getWhatsappTemplateQuery, 0, "ctwhatsapptemplatesid");
$getAttachmentQuery = $adb->pquery("SELECT * FROM vtiger_attachments
INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid\xa INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_attachments.attachmentsid
WHERE vtiger_seattachmentsrel.crmid = ? AND vtiger_crmentity.deleted = 0", array(
$templatesId
));
$imageId = $adb->query_result($getAttachmentQuery, 0, "attachmentsid");
$imagePath = $adb->query_result($getAttachmentQuery, 0, "path");
$imageName = $adb->query_result($getAttachmentQuery, 0, "name");
$type = explode("/", $adb->query_result($getAttachmentQuery, 0, "type"));
$attachmentPath = $imagePath . $imageId . "_" . $imageName;
if ($type[0] == "image") {
$whatsappMessage .= "<br><img src="" . $attachmentPath . "" style="width: 50px;">";
} else {
$whatsappMessage .= "<br><a href="" . $attachmentPath . "">" . $imageName . "</a>";
}
}
$totalMessages = $totalSend + $totalQueue;
if ($rowScheduleSendmsg != '') {
$sendqueueMessages[] = array(
"massMessageid" => $massMessageid,
"date" => $sendMessageDate,
"whatsappmessage" => $whatsappMessage,
"totalSend" => $totalSend,
"totalQueue" => $totalQueue,
"totalMessages" => $totalMessages,
"lastMessageDate" => $lastMessageDate,
"readRows" => $readRows,
"status" => $status,
"expcompdate" => $expcompdate,
"sendMessageStatus" => $sendMessageStatus,
"setype" => vtranslate($setype, $setype)
);
}
}
return $sendqueueMessages;
}
public function getWhatsAppReportData($period, $format, $periodData)
{
global $adb;
$arrayData = array();
$yAxisData1 = array();
$yAxisData2 = array();
$yAxisData3 = array();
foreach ($period as $key => $date) {
$conditionDate = $date->format($format);
$customeQuery = '';
if ($periodData == "alltime") {
$customeQuery = " AND YEAR(vtiger_crmentity.createdtime) = ?";
} else {
$customeQuery = " AND DATE(vtiger_crmentity.createdtime) = ?";
}
$whatsappMessageQuery = "SELECT * FROM vtiger_ctwhatsapp INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapp.ctwhatsappid WHERE vtiger_crmentity.deleted = 0 AND vtiger_ctwhatsapp.message_type IN('Send','Mass Message')";
$query = $adb->pquery($whatsappMessageQuery . $customeQuery, array(
$conditionDate
));
$sent = 0;
$read = 0;
$rows = $adb->num_rows($query);
for ($i = 0; $i < $rows; $i ++) {
$messageType = $adb->query_result($query, $i, "message_type");
if ($messageType != '') {
$sent = $sent + 1;
}
$messageReadUpRead = $adb->query_result($query, $i, "whatsapp_unreadread");
if ($messageReadUpRead == "Read") {
$read = $read + 1;
}
}
$yAxisData1["count"][] = $sent;
$yAxisData2["count"][] = $read;
}
$arrayData["Send"] = $yAxisData1;
$arrayData["Read"] = $yAxisData2;
return $arrayData;
}
public function massMessagePauseResume($status, $recordid)
{
global $adb;
$updateStatusQuery = $adb->pquery("UPDATE vtiger_ctwhatsappschedulesendmsg SET status = ? WHERE schedulesendmsgid = ? AND send_msg = 0", array(
$status,
$recordid
));
}
public function massMessageDelete($recordid)
{
global $adb;
$massDeleteQuery = $adb->pquery("DELETE FROM vtiger_ctwhatsappmassmessage WHERE massmessageid = ?", array(
$recordid
));
$massMessageDeleteQuery = $adb->pquery("DELETE FROM vtiger_ctwhatsappschedulesendmsg WHERE schedulesendmsgid = ?", array(
$recordid
));
}
public function getWhatsappTheme()
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE theme_view != ''", array());
$theme_view = $adb->query_result($query, 0, "theme_view");
return $theme_view;
}
public function getModulefields($tabid, $sourceModuleName, $moduleRecordId)
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_field WHERE tabid = ? AND quickcreate IN('0','2') AND uitype NOT IN('56','51','10','15','5','33','57')", array(
$tabid
));
$num_rows = $adb->num_rows($query);
$recordModel = Vtiger_Record_Model::getInstanceById($moduleRecordId, $sourceModuleName);
$fieldLabelValue = array();
for ($i = 0; $i < $num_rows; $i ++) {
$fieldname = $adb->query_result($query, $i, "fieldname");
$fieldlabel = $adb->query_result($query, $i, "fieldlabel");
$fieldValue = $recordModel->get($fieldname);
$fieldLabelValue[$fieldlabel] = array(
"fieldName" => $fieldname,
"fieldValue" => $fieldValue
);
}
return $fieldLabelValue;
}
public function getUserScanWhatsAppAllData($userid)
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield5 = ?", array(
$userid
));
$row = $adb->num_rows($query);
$api_url = $adb->query_result($query, 0, "api_url");
$auth_token = $adb->query_result($query, 0, "auth_token");
$customfield1 = $adb->query_result($query, 0, "customfield1");
$whatsappno = $adb->query_result($query, 0, "whatsappno");
$userScanWhatsAppData = array(
"row" => $row,
"api_url" => $api_url,
"auth_token" => $auth_token,
"customfield1" => $customfield1,
"whatsappno" => $whatsappno
);
return $userScanWhatsAppData;
}
public function checkMessageId($messageid)
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsapp INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapp.ctwhatsappid WHERE vtiger_crmentity.deleted = 0 AND vtiger_ctwhatsapp.msgid = ?", array(
$messageid
));
$row = $adb->num_rows($query);
return $row;
}
public function getScanNumberUserId($scanNumber)
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE whatsappno = ?", array(
$scanNumber
));
$row = $adb->num_rows($query);
if ($row) {
$scanUserId = $adb->query_result($query, 0, "customfield5");
$userScanUsersData = array(
"scanUserId" => $scanUserId
);
}
return $userScanUsersData;
}
public function getAdmminScanDetail()
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsappconfiguration WHERE customfield4 != ''", array());
$row = $adb->num_rows($query);
if ($row) {
$showunknownmsg = $adb->query_result($query, 0, "showunknownmsg");
$customfield3 = $adb->query_result($query, 0, "customfield3");
$api_url = $adb->query_result($query, 0, "api_url");
$admminScanDetail = array(
"showunknownmsg" => $showunknownmsg,
"multipleuser" => $customfield3,
"api_url" => $api_url
);
}
return $admminScanDetail;
}
public function getOneDaysMessages()
{
global $adb;
$todayDate = date("Y-m-d");
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsapp INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapp.ctwhatsappid WHERE vtiger_crmentity.deleted = 0 AND vtiger_ctwhatsapp.message_type IN ('Send','Mass Message') AND DATE(vtiger_crmentity.createdtime) = '" . $todayDate . "'");
$rows = $adb->num_rows($query);
return $rows;
}
public function getWhatsappAccountDetail($licenseKey)
{
$apiURL = "https://www.crmtiger.com/whatsapp/checklifromapi.php?license_key=" . $licenseKey;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $apiURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13"
));
$result = curl_exec($curl);
$response = json_decode($result);
curl_close($curl);
$type = $response->type;
return $type;
}
public function getWhatsappNumberImportant($mobileno)
{
global $adb;
$query = $adb->pquery("SELECT * FROM vtiger_ctwhatsapp INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_ctwhatsapp.ctwhatsappid WHERE vtiger_ctwhatsapp.whatsapp_withccode = ? AND vtiger_crmentity.deleted = 0 LIMIT 0,1", array(
$mobileno
));
$important = $adb->query_result($query, 0, "whatsapp_important");
return $important;
}
} ?>
Did this file decode correctly?
Original Code
<?php
class CTWhatsApp_Record_Model extends Vtiger_Record_Model
{
public function getWhatsappIcon($sourceModule)
{
global $adb, $current_user;
$currenUserID = $current_user->id;
$isAdmin = $current_user->is_admin;
$roleID = $current_user->roleid;
$getUserGrous = $adb->pquery("\x53\105\114\105\103\124\40\52\40\106\x52\x4f\115\40\166\x74\x69\x67\145\x72\x5f\143\x74\x77\x68\x61\x74\163\x61\160\x70\143\157\x6e\x66\151\147\165\x72\141\164\151\x6f\156\40\127\x48\105\122\105\40\x75\163\145\162\x73\137\x67\162\157\165\160\x73\x20\41\75\x20\x27\47");
$usersGroups = explode("\x2c", $adb->query_result($getUserGrous, 0, "\165\163\145\x72\x73\x5f\x67\162\157\165\x70\163"));
$userid = in_array($currenUserID, $usersGroups);
if ($userid) {
$num_rows = 1;
} else {
$queryGetGroupId = $adb->pquery("\123\x45\x4c\x45\x43\124\40\52\40\106\122\117\115\x20\166\x74\151\147\x65\162\x5f\x67\x72\157\165\160\x32\162\x6f\154\x65\x20\127\110\105\x52\105\40\x72\157\x6c\145\x69\144\x20\75\x20\77", array(
$roleID
));
$groupid = $adb->query_result($queryGetGroupId, 0, "\x67\x72\x6f\x75\160\x69\144");
$existGroup = in_array($groupid, $usersGroups);
if ($existGroup) {
$num_rows = 1;
} else {
$num_rows = 0;
}
}
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$apiurl = str_replace("\x2f\x61\x70\x69\x2f", '', $configurationData["\141\160\x69\x5f\165\162\154"]);
$apiUrl = $apiurl . "\57" . $configurationData["\141\165\x74\150\x74\157\x6b\145\x6e"];
$iconactive = $configurationData["\x69\x63\x6f\156\141\x63\164\x69\166\145"];
$whatsappStatus = $configurationData["\167\150\141\x74\x73\x61\x70\160\163\x74\141\164\x75\163"];
$inappNotification = $configurationData["\x69\156\141\x70\x70\137\x6e\157\164\x69\x66\151\x63\x61\164\151\157\x6e"];
$themeView = CTWhatsApp_Record_Model::getWhatsappTheme();
if ($themeView == "\x52\x54\x4c") {
$picStyle1 = "\155\141\162\x67\151\x6e\72\40\x30\160\x78\40\60\160\170\x20\60\160\x78\x20\x31\60\160\x78\73\146\x6c\x6f\x61\164\72\x20\x72\x69\147\x68\x74\73";
$picStyle2 = "\155\x61\x72\147\151\x6e\x3a\x20\x30\x70\x78\x20\x30\x70\170\40\60\160\x78\x20\x31\60\x70\x78\x3b\x66\x6c\x6f\141\x74\x3a\x20\162\x69\x67\150\x74\73";
$divStyle = "\x73\164\x79\154\145\75\47\144\x69\162\145\143\x74\x69\x6f\156\x3a\40\x72\x74\x6c\x3b\164\145\170\164\x2d\x61\154\151\147\x6e\x3a\40\x72\151\147\x68\x74\x3b\47";
$timeStyle = "\x66\x6c\157\141\164\72\x20\x6c\x65\146\164\x3b\x64\x69\x72\x65\143\164\151\157\156\72\x20\154\x74\162\x3b";
} else {
$picStyle1 = "\155\x61\x72\x67\151\156\x3a\40\60\160\170\x20\x31\x39\x70\x78\x20\x30\x70\x78\40\60\x70\x78\73\x66\154\x6f\141\164\x3a\x20\x6c\145\x66\x74\x3b";
$picStyle2 = "\x6d\141\162\x67\x69\x6e\x3a\40\60\160\x78\40\61\x39\x70\x78\40\x30\160\170\40\60\160\170\73\x66\x6c\157\x61\x74\x3a\x20\x6c\x65\146\x74\x3b";
$divStyle = '';
$timeStyle = "\146\x6c\157\141\164\x3a\40\162\x69\147\x68\164\73";
}
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$unreadmsgCountsQuery = $adb->pquery($unreadQuery . "\x20\101\116\x44\40\x76\164\151\147\x65\162\x5f\143\x74\167\150\x61\x74\x73\x61\160\160\56\167\150\x61\164\163\141\160\160\x5f\x75\156\x72\x65\141\144\162\x65\141\144\x20\x3d\40\x27\125\x6e\162\145\141\x64\x27\x20\x41\x4e\104\x20\x76\x74\151\x67\x65\162\137\143\164\167\150\x61\164\x73\141\x70\x70\x2e\155\x65\x73\163\x61\x67\x65\x5f\x74\171\160\x65\x20\x3d\x20\47\122\145\x63\151\x65\x76\145\x64\47\x20\x41\x4e\104\40\x76\x74\x69\147\145\162\x5f\x63\164\167\150\x61\164\x73\x61\x70\x70\x2e\167\150\141\164\x73\x61\x70\x70\x5f\167\151\x74\150\143\x63\157\144\145\40\41\75\x20\47\x47\x72\157\165\160\x73\47");
$unreadCountCounts = $adb->num_rows($unreadmsgCountsQuery);
$unreadmsgQuery = $adb->pquery($unreadQuery . "\x20\x41\x4e\104\x20\x76\164\x69\x67\x65\162\x5f\x63\x74\x77\150\141\x74\163\141\160\x70\56\x6d\x65\163\163\141\x67\x65\x5f\x74\x79\160\x65\x20\x3d\x20\x27\x52\145\x63\x69\x65\166\x65\144\x27\x20\x4f\x52\104\105\x52\40\x42\x59\x20\x76\x74\151\x67\145\x72\x5f\x63\x74\167\x68\141\x74\163\141\160\x70\x2e\167\150\x61\164\x73\141\160\x70\x5f\x64\x61\x74\145\164\151\155\x65\x20\104\x45\123\103\40\114\x49\115\111\x54\40\x30\x2c\x20\65");
$unreadCountRow = $adb->num_rows($unreadmsgQuery);
$notificationHTML = '';
for ($i = 0; $i < $unreadCountRow; $i ++) {
$recordId = $adb->query_result($unreadmsgQuery, $i, "\x77\150\141\164\x73\141\160\160\137\143\157\x6e\x74\141\143\x74\x69\144");
if ($recordId == '') {
$label = $adb->query_result($unreadmsgQuery, $i, "\x77\150\x61\x74\163\141\160\160\x5f\167\151\x74\x68\x63\143\x6f\x64\145");
$lastBody = $adb->query_result($unreadmsgQuery, $i, "\155\x65\163\x73\141\147\x65\137\x62\x6f\x64\171");
$lastDateTime = $adb->query_result($unreadmsgQuery, $i, "\167\150\x61\x74\163\x61\160\x70\137\144\x61\164\x65\164\151\x6d\x65");
if ($label != "\x47\162\157\165\x70\163") {
$individulMessageID = "\x69\x64\75\42\x77\150\141\x74\163\x61\160\160\x22";
$class = '';
$imageIcon = "\x6c\141\x79\x6f\165\164\163\x2f\x76\x37\x2f\x6d\x6f\144\165\154\x65\x73\x2f\103\x54\127\x68\141\x74\x73\101\160\x70\x2f\151\x6d\141\147\145\57\x41\x76\x74\141\162\111\x63\x6f\x6e\x2e\x70\156\147";
$messagename = $adb->query_result($unreadmsgQuery, $i, "\x77\x68\141\x74\x73\x61\x70\x70\137\167\x69\164\150\x63\143\x6f\x64\x65");
} else {
$individulMessageID = '';
$class = "\x72\x65\x63\145\151\166\x65\x64\156\145\167\155\x65\163\x73\141\147\x65\x73";
$imageIcon = "\x6c\141\171\x6f\165\164\x73\57\x76\x37\x2f\x6d\157\144\165\154\x65\x73\57\103\x54\x57\150\141\x74\x73\101\160\x70\x2f\x69\155\x61\147\x65\x2f\x67\x72\157\x75\x70\x73\x2e\160\x6e\x67";
$messagename = $adb->query_result($unreadmsgQuery, $i, "\167\x68\x61\164\x73\x61\160\160\x5f\x63\150\x61\x74\151\x64");
}
$notificationHTML .= "\x3c\154\x69\40\x63\154\x61\x73\x73\75\42\167\150\x61\x74\x73\141\x70\x70\x5f\x6e\x65\x77\137\155\x65\x73\163\x61\147\145\163\40" . $class . "\42\x20" . $individulMessageID . "\x20\x64\141\x74\x61\55\162\x65\143\x6f\x72\144\151\x64\x3d\x22" . $label . "\x22\x20\163\x74\x79\x6c\145\x3d\x22\167\x69\144\x74\x68\x3a\40\61\60\x30\45\73\x64\x69\x73\160\x6c\141\x79\72\x20\x69\156\x6c\151\x6e\x65\x2d\x62\x6c\157\143\153\x3b\x66\x6c\x6f\x61\164\x3a\x20\x6c\x65\146\164\x3b\x62\x6f\x72\x64\145\162\x2d\142\157\x74\x74\x6f\155\x3a\40\61\x70\170\x20\163\x6f\154\151\144\x20\162\147\142\50\64\64\40\x35\71\40\67\63\x20\57\x20\x31\65\x25\51\73\42\76\12\11\11\x20\x20\x20\40\40\x20\x20\x20\40\x20\40\x20\74\x61\40\150\x72\x65\x66\x3d\x22\43\x22\40\x73\x74\171\154\x65\75\x22\x70\x61\144\x64\x69\x6e\x67\x3a\x20\x31\x30\160\170\x20\x31\x30\160\x78\40\41\x69\155\x70\x6f\162\164\141\156\x74\73\143\157\x6c\157\x72\x3a\x20\x23\x33\x33\63\40\41\x69\155\160\157\162\164\141\x6e\164\73\x64\151\163\x70\x6c\141\x79\72\40\x69\x6e\x6c\x69\x6e\145\x2d\142\x6c\157\x63\153\73\146\154\157\x61\164\72\40\154\x65\x66\164\73\167\x69\x64\x74\x68\72\x20\61\x30\60\45\73\42\76\12\x9\x9\40\x20\40\40\x20\40\x20\40\x20\40\x20\x20\x20\x20\x20\x20\x3c\144\151\166\x20\143\x6c\x61\x73\x73\x3d\42\160\151\x63\42\40\163\x74\x79\154\145\75\42\144\151\x73\160\154\141\171\72\40\x69\x6e\154\x69\x6e\x65\x2d\142\154\x6f\x63\x6b\x3b\x70\x61\x64\x64\151\x6e\147\55\162\151\147\150\x74\72\x20\61\60\x70\x78\x3b\x77\151\144\164\150\x3a\x20\65\60\x70\170\x3b\x68\145\x69\x67\x68\164\x3a\40\x35\x30\160\x78\x3b\142\157\x72\144\x65\162\x2d\162\x61\x64\151\x75\x73\x3a\x20\x35\60\x25\73\x62\157\170\55\163\x68\x61\144\157\x77\x3a\x20\x30\x20\60\40\65\160\x78\x20\x72\x67\142\50\66\70\40\70\60\x20\61\60\x30\x20\57\x20\x30\56\x32\x35\51\73\155\141\x78\55\x77\151\x64\164\x68\x3a\x20\63\x36\160\x78\x3b\x6d\x61\x78\x2d\150\x65\151\147\150\164\x20\72\40\x33\66\x70\170\73\x6d\141\x72\x67\151\x6e\x20\72\40\x30\x3b" . $picStyle1 . "\42\x3e\xa\11\11\x20\x20\40\40\x20\40\x20\40\40\40\40\40\40\40\40\x20\11\74\x69\x6d\x67\40\x73\x72\143\x3d\42" . $imageIcon . "\42\40\163\164\171\154\145\x3d\42\x77\151\144\x74\x68\x3a\x20\x34\x30\x70\x78\x3b\155\141\x78\55\167\x69\x64\164\x68\x3a\40\x33\x36\160\x78\x3b\x6d\x61\170\x2d\150\x65\151\x67\150\164\x20\72\40\x33\66\160\170\73\155\141\162\147\151\156\x20\x3a\x20\60\73\x62\x6f\162\144\145\x72\55\162\x61\x64\151\165\x73\72\40\65\x30\45\x3b\x62\x61\x63\x6b\x67\x72\x6f\165\156\144\72\x20\43\64\x65\142\x62\x34\x36\73\x22\x2f\x3e\12\x9\11\40\x20\x20\40\40\x20\x20\x20\x20\40\x20\40\40\x20\40\x20\x3c\x2f\x64\151\166\76\12\x9\11\40\40\x20\x20\x20\x20\x20\40\40\x20\40\x20\40\40\x20\40\74\x64\151\166\x20" . $divStyle . "\76\12\11\x9\x20\x20\40\40\40\40\40\x20\40\40\40\x20\40\40\40\40\x20\40\x20\40\74\x73\x70\x61\156\40\x63\154\x61\x73\x73\x3d\42\42\x3e\x3c\x62\40\x73\164\171\154\145\75\x22\x66\157\x6e\x74\x2d\x73\151\172\145\72\40\x31\64\x70\170\x3b\x20\x21\151\x6d\160\x6f\162\x74\x61\156\x74\x3b\x22\76" . $messagename . "\x3c\x2f\x62\76\74\x2f\163\160\x61\x6e\76\12\x9\11\40\x20\40\40\40\40\x20\40\x20\40\40\x20\40\x20\x20\40\40\40\40\40\74\x70\40\x73\x74\171\x6c\145\75\42\x6d\x61\170\x2d\x77\x69\144\x74\x68\x3a\x20\63\60\60\160\170\73\146\x6f\156\x74\x2d\x73\x69\172\x65\x3a\40\x31\x32\x70\x78\x3b\155\141\170\x2d\x77\x69\144\x74\150\72\x20\x32\x30\60\160\170\73\157\x76\x65\162\x66\x6c\157\x77\x3a\40\x68\x69\x64\144\145\x6e\x3b\164\145\x78\164\55\x6f\x76\x65\x72\146\154\157\x77\72\x20\145\x6c\x6c\151\160\163\151\163\x3b\167\x68\x69\164\x65\55\x73\x70\141\143\x65\72\x20\x6e\x6f\x77\162\141\160\x3b\42\76" . $lastBody . "\x3c\x2f\160\x3e\12\x9\11\40\x20\40\40\x20\40\x20\40\x20\x20\x20\40\x20\40\40\x20\x20\x20\40\40\x3c\x73\160\x61\156\x20\143\x6c\x61\163\x73\x3d\x22\x22\x20\163\x74\171\x6c\145\x3d\42\x66\157\156\164\x2d\163\x69\172\x65\72\x20\61\62\160\x78\73\x6c\151\156\x65\55\x68\145\151\x67\150\x74\x3a\x20\61\66\160\x78\73\146\157\156\x74\55\x77\x65\x69\147\x68\x74\72\40\64\60\x30\73\x64\x69\x73\160\154\x61\x79\72\x20\142\x6c\x6f\143\x6b\73" . $timeStyle . "\42\x3e" . Vtiger_Util_Helper::formatDateDiffInStrings($lastDateTime) . "\74\x2f\163\x70\x61\x6e\x3e\xa\x9\x9\40\40\40\40\x20\40\40\x20\x20\40\x20\x20\40\40\40\40\x3c\57\144\x69\x76\76\xa\11\x9\x20\x20\x20\x20\x20\40\x20\x20\x20\40\40\x20\74\57\x61\x3e\12\11\x9\40\x20\40\x20\x20\x20\x20\40\74\x2f\154\151\76";
} else {
$setype = VtigerCRMObject::getSEType($recordId);
$deleteRecord = CTWhatsApp_Record_Model::recordDelete($recordId);
if ($deleteRecord == 0) {
if ($recordId) {
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $setype);
$label = $recordModel->get("\x6c\141\142\x65\x6c");
}
$profileImage = CTWhatsApp_Record_Model::getImageDetails($recordId, $setype);
$imageTag = 1;
if ($profileImage == '') {
$labelExplode = explode("\40", $label);
$profileImage = mb_substr($labelExplode[0], 0, 1, "\125\x54\x46\x2d\x38") . mb_substr($labelExplode[1], 0, 1, "\x55\124\x46\x2d\70");
$imageTag = 0;
}
$lastBody = $adb->query_result($unreadmsgQuery, $i, "\155\145\163\x73\141\x67\145\x5f\x62\157\x64\171");
$lastDateTime = $adb->query_result($unreadmsgQuery, $i, "\167\x68\x61\x74\163\141\x70\160\x5f\144\141\x74\145\x74\x69\x6d\145");
$notificationHTML .= "\x3c\x6c\x69\x20\x63\154\141\x73\163\75\42\167\x68\x61\x74\163\141\160\160\x5f\x6e\x65\x77\137\155\x65\x73\x73\x61\147\145\x73\42\40\x69\144\x3d\x22\x77\x68\141\x74\x73\x61\x70\x70\x22\x20\x64\x61\164\141\55\x72\x65\x63\x6f\x72\144\x69\144\x3d\42" . $recordId . "\x22\40\x64\x61\164\x61\55\x73\x65\x74\x79\x70\145\x3d\42" . $setype . "\x22\x20\163\164\x79\154\145\75\x22\x77\x69\144\164\x68\72\40\61\60\60\x25\73\144\x69\x73\160\x6c\141\171\72\40\151\156\x6c\x69\x6e\145\55\x62\x6c\x6f\143\153\73\x66\x6c\x6f\x61\164\x3a\x20\154\x65\x66\164\x3b\142\x6f\162\x64\x65\x72\x2d\142\157\x74\x74\x6f\155\72\x20\61\160\170\40\163\x6f\x6c\x69\144\x20\x72\147\142\x28\64\64\x20\x35\71\x20\67\63\x20\x2f\x20\61\65\x25\x29\x3b\x22\x3e\xa\11\11\11\x20\40\40\x20\40\40\40\40\x20\40\x20\40\x3c\141\x20\x68\162\145\x66\x3d\x22\x23\x22\x20\163\164\171\x6c\145\x3d\x22\x70\141\144\x64\151\x6e\x67\x3a\x20\61\x30\160\170\x20\x31\60\160\170\x20\x21\x69\x6d\x70\x6f\x72\x74\x61\156\164\x3b\x63\157\154\157\162\72\x20\43\x33\63\x33\x20\x21\x69\x6d\160\x6f\162\164\141\156\164\73\x64\x69\163\160\154\x61\x79\x3a\x20\151\x6e\154\151\156\x65\55\x62\x6c\x6f\x63\153\73\146\154\x6f\x61\164\72\40\154\145\x66\x74\73\167\x69\x64\164\x68\72\40\x31\x30\x30\x25\x3b\42\76\xa\11\x9\11\x20\x20\40\x20\x20\40\40\x20\x20\40\x20\x20\40\40\40\40\74\x64\151\x76\x20\x63\x6c\x61\163\x73\x3d\x22\160\x69\x63\42\x20\x73\164\171\154\145\x3d\x22\x64\151\163\160\x6c\141\x79\x3a\40\x69\156\154\151\x6e\x65\x2d\142\154\x6f\143\x6b\x3b\146\x6c\157\141\164\72\x20\154\145\146\x74\73\x20\167\151\144\164\150\72\40\x33\x36\x70\x78\73\150\x65\151\147\x68\x74\72\x20\x33\66\x70\170\73\x62\x6f\x72\144\145\x72\55\162\x61\x64\x69\165\x73\72\x20\x35\x30\45\x3b\x62\x6f\170\55\x73\x68\141\x64\x6f\167\72\40\x30\40\60\x20\x35\x70\170\40\x72\x67\x62\x28\66\70\40\x38\60\x20\61\60\x30\x20\x2f\x20\x30\56\x32\65\x29\73\x20" . $picStyle2 . "\x20\x74\x65\x78\164\x2d\x61\x6c\x69\147\156\72\40\x63\145\156\x74\x65\162\x3b\40\143\157\x6c\x6f\x72\x3a\x20\x23\x34\x65\x62\x62\x34\x36\x3b\42\76";
if ($imageTag == 1) {
$notificationHTML .= "\74\x69\155\x67\40\163\162\143\75\x22" . $profileImage . "\x22\40\x73\164\171\x6c\145\x3d\42\x20\167\151\144\164\x68\x3a\x20\x31\60\60\45\73\x6d\x61\162\x67\x69\156\x3a\40\60\73\x68\x65\x69\x67\x68\164\x3a\x20\61\60\60\45\73\142\157\x72\x64\145\162\55\x72\x61\144\x69\165\x73\72\40\x35\x30\x25\73\x22\57\76";
} else {
$notificationHTML .= "\74\163\160\x61\x6e\x20\x63\x6c\141\x73\163\75\x22\x69\155\141\147\x65\156\x61\x6d\x65\x22\x20\151\144\x3d\x22\x69\x6d\141\x67\145\x6e\141\x6d\145\x22\x20\163\164\171\154\145\x3d\x22\x66\x6f\156\164\x2d\x73\151\172\x65\x3a\x20\61\65\x70\x78\x3b\154\151\156\x65\55\150\145\x69\147\150\164\72\40\x33\66\160\x78\x3b\x22\76\74\x62\76" . $profileImage . "\74\57\142\x3e\74\x2f\163\160\x61\x6e\x3e";
}
$notificationHTML .= "\74\x2f\x64\151\x76\x3e\xa\11\x9\11\40\x20\40\40\x20\40\40\40\40\x20\x20\x20\x20\40\40\x20\74\x64\x69\x76\40\x20" . $divStyle . "\76\12\x9\11\11\40\x20\40\x20\x20\40\40\x20\x20\x20\x20\x20\40\x20\40\40\40\40\x20\x20\74\x73\x70\x61\x6e\x20\x63\154\141\163\163\75\42\42\76\74\x62\40\x73\164\171\154\145\75\x22\146\157\x6e\x74\x2d\x73\x69\x7a\x65\72\x20\61\64\x70\170\73\40\x21\151\x6d\160\157\162\x74\141\156\164\x3b\x22\x3e" . $label . "\74\57\x62\76\74\57\x73\160\x61\x6e\76\12\11\x9\x9\x20\40\x20\40\x20\x20\40\x20\40\40\40\40\x20\x20\x20\40\40\x20\40\40\x3c\x70\40\x73\x74\171\154\145\x3d\42\x6d\141\x78\x2d\x77\x69\x64\x74\150\72\40\63\60\60\x70\170\x3b\146\x6f\156\x74\55\163\151\x7a\145\x3a\40\61\x32\160\x78\x3b\155\141\170\x2d\x77\x69\x64\164\150\72\x20\x32\60\x30\160\x78\x3b\157\x76\x65\162\x66\x6c\157\x77\72\40\x68\x69\x64\144\145\156\73\164\x65\x78\x74\55\x6f\166\x65\162\146\154\157\x77\72\x20\145\x6c\154\x69\160\163\151\x73\73\x77\x68\151\164\x65\55\x73\x70\141\x63\x65\72\40\x6e\x6f\x77\x72\x61\x70\x3b\x22\76" . $lastBody . "\74\57\x70\x3e\12\11\x9\x9\40\x20\40\40\x20\x20\x20\40\40\x20\x20\x20\40\x20\40\x20\x20\40\40\40\x3c\x73\160\141\x6e\x20\143\154\x61\x73\x73\75\x22\42\40\x73\x74\x79\x6c\145\x3d\x22\x66\157\x6e\x74\55\163\151\172\145\x3a\x20\61\62\160\170\73\154\x69\x6e\x65\55\x68\145\x69\x67\x68\164\x3a\x20\61\x36\160\x78\x3b\x66\x6f\x6e\x74\55\167\x65\151\147\150\x74\72\40\x34\60\x30\x3b\144\151\163\160\154\x61\171\72\x20\142\154\x6f\143\x6b\73" . $timeStyle . "\42\x3e" . Vtiger_Util_Helper::formatDateDiffInStrings($lastDateTime) . "\x3c\x2f\x73\x70\141\156\x3e\xa\x9\11\11\40\40\x20\40\x20\40\40\x20\40\x20\x20\x20\x20\40\x20\40\74\x2f\x64\x69\x76\76\xa\11\11\x9\x20\x20\40\x20\40\40\40\x20\x20\40\x20\40\x3c\x2f\x61\76\12\x9\x9\11\x20\40\40\x20\40\x20\x20\x20\74\x2f\154\151\76";
}
}
}
$currentdate = date("\x59\55\155\x2d\x64");
$getexpiredate = $adb->pquery("\123\105\114\x45\103\124\40\x2a\40\106\x52\x4f\x4d\x20\x76\x74\151\147\145\x72\x5f\143\164\167\150\141\x74\x73\141\160\x70\137\x6c\151\x63\145\156\x73\x65\x5f\x73\x65\164\x74\x69\x6e\147");
$expirydate = $adb->query_result($getexpiredate, 0, "\x65\x78\x70\x69\162\171\x64\141\164\x65");
$licenseKey = $adb->query_result($getexpiredate, 0, "\x6c\x69\x63\145\156\163\145\137\153\145\171");
$date = Settings_CTWhatsApp_ConfigurationDetail_View::encrypt_decrypt($expirydate, $action = "\x64");
$allwModules = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($sourceModule);
$moduleMassMessage = $allwModules["\x72\157\x77\163"];
$moduleIconActive = $allwModules["\155\x6f\x64\x75\x6c\145\x49\x63\x6f\x6e\x41\x63\164\x69\x76\x65"];
$phoneField = $allwModules["\160\150\x6f\156\x65\106\151\145\x6c\144"];
if ($licenseKey != '' && strtotime($date) > strtotime($currentdate)) {
$whatsappModuleData = array(
"\x6d\x6f\144\165\154\x65\x4d\x61\x73\x73\x4d\x65\x73\x73\x61\x67\145" => $moduleMassMessage,
"\x61\x70\151\125\x72\x6c" => $apiUrl,
"\x77\x68\x61\164\x73\141\x70\x70\151\143\x6f\x6e" => $num_rows,
"\165\x6e\x72\145\x61\144\137\143\157\x75\156\x74" => $unreadCountCounts,
"\x63\x75\162\162\x65\x6e\x74\144\141\164\145" => strtotime($currentdate),
"\x6c\151\143\x65\156\x73\145\144\x61\x74\145" => strtotime($date),
"\167\150\141\164\x73\x61\160\160\x53\x74\141\164\165\x73" => $whatsappStatus,
"\x6d\157\x64\165\x6c\145\111\143\157\x6e\101\x63\x74\x69\166\x65" => $moduleIconActive,
"\160\x68\x6f\x6e\145\x46\x69\145\154\144" => $phoneField,
"\x69\156\141\x70\160\x4e\157\164\x69\x66\x69\143\x61\x74\151\157\x6e" => $inappNotification,
"\156\x6f\164\x69\146\x69\x63\x61\164\151\x6f\x6e\110\x54\x4d\114" => $notificationHTML,
"\x69\163\101\x64\155\151\x6e" => $isAdmin,
"\164\150\x65\x6d\x65\x56\151\x65\167" => $themeView,
"\x69\143\x6f\156\x61\x63\164\151\x76\x65" => $iconactive
);
}
return $whatsappModuleData;
}
function getScanQRCodeURL()
{
global $adb, $current_user;
$currentUserID = $current_user->id;
$isAdmin = $current_user->is_admin;
$queryUserExist = $adb->pquery("\123\105\114\x45\x43\124\x20\52\x20\106\x52\117\x4d\40\166\x74\151\x67\145\x72\137\x63\164\167\150\141\x74\x73\141\160\x70\143\157\156\x66\x69\x67\165\x72\141\x74\151\x6f\x6e\x20\x57\x48\105\122\105\40\143\165\x73\x74\157\155\146\x69\x65\154\x64\63\40\x4c\x49\113\x45\x20\47\x25" . $currentUserID . "\45\47", array());
$numRowsUsers = $adb->num_rows($queryUserExist);
if ($numRowsUsers == 0) {
$queryGetGroupId = $adb->pquery("\x53\x45\x4c\x45\103\x54\x20\52\x20\106\x52\x4f\115\x20\x76\164\x69\147\x65\x72\137\x67\x72\157\165\160\x32\x72\x6f\154\145\x20\111\x4e\x4e\105\122\x20\x4a\x4f\111\116\40\x76\164\151\x67\x65\162\x5f\165\163\x65\x72\x32\162\x6f\x6c\x65\x20\117\116\x20\166\164\x69\x67\145\162\137\165\x73\x65\162\62\x72\x6f\154\x65\56\162\157\x6c\145\x69\x64\40\75\x20\166\x74\151\x67\145\162\x5f\x67\x72\157\x75\x70\x32\x72\x6f\x6c\x65\x2e\162\157\154\x65\x69\x64\40\x57\110\x45\122\x45\40\x76\164\x69\x67\145\162\x5f\x75\x73\x65\162\62\x72\157\x6c\145\x2e\165\163\x65\162\151\x64\x20\75\40\x3f", array(
$currentUserID
));
$groupid = $adb->query_result($queryGetGroupId, 0, "\x67\162\x6f\x75\x70\x69\144");
if ($groupid != '') {
$queryGroupExist = $adb->pquery("\123\105\114\105\103\x54\x20\x2a\40\x46\122\x4f\x4d\x20\166\x74\151\147\145\162\x5f\143\164\167\150\x61\164\163\x61\160\160\143\x6f\x6e\146\x69\x67\165\x72\x61\x74\151\x6f\156\40\127\110\x45\x52\x45\x20\143\165\x73\x74\157\x6d\x66\151\145\x6c\144\x33\40\x4c\111\113\105\40\47\45" . $groupid . "\x25\x27", array());
}
$numRowsUsers = $adb->num_rows($queryGroupExist);
}
if ($isAdmin == "\157\x6e") {
$scanQRCode = "\151\156\x64\145\170\56\160\150\x70\x3f\x6d\157\144\165\x6c\145\x3d\103\124\x57\x68\141\x74\x73\101\x70\160\x26\x70\141\162\145\x6e\x74\75\x53\x65\164\x74\151\x6e\147\163\x26\166\151\145\x77\75\x43\x6f\x6e\146\x69\147\x75\162\141\x74\x69\x6f\156\104\145\x74\x61\x69\154";
} else {
$scanQRCode = "\x69\x6e\144\145\x78\56\x70\150\x70\x3f\155\157\x64\x75\154\x65\75\x43\x54\127\x68\x61\x74\163\x41\x70\160\46\166\151\x65\x77\75\x44\141\163\150\x42\157\141\162\x64\46\155\157\144\x65\75\155\157\144\165\154\145\x44\x61\163\x68\102\x6f\141\x72\144\x26\163\150\157\x77\161\162\143\157\x64\x65\x3d\x31";
}
return $scanQRCode;
}
function getWhatsappAllowModules()
{
global $adb;
$whatsappModuleQuery = $adb->pquery("\x53\105\114\105\x43\x54\40\x2a\x20\106\122\x4f\115\x20\x76\164\151\147\x65\162\x5f\x63\x74\x77\150\x61\x72\x73\x61\x70\160\x61\154\x6c\x6f\167\137\167\150\141\x74\x73\x61\x70\160\155\x6f\144\165\x6c\145\40\x57\x48\x45\122\105\x20\141\x63\164\151\x76\x65\x20\x3d\x20\61");
$rows = $adb->num_rows($whatsappModuleQuery);
$whatsaappModule = array();
for ($i = 0; $i < $rows; $i ++) {
$module = $adb->query_result($whatsappModuleQuery, $i, "\155\x6f\144\x75\x6c\x65");
$data = CTWhatsApp_Record_Model::checkPermissionModule($module);
if ($data == 1) {
$moduleIsEnable = CTWhatsApp_Record_Model::getmoduleIsEnable($module);
if ($moduleIsEnable == 0) {
$whatsaappModuleData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($module);
$phoneField = $whatsaappModuleData["\x70\150\157\x6e\x65\106\151\x65\154\x64"];
$serach = '';
$moduleQuery = CTWhatsApp_Record_Model::moduleQuery($module, $phoneField, $serach);
$query = $adb->pquery($moduleQuery);
$row = $adb->num_rows($query);
if ($row == '') {
$row = 0;
}
$whatsaappModule[] = array(
"\155\x6f\x64\x75\154\145" => $module,
"\162\157\x77\163" => $row,
"\x70\150\x6f\156\x65\106\x69\x65\x6c\x64" => $phoneField
);
}
}
}
return $whatsaappModule;
}
function getmoduleIsEnable($moduleName)
{
global $adb;
$moduleQuery = $adb->pquery("\x53\x45\114\105\x43\124\40\x2a\40\106\122\117\x4d\x20\x76\164\151\147\x65\162\x5f\164\141\x62\40\127\x48\x45\x52\x45\x20\x6e\x61\x6d\145\x20\75\x20\x3f", array(
$moduleName
));
return $presence = $adb->query_result($moduleQuery, 0, "\160\162\x65\163\145\156\143\x65");
}
function getWhatsappAllowModuleFields($sourceModule)
{
global $adb;
$getAllowModule = $adb->pquery("\x53\x45\114\105\103\x54\x20\52\x20\106\x52\x4f\115\x20\x76\164\151\x67\145\x72\x5f\x63\x74\167\x68\x61\x72\163\141\x70\x70\141\x6c\x6c\x6f\x77\137\x77\150\x61\x74\163\x61\x70\160\x6d\x6f\x64\165\x6c\x65\40\x57\110\x45\x52\x45\40\x6d\157\x64\165\x6c\x65\40\75\40\77", array(
$sourceModule
));
$rows = $adb->num_rows($getAllowModule);
$moduleIconActive = $adb->query_result($getAllowModule, 0, "\141\143\x74\151\166\145");
$phoneField = $adb->query_result($getAllowModule, 0, "\x70\x68\157\x6e\145\x5f\146\151\x65\x6c\144");
$allwModules = array(
"\x6d\x6f\144\165\x6c\x65\111\x63\157\x6e\x41\143\164\151\166\x65" => $moduleIconActive,
"\160\x68\157\x6e\145\106\151\145\154\144" => $phoneField,
"\162\x6f\167\163" => $rows
);
return $allwModules;
}
function moduleQuery($modulename, $phoneField, $searchValue)
{
global $adb, $current_user;
$currenUserID = $current_user->id;
$moduleModel = CRMEntity::getInstance($modulename);
$moduleInstance = Vtiger_Module::getInstance($modulename);
$baseTable = $moduleInstance->basetable;
$baseTableid = $moduleInstance->basetableid;
if ($searchValue) {
$searchQuery = "\40\x41\x4e\104\40\166\164\151\x67\145\162\x5f\143\162\x6d\x65\x6e\x74\x69\164\x79\56\154\x61\x62\145\154\40\x4c\x49\x4b\105\40\47\x25" . $searchValue . "\x25\47";
} else {
$searchQuery = '';
}
$mainTable = 0;
$query = "\123\x45\x4c\105\103\x54\40\52\x20\106\x52\117\115\x20" . $baseTable;
foreach ($moduleModel->tab_name_index as $key => $value) {
$mainTable = $mainTable + 1;
if ($mainTable != 2) {
if ($key != "\166\x74\151\x67\x65\162\x5f\x73\x65\x70\162\157\x64\x75\x63\x74\163\x72\x65\154" && $key != "\166\x74\151\x67\145\x72\x5f\160\x72\x6f\144\x75\143\164\164\141\x78\162\145\154") {
$query .= "\40\111\116\x4e\105\x52\x20\x4a\117\x49\116\40" . $key . "\40\117\116\40" . $key . "\x2e" . $value . "\40\x3d\40" . $baseTable . "\x2e" . $baseTableid;
}
}
}
$isAdmin = $current_user->is_admin;
if ($isAdmin != "\157\156") {
$tabid = getTabid($modulename);
if ($tabid) {
$getRecordPermissionQuery = $adb->pquery("\x53\105\114\105\x43\x54\40\x2a\x20\106\122\x4f\x4d\40\166\x74\x69\147\x65\162\x5f\x64\145\x66\137\157\162\x67\x5f\163\x68\x61\162\x65\40\127\110\x45\x52\105\x20\x74\141\142\x69\x64\x20\75\x20\77", array(
$tabid
));
$permission = $adb->query_result($getRecordPermissionQuery, 0, "\160\145\x72\155\151\163\x73\x69\157\156");
if ($permission == "\x33") {
$assignQuery = "\x20\x41\116\104\40\x76\x74\151\147\145\162\x5f\143\162\x6d\145\x6e\164\x69\x74\x79\56\x73\x6d\157\x77\156\145\162\151\x64\x20\x3d\x20\x27{$currenUserID}\x27";
}
}
}
$query .= "\x20\x4c\x45\106\124\x20\112\x4f\x49\x4e\40\166\164\x69\147\145\162\x5f\x75\x73\145\162\163\40\x4f\x4e\40\x76\164\151\147\145\162\137\143\x72\x6d\x65\156\x74\151\x74\x79\x2e\163\x6d\157\167\x6e\145\x72\151\144\40\x3d\x20\x76\164\151\x67\145\162\137\165\x73\x65\x72\163\56\x69\x64\x20\114\x45\x46\x54\40\112\117\x49\116\40\166\164\151\147\x65\x72\137\147\x72\157\x75\x70\163\x20\x4f\116\40\166\x74\x69\147\145\162\x5f\143\162\155\145\x6e\164\151\x74\171\56\x73\155\x6f\167\x6e\145\162\151\144\x20\x3d\x20\x76\x74\x69\x67\x65\x72\x5f\147\x72\x6f\165\x70\163\56\x67\162\x6f\x75\160\151\x64\x20";
$query .= "\40\x4c\x45\x46\x54\x20\x4a\117\x49\116\xa\x9\x9\11\x28\12\x9\x9\x9\40\x20\x53\x45\x4c\105\x43\x54\x20\x77\x68\141\x74\163\x61\160\x70\x5f\x63\x6f\x6e\164\x61\x63\x74\x69\144\x2c\x20\x6d\x61\x78\x28\x77\150\141\x74\x73\141\160\x70\x5f\x64\x61\164\145\164\151\155\x65\51\x20\141\163\40\x77\150\141\164\163\x61\160\x70\137\x64\141\164\x65\12\x9\x9\11\40\x20\106\x52\x4f\115\x20\x76\x74\151\147\x65\162\137\x63\x74\x77\150\141\x74\163\141\160\160\12\x9\11\11\x20\40\x67\162\x6f\x75\160\40\x62\x79\40\x77\x68\141\164\163\141\x70\x70\x5f\x63\157\156\164\x61\143\x74\151\144\xa\11\x9\x9\51\x20\x6c\141\163\x74\x5f\163\150\141\162\x65\144\x20\157\x6e\40\x28\x6c\141\163\x74\x5f\x73\x68\x61\x72\x65\x64\56\x77\x68\141\x74\x73\x61\160\x70\x5f\x63\x6f\x6e\x74\141\143\x74\x69\144\40\75\x20" . $baseTable . "\56" . $baseTableid . "\x20\x29";
$query .= "\40\x57\x48\x45\122\105\x20\166\x74\x69\x67\145\162\137\143\x72\x6d\145\x6e\164\151\164\x79\x2e\x64\145\154\145\164\145\x64\75\60\40\101\x4e\x44\40" . $baseTable . "\x2e" . $baseTableid . "\40\x3e\x20\60\x20\x41\x4e\104\40" . $phoneField . "\40\x21\x3d\x20\x27\47" . $searchQuery . "\x20" . $assignQuery . "\40\x47\122\117\125\x50\40\102\x59\40" . $phoneField . "\40\117\x52\104\105\x52\40\102\131\40\x63\157\141\154\x65\x73\143\x65\50\154\x61\163\x74\137\x73\x68\x61\x72\145\x64\56\x77\150\x61\164\x73\141\x70\160\x5f\x64\x61\164\x65\51\40\104\x45\123\103";
return $query;
}
public function unreadQuery()
{
$query = "\123\x45\x4c\x45\x43\x54\40\52\x20\x46\122\117\x4d\x20\x76\164\151\x67\x65\162\137\x63\164\x77\x68\x61\164\163\141\x70\x70\x20\xa\11\x9\11\111\116\x4e\x45\122\40\112\x4f\x49\x4e\40\166\x74\151\147\145\x72\x5f\x63\162\x6d\145\156\164\151\164\x79\x20\117\116\x20\x76\x74\151\147\145\x72\x5f\x63\x72\x6d\x65\x6e\164\151\x74\x79\x2e\x63\x72\x6d\x69\144\40\x3d\40\166\x74\x69\x67\145\162\x5f\x63\x74\167\x68\x61\164\x73\141\x70\x70\x2e\x63\x74\x77\150\x61\164\x73\141\x70\x70\x69\144\40\12\11\x9\x9\127\110\105\x52\x45\40\166\x74\151\147\x65\x72\137\x63\x72\x6d\x65\x6e\164\151\x74\171\56\x64\x65\x6c\x65\x74\x65\x64\x20\x3d\x20\60";
return $query;
}
public function getUnreadMessagesCount()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . "\40\101\116\104\40\x76\164\x69\x67\x65\162\x5f\x63\x74\x77\x68\141\164\x73\x61\x70\x70\56\x77\150\141\x74\x73\x61\x70\x70\137\x75\156\162\145\141\144\162\145\x61\x64\x20\75\40\x27\125\156\162\145\141\x64\x27\40\101\116\104\40\166\164\151\147\x65\162\x5f\x63\x74\167\150\x61\x74\x73\x61\160\160\56\155\145\x73\x73\x61\147\145\137\164\171\160\x65\x20\75\40\47\x52\x65\x63\151\145\166\145\x64\x27\x20\101\116\x44\x20\x76\164\x69\147\x65\162\x5f\143\164\167\150\141\x74\163\141\160\160\x2e\167\150\141\164\163\x61\x70\160\x5f\167\x69\x74\150\x63\143\157\144\145\40\41\x3d\40\47\107\x72\x6f\x75\x70\163\x27");
$rows = $adb->num_rows($query);
return $rows;
}
public function getImportantMessagesCounts()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . "\40\x41\116\104\40\166\164\x69\147\x65\162\x5f\143\x74\x77\150\x61\164\x73\x61\160\x70\56\167\x68\x61\164\x73\141\x70\160\x5f\151\155\160\157\x72\164\x61\x6e\164\x20\x3d\x20\x31\x20\107\122\117\125\120\x20\x42\x59\40\x76\x74\x69\147\145\x72\137\x63\164\x77\x68\x61\x74\163\141\x70\160\x2e\167\150\141\164\x73\x61\160\x70\137\x63\157\156\x74\141\x63\x74\x69\144\x2c\40\x76\x74\151\x67\x65\162\137\x63\164\167\150\x61\164\x73\141\160\160\x2e\x77\150\x61\164\163\x61\160\x70\137\x77\x69\x74\x68\143\x63\x6f\144\x65", array());
$rows = $adb->num_rows($query);
$delete = 0;
for ($i = 0; $i < $rows; $i ++) {
$relatedRecordId = $adb->query_result($query, $i, "\x77\x68\x61\x74\x73\x61\x70\x70\137\x63\x6f\156\164\141\143\164\151\x64");
if ($relatedRecordId != '') {
$deleteRecord = CTWhatsApp_Record_Model::recordDelete($relatedRecordId);
if ($deleteRecord == 1) {
$delete = $delete + 1;
}
}
}
$rows = $rows - $delete;
return $rows;
}
public function getNewMessagesCounts()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . "\x20\x41\116\104\x20\166\x74\x69\x67\145\162\137\143\164\167\150\x61\164\x73\141\x70\160\x2e\x77\150\x61\x74\163\x61\x70\160\x5f\x77\x69\164\150\x63\143\x6f\x64\x65\x20\x21\x3d\x20\47\47\x20\x41\116\x44\40\x76\x74\x69\x67\145\x72\x5f\143\x74\167\150\141\164\x73\x61\160\x70\56\x77\150\141\x74\x73\141\x70\x70\x5f\165\x6e\x72\145\x61\144\x72\x65\x61\144\40\75\40\47\125\x6e\162\x65\x61\144\47\40\40\101\x4e\x44\x20\x76\x74\151\147\x65\x72\x5f\143\x74\x77\x68\x61\x74\x73\141\x70\160\x2e\155\x65\x73\x73\141\147\x65\x5f\164\x79\x70\x65\x20\x3d\x20\x27\x52\145\x63\151\x65\x76\145\144\47\x20\101\x4e\x44\40\x76\x74\151\147\145\x72\x5f\143\164\x77\150\141\x74\x73\x61\x70\160\56\x77\x68\x61\164\x73\141\160\x70\x5f\167\x69\164\x68\143\x63\157\144\145\40\x21\x3d\x20\x27\x47\162\157\x75\160\x73\x27\40\107\x52\117\x55\120\x20\102\x59\x20\166\x74\151\147\x65\x72\137\x63\x74\x77\x68\x61\164\163\141\160\x70\56\x77\x68\x61\164\163\x61\x70\160\137\x63\x6f\156\164\141\x63\164\151\x64\x2c\x20\166\x74\x69\x67\x65\162\x5f\143\164\x77\150\x61\164\x73\141\x70\x70\56\167\150\141\164\163\x61\160\x70\137\167\x69\164\x68\143\143\x6f\x64\145\40\x4f\x52\x44\105\x52\x20\102\x59\40\x76\164\151\x67\145\162\x5f\143\x72\155\x65\x6e\164\151\164\x79\x2e\x63\162\x65\141\164\145\144\x74\x69\155\x65", array());
$rows = $adb->num_rows($query);
$allNewMessageCountquery = $adb->pquery($unreadQuery . "\40\101\116\x44\x20\166\164\151\147\x65\162\137\143\164\167\x68\141\x74\x73\x61\160\160\56\167\150\141\x74\163\141\x70\x70\x5f\x77\x69\x74\150\143\143\157\x64\x65\40\41\75\x20\47\x27\40\101\x4e\x44\x20\x76\x74\151\147\x65\162\x5f\x63\x74\x77\x68\141\164\163\x61\x70\x70\56\x77\x68\141\x74\163\x61\x70\x70\x5f\x75\156\162\145\141\144\x72\145\x61\x64\x20\75\x20\x27\125\156\x72\145\x61\x64\x27\40\40\x41\x4e\x44\40\x76\x74\151\x67\x65\x72\x5f\143\x74\167\150\141\164\163\141\160\x70\x2e\155\x65\163\x73\141\x67\145\x5f\164\x79\160\x65\x20\x3d\x20\x27\x52\145\143\151\x65\166\145\144\x27\x20\101\116\x44\40\x76\164\x69\x67\145\162\x5f\143\x74\x77\x68\141\164\x73\141\160\x70\56\167\150\141\x74\x73\141\160\x70\137\x77\x69\x74\x68\143\143\157\x64\x65\40\41\75\40\47\x47\x72\x6f\x75\160\x73\47", array());
$allRows = $adb->num_rows($allNewMessageCountquery);
$result = array(
"\x72\157\167\x73" => $rows,
"\141\154\154\122\x6f\x77\x73" => $allRows
);
return $result;
}
public function getAllMessagesCounts()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$allQuery = $unreadQuery . "\40\101\x4e\x44\40\166\164\151\x67\145\x72\137\143\x74\x77\x68\141\x74\x73\141\160\x70\x2e\167\150\141\164\163\x61\x70\x70\137\167\151\x74\x68\143\143\157\144\145\40\41\x3d\x20\x27\47\x20\x41\x4e\x44\x20\166\164\151\147\145\x72\137\x63\x74\x77\x68\141\x74\x73\141\160\x70\56\x77\x68\x61\x74\163\141\x70\x70\137\x77\151\164\150\143\143\x6f\144\145\40\41\75\40\47\x47\162\x6f\165\x70\163\x27\40\107\122\x4f\125\x50\x20\102\x59\40\x76\164\151\x67\145\162\137\x63\x74\x77\x68\141\164\163\141\x70\x70\56\x77\x68\141\x74\163\x61\160\x70\137\x63\157\156\x74\141\x63\x74\151\144\x2c\40\x76\164\x69\147\145\162\137\x63\x74\x77\150\x61\x74\x73\141\160\160\x2e\167\150\141\164\x73\141\x70\x70\x5f\x77\x69\164\150\143\x63\157\x64\145";
$unreadQuery = $unreadQuery . "\x20\x41\x4e\104\x20\x76\164\x69\x67\x65\x72\x5f\143\x74\167\x68\141\x74\163\141\160\160\x2e\x77\150\141\x74\163\x61\x70\160\137\x77\151\x74\150\143\x63\157\x64\145\x20\41\x3d\40\x27\x27\40\x41\x4e\104\x20\x76\164\x69\147\x65\x72\x5f\x63\x74\167\x68\x61\x74\163\x61\160\160\56\x6d\x65\163\163\141\147\x65\x5f\x74\x79\x70\145\x20\x3d\40\x27\122\145\143\151\x65\x76\x65\x64\x27\40\x41\116\104\40\x76\164\151\147\145\162\x5f\x63\164\167\150\x61\164\163\x61\x70\x70\x2e\167\150\141\164\163\x61\160\160\x5f\x75\156\162\x65\x61\144\162\x65\141\144\40\75\40\47\x55\x6e\x72\145\x61\144\x27\40\101\x4e\104\x20\x76\x74\151\147\145\x72\137\x63\x74\x77\x68\x61\164\x73\x61\160\x70\56\x77\x68\141\x74\163\x61\x70\160\137\x77\151\164\150\143\143\157\144\145\40\41\75\x20\47\107\x72\157\x75\160\x73\x27\x20\107\122\117\125\120\40\x42\x59\40\166\x74\151\147\x65\x72\137\x63\x74\167\150\141\x74\163\141\160\x70\56\x77\x68\141\x74\163\x61\x70\160\137\x63\157\156\x74\141\143\164\151\144\x2c\x20\x76\x74\x69\147\145\x72\137\x63\164\x77\x68\141\164\x73\x61\160\160\x2e\x77\150\x61\164\163\x61\160\x70\137\167\151\x74\150\143\143\x6f\144\145";
$allUnreadMessageCount = $adb->pquery($allQuery);
$row = $adb->num_rows($allUnreadMessageCount);
$delete = 0;
for ($i = 0; $i < $row; $i ++) {
$relatedRecordId = $adb->query_result($allUnreadMessageCount, $i, "\167\150\141\164\x73\141\160\160\137\x63\157\x6e\164\x61\x63\x74\151\144");
if ($relatedRecordId != '') {
$deleteRecord = CTWhatsApp_Record_Model::recordDelete($relatedRecordId);
if ($deleteRecord == 1) {
$delete = $delete + 1;
}
}
}
$rows = $row - $delete;
$allUnreadCount = $adb->pquery($unreadQuery);
$allRows = $adb->num_rows($allUnreadCount);
$result = array(
"\x72\157\167\163" => $allRows,
"\x61\154\x6c\x52\157\167\x73" => $rows
);
return $result;
}
public function getUnknownMessagesCounts()
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . "\40\101\x4e\x44\40\166\x74\x69\x67\x65\x72\x5f\x63\164\x77\x68\141\x74\163\141\x70\160\x2e\x77\150\x61\x74\x73\x61\x70\x70\x5f\143\x6f\x6e\x74\x61\143\x74\151\x64\40\x3d\x20\47\x27\x20\x41\x4e\x44\x20\x76\164\x69\147\x65\x72\x5f\x63\x74\x77\150\x61\x74\163\141\x70\x70\56\x77\x68\141\164\163\141\160\x70\x5f\x75\x6e\x72\x65\x61\144\x72\145\141\x64\40\75\x20\x27\125\156\162\145\141\144\x27\x20\x41\116\x44\x20\x76\164\x69\x67\145\162\x5f\x63\164\x77\x68\141\x74\x73\141\160\x70\x2e\x77\150\x61\164\163\x61\x70\160\137\167\x69\164\150\143\143\x6f\144\145\40\x21\75\40\x27\x47\162\x6f\165\x70\163\x27\40\101\x4e\104\x20\x76\x74\x69\147\145\162\x5f\143\x74\167\150\141\164\163\x61\160\160\56\x6d\x65\163\163\x61\147\145\x5f\164\171\160\x65\40\x3d\40\47\x52\145\x63\x69\145\x76\x65\144\47\x20\107\122\x4f\125\120\x20\102\131\40\x76\164\x69\147\x65\x72\x5f\143\164\167\150\x61\x74\163\141\160\160\56\167\150\141\164\163\x61\x70\160\x5f\167\151\x74\150\143\x63\157\x64\145", array());
$unknownRows = $adb->num_rows($query);
if ($unknownRows == '') {
$unknownRows = 0;
}
$allUnknownquery = $adb->pquery($unreadQuery . "\x20\x41\116\104\x20\x76\164\151\147\x65\x72\137\x63\x74\167\150\x61\x74\163\141\x70\x70\x2e\x77\150\141\164\x73\141\x70\x70\x5f\x63\157\x6e\164\x61\143\x74\151\144\x20\75\x20\x27\x27\x20\101\x4e\x44\40\166\164\x69\147\145\x72\x5f\x63\x74\x77\x68\x61\164\x73\x61\160\160\x2e\x77\150\x61\164\x73\x61\x70\x70\x5f\165\156\x72\x65\x61\144\x72\145\141\x64\40\x3d\40\x27\125\x6e\162\x65\x61\x64\47\x20\x41\116\104\x20\x76\x74\x69\x67\x65\162\137\x63\x74\x77\x68\x61\164\x73\141\160\160\56\x77\x68\141\x74\x73\x61\x70\160\x5f\x77\151\164\x68\x63\x63\x6f\x64\145\40\x21\75\x20\x27\107\x72\x6f\165\x70\163\x27\x20\x47\122\x4f\x55\x50\40\102\x59\40\166\x74\x69\x67\145\162\x5f\143\164\x77\150\x61\x74\163\141\x70\160\56\167\150\x61\164\x73\x61\160\160\137\167\x69\x74\150\x63\x63\157\x64\145", array());
$allUnknownRows = $adb->num_rows($allUnknownquery);
if ($allUnknownRows == '') {
$allUnknownRows = 0;
}
$result = array(
"\x75\156\x6b\x6e\157\x77\156\122\157\x77\163" => $unknownRows,
"\x61\x6c\x6c\x55\156\153\156\x6f\167\x6e\122\157\x77\x73" => $allUnknownRows
);
return $result;
}
public function getModuleRecrods($request)
{
$moduleName = $request->getModule();
$whatsappmodule = $request->get("\167\150\x61\x74\x73\x61\160\160\x6d\157\x64\x75\154\145");
$searchValue = $request->get("\163\x65\x61\162\x63\x68\x56\x61\x6c\x75\x65");
$start = $request->get("\x73\164\x61\x72\x74");
$end = $request->get("\145\156\144");
$html = '';
if ($whatsappmodule == "\x49\155\160\x6f\162\164\141\156\164") {
$importantMessages = "\171\145\x73";
$moduleMessages = CTWhatsApp_Record_Model::getNewMessagesData($importantMessages, $start, $end, $searchValue, $whatsappmodule);
} else {
if ($whatsappmodule == "\116\145\167\x4d\x65\x73\x73\x61\x67\145\163") {
$importantMessages = "\156\157";
$moduleMessages = CTWhatsApp_Record_Model::getNewMessagesData($importantMessages, $start, $end, $searchValue, $whatsappmodule);
} else {
if ($whatsappmodule == "\125\156\x6b\156\x6f\167\156") {
$moduleMessages = CTWhatsApp_Record_Model::getUnknownMessagesData($start, $end, $searchValue);
} else {
if ($whatsappmodule == "\101\154\x6c\115\x65\x73\x73\141\x67\x65\163") {
$importantMessages = "\x6e\157";
$moduleMessages = CTWhatsApp_Record_Model::getNewMessagesData($importantMessages, $start, $end, $searchValue, $whatsappmodule);
} else {
if ($whatsappmodule == "\107\162\157\x75\x70\163") {
$moduleMessages = CTWhatsApp_Record_Model::getWhatsappGroup();
} else {
$moduleMessages = CTWhatsApp_Record_Model::getModuleMessagesData($whatsappmodule, $start, $end, $searchValue);
}
}
}
}
}
$index = 0;
foreach ($moduleMessages as $key => $value) {
if ($value["\165\x6e\162\145\141\x64\115\145\x73\x73\x61\147\x65\x43\157\x75\156\164"] == 0) {
$read = '';
$count = '';
} else {
$read = "\165\156\x52\x65\x61\x64";
$count = "\x3c\163\x70\x61\x6e\40\x63\x6c\141\x73\163\75\x22\143\x6f\165\156\x74\145\x72\115\163\147\42\40\x73\x74\x79\154\x65\x3d\42\164\157\160\x3a\x20\60\x70\x78\40\x21\151\x6d\160\x6f\x72\x74\x61\x6e\x74\73\155\141\x72\147\151\x6e\x2d\x6c\x65\146\x74\x3a\40\x34\60\160\x78\x3b\x20\x21\x69\155\160\x6f\162\x74\141\156\164\42\76" . $value["\x75\156\162\145\x61\144\115\145\x73\163\141\x67\x65\103\x6f\x75\156\164"] . "\x3c\x2f\x73\x70\141\156\76";
}
if ($index == 0) {
$bydefaulOpenChat = "\142\x79\x64\x65\x66\141\165\x6c\x4f\160\145\156\x43\150\x61\x74";
} else {
$bydefaulOpenChat = '';
}
if ($whatsappmodule == "\107\x72\x6f\x75\160\163") {
$html .= "\74\x64\x69\x76\40\143\154\141\163\x73\75\42\x70\x72\x6f\146\x69\x6c\145\40\163\x68\157\167\x43\150\141\x74\115\x65\163\x73\x61\147\145\x73\40" . $bydefaulOpenChat . "\x22\40\144\141\x74\141\x2d\162\x65\143\157\162\144\x69\x64\x3d\42" . $value["\162\145\143\157\162\144\111\144"] . "\x22\x20\x64\x61\x74\x61\55\154\141\142\145\x6c\75\x22" . $value["\x6c\x61\x62\145\154"] . "\42\40\144\x61\x74\x61\x2d\147\x72\x6f\165\160\151\x64\x3d\42" . $value["\147\162\x6f\x75\x70\151\x64"] . "\x22\x20\x73\164\171\x6c\145\x3d\42\x63\165\x72\163\157\162\x3a\40\x70\x6f\151\156\x74\x65\162\x3b\x22\76";
if ($value["\151\x6d\x61\x67\x65\164\141\x67"] == 1) {
$html .= "\74\144\x69\x76\40\143\154\x61\x73\x73\x3d\x22\x70\151\143\42\76\74\x69\155\x67\x20\163\162\143\x3d\x22" . $value["\x70\162\x6f\146\x69\154\145\111\x6d\141\x67\x65"] . "\42\x20\x73\x74\171\x6c\145\x3d\x22\167\151\x64\x74\x68\72\x20\61\60\60\45\x3b\x22\57\x3e\74\57\x64\x69\166\x3e";
} else {
$html .= "\x3c\144\151\x76\40\143\x6c\141\x73\163\75\x22\160\151\143\42\x3e\74\x73\160\141\156\40\x63\x6c\141\x73\x73\75\x22\151\x6d\x61\147\x65\x6e\x61\155\x65\x22\40\151\x64\x3d\42\x69\x6d\141\147\x65\156\x61\x6d\145\x22\x20\163\164\171\x6c\145\x3d\x22\x6d\141\x72\147\x69\156\72\x20\67\x70\x78\73\146\x6f\156\x74\x2d\x73\x69\x7a\145\x3a\x20\62\70\x70\x78\x3b\x6d\x61\162\x67\151\156\x3a\x20\62\160\170\73\x63\157\154\x6f\x72\x3a\x20\164\145\141\154\73\x22\x3e\74\x62\x3e" . $value["\160\162\157\x66\x69\x6c\145\x49\155\x61\147\145"] . "\74\57\142\x3e\74\x2f\x73\160\x61\x6e\x3e\x3c\x2f\x64\151\166\76";
}
$html .= "\74\x64\x69\x76\40\143\154\x61\163\163\75\42\160\124\145\x78\x74\x22\x3e\xa\x9\x9\x9\x9\11\x9\x9\11\x3c\x73\x70\x61\156\76" . $value["\154\141\142\145\154"] . "\74\57\x73\160\x61\x6e\76" . $count . "\x3c\160\76" . $value["\154\x61\x73\164\102\157\x64\171"] . "\74\57\160\x3e\xa\11\11\x9\11\x9\11\11\x3c\x2f\x64\x69\166\x3e\xa\11\11\x9\x9\x9\x9\x3c\x2f\144\x69\x76\x3e";
} else {
$html .= "\74\x64\x69\x76\x20\x63\x6c\x61\x73\x73\x3d\x22\160\162\x6f\146\151\x6c\x65\x20\163\150\157\167\x43\x68\141\164\x4d\x65\x73\163\141\x67\145\163\40" . $bydefaulOpenChat . "\42\40\144\141\164\141\x2d\x72\145\143\x6f\x72\x64\151\x64\75\x22" . $value["\x72\x65\x63\157\162\x64\111\x64"] . "\x22\40\163\x74\x79\x6c\145\x3d\x22\143\x75\162\x73\x6f\x72\x3a\x20\160\x6f\151\x6e\x74\x65\x72\x3b\42\x3e";
if ($value["\151\155\x61\x67\x65\164\x61\x67"] == 1) {
$html .= "\x3c\x64\151\x76\40\x63\x6c\141\163\x73\x3d\42\160\151\x63\x22\76\x3c\x69\155\x67\x20\x73\x72\143\x3d\x22" . $value["\x70\x72\157\146\x69\x6c\x65\x49\155\141\147\145"] . "\x22\x20\163\x74\171\154\x65\x3d\42\x77\x69\144\x74\150\x3a\40\x31\60\x30\45\x3b\42\57\76\74\x2f\144\x69\166\76";
} else {
$html .= "\x3c\x64\x69\166\x20\x63\x6c\x61\163\163\75\42\160\x69\x63\42\76\74\163\160\x61\156\40\143\x6c\141\163\163\75\42\x69\x6d\141\147\x65\156\x61\155\145\42\40\151\144\75\x22\151\x6d\141\147\145\x6e\141\155\x65\x22\x20\x73\164\171\x6c\x65\x3d\42\155\141\x72\x67\151\x6e\x3a\40\x37\x70\x78\x3b\146\x6f\x6e\x74\55\x73\151\x7a\x65\72\x20\62\x38\160\x78\x3b\155\x61\x72\x67\x69\156\72\x20\x32\x70\x78\x3b\143\x6f\x6c\x6f\162\72\x20\x74\145\x61\x6c\x3b\x22\76\74\142\x3e" . $value["\x70\x72\x6f\146\x69\x6c\145\x49\x6d\141\147\145"] . "\74\x2f\142\76\x3c\x2f\x73\x70\x61\156\76\74\x2f\x64\x69\166\76";
}
$html .= "\74\144\x69\x76\40\x63\154\141\163\163\75\x22\x70\124\x65\170\x74\42\76\12\11\11\11\x9\11\11\x9\11\x3c\163\160\x61\156\76" . $value["\x6c\x61\142\x65\154"] . "\x3c\57\x73\x70\x61\156\x3e" . $count . "\74\160\x3e" . $value["\x6c\141\x73\x74\102\157\x64\x79"] . "\x3c\57\160\x3e\xa\11\11\x9\11\11\x9\11\x3c\57\x64\x69\166\x3e\12\x9\x9\11\11\11\11\11\74\144\151\x76\40\143\154\x61\163\x73\x3d\42\144\x61\164\x65\x54\151\x6d\x65\x22\76" . $value["\154\141\x73\164\x44\x61\x74\x65\x54\151\x6d\x65"] . "\x3c\x2f\144\x69\166\x3e\12\x9\x9\11\11\11\11\x3c\x2f\x64\x69\x76\76";
}
$index = $index + 1;
}
$html .= "\74\x2f\144\x69\166\76\xa\x9\x9\x9\11\74\x2f\144\151\166\76";
if (empty($moduleMessages)) {
return '';
} else {
return $html;
}
}
public function recordDelete($recordId)
{
global $adb;
$query = $adb->pquery("\x53\x45\114\x45\103\124\x20\x2a\40\106\122\117\115\40\x76\164\x69\x67\145\162\x5f\143\x72\x6d\x65\156\164\151\164\x79\x20\127\110\105\x52\105\40\x63\162\x6d\x69\144\x20\75\x20\x3f", array(
$recordId
));
$deleted = $adb->query_result($query, 0, "\144\x65\x6c\145\164\x65\x64");
return $deleted;
}
public function getNewMessagesData($importantMessages, $start, $end, $searchValue, $whatsappmodule)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
if ($searchValue) {
$searchQuery = "\40\x41\116\x44\40\166\164\151\147\145\x72\x5f\x63\164\x77\150\141\x74\x73\x61\160\x70\56\167\150\141\164\163\141\x70\160\137\x77\151\164\x68\143\x63\x6f\144\145\x20\x4c\111\x4b\105\40\x27\x25" . $searchValue . "\45\x27";
} else {
$searchQuery = '';
}
if ($whatsappmodule != "\101\154\154\115\145\x73\163\x61\x67\145\x73") {
$customQuery = "\x20\101\x4e\x44\40\166\164\x69\147\145\162\x5f\143\x74\167\x68\x61\164\x73\141\x70\x70\x2e\x77\x68\x61\164\163\141\x70\x70\x5f\x75\156\x72\x65\141\144\x72\145\141\144\40\75\40\47\x55\156\x72\145\141\x64\x27";
}
if ($whatsappmodule == "\x4e\x65\x77\115\145\x73\163\141\147\145\x73") {
$customUnreadQuery = "\x20\x41\116\104\x20\166\x74\151\x67\145\162\x5f\x63\164\167\150\x61\x74\163\141\160\160\56\x77\x68\x61\x74\163\x61\x70\x70\x5f\165\x6e\162\145\141\x64\x72\x65\x61\x64\x20\75\x20\x27\x55\x6e\x72\x65\141\144\x27\40\x41\116\x44\40\x76\164\151\x67\145\162\137\143\164\167\x68\141\x74\163\x61\160\160\x2e\x6d\x65\163\x73\141\x67\145\137\x74\171\x70\145\x20\75\x20\x27\122\x65\143\151\145\x76\x65\144\47";
}
if ($importantMessages == "\x79\145\163") {
$importantQuery = $searchQuery . "\40\101\116\104\x20\x76\x74\151\x67\x65\x72\137\143\164\167\x68\141\x74\x73\141\160\x70\56\x77\x68\x61\x74\163\141\x70\x70\x5f\167\151\164\150\x63\143\157\144\x65\x20\41\x3d\x20\x27\107\162\x6f\165\x70\x73\47\40\101\116\104\x20\x76\x74\x69\147\x65\162\137\x63\164\167\150\x61\164\163\141\160\160\x2e\167\x68\x61\164\163\x61\160\x70\x5f\151\x6d\160\x6f\162\x74\141\x6e\x74\40\x3d\x20\x31\x20\x47\x52\117\125\120\40\x42\131\40\166\x74\151\x67\x65\x72\137\143\x74\x77\150\x61\x74\163\x61\160\x70\56\167\x68\141\164\163\x61\x70\160\x5f\x77\151\164\x68\x63\x63\157\x64\x65\54\x20\x76\164\x69\x67\x65\162\137\143\x74\x77\x68\141\x74\x73\141\160\160\56\167\150\141\164\163\141\x70\160\x5f\143\157\156\x74\x61\143\x74\x69\144\x20\x4f\122\104\x45\x52\x20\x42\x59\40\166\x74\x69\x67\x65\x72\x5f\143\x74\167\150\x61\x74\163\x61\160\160\56\x77\x68\141\164\x73\141\160\x70\137\144\x61\x74\x65\164\151\x6d\145\40\x44\x45\123\103";
} else {
$importantQuery = $searchQuery . "\x20" . $customQuery . "\x20" . $customUnreadQuery . "\40\101\116\x44\40\166\x74\151\x67\145\x72\137\x63\164\x77\150\x61\164\163\x61\160\160\56\x77\150\141\x74\163\141\x70\x70\137\x77\151\164\x68\143\x63\x6f\144\145\40\x21\75\x20\x27\107\162\157\x75\x70\163\47\x20\107\x52\117\125\x50\x20\102\131\x20\x76\164\x69\x67\x65\162\137\143\x74\x77\x68\141\x74\163\141\x70\x70\56\x77\150\x61\164\x73\x61\x70\x70\x5f\143\x6f\156\164\x61\x63\164\x69\x64\54\40\166\x74\151\x67\145\x72\137\143\x74\x77\150\141\164\163\x61\x70\x70\56\167\150\x61\x74\163\141\160\x70\x5f\x77\x69\164\150\143\143\x6f\144\145\40\117\x52\x44\105\x52\x20\102\x59\x20\x76\164\151\x67\145\x72\137\x63\164\167\x68\141\164\x73\141\160\160\56\167\x68\141\x74\x73\x61\x70\x70\x5f\x64\x61\x74\x65\164\151\155\145\x20\104\105\123\103";
}
if ($searchValue) {
$query = $adb->pquery($unreadQuery . "\40\x41\116\x44\40\x76\x74\x69\147\x65\x72\137\x63\164\167\x68\x61\x74\x73\141\x70\x70\x2e\143\164\x77\150\141\x74\x73\x61\x70\x70\151\x64\x20\x49\x4e\x28\123\105\114\105\x43\124\x20\155\141\170\x28\x76\x74\x69\x67\145\x72\x5f\143\164\x77\x68\x61\x74\163\x61\x70\x70\56\143\x74\167\150\x61\x74\163\x61\160\160\151\x64\51\40\x46\122\x4f\115\x20\166\164\x69\147\145\x72\137\x63\x74\167\150\x61\x74\x73\141\160\160\x20\107\122\117\x55\120\40\x42\131\40\166\164\x69\x67\145\162\137\143\164\167\150\x61\x74\163\x61\160\x70\56\x77\150\141\164\163\x61\x70\x70\137\167\x69\x74\150\x63\143\157\x64\145\54\x20\166\164\151\x67\145\x72\137\x63\x74\x77\150\141\x74\x73\x61\160\x70\56\x77\150\x61\x74\x73\141\x70\160\137\x63\x6f\x6e\164\x61\143\164\151\144\x29\40\101\x4e\x44\x20\166\x74\151\x67\x65\162\137\x63\164\167\x68\x61\164\163\x61\x70\x70\x2e\x77\150\141\164\163\141\160\x70\137\x77\x69\164\150\x63\x63\157\144\x65\x20\41\75\40\47\47" . $importantQuery);
} else {
$query = $adb->pquery($unreadQuery . "\40\x41\x4e\104\x20\166\x74\151\x67\145\x72\x5f\x63\164\167\150\141\164\163\141\160\160\56\143\164\x77\150\x61\164\163\x61\160\x70\x69\x64\x20\x49\116\x28\123\105\114\105\x43\x54\x20\x6d\x61\x78\50\x76\x74\151\147\x65\x72\137\x63\x74\167\x68\141\164\163\x61\x70\x70\56\x63\x74\167\150\141\x74\163\x61\160\160\151\x64\51\40\106\x52\117\x4d\40\x76\164\x69\x67\x65\x72\137\143\164\x77\x68\x61\x74\x73\141\160\160\x20\107\122\x4f\125\x50\40\x42\131\40\x76\x74\x69\x67\145\x72\137\143\164\167\150\x61\164\x73\x61\160\x70\x2e\167\x68\141\x74\163\x61\x70\x70\137\167\x69\164\150\143\x63\157\144\145\x2c\40\166\164\x69\x67\x65\x72\137\x63\164\167\x68\x61\164\163\x61\160\x70\56\167\150\141\x74\163\141\160\x70\x5f\x63\x6f\156\164\x61\143\164\x69\x64\x29\x20\101\x4e\104\x20\x76\x74\x69\x67\145\162\137\x63\164\167\150\x61\164\163\x61\160\160\x2e\x77\150\141\164\x73\141\x70\160\137\167\151\164\x68\x63\143\x6f\x64\145\40\41\x3d\40\47\47" . $importantQuery . "\40\x4c\111\x4d\x49\x54\40\x30\x2c\40" . $start);
}
$rows = $adb->num_rows($query);
$newMessagearray = array();
for ($i = 0; $i < $rows; $i ++) {
$recordId = $adb->query_result($query, $i, "\167\x68\141\164\x73\141\x70\160\x5f\143\x6f\x6e\164\141\x63\164\x69\144");
if ($recordId == '') {
$label = $adb->query_result($query, $i, "\167\x68\x61\x74\x73\x61\160\x70\x5f\167\151\164\x68\143\x63\x6f\x64\145");
$recordId = $label;
$profileImage = "\154\x61\x79\157\x75\x74\163\57\x76\67\x2f\x6d\157\x64\165\x6c\145\163\x2f\103\124\127\150\141\164\x73\x41\x70\160\x2f\151\x6d\141\147\x65\x2f\101\x76\x74\x61\162\x49\143\x6f\x6e\56\x70\x6e\x67";
$imagetag = 1;
$messageData = CTWhatsApp_Record_Model::getWhatsappUnReadNewMessageCounts($label);
$unreadMessageCount = $messageData["\x75\x6e\162\x65\x61\144\x43\x6f\x75\x6e\164"];
$avgMessageDay = $messageData["\x61\x76\x67\x4d\145\x73\163\x61\147\x65\104\x61\x79"];
$lastWhatsappMessageData = CTWhatsApp_Record_Model::getLastWhatsappNewMessageData($label);
$lastBody = $lastWhatsappMessageData["\x62\x6f\x64\171"];
$lastDateTime = $lastWhatsappMessageData["\x64\x61\164\145\124\x69\155\x65"];
$newMessagearray[$label] = array(
"\162\x65\143\157\x72\144\111\x64" => $recordId,
"\x6c\141\142\145\154" => $label,
"\x70\x72\x6f\146\151\154\x65\111\155\x61\x67\145" => $profileImage,
"\x69\155\x61\x67\x65\164\141\x67" => $imagetag,
"\x75\x6e\162\145\141\144\115\145\163\163\x61\147\145\103\x6f\165\x6e\164" => $unreadMessageCount,
"\x61\x76\x67\115\145\x73\163\x61\x67\145\104\141\x79" => $avgMessageDay,
"\x6c\x61\163\164\102\x6f\x64\171" => $lastBody,
"\154\141\x73\164\x44\x61\164\x65\x54\151\155\145" => $lastDateTime
);
} else {
$setype = VtigerCRMObject::getSEType($recordId);
$actionName = "\x45\144\151\x74\126\151\x65\x77";
if (! Users_Privileges_Model::isPermitted($setype, $actionName, $recordId)) {
$permissionRecord = "\60";
} else {
$permissionRecord = "\61";
}
if ($permissionRecord == 1) {
$moduleIsEnable = CTWhatsApp_Record_Model::getmoduleIsEnable($setype);
if ($moduleIsEnable == 0) {
$deleteRecord = CTWhatsApp_Record_Model::recordDelete($recordId);
if ($deleteRecord == 0) {
if ($recordId) {
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $setype);
$label = $recordModel->get("\x6c\x61\142\145\154");
}
$profileImage = CTWhatsApp_Record_Model::getImageDetails($recordId, $setype);
$imagetag = 1;
if ($profileImage == '') {
$labelExplode = explode("\x20", $label);
$profileImage = mb_substr($labelExplode[0], 0, 1, "\125\x54\106\55\70") . mb_substr($labelExplode[1], 0, 1, "\125\124\x46\x2d\x38");
$imagetag = 0;
}
$messageData = CTWhatsApp_Record_Model::getWhatsappUnReadMessageCounts($recordId);
$unreadMessageCount = $messageData["\x75\x6e\x72\x65\141\x64\103\x6f\165\156\x74"];
$avgMessageDay = $messageData["\141\x76\147\x4d\x65\163\163\141\147\145\104\x61\x79"];
$lastWhatsappMessageData = CTWhatsApp_Record_Model::getLastWhatsappMessageData($recordId);
$lastBody = $lastWhatsappMessageData["\x62\157\x64\171"];
$lastDateTime = $lastWhatsappMessageData["\144\x61\164\145\124\151\x6d\x65"];
$newMessagearray[$label] = array(
"\x72\x65\143\x6f\x72\x64\111\x64" => $recordId,
"\154\x61\x62\145\x6c" => $label,
"\160\x72\157\146\151\x6c\x65\111\x6d\141\x67\145" => $profileImage,
"\x69\x6d\141\x67\145\164\141\x67" => $imagetag,
"\x75\x6e\162\145\x61\144\115\145\163\163\141\147\x65\103\157\165\x6e\x74" => $unreadMessageCount,
"\x61\x76\x67\x4d\x65\x73\163\141\x67\145\104\x61\x79" => $avgMessageDay,
"\154\x61\x73\164\x42\x6f\x64\x79" => $lastBody,
"\x6c\141\163\x74\104\x61\164\145\x54\x69\155\145" => $lastDateTime
);
}
}
}
}
}
return $newMessagearray;
}
public function getWhatsappUnReadNewMessageCounts($phonenumber)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . "\x20\101\116\104\x20\166\164\151\x67\x65\x72\137\143\x74\167\150\x61\x74\x73\141\x70\160\56\x77\x68\141\164\163\x61\x70\160\x5f\165\x6e\x72\145\141\x64\162\x65\x61\x64\40\75\x20\x27\x55\156\162\145\x61\x64\x27\40\101\116\104\40\166\x74\x69\x67\145\162\x5f\x63\x74\167\x68\141\164\x73\141\x70\x70\56\x77\150\x61\x74\163\x61\x70\160\137\167\151\x74\x68\x63\x63\x6f\x64\145\x20\75\x20\77\x20\101\x4e\x44\40\166\164\151\147\x65\x72\137\x63\164\x77\x68\141\164\163\x61\x70\x70\56\x6d\x65\163\163\141\x67\145\137\164\x79\x70\x65\40\x3d\x20\x27\122\145\143\151\x65\166\145\144\47", array(
$phonenumber
));
$unreadCount = $adb->num_rows($query);
$allMessageQuery = $adb->pquery($unreadQuery . "\40\101\116\104\40\166\164\x69\147\x65\x72\137\x63\x74\x77\150\141\x74\x73\x61\160\x70\56\167\150\141\164\163\x61\160\160\137\167\x69\x74\150\143\x63\157\x64\145\40\75\40\x3f", array(
$phonenumber
));
$rows = $adb->num_rows($allMessageQuery);
$totalDays = 30;
$avgMessageDay = $rows / $totalDays;
$result = array(
"\165\156\x72\x65\x61\x64\x43\x6f\x75\x6e\x74" => $unreadCount,
"\141\166\147\115\x65\163\163\141\147\145\104\x61\x79" => number_format($avgMessageDay, 2)
);
return $result;
}
public function getLastWhatsappNewMessageData($phonenumber)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . "\40\101\x4e\x44\40\x76\164\x69\x67\x65\x72\x5f\x63\x74\x77\x68\141\x74\163\x61\160\160\56\167\150\141\x74\163\x61\x70\x70\x5f\x77\151\x74\x68\x63\x63\157\144\x65\x20\x3d\40\77\x20\x4f\x52\x44\x45\122\40\x42\x59\x20\166\164\151\x67\x65\x72\137\x63\164\x77\150\141\x74\163\x61\160\160\x2e\x63\164\167\150\141\164\163\x61\160\x70\151\144\40\x44\x45\123\x43\40\114\111\115\x49\124\40\x30\54\x31", array(
$phonenumber
));
$body = $adb->query_result($query, 0, "\155\x65\x73\163\141\x67\145\x5f\142\157\144\x79");
if ($adb->query_result($query, 0, "\167\150\141\x74\x73\141\x70\x70\x5f\144\x61\x74\x65\x74\151\x6d\x65")) {
$dateTime = Vtiger_Util_Helper::formatDateDiffInStrings($adb->query_result($query, 0, "\x77\x68\x61\x74\163\141\x70\160\x5f\144\x61\164\145\x74\x69\x6d\x65"));
} else {
$dateTime == '';
}
$whatsappData = array(
"\142\157\x64\171" => $body,
"\144\141\x74\145\x54\151\x6d\145" => $dateTime
);
return $whatsappData;
}
public function getImageDetails($recordId, $setype)
{
global $root_directory;
$db = PearDatabase::getInstance();
$imageDetails = array();
if ($recordId) {
$sql = "\123\105\114\x45\x43\124\x20\166\x74\x69\147\x65\x72\137\x61\164\164\141\x63\150\x6d\x65\156\x74\163\x2e\x2a\x2c\40\166\164\151\147\145\x72\x5f\143\x72\155\x65\x6e\x74\151\164\x79\x2e\x73\x65\x74\x79\160\145\40\x46\x52\x4f\115\40\166\164\x69\x67\x65\162\137\141\164\x74\x61\143\150\155\x65\156\164\163\xa\11\x9\11\x9\11\x9\x49\x4e\x4e\105\x52\40\112\x4f\x49\x4e\x20\x76\164\151\147\145\x72\137\163\145\x61\164\x74\141\x63\x68\155\145\156\x74\x73\162\x65\x6c\x20\x4f\x4e\40\x76\164\151\147\145\162\137\163\145\x61\164\x74\141\x63\150\155\145\x6e\x74\x73\x72\145\154\56\141\x74\x74\x61\x63\150\x6d\x65\156\164\x73\151\x64\40\x3d\40\x76\x74\151\x67\x65\162\x5f\141\x74\164\141\x63\x68\155\145\x6e\164\x73\x2e\x61\x74\164\x61\143\x68\x6d\x65\x6e\164\x73\x69\x64\xa\11\x9\x9\x9\11\11\x49\116\x4e\x45\122\x20\x4a\x4f\x49\116\x20\166\164\x69\x67\145\162\137\x63\x72\155\x65\x6e\x74\x69\x74\x79\x20\117\x4e\x20\166\x74\151\147\x65\x72\x5f\143\162\155\145\x6e\x74\x69\x74\171\x2e\x63\162\155\151\x64\40\75\40\x76\164\151\x67\145\162\x5f\141\164\164\141\143\x68\155\145\x6e\164\163\56\x61\x74\164\141\143\x68\155\x65\x6e\x74\x73\151\x64\xa\x9\11\11\11\x9\11\127\110\x45\x52\x45\40\166\x74\151\147\x65\162\x5f\163\145\x61\164\x74\x61\143\x68\155\145\x6e\x74\x73\x72\x65\154\56\143\x72\155\151\x64\40\x3d\x20\x3f";
$result = $db->pquery($sql, array(
$recordId
));
$imageId = $db->query_result($result, 0, "\x61\x74\x74\x61\143\x68\155\x65\x6e\164\x73\151\144");
$imagePath = $db->query_result($result, 0, "\x70\141\x74\150");
$imageName = $db->query_result($result, 0, "\x6e\x61\x6d\145");
$imageOriginalName = urlencode(decode_html($imageName));
if (! empty($imageName)) {
$imageDetails[] = array(
"\x69\144" => $imageId,
"\x6f\162\147\x6e\x61\155\x65" => $imageOriginalName,
"\x70\x61\x74\x68" => $imagePath . $imageId,
"\x6e\x61\155\x65" => $imageName
);
$imagePath = $imagePath . $imageId . "\x5f" . $imageName;
}
}
return $imagePath;
}
public function getWhatsappUnReadMessageCounts($recordId)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . "\40\x41\x4e\104\40\166\x74\x69\147\x65\162\137\x63\164\167\150\x61\164\163\x61\x70\160\56\x77\150\141\164\x73\141\x70\x70\x5f\x75\156\x72\145\141\x64\162\x65\141\x64\40\75\x20\47\125\156\x72\145\x61\144\x27\40\101\116\104\x20\166\164\x69\x67\145\x72\x5f\x63\x74\167\x68\x61\x74\x73\x61\x70\x70\x2e\x77\x68\141\164\163\x61\x70\x70\x5f\x63\157\x6e\164\x61\x63\164\151\144\x20\75\40\77\x20\101\x4e\104\x20\x76\x74\x69\147\145\162\137\x63\x74\x77\150\x61\x74\163\141\x70\x70\x2e\155\x65\163\x73\141\x67\145\x5f\x74\171\160\145\x20\75\x20\x27\x52\x65\x63\x69\x65\x76\x65\144\47", array(
$recordId
));
$unreadCount = $adb->num_rows($query);
$allMessageQuery = $adb->pquery($unreadQuery . "\x20\x41\116\x44\40\166\164\x69\147\x65\162\137\143\x74\x77\x68\141\164\x73\x61\x70\160\x2e\x77\150\141\164\163\x61\x70\160\137\143\157\x6e\164\x61\x63\164\151\x64\x20\75\x20\x3f", array(
$recordId
));
$rows = $adb->num_rows($allMessageQuery);
$totalDays = 30;
$avgMessageDay = $rows / $totalDays;
$result = array(
"\x75\x6e\x72\x65\x61\144\103\157\165\x6e\164" => $unreadCount,
"\141\166\x67\x4d\145\163\163\141\x67\145\104\141\x79" => number_format($avgMessageDay, 2)
);
return $result;
}
public function getLastWhatsappMessageData($recordId)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $adb->pquery($unreadQuery . "\x20\x41\x4e\x44\40\x76\164\151\x67\145\162\x5f\x63\164\x77\x68\141\x74\163\141\x70\160\x2e\167\x68\141\x74\163\141\x70\x70\137\x63\x6f\156\164\141\143\164\151\x64\40\x3d\x20\x3f\40\x4f\x52\x44\x45\122\40\102\131\40\166\x74\151\147\x65\x72\137\143\x74\167\150\x61\164\163\141\x70\x70\56\143\164\x77\150\x61\x74\163\141\x70\160\x69\144\x20\104\x45\x53\103\40\114\x49\115\111\124\x20\x30\54\61", array(
$recordId
));
$body = $adb->query_result($query, 0, "\155\145\163\x73\x61\x67\145\137\x62\157\x64\171");
if ($adb->query_result($query, 0, "\167\x68\x61\x74\x73\x61\x70\160\137\x64\141\x74\145\164\151\155\x65")) {
$dateTime = Vtiger_Util_Helper::formatDateDiffInStrings($adb->query_result($query, 0, "\x77\150\x61\164\x73\x61\160\x70\x5f\x64\x61\164\145\164\151\155\x65"));
} else {
$dateTime == '';
}
$whatsappData = array(
"\x62\x6f\144\171" => $body,
"\x64\141\164\x65\124\x69\x6d\145" => $dateTime
);
return $whatsappData;
}
public function getUnknownMessagesData($start, $end, $searchValue)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
if ($searchValue) {
$customQuery = "\40\x41\116\x44\40\166\164\x69\147\x65\x72\x5f\x63\164\x77\x68\x61\164\163\141\160\x70\x2e\167\150\x61\164\x73\141\160\x70\x5f\x77\151\x74\x68\143\x63\x6f\144\x65\x20\x4c\x49\x4b\105\40\x27\45" . $searchValue . "\x25\47";
$query = $adb->pquery($unreadQuery . "\x20\x41\x4e\104\40\x28\x76\x74\151\147\145\162\x5f\143\164\167\x68\141\164\x73\141\160\160\x2e\167\150\141\x74\x73\x61\x70\x70\137\167\x69\x74\x68\x63\143\x6f\144\145\x20\x21\x3d\x20\x27\107\162\x6f\x75\160\x73\47\x20\x41\116\104\x20\166\164\x69\147\x65\162\137\x63\164\x77\x68\141\x74\163\x61\160\x70\56\167\150\141\164\163\x61\160\160\137\167\151\164\150\143\x63\x6f\144\x65\x20\x21\75\x20\47\47\x29\40\101\116\x44\x20\x76\x74\151\147\145\x72\137\143\164\x77\x68\x61\x74\x73\141\160\160\x2e\x77\x68\x61\x74\x73\x61\160\160\x5f\x63\157\x6e\164\141\x63\x74\151\x64\x20\75\x20\x27\47\40" . $customQuery . "\40\x47\122\117\x55\120\x20\x42\x59\x20\x76\x74\x69\x67\x65\162\137\x63\164\167\150\141\x74\x73\x61\160\x70\x2e\167\150\x61\x74\163\141\160\160\137\x77\x69\164\150\143\x63\157\144\x65\40\x4f\x52\104\105\x52\40\102\x59\x20\x76\x74\151\x67\145\162\x5f\143\x72\x6d\x65\156\x74\151\x74\x79\x2e\x63\162\145\141\164\x65\x64\x74\x69\x6d\145\40\104\105\123\x43");
} else {
$searchQuery = "\x20\117\122\x44\x45\x52\40\102\x59\40\166\x74\x69\x67\x65\162\137\x63\x72\155\x65\x6e\x74\151\x74\x79\56\x63\x72\145\141\x74\x65\144\164\x69\x6d\145\40\x44\105\123\x43\40\114\111\115\x49\124\40\60\54\40" . $start;
$query = $adb->pquery($unreadQuery . "\x20\x41\x4e\x44\40\50\x76\164\151\x67\x65\x72\x5f\143\x74\167\150\141\x74\x73\141\x70\x70\56\167\x68\x61\164\x73\x61\160\160\137\x77\151\x74\150\143\x63\x6f\x64\x65\x20\x21\x3d\40\x27\x47\x72\x6f\165\x70\x73\47\x20\101\x4e\x44\40\x76\164\x69\147\x65\162\x5f\x63\x74\167\x68\141\x74\x73\141\160\x70\x2e\x77\150\x61\164\163\141\160\x70\x5f\167\151\164\x68\x63\143\x6f\x64\145\x20\x21\75\x20\x27\47\51\x20\101\116\x44\x20\166\164\151\x67\x65\x72\x5f\143\164\167\x68\141\164\x73\x61\160\160\x2e\167\150\141\164\x73\x61\x70\160\x5f\x63\x6f\156\x74\x61\x63\x74\x69\144\40\75\x20\47\47\x20\x47\122\x4f\125\x50\40\102\131\40\x76\x74\151\147\x65\x72\x5f\x63\x74\x77\150\141\x74\x73\141\x70\x70\x2e\167\150\141\x74\163\x61\160\x70\137\167\151\164\150\143\x63\157\144\145" . $searchQuery);
}
$rows = $adb->num_rows($query);
$newMessagearray = array();
for ($i = 0; $i < $rows; $i ++) {
$label = $adb->query_result($query, $i, "\x77\x68\x61\164\163\141\x70\x70\x5f\167\151\x74\x68\143\143\157\x64\x65");
$recordId = $label;
$profileImage = "\x6c\x61\x79\157\x75\164\163\x2f\x76\x37\57\155\157\x64\x75\x6c\145\x73\x2f\103\124\x57\150\x61\164\163\101\160\160\x2f\151\155\141\x67\x65\x2f\101\x76\x74\x61\x72\111\x63\157\x6e\x2e\160\x6e\147";
$imagetag = 1;
$messageData = CTWhatsApp_Record_Model::getWhatsappUnReadNewMessageCounts($label);
$unreadMessageCount = $messageData["\x75\x6e\162\x65\141\x64\103\x6f\165\x6e\x74"];
$avgMessageDay = $messageData["\141\x76\x67\x4d\145\163\x73\141\x67\145\x44\141\x79"];
$lastWhatsappMessageData = CTWhatsApp_Record_Model::getLastWhatsappNewMessageData($label);
$lastBody = $lastWhatsappMessageData["\x62\157\x64\171"];
$lastDateTime = $lastWhatsappMessageData["\144\x61\164\145\124\151\x6d\145"];
$newMessagearray[$label] = array(
"\162\145\x63\157\162\x64\111\144" => $recordId,
"\154\x61\142\145\x6c" => $label,
"\160\162\x6f\146\151\x6c\145\x49\x6d\x61\x67\x65" => $profileImage,
"\151\155\x61\147\x65\164\x61\x67" => $imagetag,
"\x75\156\x72\x65\141\144\115\x65\x73\x73\x61\147\x65\103\157\165\x6e\x74" => $unreadMessageCount,
"\x61\x76\147\x4d\x65\163\163\x61\x67\145\x44\x61\x79" => $avgMessageDay,
"\154\x61\163\x74\x42\157\x64\171" => $lastBody,
"\x6c\x61\x73\x74\104\141\x74\x65\x54\151\155\x65" => $lastDateTime
);
}
return $newMessagearray;
}
public function getModuleMessagesData($whatsappmodule, $start, $end, $searchValue)
{
global $adb;
$whatsaappModuleData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($whatsappmodule);
$phoneField = $whatsaappModuleData["\x70\150\157\156\x65\x46\x69\x65\154\144"];
$moduleQuery = CTWhatsApp_Record_Model::moduleQuery($whatsappmodule, $phoneField, $searchValue);
if ($searchValue) {
$query = $adb->pquery($moduleQuery);
} else {
$query = $adb->pquery($moduleQuery . "\x20\114\x49\x4d\111\x54\x20\x30\x2c\x20" . $start);
}
$rows = $adb->num_rows($query);
$moduleRecordData = array();
for ($i = 0; $i < $rows; $i ++) {
$recordId = $adb->query_result($query, $i, "\x63\x72\155\x69\x64");
$label = $adb->query_result($query, $i, "\154\x61\x62\145\x6c");
$setype = $adb->query_result($query, $i, "\163\x65\x74\171\160\145");
$profileImage = CTWhatsApp_Record_Model::getImageDetails($recordId, $setype);
$imagetag = 1;
if ($profileImage == '') {
$labelExplode = explode("\x20", $label);
$profileImage = mb_substr($labelExplode[0], 0, 1, "\x55\124\x46\55\x38") . mb_substr($labelExplode[1], 0, 1, "\x55\124\106\x2d\x38");
$imagetag = 0;
}
$messageData = CTWhatsApp_Record_Model::getWhatsappUnReadMessageCounts($recordId);
$unreadMessageCount = $messageData["\x75\156\x72\x65\x61\144\x43\x6f\x75\156\164"];
$avgMessageDay = $messageData["\141\x76\147\115\145\x73\x73\141\x67\x65\x44\x61\171"];
$lastWhatsappMessageData = CTWhatsApp_Record_Model::getLastWhatsappMessageData($recordId);
$lastBody = $lastWhatsappMessageData["\142\157\x64\x79"];
$lastDateTime = $lastWhatsappMessageData["\144\x61\164\x65\124\x69\155\145"];
$moduleRecordData[] = array(
"\x72\145\x63\x6f\x72\x64\x49\x64" => $recordId,
"\x6c\x61\142\x65\154" => $label,
"\160\x72\x6f\x66\151\x6c\x65\111\x6d\x61\147\x65" => $profileImage,
"\x69\155\141\147\x65\x74\141\147" => $imagetag,
"\x75\156\x72\x65\x61\x64\115\145\163\x73\141\147\x65\103\x6f\x75\x6e\164" => $unreadMessageCount,
"\141\166\147\115\145\x73\163\x61\147\145\x44\x61\171" => $avgMessageDay,
"\x6c\x61\163\164\x42\157\144\171" => $lastBody,
"\154\x61\163\x74\104\141\x74\x65\x54\151\x6d\x65" => $lastDateTime
);
}
return $moduleRecordData;
}
public function getModuleRecordData($recordId, $setype, $whatsappModule, $groupid)
{
global $adb;
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $setype);
$label = $recordModel->get("\154\x61\142\x65\154");
$phoneFieldData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($setype);
$phoneField = $phoneFieldData["\160\150\x6f\156\x65\x46\151\145\x6c\x64"];
$phone = $recordModel->get($phoneField);
$profileImage = CTWhatsApp_Record_Model::getImageDetails($recordId, $setype);
$imagetag = 1;
if ($profileImage == '') {
$labelExplode = explode("\x20", $label);
$profileImage = mb_substr($labelExplode[0], 0, 1, "\x55\x54\106\x2d\x38") . mb_substr($labelExplode[1], 0, 1, "\125\124\x46\55\70");
$imagetag = 0;
}
$getWhatsappMessages = CTWhatsApp_Record_Model::getWhatsappMessages($recordId, $setype, $whatsappModule, $groupid);
$whatsappMessageHTML = $getWhatsappMessages["\x77\150\141\164\163\x61\x70\160\x4d\x65\x73\x73\141\147\x65\110\x54\115\x4c"];
$totalSent = $getWhatsappMessages["\x74\157\164\x61\x6c\x53\145\x6e\x74"];
$totalReceived = $getWhatsappMessages["\164\157\164\x61\x6c\122\x65\x63\145\x69\166\145\x64"];
$recentComments = $getWhatsappMessages["\x63\157\x6d\155\x65\156\164\110\124\115\114"];
$messageImportant = $getWhatsappMessages["\x6d\145\163\x73\141\x67\145\x49\155\x70\157\162\164\141\156\164"];
$moduleIsEnable = $getWhatsappMessages["\x6d\x6f\144\165\154\x65\111\x73\105\x6e\141\142\x6c\x65"];
$tabid = getTabid($setype);
$query = $adb->pquery("\123\105\114\105\103\x54\40\x2a\x20\106\122\117\x4d\x20\166\164\151\147\x65\162\x5f\146\x69\x65\154\144\40\x57\110\105\x52\x45\x20\x74\141\x62\x69\x64\40\75\x20\x3f\40\x41\x4e\104\x20\x73\165\x6d\155\x61\162\x79\146\151\x65\154\144\40\x3d\x20\x3f\x20\101\116\104\x20\x75\x69\x74\171\160\x65\40\x4e\117\x54\40\x49\x4e\x20\x28\x27\61\x30\x27\54\40\47\65\x31\47\51", array(
$tabid,
1
));
$rows = $adb->num_rows($query);
$keyFields = array();
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $setype);
$commentModule = CTWhatsApp_Record_Model::checkCommentModuleEnable($setype);
$ModCommentsEnable = CTWhatsApp_Record_Model::checkPermissionModule("\115\157\x64\x43\157\x6d\155\x65\156\x74\163");
$actionName = "\x45\x64\x69\x74\x56\151\x65\x77";
if (! Users_Privileges_Model::isPermitted($setype, $actionName, $recordId)) {
$permissionRecord = "\x30";
} else {
$permissionRecord = "\61";
}
$themeView = CTWhatsApp_Record_Model::getWhatsappTheme();
$keyFieldsHTML = '';
if ($permissionRecord == 1) {
for ($i = 0; $i < $rows; $i ++) {
if ($i < 4) {
$fieldlabel = vtranslate($adb->query_result($query, $i, "\x66\x69\145\x6c\x64\154\141\x62\145\154"), $setype);
$fieldname = $adb->query_result($query, $i, "\146\x69\x65\154\144\156\x61\155\145");
$fieldvalue = $recordModel->get($fieldname);
if ($fieldname == "\x61\163\163\151\147\156\x65\x64\x5f\165\x73\145\x72\137\x69\x64") {
$getusername = $adb->pquery("\x53\105\x4c\105\103\124\40\x2a\x20\106\122\x4f\115\40\x76\x74\x69\147\145\162\137\x75\x73\145\x72\163\40\x57\110\x45\x52\x45\40\151\x64\75\77", array(
$fieldvalue
));
$userrows = $adb->num_rows($getusername);
if ($userrows == 0) {
$getgroup = $adb->pquery("\123\x45\x4c\105\x43\x54\40\52\x20\106\122\117\115\40\166\x74\x69\147\145\x72\137\147\x72\x6f\x75\160\x73\40\127\x48\x45\122\105\40\147\162\157\x75\160\x69\x64\x3d\77", array(
$fieldvalue
));
$grouprows = $adb->num_rows($getgroup);
$fieldvalue = $adb->query_result($getgroup, 0, "\147\x72\157\165\x70\x6e\141\x6d\145");
} else {
$fieldvalue = $adb->query_result($getusername, 0, "\x66\151\x72\163\164\137\156\x61\155\145") . "\x20" . $adb->query_result($getusername, 0, "\154\141\x73\164\137\156\141\x6d\145");
}
}
if ($themeView == "\x52\124\x4c") {
$keyFieldsHTML .= "\74\x70\76\74\163\160\141\x6e\x20\x63\154\141\163\163\x3d\42\x22\76" . $fieldvalue . "\x3c\57\x73\160\x61\x6e\76\x20\x3a\40" . $fieldlabel . "\x3c\x2f\160\x3e";
} else {
$keyFieldsHTML .= "\74\160\x3e" . $fieldlabel . "\40\x3a\40\74\163\160\141\x6e\x20\x63\154\x61\x73\163\75\x22\42\76" . $fieldvalue . "\74\x2f\163\x70\x61\156\76\74\x2f\160\x3e";
}
}
}
}
$relatedModules = CTWhatsApp_Record_Model::getRelatedModules($setype);
$relatedModuleHTML = '';
foreach ($relatedModules as $key => $value) {
$relatedModule = vtranslate($value["\162\145\x6c\141\164\145\x64\x4d\157\x64\x75\x6c\145"], $value["\x72\x65\154\x61\164\x65\144\115\x6f\x64\165\x6c\145"]);
$moduleURL = "\x69\x6e\144\145\170\x2e\160\150\x70\77\155\x6f\144\x75\x6c\145\x3d" . $value["\x72\145\154\141\164\x65\x64\x4d\157\144\x75\154\145"] . "\46\x76\151\145\167\75\121\x75\x69\143\x6b\103\x72\145\x61\164\x65\x41\x6a\x61\x78\46" . $value["\x72\x65\x6c\141\x74\145\144\x46\x69\145\154\x64\116\x61\x6d\145"] . "\75" . $recordId;
$relatedModuleHTML .= "\74\x61\x20\x69\x64\75\42\155\145\156\x75\142\141\x72\137\161\165\x69\x63\x6b\x43\162\145\x61\164\145\x5f" . $value["\x72\x65\x6c\x61\x74\145\x64\115\157\144\165\154\x65"] . "\42\x20\x63\x6c\x61\163\163\x3d\42\x64\162\x6f\160\x64\157\167\156\x2d\x69\164\x65\155\40\161\x75\x69\143\153\x43\162\x65\141\x74\145\x4d\x6f\144\165\154\x65\x22\x20\x68\x72\x65\x66\75\x22\43\42\40\144\141\164\x61\55\x6e\x61\x6d\x65\x3d\42" . $value["\x72\145\154\x61\x74\145\144\x4d\x6f\144\165\154\x65"] . "\x22\40\x64\x61\x74\x61\55\165\162\154\x3d\42" . $moduleURL . "\x22\x3e" . $relatedModule . "\x3c\57\141\x3e";
}
$moduleRecrodData = array(
"\162\x65\143\157\x72\144\x49\144" => $recordId,
"\154\x61\142\145\x6c" => $label,
"\x70\150\157\x6e\145" => $phone,
"\160\x72\x6f\146\x69\154\x65\x49\x6d\141\147\x65" => $profileImage,
"\x69\x6d\x61\147\145\164\x61\147" => $imagetag,
"\167\150\141\164\x73\x61\x70\x70\x4d\145\163\x73\x61\147\x65\163" => $whatsappMessageHTML,
"\153\x65\x79\x46\x69\145\154\x64\x73\110\124\115\x4c" => $keyFieldsHTML,
"\164\157\164\x61\x6c\123\145\156\164" => $totalSent,
"\164\x6f\164\141\x6c\122\145\x63\145\x69\x76\x65\144" => $totalReceived,
"\162\145\x63\x65\156\164\103\x6f\155\x6d\x65\156\x74\163" => $recentComments,
"\x72\145\x6c\x61\x74\x65\144\x4d\x6f\x64\165\x6c\145\x48\x54\115\114" => $relatedModuleHTML,
"\155\145\163\163\x61\147\x65\111\155\x70\x6f\x72\x74\x61\x6e\164" => $messageImportant,
"\163\x65\164\x79\x70\145" => $setype,
"\143\157\x6d\x6d\145\x6e\x74\x4d\x6f\144\x75\x6c\145" => $commentModule,
"\155\x6f\144\x75\154\145\111\x73\x45\156\x61\142\x6c\x65" => $moduleIsEnable,
"\x4d\x6f\144\103\157\x6d\x6d\145\x6e\x74\x73\x45\156\x61\142\154\x65" => $ModCommentsEnable,
"\160\145\x72\x6d\x69\163\163\151\157\x6e\122\x65\143\x6f\x72\144" => $permissionRecord
);
return $moduleRecrodData;
}
public function getMessagesRecordData($recordId, $whatsappModule, $groupid)
{
global $adb;
$label = $recordId;
if ($groupid) {
$profileImage = "\154\x61\x79\x6f\165\164\163\57\166\x37\57\x6d\x6f\x64\x75\x6c\x65\x73\x2f\103\124\x57\x68\x61\x74\x73\101\x70\160\x2f\151\x6d\x61\x67\x65\x2f\x67\x72\157\x75\160\163\56\x70\x6e\147";
} else {
$profileImage = "\154\x61\x79\x6f\x75\x74\x73\57\166\67\57\155\x6f\x64\165\x6c\x65\x73\x2f\x43\x54\x57\150\141\x74\163\101\x70\160\57\151\155\141\x67\x65\x2f\x41\x76\x74\141\162\x49\x63\157\156\x2e\x70\x6e\147";
}
$imagetag = 1;
$getWhatsappMessages = CTWhatsApp_Record_Model::getWhatsappMessages($recordId, $setype, $whatsappModule, $groupid);
$whatsappMessageHTML = $getWhatsappMessages["\167\150\x61\164\x73\x61\x70\x70\115\x65\163\x73\141\x67\145\x48\x54\115\114"];
$totalSent = $getWhatsappMessages["\164\157\164\141\154\123\x65\156\164"];
$totalReceived = $getWhatsappMessages["\164\x6f\x74\x61\154\x52\x65\x63\x65\x69\166\145\144"];
$messageImportant = $getWhatsappMessages["\x6d\145\x73\163\x61\x67\x65\111\x6d\160\x6f\x72\x74\x61\x6e\164"];
$moduleIsEnable = $getWhatsappMessages["\x6d\157\x64\x75\x6c\x65\111\x73\x45\x6e\x61\x62\154\x65"];
$recentComments = '';
$themeView = CTWhatsApp_Record_Model::getWhatsappTheme();
if ($themeView == "\x52\x54\114") {
$keyFieldsHTML = "\74\160\76\74\163\160\141\x6e\x20\x63\154\141\x73\163\x3d\x22\x22\76" . $recordId . "\74\57\163\x70\x61\156\76\40\x3a\40" . vtranslate("\114\x42\x4c\137\x50\x48\x4f\x4e\105\137\x4e\x55\115\102\x45\x52", "\x56\164\x69\x67\x65\162") . "\x3c\x2f\160\x3e";
} else {
$keyFieldsHTML = "\x3c\160\76" . vtranslate("\x4c\102\x4c\x5f\120\110\x4f\116\105\137\116\125\x4d\x42\105\x52", "\x56\x74\151\x67\145\162") . "\x20\x3a\40\x3c\163\160\x61\156\40\x63\x6c\141\163\x73\75\x22\42\x3e" . $recordId . "\x3c\57\163\x70\141\156\x3e\x3c\x2f\160\x3e";
}
$relatedModules = CTWhatsApp_Record_Model::getWhatsappAllowModules();
$commentModule = CTWhatsApp_Record_Model::checkCommentModuleEnable($setype);
$ModCommentsEnable = CTWhatsApp_Record_Model::checkPermissionModule("\115\x6f\x64\x43\157\155\155\145\156\x74\x73");
$relatedModuleHTML = '';
foreach ($relatedModules as $key => $value) {
$relatedModule = vtranslate($value["\155\157\x64\165\154\145"], $value["\x6d\157\x64\x75\154\x65"]);
$moduleURL = "\151\156\144\145\170\56\160\x68\160\x3f\155\x6f\144\x75\x6c\145\75" . $value["\155\x6f\x64\x75\x6c\x65"] . "\x26\x76\151\145\x77\x3d\x51\x75\x69\143\153\x43\162\145\x61\164\145\101\x6a\141\170\46" . $value["\160\150\x6f\x6e\x65\x46\x69\145\x6c\x64"] . "\75" . $recordId;
$relatedModuleHTML .= "\x3c\x61\x20\151\x64\x3d\x22\x6d\x65\156\165\x62\141\x72\137\161\x75\151\143\x6b\x43\x72\x65\141\x74\x65\x5f" . $value["\x6d\x6f\144\165\154\x65"] . "\x22\x20\143\x6c\x61\x73\163\x3d\x22\144\162\x6f\x70\144\157\x77\156\55\151\x74\x65\155\40\x71\x75\x69\143\x6b\103\x72\x65\x61\x74\x65\x4d\157\144\165\x6c\x65\x22\40\150\162\x65\x66\75\x22\x23\x22\40\144\141\x74\141\x2d\156\x61\x6d\x65\75\x22" . $value["\x6d\157\x64\165\154\x65"] . "\x22\x20\144\x61\164\141\x2d\165\162\154\x3d\42" . $moduleURL . "\x22\x3e" . $relatedModule . "\x3c\x2f\141\76";
}
$moduleRecrodData = array(
"\154\141\142\x65\x6c" => $label,
"\160\150\x6f\156\x65" => $recordId,
"\160\x72\157\146\151\154\145\111\x6d\141\x67\145" => $profileImage,
"\x69\155\x61\147\x65\x74\x61\x67" => $imagetag,
"\x77\x68\141\x74\163\x61\160\160\115\145\163\x73\141\x67\x65\x73" => $whatsappMessageHTML,
"\x74\x6f\x74\141\154\123\145\156\x74" => $totalSent,
"\164\x6f\164\x61\154\122\x65\x63\145\151\x76\145\144" => $totalReceived,
"\x6b\x65\171\x46\151\x65\x6c\x64\x73\x48\124\115\x4c" => $keyFieldsHTML,
"\x72\x65\x63\x65\x6e\164\103\157\155\x6d\x65\156\164\163" => $recentComments,
"\x72\145\x6c\141\164\145\x64\115\157\x64\x75\154\x65\110\124\x4d\x4c" => $relatedModuleHTML,
"\155\x65\x73\x73\x61\x67\145\111\155\x70\x6f\x72\164\141\156\164" => $messageImportant,
"\x63\157\x6d\x6d\x65\156\164\x4d\x6f\x64\x75\x6c\145" => $commentModule,
"\155\x6f\144\x75\x6c\x65\x49\163\x45\156\141\x62\x6c\145" => $moduleIsEnable,
"\x4d\x6f\144\x43\x6f\x6d\x6d\145\x6e\x74\x73\x45\156\141\142\154\145" => $ModCommentsEnable
);
return $moduleRecrodData;
}
public function getWhatsappMessages($recordId, $setype, $whatsappModule, $groupid)
{
global $adb;
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
if ($whatsappModule == "\107\162\x6f\165\x70\163") {
$customQuery = "\40\101\x4e\104\40\155\163\x67\x69\x64\40\75\40\x3f";
$query = $adb->pquery($unreadQuery . $customQuery, array(
$groupid
));
} else {
if ($setype) {
$customQuery = "\x20\x41\x4e\x44\x20\167\x68\141\x74\163\x61\x70\x70\x5f\x63\157\156\x74\x61\143\x74\151\144\x20\75\x20\x3f";
$query = $adb->pquery($unreadQuery . $customQuery, array(
$recordId
));
} else {
$recordId = preg_replace("\57\133\136\101\55\x5a\x61\x2d\172\60\x2d\x39\135\x2f", '', $recordId);
$customQuery = "\x20\101\116\104\40\x77\150\141\164\163\x61\160\x70\x5f\167\x69\x74\150\x63\143\157\144\145\40\114\111\x4b\x45\x20\x22\45" . $recordId . "\45\x22";
$query = $adb->pquery($unreadQuery . $customQuery, array());
}
}
$rows = $adb->num_rows($query);
$totalSent = 0;
$totalReceived = 0;
$whatsappMessage = array();
$whatsappMessageHTML = "\x3c\144\151\166\40\143\154\x61\163\x73\x3d\42\143\x68\x61\x74\x44\x69\166\x22\76";
$imgExts = array(
"\x67\x69\146",
"\152\x70\x67",
"\152\160\145\x67",
"\x70\156\147",
"\164\151\x66\146",
"\164\151\146"
);
$fileExts = array(
"\160\x64\146",
"\164\170\164",
"\x70\150\x70",
"\172\x69\160",
"\143\x73\166",
"\x64\157\x63\x78",
"\150\164\x74\160\163"
);
for ($i = 0; $i < $rows; $i ++) {
$ctWhatsappId = $adb->query_result($query, $i, "\x63\x74\x77\150\141\x74\x73\x61\160\160\151\144");
$messageImportant = $adb->query_result($query, $i, "\167\150\x61\x74\x73\141\160\x70\137\x69\155\x70\157\x72\164\141\x6e\164");
$messageType = $adb->query_result($query, $i, "\155\145\163\x73\x61\147\x65\137\164\x79\x70\x65");
$messageReadUnRead = $adb->query_result($query, $i, "\167\150\141\x74\x73\x61\160\160\137\165\156\x72\x65\141\x64\162\x65\141\144");
$messageSenderame = $adb->query_result($query, $i, "\x77\150\x61\x74\x73\141\x70\x70\x5f\x73\x65\156\x64\145\x72\156\x61\155\x65");
$isGroup = $adb->query_result($query, $i, "\x77\150\x61\x74\163\x61\x70\x70\137\x77\151\164\x68\143\143\x6f\x64\145");
if ($ctWhatsappId) {
if ($messageReadUnRead == "\x55\156\162\x65\x61\x64" && $messageType == "\122\145\x63\151\145\166\145\x64") {
$recordModel = Vtiger_Record_Model::getInstanceById($ctWhatsappId, "\x43\x54\127\150\141\164\163\101\160\x70");
$recordModel->set("\x6d\157\x64\x65", "\x65\x64\x69\x74");
$recordModel->set("\x69\x64", $ctWhatsappId);
$recordModel->set("\x77\150\141\164\163\141\160\x70\x5f\165\156\162\145\141\x64\162\x65\141\144", "\122\145\141\144");
$recordModel->save();
}
}
$messageBody = nl2br(preg_replace("\43\134\52\50\x5b\136\x2a\135\x2b\x29\134\52\x23", "\74\142\76\44\x31\x3c\x2f\142\x3e", $adb->query_result($query, $i, "\x6d\145\x73\x73\141\x67\145\137\x62\157\x64\171")));
$urlExt = pathinfo($messageBody, PATHINFO_EXTENSION);
if (in_array($urlExt, $imgExts)) {
$messageBody = "\x3c\x69\155\x61\x67\x65\x20\163\162\143\75\42" . $messageBody . "\42\40\x73\164\171\154\x65\75\x22\150\x65\151\x67\150\164\x3a\40\66\60\160\x78\73\x22\76";
} else {
if (in_array($urlExt, $fileExts)) {
$messageBody = "\74\141\40\x68\162\145\146\75\x22" . $messageBody . "\42\x20\164\x61\162\x67\x65\x74\75\x22\137\x62\154\x61\x63\153\42\x3e" . $messageBody . "\74\57\x61\x3e";
}
}
$createdTime = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($adb->query_result($query, $i, "\x77\150\141\x74\x73\x61\160\x70\137\144\x61\164\145\x74\x69\x6d\x65"));
$whatsappMessage[] = array(
"\155\145\x73\163\141\147\x65\124\x79\160\145" => $messageType,
"\x6d\x65\163\163\x61\x67\x65\102\157\x64\x79" => $messageBody,
"\x63\162\145\x61\164\145\144\x54\x69\x6d\x65" => $createdTime
);
if ($messageType == "\123\145\x6e\144" || $messageType == "\115\x61\163\163\x20\x4d\145\x73\x73\x61\x67\145") {
$totalSent = $totalSent + 1;
$whatsappMessageHTML .= "\74\x64\151\x76\40\143\154\x61\x73\x73\x3d\x22\163\145\x6e\144\103\x68\141\164\42\76\12\11\x9\x9\x9\11\x9\x9\x9\x9\x9\x9\x3c\144\151\x76\x20\x63\x6c\x61\x73\x73\x3d\42\x63\157\154\55\x78\163\55\61\x32\40\143\157\x6c\x2d\163\155\55\62\40\143\157\x6c\x2d\x6d\144\55\x32\40\x63\x6f\154\55\x6c\x67\55\62\x22\x3e\12\x9\11\11\11\x9\x9\x9\11\11\x9\x9\74\x2f\144\151\x76\x3e\12\x9\11\x9\x9\x9\11\11\x9\x9\x9\x9\x3c\x64\151\x76\x20\x63\154\141\x73\x73\75\x22\143\157\x6c\55\170\163\x2d\x31\62\40\x63\157\154\x2d\163\x6d\55\62\x20\143\157\x6c\55\x6d\144\x2d\62\x20\143\157\x6c\55\154\147\55\62\42\76\xa\x9\x9\x9\x9\11\11\11\11\x9\x9\x9\74\57\x64\x69\x76\76\xa\11\11\11\x9\11\11\x9\x9\x9\x9\x9\74\144\x69\166\x20\x63\154\x61\x73\163\75\x22\x63\x6f\154\55\170\x73\55\61\x30\x20\143\x6f\154\55\163\x6d\x2d\70\40\x63\x6f\x6c\55\x6d\144\x2d\x38\40\143\157\x6c\55\x6c\x67\55\70\x22\76\11\xa\11\x9\x9\x9\11\x9\x9\x9\x9\x9\x9\x9\x3c\x64\x69\166\x20\x63\154\x61\x73\x73\x3d\42\142\x75\142\142\x6c\x65\x20\163\145\156\x64\42\76\xa\x9\11\x9\11\11\11\11\11\11\x9\11\x9\x9\x3c\160\40\x73\164\x79\154\145\x3d\42\167\x6f\x72\144\x2d\167\x72\x61\160\x3a\40\x62\162\x65\x61\153\55\167\157\x72\x64\x3b\x22\x3e" . $messageBody . "\x3c\57\x70\76\xa\11\x9\11\x9\11\x9\11\x9\x9\11\11\11\74\57\x64\151\x76\76\xa\x9\11\x9\11\x9\x9\11\x9\x9\x9\11\11\74\163\160\x61\156\40\x63\x6c\141\163\163\x3d\x22\143\150\x61\164\124\151\x6d\x65\42\76" . $createdTime . '';
if ($messageReadUnRead == "\x52\145\x61\144") {
$whatsappMessageHTML .= "\x3c\x69\x6d\147\40\x73\x72\x63\x3d\42\154\x61\171\x6f\x75\x74\x73\x2f\x76\67\x2f\x6d\x6f\x64\x75\x6c\145\163\57\x43\x54\x57\150\141\164\163\x41\160\160\57\151\155\141\147\x65\x2f\x72\145\x61\144\56\x70\156\x67\x22\76";
} else {
$whatsappMessageHTML .= "\x3c\151\x6d\147\x20\163\x72\143\x3d\x22\154\141\171\x6f\165\164\163\57\x76\x37\x2f\x6d\x6f\x64\x75\154\x65\163\x2f\x43\x54\127\x68\x61\164\x73\x41\x70\160\x2f\x69\x6d\141\x67\x65\x2f\x75\156\x72\x65\x61\144\56\x70\156\x67\x22\76";
}
$whatsappMessageHTML .= "\74\57\163\160\x61\x6e\x3e\x3c\57\144\151\166\x3e\xa\x9\x9\x9\x9\11\11\11\11\11\11\74\x2f\x64\x69\x76\76";
} else {
if ($messageType == "\122\x65\x63\x69\x65\166\145\x64") {
$totalReceived = $totalReceived + 1;
$whatsappMessageHTML .= "\74\144\151\x76\x20\143\x6c\141\163\x73\x3d\x22\162\x65\x70\x6c\x79\103\x68\x61\164\42\76\12\x9\11\x9\x9\x9\11\11\11\11\11\11\x3c\x64\x69\166\x20\x63\x6c\141\x73\163\x3d\42\143\157\x6c\x2d\170\x73\55\x31\x30\40\x63\x6f\154\x2d\x73\x6d\x2d\x38\40\143\x6f\x6c\55\x6d\x64\55\70\40\143\157\x6c\x2d\x6c\x67\55\70\42\x3e\xa\11\x9\x9\11\11\11\x9\x9\x9\11\x9\x9\x3c\144\x69\x76\x20\143\154\141\163\163\x3d\42\142\x75\x62\x62\x6c\145\x20\162\x65\x70\154\x79\x22\x3e";
if ($isGroup == "\107\162\157\x75\x70\163") {
$whatsappMessageHTML .= "\x3c\x73\x70\x61\x6e\x3e\74\x62\76" . $messageSenderame . "\74\57\x62\x3e\74\57\163\x70\x61\156\x3e";
}
$whatsappMessageHTML .= "\74\160\x20\163\164\171\x6c\x65\x3d\x22\167\x6f\162\x64\55\167\x72\141\x70\72\x20\x62\162\x65\x61\153\x2d\167\x6f\162\144\x3b\x22\x3e" . $messageBody . "\74\57\x70\x3e\12\11\11\x9\x9\11\11\11\x9\x9\x9\x9\x9\x3c\x2f\144\151\x76\76\xa\x9\x9\x9\x9\x9\11\11\x9\x9\11\x9\x9\x3c\x73\160\141\156\40\143\154\x61\x73\x73\x3d\x22\143\150\x61\164\124\x69\x6d\145\x22\x20\163\164\x79\154\x65\x3d\42\167\x69\x64\x74\x68\x3a\x20\x33\x35\x25\73\40\41\151\x6d\x70\x6f\162\164\141\156\x74\x22\76" . $createdTime . '';
if ($messageReadUnRead == "\122\145\x61\144") {
$whatsappMessageHTML .= "\74\x69\x6d\x67\x20\x73\x72\x63\x3d\x22\x6c\x61\171\157\165\164\163\57\x76\x37\57\x6d\x6f\144\x75\154\x65\x73\57\x43\124\127\x68\141\164\163\x41\x70\x70\x2f\x69\155\141\147\145\x2f\x72\145\x61\x64\56\160\x6e\x67\x22\76";
} else {
$whatsappMessageHTML .= "\74\151\x6d\x67\40\x73\162\x63\x3d\42\x6c\x61\x79\157\165\164\x73\x2f\x76\67\x2f\x6d\157\144\x75\154\145\x73\x2f\x43\124\x57\150\141\164\x73\x41\160\x70\x2f\x69\155\141\x67\145\57\x75\156\x72\145\x61\144\56\160\156\147\x22\76";
}
$whatsappMessageHTML .= "\x3c\x2f\163\x70\x61\156\x3e\74\x2f\x64\x69\166\76";
if ($setype) {
if (in_array($urlExt, $imgExts)) {
$whatsappMessageHTML .= '';
} else {
$whatsappMessageHTML .= "\x26\156\142\163\160\73\46\x6e\x62\x73\x70\x3b\12\x9\11\x20\40\40\x20\40\40\40\40\x20\40\40\40\x20\x20\40\40\40\x20\x20\x20\40\40\x20\x20\40\40\x20\40\40\40\x20\x20\40\x20\40\x20\x20\40\40\x20\x20\40\40\x20\11\74\x73\x70\x61\156\x20\x63\x6c\141\x73\163\75\42\145\x64\151\x74\x46\x69\x65\154\x64\42\x20\163\x74\171\x6c\145\75\x22\x63\165\x72\163\x6f\162\72\x20\x70\x6f\151\156\x74\x65\x72\x3b\x22\76\12\11\11\40\x20\x20\40\40\40\x20\40\x20\x20\40\40\x20\x20\x20\40\x20\40\x20\40\40\40\x20\40\40\x20\40\x20\x20\x20\x20\40\40\40\40\x20\40\x20\x20\x20\40\40\40\x20\x9\x9\x3c\x69\x6d\x67\x20\x73\x74\171\x6c\145\x3d\x22\146\x6c\x6f\x61\164\72\40\154\x65\x66\x74\x3b\x6d\x61\x72\x67\x69\156\x2d\x6c\x65\146\164\72\x20\55\62\160\x78\x3b\x77\151\x64\164\150\x3a\40\x31\x35\x70\x78\73\40\x21\x69\x6d\x70\157\162\164\x61\156\164\42\x20\163\162\x63\75\x22\154\x61\171\157\x75\164\163\57\166\67\57\155\x6f\x64\165\154\x65\163\57\x43\124\127\150\x61\164\x73\101\160\160\x2f\x69\155\x61\147\x65\x2f\145\x64\x69\x74\x63\157\x6e\x74\145\156\x74\x2e\x70\x6e\147\42\40\x74\151\164\154\145\x3d\x22" . vtranslate("\114\x42\x4c\x5f\105\104\111\124\x46\x49\105\x4c\104", "\x43\124\127\x68\x61\x74\163\x41\160\160") . "\x20" . vtranslate($setype, $setype) . "\42\x3e\xa\x9\x9\x20\40\40\40\x20\x20\x20\x20\x20\x20\x20\40\40\40\40\40\x20\x20\x20\x20\x20\40\x20\40\40\40\x20\40\x20\40\x20\40\x20\x20\40\40\40\x20\x20\x20\x9\11\74\x2f\x73\x70\x61\156\76";
}
}
$whatsappMessageHTML .= "\x3c\144\151\x76\x20\x63\154\141\163\x73\x3d\x22\x63\x6f\x6c\x2d\170\x73\x2d\x31\62\x20\x63\157\154\55\x73\155\55\x32\x20\x63\x6f\x6c\x2d\x6d\x64\55\x32\40\x63\157\x6c\x2d\x6c\147\x2d\62\x22\76\xa\x9\11\x9\11\11\11\x9\11\11\x9\x9\x3c\57\x64\151\166\76\12\xa\x9\x9\x9\11\x9\x9\x9\x9\x9\x9\x3c\57\x64\x69\166\76";
}
}
}
$whatsappMessageHTML .= "\x3c\x2f\x64\151\x76\76";
$moduleIsEnable = CTWhatsApp_Record_Model::getmoduleIsEnable($setype);
if ($setype) {
$pagingModel = new Vtiger_Paging_Model();
$recentComments = ModComments_Record_Model::getRecentComments($recordId, $pagingModel);
$comments = array();
$commentHTML = '';
foreach ($recentComments as $key => $value) {
if ($key < 2) {
$commentcontent = $recentComments[$key]->get("\x63\x6f\155\x6d\x65\x6e\164\x63\x6f\156\164\x65\x6e\164");
$createdtime = $recentComments[$key]->get("\143\x72\x65\x61\164\145\x64\x74\x69\x6d\145");
$smownerid = $recentComments[$key]->get("\163\155\157\167\x6e\145\162\x69\144");
$commentHTML .= "\x3c\x64\151\166\x20\x63\x6c\x61\x73\x73\75\42\x63\157\155\155\145\156\164\x31\x22\x3e\xa\11\x9\x9\11\11\x9\11\x9\x9\11\x3c\x21\x2d\55\x20\x3c\x64\x69\x76\40\143\x6c\x61\x73\x73\75\42\160\151\143\x22\x3e\74\151\155\x67\40\x73\x72\143\x3d\42\154\x61\x79\157\165\164\x73\x2f\x76\x37\x2f\x6d\x6f\x64\165\154\x65\x73\x2f\x43\x54\x57\150\x61\x74\163\x41\160\160\57\x69\155\x61\x67\x65\57\160\151\143\64\56\160\156\147\x22\x20\x2f\76\x3c\x2f\144\x69\x76\76\40\55\55\x3e\12\11\11\11\x9\x9\x9\x9\x9\11\11\74\144\151\x76\x20\143\x6c\141\x73\163\75\42\160\116\141\155\x65\x22\76\xa\11\x9\11\11\x9\11\x9\11\11\11\x9\x3c\144\x69\x76\40\x63\x6c\141\163\x73\x3d\x22\x70\124\145\170\x74\x22\76\12\x9\x9\11\11\x9\11\11\11\11\x9\x9\x9\74\x73\160\141\x6e\76" . Vtiger_Functions::getUserName($smownerid) . "\74\57\x73\x70\x61\x6e\76\xa\11\11\x9\11\11\11\11\11\x9\11\x9\x9\x3c\x73\x70\141\156\x20\x63\154\x61\x73\163\x3d\42\164\x69\x6d\x65\x22\76" . Vtiger_Util_Helper::formatDateDiffInStrings($createdtime) . "\74\57\163\160\x61\x6e\x3e\12\x9\x9\x9\11\x9\11\x9\11\x9\11\11\x9\x3c\x70\76" . decode_html($commentcontent) . "\x3c\57\x70\x3e\xa\x9\x9\x9\x9\11\11\11\x9\11\x9\x9\x3c\57\144\x69\x76\76\12\x9\11\11\11\x9\11\11\x9\x9\11\74\x2f\144\x69\166\x3e\12\x9\x9\x9\11\11\x9\x9\11\11\74\57\144\x69\166\76";
}
if ($key > 3) {
$moreCommentLink = "\74\x73\160\x61\156\40\143\154\x61\163\163\x3d\x27\160\x75\154\154\x2d\162\151\147\150\164\x27\40\x73\164\171\x6c\145\x3d\47\143\x6f\x6c\157\x72\x3a\x20\142\x6c\165\145\73\47\76\x3c\141\40\150\x72\145\x66\x3d\x27\x69\x6e\x64\x65\x78\56\160\x68\x70\x3f\155\157\x64\x75\154\x65\75" . $setype . "\x26\x72\145\x6c\x61\164\x65\144\115\x6f\x64\165\154\145\x3d\115\x6f\144\x43\x6f\155\x6d\145\x6e\164\163\x26\x76\x69\x65\x77\75\x44\145\x74\141\x69\154\x26\x72\x65\143\x6f\162\x64\75" . $recordId . "\46\x6d\157\x64\145\x3d\163\150\157\x77\122\x65\154\141\x74\145\x64\114\x69\163\x74\47\40\164\141\162\x67\145\164\75\47\137\x62\x6c\141\143\153\47\76" . vtranslate("\x4c\x42\x4c\137\x53\x48\117\127\137\115\x4f\122\105", "\x56\x74\151\x67\x65\x72") . "\74\57\141\76\74\x73\160\141\156\x3e";
}
}
}
$messageData = array(
"\167\x68\141\x74\163\141\160\x70\x4d\x65\x73\163\x61\147\x65\110\x54\x4d\114" => $whatsappMessageHTML,
"\x74\157\x74\141\x6c\123\145\x6e\x74" => $totalSent,
"\164\x6f\164\141\x6c\x52\x65\143\145\151\x76\145\144" => $totalReceived,
"\143\x6f\155\155\x65\156\164\110\124\x4d\114" => $commentHTML . $moreCommentLink,
"\x6d\145\x73\163\x61\147\x65\111\x6d\x70\x6f\162\164\141\156\164" => $messageImportant,
"\x6d\157\144\165\x6c\145\x49\163\x45\x6e\x61\x62\x6c\x65" => $moduleIsEnable
);
return $messageData;
}
function getRelatedModules($moduleName)
{
global $adb;
$tabid = getTabid($moduleName);
$getRelatedModuleQuery = $adb->pquery("\x53\105\x4c\105\103\124\x20\52\x20\106\x52\117\x4d\40\x76\x74\x69\147\x65\x72\137\162\x65\154\141\164\145\x64\154\x69\163\x74\163\x20\127\110\x45\122\105\40\x74\x61\142\x69\144\x20\x3d\x20\x3f\40\x41\116\x44\x20\x70\162\x65\x73\x65\x6e\143\x65\40\75\x20\60\x20\x41\x4e\104\40\x72\x65\154\x61\x74\x65\x64\x5f\164\x61\142\x69\x64\40\116\117\124\40\111\x4e\50\x38\x2c\71\54\61\60\54\x32\60\54\x32\x31\x2c\62\62\54\62\x33\x2c\63\x35\x2c\64\x33\51\x20\x41\116\x44\x20\x61\x63\164\x69\x6f\156\163\40\114\111\x4b\105\x20\47\45\x41\x44\x44\x25\47", array(
$tabid
));
$relatedModulesRows = $adb->num_rows($getRelatedModuleQuery);
$relatedModuleArray = array();
for ($j = 0; $j < $relatedModulesRows; $j ++) {
$relatedModuleTabid = $adb->query_result($getRelatedModuleQuery, $j, "\162\145\154\141\x74\145\x64\x5f\164\x61\x62\151\144");
$getModuleNameQuery = $adb->pquery("\123\x45\x4c\x45\x43\x54\x20\52\x20\106\122\117\115\x20\x76\164\x69\x67\145\162\x5f\x74\x61\142\40\x57\x48\105\x52\x45\40\x74\141\x62\x69\x64\x20\x3d\40\77\x20\x41\x4e\104\x20\x70\162\145\163\145\156\143\x65\x20\x3d\x20\60", array(
$relatedModuleTabid
));
$relatedModule = $adb->query_result($getModuleNameQuery, 0, "\156\x61\155\145");
if ($relatedModule != '') {
$data = CTWhatsApp_Record_Model::checkPermissionModule($relatedModule);
if ($data == 1) {
$getRelatedFieldNameQuery = $adb->pquery("\x53\x45\114\x45\x43\124\40\x76\x74\x69\x67\x65\x72\137\x66\x69\x65\x6c\144\56\x66\x69\x65\154\x64\x6e\141\x6d\x65\40\106\122\117\115\40\166\164\x69\147\x65\x72\137\x72\145\154\x61\x74\x65\144\154\151\x73\x74\163\x20\111\116\116\105\122\40\x4a\x4f\111\116\40\x76\x74\x69\x67\145\162\x5f\x66\x69\x65\154\x64\40\x4f\x4e\x20\166\164\x69\x67\145\162\137\146\x69\x65\x6c\x64\x2e\146\151\x65\154\144\151\x64\x20\75\40\166\x74\x69\x67\145\162\x5f\x72\145\154\x61\x74\145\x64\x6c\x69\163\164\x73\56\162\145\154\141\164\x69\x6f\156\x66\x69\145\154\x64\x69\144\40\127\110\x45\x52\105\40\x76\x74\151\147\x65\x72\x5f\162\145\x6c\x61\164\145\144\x6c\x69\x73\x74\163\56\162\145\x6c\x61\164\145\144\x5f\164\x61\x62\151\x64\x20\x3d\x20\77\x20\101\x4e\x44\x20\x76\164\x69\147\145\162\x5f\x72\x65\154\x61\164\x65\x64\154\151\163\164\163\56\x74\141\142\x69\144\40\75\x20\77", array(
$relatedModuleTabid,
$tabid
));
$relatedFieldName = $adb->query_result($getRelatedFieldNameQuery, 0, "\146\x69\x65\x6c\x64\x6e\x61\x6d\x65");
$relatedModuleArray[$relatedModule] = array(
"\162\x65\154\141\164\x65\144\x4d\x6f\144\x75\x6c\x65" => $relatedModule,
"\162\x65\154\x61\x74\x65\144\x46\151\x65\154\x64\116\141\x6d\x65" => $relatedFieldName
);
}
}
}
return $relatedModuleArray;
}
public function checkPermissionModule($moduleName)
{
$moduleName = $moduleName;
$record = '';
$actionName = "\103\x72\x65\x61\x74\145\x56\x69\x65\167";
if (! Users_Privileges_Model::isPermitted($moduleName, $actionName, $record)) {
return 0;
} else {
return 1;
}
}
public function setMessagesImportant($recordId, $messagesImportant)
{
global $adb;
$setype = VtigerCRMObject::getSEType($recordId);
if ($messagesImportant == 0) {
$query = "\125\120\x44\x41\124\x45\40\166\164\x69\x67\x65\x72\137\x63\x74\167\150\141\x74\163\x61\x70\160\40\123\105\124\x20\x77\150\141\164\x73\x61\x70\x70\137\x69\x6d\x70\157\162\x74\141\x6e\164\40\x3d\40\61";
} else {
$query = "\x55\120\x44\x41\x54\x45\x20\166\x74\151\x67\x65\162\x5f\143\x74\167\x68\141\x74\163\x61\160\x70\40\x53\105\124\40\167\150\141\x74\163\141\160\x70\x5f\x69\155\160\157\x72\164\x61\x6e\164\40\75\x20\x30";
}
if ($setype) {
$customQuery = "\40\x57\110\105\x52\x45\x20\x77\150\141\164\163\x61\x70\160\137\x63\157\156\164\141\x63\164\151\144\x20\x3d\40\77";
} else {
$customQuery = "\40\x57\x48\x45\x52\105\x20\x77\150\141\x74\x73\x61\160\160\137\x77\151\x74\x68\143\143\x6f\x64\x65\40\x3d\40\x3f";
}
$updateQuery = $adb->pquery($query . $customQuery, array(
$recordId
));
return 1;
}
public function getAllNewUnreadMessages($recordId, $moduleName, $individulMessage)
{
global $adb;
$setype = VtigerCRMObject::getSEType($recordId);
if ($setype) {
$customQuery = "\x20\x41\x4e\104\x20\x77\150\x61\164\163\141\160\160\x5f\143\157\x6e\x74\x61\143\164\x69\x64\40\75\40\77";
} else {
if (strpos($recordId, "\x40\x67\x2e\165\x73") !== false) {
$customQuery = "\40\101\116\x44\x20\x6d\163\x67\151\x64\x20\x3d\40\x3f";
} else {
$customQuery = "\40\x41\116\x44\x20\167\x68\x61\x74\x73\141\x70\x70\x5f\x77\151\164\150\x63\x63\157\144\145\x20\x3d\x20\77";
}
}
$unreadQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $unreadQuery . $customQuery . "\x20\x41\116\x44\x20\x76\x74\x69\x67\x65\x72\137\x63\164\167\x68\141\164\x73\x61\x70\x70\x2e\x77\x68\x61\164\x73\141\160\x70\x5f\165\156\162\145\141\x64\162\145\141\144\40\75\x20\x27\125\156\162\x65\141\x64\47\x20\x41\x4e\104\x20\166\164\151\147\x65\x72\137\x63\164\167\150\141\164\x73\141\x70\160\56\x6d\x65\163\163\141\x67\x65\137\164\x79\160\145\x20\75\40\47\x52\x65\x63\151\x65\166\145\144\47";
$queryResult = $adb->pquery($query, array(
$recordId
));
$rows = $adb->num_rows($queryResult);
$whatsappMessageHTML = '';
$imgExts = array(
"\147\x69\146",
"\152\x70\147",
"\152\160\x65\x67",
"\x70\x6e\x67",
"\164\x69\146\146",
"\x74\151\x66"
);
$fileExts = array(
"\x70\144\146",
"\x74\x78\x74",
"\160\x68\160",
"\172\x69\160",
"\x63\163\166"
);
for ($i = 0; $i < $rows; $i ++) {
$ctwhatsappId = $adb->query_result($queryResult, $i, "\x63\x74\x77\x68\141\x74\x73\x61\x70\160\151\x64");
$senderName = $adb->query_result($queryResult, $i, "\167\150\x61\x74\x73\141\160\160\137\x73\x65\156\x64\x65\x72\156\x61\x6d\145");
$messageType = $adb->query_result($queryResult, $i, "\x6d\145\163\x73\x61\147\145\137\x74\171\160\145");
$messageReadUnRead = $adb->query_result($queryResult, $i, "\167\x68\x61\x74\x73\141\x70\x70\137\165\x6e\x72\x65\141\144\162\145\141\144");
$messageBody = nl2br(preg_replace("\x23\x5c\52\x28\133\136\x2a\x5d\x2b\x29\x5c\52\43", "\74\142\76\44\61\x3c\x2f\142\x3e", $adb->query_result($queryResult, $i, "\x6d\x65\163\x73\x61\x67\145\137\x62\157\x64\171")));
if ($ctwhatsappId) {
if ($messageReadUnRead == "\125\156\x72\x65\141\x64" && $messageType == "\x52\x65\x63\151\145\166\x65\144") {
$recordModel = Vtiger_Record_Model::getInstanceById($ctwhatsappId, "\103\x54\x57\150\x61\x74\163\x41\x70\160");
$recordModel->set("\155\x6f\x64\x65", "\x65\x64\x69\164");
$recordModel->set("\x69\x64", $ctwhatsappId);
$recordModel->set("\167\x68\141\x74\x73\141\160\x70\x5f\x75\x6e\x72\145\x61\x64\x72\x65\141\x64", "\122\145\x61\x64");
$recordModel->save();
}
}
$urlExt = pathinfo($messageBody, PATHINFO_EXTENSION);
if ($urlExt) {
if (in_array($urlExt, $imgExts)) {
$messageBody = "\x3c\151\155\x61\x67\x65\40\x73\x72\x63\75\42" . $messageBody . "\x22\x20\163\164\171\154\145\x3d\x22\150\145\x69\147\x68\x74\72\40\x36\x30\160\x78\73\42\x3e";
} else {
if (in_array($urlExt, $fileExts)) {
$messageBody = "\74\x61\x20\150\x72\x65\x66\75\x22" . $messageBody . "\42\x20\x74\x61\x72\x67\145\x74\75\x22\137\x62\x6c\141\x63\x6b\42\76" . $messageBody . "\74\57\141\76";
}
}
} else {
$messageBody = $messageBody;
if ($individulMessage == 1) {
$style = "\x20";
} else {
$style = "\163\x74\x79\154\145\75\x27\x66\x6c\x6f\141\164\72\40\x6c\145\x66\164\x3b\x6d\141\162\147\151\156\x2d\154\x65\x66\164\x3a\x20\55\x32\x70\x78\73\167\151\x64\164\150\x3a\40\61\65\x70\x78\x3b\47";
}
if ($setype) {
$editFieldHTML = "\46\x6e\x62\x73\160\x3b\x26\156\x62\x73\160\x3b\12\x20\40\x20\40\40\x20\40\40\40\x20\x20\x20\x20\x20\40\x20\x20\40\40\40\x20\x20\x20\x20\x20\40\x20\40\x20\x20\40\40\74\x73\x70\141\156\x20\143\x6c\x61\x73\x73\75\x27\145\144\151\164\x46\151\145\154\144\47\x3e\74\151\155\147\x20\x73\x72\x63\x3d\x27\x6c\141\x79\157\x75\x74\163\x2f\x76\x37\x2f\x6d\157\x64\165\x6c\145\163\57\103\124\127\x68\x61\164\163\101\160\160\57\151\155\141\x67\x65\57\145\x64\x69\x74\143\157\x6e\x74\145\x6e\x74\56\x70\x6e\x67\x27\40\164\x69\x74\x6c\x65\x3d\47\x7b\x76\164\x72\x61\156\163\154\x61\x74\145\x28\x27\x4c\x42\114\x5f\105\x44\111\x54\x46\x49\x45\x4c\104\x27\x2c\x27\103\124\127\150\141\164\x73\141\x41\x70\x70\x27\51\175\40\173\166\x74\162\x61\x6e\163\154\141\x74\x65\x28" . $moduleName . "\x2c" . $moduleName . "\51\175\47\40" . $style . "\76\x3c\x2f\163\x70\141\156\x3e";
}
}
$createdTime = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($adb->query_result($queryResult, $i, "\167\x68\x61\164\x73\141\160\160\137\x64\141\x74\145\164\x69\155\145"));
if ($individulMessage == 1) {
$whatsappMessageHTML .= "\74\144\151\166\40\x63\x6c\141\163\x73\75\42\x6d\x65\163\163\141\x67\x65\40\x72\x65\x63\145\x69\x76\145\x64\42\76\xa\x9\x9\11\11\11\x9\11\x9\11\x9\11" . $messageBody . "\12\x20\x20\40\x20\40\40\x20\40\40\x20\x20\x20\x20\x20\x20\40\x20\40\40\40\x20\40\x20\x20\x20\x20\40\40\40\x20\40\40\x20\40\40\40\x20\40\40\40\x20\x20\40\40\74\163\160\141\x6e\x20\143\x6c\x61\x73\163\75\x22\x6d\x65\164\x61\x64\141\x74\x61\42\76\12\x9\11\11\x9\11\x9\x9\x9\11\11\11\x9\x3c\x73\x70\141\156\x20\143\x6c\x61\163\163\75\x22\x74\151\x6d\x65\42\76\x3c\142\76" . $senderName . "\x3c\x2f\142\76\x26\x6e\x62\x73\x70\x3b\x26\x6e\142\x73\x70\73\x20" . $createdTime . "\x3c\x2f\163\160\141\x6e\x3e\46\156\x62\x73\160";
if ($messageReadUnRead == "\125\156\162\145\x61\x64") {
$whatsappMessageHTML .= "\74\151\155\147\x20\x73\162\143\x3d\42\x6c\141\x79\x6f\x75\x74\x73\57\x76\x37\x2f\155\157\x64\x75\154\145\163\57\x43\x54\127\150\x61\x74\x73\x41\x70\x70\x2f\x69\155\141\x67\145\x2f\165\156\162\145\x61\x64\x2e\160\156\147\x22\x2f\x3e";
} else {
$whatsappMessageHTML .= "\74\x69\x6d\x67\40\163\162\143\x3d\x22\x6c\141\x79\157\165\x74\x73\57\x76\x37\57\x6d\x6f\x64\165\154\145\x73\57\103\124\x57\x68\x61\164\x73\x41\160\160\x2f\151\x6d\x61\x67\145\x2f\x72\145\x61\144\x2e\160\156\147\x22\57\x3e";
}
$whatsappMessageHTML .= "\74\57\163\160\x61\x6e\76\x26\x6e\x62\x73\160\x3b\xa\40\x20\40\x20\x20\x20\40\40\x20\x20\x20\x20\x20\x20\40\40\x20\x20\40\x20\x20\x20\x20\40\40\x20\40\x20\x20\40\40\x20\40\x20\40\x20\x20\x20\40\40\74\x2f\x64\x69\x76\76";
$whatsappMessageHTML .= $editFieldHTML;
} else {
$whatsappMessageHTML .= "\74\x64\x69\166\40\143\154\141\163\163\75\42\x72\x65\160\154\x79\x43\150\x61\x74\42\76\12\x9\x9\x9\x9\x9\11\11\x9\x9\11\11\74\144\151\x76\40\143\154\141\163\x73\75\x22\x63\x6f\154\x2d\x78\x73\55\61\60\40\x63\x6f\154\55\x73\155\x2d\x38\x20\143\157\154\55\x6d\x64\x2d\70\40\143\x6f\154\55\x6c\147\x2d\70\x22\76\xa\x9\x9\x9\11\11\11\x9\x9\11\11\11\x9\74\144\x69\166\x20\143\x6c\141\x73\x73\x3d\x22\x62\x75\x62\x62\x6c\x65\40\162\145\x70\x6c\171\42\76\12\11\x9\x9\11\11\x9\x9\11\11\11\x9\11\11\x3c\163\160\141\x6e\76\x3c\142\x3e" . $senderName . "\74\x2f\142\76\74\57\x73\160\141\x6e\76\12\x9\11\11\11\x9\11\11\11\11\11\11\x9\11\74\160\x3e" . $messageBody . "\74\x2f\x70\76\12\11\11\11\x9\11\x9\11\11\11\x9\x9\11\x3c\x2f\144\151\x76\76\xa\11\x9\11\x9\x9\11\x9\11\11\11\11\x9\74\x73\x70\141\x6e\40\143\x6c\x61\x73\x73\x3d\42\143\150\141\164\124\x69\155\145\x22\40\163\x74\x79\154\x65\x3d\42\167\x69\144\164\x68\72\x20\63\65\x25\x3b\40\41\x69\x6d\160\157\162\164\141\156\164\x22\x3e" . $createdTime . '';
if ($messageReadUnRead == "\125\156\162\145\141\x64") {
$whatsappMessageHTML .= "\x3c\x69\x6d\147\x20\163\x72\143\75\42\154\x61\171\157\165\x74\163\x2f\x76\67\x2f\155\x6f\x64\x75\x6c\x65\x73\x2f\x43\x54\127\x68\141\164\163\x41\160\x70\x2f\x69\155\141\147\145\57\x75\x6e\162\x65\141\x64\x2e\160\x6e\147\x22\x2f\76";
} else {
$whatsappMessageHTML .= "\x3c\x69\x6d\147\40\163\162\x63\x3d\x22\x6c\x61\x79\157\165\x74\x73\x2f\166\67\x2f\x6d\x6f\144\165\154\145\x73\x2f\x43\124\x57\x68\141\164\163\x41\x70\160\57\x69\x6d\141\147\145\x2f\162\145\x61\x64\56\x70\156\x67\x22\57\x3e";
}
$whatsappMessageHTML .= "\74\x2f\163\160\141\x6e\x3e\46\156\x62\x73\x70\x3b\x3c\x2f\144\151\x76\x3e";
$whatsappMessageHTML .= $editFieldHTML;
$whatsappMessageHTML .= "\74\144\x69\x76\40\143\x6c\141\163\163\x3d\x22\x63\157\154\55\170\x73\x2d\x31\62\x20\x63\157\154\x2d\x73\155\x2d\x32\40\143\x6f\154\x2d\x6d\x64\55\62\x20\143\157\154\55\154\147\55\x32\42\x3e\12\x9\11\11\x9\x9\11\11\11\11\x9\x9\x3c\57\x64\x69\166\76\xa\x9\x9\11\11\11\x9\x9\11\x9\x9\74\x2f\x64\x69\x76\76";
}
}
$unreadArray = array(
"\x72\157\x77\163" => $rows,
"\167\150\141\164\163\141\x70\x70\x4d\x65\163\163\x61\147\x65\110\124\x4d\114" => $whatsappMessageHTML
);
return $unreadArray;
}
public function getIndividualMessages($recordId)
{
global $adb;
$whatsappQuery = CTWhatsApp_Record_Model::unreadQuery();
$setype = VtigerCRMObject::getSEType($recordId);
if ($setype) {
$query = $whatsappQuery . "\x20\101\116\x44\x20\x76\164\151\147\145\162\137\x63\x74\167\150\x61\164\163\x61\x70\160\56\167\150\141\x74\x73\x61\160\160\137\143\157\x6e\164\x61\143\164\x69\x64\40\x3d\x20\77";
$queryResult = $adb->pquery($query, array(
$recordId
));
} else {
$recordId = preg_replace("\x2f\133\136\x41\55\132\x61\55\172\x30\55\71\135\57", '', $recordId);
$query = $whatsappQuery . "\40\x41\116\104\40\166\x74\x69\x67\x65\162\x5f\x63\164\167\x68\141\x74\x73\141\x70\160\x2e\x77\150\141\164\x73\141\x70\160\x5f\167\151\x74\150\143\x63\157\x64\145\40\114\x49\113\105\40\x22\45" . $recordId . "\x25\x22";
$queryResult = $adb->pquery($query, array());
}
$rows = $adb->num_rows($queryResult);
$imgExts = array(
"\x67\x69\146",
"\152\x70\x67",
"\152\x70\x65\147",
"\x70\x6e\x67",
"\x74\x69\x66\146",
"\164\151\x66"
);
$fileExts = array(
"\x70\144\x66",
"\164\170\164",
"\x70\150\160",
"\x7a\x69\x70",
"\143\x73\166"
);
$whatsappMessages = array();
for ($i = 0; $i < $rows; $i ++) {
$ctwhatsappId = $adb->query_result($queryResult, $i, "\143\164\167\150\141\x74\163\141\x70\x70\x69\x64");
$messageType = $adb->query_result($queryResult, $i, "\x6d\x65\163\x73\x61\x67\145\137\164\x79\x70\x65");
$senderName = $adb->query_result($queryResult, $i, "\167\150\141\164\x73\141\x70\160\x5f\x73\x65\x6e\144\145\x72\x6e\x61\x6d\x65");
$messageReadUnRead = $adb->query_result($queryResult, $i, "\167\x68\x61\164\x73\141\160\160\x5f\x75\156\x72\145\x61\x64\x72\145\141\144");
if ($ctwhatsappId) {
if ($messageReadUnRead == "\125\156\162\x65\x61\144" && $messageType == "\x52\x65\143\x69\145\x76\x65\x64") {
$recordModel = Vtiger_Record_Model::getInstanceById($ctwhatsappId, "\x43\x54\x57\150\141\x74\x73\x41\160\x70");
$recordModel->set("\155\157\144\x65", "\x65\144\x69\164");
$recordModel->set("\151\x64", $ctwhatsappId);
$recordModel->set("\x77\150\141\x74\x73\x61\160\160\137\165\156\162\x65\x61\x64\162\x65\x61\144", "\122\x65\141\x64");
$recordModel->save();
}
}
$messageBody = nl2br(preg_replace("\43\134\x2a\x28\x5b\x5e\52\135\x2b\51\134\52\43", "\74\x62\x3e\44\x31\x3c\57\x62\x3e", $adb->query_result($queryResult, $i, "\155\x65\x73\x73\x61\147\145\137\142\157\x64\x79")));
$urlExt = pathinfo($messageBody, PATHINFO_EXTENSION);
if (in_array($urlExt, $imgExts)) {
$messageBody = "\74\x69\x6d\x61\147\x65\x20\x73\x72\x63\75\x22" . $messageBody . "\x22\x20\x73\x74\x79\154\x65\75\x22\x68\145\151\x67\x68\164\72\40\66\x30\160\x78\73\42\76";
} else {
if (in_array($urlExt, $fileExts)) {
$messageBody = "\x3c\x61\x20\150\162\145\146\x3d\42" . $messageBody . "\x22\40\164\x61\x72\147\145\164\x3d\42\x5f\142\x6c\141\143\153\x22\x3e" . $messageBody . "\x3c\57\141\x3e";
}
}
$createdTime = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($adb->query_result($queryResult, $i, "\167\x68\141\x74\x73\141\x70\160\x5f\144\141\x74\x65\x74\151\x6d\x65"));
$whatsappMessages[] = array(
"\x6d\145\x73\x73\141\x67\x65\124\171\x70\x65" => $messageType,
"\x6d\145\x73\x73\x61\x67\x65\102\x6f\x64\171" => $messageBody,
"\143\x72\145\141\x74\x65\x64\124\151\x6d\x65" => $createdTime,
"\x73\145\x6e\x64\145\162\x4e\x61\155\x65" => $senderName,
"\155\x65\x73\163\141\x67\x65\122\x65\x61\144\x55\156\x52\145\x61\144" => $messageReadUnRead
);
}
return $whatsappMessages;
}
public function checkCommentModuleEnable($sourceModuleName)
{
global $adb;
$modCommentQuery = $adb->pquery("\123\105\114\105\103\x54\x20\x2a\x20\x46\x52\x4f\115\x20\166\164\151\147\145\162\x5f\164\141\x62\40\127\110\x45\122\105\x20\156\x61\155\x65\40\x3d\x20\x27\x4d\157\x64\103\157\x6d\155\x65\156\164\163\47\x20\x41\x4e\104\40\160\162\x65\x73\145\x6e\x63\145\40\x3d\40\x30", array());
$commentRows = $adb->num_rows($modCommentQuery);
if ($commentRows) {
$commentTabid = $adb->query_result($modCommentQuery, 0, "\x74\x61\x62\151\x64");
$sourceModuleTabid = getTabid($sourceModuleName);
$enableCommentQuery = $adb->pquery("\x53\x45\x4c\105\103\x54\40\52\x20\x46\x52\x4f\x4d\x20\x76\164\x69\x67\145\162\x5f\x72\x65\x6c\x61\x74\145\144\x6c\151\163\x74\163\40\127\110\105\x52\105\x20\162\145\x6c\141\164\x65\x64\137\x74\141\x62\x69\144\x20\x3d\x20\x3f\x20\101\x4e\104\40\164\141\x62\x69\x64\x20\x3d\x20\77", array(
$commentTabid,
$sourceModuleTabid
));
$commentModuleEnable = $adb->num_rows($enableCommentQuery);
}
return $commentModuleEnable;
}
public function sendIndividulMessage($request)
{
global $adb, $site_URL, $current_user, $root_directory;
$moduleName = $request->getModule();
$whatsappModule = $request->get("\x77\150\x61\x74\x73\141\160\x70\x4d\x6f\x64\x75\x6c\145");
$wptemplateid = $request->get("\x77\160\x74\145\155\160\x6c\141\x74\x65\x69\x64");
if ($whatsappModule == "\x47\162\x6f\165\x70\163") {
$mobileno = $request->get("\x6d\x6f\142\x69\154\x65\x6e\157");
} else {
$mobileno = preg_replace("\x2f\x5b\136\101\x2d\132\x61\55\172\x30\x2d\x39\x5d\x2f", '', $request->get("\x6d\x6f\142\x69\x6c\x65\x6e\x6f"));
}
$msgbody = html_entity_decode($request->get("\x6d\163\147\x62\x6f\144\x79"));
$moduleRecordid = $request->get("\155\x6f\x64\165\x6c\x65\122\145\x63\x6f\162\144\x69\x64");
if ($moduleRecordid == '') {
$moduleRecordid = $request->get("\155\x6f\x64\x75\x6c\145\x5f\162\145\x63\157\x72\x64\151\144");
}
$base64imagedata = $request->get("\x62\141\x73\145\66\64\x69\155\x61\x67\145\144\141\164\141");
$filename = $request->get("\146\x69\x6c\145\156\x61\x6d\x65");
$filetype = $request->get("\146\151\154\145\164\171\160\145");
$fileURL = '';
$date_var = date("\131\x2d\x6d\x2d\x64\40\x48\72\151\x3a\163");
$currenUserID = $current_user->id;
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$api_url = $configurationData["\141\x70\x69\x5f\165\x72\154"];
$auth_token = $configurationData["\x61\165\164\x68\164\157\x6b\145\156"];
$customfield1 = $configurationData["\x63\x75\x73\164\x6f\x6d\x66\151\x65\154\x64\61"];
$whatsappScanNo = $configurationData["\x77\x68\141\164\163\x61\160\160\x6e\x6f"];
$whatsappStatus = $configurationData["\167\150\141\x74\x73\x61\x70\160\163\164\141\164\165\163"];
$mobilenoLen = strlen($mobileno);
if ($mobilenoLen > 10 && $customfield1 != '') {
$withoutcode = substr($mobileno, - 10);
$mobileno = $customfield1 . $withoutcode;
} else {
$mobileno = $customfield1 . $mobileno;
}
if ($base64imagedata != '' || $wptemplateid != '') {
$whatsappFolderPath = "\x2f\x6d\157\144\165\x6c\x65\x73\x2f\x43\x54\x57\150\141\164\163\x41\160\160\x2f\103\124\127\150\141\x74\x73\x41\160\160\x53\164\157\162\x61\147\x65\57";
$year = date("\x59");
$month = date("\x46");
$day = date("\152");
$week = '';
if (! is_dir($root_directory . $whatsappFolderPath)) {
mkdir($root_directory . $whatsappFolderPath);
chmod($root_directory . $whatsappFolderPath, 511);
}
if (! is_dir($root_directory . $whatsappFolderPath . $year)) {
mkdir($root_directory . $whatsappFolderPath . $year);
chmod($root_directory . $whatsappFolderPath . $year, 511);
}
if (! is_dir($root_directory . $whatsappFolderPath . $year . "\57" . $month)) {
mkdir($root_directory . $whatsappFolderPath . "{$year}\x2f{$month}\57");
chmod($root_directory . $whatsappFolderPath . "{$year}\57{$month}\x2f", 511);
}
if ($day > 0 && $day <= 7) {
$week = "\x77\x65\145\x6b\61";
} elseif ($day > 7 && $day <= 14) {
$week = "\167\145\145\x6b\62";
} elseif ($day > 14 && $day <= 21) {
$week = "\x77\x65\145\x6b\63";
} elseif ($day > 21 && $day <= 28) {
$week = "\x77\x65\145\153\64";
} else {
$week = "\x77\145\x65\x6b\65";
}
if (! is_dir($root_directory . $whatsappFolderPath . $year . "\57" . $month . "\x2f" . $week)) {
mkdir($root_directory . $whatsappFolderPath . "{$year}\57{$month}\x2f{$week}\x2f");
chmod($root_directory . $whatsappFolderPath . "{$year}\57{$month}\57{$week}\x2f", 511);
}
}
if ($wptemplateid) {
$getWhatsappTemplateQuery = $adb->pquery("\x53\105\x4c\x45\103\124\40\x2a\40\x46\122\x4f\x4d\40\166\x74\151\147\x65\162\x5f\x63\x74\x77\150\141\x74\163\x61\160\x70\164\x65\x6d\x70\154\141\x74\145\x73\40\xa\x9\x9\11\x9\111\116\x4e\x45\x52\x20\x4a\x4f\x49\x4e\40\x76\164\151\147\145\x72\x5f\143\162\155\145\x6e\164\151\x74\171\40\x4f\x4e\40\x76\164\x69\147\145\162\x5f\143\162\x6d\x65\x6e\164\151\x74\x79\x2e\143\x72\x6d\x69\144\40\75\40\x76\164\151\x67\x65\162\x5f\x63\x74\x77\x68\141\164\x73\x61\160\x70\x74\145\155\160\x6c\x61\x74\145\x73\56\143\164\167\x68\141\164\x73\141\x70\x70\164\145\155\x70\154\141\164\x65\163\x69\144\x20\12\11\11\11\11\x49\116\x4e\x45\122\x20\x4a\117\x49\116\x20\x76\x74\x69\147\145\x72\x5f\163\x65\141\164\x74\x61\143\x68\155\145\x6e\164\163\162\145\x6c\x20\117\x4e\40\166\x74\151\x67\145\x72\137\x73\x65\x61\164\x74\x61\143\150\x6d\145\x6e\x74\163\x72\145\154\x2e\x63\x72\x6d\x69\144\40\x3d\x20\x76\164\x69\147\x65\162\137\x63\x74\x77\150\141\164\163\141\x70\x70\x74\145\x6d\x70\x6c\141\x74\145\x73\x2e\143\164\167\150\x61\x74\163\x61\x70\160\x74\x65\155\160\154\x61\x74\145\x73\x69\x64\40\xa\11\x9\x9\11\111\116\x4e\105\x52\x20\x4a\117\111\116\x20\166\x74\x69\147\145\x72\x5f\x61\x74\x74\x61\143\x68\x6d\x65\x6e\164\163\x20\x4f\x4e\x20\x76\x74\x69\147\x65\x72\137\141\164\x74\141\143\150\155\145\x6e\164\x73\x2e\141\x74\164\x61\143\x68\155\145\156\164\x73\151\x64\x20\x3d\40\166\164\151\x67\145\162\137\x73\145\141\164\x74\141\x63\x68\155\x65\156\x74\163\x72\145\x6c\x2e\x61\164\x74\141\143\x68\155\145\x6e\164\163\151\x64\xa\x9\11\x9\x9\127\110\x45\x52\105\x20\166\164\151\147\145\162\137\143\x72\155\145\156\164\151\164\x79\x2e\144\145\x6c\145\164\x65\x64\40\75\x20\x30\x20\x41\x4e\x44\40\166\164\151\147\145\162\137\143\x74\167\150\141\x74\163\x61\160\x70\164\145\x6d\160\x6c\141\x74\x65\163\x2e\x63\164\167\150\141\164\x73\141\160\160\x74\145\x6d\160\154\141\164\145\163\151\x64\40\x3d\x20\x3f", array(
$wptemplateid
));
$isTemplates = $adb->num_rows($getWhatsappTemplateQuery);
if ($isTemplates) {
$templatesID = $adb->query_result($getWhatsappTemplateQuery, 0, "\x63\x74\167\150\x61\x74\x73\x61\160\160\x74\145\155\160\x6c\x61\x74\145\x73\151\x64");
$templateMsg = $adb->query_result($getWhatsappTemplateQuery, 0, "\167\x70\x74\x65\155\x70\x6c\141\164\145\137\164\145\170\164");
$wptemplateImage = $adb->query_result($getWhatsappTemplateQuery, 0, "\156\x61\x6d\145");
if ($moduleRecordid) {
$bodydata = str_replace("\134\x72\134\x6e", "\x20", html_entity_decode($templateMsg));
$setype = VtigerCRMObject::getSEType($moduleRecordid);
$msgbody = getMergedDescription($bodydata, $moduleRecordid, $setype);
} else {
$msgbody = str_replace("\134\162\134\x6e", "\x20", html_entity_decode($templateMsg));
}
$getAttachmentQuery = $adb->pquery("\x53\105\x4c\x45\x43\124\x20\x76\x74\x69\147\145\162\137\x61\164\164\x61\143\x68\155\145\156\164\163\x2e\x2a\x2c\x20\x76\x74\x69\x67\x65\x72\x5f\143\x72\155\x65\156\x74\151\x74\x79\56\163\145\164\171\x70\145\x20\x46\122\117\115\40\x76\x74\151\147\x65\162\x5f\141\164\x74\x61\143\150\x6d\x65\156\164\163\xa\x9\x9\x9\x9\11\x49\116\x4e\x45\122\40\112\117\111\x4e\x20\x76\x74\x69\147\145\162\137\163\145\141\164\164\x61\143\x68\x6d\x65\156\x74\x73\x72\145\x6c\x20\117\x4e\40\166\164\x69\x67\x65\162\x5f\163\x65\x61\x74\164\x61\x63\150\155\145\x6e\164\163\162\x65\x6c\56\x61\164\164\141\x63\x68\155\x65\x6e\164\x73\151\x64\x20\x3d\40\x76\x74\151\147\x65\x72\x5f\x61\164\164\x61\x63\x68\x6d\145\x6e\x74\163\56\141\164\x74\x61\143\x68\x6d\145\156\x74\163\151\x64\xa\x9\x9\11\11\11\111\116\116\x45\122\40\x4a\117\111\x4e\x20\166\164\151\x67\x65\162\x5f\143\x72\155\145\x6e\x74\151\x74\x79\40\x4f\116\x20\166\x74\x69\x67\x65\162\137\143\162\155\145\156\x74\x69\164\171\56\x63\x72\155\x69\x64\x20\x3d\40\x76\x74\x69\147\145\162\137\141\164\x74\141\x63\x68\x6d\x65\x6e\164\x73\x2e\141\164\x74\141\x63\150\155\145\x6e\x74\163\x69\144\xa\11\11\x9\11\x9\127\x48\105\122\105\40\166\164\x69\x67\145\162\x5f\163\x65\141\x74\164\141\x63\150\155\x65\156\x74\x73\162\145\154\x2e\x63\162\155\x69\144\40\x3d\x20\x3f\x20\x41\116\104\x20\x76\164\151\147\x65\x72\x5f\x63\x72\155\x65\156\x74\151\x74\171\x2e\144\x65\154\x65\164\x65\x64\x20\75\x20\60", array(
$templatesID
));
$imageId = $adb->query_result($getAttachmentQuery, 0, "\x61\x74\164\x61\x63\150\x6d\145\x6e\164\x73\151\x64");
$imagePath = $adb->query_result($getAttachmentQuery, 0, "\160\x61\x74\150");
$imageName = $adb->query_result($getAttachmentQuery, 0, "\x6e\141\155\x65");
$attachmentPath = $root_directory . $imagePath . $imageId . "\137" . $imageName;
$newfile = $root_directory . $whatsappFolderPath . "{$year}\x2f{$month}\x2f{$week}\x2f" . $imageName;
copy($attachmentPath, $newfile);
$newfileURL = $site_URL . $whatsappFolderPath . "{$year}\57{$month}\57{$week}\57" . $imageName;
$url = $api_url . "\x2f" . $auth_token . "\57\x73\x65\x6e\x64\167\151\164\150\143\x61\160\164\x69\157\156";
$postfields = array(
"\x6e\165\155\x62\145\x72" => $mobileno,
"\x6d\x73\147" => urlencode(htmlspecialchars_decode($msgbody, ENT_QUOTES)),
"\x75\162\x6c" => $newfileURL
);
}
} else {
if ($base64imagedata != '') {
$documentpath = "\163\x74\x6f\162\141\147\145";
$filepath = "\163\164\157\x72\x61\x67\145\57";
$year = date("\x59");
$month = date("\106");
$day = date("\152");
$week = '';
if (! is_dir($root_directory . $filepath . $year)) {
mkdir($root_directory . $filepath . $year);
chmod($root_directory . $filepath . $year, 511);
}
if (! is_dir($root_directory . $filepath . $year . "\57" . $month)) {
mkdir($root_directory . $filepath . "{$year}\x2f{$month}");
chmod($root_directory . $filepath . "{$year}\57{$month}", 511);
}
if ($day > 0 && $day <= 7) {
$week = "\167\145\x65\153\61";
} elseif ($day > 7 && $day <= 14) {
$week = "\167\145\145\153\62";
} elseif ($day > 14 && $day <= 21) {
$week = "\x77\145\x65\x6b\63";
} elseif ($day > 21 && $day <= 28) {
$week = "\167\145\x65\153\x34";
} else {
$week = "\x77\x65\x65\x6b\65";
}
if (! is_dir($root_directory . $filepath . $year . "\57" . $month . "\x2f" . $week)) {
mkdir($root_directory . $filepath . "{$year}\57{$month}\x2f{$week}");
chmod($root_directory . $filepath . "{$year}\x2f{$month}\57{$week}", 511);
}
$target_file = $root_directory . $filepath . $year . "\57" . $month . "\57" . $week . "\57";
list ($type, $base64imagedata) = explode("\x3b", $base64imagedata);
list (, $base64imagedata) = explode("\x2c", $base64imagedata);
$base64imagedata = base64_decode($base64imagedata);
$filemove = file_put_contents($target_file . $filename, $base64imagedata);
if ($filemove) {
$Document = Vtiger_Record_Model::getCleanInstance("\104\157\143\x75\155\x65\156\x74\x73");
$Document->set("\x6d\x6f\x64\145", '');
$Document->set("\141\163\x73\151\x67\x6e\x65\x64\x5f\165\x73\x65\x72\x5f\x69\144", $current_user->id);
$Document->set("\146\157\x6c\144\145\162\x69\144", 1);
$Document->set("\146\151\x6c\145\x6c\157\x63\x61\164\x69\x6f\156\x74\x79\160\145", "\111");
$Document->set("\146\x69\154\x65\163\x74\x61\x74\x75\x73", 1);
$Document->set("\146\151\x6c\145\x6e\x61\x6d\145", $filename);
$Document->save();
$documentid = $Document->getId();
$current_id = $adb->getUniqueID("\166\164\151\147\145\x72\137\143\162\155\145\x6e\x74\151\x74\x79");
$sql1 = "\x69\156\x73\x65\162\x74\x20\151\156\x74\x6f\x20\166\x74\x69\147\x65\162\x5f\143\162\155\x65\x6e\164\x69\164\171\x20\x28\143\x72\x6d\151\x64\54\163\155\143\x72\x65\x61\164\x6f\x72\151\x64\54\163\155\157\167\x6e\145\162\151\x64\x2c\x73\145\x74\x79\x70\145\x2c\x64\145\x73\x63\162\x69\x70\x74\x69\157\156\54\143\162\145\141\164\145\144\x74\x69\x6d\x65\x2c\x6d\x6f\144\151\x66\151\145\x64\x74\151\155\145\51\40\x76\x61\154\x75\x65\x73\50\x3f\x2c\x20\77\x2c\x20\77\54\40\x3f\x2c\40\x3f\54\x20\77\x2c\40\77\x29";
$params1 = array(
$current_id,
$current_user->id,
1,
"\x44\x6f\x63\x75\155\x65\x6e\x74\x73\40\101\164\164\x61\143\x68\155\145\156\164",
'',
$adb->formatDate($date_var, true),
$adb->formatDate($date_var, true)
);
$adb->pquery($sql1, $params1);
rename($target_file . $filename, $target_file . $current_id . "\137" . $filename);
chmod($target_file, 511);
$sql2 = "\x69\156\x73\145\x72\x74\40\x69\x6e\164\157\x20\166\164\x69\x67\145\162\137\x61\164\x74\141\x63\x68\x6d\x65\156\x74\163\50\x61\164\164\x61\143\150\155\145\x6e\x74\163\151\x64\x2c\x20\156\x61\155\145\x2c\x20\x64\x65\x73\143\x72\151\x70\x74\x69\157\156\x2c\40\x74\171\160\x65\x2c\x20\160\141\164\150\51\40\x76\141\x6c\165\x65\163\x28\77\54\40\x3f\x2c\x20\77\x2c\x20\x3f\54\x20\x3f\51";
$params2 = array(
$current_id,
$filename,
'',
'',
$filepath . $year . "\57" . $month . "\x2f" . $week . "\57"
);
$result = $adb->pquery($sql2, $params2);
$sql3 = "\151\156\x73\145\162\164\x20\151\156\164\157\40\166\x74\x69\147\x65\x72\137\x73\x65\x61\x74\x74\x61\143\150\x6d\x65\156\164\x73\x72\x65\154\x20\x76\x61\x6c\x75\145\163\x28\x3f\x2c\77\x29";
$adb->pquery($sql3, array(
$documentid,
$current_id
));
$sql4 = "\x69\x6e\x73\145\162\x74\40\151\156\x74\x6f\x20\x76\164\x69\147\x65\162\x5f\x73\x65\156\x6f\x74\145\x73\x72\145\x6c\x20\166\141\x6c\x75\x65\x73\x28\x3f\x2c\x3f\51";
$adb->pquery($sql4, array(
$moduleRecordid,
$documentid
));
}
$fileURL = $site_URL . $filepath . $year . "\x2f" . $month . "\x2f" . $week . "\57" . $current_id . "\137" . $filename;
$oldfile = $root_directory . $filepath . $year . "\57" . $month . "\57" . $week . "\x2f" . $current_id . "\x5f" . $filename;
$filename = str_replace("\x20", '', $filename);
$newfile = $root_directory . $whatsappFolderPath . "{$year}\57{$month}\57{$week}\x2f" . $filename;
copy($oldfile, $newfile);
$newfileURL = $site_URL . $whatsappFolderPath . "{$year}\57{$month}\x2f{$week}\57" . $filename;
}
if ($fileURL) {
if ($filetype == "\151\155\x61\x67\145\x2f\152\160\145\147" || $filetype == "\151\x6d\141\x67\x65\57\152\160\147" || $filetype == "\151\x6d\x61\147\145\x2f\160\156\x67") {
$url = $api_url . "\57" . $auth_token . "\x2f\163\145\x6e\x64\x66\151\x6c\145\x75\x72\x6c";
$postfields = array(
"\156\x75\x6d\142\145\162" => $mobileno,
"\x75\x72\x6c" => $newfileURL
);
} else {
$url = $api_url . "\x2f" . $auth_token . "\57\163\145\156\x64\146\x69\154\145\165\x72\154";
$postfields = array(
"\x6e\x75\155\x62\145\x72" => $mobileno,
"\x75\162\x6c" => urlencode($newfileURL)
);
}
} else {
$url = $api_url . "\57" . $auth_token . "\57\x73\x65\x6e\x64";
$postfields = array(
"\x6e\x75\x6d\142\x65\x72" => $mobileno,
"\155\163\147" => urlencode($msgbody)
);
}
}
if ($whatsappStatus == 1) {
$val = CTWhatsApp_WhatsappChat_View::callCURL($url, $postfields);
if ($val) {
$getLicenseDetail = CTWhatsApp_Record_Model::getWhatsAppLicenseDetail();
$licenseKey = $getLicenseDetail["\154\x69\x63\145\156\163\145\x4b\x65\x79"];
$getWhatsappAccount = CTWhatsApp_Record_Model::getWhatsappAccountDetail($licenseKey);
$oneDayMessages = CTWhatsApp_Record_Model::getOneDaysMessages();
$module_Name = "\x43\x54\x57\x68\141\x74\x73\101\x70\160";
$currentusername = $current_user->first_name . "\40" . $current_user->last_name;
$recordModel = Vtiger_Record_Model::getCleanInstance($module_Name);
$recordModel->set("\x77\150\x61\164\x73\141\x70\x70\137\x73\x65\156\x64\x65\162\156\x61\155\x65", $currentusername);
$recordModel->set("\167\x68\x61\164\163\141\160\160\x5f\x63\x68\x61\x74\x69\144", $val["\155\145\163\x73\141\x67\x65"]);
if ($whatsappModule == "\x47\162\x6f\165\x70\163") {
$recordModel->set("\155\163\x67\151\144", $mobileno);
$recordModel->set("\167\150\141\164\x73\141\160\160\137\167\151\x74\x68\143\143\x6f\144\145", "\107\x72\157\x75\160\163");
} else {
$recordModel->set("\155\163\147\x69\x64", $val["\x69\144"]["\151\144"]);
$recordModel->set("\167\150\x61\164\x73\x61\x70\160\x5f\x77\x69\164\150\143\x63\157\144\x65", $mobileno);
}
$recordModel->set("\x6d\x65\x73\163\x61\147\x65\137\164\x79\160\x65", "\x53\145\156\x64");
if ($fileURL) {
$recordModel->set("\155\145\x73\163\x61\147\145\x5f\142\157\x64\171", $newfileURL);
} else {
$recordModel->set("\x6d\145\163\x73\x61\147\x65\x5f\x62\157\x64\x79", $msgbody);
}
$recordModel->set("\167\x68\x61\x74\163\x61\160\x70\x5f\143\x6f\156\x74\x61\143\x74\151\144", $moduleRecordid);
$recordModel->set("\167\150\141\x74\x73\x61\160\160\x5f\x75\156\162\145\141\144\162\145\141\144", "\125\156\162\145\141\144");
$recordModel->set("\x77\150\x61\164\163\x61\x70\160\x5f\x66\162\x6f\x6d\156\x6f", $whatsappScanNo);
$recordModel->set("\167\150\x61\164\163\x61\160\160\137\144\x61\x74\x65\164\x69\155\x65", $adb->formatDate($date_var, true));
if ($getWhatsappAccount == "\146\162\145\145" && $oneDayMessages < "\x31\x30\x30") {
$recordModel->save();
} else {
if ($getWhatsappAccount == "\x70\162\x65\155\151\x75\x6d") {
$recordModel->save();
}
}
}
$currenDatTime = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($date_var);
}
return $currenDatTime;
}
public function getallowToWhatsAppModule($request)
{
global $adb, $current_user;
$moduleName = $request->getModule();
$sourceModuleName = $request->get("\163\157\x75\x72\143\x65\x5f\155\x6f\144\x75\x6c\x65");
$recordid = $request->get("\162\x65\143\157\162\x64\151\144");
$allowModuleData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($sourceModuleName);
$active = $allowModuleData["\x6d\x6f\144\x75\x6c\145\x49\x63\157\156\101\x63\x74\151\166\145"];
$phoneField = $allowModuleData["\160\x68\x6f\x6e\145\x46\x69\145\154\144"];
$whatsappQuery = CTWhatsApp_Record_Model::unreadQuery();
$getUreadMsgQuery = $adb->pquery($whatsappQuery . "\40\x41\x4e\x44\x20\166\164\151\x67\x65\x72\x5f\143\164\167\x68\141\164\163\x61\160\x70\56\167\150\141\164\x73\141\160\x70\x5f\x63\x6f\156\x74\141\143\164\151\x64\x20\75\40\77\x20\x41\x4e\x44\x20\x76\x74\x69\x67\x65\162\x5f\x63\164\167\150\141\x74\x73\x61\160\160\56\155\145\163\x73\141\x67\x65\x5f\x74\171\160\x65\40\75\40\47\122\145\x63\x69\145\166\x65\144\x27\x20\101\116\104\x20\x76\164\151\147\x65\162\x5f\x63\164\x77\x68\x61\164\163\141\x70\x70\x2e\x77\150\x61\x74\x73\141\x70\160\x5f\x75\156\162\145\x61\144\x72\x65\x61\144\x20\x3d\40\x27\125\x6e\162\145\x61\x64\x27", array(
$recordid
));
$unreadmsg = $adb->num_rows($getUreadMsgQuery);
$currenUserID = $current_user->id;
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$iconActive = $configurationData["\x69\143\x6f\156\x61\143\164\x69\x76\145"];
$api_url = $configurationData["\x61\160\151\137\165\162\x6c"];
$auth_token = $configurationData["\x61\x75\x74\150\164\x6f\153\145\156"];
$currentDate = date("\x59\55\155\x2d\144");
$getexpiredate = $adb->pquery("\x53\105\114\105\x43\124\40\52\40\x46\x52\x4f\x4d\40\166\164\x69\x67\145\x72\137\143\164\167\x68\x61\x74\x73\x61\x70\x70\137\x6c\x69\x63\145\x6e\163\145\137\x73\x65\164\164\151\x6e\147");
$expirydate = $adb->query_result($getexpiredate, 0, "\x65\170\160\x69\162\x79\x64\x61\164\x65");
$licenseKey = $adb->query_result($getexpiredate, 0, "\154\x69\143\145\156\163\x65\x5f\153\145\x79");
$date = Settings_CTWhatsApp_ConfigurationDetail_View::encrypt_decrypt($expirydate, $action = "\x64");
if (strtotime($currentDate) >= strtotime($date)) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "\150\x74\x74\160\163\x3a\57\x2f\167\167\167\x2e\143\162\x6d\164\x69\x67\145\162\x2e\143\x6f\x6d\x2f\167\150\x61\164\163\x61\x70\x70\57\143\150\145\x63\153\154\56\160\x68\160",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => "\x50\117\x53\x54",
CURLOPT_USERAGENT => "\x4d\157\172\x69\154\154\x61\x2f\65\x2e\x30\x20\x28\x57\151\x6e\x64\157\x77\163\x3b\x20\x55\x3b\x20\x57\x69\156\144\x6f\167\163\40\116\124\x20\x35\x2e\x31\x3b\x20\x65\x6e\55\125\123\x3b\x20\162\x76\x3a\x31\56\x38\56\61\x2e\x31\63\x29\40\107\145\143\153\x6f\x2f\x32\x30\x30\70\60\63\61\x31\40\x46\151\162\x65\146\157\x78\x2f\x32\56\60\56\60\x2e\61\63",
CURLOPT_POSTFIELDS => array(
"\154\x69\143\145\x6e\x73\x65\137\x6b\x65\x79" => $licenseKey
)
));
$response = curl_exec($curl);
curl_close($curl);
$resultResponse = json_decode($response, true);
if (strtotime($resultResponse["\x65\170\160\x69\x72\171\x64\141\164\x65"]) >= strtotime($date)) {
$newdate = Settings_Whatsapp_ConfigurationDetail_View::encrypt_decrypt($resultResponse["\x65\170\x70\x69\162\171\x64\x61\x74\x65"], $action = "\145");
$adb->pquery("\125\x50\x44\x41\124\x45\x20\166\164\x69\x67\x65\162\137\143\164\167\x68\x61\x74\x73\x61\x70\x70\137\154\x69\x63\x65\x6e\163\145\x5f\x73\x65\164\x74\x69\x6e\147\x20\163\x65\164\40\x65\170\160\x69\162\171\x64\x61\164\145\x20\x3d\x20\47{$newdate}\x27");
}
}
$recordModel = Vtiger_Record_Model::getInstanceById($recordid, $source_module);
$fieldValue = preg_replace("\x2f\x5b\136\x41\x2d\132\141\x2d\x7a\60\55\x39\135\57", '', $recordModel->get($phoneField));
$result = array(
"\151\143\157\x6e\101\x63\164\x69\x76\x65" => $iconActive,
"\x64\141\x74\x65" => $date,
"\x63\165\x72\162\145\156\164\x44\x61\164\145" => $currentDate,
"\141\143\164\x69\x76\x65" => $active,
"\x75\156\162\x65\x61\144\155\x73\147" => $unreadmsg,
"\x66\x69\x65\154\x64\126\141\154\165\x65" => $fieldValue
);
return $result;
}
public function getWhatsAppLicenseDetail()
{
global $adb;
$getexpiredate = $adb->pquery("\123\105\x4c\105\x43\x54\40\x2a\x20\x46\122\x4f\x4d\40\x76\164\x69\x67\145\162\x5f\x63\x74\167\x68\141\x74\163\141\x70\160\137\x6c\151\143\145\x6e\x73\x65\x5f\163\145\164\164\x69\156\147");
$rows = $adb->num_rows($getexpiredate);
$expiryDate = $adb->query_result($getexpiredate, 0, "\x65\170\160\151\x72\171\144\141\x74\145");
$licenseKey = $adb->query_result($getexpiredate, 0, "\154\x69\x63\x65\156\x73\x65\x5f\153\x65\171");
$domain = $adb->query_result($getexpiredate, 0, "\144\157\155\x61\151\x6e");
return $licenseDetail = array(
"\x72\157\167\163" => $rows,
"\x65\170\160\151\x72\x79\104\141\x74\x65" => $expiryDate,
"\x6c\x69\143\145\x6e\163\x65\113\x65\171" => $licenseKey,
"\x64\x6f\x6d\141\151\156" => $domain
);
}
public function updateAuthCode($request)
{
global $adb, $current_user;
$currenUserID = $current_user->id;
$authTokenKey = $request->get("\141\165\164\x68\x74\x6f\x6b\x65\156\153\145\171");
$configurationQuery = $adb->pquery("\x53\105\x4c\x45\x43\x54\x20\x2a\40\106\122\x4f\115\x20\x76\x74\151\x67\145\x72\x5f\143\x74\x77\150\x61\164\163\141\160\160\x63\x6f\x6e\146\x69\147\165\162\x61\x74\151\157\156\x20\127\x48\x45\x52\x45\40\143\x75\x73\164\x6f\155\x66\x69\x65\154\144\x35\40\75\40\x3f", array(
$currenUserID
));
$row = $adb->num_rows($configurationQuery);
if ($row) {
if ($authTokenKey) {
$updatequery = $adb->pquery("\x55\x50\104\101\x54\x45\x20\x76\x74\151\147\x65\x72\137\143\164\167\x68\x61\x74\163\x61\x70\x70\143\x6f\156\146\x69\147\165\162\x61\164\151\x6f\x6e\40\x53\105\x54\40\x61\165\x74\x68\137\164\157\x6b\145\x6e\75\77\x20\127\110\x45\122\x45\40\143\165\x73\x74\157\155\146\151\x65\x6c\x64\x35\x20\x3d\40\x3f", array(
$authTokenKey,
$currenUserID
));
}
}
}
public function getWhatsAppStatus($request)
{
global $adb, $current_user;
$currenUserID = $current_user->id;
$whatsappbot = $request->get("\x77\x68\x61\164\x73\x61\160\x70\x62\157\x74");
if ($whatsappbot == "\x79\145\163") {
$getWhatsappStatusQuery = $adb->pquery("\123\105\x4c\x45\x43\124\40\52\x20\106\x52\117\115\40\x76\x74\151\x67\145\x72\137\x63\164\x77\150\x61\164\163\x61\x70\x70\x63\157\156\146\x69\x67\165\x72\141\x74\x69\x6f\x6e\x20\127\110\105\x52\x45\40\143\165\x73\x74\157\x6d\146\x69\x65\154\x64\x35\40\x3d\x20\47\x77\150\141\164\x73\141\x70\160\102\157\164\x27", array());
} else {
$getWhatsappStatusQuery = $adb->pquery("\123\x45\x4c\x45\x43\124\40\x2a\40\106\x52\x4f\x4d\40\x76\164\x69\147\x65\162\137\143\x74\167\150\x61\x74\x73\141\160\x70\143\157\x6e\x66\x69\147\x75\x72\141\164\x69\157\156\40\127\x48\x45\x52\x45\x20\143\165\x73\x74\157\155\x66\x69\145\x6c\x64\65\x20\x3d\40\x3f", array(
$currenUserID
));
}
$whatsappStatus = $adb->query_result($getWhatsappStatusQuery, 0, "\x77\x68\x61\164\163\x61\x70\160\x73\x74\141\x74\x75\x73");
$whatsappNo = $adb->query_result($getWhatsappStatusQuery, 0, "\167\150\141\x74\163\x61\160\160\156\157");
$whatsappStatusArray = array(
"\167\x68\x61\x74\163\141\160\160\123\x74\x61\x74\165\163" => $whatsappStatus,
"\167\150\141\164\163\x61\x70\x70\116\x6f" => $whatsappNo
);
return $whatsappStatusArray;
}
public function getMassMessageData()
{
global $adb;
$query = $adb->pquery("\x53\105\114\x45\103\x54\x20\52\40\x46\x52\x4f\115\40\166\x74\151\x67\145\x72\x5f\143\x74\x77\x68\141\164\x73\x61\160\160\x6d\x61\163\x73\x62\141\164\143\x68");
$batch = $adb->query_result($query, 0, "\142\141\x74\x63\x68");
$timeinterval = $adb->query_result($query, 0, "\164\151\155\x65\151\x6e\x74\x65\x72\166\x61\x6c");
$crondatetime = $adb->query_result($query, 0, "\x63\162\x6f\x6e\x64\x61\x74\x65\164\151\155\145");
$getMassMessageDetail = array(
"\142\141\164\x63\x68" => $batch,
"\x74\x69\x6d\145\x69\156\164\145\162\166\x61\x6c" => $timeinterval,
"\x63\162\157\156\x64\141\164\145\x74\151\155\145" => $crondatetime
);
return $getMassMessageDetail;
}
public function sendMassMessages($request)
{
global $adb, $site_URL, $current_user;
$moduleName = $request->getModule();
$source_module = $request->get("\x73\157\x75\x72\143\145\x5f\x6d\157\144\165\x6c\x65");
$templatesid = $request->get("\164\145\155\x70\154\141\x74\145\x73\151\x64");
$sendNowLater = $request->get("\163\145\x6e\x64\116\157\167\x4c\x61\164\145\162");
$laterDateTime = explode("\x20", $request->get("\x6c\141\164\x65\162\104\141\164\x65\124\x69\x6d\x65"));
$cvid = $request->get("\x63\x76\151\x64");
$whatsappModuleFieldsData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($source_module);
$phoneField = $whatsappModuleFieldsData["\x70\x68\x6f\x6e\145\106\151\x65\x6c\144"];
$selected_ids = $request->get("\x73\145\x6c\x65\x63\x74\x65\x64\x5f\151\x64\163");
if ($selected_ids == "\x61\x6c\x6c") {
$customViewModel = CustomView_Record_Model::getInstanceById($cvid);
$customViewModel->set("\163\145\141\162\143\150\x5f\x70\x61\x72\x61\155\x73", $request->get("\163\x65\x61\162\x63\150\x76\x61\x6c\x75\x65"));
$selected_ids = $customViewModel->getRecordIds($excludedIds, $source_module);
} else {
$selected_ids = $request->get("\163\x65\x6c\x65\x63\x74\x65\144\x5f\x69\144\x73");
}
if ($templatesid) {
$templatesID = $templatesid;
} else {
$templatesID = "\x30";
}
$msg_body = $request->get("\x6d\163\147\142\157\x64\x79");
$date_var = date("\x59\x2d\155\x2d\x64\40\110\72\x69\72\x73");
$currentDate = date("\x59\55\155\55\x64\x20\x48\x3a\151\72\x73");
$currenUserID = $current_user->id;
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$api_url = $configurationData["\x61\160\x69\137\165\162\x6c"];
$auth_token = $configurationData["\141\165\164\x68\164\157\x6b\x65\156"];
$customfield1 = $configurationData["\143\x75\x73\164\157\155\146\x69\x65\x6c\144\x31"];
$getMassBatchConfiguration = Settings_CTWhatsApp_ConfigurationDetail_View::getMassBatchConfigurationData();
$selectBatch = $getMassBatchConfiguration["\142\141\164\x63\x68"];
if ($selectBatch) {
$getScheduleSendMsgidQuery = $adb->pquery("\x53\x45\114\105\103\x54\x20\x2a\40\106\122\117\115\40\166\164\x69\147\x65\x72\137\x63\x74\167\x68\141\x74\x73\141\160\x70\155\141\163\163\155\x65\163\x73\x61\147\x65\40\x47\x52\117\125\120\x20\102\131\x20\x6d\141\x73\x73\x6d\x65\x73\x73\141\147\145\151\144\x20\x44\105\123\103\40\114\x49\115\x49\x54\40\60\x2c\x31");
$schedulesendmsgid = $adb->query_result($getScheduleSendMsgidQuery, 0, "\x6d\141\163\x73\155\145\163\x73\141\147\x65\x69\x64") + 1;
if ($sendNowLater == "\154\x61\164\x65\x72") {
$cronDate_Time = $laterDateTime[0] . "\40" . Vtiger_Time_UIType::getTimeValueWithSeconds($laterDateTime[1] . "\40" . $laterDateTime[2]);
$cronDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($cronDate_Time);
$insertQuery = $adb->pquery("\111\x4e\123\x45\122\x54\40\x49\x4e\x54\x4f\40\x76\164\x69\147\x65\162\137\x63\x74\x77\150\141\x74\x73\141\160\160\155\141\x73\163\155\145\163\x73\141\147\x65\50\x6d\x61\163\x73\x6d\x65\x73\x73\141\x67\x65\151\144\x2c\40\164\145\155\x70\x6c\141\164\145\x73\151\x64\x2c\40\x77\150\x61\x74\163\141\160\160\x6d\x65\163\x73\x61\x67\145\54\x20\163\x65\156\x64\x6d\145\x73\x73\141\x67\x65\144\141\x74\145\54\40\155\141\x73\163\155\x73\x67\x64\141\x74\145\x74\151\x6d\x65\x29\x20\x56\x41\114\125\105\123\40\x28\77\x2c\77\54\77\x2c\77\54\77\x29", array(
$schedulesendmsgid,
$templatesID,
$msg_body,
$currentDate,
$cronDateTime
));
} else {
$insertQuery = $adb->pquery("\x49\116\x53\105\x52\x54\40\x49\x4e\x54\117\x20\166\x74\x69\147\145\162\x5f\143\164\167\150\141\x74\x73\x61\x70\160\155\x61\163\x73\155\x65\x73\x73\x61\x67\x65\50\155\141\163\163\x6d\145\x73\x73\x61\147\x65\x69\144\54\40\164\x65\x6d\x70\154\x61\x74\x65\x73\151\x64\x2c\40\x77\150\x61\164\163\x61\160\x70\x6d\145\163\x73\141\147\x65\x2c\x20\163\x65\156\144\155\x65\163\x73\x61\147\145\x64\141\164\145\54\40\155\x61\x73\x73\x6d\x73\147\x64\141\164\x65\x74\151\155\x65\x29\40\x56\101\x4c\125\x45\x53\x20\50\77\x2c\x3f\54\x3f\54\x3f\54\x3f\51", array(
$schedulesendmsgid,
$templatesID,
$msg_body,
$currentDate,
''
));
}
foreach ($selected_ids as $key => $value) {
$scheduleSendmsgQuery = $adb->pquery("\x49\x4e\x53\105\x52\x54\x20\x49\116\124\117\x20\x76\164\151\x67\x65\162\x5f\143\164\167\150\x61\164\x73\141\160\x70\x73\x63\150\x65\x64\165\x6c\145\163\x65\x6e\x64\x6d\163\x67\x28\x73\143\x68\145\144\x75\x6c\x65\163\145\x6e\144\x6d\x73\147\x69\x64\54\40\162\x65\x63\157\162\x64\151\144\x2c\x20\142\x6f\x64\x79\54\x20\163\x74\x61\x74\165\163\x2c\40\163\x65\x6e\144\x5f\x6d\163\147\x2c\x20\x64\141\164\x65\163\x65\156\x64\155\145\x73\x73\x61\147\145\51\x20\x56\x41\114\125\x45\123\x20\x28\x3f\54\x3f\54\x3f\x2c\77\x2c\77\54\77\51", array(
$schedulesendmsgid,
$value,
$msg_body,
0,
0,
''
));
}
} else {
foreach ($selected_ids as $key => $value) {
$recordModelModel = Vtiger_Record_Model::getInstanceById($value, $source_module);
$mobileno = preg_replace("\57\133\136\x41\x2d\x5a\141\55\172\60\x2d\x39\135\x2f", '', $recordModelModel->get($phoneField));
$msgbody = getMergedDescription($msg_body, $value, $source_module);
$mobilenoLen = strlen($mobileno);
if ($mobilenoLen > 10 && $customfield1 != '') {
$withoutcode = substr($mobileno, - 10);
$sendsmsnumber = $customfield1 . $withoutcode;
} else {
$sendsmsnumber = $customfield1 . $mobileno;
}
$url = $api_url . "\57" . $auth_token . "\x2f\x73\145\156\x64";
$postfields = array(
"\x6e\x75\155\142\x65\162" => $sendsmsnumber,
"\x6d\x73\147" => urlencode($msgbody)
);
$val = CTWhatsApp_WhatsappChat_View::callCURL($url, $postfields);
$currentusername = $current_user->first_name . "\x20" . $current_user->last_name;
$module_Name = "\103\124\x57\x68\141\x74\163\101\160\x70";
$recordModel = Vtiger_Record_Model::getCleanInstance($module_Name);
$recordModel->set("\x77\150\x61\x74\x73\x61\x70\160\x5f\x73\145\156\x64\x65\162\156\141\155\145", $currentusername);
$recordModel->set("\x77\x68\141\164\163\141\160\160\x5f\x63\x68\x61\x74\x69\x64", $val["\x6d\145\x73\x73\x61\x67\x65"]);
$recordModel->set("\x6d\163\147\x69\x64", $val["\151\144"]["\x69\x64"]);
$recordModel->set("\x6d\145\163\163\141\x67\x65\x5f\164\171\160\145", "\123\145\156\144");
$recordModel->set("\155\x65\163\x73\x61\x67\x65\137\x62\157\x64\x79", $msgbody);
$recordModel->set("\167\150\x61\x74\163\141\x70\x70\x5f\143\x6f\156\164\x61\x63\x74\x69\144", $value);
$recordModel->set("\x77\x68\x61\164\163\x61\x70\x70\x5f\165\156\162\145\x61\x64\x72\145\x61\x64", "\125\156\x72\145\x61\x64");
$recordModel->set("\167\x68\x61\x74\x73\x61\x70\x70\x5f\x77\151\164\150\143\x63\157\144\145", $sendsmsnumber);
$recordModel->set("\x77\150\141\164\163\141\160\x70\137\144\141\164\145\x74\151\155\145", $adb->formatDate($date_var, true));
$recordModel->save();
}
}
}
public function getWhatsAppTemplateData($request)
{
global $adb, $root_directory;
$moduleName = $request->getModule();
$templatesid = $request->get("\164\145\x6d\x70\x6c\141\x74\145\x73\151\144");
if ($templatesid) {
$recordModel = Vtiger_Record_Model::getInstanceById($templatesid, "\x43\x54\x57\150\141\164\x73\x41\160\x70\124\x65\155\x70\x6c\x61\x74\145\163");
$getAttachmentQuery = $adb->pquery("\123\x45\114\105\103\x54\40\166\x74\151\147\145\162\x5f\x61\164\164\x61\x63\150\x6d\145\156\164\x73\x2e\52\54\x20\x76\x74\151\147\x65\162\x5f\x63\162\x6d\145\x6e\164\151\164\x79\56\x73\x65\164\171\x70\145\40\x46\122\x4f\x4d\x20\166\x74\151\147\x65\162\137\141\x74\x74\141\x63\x68\155\145\156\164\163\xa\11\11\11\x9\x49\x4e\x4e\x45\x52\40\112\x4f\x49\x4e\40\x76\x74\151\x67\145\x72\137\x73\x65\141\x74\x74\x61\143\x68\x6d\x65\x6e\x74\x73\x72\145\154\40\x4f\116\40\x76\164\x69\x67\145\162\137\x73\x65\141\164\164\x61\x63\x68\155\x65\x6e\164\163\162\x65\x6c\56\x61\x74\164\141\143\x68\x6d\x65\156\164\x73\151\x64\40\x3d\x20\x76\164\x69\147\x65\x72\x5f\141\x74\164\x61\x63\150\x6d\x65\156\x74\163\56\x61\x74\164\x61\x63\x68\155\x65\156\164\163\x69\x64\xa\x9\11\11\x9\x49\116\116\x45\122\x20\112\117\x49\116\x20\166\x74\151\x67\x65\162\137\143\x72\x6d\145\156\x74\x69\x74\x79\x20\x4f\116\40\166\164\x69\147\x65\x72\137\x63\x72\x6d\145\156\164\x69\x74\171\56\x63\162\x6d\151\x64\x20\75\40\x76\x74\151\147\x65\x72\137\x61\164\x74\x61\x63\150\x6d\145\156\x74\x73\56\x61\x74\x74\x61\143\x68\x6d\x65\156\164\163\x69\x64\xa\x9\11\x9\11\127\x48\105\122\x45\x20\x76\x74\151\x67\145\162\x5f\163\x65\141\x74\164\141\143\x68\155\x65\156\x74\x73\x72\145\x6c\56\x63\162\155\151\x64\40\75\40\77\x20\101\x4e\x44\x20\x76\164\x69\x67\x65\162\137\143\162\x6d\x65\x6e\x74\x69\164\x79\56\144\x65\154\x65\164\x65\144\40\x3d\x20\x30", array(
$templatesid
));
$imageId = $adb->query_result($getAttachmentQuery, 0, "\x61\164\164\x61\x63\x68\155\145\x6e\164\x73\x69\144");
$imagePath = $adb->query_result($getAttachmentQuery, 0, "\x70\x61\x74\x68");
$fileName = $adb->query_result($getAttachmentQuery, 0, "\156\141\x6d\x65");
$type = $adb->query_result($getAttachmentQuery, 0, "\164\x79\160\145");
if (strpos($type, "\151\x6d\141\147\x65") !== false) {
$fileType = 1;
} else {
$fileType = 0;
}
$attachmentPath = $imagePath . $imageId . "\x5f" . $fileName;
$templateData = array(
"\164\x65\x6d\160\154\141\164\145\163\151\144" => $templatesid,
"\x6d\145\163\x73\141\x67\x65" => decode_html($recordModel->get("\x77\x70\164\145\155\160\154\141\x74\145\x5f\164\145\170\x74")),
"\x69\155\x61\147\x65" => $attachmentPath,
"\146\151\x6c\145\124\x79\x70\145" => $fileType,
"\146\x69\x6c\x65\x4e\141\x6d\x65" => $fileName
);
}
return $templateData;
}
public function createWhatsappUser($currenUserID)
{
global $adb, $site_URL;
if ($currenUserID == "\171\x65\x73") {
$query = $adb->pquery("\x53\x45\x4c\x45\103\x54\40\x2a\40\x46\122\117\115\40\166\x74\x69\x67\x65\162\137\143\164\x77\x68\141\x74\163\141\160\160\x63\x6f\156\146\151\147\x75\x72\x61\164\x69\157\x6e\40\x57\x48\105\122\x45\x20\x63\165\163\x74\x6f\x6d\146\x69\x65\154\144\x35\40\75\x20\x27\167\150\141\164\163\x61\x70\160\x42\157\164\47", array());
} else {
$query = $adb->pquery("\x53\x45\x4c\x45\x43\124\x20\52\40\106\122\117\115\x20\166\x74\151\147\145\162\x5f\x63\x74\167\x68\x61\x74\x73\x61\160\x70\143\x6f\x6e\146\x69\147\x75\162\141\164\151\157\x6e\40\127\110\x45\122\x45\40\143\x75\163\164\157\155\x66\x69\x65\x6c\x64\65\x20\x3d\40\x3f", array(
$currenUserID
));
}
$numrows = $adb->num_rows($query);
if ($numrows == 0) {
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$adminApiUrl = $configurationData["\x61\x70\151\137\165\x72\x6c"];
$contryCode = $configurationData["\143\x75\x73\x74\157\155\x66\x69\145\154\x64\61"];
$iconActive = $configurationData["\x69\143\157\x6e\141\x63\164\151\x76\145"];
if ($currenUserID == "\x79\x65\163") {
$insertQuery = $adb->pquery("\x49\116\x53\105\x52\124\40\111\116\x54\117\40\166\164\x69\147\145\162\x5f\143\x74\x77\x68\141\164\x73\x61\160\160\143\x6f\x6e\146\x69\x67\165\162\141\164\151\157\x6e\40\123\x45\x54\x20\141\160\151\137\x75\x72\154\x3d\47{$adminApiUrl}\x27\x2c\40\143\165\x73\164\x6f\155\x66\151\145\154\144\65\x3d\47\167\x68\141\164\x73\x61\x70\x70\x42\x6f\x74\47\54\x20\x63\x75\163\164\157\155\x66\x69\x65\x6c\144\x31\x3d\47{$contryCode}\47\x2c\40\151\x63\157\156\141\143\164\x69\166\x65\x3d\x27{$iconActive}\47", array());
} else {
$insertQuery = $adb->pquery("\111\116\x53\x45\x52\124\40\111\116\x54\x4f\x20\x76\x74\x69\x67\145\x72\137\x63\x74\167\x68\x61\x74\163\x61\160\x70\143\157\156\x66\x69\x67\x75\x72\x61\x74\151\x6f\156\x20\123\105\x54\x20\x61\x70\x69\137\165\162\x6c\75\x27{$adminApiUrl}\47\54\40\143\x75\x73\164\x6f\155\x66\x69\x65\x6c\144\65\x3d\47{$currenUserID}\x27\54\x20\x63\165\x73\x74\x6f\x6d\x66\151\145\154\x64\61\75\47{$contryCode}\47\x2c\x20\x69\143\157\156\x61\143\164\x69\x76\145\x3d\x27{$iconActive}\47", array());
}
}
$configurationUserData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$apiUrl = $configurationUserData["\x61\160\x69\137\x75\162\x6c"];
$whatsappStatus = $configurationUserData["\167\x68\x61\164\163\141\x70\160\163\164\141\164\165\163"];
$whatsappNo = $configurationData["\x77\x68\141\164\163\x61\x70\x70\156\157"];
if ($whatsappNo == '') {
$whatsappNo = $adb->query_result($query, 0, "\167\x68\141\164\x73\x61\160\160\156\157");
}
$getLicenseDetail = CTWhatsApp_DashBoard_View::getLicenseDetail();
$licenseKey = $getLicenseDetail["\x6c\x69\x63\x65\156\x73\145\x4b\145\171"];
if ($whatsappNo == '') {
$qrcodeurl = $apiUrl . "\57\151\x6e\151\x74";
$fields = array(
"\165\x72\154" => $site_URL . "\57\155\x6f\x64\x75\154\x65\x73\x2f\x43\x54\127\x68\x61\x74\163\x41\x70\160\x2f\x43\x54\127\150\141\164\101\160\160\122\145\x63\x65\x69\166\145\x72\x2e\x70\150\x70",
"\154\x69\143\145\156\143\145\x4b\145\171" => $licenseKey,
"\x73\x74\141\164\165\163\x75\x72\x6c" => $site_URL . "\x2f\155\157\x64\165\x6c\145\163\x2f\103\124\x57\x68\141\164\x73\x41\x70\x70\x2f\x57\x68\x61\x74\x73\x61\x70\x70\123\x74\141\164\165\x73\x2e\160\x68\x70\x3f\x75\163\145\162\x69\144\75" . $currenUserID
);
foreach ($fields as $key => $value) {
$fieldsString .= $key . "\75" . $value . "\46";
}
rtrim($fieldsString, "\46");
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $qrcodeurl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => "\x50\x4f\123\124",
CURLOPT_USERAGENT => "\x4d\x6f\x7a\x69\154\154\141\57\65\56\x30\x20\x28\x57\x69\156\144\157\x77\x73\73\40\125\73\40\127\151\x6e\x64\x6f\167\x73\x20\x4e\x54\40\65\x2e\x31\x3b\x20\145\x6e\55\125\x53\x3b\x20\x72\x76\72\x31\x2e\x38\x2e\61\x2e\x31\x33\x29\x20\x47\145\143\153\x6f\57\62\x30\x30\70\x30\63\x31\61\40\x46\151\x72\x65\x66\157\x78\x2f\62\x2e\60\56\60\x2e\61\63",
CURLOPT_POSTFIELDS => $fieldsString
));
$result = curl_exec($curl);
$response = json_decode($result);
curl_close($curl);
$qrcodeurl = $response->qr;
$authTokenKey = $response->key;
$scanMessage = $response->message;
if ($authTokenKey) {
if ($currenUserID == "\x79\x65\x73") {
$updatequery = $adb->pquery("\125\x50\104\101\124\105\40\x76\x74\x69\x67\145\162\x5f\143\x74\x77\150\x61\164\x73\141\160\160\x63\157\156\146\151\x67\x75\x72\141\x74\151\157\x6e\40\x53\x45\x54\x20\141\x75\164\x68\137\x74\157\153\145\156\x3d\x3f\40\x57\x48\x45\x52\x45\40\143\165\163\x74\157\x6d\x66\x69\145\154\x64\x35\x20\x3d\x20\47\167\x68\141\164\163\141\160\160\x42\157\x74\x27", array(
$authTokenKey
));
} else {
$updatequery = $adb->pquery("\125\x50\x44\101\124\x45\40\166\x74\x69\147\145\x72\x5f\143\164\167\x68\141\x74\x73\141\x70\160\143\157\x6e\146\151\x67\x75\162\141\x74\151\x6f\156\x20\x53\105\124\x20\x61\165\x74\150\137\x74\157\x6b\145\x6e\75\x3f\x20\127\110\x45\122\x45\40\x63\165\163\x74\157\x6d\146\x69\x65\154\x64\65\x20\75\40\x3f", array(
$authTokenKey,
$currenUserID
));
}
}
}
$qrCodeDetail = array(
"\x71\162\x63\x6f\144\x65\165\162\x6c" => $qrcodeurl,
"\x61\165\164\150\x54\157\153\145\156\x4b\x65\171" => $authTokenKey,
"\x77\x68\x61\x74\x73\141\x70\160\116\x6f" => $whatsappNo,
"\163\143\141\156\x4d\145\163\163\141\147\x65" => $scanMessage
);
return $qrCodeDetail;
}
public function getWhatsappGroup()
{
$configurationData = Settings_CTWhatsApp_ConfigurationDetail_View::getConfigurationData();
$apiUrl = $configurationData["\141\160\151\x5f\165\x72\154"];
$authToken = $configurationData["\141\165\164\150\x74\157\x6b\x65\156"];
$customfield1 = $configurationData["\143\x75\163\164\x6f\155\x66\151\145\x6c\144\61"];
$whatsappScanNo = $configurationData["\x77\x68\x61\x74\x73\141\x70\x70\x6e\x6f"];
$url = $apiUrl . "\x2f" . $authToken . "\57\143\150\141\x74\154\151\163\x74";
$postfields = array(
"\156\165\155\142\x65\162" => $whatsappScanNo
);
if ($whatsappScanNo) {
$getAllGroups = CTWhatsApp_WhatsappChat_View::callCURL($url, $postfields);
}
$groupsData = array();
foreach ($getAllGroups as $key => $value) {
if ($value["\x67\162\157\x75\x70\115\145\164\141\144\x61\164\x61"]) {
$recordId = '';
$label = $value["\x6e\x61\x6d\145"];
$labelExplode = explode("\40", $label);
$profileImage = "\x6c\141\171\x6f\x75\164\163\57\x76\x37\57\x6d\x6f\x64\165\154\145\x73\57\103\x54\x57\150\141\x74\163\x41\x70\x70\57\151\155\x61\x67\x65\57\147\162\157\165\160\163\56\x70\156\x67";
$imagetag = 1;
$groupid = $value["\151\144"]["\x5f\x73\x65\x72\151\x61\x6c\x69\172\x65\144"];
$groupsData[$groupid] = array(
"\162\x65\143\157\x72\x64\111\x64" => $recordId,
"\x6c\141\x62\x65\154" => $label,
"\160\162\x6f\x66\x69\154\x65\111\x6d\141\x67\145" => $profileImage,
"\x69\155\x61\x67\145\x74\x61\x67" => $imagetag,
"\147\x72\157\165\x70\151\144" => $groupid
);
}
if ($value["\151\x64"]["\163\145\162\x76\x65\162"] == "\142\162\x6f\x61\x64\143\x61\163\164") {
$recordId = '';
$label = $value["\x6e\x61\155\145"];
$labelExplode = explode("\x20", $label);
$profileImage = "\154\x61\x79\x6f\165\x74\x73\x2f\x76\67\x2f\155\157\x64\165\154\x65\x73\x2f\x43\124\x57\150\141\164\163\101\160\160\57\151\x6d\141\147\x65\x2f\147\x72\157\165\x70\163\56\160\x6e\147";
$imagetag = 1;
$groupid = $value["\151\x64"]["\137\163\x65\x72\x69\x61\154\151\172\x65\144"];
$groupsData[$groupid] = array(
"\162\x65\x63\157\x72\144\x49\x64" => $recordId,
"\x6c\x61\142\145\154" => $label,
"\160\162\x6f\x66\151\154\145\111\x6d\x61\147\145" => $profileImage,
"\151\x6d\x61\x67\x65\164\141\x67" => $imagetag,
"\x67\162\157\165\x70\x69\x64" => $groupid
);
}
}
return $groupsData;
}
public function updateWhatsappRecords($request)
{
global $adb;
$phone = $request->get("\x70\x68\157\x6e\145");
$recordId = $request->get("\162\145\143\x6f\x72\144\111\144");
$updateQuery = $adb->pquery("\x55\x50\104\x41\124\105\x20\x76\164\x69\147\x65\162\137\x63\x74\167\150\141\x74\163\141\160\x70\40\123\x45\124\x20\x77\x68\141\164\x73\x61\x70\x70\137\143\157\x6e\164\141\143\164\151\x64\x20\x3d\40\77\x20\127\x48\105\x52\105\x20\x77\150\141\164\x73\141\160\160\137\x77\151\164\x68\x63\x63\x6f\144\x65\40\75\x20\x3f", array(
$recordId,
$phone
));
}
public function getWhatsappTemplates()
{
global $adb;
$getWhatsappTemplateQuery = $adb->pquery("\x53\x45\x4c\x45\103\124\x20\x2a\40\106\x52\117\x4d\40\166\x74\151\147\x65\x72\x5f\x63\x74\x77\x68\x61\164\163\141\x70\160\164\145\x6d\x70\154\x61\x74\x65\x73\x20\111\x4e\x4e\x45\x52\40\x4a\x4f\x49\116\x20\x76\x74\151\x67\x65\x72\137\x63\162\x6d\145\x6e\164\x69\164\x79\40\117\x4e\x20\x76\x74\151\147\x65\x72\x5f\143\162\x6d\x65\156\164\x69\164\x79\56\143\x72\x6d\151\144\x20\75\x20\166\164\x69\147\145\162\x5f\143\164\x77\x68\141\x74\x73\x61\x70\160\164\145\x6d\x70\x6c\x61\x74\x65\163\56\143\164\x77\x68\x61\x74\163\141\x70\x70\164\x65\155\160\x6c\x61\x74\145\163\x69\144\40\127\110\105\122\x45\x20\x76\164\151\x67\145\162\x5f\143\162\155\145\156\x74\151\x74\x79\56\x64\145\154\x65\164\145\144\x20\75\40\60", array());
$whatsappTemplateRows = $adb->num_rows($getWhatsappTemplateQuery);
$templatesArray = array();
for ($j = 0; $j < $whatsappTemplateRows; $j ++) {
$templatesID = $adb->query_result($getWhatsappTemplateQuery, $j, "\x63\x74\167\x68\141\164\x73\x61\x70\x70\164\x65\155\x70\154\141\x74\x65\163\151\144");
$templateTitle = $adb->query_result($getWhatsappTemplateQuery, $j, "\x77\x70\164\145\x6d\160\x6c\141\x74\x65\x5f\x74\x69\164\154\145");
$templatesArray[$templatesID] = $templateTitle;
}
return $templatesArray;
}
public function getRelatedToId($mobileno)
{
global $adb;
$whatsappModuleQuery = $adb->pquery("\x53\x45\114\x45\x43\x54\x20\x2a\40\106\x52\117\x4d\40\x76\164\x69\x67\x65\162\x5f\143\164\x77\150\x61\x72\163\141\x70\x70\141\154\x6c\x6f\x77\x5f\167\150\x61\x74\x73\x61\160\160\155\157\x64\x75\x6c\145\40\x57\x48\105\122\x45\x20\x61\x63\x74\151\x76\145\x20\x3d\40\x31");
$rows = $adb->num_rows($whatsappModuleQuery);
$whatsaappModule = array();
for ($i = 0; $i < $rows; $i ++) {
$modulename = $adb->query_result($whatsappModuleQuery, $i, "\x6d\157\144\165\154\145");
$moduleIsEnable = CTWhatsApp_Record_Model::getmoduleIsEnable($modulename);
if ($moduleIsEnable == 0) {
$whatsaappModuleData = CTWhatsApp_Record_Model::getWhatsappAllowModuleFields($modulename);
$phoneField = $whatsaappModuleData["\160\x68\157\156\x65\x46\x69\x65\154\144"];
$moduleModel = CRMEntity::getInstance($modulename);
$moduleInstance = Vtiger_Module::getInstance($modulename);
$baseTable = $moduleInstance->basetable;
$baseTableid = $moduleInstance->basetableid;
$mainTable = 0;
$query = "\123\105\114\x45\x43\124\x20\52\40\106\122\117\x4d\40" . $baseTable;
foreach ($moduleModel->tab_name_index as $key => $value) {
$mainTable = $mainTable + 1;
if ($mainTable != 2) {
if ($key != "\x76\164\x69\147\145\x72\x5f\163\x65\160\162\x6f\144\x75\143\164\x73\162\145\154" && $key != "\x76\164\151\x67\x65\162\137\160\162\x6f\x64\x75\x63\164\164\141\170\162\145\154") {
$query .= "\40\x49\116\x4e\105\x52\40\x4a\117\x49\116\x20" . $key . "\40\117\x4e\x20" . $key . "\56" . $value . "\40\x3d\40" . $baseTable . "\56" . $baseTableid;
}
}
}
$query .= "\40\x57\x48\105\x52\x45\x20\x52\105\x50\114\101\x43\105\x28\122\105\120\114\x41\103\x45\50\122\105\120\x4c\x41\x43\x45\x28\x52\105\120\114\x41\103\x45\50\122\x45\120\x4c\x41\x43\x45\50" . $phoneField . "\x2c\40\x27\x29\47\54\40\x27\47\x29\54\x20\47\50\47\x2c\x20\47\47\x29\x2c\x27\x2d\x27\54\47\47\51\x2c\x27\40\x27\x2c\47\x27\x29\x2c\47\56\x27\54\47\x27\51\x20\114\111\113\105\40\x27\45" . $mobileno . "\45\x27\x20\x41\x4e\104\40\166\x74\x69\147\x65\162\137\x63\x72\155\x65\x6e\x74\x69\x74\x79\56\144\x65\x6c\145\164\145\x64\75\60";
$queryResult = $adb->pquery($query);
$row = $adb->num_rows($queryResult);
if ($row) {
$relatedTo = $adb->query_result($queryResult, 0, $baseTableid);
$smownerid = $adb->query_result($queryResult, 0, "\x73\x6d\157\x77\x6e\x65\x72\x69\144");
}
}
}
$resultData = array(
"\x72\x65\x6c\141\164\145\144\124\x6f" => $relatedTo,
"\x73\x6d\157\167\x6e\145\162\151\144" => $smownerid
);
return $resultData;
}
public function getWhatsAppStoragePath()
{
global $root_directory;
$year = date("\131");
$month = date("\106");
$day = date("\x6a");
$week = '';
$whatsappfolderpath = "\x6d\x6f\144\165\154\x65\x73\x2f\103\x54\x57\x68\x61\x74\163\101\x70\160\x2f\x43\x54\127\150\141\164\163\101\160\x70\x53\164\x6f\162\x61\x67\145\x2f";
if (! is_dir($root_directory . $whatsappfolderpath)) {
mkdir($root_directory . $whatsappfolderpath);
chmod($root_directory . $whatsappfolderpath, 511);
}
if (! is_dir($root_directory . $whatsappfolderpath . $year)) {
mkdir($root_directory . $whatsappfolderpath . $year);
chmod($root_directory . $whatsappfolderpath . $year, 511);
}
if (! is_dir($root_directory . $whatsappfolderpath . $year . "\x2f" . $month)) {
mkdir($root_directory . $whatsappfolderpath . "{$year}\x2f{$month}\x2f");
chmod($root_directory . $whatsappfolderpath . "{$year}\x2f{$month}\57", 511);
}
if ($day > 0 && $day <= 7) {
$week = "\x77\x65\x65\x6b\61";
} elseif ($day > 7 && $day <= 14) {
$week = "\x77\145\145\x6b\62";
} elseif ($day > 14 && $day <= 21) {
$week = "\167\x65\x65\x6b\63";
} elseif ($day > 21 && $day <= 28) {
$week = "\x77\145\145\x6b\64";
} else {
$week = "\167\145\145\x6b\65";
}
if (! is_dir($root_directory . $whatsappfolderpath . $year . "\x2f" . $month . "\57" . $week)) {
mkdir($root_directory . $whatsappfolderpath . "{$year}\57{$month}\57{$week}\x2f");
chmod($root_directory . $whatsappfolderpath . "{$year}\57{$month}\x2f{$week}\57", 511);
}
$target_file = $root_directory . $whatsappfolderpath . "{$year}\x2f{$month}\x2f{$week}\57";
return $target_file;
}
public function getWhatsAppTemplatesData($recordid)
{
global $adb;
$getWhatsappTemplateQuery = $adb->pquery("\x53\x45\114\x45\103\124\40\52\40\106\122\117\115\x20\166\164\151\x67\145\162\x5f\x63\x74\x77\150\141\164\x73\141\160\160\x74\145\x6d\x70\154\141\164\x65\163\x20\12\x9\11\x9\x49\x4e\x4e\x45\122\40\x4a\x4f\x49\x4e\x20\x76\x74\151\147\x65\x72\x5f\143\162\x6d\145\x6e\164\x69\x74\x79\x20\x4f\116\x20\166\x74\151\x67\145\162\137\x63\x72\x6d\145\156\164\x69\x74\x79\56\143\162\x6d\x69\x64\40\x3d\x20\166\x74\x69\x67\x65\x72\137\143\164\167\150\x61\164\x73\x61\160\x70\x74\145\155\x70\154\x61\164\x65\163\x2e\x63\164\x77\x68\x61\164\x73\x61\160\160\164\x65\155\x70\x6c\x61\x74\x65\x73\151\144\x20\12\x9\11\11\111\116\116\105\122\x20\112\x4f\111\116\40\166\x74\151\x67\145\162\x5f\163\x65\x61\x74\164\141\x63\x68\155\145\x6e\164\163\162\145\154\x20\x4f\x4e\x20\x76\164\x69\147\145\x72\137\163\145\x61\164\x74\x61\143\x68\x6d\x65\156\164\163\x72\145\x6c\x2e\x63\162\155\x69\144\x20\x3d\40\x76\x74\151\x67\145\162\137\x63\164\x77\150\141\x74\x73\141\x70\160\164\145\x6d\x70\x6c\141\164\x65\163\56\143\164\x77\x68\x61\x74\x73\141\160\160\164\x65\x6d\x70\x6c\141\x74\145\x73\151\x64\x20\12\11\x9\x9\x49\x4e\x4e\105\x52\40\112\117\x49\116\x20\x76\x74\x69\x67\145\x72\x5f\x61\x74\x74\141\143\150\x6d\x65\x6e\164\x73\40\x4f\x4e\x20\166\x74\151\x67\145\162\x5f\141\164\x74\141\x63\150\x6d\x65\156\164\163\x2e\x61\164\164\141\x63\x68\x6d\145\x6e\x74\163\x69\144\x20\75\x20\166\164\x69\147\145\x72\x5f\x73\145\x61\x74\x74\x61\x63\150\155\x65\x6e\x74\163\162\145\x6c\x2e\141\x74\164\x61\143\x68\x6d\145\x6e\164\163\x69\x64\12\x9\x9\11\x57\x48\105\x52\105\x20\166\x74\x69\147\145\x72\137\x63\x72\155\145\x6e\164\151\164\x79\56\144\x65\154\145\164\145\x64\40\75\40\x30\40\101\116\104\x20\166\164\151\x67\145\x72\x5f\x63\x74\x77\x68\x61\164\x73\x61\160\x70\164\145\x6d\x70\x6c\x61\x74\x65\x73\56\x63\164\167\x68\x61\x74\163\x61\160\x70\164\145\x6d\160\154\x61\x74\x65\163\x69\144\40\x3d\40\x3f", array(
$recordid
));
$isTemplates = $adb->num_rows($getWhatsappTemplateQuery);
if ($isTemplates) {
$templatesID = $adb->query_result($getWhatsappTemplateQuery, 0, "\143\x74\x77\150\x61\164\163\141\x70\x70\x74\145\155\160\x6c\x61\164\145\163\x69\x64");
$message = $adb->query_result($getWhatsappTemplateQuery, 0, "\x77\x70\x74\145\x6d\x70\x6c\x61\164\145\137\x74\145\170\x74");
$templateMsg = $adb->query_result($getWhatsappTemplateQuery, 0, "\x77\160\x74\145\155\x70\154\x61\x74\x65\137\x6d\x73\x67");
$wptemplateImage = $adb->query_result($getWhatsappTemplateQuery, 0, "\x6e\141\x6d\x65");
}
$whatsAppTemplateData = array(
"\164\x65\155\160\x6c\141\x74\145\163\111\x44" => $templatesID,
"\155\145\163\163\141\x67\x65" => $message,
"\164\145\155\160\x6c\141\x74\x65\115\x73\x67" => $templateMsg,
"\x77\160\x74\145\155\160\x6c\x61\x74\145\x49\x6d\x61\147\145" => $wptemplateImage
);
return $whatsAppTemplateData;
}
public function getAttachmentData($templatesID)
{
global $adb;
$getAttachmentQuery = $adb->pquery("\123\x45\x4c\x45\103\x54\x20\x76\164\151\147\x65\x72\x5f\141\x74\x74\x61\x63\150\155\145\x6e\164\x73\x2e\x2a\x2c\x20\x76\x74\151\147\x65\162\137\x63\x72\x6d\x65\x6e\164\x69\164\171\56\x73\145\x74\x79\160\x65\40\x46\122\117\x4d\x20\x76\x74\x69\x67\x65\162\137\x61\x74\164\x61\143\150\155\x65\156\x74\163\12\x9\11\11\x49\116\116\105\x52\x20\x4a\x4f\111\116\40\166\x74\151\x67\145\162\137\x73\x65\x61\164\x74\x61\x63\150\155\x65\156\164\x73\162\x65\x6c\x20\117\116\x20\x76\x74\151\x67\145\162\x5f\163\145\141\x74\164\x61\143\x68\x6d\145\x6e\x74\163\162\145\x6c\x2e\141\x74\164\x61\x63\x68\155\x65\156\x74\x73\151\x64\40\75\x20\166\x74\x69\x67\145\162\137\141\164\x74\141\x63\150\x6d\145\156\164\163\x2e\x61\x74\x74\141\x63\x68\x6d\x65\x6e\x74\x73\x69\x64\12\11\x9\11\111\x4e\116\x45\x52\x20\112\117\111\116\x20\166\x74\x69\x67\145\x72\x5f\x63\x72\155\145\x6e\x74\x69\164\171\x20\117\116\x20\166\x74\151\147\x65\x72\x5f\x63\x72\x6d\145\156\x74\x69\x74\x79\x2e\143\x72\x6d\x69\144\x20\75\40\166\164\x69\147\145\162\x5f\x61\x74\x74\141\x63\150\155\145\x6e\164\163\56\x61\x74\164\141\143\x68\x6d\x65\x6e\x74\x73\151\x64\xa\11\x9\11\127\x48\105\122\x45\40\166\164\151\147\145\x72\x5f\163\145\x61\164\x74\x61\143\150\x6d\x65\x6e\x74\x73\x72\x65\x6c\56\143\x72\155\151\x64\x20\75\40\x3f\40\101\x4e\104\x20\x76\164\x69\x67\145\162\x5f\x63\x72\155\145\156\164\x69\164\x79\56\144\145\154\145\164\x65\144\40\x3d\x20\60", array(
$templatesID
));
$imageId = $adb->query_result($getAttachmentQuery, 0, "\x61\x74\x74\141\143\150\155\x65\x6e\164\163\151\144");
$imagePath = $adb->query_result($getAttachmentQuery, 0, "\x70\141\x74\x68");
$imageName = $adb->query_result($getAttachmentQuery, 0, "\x6e\141\x6d\x65");
$attachmentData = array(
"\151\x6d\x61\147\145\x49\x64" => $imageId,
"\151\x6d\141\147\x65\x50\141\164\150" => $imagePath,
"\x69\x6d\141\147\145\116\141\x6d\x65" => $imageName
);
return $attachmentData;
}
public function getWhatsAppRecordQuery($startdate, $enddate)
{
$whatsappQuery = CTWhatsApp_Record_Model::unreadQuery();
$query = $whatsappQuery . "\x20\101\x4e\x44\x20\x76\164\x69\x67\x65\162\x5f\x63\164\x77\x68\141\164\163\141\x70\x70\x2e\x77\x68\x61\164\x73\141\x70\x70\137\x63\157\x6e\x74\141\143\164\x69\144\40\x3d\40\x3f\40\x41\116\104\x20\x44\x41\124\x45\x28\166\164\151\x67\x65\x72\x5f\143\x72\x6d\x65\x6e\x74\151\x74\171\x2e\x63\x72\x65\x61\x74\145\x64\164\151\155\145\x29\40\102\x45\x54\x57\105\105\x4e\x20\47{$startdate}\x27\40\x41\x4e\x44\40\47{$enddate}\47";
return $query;
}
public function getPhoneFieldLabel($tabid, $phoneField)
{
global $adb;
$getFieldsLabel = $adb->pquery("\x53\x45\114\x45\103\124\x20\x2a\x20\x46\122\x4f\115\40\166\x74\x69\x67\x65\162\137\146\151\x65\154\x64\x20\x57\x48\105\x52\x45\x20\x74\x61\142\x69\144\75\77\x20\x41\116\x44\40\146\x69\145\x6c\x64\x6e\x61\155\x65\75\77", array(
$tabid,
$phoneField
));
$phonefield = $adb->query_result($getFieldsLabel, 0, "\146\151\145\154\144\x6c\x61\142\145\154");
return $phonefield;
}
public function userConfigurationData($currenUserID)
{
global $adb;
$queryUserExist = $adb->pquery("\x53\x45\114\105\x43\124\x20\x2a\40\106\x52\x4f\115\x20\x76\164\151\147\x65\162\137\x63\x74\167\150\x61\x74\x73\x61\160\160\x63\x6f\156\x66\151\147\x75\x72\x61\x74\x69\x6f\x6e\40\x57\x48\x45\122\105\x20\x63\165\x73\164\157\155\146\x69\145\154\144\x33\40\114\111\113\105\40\47\x25" . $currenUserID . "\45\47", array());
$numRowsUsers = $adb->num_rows($queryUserExist);
if ($numRowsUsers == 0) {
$queryGetGroupId = $adb->pquery("\x53\105\114\x45\103\x54\x20\52\x20\106\122\117\x4d\x20\166\x74\151\x67\x65\x72\x5f\147\162\157\x75\x70\x32\x72\x6f\x6c\145\40\x49\x4e\x4e\x45\x52\x20\x4a\x4f\x49\116\x20\x76\164\151\147\x65\162\x5f\x75\163\x65\162\62\x72\157\x6c\145\40\117\x4e\40\x76\x74\x69\x67\145\162\x5f\x75\x73\145\x72\62\x72\x6f\x6c\x65\x2e\x72\x6f\154\145\151\x64\x20\x3d\x20\x76\x74\151\147\145\162\137\147\x72\157\x75\160\x32\162\x6f\154\145\56\162\157\154\x65\x69\144\40\x57\110\x45\x52\105\x20\x76\164\151\x67\145\162\x5f\165\x73\x65\x72\62\x72\x6f\154\x65\x2e\165\x73\x65\162\151\144\x20\x3d\40\77", array(
$currenUserID
));
$groupid = $adb->query_result($queryGetGroupId, 0, "\147\162\x6f\x75\x70\x69\x64");
if ($groupid != '') {
$queryGroupExist = $adb->pquery("\x53\x45\114\105\103\x54\40\x2a\x20\106\122\117\115\40\166\164\x69\x67\x65\162\137\x63\x74\167\x68\141\164\163\x61\x70\x70\143\157\156\146\151\x67\165\162\141\x74\x69\157\x6e\40\127\x48\105\122\x45\x20\143\165\x73\x74\157\x6d\x66\x69\x65\154\x64\63\40\x4c\x49\113\x45\40\47\x25" . $groupid . "\x25\47", array());
}
$numRowsUsers = $adb->num_rows($queryGroupExist);
}
return $numRowsUsers;
}
public function updateWhatsAppSatatus($currenUserID)
{
global $adb;
$udpateStatusQuery = $adb->pquery("\x55\x50\x44\x41\x54\105\40\x76\x74\x69\147\x65\x72\137\x63\x74\167\x68\141\x74\163\x61\x70\160\143\157\x6e\x66\151\147\165\x72\141\164\151\x6f\x6e\x20\123\105\x54\40\x77\x68\x61\164\163\x61\160\160\163\164\141\164\165\163\40\75\40\60\54\x20\x77\150\x61\x74\x73\141\160\160\156\157\x20\x3d\40\x27\x27\x20\x57\110\105\x52\105\40\x63\x75\163\x74\157\x6d\x66\x69\145\154\144\x35\x20\75\40\77", array(
$currenUserID
));
}
public function createNewUser($currenUserID, $adminApiUrl, $contryCode, $iconActive)
{
global $adb;
$query = $adb->pquery("\123\105\x4c\x45\103\x54\40\52\x20\x46\122\117\x4d\40\166\x74\151\x67\x65\162\137\143\x74\x77\150\x61\x74\x73\141\x70\x70\x63\157\x6e\x66\151\147\165\x72\141\164\x69\157\156\40\x57\x48\105\x52\105\40\x63\x75\163\x74\x6f\x6d\x66\151\x65\154\x64\x35\40\75\40\x3f", array(
$currenUserID
));
$numrows = $adb->num_rows($query);
if ($numrows == 0) {
$insertQuery = $adb->pquery("\111\x4e\123\105\122\x54\x20\111\x4e\x54\x4f\40\x76\x74\151\147\x65\162\137\143\x74\167\150\141\164\x73\x61\160\160\143\157\x6e\146\151\x67\x75\x72\141\x74\151\x6f\x6e\x20\x53\105\124\x20\x61\x70\151\137\x75\162\x6c\75\47{$adminApiUrl}\47\x2c\40\143\x75\163\164\157\x6d\146\151\145\x6c\x64\x35\75\x27{$currenUserID}\47\x2c\40\143\x75\163\x74\157\x6d\146\x69\145\x6c\144\61\75\x27{$contryCode}\47\54\40\151\x63\157\x6e\141\x63\164\151\x76\x65\75\x27{$iconActive}\x27", array());
}
}
public function getLastMessageDataTime($massMessageid)
{
global $adb;
$query = $adb->pquery("\x53\105\114\x45\x43\x54\x20\52\40\x46\122\117\115\40\x76\x74\151\x67\x65\162\137\143\164\167\150\141\164\x73\141\x70\x70\163\x63\150\145\144\165\154\145\x73\x65\156\144\155\163\147\x20\x57\x48\x45\x52\x45\x20\163\143\150\x65\x64\165\154\145\x73\x65\x6e\x64\x6d\163\147\151\x64\40\75\x20{$massMessageid}\40\x41\x4e\104\40\x76\x74\x69\x67\145\162\137\143\164\x77\150\x61\x74\163\x61\x70\160\163\143\150\x65\x64\x75\154\145\x73\x65\x6e\144\x6d\163\147\56\x73\x74\x61\x74\165\163\x20\x3d\x20\61\40\101\x4e\104\40\163\x65\x6e\144\x5f\x6d\x73\x67\40\x3d\x20\x31\40\x41\116\x44\40\x64\x61\164\145\x73\x65\156\144\155\x65\163\x73\141\x67\x65\40\x21\75\x20\x27\47\40\x4f\122\104\105\122\40\102\x59\40\x64\141\164\145\x73\145\156\x64\155\145\x73\x73\141\147\145\40\104\x45\123\x43\x20\114\x49\115\111\124\x20\x30\x2c\x31");
$lastMessageDataTime = $adb->query_result($query, 0, "\144\141\164\145\x73\145\x6e\x64\x6d\145\163\x73\x61\147\x65");
return $lastMessageDataTime;
}
public function getSendQueueMessages($request)
{
global $adb;
$progress = $request->get("\160\162\157\x67\x72\x65\x73\163");
if ($progress == "\103\x6f\155\x70\x6c\145\x74\x65\144") {
$progressMessages = "\x20\x41\116\x44\40\x73\x74\141\x74\x75\163\x20\x3d\x20\61";
} else {
if ($progress == "\x49\156\120\162\x6f\x67\162\x65\163\x73") {
$progressMessages = "\40\101\x4e\x44\40\163\x74\141\x74\165\163\x20\75\40\x30";
} else {
if ($progress == "\x48\x6f\154\144") {
$progressMessages = "\40\101\x4e\x44\x20\x73\x74\x61\x74\x75\163\40\75\x20\62";
} else {
if ($progress == "\x41\154\x6c") {
$progressMessages = "\40\x41\116\104\40\x73\x74\141\x74\165\x73\40\x49\116\40\50\60\54\61\54\x32\x29";
}
}
}
}
$date_var = date("\x59\55\x6d\55\144\40\110\x3a\x69\72\x73");
$currenDateTime = $adb->formatDate($date_var, true);
$getMassMessageDetail = CTWhatsApp_DashBoard_View::getMassMessageDetail();
$batch = $getMassMessageDetail["\x62\141\164\x63\x68"];
$timeinterval = $getMassMessageDetail["\x74\x69\x6d\145\151\x6e\164\x65\x72\x76\x61\x6c"];
$periodData = CTWhatsApp_DashBoard_View::getPeriodDataQuery($request, "\x73\x65\156\x64\155\x65\163\x73\141\147\145\x64\141\164\x65");
$selectPeriodData = $request->get("\160\x65\x72\x69\157\x64\104\141\x74\x61");
if ($selectPeriodData == "\141\154\154\164\151\x6d\145") {
$query = $adb->pquery("\123\x45\114\105\103\x54\x20\x2a\40\106\122\117\115\40\166\x74\151\147\x65\x72\137\143\x74\x77\150\141\164\163\141\160\160\x6d\x61\x73\x73\x6d\x65\x73\x73\141\147\x65\40\x4f\x52\104\x45\x52\x20\102\131\40\155\141\x73\163\x6d\145\163\x73\x61\147\145\x69\x64\40\104\x45\x53\x43");
} else {
$query = $adb->pquery("\123\105\114\x45\x43\124\x20\x2a\x20\x46\x52\117\x4d\x20\166\164\151\147\x65\162\137\143\164\167\150\x61\x74\x73\x61\160\160\155\x61\x73\163\x6d\x65\x73\x73\141\x67\x65\x20\127\110\105\x52\x45\40" . $periodData . "\40\x4f\122\104\105\122\40\x42\131\x20\x6d\x61\x73\163\x6d\x65\x73\x73\x61\x67\145\151\144\x20\x44\105\123\103\40\114\111\115\x49\124\40\x30\x2c\65");
}
$rows = $adb->num_rows($query);
$sendqueueMessages = array();
for ($i = 0; $i < $rows; $i ++) {
$status = '';
$expcompdate = '';
$readRows = 0;
$massMessageid = $adb->query_result($query, $i, "\x6d\x61\163\163\155\145\x73\163\x61\x67\x65\151\144");
$whatsappMessage = $adb->query_result($query, $i, "\167\150\x61\x74\x73\141\x70\x70\x6d\x65\163\163\x61\x67\145");
$massmsgdatetime = $adb->query_result($query, $i, "\155\x61\163\x73\x6d\x73\x67\144\x61\164\x65\164\x69\155\x65");
$templatesid = $adb->query_result($query, $i, "\164\145\155\160\154\141\x74\145\x73\x69\x64");
$sendMessageDate = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($adb->query_result($query, $i, "\163\x65\156\144\155\x65\x73\163\141\147\145\x64\141\x74\x65"));
$getLastMessageDataTime = CTWhatsApp_Record_Model::getLastMessageDataTime($massMessageid);
if ($getLastMessageDataTime != '') {
$lastMessageDate = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat($getLastMessageDataTime);
} else {
$lastMessageDate = "\55";
}
$queryScheduleSendmsg = $adb->pquery("\x53\105\x4c\105\x43\x54\40\52\x20\106\122\x4f\x4d\x20\166\x74\x69\147\145\162\137\x63\164\167\x68\141\x74\163\x61\160\160\x73\x63\150\x65\x64\165\x6c\x65\163\145\156\144\x6d\163\147\40\x57\x48\105\122\105\40\163\143\150\145\144\x75\x6c\x65\163\x65\x6e\144\155\163\x67\151\144\x20\x3d\x20\77\x20{$progressMessages}", array(
$massMessageid
));
$rowScheduleSendmsg = $adb->num_rows($queryScheduleSendmsg);
$totalSend = 0;
$totalQueue = 0;
for ($j = 0; $j < $rowScheduleSendmsg; $j ++) {
$send_msg = $adb->query_result($queryScheduleSendmsg, $j, "\163\145\156\144\x5f\x6d\163\147");
$whatsappRecordid = $adb->query_result($queryScheduleSendmsg, $j, "\x72\145\x63\x6f\x72\x64\x69\x64");
$sendMessageStatus = $adb->query_result($queryScheduleSendmsg, $j, "\x73\x74\141\164\x75\x73");
$scheduleSendmsgID = $adb->query_result($queryScheduleSendmsg, $j, "\163\x63\x68\145\x64\165\154\x65\163\x65\x6e\x64\155\x73\x67\151\144");
$getReadQuery = $adb->pquery("\123\105\114\x45\x43\124\x20\x2a\x20\x46\122\x4f\115\40\166\x74\x69\147\145\162\x5f\x63\x74\x77\x68\x61\164\163\x61\160\x70\40\111\116\x4e\x45\x52\x20\x4a\117\111\116\x20\x76\164\151\x67\x65\x72\x5f\x63\x72\155\x65\156\x74\151\x74\171\x20\x4f\x4e\40\166\164\x69\x67\145\162\137\143\162\x6d\145\x6e\x74\151\x74\x79\x2e\x63\162\155\151\x64\x20\75\x20\166\x74\x69\x67\x65\x72\x5f\x63\164\167\x68\x61\164\163\x61\160\x70\x2e\143\164\x77\x68\141\x74\163\141\160\160\x69\x64\40\127\110\x45\x52\x45\40\166\x74\x69\x67\x65\x72\137\x63\162\155\145\x6e\x74\x69\x74\171\x2e\144\x65\154\145\x74\x65\x64\40\x3d\40\x30\40\101\116\104\40\x76\x74\x69\x67\145\x72\137\143\x74\x77\150\x61\164\x73\x61\x70\x70\x2e\x77\150\x61\x74\x73\141\160\160\x5f\143\157\x6e\164\x61\143\164\151\144\40\75\40\x3f\40\101\x4e\x44\40\166\164\x69\147\145\162\137\x63\x74\167\x68\141\x74\x73\x61\x70\160\56\x6d\x65\x73\x73\141\x67\145\x5f\164\x79\160\x65\x20\75\x20\x27\115\141\163\x73\40\x4d\x65\163\x73\141\x67\145\x27\40\x41\116\104\40\x76\x74\x69\x67\145\x72\137\143\x74\167\150\x61\164\x73\141\x70\x70\x2e\167\x68\141\164\163\141\160\160\x5f\165\x6e\x72\x65\141\x64\x72\145\x61\144\x20\75\x20\47\x52\x65\x61\144\47\x20\x41\116\x44\40\166\164\151\x67\x65\162\x5f\x63\x74\167\150\x61\164\163\141\x70\x70\x2e\167\x68\141\164\x73\x61\160\160\x5f\x77\x69\x74\x68\157\x63\143\x6f\x64\145\x20\75\40\x3f", array(
$whatsappRecordid,
$scheduleSendmsgID
));
$readRows = $readRows + $adb->num_rows($getReadQuery);
$deleteCheckQuery = $adb->pquery("\x53\105\x4c\105\x43\x54\40\x2a\x20\106\122\x4f\x4d\40\x76\164\151\x67\145\x72\137\143\x72\155\145\x6e\x74\151\x74\x79\x20\127\x48\105\122\105\40\x63\x72\155\x69\x64\x20\x3d\40\77", array(
$whatsappRecordid
));
if ($adb->query_result($deleteCheckQuery, 0, "\x64\x65\154\145\164\x65\x64") == 0) {
$setype = VtigerCRMObject::getSEType($whatsappRecordid);
}
if ($send_msg == 1) {
$totalSend = $totalSend + 1;
}
$totalQueue = $rowScheduleSendmsg - $totalSend;
}
if ($totalQueue != 0) {
$total = $rowScheduleSendmsg / $batch;
if ($massmsgdatetime) {
$currentdatetime = $massmsgdatetime;
} else {
$currentdatetime = date("\131\55\x6d\55\x64\40\x48\x3a\151\72\163");
}
if ($total <= 1) {
$expexteddatetime = strtotime($currentdatetime . "\40\x2b\40" . $timeinterval . "\40\155\x69\156\x75\x74\145");
} else {
$totalminutes = $total * $timeinterval;
$expexteddatetime = strtotime($currentdatetime . "\x20\x2b\40" . round($totalminutes) . "\40\x6d\151\x6e\165\164\145");
}
}
if ($sendMessageStatus == 2) {
$status = "\110\x6f\x6c\x64";
$expcompdate = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat(date("\x59\55\x6d\x2d\x64\40\110\x3a\x69\72\x73", $expexteddatetime));
} else {
if ($sendMessageStatus == 1) {
$status = "\103\157\155\160\154\145\164\x65\144";
$expcompdate = "\x2d";
} else {
$status = "\x49\156\120\162\157\147\162\145\x73\163";
$expcompdate = Vtiger_Util_Helper::convertDateTimeIntoUsersDisplayFormat(date("\131\55\x6d\55\144\40\110\72\151\72\163", $expexteddatetime));
}
}
$getWhatsappTemplateQuery = $adb->pquery("\x53\x45\114\105\103\x54\x20\x2a\x20\x46\122\x4f\115\40\x76\164\151\x67\x65\162\x5f\143\x74\167\x68\141\x74\x73\x61\160\x70\x74\x65\x6d\160\154\141\x74\145\x73\x20\111\x4e\116\x45\x52\40\x4a\117\111\116\x20\166\164\151\147\145\162\x5f\x63\162\155\x65\x6e\x74\151\x74\171\40\117\116\40\x76\164\x69\147\145\x72\x5f\143\x72\x6d\x65\x6e\x74\151\164\171\x2e\143\162\155\x69\x64\40\x3d\40\x76\x74\151\x67\x65\x72\x5f\x63\164\167\150\141\x74\163\141\160\x70\164\145\x6d\x70\x6c\x61\164\x65\x73\56\x63\x74\x77\x68\x61\x74\163\x61\x70\x70\164\145\x6d\x70\154\x61\x74\x65\x73\151\x64\40\x57\x48\105\x52\105\x20\x76\164\151\x67\x65\162\137\143\162\155\145\x6e\164\151\x74\x79\x2e\144\x65\154\x65\x74\x65\144\40\x3d\40\60\x20\101\x4e\104\x20\166\x74\x69\x67\145\162\137\143\x74\x77\150\141\164\x73\x61\x70\160\164\145\x6d\160\154\x61\164\x65\x73\56\143\164\x77\150\x61\x74\x73\141\160\160\164\145\155\x70\154\141\164\145\x73\x69\144\40\75\40\x3f", array(
$templatesid
));
$isTemplates = $adb->num_rows($getWhatsappTemplateQuery);
if ($isTemplates) {
$whatsappMessage = '';
$whatsappMessage = $adb->query_result($getWhatsappTemplateQuery, 0, "\167\x70\x74\145\x6d\160\x6c\141\x74\145\x5f\x74\x65\x78\x74");
$templatesId = $adb->query_result($getWhatsappTemplateQuery, 0, "\x63\x74\167\x68\141\164\x73\x61\x70\160\164\x65\x6d\160\x6c\141\164\x65\x73\151\144");
$getAttachmentQuery = $adb->pquery("\123\x45\x4c\105\103\124\x20\x2a\x20\x46\122\x4f\115\x20\166\164\x69\147\145\162\137\141\164\164\141\x63\150\x6d\145\156\x74\163\12\x20\40\x20\x20\40\x20\40\x20\40\x20\40\40\x20\x20\x20\40\40\40\x20\40\x49\116\116\105\122\x20\x4a\x4f\x49\x4e\x20\x76\164\x69\x67\145\162\x5f\x73\x65\141\x74\x74\x61\x63\x68\155\145\x6e\164\163\162\x65\x6c\x20\117\x4e\x20\x76\x74\x69\x67\x65\x72\137\163\x65\141\x74\164\x61\x63\x68\x6d\145\156\x74\163\x72\x65\154\x2e\x61\164\164\x61\x63\150\155\x65\x6e\x74\x73\151\x64\40\75\x20\x76\x74\x69\147\145\x72\x5f\141\164\x74\x61\x63\x68\155\145\x6e\164\x73\x2e\x61\x74\164\141\143\x68\x6d\145\x6e\x74\x73\x69\x64\xa\x20\40\x20\40\40\40\x20\x20\x20\x20\x20\x20\x20\x20\x20\40\x20\x20\40\x20\111\116\x4e\105\x52\x20\112\x4f\x49\116\40\x76\x74\x69\147\145\162\x5f\x63\x72\155\145\x6e\x74\151\164\171\40\117\116\40\166\164\151\147\145\x72\x5f\x63\x72\155\x65\156\x74\151\164\171\x2e\143\x72\155\151\144\x20\75\x20\166\x74\x69\147\145\162\x5f\141\164\x74\141\x63\x68\155\145\156\164\x73\56\141\x74\x74\x61\143\150\x6d\x65\x6e\164\x73\x69\144\12\40\x20\x20\x20\x20\40\40\x20\x20\x20\x20\x20\x20\40\40\x20\x20\x20\40\x20\127\x48\x45\122\105\x20\x76\x74\151\147\145\x72\137\x73\x65\x61\164\164\x61\143\x68\155\x65\156\x74\163\162\145\x6c\x2e\143\162\155\x69\x64\40\75\40\77\40\101\x4e\x44\x20\x76\x74\151\147\145\x72\137\143\x72\155\x65\156\x74\x69\164\171\x2e\144\x65\x6c\x65\x74\x65\x64\x20\75\40\60", array(
$templatesId
));
$imageId = $adb->query_result($getAttachmentQuery, 0, "\141\164\164\141\143\x68\x6d\x65\156\164\x73\151\144");
$imagePath = $adb->query_result($getAttachmentQuery, 0, "\160\x61\x74\x68");
$imageName = $adb->query_result($getAttachmentQuery, 0, "\156\141\x6d\145");
$type = explode("\57", $adb->query_result($getAttachmentQuery, 0, "\164\x79\x70\x65"));
$attachmentPath = $imagePath . $imageId . "\x5f" . $imageName;
if ($type[0] == "\x69\155\141\147\145") {
$whatsappMessage .= "\x3c\142\162\76\74\x69\x6d\147\x20\x73\162\x63\x3d\x22" . $attachmentPath . "\42\x20\x73\164\171\154\x65\x3d\42\167\x69\x64\x74\150\72\x20\65\60\x70\170\x3b\x22\76";
} else {
$whatsappMessage .= "\74\142\x72\76\x3c\x61\x20\x68\162\145\x66\75\x22" . $attachmentPath . "\42\x3e" . $imageName . "\74\57\141\76";
}
}
$totalMessages = $totalSend + $totalQueue;
if ($rowScheduleSendmsg != '') {
$sendqueueMessages[] = array(
"\x6d\x61\x73\x73\x4d\x65\163\163\141\x67\x65\151\144" => $massMessageid,
"\144\141\164\145" => $sendMessageDate,
"\x77\150\141\x74\163\x61\x70\160\x6d\x65\163\x73\x61\x67\x65" => $whatsappMessage,
"\x74\157\x74\141\154\x53\x65\156\144" => $totalSend,
"\x74\157\x74\141\x6c\121\x75\145\165\145" => $totalQueue,
"\164\x6f\164\x61\x6c\115\145\163\163\x61\x67\145\x73" => $totalMessages,
"\154\141\x73\x74\115\x65\163\x73\x61\x67\145\x44\141\x74\145" => $lastMessageDate,
"\x72\145\141\x64\122\x6f\167\163" => $readRows,
"\x73\164\141\x74\165\x73" => $status,
"\x65\x78\x70\x63\157\155\160\x64\x61\x74\145" => $expcompdate,
"\163\145\156\x64\x4d\x65\x73\x73\x61\147\145\x53\164\x61\x74\x75\x73" => $sendMessageStatus,
"\163\x65\164\171\x70\145" => vtranslate($setype, $setype)
);
}
}
return $sendqueueMessages;
}
public function getWhatsAppReportData($period, $format, $periodData)
{
global $adb;
$arrayData = array();
$yAxisData1 = array();
$yAxisData2 = array();
$yAxisData3 = array();
foreach ($period as $key => $date) {
$conditionDate = $date->format($format);
$customeQuery = '';
if ($periodData == "\141\154\x6c\164\x69\155\145") {
$customeQuery = "\40\101\116\104\40\x59\105\x41\122\50\x76\x74\151\147\x65\x72\x5f\143\x72\155\x65\x6e\164\x69\164\x79\56\143\x72\x65\x61\164\x65\x64\x74\x69\155\x65\51\x20\75\40\77";
} else {
$customeQuery = "\x20\x41\116\104\x20\104\x41\x54\x45\x28\166\x74\151\x67\145\x72\x5f\x63\162\x6d\x65\156\164\x69\164\x79\x2e\x63\162\145\x61\x74\x65\144\x74\151\155\145\51\40\x3d\40\x3f";
}
$whatsappMessageQuery = "\123\x45\114\x45\x43\124\x20\x2a\40\106\122\117\115\x20\x76\x74\x69\x67\x65\162\x5f\x63\x74\167\150\141\164\163\x61\x70\160\x20\x49\x4e\x4e\x45\x52\x20\112\117\x49\116\x20\x76\164\x69\147\x65\x72\137\143\162\x6d\145\x6e\x74\151\x74\171\40\117\x4e\40\166\164\x69\147\x65\162\x5f\x63\162\155\145\156\164\151\x74\171\56\143\x72\x6d\x69\x64\40\x3d\x20\166\164\151\x67\145\x72\137\143\164\x77\150\x61\164\x73\141\x70\160\56\143\x74\x77\x68\141\x74\163\141\160\x70\151\144\40\x57\x48\x45\x52\x45\x20\x76\164\151\x67\145\x72\x5f\143\x72\155\x65\156\164\x69\x74\x79\x2e\144\x65\x6c\x65\164\x65\144\40\75\x20\x30\x20\101\x4e\x44\40\166\x74\151\147\x65\x72\137\143\164\167\x68\x61\164\x73\x61\160\x70\x2e\x6d\145\x73\x73\141\147\x65\x5f\164\171\x70\x65\x20\x49\x4e\50\47\x53\x65\x6e\144\x27\x2c\x27\115\141\163\163\40\x4d\x65\163\163\x61\x67\x65\x27\51";
$query = $adb->pquery($whatsappMessageQuery . $customeQuery, array(
$conditionDate
));
$sent = 0;
$read = 0;
$rows = $adb->num_rows($query);
for ($i = 0; $i < $rows; $i ++) {
$messageType = $adb->query_result($query, $i, "\155\145\163\x73\141\147\x65\x5f\x74\x79\x70\145");
if ($messageType != '') {
$sent = $sent + 1;
}
$messageReadUpRead = $adb->query_result($query, $i, "\167\x68\141\x74\163\x61\160\x70\137\x75\x6e\162\145\141\x64\162\x65\141\x64");
if ($messageReadUpRead == "\122\145\141\144") {
$read = $read + 1;
}
}
$yAxisData1["\x63\157\165\156\164"][] = $sent;
$yAxisData2["\143\157\x75\x6e\164"][] = $read;
}
$arrayData["\123\145\156\144"] = $yAxisData1;
$arrayData["\122\x65\141\144"] = $yAxisData2;
return $arrayData;
}
public function massMessagePauseResume($status, $recordid)
{
global $adb;
$updateStatusQuery = $adb->pquery("\x55\x50\104\101\x54\x45\40\166\164\x69\147\145\x72\x5f\x63\x74\167\150\141\164\x73\x61\x70\x70\x73\x63\150\x65\x64\x75\x6c\145\163\x65\156\x64\155\x73\147\x20\x53\x45\124\x20\x73\x74\141\164\x75\x73\40\x3d\40\x3f\x20\x57\x48\105\x52\x45\x20\163\143\x68\x65\x64\165\154\145\163\x65\x6e\x64\155\x73\x67\151\x64\40\75\x20\77\x20\x41\116\x44\40\x73\x65\x6e\144\137\x6d\163\x67\40\x3d\40\60", array(
$status,
$recordid
));
}
public function massMessageDelete($recordid)
{
global $adb;
$massDeleteQuery = $adb->pquery("\x44\105\x4c\x45\x54\x45\x20\x46\x52\117\x4d\x20\166\x74\x69\147\145\x72\137\x63\x74\167\x68\141\x74\x73\141\x70\160\155\x61\163\163\x6d\145\x73\x73\141\147\145\x20\127\x48\105\x52\105\40\x6d\141\x73\x73\155\x65\x73\163\x61\x67\145\x69\x64\x20\75\40\x3f", array(
$recordid
));
$massMessageDeleteQuery = $adb->pquery("\x44\x45\114\105\124\x45\40\106\122\x4f\115\40\166\x74\151\x67\145\x72\137\143\x74\167\150\141\164\x73\x61\x70\x70\163\143\150\145\x64\x75\154\145\x73\145\x6e\144\x6d\x73\147\x20\x57\x48\x45\x52\x45\40\x73\143\150\145\144\165\x6c\145\x73\145\x6e\x64\155\163\147\x69\144\40\75\40\77", array(
$recordid
));
}
public function getWhatsappTheme()
{
global $adb;
$query = $adb->pquery("\123\x45\x4c\x45\x43\x54\x20\x2a\x20\x46\122\x4f\115\40\x76\164\x69\x67\x65\162\137\143\164\167\x68\141\164\x73\141\160\x70\x63\x6f\x6e\146\x69\x67\x75\x72\x61\x74\x69\x6f\156\40\127\110\x45\x52\105\40\x74\150\145\x6d\x65\x5f\166\151\x65\x77\40\x21\x3d\40\47\47", array());
$theme_view = $adb->query_result($query, 0, "\164\150\145\155\x65\137\x76\151\x65\167");
return $theme_view;
}
public function getModulefields($tabid, $sourceModuleName, $moduleRecordId)
{
global $adb;
$query = $adb->pquery("\123\x45\x4c\x45\103\x54\40\x2a\x20\106\x52\117\x4d\40\x76\x74\151\147\145\162\x5f\146\151\x65\x6c\144\x20\x57\110\x45\122\x45\x20\x74\x61\142\151\144\x20\x3d\40\x3f\x20\101\116\104\x20\x71\x75\x69\143\x6b\x63\x72\x65\141\164\x65\x20\x49\x4e\x28\x27\x30\47\x2c\x27\62\x27\51\40\x41\x4e\104\40\x75\151\x74\171\160\145\40\x4e\x4f\x54\40\x49\x4e\50\47\x35\66\47\x2c\47\x35\61\x27\x2c\x27\61\60\x27\x2c\x27\x31\65\x27\x2c\x27\x35\x27\54\47\63\63\x27\54\x27\x35\67\47\51", array(
$tabid
));
$num_rows = $adb->num_rows($query);
$recordModel = Vtiger_Record_Model::getInstanceById($moduleRecordId, $sourceModuleName);
$fieldLabelValue = array();
for ($i = 0; $i < $num_rows; $i ++) {
$fieldname = $adb->query_result($query, $i, "\x66\151\145\x6c\x64\156\141\155\145");
$fieldlabel = $adb->query_result($query, $i, "\x66\151\x65\x6c\x64\154\x61\142\145\154");
$fieldValue = $recordModel->get($fieldname);
$fieldLabelValue[$fieldlabel] = array(
"\x66\151\x65\154\x64\x4e\141\155\x65" => $fieldname,
"\146\151\145\154\144\126\141\154\165\x65" => $fieldValue
);
}
return $fieldLabelValue;
}
public function getUserScanWhatsAppAllData($userid)
{
global $adb;
$query = $adb->pquery("\x53\105\x4c\x45\103\124\x20\x2a\x20\106\122\x4f\115\x20\166\x74\x69\147\145\162\x5f\143\x74\167\150\141\x74\163\141\x70\x70\143\x6f\156\146\x69\x67\165\x72\141\164\151\x6f\156\40\127\110\x45\122\x45\x20\x63\x75\x73\x74\x6f\155\x66\x69\145\154\144\x35\x20\x3d\40\77", array(
$userid
));
$row = $adb->num_rows($query);
$api_url = $adb->query_result($query, 0, "\x61\160\x69\x5f\165\x72\154");
$auth_token = $adb->query_result($query, 0, "\141\x75\164\x68\x5f\x74\x6f\153\145\x6e");
$customfield1 = $adb->query_result($query, 0, "\143\165\x73\164\x6f\x6d\146\x69\145\154\144\x31");
$whatsappno = $adb->query_result($query, 0, "\x77\150\x61\x74\163\x61\x70\160\156\157");
$userScanWhatsAppData = array(
"\x72\157\x77" => $row,
"\x61\160\151\x5f\165\x72\x6c" => $api_url,
"\x61\x75\164\150\137\x74\x6f\153\145\x6e" => $auth_token,
"\143\165\163\x74\157\x6d\x66\151\145\x6c\x64\x31" => $customfield1,
"\167\150\x61\x74\x73\x61\160\x70\156\x6f" => $whatsappno
);
return $userScanWhatsAppData;
}
public function checkMessageId($messageid)
{
global $adb;
$query = $adb->pquery("\123\105\114\105\103\x54\x20\52\x20\x46\x52\117\x4d\40\x76\x74\x69\x67\145\x72\x5f\x63\x74\167\x68\141\x74\163\x61\160\160\x20\111\116\x4e\x45\x52\40\112\117\x49\x4e\40\166\x74\x69\147\145\162\x5f\x63\x72\155\145\x6e\164\151\164\x79\40\117\x4e\x20\x76\164\x69\x67\145\x72\x5f\x63\162\155\145\156\x74\151\x74\x79\x2e\143\x72\155\x69\144\40\x3d\x20\166\164\x69\147\145\x72\x5f\x63\164\167\150\141\x74\x73\x61\160\x70\x2e\x63\164\167\150\x61\164\x73\x61\x70\x70\x69\144\x20\x57\110\105\122\105\40\166\164\x69\x67\145\x72\137\x63\162\155\145\156\164\x69\x74\x79\56\144\x65\x6c\145\x74\x65\x64\x20\75\x20\60\x20\101\x4e\104\x20\x76\x74\151\147\x65\162\x5f\143\164\167\150\141\164\163\141\x70\160\x2e\155\x73\147\151\x64\x20\75\40\77", array(
$messageid
));
$row = $adb->num_rows($query);
return $row;
}
public function getScanNumberUserId($scanNumber)
{
global $adb;
$query = $adb->pquery("\x53\x45\114\x45\103\124\40\x2a\40\106\x52\117\115\40\166\164\151\147\145\x72\137\143\164\x77\x68\141\164\163\x61\160\160\x63\157\x6e\x66\151\147\165\162\141\164\151\157\x6e\40\x57\x48\x45\122\x45\40\167\x68\141\x74\x73\141\x70\160\156\x6f\40\x3d\40\x3f", array(
$scanNumber
));
$row = $adb->num_rows($query);
if ($row) {
$scanUserId = $adb->query_result($query, 0, "\143\x75\163\164\x6f\x6d\146\151\x65\x6c\144\65");
$userScanUsersData = array(
"\163\x63\x61\156\125\x73\x65\x72\x49\x64" => $scanUserId
);
}
return $userScanUsersData;
}
public function getAdmminScanDetail()
{
global $adb;
$query = $adb->pquery("\123\105\x4c\x45\x43\124\40\x2a\40\106\122\117\115\x20\166\164\x69\147\x65\162\137\143\x74\167\150\141\164\163\141\160\x70\x63\x6f\x6e\146\x69\x67\165\x72\x61\164\151\x6f\x6e\x20\127\x48\105\x52\x45\x20\x63\x75\x73\x74\x6f\155\146\x69\145\154\x64\x34\40\x21\x3d\40\x27\47", array());
$row = $adb->num_rows($query);
if ($row) {
$showunknownmsg = $adb->query_result($query, 0, "\163\150\x6f\x77\x75\x6e\153\156\157\x77\x6e\155\x73\147");
$customfield3 = $adb->query_result($query, 0, "\143\165\163\164\157\155\146\x69\145\x6c\144\x33");
$api_url = $adb->query_result($query, 0, "\x61\160\x69\137\165\162\154");
$admminScanDetail = array(
"\163\150\157\x77\165\156\153\156\157\x77\x6e\x6d\163\x67" => $showunknownmsg,
"\x6d\x75\x6c\x74\151\x70\x6c\145\x75\x73\145\162" => $customfield3,
"\141\x70\x69\x5f\165\162\154" => $api_url
);
}
return $admminScanDetail;
}
public function getOneDaysMessages()
{
global $adb;
$todayDate = date("\131\55\155\x2d\144");
$query = $adb->pquery("\123\105\x4c\105\103\x54\x20\52\x20\106\122\117\115\x20\x76\x74\x69\147\145\x72\137\143\x74\x77\x68\141\x74\x73\x61\x70\160\40\111\116\x4e\105\x52\x20\x4a\117\x49\x4e\40\x20\x76\x74\x69\x67\145\162\x5f\x63\162\155\145\156\x74\x69\x74\x79\x20\x4f\116\x20\x76\164\151\147\x65\162\137\143\162\x6d\145\x6e\x74\151\164\171\x2e\x63\x72\155\151\144\40\x3d\40\x76\164\151\147\x65\x72\x5f\143\x74\167\x68\x61\164\163\141\160\x70\x2e\143\164\167\x68\141\x74\x73\141\x70\160\151\x64\40\127\110\x45\x52\105\40\166\x74\151\147\145\162\137\x63\x72\155\145\156\x74\x69\164\171\x2e\x64\x65\154\145\x74\x65\x64\x20\x3d\40\60\40\x41\116\104\40\166\x74\151\x67\145\162\x5f\x63\x74\x77\x68\141\164\163\x61\x70\x70\x2e\155\x65\x73\x73\x61\147\x65\x5f\164\x79\160\x65\40\111\x4e\x20\x28\x27\123\x65\156\144\x27\x2c\47\115\141\163\x73\40\115\x65\163\x73\141\x67\x65\x27\51\x20\101\x4e\104\40\104\101\x54\x45\x28\166\x74\151\147\x65\162\x5f\143\x72\x6d\145\156\x74\x69\164\171\56\x63\x72\145\141\x74\145\144\x74\x69\x6d\145\x29\x20\75\40\x27" . $todayDate . "\x27");
$rows = $adb->num_rows($query);
return $rows;
}
public function getWhatsappAccountDetail($licenseKey)
{
$apiURL = "\x68\164\164\x70\163\x3a\x2f\57\x77\x77\x77\x2e\x63\x72\x6d\164\151\147\145\x72\56\x63\x6f\x6d\x2f\167\x68\x61\164\x73\x61\160\160\57\143\150\x65\143\x6b\154\151\146\162\157\x6d\141\160\x69\56\x70\x68\x70\x3f\x6c\151\143\145\156\163\145\x5f\153\x65\x79\x3d" . $licenseKey;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $apiURL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_CUSTOMREQUEST => "\x50\x4f\123\x54",
CURLOPT_USERAGENT => "\115\x6f\x7a\151\x6c\x6c\141\57\65\x2e\60\x20\x28\127\151\x6e\144\x6f\167\163\73\x20\x55\x3b\x20\x57\151\x6e\144\157\x77\x73\40\116\124\40\x35\56\x31\x3b\x20\145\156\x2d\125\x53\x3b\40\162\x76\72\61\x2e\70\x2e\x31\56\x31\x33\51\x20\x47\x65\x63\x6b\x6f\57\x32\x30\60\70\60\x33\61\61\x20\x46\x69\162\145\146\157\170\57\x32\56\x30\x2e\60\56\61\63"
));
$result = curl_exec($curl);
$response = json_decode($result);
curl_close($curl);
$type = $response->type;
return $type;
}
public function getWhatsappNumberImportant($mobileno)
{
global $adb;
$query = $adb->pquery("\x53\x45\114\105\x43\124\x20\52\40\106\122\x4f\x4d\x20\166\x74\x69\147\145\162\x5f\143\x74\167\150\141\164\x73\x61\160\x70\40\111\116\116\105\x52\x20\112\x4f\111\x4e\x20\166\164\x69\147\x65\x72\137\x63\162\x6d\x65\156\164\x69\164\x79\x20\x4f\116\x20\166\x74\x69\147\145\162\137\x63\162\155\145\156\164\151\x74\x79\x2e\x63\x72\155\x69\x64\40\75\40\166\164\151\147\145\162\137\x63\164\167\x68\141\164\163\x61\160\160\x2e\143\x74\x77\x68\141\164\163\141\x70\160\151\x64\40\x57\x48\x45\122\105\40\166\x74\151\147\x65\x72\x5f\143\164\167\150\141\164\x73\x61\x70\x70\56\x77\150\141\164\x73\x61\160\160\137\167\151\164\x68\x63\143\x6f\144\145\40\75\x20\x3f\40\x41\x4e\x44\40\x76\x74\x69\147\x65\162\137\x63\162\155\x65\156\164\x69\x74\171\56\144\145\x6c\145\164\x65\144\x20\x3d\x20\60\40\x4c\111\115\111\124\40\60\x2c\x31", array(
$mobileno
));
$important = $adb->query_result($query, 0, "\167\150\141\164\163\141\x70\x70\137\x69\155\160\157\x72\x74\141\x6e\x74");
return $important;
}
}
Function Calls
None |
Stats
MD5 | 76488c54f309360f95f0e247fadaf218 |
Eval Count | 0 |
Decode Time | 182 ms |