function vtws_getUsersInTheSameGroup($id) { require_once 'include/utils/GetGroupUsers.php'; require_once 'include/utils/GetUserGroups.php'; $groupUsers = new GetGroupUsers(); $userGroups = new GetUserGroups(); $allUsers = array(); $userGroups->getAllUserGroups($id); $groups = $userGroups->user_groups; foreach ($groups as $group) { $groupUsers->getAllUsersInGroup($group); $usersInGroup = $groupUsers->group_users; foreach ($usersInGroup as $user) { if ($user != $id) { $allUsers[$user] = getUserFullName($user); } } } return $allUsers; }
public function getRecipientEmails() { $recipientsInfo = $this->get('recipients'); if (!empty($recipientsInfo)) { $recipients = array(); $recipientsInfo = Zend_Json::decode($recipientsInfo); foreach ($recipientsInfo as $key => $recipient) { if (strpos($recipient, 'USER') !== false) { $id = explode('::', $recipient); $recipients['Users'][] = $id[1]; } else { if (strpos($recipient, 'GROUP') !== false) { $id = explode('::', $recipient); $recipients['Groups'][] = $id[1]; } else { if (strpos($recipient, 'ROLE') !== false) { $id = explode('::', $recipient); $recipients['Roles'][] = $id[1]; } } } } } $recipientsList = array(); if (!empty($recipients)) { if (!empty($recipients['Users'])) { $recipientsList = array_merge($recipientsList, $recipients['Users']); } if (!empty($recipients['Roles'])) { foreach ($recipients['Roles'] as $roleId) { $roleUsers = getRoleUsers($roleId); foreach ($roleUsers as $userId => $userName) { array_push($recipientsList, $userId); } } } if (!empty($recipients['Groups'])) { require_once 'include/utils/GetGroupUsers.php'; foreach ($recipients['Groups'] as $groupId) { $userGroups = new GetGroupUsers(); $userGroups->getAllUsersInGroup($groupId); $recipientsList = array_merge($recipientsList, $userGroups->group_users); } } } $recipientsList = array_unique($recipientsList); $recipientsEmails = array(); if (!empty($recipientsList) && count($recipientsList) > 0) { foreach ($recipientsList as $userId) { if (!Vtiger_Util_Helper::isUserDeleted($userId)) { $userName = getUserFullName($userId); $userEmail = getUserEmail($userId); if (!in_array($userEmail, $recipientsEmails)) { $recipientsEmails[$userName] = $userEmail; } } } } //Added for specific email address. $specificemails = explode(',', Zend_Json::decode($this->get('specificemails'))); if (!empty($specificemails)) { $recipientsEmails = array_merge($recipientsEmails, $specificemails); } return $recipientsEmails; }
/** Gives an array which contains the information for what all roles, groups and user's related module data that is to be shared for the specified parent module and shared module * @param $par_mod -- parent module name:: Type varchar * @param $share_mod -- shared module name:: Type varchar * @param $userid -- user id:: Type integer * @param $def_org_share -- default organization sharing permission array:: Type array * @param $mod_sharingrule_members -- Sharing Rule Members array:: Type array * @param $$mod_share_read_per -- Sharing Module Read Permission array:: Type array * @param $$mod_share_write_per -- Sharing Module Write Permission array:: Type array * @returns $related_mod_sharing_permission; -- array which contains the id of roles,group and users related module data to be shared */ function getRelatedModuleSharingArray($par_mod, $share_mod, $mod_sharingrule_members, $mod_share_read_per, $mod_share_write_per, $def_org_share) { global $adb; $related_mod_sharing_permission = array(); $mod_share_read_permission = array(); $mod_share_write_permission = array(); $mod_share_read_permission['ROLE'] = array(); $mod_share_write_permission['ROLE'] = array(); $mod_share_read_permission['GROUP'] = array(); $mod_share_write_permission['GROUP'] = array(); $par_mod_id = getTabid($par_mod); $share_mod_id = getTabid($share_mod); if ($def_org_share[$share_mod_id] == 3 || $def_org_share[$share_mod_id] == 0) { $role_read_per = array(); $role_write_per = array(); $grp_read_per = array(); $grp_write_per = array(); foreach ($mod_sharingrule_members as $sharingid => $sharingInfoArr) { $query = "select vtiger_datashare_relatedmodule_permission.* from vtiger_datashare_relatedmodule_permission inner join vtiger_datashare_relatedmodules on vtiger_datashare_relatedmodules.datashare_relatedmodule_id=vtiger_datashare_relatedmodule_permission.datashare_relatedmodule_id where vtiger_datashare_relatedmodule_permission.shareid=? and vtiger_datashare_relatedmodules.tabid=? and vtiger_datashare_relatedmodules.relatedto_tabid=?"; $result = $adb->pquery($query, array($sharingid, $par_mod_id, $share_mod_id)); $share_permission = $adb->query_result($result, 0, 'permission'); foreach ($sharingInfoArr as $shareType => $shareEntArr) { foreach ($shareEntArr as $key => $shareEntId) { if ($shareType == 'ROLE') { if ($share_permission == 1) { if ($def_org_share[$share_mod_id] == 3) { if (!array_key_exists($shareEntId, $role_read_per)) { if (array_key_exists($shareEntId, $mod_share_read_per['ROLE'])) { $share_role_users = $mod_share_read_per['ROLE'][$shareEntId]; } elseif (array_key_exists($shareEntId, $mod_share_write_per['ROLE'])) { $share_role_users = $mod_share_write_per['ROLE'][$shareEntId]; } else { $share_role_users = getRoleUserIds($shareEntId); } $role_read_per[$shareEntId] = $share_role_users; } } if (!array_key_exists($shareEntId, $role_write_per)) { if (array_key_exists($shareEntId, $mod_share_read_per['ROLE'])) { $share_role_users = $mod_share_read_per['ROLE'][$shareEntId]; } elseif (array_key_exists($shareEntId, $mod_share_write_per['ROLE'])) { $share_role_users = $mod_share_write_per['ROLE'][$shareEntId]; } else { $share_role_users = getRoleUserIds($shareEntId); } $role_write_per[$shareEntId] = $share_role_users; } } elseif ($share_permission == 0 && $def_org_share[$share_mod_id] == 3) { if (!array_key_exists($shareEntId, $role_read_per)) { if (array_key_exists($shareEntId, $mod_share_read_per['ROLE'])) { $share_role_users = $mod_share_read_per['ROLE'][$shareEntId]; } elseif (array_key_exists($shareEntId, $mod_share_write_per['ROLE'])) { $share_role_users = $mod_share_write_per['ROLE'][$shareEntId]; } else { $share_role_users = getRoleUserIds($shareEntId); } $role_read_per[$shareEntId] = $share_role_users; } } } elseif ($shareType == 'GROUP') { if ($share_permission == 1) { if ($def_org_share[$share_mod_id] == 3) { if (!array_key_exists($shareEntId, $grp_read_per)) { if (array_key_exists($shareEntId, $mod_share_read_per['GROUP'])) { $share_grp_users = $mod_share_read_per['GROUP'][$shareEntId]; } elseif (array_key_exists($shareEntId, $mod_share_write_per['GROUP'])) { $share_grp_users = $mod_share_write_per['GROUP'][$shareEntId]; } else { $focusGrpUsers = new GetGroupUsers(); $focusGrpUsers->getAllUsersInGroup($shareEntId); $share_grp_users = $focusGrpUsers->group_users; foreach ($focusGrpUsers->group_subgroups as $subgrpid => $subgrpusers) { if (!array_key_exists($subgrpid, $grp_read_per)) { $grp_read_per[$subgrpid] = $subgrpusers; } } } $grp_read_per[$shareEntId] = $share_grp_users; } } if (!array_key_exists($shareEntId, $grp_write_per)) { if (!array_key_exists($shareEntId, $grp_write_per)) { if (array_key_exists($shareEntId, $mod_share_read_per['GROUP'])) { $share_grp_users = $mod_share_read_per['GROUP'][$shareEntId]; } elseif (array_key_exists($shareEntId, $mod_share_write_per['GROUP'])) { $share_grp_users = $mod_share_write_per['GROUP'][$shareEntId]; } else { $focusGrpUsers = new GetGroupUsers(); $focusGrpUsers->getAllUsersInGroup($shareEntId); $share_grp_users = $focusGrpUsers->group_users; foreach ($focusGrpUsers->group_subgroups as $subgrpid => $subgrpusers) { if (!array_key_exists($subgrpid, $grp_write_per)) { $grp_write_per[$subgrpid] = $subgrpusers; } } } $grp_write_per[$shareEntId] = $share_grp_users; } } } elseif ($share_permission == 0 && $def_org_share[$share_mod_id] == 3) { if (!array_key_exists($shareEntId, $grp_read_per)) { if (array_key_exists($shareEntId, $mod_share_read_per['GROUP'])) { $share_grp_users = $mod_share_read_per['GROUP'][$shareEntId]; } elseif (array_key_exists($shareEntId, $mod_share_write_per['GROUP'])) { $share_grp_users = $mod_share_write_per['GROUP'][$shareEntId]; } else { $focusGrpUsers = new GetGroupUsers(); $focusGrpUsers->getAllUsersInGroup($shareEntId); $share_grp_users = $focusGrpUsers->group_users; foreach ($focusGrpUsers->group_subgroups as $subgrpid => $subgrpusers) { if (!array_key_exists($subgrpid, $grp_read_per)) { $grp_read_per[$subgrpid] = $subgrpusers; } } } $grp_read_per[$shareEntId] = $share_grp_users; } } } } } } $mod_share_read_permission['ROLE'] = $role_read_per; $mod_share_write_permission['ROLE'] = $role_write_per; $mod_share_read_permission['GROUP'] = $grp_read_per; $mod_share_write_permission['GROUP'] = $grp_write_per; } $related_mod_sharing_permission['read'] = $mod_share_read_permission; $related_mod_sharing_permission['write'] = $mod_share_write_permission; return $related_mod_sharing_permission; }
protected function smsAssignedTo() { global $adb; // Determine the number based on Assign To $assignedtoid = $this->column_fields['assigned_user_id']; $type = $this->isUserOrGroup($assignedtoid); if ($type == 'U') { $userIds = array($assignedtoid); } else { require_once 'include/utils/GetGroupUsers.php'; $getGroupObj = new GetGroupUsers(); $getGroupObj->getAllUsersInGroup($assignedtoid); $userIds = $getGroupObj->group_users; } $tonumbers = array(); if (count($userIds) > 0) { $phoneSqlQuery = "select phone_mobile, id from vtiger_users WHERE status='Active' AND id in(" . generateQuestionMarks($userIds) . ")"; $phoneSqlResult = $adb->pquery($phoneSqlQuery, array($userIds)); while ($phoneSqlResultRow = $adb->fetch_array($phoneSqlResult)) { $number = $phoneSqlResultRow['phone_mobile']; if (!empty($number)) { $tonumbers[] = $number; } } } if (!empty($tonumbers)) { $responses = self::fireSendSMS($this->column_fields['message'], $tonumbers); $this->processFireSendSMSResponse($responses); } }
public function handleEvent($handlerType, $entityData) { global $log, $adb, $root_directory, $current_user; if ($handlerType == 'vtiger.entity.aftersave' && isset($_REQUEST['geventid']) && $_REQUEST['geventid'] != '') { $q = 'select activitytypeid from vtiger_activitytype where activitytype = ?'; $Res = $adb->pquery($q, array($_REQUEST["gevent_type"])); $event = $adb->query_result($Res, 0, 'activitytypeid'); $geventid = vtlib_purify($_REQUEST['geventid']); $id = $entityData->getId(); $p = array($id, $geventid, $current_user->id, $event); $sql1 = 'SELECT * FROM its4you_googlesync4you_events WHERE crmid = ? AND geventid = ? AND userid = ? AND eventtype = ?'; $result1 = $adb->pquery($sql1, $p); $num_rows1 = $adb->num_rows($result1); if ($num_rows1 == 0) { $sql2 = 'INSERT INTO its4you_googlesync4you_events (crmid,geventid,userid,eventtype) VALUES (?,?,?,?)'; $result2 = $adb->pquery($sql2, $p); } } if ($handlerType == 'vtiger.entity.aftersave' || $handlerType == 'vtiger.entity.beforedelete') { $moduleName = $entityData->getModuleName(); if ($moduleName == 'Calendar' || $moduleName == 'Events') { $InGCalendars = array(); $id = $entityData->getId(); //$Data = $entityData->getData(); $ev = CRMEntity::getInstance("Calendar"); $ev->id = $id; $ev->mode = 'edit'; $evv = $ev->retrieve_entity_info($id, "Events"); $Data = $ev->column_fields; $sql1 = 'SELECT userid, geventid, eventtype FROM its4you_googlesync4you_events WHERE crmid = ?'; $result1 = $adb->pquery($sql1, array($id)); $num_rows1 = $adb->num_rows($result1); if ($num_rows1 > 0) { while ($row = $adb->fetchByAssoc($result1)) { $InGCalendars[$row['eventtype']][$row['userid']] = $row['geventid']; } } if ($handlerType == 'vtiger.entity.aftersave') { if ($moduleName == 'Calendar') { $event = 'task'; } else { $q = 'select activitytypeid from vtiger_activitytype where activitytype = ?'; $Res = $adb->pquery($q, array($Data['activitytype'])); $event = $adb->query_result($Res, 0, 'activitytypeid'); } $assigned_user_id = $entityData->get('assigned_user_id'); $user_name = getUserName($assigned_user_id); if ($user_name != '') { $this->AddIntoCalendar($id, $assigned_user_id, $event, $Data); unset($InGCalendars[$event][$assigned_user_id]); } else { $userGroups = new GetGroupUsers(); $userGroups->getAllUsersInGroup($assigned_user_id); foreach ($userGroups->group_users as $to_email_id) { $this->AddIntoCalendar($id, $to_email_id, $event, $Data); unset($InGCalendars[$event][$to_email_id]); } } } if (count($InGCalendars) > 0) { while (list($event, $Events) = each($InGCalendars)) { foreach ($Events as $userid => $eventURL) { $this->DeleteGCalendarEvent($id, $userid, $eventURL, $event); } } } } } }
global $adb; global $current_user; //set the return module and return action and set the return id based on return module and record $returnmodule = vtlib_purify($_REQUEST['return_module']); $returnaction = vtlib_purify($_REQUEST['return_action']); if (($returnmodule != 'Emails' || $returnmodule == 'Emails' && $_REQUEST['record'] == '') && $_REQUEST['return_id'] != '') { $returnid = vtlib_purify($_REQUEST['return_id']); } else { $returnid = $focus->id; //$_REQUEST['record']; } $adb->println("\n\nMail Sending Process has been started."); //This function call is used to send mail to the assigned to user. In this mail CC and BCC addresses will be added. if ($_REQUEST['assigntype' == 'T'] && $_REQUEST['assigned_group_id'] != '') { $grp_obj = new GetGroupUsers(); $grp_obj->getAllUsersInGroup($_REQUEST['assigned_group_id']); $users_list = constructList($grp_obj->group_users, 'INTEGER'); if (count($users_list) > 0) { $sql = "select first_name, last_name, email1, email2, yahoo_id from vtiger_users where id in (" . generateQuestionMarks($users_list) . ")"; $params = array($users_list); } else { $sql = "select first_name, last_name, email1, email2, yahoo_id from vtiger_users"; $params = array(); } $res = $adb->pquery($sql, $params); $user_email = ''; while ($user_info = $adb->fetch_array($res)) { $email = $user_info['email1']; if ($email == '' || $email == 'NULL') { $email = $user_info['email2']; if ($email == '' || $email == 'NULL') {
/** * Function to get the group users Email ids */ function getDefaultAssigneeEmailIds($groupId) { $adb = PearDatabase::getInstance(); $emails = array(); if ($groupId != '') { require_once 'include/utils/GetGroupUsers.php'; $userGroups = new GetGroupUsers(); $userGroups->getAllUsersInGroup($groupId); if (count($userGroups->group_users) == 0) { return array(); } $result = $adb->pquery('SELECT email1 FROM vtiger_users WHERE vtiger_users.id IN (' . generateQuestionMarks($userGroups->group_users) . ') AND vtiger_users.status= ?', array($userGroups->group_users, 'Active')); $rows = $adb->num_rows($result); for ($i = 0; $i < $rows; $i++) { $email = $adb->query_result($result, $i, 'email1'); array_push($emails, $email); } $adb->println("Email ids are selected => '" . $emails . "'"); return $emails; } else { $adb->println("User id is empty. so return value is ''"); return array(); } }
/** * Function to get the group users Email ids */ function getDefaultAssigneeEmailIds($groupId) { global $adb; $emails = array(); if ($groupId != '') { require_once 'include/utils/GetGroupUsers.php'; $userGroups = new GetGroupUsers(); $userGroups->getAllUsersInGroup($groupId); if (count($userGroups->group_users) > 0) { $result = $adb->pquery('SELECT email1,email2,secondaryemail FROM vtiger_users WHERE vtiger_users.id IN (' . generateQuestionMarks($userGroups->group_users) . ') AND vtiger_users.status= ?', array($userGroups->group_users, 'Active')); $rows = $adb->num_rows($result); for ($i = 0; $i < $rows; $i++) { $email = $adb->query_result($result, $i, 'email1'); if ($email == '') { $email = $adb->query_result($result, $i, 'email2'); if ($email == '') { $email = $adb->query_result($result, $i, 'secondaryemail'); } else { $email = ''; } } array_push($emails, $email); } $adb->println("Email ids are selected => '" . implode(',', $emails) . "'"); } else { $adb->println("No users found in Group id {$groupId}"); } } else { $adb->println('Group id is empty, so return value is empty'); } return $emails; }
public function getRecipientEmails() { $recipientsInfo = $this->scheduledRecipients; $recipientsList = array(); if (!empty($recipientsInfo)) { if (!empty($recipientsInfo['users'])) { $recipientsList = array_merge($recipientsList, $recipientsInfo['users']); } if (!empty($recipientsInfo['roles'])) { foreach ($recipientsInfo['roles'] as $roleId) { $roleUsers = getRoleUsers($roleId); foreach ($roleUsers as $userId => $userName) { array_push($recipientsList, $userId); } } } if (!empty($recipientsInfo['rs'])) { foreach ($recipientsInfo['rs'] as $roleId) { $users = getRoleAndSubordinateUsers($roleId); foreach ($users as $userId => $userName) { array_push($recipientsList, $userId); } } } if (!empty($recipientsInfo['groups'])) { require_once 'include/utils/GetGroupUsers.php'; foreach ($recipientsInfo['groups'] as $groupId) { $userGroups = new GetGroupUsers(); $userGroups->getAllUsersInGroup($groupId); $recipientsList = array_merge($recipientsList, $userGroups->group_users); } } } $recipientsEmails = array(); if (!empty($recipientsList) && count($recipientsList) > 0) { foreach ($recipientsList as $userId) { $userName = getUserFullName($userId); $userEmail = getUserEmail($userId); if (!in_array($userEmail, $recipientsEmails)) { $recipientsEmails[$userName] = $userEmail; } } } return $recipientsEmails; }
/** to get all the vtiger_users and vtiger_groups of the specified group * @params $groupId --> Group Id :: Type Integer * @returns the vtiger_users present in the group in the variable $parent_groups of the class * @returns the sub vtiger_groups present in the group in the variable $group_subgroups of the class */ function getAllUsersInGroup($groupid) { $adb = PearDatabase::getInstance(); $log = vglobal('log'); $log->debug("Entering getAllUsersInGroup(" . $groupid . ") method..."); //Retreiving from the user2grouptable $query = "select * from vtiger_users2group where groupid=?"; $result = $adb->pquery($query, array($groupid)); $num_rows = $adb->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $now_user_id = $adb->query_result($result, $i, 'userid'); if (!in_array($now_user_id, $this->group_users)) { $this->group_users[] = $now_user_id; } } //Retreiving from the vtiger_group2role $query = "select * from vtiger_group2role where groupid=?"; $result = $adb->pquery($query, array($groupid)); $num_rows = $adb->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $now_role_id = $adb->query_result($result, $i, 'roleid'); $now_role_users = array(); $now_role_users = getRoleUsers($now_role_id); foreach ($now_role_users as $now_role_userid => $now_role_username) { if (!in_array($now_role_userid, $this->group_users)) { $this->group_users[] = $now_role_userid; } } } //Retreiving from the vtiger_group2rs $query = "select * from vtiger_group2rs where groupid=?"; $result = $adb->pquery($query, array($groupid)); $num_rows = $adb->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $now_rs_id = $adb->query_result($result, $i, 'roleandsubid'); $now_rs_users = getRoleAndSubordinateUsers($now_rs_id); foreach ($now_rs_users as $now_rs_userid => $now_rs_username) { if (!in_array($now_rs_userid, $this->group_users)) { $this->group_users[] = $now_rs_userid; } } } //Retreving from group2group $query = "select * from vtiger_group2grouprel where groupid=?"; $result = $adb->pquery($query, array($groupid)); $num_rows = $adb->num_rows($result); for ($i = 0; $i < $num_rows; $i++) { $now_grp_id = $adb->query_result($result, $i, 'containsgroupid'); $focus = new GetGroupUsers(); $focus->getAllUsersInGroup($now_grp_id); $now_grp_users = $focus->group_users; $now_grp_grps = $focus->group_subgroups; if (!array_key_exists($now_grp_id, $this->group_subgroups)) { $this->group_subgroups[$now_grp_id] = $now_grp_users; } foreach ($focus->group_users as $temp_user_id) { if (!in_array($temp_user_id, $this->group_users)) { $this->group_users[] = $temp_user_id; } } foreach ($focus->group_subgroups as $temp_grp_id => $users_array) { if (!array_key_exists($temp_grp_id, $this->group_subgroups)) { $this->group_subgroups[$temp_grp_id] = $focus->group_users; } } } $log->debug("Exiting getAllUsersInGroup method..."); }
function HeldDeskNewCommentOwner($entityData) { $log = vglobal('log'); $log->debug('Entering HeldDeskNewCommentAccount'); $db = PearDatabase::getInstance(); $wsId = $entityData->getId(); $parts = explode('x', $wsId); $entityId = $parts[1]; $data = $entityData->getData(); $relatedToWSId = $data['related_to']; $relatedToId = explode('x', $relatedToWSId); $mails = []; $sql = 'SELECT smownerid FROM vtiger_crmentity WHERE deleted = 0 AND crmid = ? '; $result = $db->pquery($sql, [$relatedToId[1]]); if ($result->rowCount() > 0) { $smownerid = $db->getSingleValue($result); $ownerType = vtws_getOwnerType($smownerid); if ($ownerType == 'Users') { $user = new Users(); $currentUser = $user->retrieveCurrentUserInfoFromFile($smownerid); if ($currentUser->column_fields['emailoptout'] == '1') { $mails[] = $currentUser->column_fields['email1']; } } else { require_once 'include/utils/GetGroupUsers.php'; $ggu = new GetGroupUsers(); $ggu->getAllUsersInGroup($smownerid); foreach ($ggu->group_users as $userId) { $user = new Users(); $currentUser = $user->retrieveCurrentUserInfoFromFile($userId); if ($currentUser->column_fields['emailoptout'] == '1') { $mails[] = $currentUser->column_fields['email1']; } } } } if (count($mails) > 0) { $mails = implode(',', $mails); $data = ['sysname' => 'NewCommentAddedToTicketOwner', 'to_email' => $mails, 'module' => 'ModComments', 'record' => $entityId]; $recordModel = Vtiger_Record_Model::getCleanInstance('OSSMailTemplates'); if ($recordModel->sendMailFromTemplate($data)) { $log->debug('HeldDeskNewCommentAccount'); return true; } } $log->debug('HeldDeskNewCommentAccount'); return false; }
function sendNotificationToGroups($groupid, $crmid, $module) { global $adb, $app_strings, $current_user; $returnEntity = array(); $returnEntity = getEntityName($module, array($crmid)); $mycrmid = $groupid; require_once 'include/utils/GetGroupUsers.php'; $getGroupObj = new GetGroupUsers(); $getGroupObj->getAllUsersInGroup($mycrmid); $userIds = $getGroupObj->group_users; if (count($userIds) > 0) { $groupqry = "select email1,id,user_name from vtiger_users WHERE status='Active' AND id in(" . generateQuestionMarks($userIds) . ")"; $groupqry_res = $adb->pquery($groupqry, array($userIds)); for ($z = 0; $z < $adb->num_rows($groupqry_res); $z++) { //handle the mail send to vtiger_users $emailadd = $adb->query_result($groupqry_res, $z, 'email1'); $curr_userid = $adb->query_result($groupqry_res, $z, 'id'); $tosender = $adb->query_result($groupqry_res, $z, 'user_name'); $pmodule = 'Users'; $description = $app_strings['MSG_DEAR'] . " " . $tosender . ",<br>" . $returnEntity[$crmid] . " " . $app_strings['MSG_HAS_BEEN_CREATED_FOR'] . " " . $module . "<br><br>" . $app_strings['MSG_THANKS'] . ",<br>" . $app_strings['MSG_VTIGERTEAM']; require_once 'modules/Emails/mail.php'; $mail_status = send_mail('Emails', $emailadd, $current_user->user_name, '', 'Record created-vTiger Team', $description, '', '', 'all', $crmid); $all_to_emailids[] = $emailadd; $mail_status_str .= $emailadd . "=" . $mail_status . "&&&"; } } }
function getEventNotification($mode, $subject, $desc) { global $current_user, $adb; require_once "modules/Emails/mail.php"; $subject = $mode . ' : ' . $subject; $crmentity = new CRMEntity(); if ($desc['assingn_type'] == "U") { $to_email = getUserEmailId('id', $desc['user_id']); $description = getActivityDetails($desc, $desc['user_id']); send_mail('Calendar', $to_email, $current_user->user_name, '', $subject, $description); } if ($desc['assingn_type'] == "T") { $groupid = ''; $groupname = $desc['group_name']; // getGroupName API was changed to return array of two elements! if (is_array($groupname) && !empty($groupname)) { $groupid = $groupname[1]; $groupname = $groupname[0]; } else { $resultqry = $adb->pquery("select groupid from vtiger_groups where groupname=?", array($groupname)); $groupid = $adb->query_result($resultqry, 0, "groupid"); } require_once 'include/utils/GetGroupUsers.php'; $getGroupObj = new GetGroupUsers(); $getGroupObj->getAllUsersInGroup($groupid); $userIds = $getGroupObj->group_users; if (count($userIds) > 0) { $groupqry = "select email1,id from vtiger_users where id in(" . generateQuestionMarks($userIds) . ")"; $groupqry_res = $adb->pquery($groupqry, array($userIds)); $noOfRows = $adb->num_rows($groupqry_res); for ($z = 0; $z < $noOfRows; $z++) { $emailadd = $adb->query_result($groupqry_res, $z, 'email1'); $curr_userid = $adb->query_result($groupqry_res, $z, 'id'); $description = getActivityDetails($desc, $curr_userid); $mail_status = send_mail('Calendar', $emailadd, getUserName($curr_userid), '', $subject, $description); } } } }
function getEventNotification($mode, $subject, $desc) { global $current_user, $adb; require_once "modules/Emails/mail.php"; $subject = $mode . ' : ' . $subject; $crmentity = new CRMEntity(); if (getUserName($desc['user_id'])) { $to_email = getUserEmailId('id', $desc['user_id']); $description = getActivityDetails($desc, $desc['user_id']); send_mail('Calendar', $to_email, $current_user->user_name, '', $subject, $description); } else { $groupid = $desc['user_id']; require_once 'include/utils/GetGroupUsers.php'; $getGroupObj = new GetGroupUsers(); $getGroupObj->getAllUsersInGroup($groupid); $userIds = $getGroupObj->group_users; if (count($userIds) > 0) { $groupqry = "select email1,id from vtiger_users where id in(" . generateQuestionMarks($userIds) . ")"; $groupqry_res = $adb->pquery($groupqry, array($userIds)); $noOfRows = $adb->num_rows($groupqry_res); for ($z = 0; $z < $noOfRows; $z++) { $emailadd = $adb->query_result($groupqry_res, $z, 'email1'); $curr_userid = $adb->query_result($groupqry_res, $z, 'id'); $description = getActivityDetails($desc, $curr_userid); $mail_status = send_mail('Calendar', $emailadd, getUserName($curr_userid), '', $subject, $description); } } } }
/** * @param $context \Workflow\VTEntity */ public function handleTask(&$context) { global $current_user, $adb; if ($this->isContinued()) { $sql = "SELECT id, result, result_user_id FROM vtiger_wf_confirmation WHERE execID = '" . $this->getExecId() . "' AND result != '' AND visible = 1"; $result = $adb->query($sql); if ($adb->num_rows($result) == 0) { $timeout = $context->getEnvironment('_permissionTimeout'); $timeoutValue = $context->getEnvironment('_permissionTimeoutValue'); if ($timeout == true) { if (time() > $timeoutValue) { $this->addStat('Timeout action: ' . $this->get('timeout_output')); return $this->get('timeout_output'); } } return array("delay" => time() + 60 * 10, "checkmode" => "static"); } $data = $adb->fetchByAssoc($result); $sql = "SELECT user_name FROM vtiger_users WHERE id = " . $data["result_user_id"]; $resultUser = $adb->query($sql); $resultUser = $adb->fetchByAssoc($resultUser); $this->addStat("Permission: " . $data["result"] . " by " . $resultUser["user_name"]); $sql = "UPDATE vtiger_wf_confirmation SET visible = 0 WHERE id = " . $data["id"]; $adb->query($sql); return $data["result"]; } $this->_compatible(); $connected = $this->getConnectedObjects("assigned_to"); $targets = array(); if (!empty($connected)) { foreach ($connected as $user) { if (empty($user)) { continue; } $targets['user'][] = intval($user->getId()); } } $TMPtargets = $this->get('targets'); if (is_array($TMPtargets)) { foreach ($TMPtargets as $value) { $parts = explode('##', $value); if ($parts[0] == 'USER' && !in_array(intval($parts[1]), $targets['user'])) { $targets['user'][] = intval($parts[1]); } if ($parts[0] == 'GROUP') { $focusGrpUsers = new GetGroupUsers(); $focusGrpUsers->getAllUsersInGroup($parts[1]); $groupUser = $focusGrpUsers->group_users; if (is_array($groupUser)) { foreach ($groupUser as $userId) { if (!in_array($userId, $targets['user'])) { $targets['user'][] = $userId; } } } } if ($parts[0] == 'ROLE') { $focusGrpUsers = new GetGroupUsers(); $focusGrpUsers->getAllUsersInGroup($parts[0]); $groupUser = array_keys(getRoleUsers($parts[1])); if (is_array($groupUser)) { foreach ($groupUser as $userId) { if (!in_array($userId, $targets['user'])) { $targets['user'][] = $userId; } } } } } } $backgroundcolor = $this->get("backgroundcolor"); $bgmode = $this->get("bgmode"); if (!empty($bgmode) && $bgmode != -1) { if ($bgmode == "function") { $parser = new VTWfExpressionParser($backgroundcolorFKT, $context, false); # Last Parameter = DEBUG try { $parser->run(); } catch (ExpressionException $exp) { Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", ""); } $backgroundcolor = $parser->getReturn(); } else { if (strpos($backgroundcolor, '$') !== false || strpos($backgroundcolor, '?') !== false) { $objTemplate = new VTTemplate($context); $backgroundcolor = $objTemplate->render($backgroundcolor); } } } else { $backgroundcolor = "#ffffff"; } if (empty($backgroundcolor)) { $backgroundcolor = "#ffffff"; } $infomessage = $this->get("infomessage"); $infomessageFKT = $this->get("infomessageFKT"); $infomode = $this->get("infomode"); if (!empty($infomode) && $infomode != -1) { if ($infomode == "function") { $parser = new VTWfExpressionParser($infomessageFKT, $context, false); # Last Parameter = DEBUG try { $parser->run(); } catch (ExpressionException $exp) { Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", ""); } $infomessage = $parser->getReturn(); } else { if (strpos($infomessage, '$') !== false || strpos($infomessage, '?') !== false) { $objTemplate = new VTTemplate($context); $infomessage = $objTemplate->render($infomessage); } } } else { $infomessage = ""; } if (empty($infomessage)) { $infomessage = ""; } $rundirect = $this->get("rundirect"); $sql = "INSERT INTO vtiger_wf_confirmation SET crmid = " . $context->getId() . ", infomessage = ?, backgroundcolor = ?, blockID = '" . $this->getBlockId() . "', execID = '" . $this->getExecId() . "', visible = 1, result = '', module = '" . $context->getModuleName() . "', workflow_id = " . $this->getWorkflowId() . ", rundirect = " . ($rundirect == "1" ? 1 : 0) . ", from_user_id = " . $current_user->id; $adb->pquery($sql, array($infomessage, $backgroundcolor)); $confID = $adb->getLastInsertID(); foreach ($targets['user'] as $user) { $sql = "INSERT INTO vtiger_wf_confirmation_user SET confirmation_id = '" . $confID . "', user_id = " . $user; $adb->query($sql); $this->addStat("create Permission entry (Block " . $this->getBlockId() . ") for User " . $user); } // if we need an timeout than wait until $use_timeout = $this->get("use_timeout"); if ($use_timeout == '1') { $timeout_value = $this->get("timeout_value"); $timeout_value_mode = $this->get("timeout_value_mode"); $timestamp = time(); switch ($timeout_value_mode) { case "minutes": $timestamp += 60 * $timeout_value; break; case "hours": $timestamp += 60 * 60 * $timeout_value; break; case "days": $timestamp += 24 * 60 * 60 * $timeout_value; break; case "weeks": $timestamp += 7 * 24 * 60 * 60 * $timeout_value; break; } $context->setEnvironment('_permissionTimeout', true); $context->setEnvironment('_permissionTimeoutValue', $timestamp); } else { $context->setEnvironment('_permissionTimeout', false); } // check every 15 minutes return array("delay" => time() + 60 * 15, "checkmode" => "static"); }